From 9e730727ca3318067164121b52ed62d164884649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Wed, 7 Jul 2010 18:14:43 +0100 Subject: [PATCH] state: add clutter_state_set_state and clutter_state_warp_to_state Replaced clutter_state_change with a boolean argument for animating the transition or not with two separate argument-less methods. --- clutter/clutter-state.c | 61 +++++++++++++++------- clutter/clutter-state.h | 7 +-- doc/reference/clutter/clutter-sections.txt | 3 +- tests/interactive/test-state-animator.c | 6 +-- tests/interactive/test-state.c | 15 +++--- 5 files changed, 60 insertions(+), 32 deletions(-) diff --git a/clutter/clutter-state.c b/clutter/clutter-state.c index 47af79e32..46671ef8b 100644 --- a/clutter/clutter-state.c +++ b/clutter/clutter-state.c @@ -443,23 +443,7 @@ clutter_state_new_frame (ClutterTimeline *timeline, } -/** - * clutter_state_change: - * @state: a #ClutterState - * @target_state_name: the state to transition to - * @animate: whether we should animate the transition or not - * - * Change the current state of #ClutterState to @target_state_name - * - * If @animate is %FALSE, the state transition will happen immediately; - * otherwise, the state transition will be animated over the duration - * set using clutter_state_set_duration() - * - * Return value: the #ClutterTimeline that drives the state transition - * - * Since: 1.4 - */ -ClutterTimeline * +static ClutterTimeline * clutter_state_change (ClutterState *state, const gchar *target_state_name, gboolean animate) @@ -561,6 +545,47 @@ clutter_state_change (ClutterState *state, return priv->timeline; } +/** + * clutter_state_set_state: + * @state: a #ClutterState + * @target_state_name: the state to transition to + * + * Change the current state of #ClutterState to @target_state_name + * + * The state will animate during its transition, see + * #clutter_state_warp_to_state for animation-free state switching. + * + * Return value: the #ClutterTimeline that drives the state transition + * + * Since: 1.4 + */ +ClutterTimeline * +clutter_state_set_state (ClutterState *state, + const gchar *target_state_name) +{ + return clutter_state_change (state, target_state_name, FALSE); +} + +/** + * clutter_state_warp_to_state: + * @state: a #ClutterState + * @target_state_name: the state to transition to + * + * Change the current state of #ClutterState to @target_state_name + * + * Change to the specified target state immediately with no animation. + * + * Return value: the #ClutterTimeline that drives the state transition + * + * Since: 1.4 + */ +ClutterTimeline * +clutter_state_warp_to_state (ClutterState *state, + const gchar *target_state_name) +{ + return clutter_state_change (state, target_state_name, TRUE); +} + static GParamSpec * get_property_from_object (GObject *gobject, const gchar *property_name) @@ -1061,7 +1086,7 @@ clutter_state_set_property (GObject *object, switch (prop_id) { case PROP_STATE: - clutter_state_change (state, g_value_get_string (value), TRUE); + clutter_state_set_state (state, g_value_get_string (value)); break; case PROP_DURATION: state->priv->duration = g_value_get_uint (value); diff --git a/clutter/clutter-state.h b/clutter/clutter-state.h index c420bce65..414ea247e 100644 --- a/clutter/clutter-state.h +++ b/clutter/clutter-state.h @@ -91,9 +91,10 @@ GType clutter_state_get_type (void) G_GNUC_CONST; ClutterState *clutter_state_new (void); -ClutterTimeline * clutter_state_change (ClutterState *state, - const gchar *target_state_name, - gboolean animate); +ClutterTimeline * clutter_state_set_state (ClutterState *state, + const gchar *target_state_name); +ClutterTimeline * clutter_state_warp_to_state (ClutterState *state, + const gchar *target_state_name); ClutterState * clutter_state_set_key (ClutterState *state, const gchar *source_state_name, const gchar *target_state_name, diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 9679b96bf..41b22ea83 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -2250,8 +2250,9 @@ clutter_align_constraint_get_type ClutterState ClutterStateClass clutter_state_new -clutter_state_change +clutter_state_set_state clutter_state_get_state +clutter_state_warp_to_state clutter_state_set clutter_state_set_key clutter_state_set_duration diff --git a/tests/interactive/test-state-animator.c b/tests/interactive/test-state-animator.c index bdd88a91d..15aeb4279 100644 --- a/tests/interactive/test-state-animator.c +++ b/tests/interactive/test-state-animator.c @@ -11,7 +11,7 @@ static gboolean press_event (ClutterActor *actor, gpointer user_data) { clutter_grab_pointer (actor); - clutter_state_change (state, "end", TRUE); + clutter_state_set_state (state, "end"); return TRUE; } @@ -19,7 +19,7 @@ static gboolean release_event (ClutterActor *actor, ClutterEvent *event, gpointer user_data) { - clutter_state_change (state, "start", TRUE); + clutter_state_set_state (state, "start"); clutter_ungrab_pointer (); return TRUE; } @@ -125,7 +125,7 @@ test_state_animator_main (gint argc, g_object_unref (animator); clutter_actor_show (stage); - clutter_state_change (state, "start", TRUE); + clutter_state_set_state (state, "start"); clutter_main (); g_object_unref (state); diff --git a/tests/interactive/test-state.c b/tests/interactive/test-state.c index b45531556..630c4d450 100644 --- a/tests/interactive/test-state.c +++ b/tests/interactive/test-state.c @@ -19,7 +19,7 @@ static gboolean press_event (ClutterActor *actor, gpointer user_data) { ClutterState *state = CLUTTER_STATE (user_data); - clutter_state_change (state, "right", TRUE); + clutter_state_set_state (state, "right"); return TRUE; } @@ -28,7 +28,7 @@ static gboolean release_event (ClutterActor *actor, gpointer user_data) { ClutterState *state = CLUTTER_STATE (user_data); - clutter_state_change (state, "active", TRUE); + clutter_state_set_state (state, "active"); return TRUE; } @@ -37,7 +37,7 @@ static gboolean enter_event (ClutterActor *actor, gpointer user_data) { ClutterState *state = CLUTTER_STATE (user_data); - clutter_state_change (state, "hover", TRUE); + clutter_state_set_state (state, "hover"); return TRUE; } @@ -46,7 +46,7 @@ static gboolean leave_event (ClutterActor *actor, gpointer user_data) { ClutterState *state = CLUTTER_STATE (user_data); - clutter_state_change (state, "normal", TRUE); + clutter_state_set_state (state, "normal"); return TRUE; } @@ -59,7 +59,7 @@ static void completed (ClutterState *state, if (g_str_equal (clutter_state_get_state (state), "right")) { /* skip straight to left state when reaching right */ - clutter_state_change (state, "left", FALSE); + clutter_state_warp_to_state (state, "left"); } } @@ -177,8 +177,9 @@ test_state_main (gint argc, g_signal_connect (layout_state, "completed", G_CALLBACK (completed), NULL); clutter_actor_show (stage); - clutter_state_change (layout_state, "left", FALSE); - clutter_state_change (layout_state, "active", TRUE); + + clutter_state_warp_to_state (layout_state, "left"); + clutter_state_set_state (layout_state, "active"); clutter_main (); g_object_unref (layout_state);