From 530a13f02f710710607732ed21b1493f04931615 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 17 Jun 2011 16:51:05 +0100 Subject: [PATCH] stage: Allow tracking dragged actors We should be able to internally attach the actor currently being dragged to the device that is dragging it. https://bugzilla.gnome.org/show_bug.cgi?id=652842 --- clutter/clutter-stage-private.h | 8 ++++++ clutter/clutter-stage.c | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/clutter/clutter-stage-private.h b/clutter/clutter-stage-private.h index 07ac99d67..9911f380c 100644 --- a/clutter/clutter-stage-private.h +++ b/clutter/clutter-stage-private.h @@ -99,6 +99,14 @@ void _clutter_stage_release_pick_id (ClutterStage *stage, ClutterActor * _clutter_stage_get_actor_by_pick_id (ClutterStage *stage, gint32 pick_id); +void _clutter_stage_add_drag_actor (ClutterStage *stage, + ClutterInputDevice *device, + ClutterActor *actor); +ClutterActor * _clutter_stage_get_drag_actor (ClutterStage *stage, + ClutterInputDevice *device); +void _clutter_stage_remove_drag_actor (ClutterStage *stage, + ClutterInputDevice *device); + G_END_DECLS #endif /* __CLUTTER_STAGE_PRIVATE_H__ */ diff --git a/clutter/clutter-stage.c b/clutter/clutter-stage.c index 10190a904..e0454068a 100644 --- a/clutter/clutter-stage.c +++ b/clutter/clutter-stage.c @@ -4091,3 +4091,51 @@ _clutter_stage_get_actor_by_pick_id (ClutterStage *stage, return _clutter_id_pool_lookup (priv->pick_id_pool, pick_id); } + +void +_clutter_stage_add_drag_actor (ClutterStage *stage, + ClutterInputDevice *device, + ClutterActor *actor) +{ + GHashTable *drag_actors; + + drag_actors = g_object_get_data (G_OBJECT (stage), "__clutter_stage_drag_actors"); + if (drag_actors == NULL) + { + drag_actors = g_hash_table_new (NULL, NULL); + g_object_set_data_full (G_OBJECT (stage), "__clutter_stage_drag_actors", + drag_actors, + (GDestroyNotify) g_hash_table_destroy); + } + + g_hash_table_replace (drag_actors, device, actor); +} + +ClutterActor * +_clutter_stage_get_drag_actor (ClutterStage *stage, + ClutterInputDevice *device) +{ + GHashTable *drag_actors; + + drag_actors = g_object_get_data (G_OBJECT (stage), "__clutter_stage_drag_actors"); + if (drag_actors == NULL) + return NULL; + + return g_hash_table_lookup (drag_actors, device); +} + +void +_clutter_stage_remove_drag_actor (ClutterStage *stage, + ClutterInputDevice *device) +{ + GHashTable *drag_actors; + + drag_actors = g_object_get_data (G_OBJECT (stage), "__clutter_stage_drag_actors"); + if (drag_actors == NULL) + return; + + g_hash_table_remove (drag_actors, device); + + if (g_hash_table_size (drag_actors) == 0) + g_object_set_data (G_OBJECT (stage), "__clutter_stage_drag_actors", NULL); +}