static void st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect) { StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect); ClutterOffscreenEffectClass *parent; CoglHandle material; gdouble value, lower, upper, page_size; ClutterActor *vscroll = st_scroll_view_get_vscroll_bar (ST_SCROLL_VIEW (self->actor)); ClutterActor *hscroll = st_scroll_view_get_hscroll_bar (ST_SCROLL_VIEW (self->actor)); gboolean h_scroll_visible, v_scroll_visible; g_object_get (ST_SCROLL_VIEW (self->actor), "hscrollbar-visible", &h_scroll_visible, "vscrollbar-visible", &v_scroll_visible, NULL); if (self->program == COGL_INVALID_HANDLE) goto out; st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); if (self->offset_top_uniform > -1) { if (value > lower + 0.1) cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, 0.0f); } if (self->offset_bottom_uniform > -1) { if (value < upper - page_size - 0.1) cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, 0.0f); } if (self->tex_uniform > -1) cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); if (self->height_uniform > -1) cogl_program_set_uniform_1f (self->program, self->height_uniform, clutter_actor_get_height (self->actor)); if (self->width_uniform > -1) cogl_program_set_uniform_1f (self->program, self->width_uniform, clutter_actor_get_width (self->actor)); if (self->scrollbar_width_uniform > -1) cogl_program_set_uniform_1f (self->program, self->scrollbar_width_uniform, v_scroll_visible ? clutter_actor_get_width (vscroll) : 0); if (self->scrollbar_height_uniform > -1) cogl_program_set_uniform_1f (self->program, self->scrollbar_height_uniform, h_scroll_visible ? clutter_actor_get_height (hscroll) : 0); if (self->rtl_uniform > -1) cogl_program_set_uniform_1i (self->program, self->rtl_uniform, (st_widget_get_direction (ST_WIDGET (self->actor)) == ST_TEXT_DIRECTION_RTL)); material = clutter_offscreen_effect_get_target (effect); cogl_material_set_user_program (material, self->program); out: parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (st_scroll_view_fade_parent_class); parent->paint_target (effect); }
static void on_adjustment_changed (StAdjustment *adjustment, ClutterEffect *effect) { gdouble value, lower, upper, page_size; gboolean needs_fade; StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect); st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); needs_fade = (value > lower + 0.1) || (value < upper - page_size - 0.1); if (!needs_fade) { st_adjustment_get_values (self->hadjustment, &value, &lower, &upper, NULL, NULL, &page_size); needs_fade = (value > lower + 0.1) || (value < upper - page_size - 0.1); } clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), needs_fade); }
static void on_vadjustment_changed (StAdjustment *adjustment, ClutterEffect *effect) { gdouble value, lower, upper, page_size; gboolean needs_fade; st_adjustment_get_values (adjustment, &value, &lower, &upper, NULL, NULL, &page_size); needs_fade = (value > lower + 0.1) || (value < upper - page_size - 0.1); clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), needs_fade); }
static void move_slider (StScrollBar *bar, gfloat x, gfloat y) { StScrollBarPrivate *priv = bar->priv; gdouble position, lower, upper, page_size; gfloat ux, uy, pos, size; if (!priv->adjustment) return; if (!clutter_actor_transform_stage_point (priv->trough, x, y, &ux, &uy)) return; if (priv->vertical) size = clutter_actor_get_height (priv->trough) - clutter_actor_get_height (priv->handle); else size = clutter_actor_get_width (priv->trough) - clutter_actor_get_width (priv->handle); if (size == 0) return; if (priv->vertical) pos = uy - priv->y_origin; else pos = ux - priv->x_origin; pos = CLAMP (pos, 0, size); st_adjustment_get_values (priv->adjustment, NULL, &lower, &upper, NULL, NULL, &page_size); position = ((pos / size) * (upper - lower - page_size)) + lower; st_adjustment_set_value (priv->adjustment, position); }
static gboolean trough_paging_cb (StScrollBar *self) { gfloat handle_pos, event_pos, tx, ty; gdouble value; gdouble page_increment; gboolean ret; gulong mode; ClutterAnimation *a; GValue v = { 0, }; ClutterTimeline *t; if (self->priv->paging_event_no == 0) { /* Scroll on after initial timeout. */ mode = CLUTTER_EASE_OUT_CUBIC; ret = FALSE; self->priv->paging_event_no = 1; self->priv->paging_source_id = g_timeout_add ( PAGING_INITIAL_REPEAT_TIMEOUT, (GSourceFunc) trough_paging_cb, self); } else if (self->priv->paging_event_no == 1) { /* Scroll on after subsequent timeout. */ ret = FALSE; mode = CLUTTER_EASE_IN_CUBIC; self->priv->paging_event_no = 2; self->priv->paging_source_id = g_timeout_add ( PAGING_SUBSEQUENT_REPEAT_TIMEOUT, (GSourceFunc) trough_paging_cb, self); } else { /* Keep scrolling. */ ret = TRUE; mode = CLUTTER_LINEAR; self->priv->paging_event_no++; } /* Do the scrolling */ st_adjustment_get_values (self->priv->adjustment, &value, NULL, NULL, NULL, &page_increment, NULL); if (self->priv->vertical) handle_pos = clutter_actor_get_y (self->priv->handle); else handle_pos = clutter_actor_get_x (self->priv->handle); clutter_actor_transform_stage_point (CLUTTER_ACTOR (self->priv->trough), self->priv->move_x, self->priv->move_y, &tx, &ty); if (self->priv->vertical) event_pos = ty; else event_pos = tx; if (event_pos > handle_pos) { if (self->priv->paging_direction == NONE) { /* Remember direction. */ self->priv->paging_direction = DOWN; } if (self->priv->paging_direction == UP) { /* Scrolled far enough. */ return FALSE; } value += page_increment; } else { if (self->priv->paging_direction == NONE) { /* Remember direction. */ self->priv->paging_direction = UP; } if (self->priv->paging_direction == DOWN) { /* Scrolled far enough. */ return FALSE; } value -= page_increment; } if (self->priv->paging_animation) { clutter_animation_completed (self->priv->paging_animation); } /* FIXME: Creating a new animation for each scroll is probably not the best * idea, but it's a lot less involved than extenind the current animation */ a = self->priv->paging_animation = g_object_new (CLUTTER_TYPE_ANIMATION, "object", self->priv->adjustment, "duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * st_slow_down_factor), "mode", mode, NULL); g_value_init (&v, G_TYPE_DOUBLE); g_value_set_double (&v, value); clutter_animation_bind (self->priv->paging_animation, "value", &v); t = clutter_animation_get_timeline (self->priv->paging_animation); g_signal_connect (a, "completed", G_CALLBACK (animation_completed_cb), self->priv); clutter_timeline_start (t); return ret; }
static void scroll_bar_allocate_children (StScrollBar *bar, const ClutterActorBox *box, ClutterAllocationFlags flags) { StScrollBarPrivate *priv = bar->priv; StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (bar)); ClutterActorBox content_box, bw_box, fw_box, trough_box; gfloat bw_stepper_size, fw_stepper_size, min_size, natural_size; st_theme_node_get_content_box (theme_node, box, &content_box); if (priv->vertical) { gfloat width = content_box.x2 - content_box.x1; clutter_actor_get_preferred_height (priv->bw_stepper, width, &min_size, &natural_size); bw_stepper_size = MAX (min_size, natural_size); /* Backward stepper */ bw_box.x1 = content_box.x1; bw_box.y1 = content_box.y1; bw_box.x2 = content_box.x2; bw_box.y2 = bw_box.y1 + bw_stepper_size; clutter_actor_allocate (priv->bw_stepper, &bw_box, flags); clutter_actor_get_preferred_height (priv->fw_stepper, width, &min_size, &natural_size); fw_stepper_size = MAX (min_size, natural_size); /* Forward stepper */ fw_box.x1 = content_box.x1; fw_box.y1 = content_box.y2 - fw_stepper_size; fw_box.x2 = content_box.x2; fw_box.y2 = content_box.y2; clutter_actor_allocate (priv->fw_stepper, &fw_box, flags); /* Trough */ trough_box.x1 = content_box.x1; trough_box.y1 = content_box.y1 + bw_stepper_size; trough_box.x2 = content_box.x2; trough_box.y2 = content_box.y2 - fw_stepper_size; clutter_actor_allocate (priv->trough, &trough_box, flags); } else { gfloat height = content_box.y2 - content_box.y1; clutter_actor_get_preferred_width (priv->bw_stepper, height, &min_size, &natural_size); bw_stepper_size = MAX (min_size, natural_size); /* Backward stepper */ bw_box.x1 = content_box.x1; bw_box.y1 = content_box.y1; bw_box.x2 = bw_box.x1 + bw_stepper_size; bw_box.y2 = content_box.y2; clutter_actor_allocate (priv->bw_stepper, &bw_box, flags); clutter_actor_get_preferred_width (priv->fw_stepper, height, &min_size, &natural_size); fw_stepper_size = MAX (min_size, natural_size); /* Forward stepper */ fw_box.x1 = content_box.x2 - fw_stepper_size; fw_box.y1 = content_box.y1; fw_box.x2 = content_box.x2; fw_box.y2 = content_box.y2; clutter_actor_allocate (priv->fw_stepper, &fw_box, flags); /* Trough */ trough_box.x1 = content_box.x1 + bw_stepper_size; trough_box.y1 = content_box.y1; trough_box.x2 = content_box.x2 - fw_stepper_size; trough_box.y2 = content_box.y2; clutter_actor_allocate (priv->trough, &trough_box, flags); } if (priv->adjustment) { float handle_size, position, avail_size, stepper_size; gdouble value, lower, upper, page_size, increment, min_size, max_size; ClutterActorBox handle_box = { 0, }; stepper_size = bw_stepper_size + fw_stepper_size; st_adjustment_get_values (priv->adjustment, &value, &lower, &upper, NULL, NULL, &page_size); if ((upper == lower) || (page_size >= (upper - lower))) increment = 1.0; else increment = page_size / (upper - lower); min_size = 32.; st_theme_node_lookup_length (theme_node, "min-size", FALSE, &min_size); max_size = G_MAXINT16; st_theme_node_lookup_length (theme_node, "max-size", FALSE, &max_size); if (upper - lower - page_size <= 0) position = 0; else position = (value - lower) / (upper - lower - page_size); if (priv->vertical) { avail_size = content_box.y2 - content_box.y1 - stepper_size; handle_size = increment * avail_size; handle_size = CLAMP (handle_size, min_size, max_size); handle_box.x1 = content_box.x1; handle_box.y1 = bw_box.y2 + position * (avail_size - handle_size); handle_box.x2 = content_box.x2; handle_box.y2 = handle_box.y1 + handle_size; } else { avail_size = content_box.x2 - content_box.x1 - stepper_size; handle_size = increment * avail_size; handle_size = CLAMP (handle_size, min_size, max_size); handle_box.x1 = bw_box.x2 + position * (avail_size - handle_size); handle_box.y1 = content_box.y1; handle_box.x2 = handle_box.x1 + handle_size; handle_box.y2 = content_box.y2; } /* snap to pixel */ handle_box.x1 = (int) handle_box.x1; handle_box.y1 = (int) handle_box.y1; handle_box.x2 = (int) handle_box.x2; handle_box.y2 = (int) handle_box.y2; clutter_actor_allocate (priv->handle, &handle_box, flags); } }
static void st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect) { StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect); ClutterOffscreenEffectClass *parent; CoglHandle material; gdouble value, lower, upper, page_size; ClutterActor *vscroll = st_scroll_view_get_vscroll_bar (ST_SCROLL_VIEW (self->actor)); ClutterActor *hscroll = st_scroll_view_get_hscroll_bar (ST_SCROLL_VIEW (self->actor)); gboolean h_scroll_visible, v_scroll_visible; ClutterActorBox allocation, content_box, paint_box; /* * Used to pass the fade area to the shader * * [0][0] = x1 * [0][1] = y1 * [1][0] = x2 * [1][1] = y2 * */ float fade_area[2][2]; ClutterVertex verts[4]; if (self->program == COGL_INVALID_HANDLE) goto out; clutter_actor_get_paint_box (self->actor, &paint_box); clutter_actor_get_abs_allocation_vertices (self->actor, verts); clutter_actor_get_allocation_box (self->actor, &allocation); st_theme_node_get_content_box (st_widget_get_theme_node (ST_WIDGET (self->actor)), (const ClutterActorBox *)&allocation, &content_box); /* * The FBO is based on the paint_volume's size which can be larger then the actual * allocation, so we have to account for that when passing the positions */ fade_area[0][0] = content_box.x1 + (verts[0].x - paint_box.x1); fade_area[0][1] = content_box.y1 + (verts[0].y - paint_box.y1); fade_area[1][0] = content_box.x2 + (verts[3].x - paint_box.x2); fade_area[1][1] = content_box.y2 + (verts[3].y - paint_box.y2); g_object_get (ST_SCROLL_VIEW (self->actor), "hscrollbar-visible", &h_scroll_visible, "vscrollbar-visible", &v_scroll_visible, NULL); if (v_scroll_visible) { if (st_widget_get_direction (ST_WIDGET (self->actor)) == ST_TEXT_DIRECTION_RTL) fade_area[0][0] += clutter_actor_get_width (vscroll); fade_area[1][0] -= clutter_actor_get_width (vscroll); } if (h_scroll_visible) fade_area[1][1] -= clutter_actor_get_height (hscroll); st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); if (self->offset_top_uniform > -1) { if (value > lower + 0.1) cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, 0.0f); } if (self->offset_bottom_uniform > -1) { if (value < upper - page_size - 0.1) cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, 0.0f); } if (self->tex_uniform > -1) cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); if (self->height_uniform > -1) cogl_program_set_uniform_1f (self->program, self->height_uniform, clutter_actor_get_height (self->actor)); if (self->width_uniform > -1) cogl_program_set_uniform_1f (self->program, self->width_uniform, clutter_actor_get_width (self->actor)); if (self->fade_area_uniform > -1) cogl_program_set_uniform_matrix (self->program, self->fade_area_uniform, 2, 1, FALSE, (const float *)fade_area); material = clutter_offscreen_effect_get_target (effect); cogl_material_set_user_program (material, self->program); out: parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (st_scroll_view_fade_parent_class); parent->paint_target (effect); }
static void scroll_bar_allocate_children (StScrollBar *bar, const ClutterActorBox *box, ClutterAllocationFlags flags) { StScrollBarPrivate *priv = bar->priv; StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (bar)); ClutterActorBox content_box, trough_box; st_theme_node_get_content_box (theme_node, box, &content_box); if (priv->vertical) { trough_box.x1 = content_box.x1; trough_box.y1 = content_box.y1; trough_box.x2 = content_box.x2; trough_box.y2 = content_box.y2; clutter_actor_allocate (priv->trough, &trough_box, flags); } else { trough_box.x1 = content_box.x1; trough_box.y1 = content_box.y1; trough_box.x2 = content_box.x2; trough_box.y2 = content_box.y2; clutter_actor_allocate (priv->trough, &trough_box, flags); } if (priv->adjustment) { float handle_size, position, avail_size; gdouble value, lower, upper, page_size, increment, min_size, max_size; ClutterActorBox handle_box = { 0, }; st_adjustment_get_values (priv->adjustment, &value, &lower, &upper, NULL, NULL, &page_size); if ((upper == lower) || (page_size >= (upper - lower))) increment = 1.0; else increment = page_size / (upper - lower); min_size = 32.; st_theme_node_lookup_length (theme_node, "min-size", FALSE, &min_size); max_size = G_MAXINT16; st_theme_node_lookup_length (theme_node, "max-size", FALSE, &max_size); if (upper - lower - page_size <= 0) position = 0; else position = (value - lower) / (upper - lower - page_size); if (priv->vertical) { avail_size = content_box.y2 - content_box.y1; handle_size = increment * avail_size; handle_size = CLAMP (handle_size, min_size, max_size); handle_box.x1 = content_box.x1; handle_box.y1 = content_box.y1 + position * (avail_size - handle_size); handle_box.x2 = content_box.x2; handle_box.y2 = handle_box.y1 + handle_size; } else { avail_size = content_box.x2 - content_box.x1; handle_size = increment * avail_size; handle_size = CLAMP (handle_size, min_size, max_size); handle_box.x1 = content_box.x1 + position * (avail_size - handle_size); handle_box.y1 = content_box.y1; handle_box.x2 = handle_box.x1 + handle_size; handle_box.y2 = content_box.y2; } clutter_actor_allocate (priv->handle, &handle_box, flags); } }