Browse code

Implement smooth zooming

mxmgh authored on 09/01/2021 03:16:35 • José Fonseca committed on 12/02/2021 10:41:09
Showing 1 changed files

... ...
@@ -73,7 +73,8 @@ class DotWidget(Gtk.DrawingArea):
73 73
         self.add_events(Gdk.EventMask.POINTER_MOTION_MASK |
74 74
                         Gdk.EventMask.POINTER_MOTION_HINT_MASK |
75 75
                         Gdk.EventMask.BUTTON_RELEASE_MASK |
76
-                        Gdk.EventMask.SCROLL_MASK)
76
+                        Gdk.EventMask.SCROLL_MASK |
77
+                        Gdk.EventMask.SMOOTH_SCROLL_MASK)
77 78
         self.connect("motion-notify-event", self.on_area_motion_notify)
78 79
         self.connect("scroll-event", self.on_area_scroll_event)
79 80
         self.connect("size-allocate", self.on_area_size_allocate)
... ...
@@ -439,9 +440,13 @@ class DotWidget(Gtk.DrawingArea):
439 440
             self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT,
440 441
                             pos=(event.x, event.y))
441 442
             return True
442
-        if event.direction == Gdk.ScrollDirection.DOWN:
443
+        elif event.direction == Gdk.ScrollDirection.DOWN:
443 444
             self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT,
444 445
                             pos=(event.x, event.y))
446
+        else:
447
+            deltas = event.get_scroll_deltas()
448
+            self.zoom_image(self.zoom_ratio * (1 - deltas.delta_y / 10),
449
+                            pos=(event.x, event.y))
445 450
             return True
446 451
         return False
447 452