drag: Add a default drag-motion behaviour
authorEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 25 May 2010 10:01:46 +0000 (11:01 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 25 May 2010 10:01:46 +0000 (11:01 +0100)
The DragAction should, by default, drag the actor to which it has been
applied, instead of delegating what to do to the developer. If custom
code need to override it, g_signal_stop_emission_by_name() can be called
to stop the default handler to ever running.

clutter/clutter-drag-action.c
tests/interactive/test-drag.c

index ae51e81..7b3c5df 100644 (file)
@@ -349,6 +349,22 @@ clutter_drag_action_set_actor (ClutterActorMeta *meta,
 }
 
 static void
+clutter_drag_action_real_drag_motion (ClutterDragAction *action,
+                                      ClutterActor      *actor,
+                                      gfloat             delta_x,
+                                      gfloat             delta_y)
+{
+  ClutterActor *drag_handle;
+
+  if (action->priv->drag_handle != NULL)
+    drag_handle = action->priv->drag_handle;
+  else
+    drag_handle = actor;
+
+  clutter_actor_move_by (drag_handle, delta_x, delta_y);
+}
+
+static void
 clutter_drag_action_set_property (GObject      *gobject,
                                   guint         prop_id,
                                   const GValue *value,
@@ -443,6 +459,8 @@ clutter_drag_action_class_init (ClutterDragActionClass *klass)
 
   meta_class->set_actor = clutter_drag_action_set_actor;
 
+  klass->drag_motion = clutter_drag_action_real_drag_motion;
+
   /**
    * ClutterDragAction:drag-threshold:
    *
@@ -551,6 +569,13 @@ clutter_drag_action_class_init (ClutterDragActionClass *klass)
    * stage coordinates of the latest motion event you can use
    * clutter_drag_action_get_motion_coords().
    *
+   * The default handler of the signal will call clutter_actor_move_by()
+   * either on @actor or, if set, of #ClutterDragAction:drag-handle using
+   * the @delta_x and @delta_y components of the dragging motion. If you
+   * want to override the default behaviour, you can connect to this
+   * signal and call g_signal_stop_emission_by_name() from within your
+   * callback.
+   *
    * Since: 1.4
    */
   drag_signals[DRAG_MOTION] =
index e8c479c..2aa1d1d 100644 (file)
@@ -36,21 +36,6 @@ on_drag_begin (ClutterDragAction   *action,
 }
 
 static void
-on_drag_motion (ClutterDragAction   *action,
-                ClutterActor        *actor,
-                gfloat               delta_x,
-                gfloat               delta_y,
-                ClutterModifierType  modifiers)
-{
-  ClutterActor *drag_handle;
-
-  drag_handle = clutter_drag_action_get_drag_handle (action);
-  g_assert (drag_handle != NULL);
-
-  clutter_actor_move_by (drag_handle, delta_x, delta_y);
-}
-
-static void
 on_drag_end (ClutterDragAction   *action,
              ClutterActor        *actor,
              gfloat               event_x,
@@ -176,7 +161,6 @@ test_drag_main (int argc, char *argv[])
                                      get_drag_axis (drag_axis));
 
   g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL);
-  g_signal_connect (action, "drag-motion", G_CALLBACK (on_drag_motion), NULL);
   g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL);
 
   clutter_actor_add_action (handle, action);