static gboolean handle_button_press_event_cb (ClutterActor *actor, ClutterButtonEvent *event, StScrollBar *bar) { StScrollBarPrivate *priv = bar->priv; if (event->button != 1) return FALSE; if (!clutter_actor_transform_stage_point (priv->handle, event->x, event->y, &priv->x_origin, &priv->y_origin)) return FALSE; /* Account for the scrollbar-trough-handle nesting. */ priv->x_origin += clutter_actor_get_x (priv->trough); priv->y_origin += clutter_actor_get_y (priv->trough); /* Turn off picking for motion events */ clutter_set_motion_events_enabled (FALSE); priv->capture_handler = g_signal_connect_after ( clutter_actor_get_stage (priv->trough), "captured-event", G_CALLBACK (handle_capture_event_cb), bar); g_signal_emit (bar, signals[SCROLL_START], 0); return TRUE; }
static gboolean handle_button_press_event_cb (ClutterActor *actor, ClutterButtonEvent *event, StScrollBar *bar) { StScrollBarPrivate *priv = bar->priv; if (event->button != 1) return FALSE; if (!clutter_actor_transform_stage_point (priv->handle, event->x, event->y, &priv->x_origin, &priv->y_origin)) return FALSE; /* Account for the scrollbar-trough-handle nesting. */ priv->x_origin += clutter_actor_get_x (priv->trough); priv->y_origin += clutter_actor_get_y (priv->trough); g_assert (!priv->grabbed); clutter_grab_pointer (priv->handle); priv->grabbed = TRUE; g_signal_emit (bar, signals[SCROLL_START], 0); return TRUE; }
void on_timeline_move_new_frame(ClutterTimeline * timeline, gint frame_num, gpointer data) { gint x_position = clutter_actor_get_x(rect); if((++x_position) >= 150) x_position = 0; clutter_actor_set_x(rect, x_position); }
/* Dump actors */ static void _xfdashboard_dump_actor_internal(ClutterActor *inActor, gint inLevel) { ClutterActorIter iter; ClutterActor *child; gint i; g_return_if_fail(CLUTTER_IS_ACTOR(inActor)); g_return_if_fail(inLevel>=0); clutter_actor_iter_init(&iter, CLUTTER_ACTOR(inActor)); while(clutter_actor_iter_next(&iter, &child)) { for(i=0; i<inLevel; i++) g_print(" "); g_print("+- %s@%p - name: %s - geometry: %.2f,%.2f [%.2fx%.2f], mapped: %s, visible: %s, children: %d\n", G_OBJECT_TYPE_NAME(child), child, clutter_actor_get_name(child), clutter_actor_get_x(child), clutter_actor_get_y(child), clutter_actor_get_width(child), clutter_actor_get_height(child), clutter_actor_is_mapped(child) ? "yes" : "no", clutter_actor_is_visible(child) ? "yes" : "no", clutter_actor_get_n_children(child)); if(clutter_actor_get_n_children(child)>0) _xfdashboard_dump_actor_internal(child, inLevel+1); } }
static void move_handle (MxSlider *bar, gfloat x, gfloat y) { MxSliderPrivate *priv = bar->priv; gdouble value; gfloat ux, pos, fill_size; if (!clutter_actor_transform_stage_point (CLUTTER_ACTOR (bar), x, y, &ux, NULL)) { return; } priv->x_origin = priv->handle_width / 2 + clutter_actor_get_x (priv->trough); fill_size = priv->handle_middle_end - priv->handle_middle_start; pos = ux - priv->handle_middle_start; pos = CLAMP (pos, 0, fill_size); value = pos / fill_size; mx_slider_set_value (bar, value); }
static void clutter_bind_constraint_update_allocation (ClutterConstraint *constraint, ClutterActor *actor, ClutterActorBox *allocation) { ClutterBindConstraint *bind = CLUTTER_BIND_CONSTRAINT (constraint); gfloat source_width, source_height; gfloat actor_width, actor_height; ClutterVertex source_position = { 0., }; if (bind->source == NULL) return; source_position.x = clutter_actor_get_x (bind->source); source_position.y = clutter_actor_get_y (bind->source); clutter_actor_get_size (bind->source, &source_width, &source_height); clutter_actor_box_get_size (allocation, &actor_width, &actor_height); switch (bind->coordinate) { case CLUTTER_BIND_X: allocation->x1 = source_position.x + bind->offset; allocation->x2 = allocation->x1 + actor_width; break; case CLUTTER_BIND_Y: allocation->y1 = source_position.y + bind->offset; allocation->y2 = allocation->y1 + actor_height; break; case CLUTTER_BIND_POSITION: allocation->x1 = source_position.x + bind->offset; allocation->y1 = source_position.y + bind->offset; allocation->x2 = allocation->x1 + actor_width; allocation->y2 = allocation->y1 + actor_height; break; case CLUTTER_BIND_WIDTH: allocation->x2 = allocation->x1 + source_width + bind->offset; break; case CLUTTER_BIND_HEIGHT: allocation->y2 = allocation->y1 + source_height + bind->offset; break; case CLUTTER_BIND_SIZE: allocation->x2 = allocation->x1 + source_width + bind->offset; allocation->y2 = allocation->y1 + source_height + bind->offset; break; default: g_assert_not_reached (); break; } }
static gboolean button_press_color_cb(ClutterActor *actor, ClutterEvent *event, gpointer user_data) { App *app = (App *) user_data; ClutterColor color; clutter_rectangle_get_color(CLUTTER_RECTANGLE(actor), &color); int r = color.red; int g = color.green; int b = color.blue; app->setColor(r, g, b); app->setSelectionPosition(clutter_actor_get_x(actor), clutter_actor_get_y(actor)); return TRUE; // handled. Do not propagate to stage }
gboolean foo_button_pressed_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data) { ClutterScript *ui = CLUTTER_SCRIPT (user_data); ClutterStage *stage = CLUTTER_STAGE (clutter_script_get_object (ui, "stage")); ClutterScript *script; ClutterActor *rig; ClutterAnimator *animator; /* load the rig and its animator from a JSON file */ script = clutter_script_new (); /* use a function defined statically in this source file to load the JSON */ load_script_from_file (script, ANIMATION_FILE); clutter_script_get_objects (script, "rig", &rig, "animator", &animator, NULL); /* remove the button press handler from the rectangle */ g_signal_handlers_disconnect_matched (actor, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, foo_button_pressed_cb, NULL); /* add a callback to clean up the script when the rig is destroyed */ g_object_set_data_full (G_OBJECT (rig), "script", script, g_object_unref); /* add the rig to the stage */ clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig); /* place the rig at the same coordinates on the stage as the rectangle */ clutter_actor_set_position (rig, clutter_actor_get_x (actor), clutter_actor_get_y (actor)); /* put the rectangle into the top-left corner of the rig */ clutter_actor_reparent (actor, rig); clutter_actor_set_position (actor, 0, 0); /* animate the rig */ clutter_animator_start (animator); return TRUE; }
static void clutter_bin_layout_allocate (ClutterLayoutManager *manager, ClutterContainer *container, const ClutterActorBox *allocation, ClutterAllocationFlags flags) { GList *children = clutter_container_get_children (container); GList *l; gfloat available_w, available_h; available_w = clutter_actor_box_get_width (allocation); available_h = clutter_actor_box_get_height (allocation); for (l = children; l != NULL; l = l->next) { ClutterActor *child = l->data; ClutterLayoutMeta *meta; ClutterBinLayer *layer; ClutterActorBox child_alloc = { 0, }; gdouble x_align, y_align; gboolean x_fill, y_fill; meta = clutter_layout_manager_get_child_meta (manager, container, child); layer = CLUTTER_BIN_LAYER (meta); if (layer->x_align == CLUTTER_BIN_ALIGNMENT_FIXED) child_alloc.x1 = clutter_actor_get_x (child); else child_alloc.x1 = 0.0f; if (layer->y_align == CLUTTER_BIN_ALIGNMENT_FIXED) child_alloc.y1 = clutter_actor_get_y (child); else child_alloc.y1 = 0.0f; child_alloc.x2 = available_w; child_alloc.y2 = available_h; x_fill = (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL); y_fill = (layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL); x_align = get_bin_alignment_factor (layer->x_align); y_align = get_bin_alignment_factor (layer->y_align); clutter_actor_allocate_align_fill (child, &child_alloc, x_align, y_align, x_fill, y_fill, flags); } g_list_free (children); }
void App::createPalette() { ClutterColor white = { 255, 255, 255, 255 }; selection_rect_ = clutter_rectangle_new_with_color(&white); clutter_actor_set_size(selection_rect_, 55.0f, 55.0f); clutter_actor_set_anchor_point_from_gravity(selection_rect_, CLUTTER_GRAVITY_CENTER); clutter_container_add_actor(CLUTTER_CONTAINER(stage_), selection_rect_); std::vector<std::string> colors; colors.push_back(std::string("#c33")); // red colors.push_back(std::string("#cc3")); colors.push_back(std::string("#3c3")); // green colors.push_back(std::string("#3cc")); colors.push_back(std::string("#33c")); // blue colors.push_back(std::string("#c3c")); colors.push_back(std::string("#333")); // black colors.push_back(std::string("#999")); colors.push_back(std::string("#ccc")); // initial color: ClutterColor chosen; clutter_color_from_string(&chosen, (*colors.begin()).c_str()); setColor(chosen.red, chosen.green, chosen.blue); int i = 0; std::vector<std::string>::iterator iter; for (iter = colors.begin(); iter != colors.end(); ++iter) { ClutterColor color; clutter_color_from_string(&color, (*iter).c_str()); ClutterActor *rect = clutter_rectangle_new_with_color(&color); clutter_actor_set_size(rect, 50.0f, 50.0f); clutter_actor_set_anchor_point_from_gravity(rect, CLUTTER_GRAVITY_CENTER); clutter_actor_set_position(rect, 35.0f, i * 60.0f + 30.0f); clutter_actor_set_reactive(rect, TRUE); clutter_container_add_actor(CLUTTER_CONTAINER(stage_), rect); g_signal_connect(rect, "button-press-event", G_CALLBACK(button_press_color_cb), this); if (i == 0) { float x = clutter_actor_get_x(rect); float y = clutter_actor_get_y(rect); setSelectionPosition(x, y); } ++i; } }
/* add keys to the animator such that the actor is moved * to a random x position */ static void add_keys_for_actor (ClutterActor *actor, ClutterAnimator *animator) { gfloat x, end_x; x = clutter_actor_get_x (actor); end_x = 50.0; if (x == 50.0) end_x = 225.0 + (100.0 * rand () / (RAND_MAX + 1.0)); clutter_animator_set (animator, actor, "x", CLUTTER_LINEAR, 0.0, x, actor, "x", CLUTTER_EASE_OUT_CUBIC, 1.0, end_x, NULL); }
static void key_focus_in_cb (ClutterActor *actor, gpointer data) { ClutterActor *focus_box = CLUTTER_ACTOR (data); if (CLUTTER_IS_STAGE (actor)) clutter_actor_hide (focus_box); else { clutter_actor_set_position (focus_box, clutter_actor_get_x (actor) - 5, clutter_actor_get_y (actor) - 5); clutter_actor_set_size (focus_box, clutter_actor_get_width (actor) + 10, clutter_actor_get_height (actor) + 10); clutter_actor_show (focus_box); } }
static void clutter_fixed_layout_get_preferred_width (ClutterLayoutManager *manager, ClutterContainer *container, gfloat for_height, gfloat *min_width_p, gfloat *nat_width_p) { ClutterActor *actor, *child; gdouble min_right; gdouble natural_right; min_right = 0; natural_right = 0; actor = CLUTTER_ACTOR (container); for (child = clutter_actor_get_first_child (actor); child != NULL; child = clutter_actor_get_next_sibling (child)) { gfloat child_x, child_min, child_natural; child_x = clutter_actor_get_x (child); clutter_actor_get_preferred_size (child, &child_min, NULL, &child_natural, NULL); if (child_x + child_min > min_right) min_right = child_x + child_min; if (child_x + child_natural > natural_right) natural_right = child_x + child_natural; } if (min_width_p) *min_width_p = min_right; if (nat_width_p) *nat_width_p = natural_right; }
//FIXME: ClutterClone seems to have problem rendering children, so badges are stay in grandpar static void create_window_badge(MosesOverview* self, ClutterActor* parent, int order) { ClutterActor* badge = clutter_actor_new(); clutter_actor_insert_child_above(clutter_actor_get_parent(parent), badge, NULL); gfloat tw, th; clutter_actor_get_transformed_size(parent, &tw, &th); gfloat w = 60.0, h = 60.0, x = (tw - w) / 2.0 + clutter_actor_get_x(parent), y = (th - h) / 2.0 + clutter_actor_get_y(parent); clutter_actor_set_position(badge, x, y); clutter_actor_set_size(badge, w, h); g_object_set_qdata(G_OBJECT(badge), moses_overview_window_clone_order(), GINT_TO_POINTER(order)); g_object_set_qdata(G_OBJECT(parent), moses_overview_window_clone_order(), GINT_TO_POINTER(order)); ClutterContent* canvas = clutter_canvas_new(); clutter_canvas_set_size(CLUTTER_CANVAS(canvas), w, h); clutter_actor_set_content(badge, canvas); g_object_unref(canvas); g_signal_connect(canvas, "draw", G_CALLBACK(on_badge_draw), badge); clutter_content_invalidate(canvas); clutter_actor_set_scale(badge, 0.0, 0.0); //do animated show clutter_actor_save_easing_state(badge); clutter_actor_set_easing_mode(badge, CLUTTER_EASE_OUT_BACK); clutter_actor_set_easing_duration(badge, 350); clutter_actor_set_pivot_point(badge, 0.5, 0.5); clutter_actor_set_scale(badge, 1.0, 1.0); clutter_actor_restore_easing_state(badge); g_ptr_array_add(self->priv->badges, badge); }
static gboolean on_handle_button_press_event (ClutterActor *actor, ClutterButtonEvent *event, MxSlider *bar) { MxSliderPrivate *priv = bar->priv; ClutterActor *stage; if (mx_widget_get_disabled (MX_WIDGET (actor))) return FALSE; if (event->button != 1) return FALSE; if (!clutter_actor_transform_stage_point (priv->handle, event->x, event->y, &priv->x_origin, NULL)) return FALSE; g_signal_emit (bar, signals[SLIDE_START], 0); /* Account for the scrollbar-trough-handle nesting. */ priv->x_origin += clutter_actor_get_x (priv->trough); /* Turn off picking for motion events */ stage = clutter_actor_get_stage (priv->trough); clutter_stage_set_motion_events_enabled (CLUTTER_STAGE (stage), FALSE); priv->capture_handler = g_signal_connect_after (stage, "captured-event", G_CALLBACK (on_handle_capture_event), bar); return FALSE; }
static gboolean trough_paging_cb (MxScrollBar *self) { gfloat handle_pos, event_pos, tx, ty; gdouble value; gdouble page_increment; gboolean ret; gulong mode; 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 */ mx_adjustment_get_values (self->priv->adjustment, &value, NULL, NULL, NULL, &page_increment, NULL); if (self->priv->orientation == MX_ORIENTATION_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->orientation == MX_ORIENTATION_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; } mx_adjustment_interpolate (self->priv->adjustment, value, 250, mode); return ret; }
/* snap size, as affected by resizing lower right corner, * will need extension if other corners are to be supported, * it seems possible to do all needed alignments through * simple workarounds when only snapping for lower right). */ static void snap_size (ClutterActor *actor, gfloat in_width, gfloat in_height, gfloat *out_width, gfloat *out_height) { *out_width = in_width; *out_height = in_height; ClutterActor *parent; parent = clutter_actor_get_parent (actor); if (CLUTTER_IS_CONTAINER (parent)) { gfloat in_x = clutter_actor_get_x (actor); gfloat in_y = clutter_actor_get_y (actor); gfloat in_end_x = in_x + in_width; gfloat in_end_y = in_y + in_height; gfloat best_x = 0; gfloat best_x_diff = 4096; gfloat best_y = 0; gfloat best_y_diff = 4096; GList *children, *c; children = clutter_container_get_children (CLUTTER_CONTAINER (parent)); hor_pos = 0; ver_pos = 0; /* We only search our siblings for snapping... * perhaps we should search more. */ for (c=children; c; c = c->next) { gfloat this_x = clutter_actor_get_x (c->data); gfloat this_width = clutter_actor_get_width (c->data); gfloat this_height = clutter_actor_get_height (c->data); gfloat this_end_x = this_x + this_width; gfloat this_y = clutter_actor_get_y (c->data); gfloat this_end_y = this_y + this_height; /* skip self */ if (c->data == actor) continue; /* end aligned with start this_x this_mid_x this_end_x in_x in_mid_x in_end_x */ if (abs (this_x - in_end_x) < best_x_diff) { best_x_diff = abs (this_x - in_end_x); best_x = this_x; hor_pos=3; } if (abs (this_y - in_end_y) < best_y_diff) { best_y_diff = abs (this_y - in_end_y); best_y = this_y; ver_pos=3; } /* ends aligned this_x this_mid_x this_end_x in_x in_mid_x in_end_x */ if (abs (this_end_x - in_end_x) < best_x_diff) { best_x_diff = abs (this_end_x - in_end_x); best_x = this_end_x; hor_pos=3; } if (abs (this_end_y - in_end_y) < best_y_diff) { best_y_diff = abs (this_end_y - in_end_y); best_y = this_end_y; ver_pos=3; } } { if (best_x_diff < SNAP_THRESHOLD) { *out_width = best_x-in_x; } else { hor_pos = 0; } if (best_y_diff < SNAP_THRESHOLD) { *out_height = best_y-in_y; } else { ver_pos = 0; } } } }
IO_METHOD(IoClutterActor, getX) { return IONUMBER(clutter_actor_get_x(IOCACTOR(self))); }
G_MODULE_EXPORT int test_scale_main (int argc, char *argv[]) { ClutterActor *stage, *rect; ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *behave; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Scaling"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); clutter_actor_set_size (stage, 300, 300); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (rect, 100, 100); clutter_actor_set_position (rect, 100, 100); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); label = clutter_text_new_with_text ("Sans 20px", ""); clutter_text_set_color (CLUTTER_TEXT (label), CLUTTER_COLOR_White); clutter_actor_set_position (label, clutter_actor_get_x (rect), clutter_actor_get_y (rect) + clutter_actor_get_height (rect)); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); rect_color.alpha = 0xff; rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_position (rect, 100, 100); clutter_actor_set_size (rect, 100, 100); set_next_gravity (rect); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); timeline = clutter_timeline_new (750); alpha = clutter_alpha_new_with_func (timeline, my_ramp_func, NULL, NULL); behave = clutter_behaviour_scale_new (alpha, 0.0, 0.0, /* scale start */ 1.0, 1.0); /* scale end */ clutter_behaviour_apply (behave, rect); clutter_timeline_set_repeat_count (timeline, -1); g_signal_connect_swapped (timeline, "completed", G_CALLBACK (set_next_gravity), rect); clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (timeline); g_object_unref (behave); return EXIT_SUCCESS; }
/* Private functions */ static void ensure_layout (AstroAppview *view) { AstroAppviewPrivate *priv; GList *l; gint groupx = 0; gint center = 0; gint i = 0; priv = view->priv; groupx = clutter_actor_get_x (CLUTTER_ACTOR (view)); center = CSW()/2; l = clutter_container_get_children (CLUTTER_CONTAINER (view)); for (l = l; l; l = l->next) { ClutterActor *icon = l->data; gint realx, diff, y_diff;; gfloat scale; realx = clutter_actor_get_x (icon) + groupx; if (realx > center && realx < CSW ()) { diff = center - (realx - center); } else if (realx > 0 && realx <= center) { diff = realx; } else { diff = 0; } scale = (gfloat)diff/center; scale = 0.2 + (0.8 * scale); clutter_actor_set_scale (icon, scale, scale); if (realx < center) { gfloat angle, sine; angle = scale * (3.14*2); sine = sin (0.5 *angle); y_diff = (CSH()/2) + (VARIANCE * sine); } else { gfloat angle, sine; angle = scale * (3.14*2); sine = sin (0.5*angle); y_diff = (CSH()/2) - (VARIANCE * sine); } clutter_actor_set_y (icon, y_diff); astro_appicon_set_blur (ASTRO_APPICON (icon), (1.0 - scale) * MAX_BLUR); i++; } }
G_MODULE_EXPORT int test_scale_main (int argc, char *argv[]) { ClutterActor *stage, *rect; ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; ClutterColor white_color = { 0xff, 0xff, 0xff, 0xFF }; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *behave; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_actor_set_size (stage, 300, 300); rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (rect, 100, 100); clutter_actor_set_position (rect, 100, 100); clutter_group_add (CLUTTER_GROUP (stage), rect); label = clutter_text_new_with_text ("Sans 20px", ""); clutter_text_set_color (CLUTTER_TEXT (label), &white_color); clutter_actor_set_position (label, clutter_actor_get_x (rect), clutter_actor_get_y (rect) + clutter_actor_get_height (rect)); clutter_group_add (CLUTTER_GROUP (stage), label); rect_color.alpha = 0xff; rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_position (rect, 100, 100); clutter_actor_set_size (rect, 100, 100); set_next_gravity (rect); clutter_group_add (CLUTTER_GROUP (stage), rect); timeline = clutter_timeline_new (750); alpha = clutter_alpha_new_with_func (timeline, my_ramp_func, NULL, NULL); behave = clutter_behaviour_scale_new (alpha, 0.0, 0.0, /* scale start */ 1.0, 1.0); /* scale end */ clutter_behaviour_apply (behave, rect); clutter_timeline_set_loop (timeline, TRUE); g_signal_connect_swapped (timeline, "completed", G_CALLBACK (set_next_gravity), rect); clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (timeline); g_object_unref (behave); return EXIT_SUCCESS; }
static void clutter_bin_layout_allocate (ClutterLayoutManager *manager, ClutterContainer *container, const ClutterActorBox *allocation, ClutterAllocationFlags flags) { gfloat allocation_x, allocation_y; gfloat available_w, available_h; ClutterActor *actor, *child; ClutterActorIter iter; gboolean use_animations; ClutterAnimationMode easing_mode; guint easing_duration, easing_delay; clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y); clutter_actor_box_get_size (allocation, &available_w, &available_h); actor = CLUTTER_ACTOR (container); use_animations = clutter_layout_manager_get_easing_state (manager, &easing_mode, &easing_duration, &easing_delay); clutter_actor_iter_init (&iter, actor); while (clutter_actor_iter_next (&iter, &child)) { ClutterLayoutMeta *meta; ClutterBinLayer *layer; ClutterActorBox child_alloc = { 0, }; gdouble x_align, y_align; gboolean x_fill, y_fill; meta = clutter_layout_manager_get_child_meta (manager, container, child); layer = CLUTTER_BIN_LAYER (meta); if (layer->x_align == CLUTTER_BIN_ALIGNMENT_FIXED) child_alloc.x1 = clutter_actor_get_x (child); else child_alloc.x1 = allocation_x; if (layer->y_align == CLUTTER_BIN_ALIGNMENT_FIXED) child_alloc.y1 = clutter_actor_get_y (child); else child_alloc.y1 = allocation_y; child_alloc.x2 = available_w; child_alloc.y2 = available_h; if (clutter_actor_needs_expand (child, CLUTTER_ORIENTATION_HORIZONTAL)) { ClutterActorAlign align; align = _clutter_actor_get_effective_x_align (child); x_fill = align == CLUTTER_ACTOR_ALIGN_FILL; x_align = get_actor_align_factor (align); } else { x_fill = (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL); x_align = get_bin_alignment_factor (layer->x_align); } if (clutter_actor_needs_expand (child, CLUTTER_ORIENTATION_VERTICAL)) { ClutterActorAlign align; align = clutter_actor_get_y_align (child); y_fill = align == CLUTTER_ACTOR_ALIGN_FILL; y_align = get_actor_align_factor (align); } else { y_fill = (layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL); y_align = get_bin_alignment_factor (layer->y_align); } if (use_animations) { clutter_actor_save_easing_state (child); clutter_actor_set_easing_mode (child, easing_mode); clutter_actor_set_easing_duration (child, easing_duration); clutter_actor_set_easing_delay (child, easing_delay); } clutter_actor_allocate_align_fill (child, &child_alloc, x_align, y_align, x_fill, y_fill, flags); if (use_animations) clutter_actor_restore_easing_state (child); } }
void scroll_view_main (ClutterContainer *stage) { gint width, height; MxAdjustment *hadjust, *vadjust; ClutterActor *label, *elastic, *overshoot, *scroll, *kinetic, *view, *texture; scroll = mx_scroll_view_new (); /* Make sure something underneath the kinetic scroll view swallows events * so that we don't end up moving the window. */ g_signal_connect (scroll, "button-press-event", G_CALLBACK (true_cb), NULL); kinetic = mx_kinetic_scroll_view_new (); clutter_container_add_actor (stage, scroll); clutter_actor_set_position (scroll, 10, 10); clutter_actor_set_size (scroll, 300, 300); view = mx_viewport_new (); mx_viewport_set_sync_adjustments (MX_VIEWPORT (view), FALSE); clutter_container_add_actor (CLUTTER_CONTAINER (kinetic), view); clutter_container_add_actor (CLUTTER_CONTAINER (scroll), kinetic); texture = clutter_texture_new_from_file ("redhand.png", NULL); clutter_container_add_actor (CLUTTER_CONTAINER (view), texture); g_object_set (texture, "repeat-x", TRUE, "repeat-y", TRUE, NULL); clutter_actor_set_size (texture, 1280, 1280); clutter_texture_get_base_size (CLUTTER_TEXTURE (texture), &width, &height); mx_scrollable_get_adjustments (MX_SCROLLABLE (view), &hadjust, &vadjust); mx_adjustment_set_values (hadjust, 0, 0, 1280, width, width * 3, 300); mx_adjustment_set_values (vadjust, 0, 0, 1280, height, height * 3, 300); label = mx_label_new_with_text ("Toggle over-shooting:"); overshoot = mx_toggle_new (); clutter_actor_set_position (label, 320, 10); clutter_actor_set_position (overshoot, 330 + clutter_actor_get_width (label), 10); clutter_container_add (stage, label, overshoot, NULL); g_signal_connect (overshoot, "notify::active", G_CALLBACK (notify_overshoot_cb), kinetic); label = mx_label_new_with_text ("Toggle elasticity:"); elastic = mx_toggle_new (); clutter_actor_set_position (label, 320, 20 + clutter_actor_get_height (overshoot)); clutter_actor_set_position (elastic, clutter_actor_get_x (overshoot), clutter_actor_get_y (label)); clutter_container_add (stage, label, elastic, NULL); g_signal_connect (elastic, "notify::active", G_CALLBACK (notify_elastic_cb), kinetic); }
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 clutter_bin_layout_allocate (ClutterLayoutManager *manager, ClutterContainer *container, const ClutterActorBox *allocation, ClutterAllocationFlags flags) { gfloat allocation_x, allocation_y; gfloat available_w, available_h; ClutterActor *actor, *child; ClutterActorIter iter; clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y); clutter_actor_box_get_size (allocation, &available_w, &available_h); actor = CLUTTER_ACTOR (container); clutter_actor_iter_init (&iter, actor); while (clutter_actor_iter_next (&iter, &child)) { ClutterLayoutMeta *meta; ClutterBinLayer *layer; ClutterActorBox child_alloc = { 0, }; gdouble x_align, y_align; gboolean x_fill, y_fill, is_fixed_position_set; float fixed_x, fixed_y; if (!clutter_actor_is_visible (child)) continue; meta = clutter_layout_manager_get_child_meta (manager, container, child); layer = CLUTTER_BIN_LAYER (meta); fixed_x = fixed_y = 0.f; g_object_get (child, "fixed-position-set", &is_fixed_position_set, "fixed-x", &fixed_x, "fixed-y", &fixed_y, NULL); /* XXX:2.0 - remove the FIXED alignment, and just use the fixed position * of the actor if one is set */ if (is_fixed_position_set || layer->x_align == CLUTTER_BIN_ALIGNMENT_FIXED) { if (is_fixed_position_set) child_alloc.x1 = fixed_x; else child_alloc.x1 = clutter_actor_get_x (child); } else child_alloc.x1 = allocation_x; if (is_fixed_position_set || layer->y_align == CLUTTER_BIN_ALIGNMENT_FIXED) { if (is_fixed_position_set) child_alloc.y1 = fixed_y; else child_alloc.y1 = clutter_actor_get_y (child); } else child_alloc.y1 = allocation_y; child_alloc.x2 = allocation_x + available_w; child_alloc.y2 = allocation_y + available_h; if (clutter_actor_needs_expand (child, CLUTTER_ORIENTATION_HORIZONTAL)) { ClutterActorAlign align; align = clutter_actor_get_x_align (child); x_fill = align == CLUTTER_ACTOR_ALIGN_FILL; x_align = get_actor_align_factor (align); } else { ClutterTextDirection text_dir; x_fill = (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL); text_dir = clutter_actor_get_text_direction (child); if (!is_fixed_position_set) x_align = get_bin_alignment_factor (layer->x_align, text_dir); else x_align = 0.0; } if (clutter_actor_needs_expand (child, CLUTTER_ORIENTATION_VERTICAL)) { ClutterActorAlign align; align = clutter_actor_get_y_align (child); y_fill = align == CLUTTER_ACTOR_ALIGN_FILL; y_align = get_actor_align_factor (align); } else { y_fill = (layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL); if (!is_fixed_position_set) y_align = get_bin_alignment_factor (layer->y_align, CLUTTER_TEXT_DIRECTION_LTR); else y_align = 0.0; } clutter_actor_allocate_align_fill (child, &child_alloc, x_align, y_align, x_fill, y_fill, flags); } }