diff options
-rw-r--r-- | shaders/circle_mask.glsl | 2 | ||||
-rw-r--r-- | shaders/rounded_rectangle.glsl | 11 | ||||
-rw-r--r-- | src/RoundedRectangle.cpp | 12 |
3 files changed, 12 insertions, 13 deletions
diff --git a/shaders/circle_mask.glsl b/shaders/circle_mask.glsl index 61c87cb..367edbe 100644 --- a/shaders/circle_mask.glsl +++ b/shaders/circle_mask.glsl @@ -10,7 +10,7 @@ vec4 circle(vec2 uv, vec2 pos, float rad, vec4 color) { void main() { vec2 uv = gl_TexCoord[0].xy * resolution; vec2 center = resolution * 0.5; - float radius = 0.49 * resolution.y; + float radius = 0.5 * resolution.y - 1; vec4 texture_color = texture2D(texture, gl_TexCoord[0].xy); gl_FragColor = circle(uv, center, radius, texture_color); diff --git a/shaders/rounded_rectangle.glsl b/shaders/rounded_rectangle.glsl index 88a057a..d06a4ba 100644 --- a/shaders/rounded_rectangle.glsl +++ b/shaders/rounded_rectangle.glsl @@ -12,10 +12,11 @@ void main() { vec2 uv = gl_TexCoord[0].xy * resolution; vec2 center = resolution * 0.5; vec2 size = resolution * 0.5; - vec4 background_color = vec4(0.0, 0.0, 0.0, 0.0); + float a = clamp(rounded_rect(uv - center, size - radius, radius), 0.0, 1.0); - vec4 front_color = gl_Color; - if(uv.x >= band_pos.x && uv.x <= band_pos.x + band_size.x && uv.y >= band_pos.y && uv.y <= band_pos.y + band_size.y) - front_color = band_color; - gl_FragColor = mix(front_color, background_color, a); + // same as: if(uv.x >= band_pos.x && uv.x <= band_pos.x + band_size.x && uv.y >= band_pos.y && uv.y <= band_pos.y + band_size.y) + vec2 band_blend = step(band_pos, uv) - step(band_pos + band_size, uv); + vec4 front_color = mix(gl_Color, band_color, band_blend.x*band_blend.y); + front_color.a *= (1.0 - a); + gl_FragColor = front_color; }
\ No newline at end of file diff --git a/src/RoundedRectangle.cpp b/src/RoundedRectangle.cpp index 5baeac6..735c182 100644 --- a/src/RoundedRectangle.cpp +++ b/src/RoundedRectangle.cpp @@ -12,8 +12,9 @@ namespace QuickMedia { vertices[1].texCoords = sf::Vector2f(1.0f, 0.0f); vertices[2].texCoords = sf::Vector2f(1.0f, 1.0f); vertices[3].texCoords = sf::Vector2f(0.0f, 1.0f); - set_color(color); - set_size(size); + + for(size_t i = 0; i < 4; ++i) + vertices[i].color = color; const sf::Color shadow_color(0, 0, 0, 50); @@ -49,7 +50,6 @@ namespace QuickMedia { vertices[2].position = pos + sf::Vector2f(size.x, size.y); vertices[3].position = pos + sf::Vector2f(0.0f, size.y); - const sf::Color shadow_color(0, 0, 0, 100); const float shadow_radius = 5.0f; // Top @@ -83,10 +83,8 @@ namespace QuickMedia { } void RoundedRectangle::set_color(sf::Color color) { - vertices[0].color = color; - vertices[1].color = color; - vertices[2].color = color; - vertices[3].color = color; + for(size_t i = 0; i < 4; ++i) + vertices[i].color = color; } sf::Vector2f RoundedRectangle::get_position() const { |