[libshumate/tintou/zoom-click] map: Allow to zoom with double click




commit ebbaaa55f6cc17bbf6306ad3afefd41a37bc1557
Author: Corentin Noël <tintou noel tf>
Date:   Mon Aug 1 22:47:28 2022 +0200

    map: Allow to zoom with double click
    
    Handle double click on the primary button to zoom-in.

 shumate/shumate-map.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
---
diff --git a/shumate/shumate-map.c b/shumate/shumate-map.c
index 983db33..eaafc5a 100644
--- a/shumate/shumate-map.c
+++ b/shumate/shumate-map.c
@@ -596,6 +596,23 @@ on_rotate_gesture_update (ShumateMap *self,
   move_location_to_coords (self, self->gesture_begin_lat, self->gesture_begin_lon, x, y);
 }
 
+static void
+on_click_gesture_pressed (ShumateMap      *self,
+                          gint             n_press,
+                          gdouble          x,
+                          gdouble          y,
+                          GtkGestureClick *click)
+{
+  guint current_button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (click));
+  if (current_button == GDK_BUTTON_PRIMARY && n_press == 2)
+    {
+      double zoom_level = shumate_viewport_get_zoom_level (self->viewport);
+      self->current_x = x;
+      self->current_y = y;
+      set_zoom_level (self, zoom_level + 1);
+    }
+}
+
 static void
 on_motion_controller_motion (ShumateMap               *self,
                              double                    x,
@@ -804,6 +821,7 @@ shumate_map_init (ShumateMap *self)
   GtkGesture *swipe_gesture;
   GtkGesture *zoom_gesture;
   GtkGesture *rotate_gesture;
+  GtkGesture *click_gesture;
 
   self->viewport = shumate_viewport_new ();
   self->zoom_on_double_click = TRUE;
@@ -844,6 +862,10 @@ shumate_map_init (ShumateMap *self)
 
   gtk_gesture_group (zoom_gesture, rotate_gesture);
 
+  click_gesture = gtk_gesture_click_new ();
+  g_signal_connect_swapped (click_gesture, "pressed", G_CALLBACK (on_click_gesture_pressed), self);
+  gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (click_gesture));
+
   key_controller = gtk_event_controller_key_new ();
   gtk_widget_add_controller (GTK_WIDGET (self), key_controller);
 


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