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

View File

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

View File

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