diff --git a/src/st/st-scroll-view-fade.c b/src/st/st-scroll-view-fade.c index b387e384a..6c0176f5d 100644 --- a/src/st/st-scroll-view-fade.c +++ b/src/st/st-scroll-view-fade.c @@ -45,6 +45,7 @@ struct _StScrollViewFade StAdjustment *hadjustment; guint fade_edges : 1; + guint extend_fade_area: 1; ClutterMargin fade_margins; }; @@ -58,6 +59,7 @@ enum { PROP_FADE_MARGINS, PROP_FADE_EDGES, + PROP_EXTEND_FADE_AREA, N_PROPS }; @@ -168,6 +170,7 @@ st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect, value <= 1.0 : (rtl ? value > 0.0 : value < 1.0)); + clutter_shader_effect_set_uniform (shader, "extend_fade_area", G_TYPE_INT, 1, self->extend_fade_area); clutter_shader_effect_set_uniform (shader, "fade_offset_top", G_TYPE_FLOAT, 1, ABS (self->fade_margins.top)); clutter_shader_effect_set_uniform (shader, "fade_offset_bottom", G_TYPE_FLOAT, 1, ABS (self->fade_margins.bottom)); clutter_shader_effect_set_uniform (shader, "fade_offset_left", G_TYPE_FLOAT, 1, ABS (self->fade_margins.left)); @@ -325,6 +328,21 @@ st_scroll_view_fade_set_fade_edges (StScrollViewFade *self, g_object_thaw_notify (G_OBJECT (self)); } +static void +st_scroll_view_fade_set_extend_fade_area (StScrollViewFade *self, + gboolean extend_fade_area) +{ + if (self->extend_fade_area == extend_fade_area) + return; + + self->extend_fade_area = extend_fade_area; + + if (self->actor != NULL) + clutter_actor_queue_redraw (self->actor); + + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_EXTEND_FADE_AREA]); +} + static void st_scroll_view_fade_set_property (GObject *object, guint prop_id, @@ -341,6 +359,9 @@ st_scroll_view_fade_set_property (GObject *object, case PROP_FADE_EDGES: st_scroll_view_fade_set_fade_edges (self, g_value_get_boolean (value)); break; + case PROP_EXTEND_FADE_AREA: + st_scroll_view_fade_set_extend_fade_area (self, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -363,6 +384,9 @@ st_scroll_view_fade_get_property (GObject *object, case PROP_FADE_EDGES: g_value_set_boolean (value, self->fade_edges); break; + case PROP_EXTEND_FADE_AREA: + g_value_set_boolean (value, self->extend_fade_area); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -414,6 +438,18 @@ st_scroll_view_fade_class_init (StScrollViewFadeClass *klass) FALSE, ST_PARAM_READWRITE); + /** + * StScrollViewFade:extend-fade-area: + * + * Whether faded edges should extend beyond the faded area of the #StScrollViewFade. + */ + props[PROP_EXTEND_FADE_AREA] = + g_param_spec_boolean ("extend-fade-area", + "Extend Fade Area", + "Whether faded edges should extend beyond the faded area", + FALSE, + ST_PARAM_READWRITE); + g_object_class_install_properties (gobject_class, N_PROPS, props); } diff --git a/src/st/st-scroll-view-fade.glsl b/src/st/st-scroll-view-fade.glsl index 0d8812b07..39ed6a345 100644 --- a/src/st/st-scroll-view-fade.glsl +++ b/src/st/st-scroll-view-fade.glsl @@ -28,6 +28,7 @@ uniform bool fade_edges_top; uniform bool fade_edges_right; uniform bool fade_edges_bottom; uniform bool fade_edges_left; +uniform bool extend_fade_area; uniform vec2 fade_area_topleft; uniform vec2 fade_area_bottomright; @@ -38,11 +39,11 @@ void main () float y = height * cogl_tex_coord_in[0].y; float x = width * cogl_tex_coord_in[0].x; + float ratio = 1.0; if (x > fade_area_topleft[0] && x < fade_area_bottomright[0] && y > fade_area_topleft[1] && y < fade_area_bottomright[1]) { - float ratio = 1.0; float fade_top_start = fade_area_topleft[1] + fade_offset_top; float fade_left_start = fade_area_topleft[0] + fade_offset_left; float fade_bottom_start = fade_area_bottomright[1] - fade_offset_bottom; @@ -67,9 +68,14 @@ void main () if (fade_right) { ratio *= (fade_area_bottomright[0] - x) / (fade_area_bottomright[0] - fade_right_start); } - - cogl_color_out *= ratio; - } else { - cogl_color_out *= 0.0; + } else if (extend_fade_area) { + if (x <= fade_area_topleft[0] && fade_edges_left || + x >= fade_area_bottomright[0] && fade_edges_right || + y <= fade_area_topleft[1] && fade_edges_top || + y >= fade_area_bottomright[1] && fade_edges_bottom) { + ratio = 0.0; + } } + + cogl_color_out *= ratio; }