script: Allow warping to states

Do not just allow animating states connected to signals: add a "warp"
optional key that ends up calling clutter_state_warp_to_state(). This
is useful for debugging.
This commit is contained in:
Emmanuele Bassi 2011-06-13 13:07:04 +01:00
parent 3017a48228
commit a9dd5abfcc
3 changed files with 32 additions and 6 deletions

View File

@ -597,6 +597,7 @@ parse_signals (ClutterScript *script,
{ {
const gchar *state = NULL; const gchar *state = NULL;
const gchar *target = NULL; const gchar *target = NULL;
gboolean warp_to = FALSE;
target = json_object_get_string_member (object, "target-state"); target = json_object_get_string_member (object, "target-state");
if (target == NULL) if (target == NULL)
@ -610,16 +611,21 @@ parse_signals (ClutterScript *script,
if (json_object_has_member (object, "states")) if (json_object_has_member (object, "states"))
state = json_object_get_string_member (object, "states"); state = json_object_get_string_member (object, "states");
if (json_object_has_member (object, "warp"))
warp_to = json_object_get_boolean_member (object, "warp");
CLUTTER_NOTE (SCRIPT, CLUTTER_NOTE (SCRIPT,
"Added signal '%s' (states:%s, target-state:%s)", "Added signal '%s' (states:%s, target-state:%s, warp:%s)",
name, name,
state != NULL ? state : "<default>", target); state != NULL ? state : "<default>", target,
warp_to ? "true" : "false");
sinfo = g_slice_new0 (SignalInfo); sinfo = g_slice_new0 (SignalInfo);
sinfo->is_handler = FALSE; sinfo->is_handler = FALSE;
sinfo->name = g_strdup (name); sinfo->name = g_strdup (name);
sinfo->state = g_strdup (state); sinfo->state = g_strdup (state);
sinfo->target = g_strdup (target); sinfo->target = g_strdup (target);
sinfo->warp_to = warp_to;
} }
else if (json_object_has_member (object, "handler")) else if (json_object_has_member (object, "handler"))
{ {

View File

@ -94,6 +94,7 @@ typedef struct {
GConnectFlags flags; GConnectFlags flags;
guint is_handler : 1; guint is_handler : 1;
guint warp_to : 1;
} SignalInfo; } SignalInfo;
void property_info_free (gpointer data); void property_info_free (gpointer data);

View File

@ -173,6 +173,17 @@
* "name" : "leave-event", * "name" : "leave-event",
* "states" : "button-states", * "states" : "button-states",
* "target-state" : "base" * "target-state" : "base"
* },
* {
* "name" : "button-press-event",
* "states" : "button-states",
* "target-state" : "active",
* },
* {
* "name" : "key-press-event",
* "states" : "button-states",
* "target-state" : "key-focus",
* "warp" : true
* } * }
* ], * ],
* ... * ...
@ -185,9 +196,10 @@
* instance through the clutter_script_add_states() function. If no * instance through the clutter_script_add_states() function. If no
* "states" key is present, then the default #ClutterState associated to * "states" key is present, then the default #ClutterState associated to
* the #ClutterScript instance will be used; the default #ClutterState * the #ClutterScript instance will be used; the default #ClutterState
* can be set using clutter_script_add_states() using a %NULL name. * can be set using clutter_script_add_states() using a %NULL name. The
* State changes on signal emission will not affect the signal emission * "warp" key can be used to warp to a specific state instead of
* chain. * animating to it. State changes on signal emission will not affect
* the signal emission chain.
* *
* Clutter reserves the following names, so classes defining properties * Clutter reserves the following names, so classes defining properties
* through the usual GObject registration process should avoid using these * through the usual GObject registration process should avoid using these
@ -950,6 +962,7 @@ typedef struct {
gchar *target; gchar *target;
gulong signal_id; gulong signal_id;
gulong hook_id; gulong hook_id;
gboolean warp_to;
} HookData; } HookData;
typedef struct { typedef struct {
@ -982,7 +995,12 @@ clutter_script_state_change_hook (GSignalInvocationHint *ihint,
emitter = g_value_get_object (&params[0]); emitter = g_value_get_object (&params[0]);
if (emitter == hook_data->emitter) if (emitter == hook_data->emitter)
{
if (hook_data->warp_to)
clutter_state_warp_to_state (hook_data->state, hook_data->target);
else
clutter_state_set_state (hook_data->state, hook_data->target); clutter_state_set_state (hook_data->state, hook_data->target);
}
return TRUE; return TRUE;
} }
@ -1083,6 +1101,7 @@ connect_each_object (gpointer key,
hook_data->emitter = object; hook_data->emitter = object;
hook_data->state = CLUTTER_STATE (state_object); hook_data->state = CLUTTER_STATE (state_object);
hook_data->target = g_strdup (sinfo->target); hook_data->target = g_strdup (sinfo->target);
hook_data->warp_to = sinfo->warp_to;
hook_data->signal_id = signal_id; hook_data->signal_id = signal_id;
hook_data->hook_id = hook_data->hook_id =
g_signal_add_emission_hook (signal_id, signal_quark, g_signal_add_emission_hook (signal_id, signal_quark,