1
0
Fork 0

drag: Add a default drag-motion behaviour

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.
This commit is contained in:
Emmanuele Bassi 2010-05-25 11:01:46 +01:00
parent d2e91c9935
commit 728e2d8071
2 changed files with 25 additions and 16 deletions

View file

@ -348,6 +348,22 @@ clutter_drag_action_set_actor (ClutterActorMeta *meta,
CLUTTER_ACTOR_META_CLASS (clutter_drag_action_parent_class)->set_actor (meta, actor);
}
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,
@ -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] =

View file

@ -35,21 +35,6 @@ on_drag_begin (ClutterDragAction *action,
clutter_actor_set_opacity (actor, 128);
}
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,
@ -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);