mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
state-machine: made clutter_state_change take a boolean animate argument
Most of the time this will be TRUE, pass FALSE to change to the target state immediately.
This commit is contained in:
parent
54bd541270
commit
1dc8c0ff05
@ -397,98 +397,10 @@ static void clutter_state_new_frame (ClutterTimeline *timeline,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* clutter_state_change_noanim:
|
||||
* @state_name: a #ClutterState
|
||||
*
|
||||
* Change to @state_name and spend duration msecs when doing so.
|
||||
*
|
||||
* Return value: the #ClutterTimeline that drives the #ClutterState instance.
|
||||
*/
|
||||
ClutterTimeline *
|
||||
clutter_state_change_noanim (ClutterState *this,
|
||||
const gchar *target_state_name)
|
||||
{
|
||||
ClutterStatePrivate *priv = this->priv;
|
||||
State *state;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_STATE (this), NULL);
|
||||
g_return_val_if_fail (target_state_name, NULL);
|
||||
|
||||
if (target_state_name == NULL)
|
||||
target_state_name = "default";
|
||||
target_state_name = g_intern_string (target_state_name);
|
||||
if (priv->target_state_name == NULL)
|
||||
priv->target_state_name = g_intern_static_string ("default");
|
||||
|
||||
if (priv->current_animator)
|
||||
{
|
||||
clutter_animator_set_timeline (priv->current_animator, NULL);
|
||||
priv->current_animator = NULL;
|
||||
}
|
||||
|
||||
priv->source_state_name = priv->target_state_name;
|
||||
priv->target_state_name = target_state_name;
|
||||
|
||||
clutter_timeline_set_duration (priv->timeline, 1);
|
||||
|
||||
state = g_hash_table_lookup (priv->states, target_state_name);
|
||||
|
||||
g_return_val_if_fail (state, NULL);
|
||||
|
||||
{
|
||||
ClutterAnimator *animator;
|
||||
animator = clutter_state_get_animator (this, priv->source_state_name,
|
||||
priv->target_state_name);
|
||||
if (animator)
|
||||
{
|
||||
priv->current_animator = animator;
|
||||
clutter_animator_set_timeline (animator, priv->timeline);
|
||||
clutter_timeline_stop (priv->timeline);
|
||||
clutter_timeline_rewind (priv->timeline);
|
||||
clutter_timeline_start (priv->timeline);
|
||||
return priv->timeline;
|
||||
}
|
||||
}
|
||||
|
||||
if (state)
|
||||
{
|
||||
GList *k;
|
||||
|
||||
for (k = state->keys; k; k = k->next)
|
||||
{
|
||||
ClutterStateKey *key = k->data;
|
||||
GValue initial = {0,};
|
||||
|
||||
g_value_init (&initial,
|
||||
clutter_interval_get_value_type (key->interval));
|
||||
|
||||
g_object_get_property (key->object,
|
||||
key->property_name, &initial);
|
||||
if (clutter_alpha_get_mode (key->alpha) != key->mode)
|
||||
clutter_alpha_set_mode (key->alpha, key->mode);
|
||||
clutter_interval_set_initial_value (key->interval, &initial);
|
||||
clutter_interval_set_final_value (key->interval, &key->value);
|
||||
|
||||
g_value_unset (&initial);
|
||||
}
|
||||
|
||||
priv->target_state = state;
|
||||
clutter_timeline_rewind (priv->timeline);
|
||||
clutter_timeline_start (priv->timeline);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("Anim state '%s' not found\n", target_state_name);
|
||||
}
|
||||
|
||||
return priv->timeline;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* clutter_state_change:
|
||||
* @state_name: a #ClutterState
|
||||
* @animate: whether we should animate the transition or not.
|
||||
*
|
||||
* Change to @state_name and spend duration msecs when doing so.
|
||||
*
|
||||
@ -496,7 +408,8 @@ clutter_state_change_noanim (ClutterState *this,
|
||||
*/
|
||||
ClutterTimeline *
|
||||
clutter_state_change (ClutterState *this,
|
||||
const gchar *target_state_name)
|
||||
const gchar *target_state_name,
|
||||
gboolean animate)
|
||||
{
|
||||
ClutterStatePrivate *priv = this->priv;
|
||||
State *state;
|
||||
@ -528,9 +441,12 @@ clutter_state_change (ClutterState *this,
|
||||
priv->source_state_name = priv->target_state_name;
|
||||
priv->target_state_name = target_state_name;
|
||||
|
||||
clutter_timeline_set_duration (priv->timeline,
|
||||
clutter_state_get_duration (this, priv->source_state_name,
|
||||
priv->target_state_name));
|
||||
if (animate)
|
||||
clutter_timeline_set_duration (priv->timeline,
|
||||
clutter_state_get_duration (this, priv->source_state_name,
|
||||
priv->target_state_name));
|
||||
else
|
||||
clutter_timeline_set_duration (priv->timeline, 1);
|
||||
|
||||
state = g_hash_table_lookup (priv->states, target_state_name);
|
||||
|
||||
|
@ -93,13 +93,9 @@ GType clutter_state_get_type (void) G_GNUC_CONST;
|
||||
ClutterState *clutter_state_new (void);
|
||||
|
||||
|
||||
/* XXX: clutter_state_run?
|
||||
* the current (target?) transition should be a property of ClutterState
|
||||
*/
|
||||
ClutterTimeline * clutter_state_change (ClutterState *state,
|
||||
const gchar *target_transition_name);
|
||||
ClutterTimeline * clutter_state_change_noanim (ClutterState *state,
|
||||
const gchar *target_transition_name);
|
||||
const gchar *target_transition_name,
|
||||
gboolean animate);
|
||||
const gchar * clutter_state_get_target_state (ClutterState *state);
|
||||
ClutterState * clutter_state_set_key (ClutterState *state,
|
||||
const gchar *source_transition_name,
|
||||
|
@ -11,7 +11,7 @@ static gboolean press_event (ClutterActor *actor,
|
||||
gpointer user_data)
|
||||
{
|
||||
clutter_grab_pointer (actor);
|
||||
clutter_state_change (state, "end");
|
||||
clutter_state_change (state, "end", TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ static gboolean release_event (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
clutter_state_change (state, "start");
|
||||
clutter_state_change (state, "start", TRUE);
|
||||
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");
|
||||
clutter_state_change (state, "start", TRUE);
|
||||
|
||||
clutter_main ();
|
||||
g_object_unref (state);
|
||||
|
@ -10,7 +10,7 @@ static gboolean press_event (ClutterActor *actor,
|
||||
gpointer user_data)
|
||||
{
|
||||
clutter_grab_pointer (actor);
|
||||
clutter_state_change (state, "end");
|
||||
clutter_state_change (state, "end", TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -18,16 +18,16 @@ static gboolean release_event (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
clutter_state_change (state, "start");
|
||||
clutter_state_change (state, "start", TRUE);
|
||||
clutter_ungrab_pointer ();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void completed (ClutterState *state,
|
||||
static void completed (ClutterState *sstate,
|
||||
gpointer data)
|
||||
{
|
||||
g_print ("Completed transitioning to state: %s\n",
|
||||
clutter_state_get_target_state (state), data);
|
||||
clutter_state_get_target_state (sstate));
|
||||
}
|
||||
|
||||
static ClutterActor *new_rect (gint r,
|
||||
@ -95,7 +95,7 @@ test_state_main (gint argc,
|
||||
g_signal_connect (state, "completed", G_CALLBACK (completed), NULL);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
clutter_state_change (state, "start");
|
||||
clutter_state_change (state, "start", TRUE);
|
||||
|
||||
clutter_main ();
|
||||
g_object_unref (state);
|
||||
|
Loading…
Reference in New Issue
Block a user