[clutter] pan-action: Add a simple convenience function to retrieve delta/coords



commit 75b521de6e3294bb612f08b1f191b0f75778d828
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Nov 25 23:11:45 2012 -0500

    pan-action: Add a simple convenience function to retrieve delta/coords
    
    This is a simple helper designed to ease the implementation of alternate
    implementations of the "pan" signal handler.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689061

 clutter/clutter-pan-action.c               |  116 ++++++++++++++++++++++++++--
 clutter/clutter-pan-action.h               |   12 +++-
 clutter/clutter.symbols                    |    2 +
 doc/reference/clutter/clutter-sections.txt |    2 +
 4 files changed, 125 insertions(+), 7 deletions(-)
---
diff --git a/clutter/clutter-pan-action.c b/clutter/clutter-pan-action.c
index 489c867..9c62651 100644
--- a/clutter/clutter-pan-action.c
+++ b/clutter/clutter-pan-action.c
@@ -301,10 +301,7 @@ clutter_pan_action_real_pan (ClutterPanAction *self,
   gfloat dx, dy;
   ClutterMatrix transform;
 
-  if (is_interpolated)
-    clutter_pan_action_get_interpolated_delta (self, &dx, &dy);
-  else
-    clutter_gesture_action_get_motion_delta (CLUTTER_GESTURE_ACTION (self), 0, &dx, &dy);
+  clutter_pan_action_get_motion_delta (self, 0, &dx, &dy);
 
   switch (priv->pan_axis)
     {
@@ -804,16 +801,18 @@ clutter_pan_action_get_interpolated_coords (ClutterPanAction *self,
  * Retrieves the delta, in stage space, since the latest interpolated
  * event, analogous to clutter_gesture_action_get_motion_delta().
  *
+ * Return value: the distance since the latest interpolated event
+ *
  * Since: 1.12
  */
-void
+gfloat
 clutter_pan_action_get_interpolated_delta (ClutterPanAction *self,
                                            gfloat           *delta_x,
                                            gfloat           *delta_y)
 {
   ClutterPanActionPrivate *priv;
 
-  g_return_if_fail (CLUTTER_IS_PAN_ACTION (self));
+  g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f);
 
   priv = self->priv;
 
@@ -822,4 +821,109 @@ clutter_pan_action_get_interpolated_delta (ClutterPanAction *self,
 
   if (delta_y)
     *delta_y = priv->dy;
+
+  return sqrt ((priv->dx * priv->dx) + (priv->dy * priv->dy));
+}
+
+/**
+ * clutter_pan_action_get_motion_delta:
+ * @self: A #ClutterPanAction
+ * @point: the touch point index, with 0 being the first touch
+ *   point received by the action
+ * @delta_x: (out) (allow-none): return location for the X delta
+ * @delta_y: (out) (allow-none): return location for the Y delta
+ *
+ * Retrieves the delta, in stage space, dependent on the current state
+ * of the #ClutterPanAction. If it is inactive, both fields will be
+ * set to 0. If it is panning by user action, the values will be equivalent
+ * to those returned by clutter_gesture_action_get_motion_delta().
+ * If it is interpolating with some form of kinetic scrolling, the values
+ * will be equivalent to those returned by
+ * clutter_pan_action_get_interpolated_delta(). This is a convenience
+ * method designed to be used in replacement "pan" signal handlers.
+ *
+ * Since: 1.14
+ */
+gfloat
+clutter_pan_action_get_motion_delta (ClutterPanAction *self,
+                                     guint             point,
+                                     gfloat           *delta_x,
+                                     gfloat           *delta_y)
+{
+  ClutterPanActionPrivate *priv;
+
+  g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f);
+
+  priv = self->priv;
+
+  switch (priv->state)
+    {
+    case PAN_STATE_INACTIVE:
+      if (delta_x)
+        *delta_x = 0;
+
+      if (delta_y)
+        *delta_y = 0;
+
+      return 0;
+    case PAN_STATE_PANNING:
+      return clutter_gesture_action_get_motion_delta (CLUTTER_GESTURE_ACTION (self),
+                                                      point, delta_x, delta_y);
+    case PAN_STATE_INTERPOLATING:
+      return clutter_pan_action_get_interpolated_delta (self, delta_x, delta_y);
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+/**
+ * clutter_pan_action_get_motion_coords:
+ * @self: A #ClutterPanAction
+ * @point: the touch point index, with 0 being the first touch
+ *   point received by the action
+ * @motion_x: (out) (allow-none): return location for the X coordinate
+ * @motion_y: (out) (allow-none): return location for the Y coordinate
+ *
+ * Retrieves the coordinates, in stage space, dependent on the current state
+ * of the #ClutterPanAction. If it is inactive, both fields will be
+ * set to 0. If it is panning by user action, the values will be equivalent
+ * to those returned by clutter_gesture_action_get_motion_coords().
+ * If it is interpolating with some form of kinetic scrolling, the values
+ * will be equivalent to those returned by
+ * clutter_pan_action_get_interpolated_coords(). This is a convenience
+ * method designed to be used in replacement "pan" signal handlers.
+ *
+ * Since: 1.14
+ */
+void
+clutter_pan_action_get_motion_coords (ClutterPanAction *self,
+                                      guint             point,
+                                      gfloat           *motion_x,
+                                      gfloat           *motion_y)
+{
+  ClutterPanActionPrivate *priv;
+
+  g_return_if_fail (CLUTTER_IS_PAN_ACTION (self));
+
+  priv = self->priv;
+
+  switch (priv->state)
+    {
+    case PAN_STATE_INACTIVE:
+      if (motion_x)
+        *motion_x = 0;
+
+      if (motion_y)
+        *motion_y = 0;
+      break;
+    case PAN_STATE_PANNING:
+      clutter_gesture_action_get_motion_coords (CLUTTER_GESTURE_ACTION (self),
+                                                point, motion_x, motion_y);
+      break;
+    case PAN_STATE_INTERPOLATING:
+      clutter_pan_action_get_interpolated_coords (self, motion_x, motion_y);
+      break;
+    default:
+      g_assert_not_reached ();
+    }
 }
diff --git a/clutter/clutter-pan-action.h b/clutter/clutter-pan-action.h
index 8f3e185..77d6b33 100644
--- a/clutter/clutter-pan-action.h
+++ b/clutter/clutter-pan-action.h
@@ -129,9 +129,19 @@ void            clutter_pan_action_get_interpolated_coords  (ClutterPanAction *s
                                                              gfloat           *interpolated_x,
                                                              gfloat           *interpolated_y);
 CLUTTER_AVAILABLE_IN_1_12
-void            clutter_pan_action_get_interpolated_delta   (ClutterPanAction *self,
+gfloat          clutter_pan_action_get_interpolated_delta   (ClutterPanAction *self,
                                                              gfloat           *delta_x,
                                                              gfloat           *delta_y);
+CLUTTER_AVAILABLE_IN_1_14
+gfloat          clutter_pan_action_get_motion_delta         (ClutterPanAction *self,
+                                                             guint             point,
+                                                             gfloat           *delta_x,
+                                                             gfloat           *delta_y);
+CLUTTER_AVAILABLE_IN_1_14
+void            clutter_pan_action_get_motion_coords        (ClutterPanAction *self,
+                                                             guint             point,
+                                                             gfloat           *motion_x,
+                                                             gfloat           *motion_y);
 G_END_DECLS
 
 #endif /* __CLUTTER_PAN_ACTION_H__ */
diff --git a/clutter/clutter.symbols b/clutter/clutter.symbols
index 0f5f6c7..2508bdf 100644
--- a/clutter/clutter.symbols
+++ b/clutter/clutter.symbols
@@ -1063,6 +1063,8 @@ clutter_pan_action_get_deceleration
 clutter_pan_action_get_interpolated_coords
 clutter_pan_action_get_interpolated_delta
 clutter_pan_action_get_interpolate
+clutter_pan_action_get_motion_coords
+clutter_pan_action_get_motion_delta
 clutter_pan_action_get_pan_axis
 clutter_pan_action_new
 clutter_pan_action_set_acceleration_factor
diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt
index 03d3091..7bdfbb3 100644
--- a/doc/reference/clutter/clutter-sections.txt
+++ b/doc/reference/clutter/clutter-sections.txt
@@ -3477,6 +3477,8 @@ clutter_pan_action_get_acceleration_factor
 <SUBSECTION>
 clutter_pan_action_get_interpolated_coords
 clutter_pan_action_get_interpolated_delta
+clutter_pan_action_get_motion_coords
+clutter_pan_action_get_motion_delta
 <SUBSECTION Standard>
 CLUTTER_IS_PAN_ACTION
 CLUTTER_IS_PAN_ACTION_CLASS



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