static void next_state (ClutterState *transitions, gpointer user_data) { const gchar *state = clutter_state_get_state (transitions); if (g_strcmp0 (state, "right") == 0) clutter_state_set_state (transitions, "left"); else clutter_state_set_state (transitions, "right"); }
static gboolean button_pressed_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data) { ClutterState *transitions = CLUTTER_STATE (user_data); if (g_strcmp0 (clutter_state_get_state (transitions), "folded") == 0) clutter_state_set_state (transitions, "unfolded"); else clutter_state_set_state (transitions, "folded"); return TRUE; }
static void _set_next_state (ClutterState *transitions, gpointer user_data) { const gchar *current = clutter_state_get_state (transitions); gchar *next_state = "start"; if (g_strcmp0 (current, "start") == 0) next_state = "x-cw"; else if (g_strcmp0 (current, "x-cw") == 0) next_state = "x-ccw"; else if (g_strcmp0 (current, "x-ccw") == 0) next_state = "x-after"; else if (g_strcmp0 (current, "x-after") == 0) next_state = "y-cw"; else if (g_strcmp0 (current, "y-cw") == 0) next_state = "y-ccw"; else if (g_strcmp0 (current, "y-ccw") == 0) next_state = "y-after"; else if (g_strcmp0 (current, "y-after") == 0) next_state = "z-cw"; else if (g_strcmp0 (current, "z-cw") == 0) next_state = "z-ccw"; clutter_state_set_state (transitions, next_state); }
static gboolean leave_event (ClutterActor *actor, ClutterEvent *event, gpointer user_data) { ClutterState *state = CLUTTER_STATE (user_data); clutter_state_set_state (state, "normal"); return TRUE; }
static gboolean start_animation (ClutterActor *actor, ClutterEvent *event, gpointer user_data) { ClutterState *transitions = CLUTTER_STATE (user_data); clutter_state_set_state (transitions, "show-top"); return TRUE; }
static gboolean _pointer_enter_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data) { ClutterState *transitions = CLUTTER_STATE (user_data); clutter_state_set_state (transitions, "fade-in"); return TRUE; }
static void completed (ClutterState *state, gpointer data) { if (g_str_equal (clutter_state_get_state (state), "right")) { /* skip straight to left state when reaching right */ clutter_state_warp_to_state (state, "left"); } else if (g_str_equal (clutter_state_get_state (state), "active")) clutter_state_set_state (state, "right"); else { clutter_state_set_state (state, "active"); } times --; if (times <=0) clutter_main_quit (); }
static gboolean button_pressed_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data) { ClutterState *transitions = CLUTTER_STATE (user_data); /* set the state to the one with a name matching the actor's name */ clutter_state_set_state (transitions, clutter_actor_get_name (actor)); return TRUE; }
static void clutter_widget_init ( ClutterWidget *_self ) { ClutterWidgetPrivate *priv; ClutterAction *action; ClutterState *state; _self->priv = priv = CLUTTER_WIDGET_GET_PRIVATE (_self); priv->borderColor = *CLUTTER_COLOR_LightGray; clutter_actor_set_reactive ( CLUTTER_ACTOR(_self), TRUE ); // TODO: only in drag-bar { action = clutter_drag_action_new (); clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action), 0, 0); clutter_drag_action_set_drag_axis ( CLUTTER_DRAG_ACTION (action), CLUTTER_DRAG_X_AXIS&CLUTTER_DRAG_Y_AXIS ); g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL); g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL); clutter_actor_add_action (CLUTTER_ACTOR(_self), action); clutter_actor_add_effect_with_name (CLUTTER_ACTOR(_self), "disable", clutter_desaturate_effect_new (0.0)); // } TODO end // init state machine state = clutter_state_new (); g_object_set_data_full ( G_OBJECT (_self), "hover-state-machine", state, g_object_unref ); g_signal_connect ( _self, "enter-event", G_CALLBACK (on_enter), state ); g_signal_connect ( _self, "leave-event", G_CALLBACK (on_leave), state ); clutter_state_set ( state, NULL, "normal", _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_DarkGray, NULL ); clutter_state_set ( state, NULL, "hover", _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_LightSkyBlue, NULL ); clutter_state_set_duration ( state, NULL, NULL, 200 ); // set init state clutter_state_set_state (state, "normal"); }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *texture; ClutterState *transitions; GError *error = NULL; gfloat texture_width, texture_height; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); texture = clutter_texture_new (); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_texture_set_sync_size (CLUTTER_TEXTURE (texture), TRUE); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), TESTS_DATA_DIR "/redhand.png", &error); if (error != NULL) { g_error ("Problem loading image into texture - %s", error->message); g_error_free (error); return 1; } clutter_actor_get_size (texture, &texture_width, &texture_height); clutter_actor_set_size (stage, texture_width * 2, texture_height * 2); /* set all centres of rotation to the centre of the texture */ clutter_actor_set_rotation (texture, CLUTTER_X_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_rotation (texture, CLUTTER_Y_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_z_rotation_from_gravity (texture, 0.0, CLUTTER_GRAVITY_CENTER); clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture); /* set up the animations */ transitions = clutter_state_new (); clutter_state_set (transitions, NULL, "start", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-z", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "x-cw", texture, "rotation-angle-x", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-ccw", texture, "rotation-angle-x", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-after", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "y-cw", texture, "rotation-angle-y", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-ccw", texture, "rotation-angle-y", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-after", texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "z-cw", texture, "rotation-angle-z", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "z-ccw", texture, "rotation-angle-z", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set_duration (transitions, NULL, NULL, DURATION); clutter_state_set_duration (transitions, "start", NULL, DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "start", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "x-after", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "y-after", DURATION * 0.5); clutter_state_warp_to_state (transitions, "start"); g_signal_connect (transitions, "completed", G_CALLBACK (_set_next_state), NULL); clutter_state_set_state (transitions, "x-cw"); clutter_actor_show (stage); clutter_main (); return 0; }
G_MODULE_EXPORT gint test_state_main (gint argc, gchar **argv) { ClutterColor black={0,0,0,0xff}; ClutterActor *stage; ClutterState *layout_state; gint i; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); layout_state = clutter_state_new (); clutter_stage_set_color (CLUTTER_STAGE (stage), &black); clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); g_signal_connect (stage, "button-press-event", G_CALLBACK (press_event), layout_state); g_signal_connect (stage, "button-release-event", G_CALLBACK (release_event), layout_state); for (i=0; i<TOTAL; i++) { ClutterActor *actor; ClutterState *a_state; int row = i/COLS; int col = i%COLS; actor = new_rect (255 * ( 1.0*col/COLS), 50, 255 * ( 1.0*row/ROWS), 255); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); clutter_actor_set_position (actor, 320.0, 240.0); clutter_actor_set_reactive (actor, TRUE); clutter_state_set (layout_state, NULL, "active", actor, "delayed::x", CLUTTER_LINEAR, ACTOR_WIDTH * 1.0 * ((TOTAL-1-i) % COLS), ((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2, actor, "delayed::y", CLUTTER_LINEAR, ACTOR_HEIGHT * 1.0 * ((TOTAL-1-i) / COLS), ((row*1.0/ROWS))/2, 0.0, actor, "rotation-angle-x", CLUTTER_LINEAR, 0.0, actor, "rotation-angle-y", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (layout_state, NULL, "right", actor, "delayed::x", CLUTTER_LINEAR, STAGE_WIDTH * 1.0, ((row*1.0/ROWS))/2, (1.0-(row*1.0/ROWS))/2, actor, "delayed::y", CLUTTER_LINEAR, STAGE_HEIGHT * 1.0, ((row*1.0/ROWS))/2, 0.0, NULL); clutter_state_set (layout_state, NULL, "left", actor, "rotation-angle-x", CLUTTER_LINEAR, 45.0, actor, "rotation-angle-y", CLUTTER_LINEAR, 5.0, actor, "x", CLUTTER_LINEAR, 0-64.0, actor, "y", CLUTTER_LINEAR, 0-64.0, NULL); a_state = clutter_state_new (); g_object_set_data_full (G_OBJECT (actor), "hover-state-machine", a_state, g_object_unref); g_signal_connect (actor, "enter-event", G_CALLBACK (enter_event), a_state); g_signal_connect (actor, "leave-event", G_CALLBACK (leave_event), a_state); clutter_state_set (a_state, NULL, "normal", actor, "opacity", CLUTTER_LINEAR, 0x77, actor, "rotation-angle-z", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (a_state, NULL, "hover", actor, "opacity", CLUTTER_LINEAR, 0xff, actor, "rotation-angle-z", CLUTTER_LINEAR, 10.0, NULL); clutter_actor_set_opacity (actor, 0x77); clutter_state_set_duration (a_state, NULL, NULL, 500); } clutter_state_set_duration (layout_state, NULL, NULL, 1000); clutter_state_set_duration (layout_state, "active", "left", 1400); g_signal_connect (layout_state, "completed", G_CALLBACK (completed), NULL); clutter_actor_show (stage); clutter_state_warp_to_state (layout_state, "left"); clutter_state_set_state (layout_state, "active"); clutter_main (); g_object_unref (layout_state); return EXIT_SUCCESS; }
static gboolean on_leave ( ClutterActor *_actor, ClutterEvent *_event, gpointer _user_data ) { ClutterState *state = CLUTTER_STATE (_user_data); clutter_state_set_state (state, "normal"); return TRUE; }