summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2015-06-04 21:19:49 +0200
committerCarlos Garnacho <carlosg@gnome.org>2015-06-04 21:24:05 +0200
commite7216234d8e5a37855c0b6c457c985c84fd8230f (patch)
tree2762ff5e7a29b5d273849221d149d4d8ecadef51
parentb12fa39d9ee0d41a145bfc75c7bc28b82bd522d7 (diff)
downloadclutter-wip/carlosg/touchpad-gestures.tar.gz
zoom-action: Implement the ClutterTouchpadGesture interfacewip/carlosg/touchpad-gestures
This takes care of the emission of ::zoom under the same conditions than touch events.
-rw-r--r--clutter/clutter-zoom-action.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/clutter/clutter-zoom-action.c b/clutter/clutter-zoom-action.c
index acf53b33a..7f6dc8b2e 100644
--- a/clutter/clutter-zoom-action.c
+++ b/clutter/clutter-zoom-action.c
@@ -57,6 +57,7 @@
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-gesture-action-private.h"
+#include "clutter-touchpad-gesture-private.h"
#include "clutter-marshal.h"
#include "clutter-private.h"
#include "clutter-stage-private.h"
@@ -94,6 +95,9 @@ struct _ClutterZoomActionPrivate
gdouble initial_scale_y;
gdouble zoom_initial_distance;
+
+ /* Touchpad state */
+ gfloat current_scale;
};
enum
@@ -116,7 +120,12 @@ enum
static guint zoom_signals[LAST_SIGNAL] = { 0, };
-G_DEFINE_TYPE_WITH_PRIVATE (ClutterZoomAction, clutter_zoom_action, CLUTTER_TYPE_GESTURE_ACTION)
+static void clutter_touchpad_zoom_gesture_iface_init (ClutterTouchpadGestureIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (ClutterZoomAction, clutter_zoom_action, CLUTTER_TYPE_GESTURE_ACTION,
+ G_ADD_PRIVATE (ClutterZoomAction)
+ G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_TOUCHPAD_GESTURE,
+ clutter_touchpad_zoom_gesture_iface_init))
static void
initialize_focal_point (ClutterZoomAction *action,
@@ -171,6 +180,54 @@ emit_zoom (ClutterZoomAction *action,
return retval;
}
+static gboolean
+clutter_touchpad_zoom_gesture_handle_event (ClutterTouchpadGesture *gesture,
+ const ClutterEvent *event)
+{
+ ClutterZoomActionPrivate *priv = ((ClutterZoomAction *) gesture)->priv;
+ ClutterPoint point;
+
+ switch (event->type)
+ {
+ case CLUTTER_TOUCHPAD_PINCH_BEGIN:
+ clutter_point_init (&point,
+ event->touchpad_pinch.x,
+ event->touchpad_pinch.y);
+ initialize_focal_point (CLUTTER_ZOOM_ACTION (gesture), &point);
+ priv->current_scale = 1;
+ return CLUTTER_EVENT_PROPAGATE;
+
+ case CLUTTER_TOUCHPAD_PINCH_UPDATE:
+ point.x = priv->focal_point.x + event->touchpad_pinch.dx;
+ point.y = priv->focal_point.y + event->touchpad_pinch.dy;
+ update_focal_point (CLUTTER_ZOOM_ACTION (gesture), &point);
+ priv->current_scale = event->touchpad_pinch.scale;
+ return CLUTTER_EVENT_PROPAGATE;
+
+ case CLUTTER_TOUCHPAD_PINCH_END:
+ case CLUTTER_TOUCHPAD_PINCH_CANCEL:
+ return CLUTTER_EVENT_PROPAGATE;
+ default:
+ return CLUTTER_EVENT_STOP;
+ }
+}
+
+static gboolean
+clutter_touchpad_zoom_gesture_update (ClutterTouchpadGesture *gesture)
+{
+ ClutterZoomActionPrivate *priv = ((ClutterZoomAction *) gesture)->priv;
+
+ emit_zoom (CLUTTER_ZOOM_ACTION (gesture), priv->current_scale);
+ return TRUE;
+}
+
+static void
+clutter_touchpad_zoom_gesture_iface_init (ClutterTouchpadGestureIface *iface)
+{
+ iface->handle_event = clutter_touchpad_zoom_gesture_handle_event;
+ iface->update = clutter_touchpad_zoom_gesture_update;
+}
+
static void
capture_point_initial_position (ClutterGestureAction *action,
ClutterActor *actor,