[gnome-photos/wip/rishi/gesture-zoom: 10/10] preview-view: zoom gesture



commit 0c66e9dde4e5a1ebecfe00069c349e4bdc17cec3
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Oct 14 09:32:45 2017 +0200

    preview-view: zoom gesture

 src/photos-preview-view.c |   81 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 0bcb19b..a8629b5 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -54,6 +54,7 @@ struct _PhotosPreviewView
   GAction *zoom_out_action;
   GCancellable *cancellable;
   GeglNode *node;
+  GtkGesture *gesture_zoom;
   GtkWidget *overlay;
   GtkWidget *palette;
   GtkWidget *revealer;
@@ -65,6 +66,7 @@ struct _PhotosPreviewView
   gboolean grabbed;
   gdouble event_x_last;
   gdouble event_y_last;
+  gdouble gesture_zoom_scale_last;
   gdouble zoom_begin;
   gdouble zoom_best_fit;
 };
@@ -249,6 +251,69 @@ photos_preview_view_draw_overlay (PhotosPreviewView *self, cairo_t *cr, GdkRecta
 }
 
 
+static void
+photos_preview_view_gesture_zoom_begin (PhotosPreviewView *self, GdkEventSequence *sequence)
+{
+  GVariant *parameter;
+
+  g_message ("zoom begin");
+  gtk_gesture_set_state (self->gesture_zoom, GTK_EVENT_SEQUENCE_CLAIMED);
+  self->gesture_zoom_scale_last = 1.0;
+
+  parameter = photos_utils_create_zoom_target_value (0.0, PHOTOS_ZOOM_EVENT_TOUCH);
+  g_assert_true (g_variant_is_floating (parameter));
+
+  g_action_activate (self->zoom_begin_action, parameter);
+}
+
+
+static void
+photos_preview_view_gesture_zoom_end (PhotosPreviewView *self, GdkEventSequence *sequence)
+{
+  GVariant *parameter;
+
+  g_message ("zoom end");
+  self->gesture_zoom_scale_last = 0.0;
+
+  parameter = photos_utils_create_zoom_target_value (0.0, PHOTOS_ZOOM_EVENT_TOUCH);
+  g_assert_true (g_variant_is_floating (parameter));
+
+  g_action_activate (self->zoom_end_action, parameter);
+}
+
+
+static void
+photos_preview_view_gesture_zoom_scale_changed (PhotosPreviewView *self, gdouble scale)
+{
+  GVariant *parameter = NULL;
+
+  g_message ("scale changed: %f", scale);
+
+  if (photos_utils_equal_double (scale, self->gesture_zoom_scale_last))
+    goto out;
+
+  parameter = photos_utils_create_zoom_target_value (scale, PHOTOS_ZOOM_EVENT_TOUCH);
+  parameter = g_variant_ref_sink (parameter);
+
+  if (scale > self->gesture_zoom_scale_last)
+    {
+      g_action_activate (self->zoom_in_action, parameter);
+    }
+  else
+    {
+      if (g_action_get_enabled (self->zoom_out_action))
+        g_action_activate (self->zoom_out_action, parameter);
+      else
+        gtk_event_controller_reset (GTK_EVENT_CONTROLLER (self->gesture_zoom));
+    }
+
+  self->gesture_zoom_scale_last = scale;
+
+ out:
+  g_clear_pointer (&parameter, (GDestroyNotify) g_variant_unref);
+}
+
+
 static GtkWidget *
 photos_preview_view_get_invisible_child (PhotosPreviewView *self)
 {
@@ -1071,6 +1136,7 @@ photos_preview_view_dispose (GObject *object)
     }
 
   g_clear_object (&self->node);
+  g_clear_object (&self->gesture_zoom);
   g_clear_object (&self->item_mngr);
   g_clear_object (&self->mode_cntrlr);
   g_clear_object (&self->nav_buttons);
@@ -1098,6 +1164,21 @@ photos_preview_view_constructed (GObject *object)
 
   G_OBJECT_CLASS (photos_preview_view_parent_class)->constructed (object);
 
+  self->gesture_zoom = gtk_gesture_zoom_new (GTK_WIDGET (self));
+  gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (self->gesture_zoom), GTK_PHASE_CAPTURE);
+  g_signal_connect_swapped (self->gesture_zoom,
+                            "begin",
+                            G_CALLBACK (photos_preview_view_gesture_zoom_begin),
+                            self);
+  g_signal_connect_swapped (self->gesture_zoom,
+                            "end",
+                            G_CALLBACK (photos_preview_view_gesture_zoom_end),
+                            self);
+  g_signal_connect_swapped (self->gesture_zoom,
+                            "scale-changed",
+                            G_CALLBACK (photos_preview_view_gesture_zoom_scale_changed),
+                            self);
+
   self->nav_buttons = photos_preview_nav_buttons_new (self, GTK_OVERLAY (self->overlay));
   g_signal_connect_swapped (self->nav_buttons, "load-next", G_CALLBACK (photos_preview_view_navigate_next), 
self);
   g_signal_connect_swapped (self->nav_buttons, "load-previous", G_CALLBACK 
(photos_preview_view_navigate_previous), self);


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