[clutter] script: Allow warping to states



commit a9dd5abfcccd96a4da6210e2eedbb115ea5bfa74
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Jun 13 13:07:04 2011 +0100

    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.

 clutter/clutter-script-parser.c  |   10 ++++++++--
 clutter/clutter-script-private.h |    1 +
 clutter/clutter-script.c         |   27 +++++++++++++++++++++++----
 3 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/clutter/clutter-script-parser.c b/clutter/clutter-script-parser.c
index 8e8acdd..7408e1d 100644
--- a/clutter/clutter-script-parser.c
+++ b/clutter/clutter-script-parser.c
@@ -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"))
         {
diff --git a/clutter/clutter-script-private.h b/clutter/clutter-script-private.h
index 634e306..d9753ee 100644
--- a/clutter/clutter-script-private.h
+++ b/clutter/clutter-script-private.h
@@ -94,6 +94,7 @@ typedef struct {
   GConnectFlags flags;
 
   guint is_handler : 1;
+  guint warp_to    : 1;
 } SignalInfo;
 
 void property_info_free (gpointer data);
diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c
index 97fa04d..0104495 100644
--- a/clutter/clutter-script.c
+++ b/clutter/clutter-script.c
@@ -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)
-    clutter_state_set_state (hook_data->state, hook_data->target);
+    {
+      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,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]