[glide] Shapes are draggable



commit e3a95ad5d2debced3795d3badfff9bae9bfe22de
Author: Robert Carr <racarr Valentine localdomain>
Date:   Thu May 6 07:00:35 2010 -0400

    Shapes are draggable

 libglide/glide-shape-priv.h |    4 ++-
 libglide/glide-shape.c      |   61 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 61 insertions(+), 4 deletions(-)
---
diff --git a/libglide/glide-shape-priv.h b/libglide/glide-shape-priv.h
index 6171daa..3057bae 100644
--- a/libglide/glide-shape-priv.h
+++ b/libglide/glide-shape-priv.h
@@ -26,7 +26,9 @@ G_BEGIN_DECLS
 
 struct _GlideShapePrivate
 {
-  gpointer fillter;
+  gboolean dragging;
+  gboolean motion_since_press;
+  gfloat drag_center_x, drag_center_y;
 };
 
 G_END_DECLS
diff --git a/libglide/glide-shape.c b/libglide/glide-shape.c
index a56aa4c..49f392c 100644
--- a/libglide/glide-shape.c
+++ b/libglide/glide-shape.c
@@ -67,16 +67,69 @@ glide_shape_button_press (ClutterActor *actor,
 {
   GlideStageManager *m;
   GlideActor *ga = GLIDE_ACTOR (actor);
+  GlideShape *shape = GLIDE_SHAPE (actor);
+  gfloat ax, ay;
   
   m = glide_actor_get_stage_manager (ga);
   
-  if (event->button != 1)
-    return FALSE;
-  
   glide_stage_manager_set_selection (m, ga);
+  
+  clutter_actor_get_position (actor, &ax, &ay);
+  shape->priv->drag_center_x = event->x - ax;
+  shape->priv->drag_center_y = event->y - ay;
+  shape->priv->dragging = TRUE;
+  shape->priv->motion_since_press = FALSE;
+  
+  clutter_grab_pointer (actor);
+  
+  glide_actor_start_undo (ga, "Move shape");
+
+
   return TRUE;
 }
 
+static gboolean
+glide_shape_button_release (ClutterActor *actor,
+			    ClutterButtonEvent *bev)
+{
+  GlideShape *shape = GLIDE_SHAPE (actor);
+
+  if (shape->priv->dragging)
+    {
+      if (!shape->priv->motion_since_press)
+	glide_undo_manager_cancel_actor_action (glide_actor_get_undo_manager (GLIDE_ACTOR (actor)));
+      else
+	glide_actor_end_undo (GLIDE_ACTOR (actor));
+      
+      clutter_ungrab_pointer ();
+      shape->priv->dragging = FALSE;
+      
+      return TRUE;
+    }
+  
+  return FALSE;
+
+}
+
+static gboolean
+glide_shape_motion (ClutterActor *actor,
+		    ClutterMotionEvent *mev)
+{
+  GlideShape *shape = GLIDE_SHAPE (actor);
+  
+  if (shape->priv->dragging)
+    {
+      shape->priv->motion_since_press = TRUE;
+      clutter_actor_set_position (actor,
+				  mev->x - shape->priv->drag_center_x,
+				  mev->y - shape->priv->drag_center_y);
+      
+      return TRUE;
+    }
+  return FALSE;
+}
+			    
+
 static void
 glide_shape_class_init (GlideShapeClass *klass)
 {
@@ -86,6 +139,8 @@ glide_shape_class_init (GlideShapeClass *klass)
   
   actor_class->paint = glide_shape_paint;
   actor_class->button_press_event = glide_shape_button_press;
+  actor_class->button_release_event = glide_shape_button_release;
+  actor_class->motion_event = glide_shape_motion;
 }
 
 static void



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