This feels much more natural and is how, e.g. Eye of GNOME implements
mouse wheel zoom.
From: Marius Gedminas <marius@gedmin.as>
| ... | ... |
@@ -990,10 +990,17 @@ class DotWidget(gtk.DrawingArea): |
| 990 | 990 |
self.highlight = items |
| 991 | 991 |
self.queue_draw() |
| 992 | 992 |
|
| 993 |
- def zoom_image(self, zoom_ratio, center=False): |
|
| 993 |
+ def zoom_image(self, zoom_ratio, center=False, pos=None): |
|
| 994 | 994 |
if center: |
| 995 | 995 |
self.x = self.graph.width/2 |
| 996 | 996 |
self.y = self.graph.height/2 |
| 997 |
+ elif pos is not None: |
|
| 998 |
+ rect = self.get_allocation() |
|
| 999 |
+ x, y = pos |
|
| 1000 |
+ x -= 0.5*rect.width |
|
| 1001 |
+ y -= 0.5*rect.height |
|
| 1002 |
+ self.x += x / self.zoom_ratio - x / zoom_ratio |
|
| 1003 |
+ self.y += y / self.zoom_ratio - y / zoom_ratio |
|
| 997 | 1004 |
self.zoom_ratio = zoom_ratio |
| 998 | 1005 |
self.zoom_to_fit_on_resize = False |
| 999 | 1006 |
self.queue_draw() |
| ... | ... |
@@ -1126,10 +1133,12 @@ class DotWidget(gtk.DrawingArea): |
| 1126 | 1133 |
|
| 1127 | 1134 |
def on_area_scroll_event(self, area, event): |
| 1128 | 1135 |
if event.direction == gtk.gdk.SCROLL_UP: |
| 1129 |
- self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT) |
|
| 1136 |
+ self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT, |
|
| 1137 |
+ pos=(event.x, event.y)) |
|
| 1130 | 1138 |
return True |
| 1131 | 1139 |
if event.direction == gtk.gdk.SCROLL_DOWN: |
| 1132 |
- self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT) |
|
| 1140 |
+ self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT, |
|
| 1141 |
+ pos=(event.x, event.y)) |
|
| 1133 | 1142 |
return True |
| 1134 | 1143 |
return False |
| 1135 | 1144 |
|