]> saetta.ns0.it Git - libgtkgis/commitdiff
The zoom follows the mouse.
authorAndrea Zagli <azagli@libero.it>
Wed, 19 Aug 2009 16:15:25 +0000 (18:15 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 19 Aug 2009 16:15:25 +0000 (18:15 +0200)
src/gtkgis.c

index 8db9eddc2dc59fd8ba1f0ed9d68647773fec4d54..b0cae17e185b18b5785182a6eba88a0dd9153164 100644 (file)
@@ -1336,12 +1336,30 @@ gtk_gis_scroll_event (GtkWidget *widget,
        GtkGis *gtkgis;
        GtkGisScale *scale;
 
+       GtkAllocation allocation;
+
+       gdouble canvas_x;
+       gdouble canvas_y;
+
+       gdouble new_canvas_x;
+       gdouble new_canvas_y;
+
        g_return_val_if_fail (IS_GTK_GIS (widget), FALSE);
        g_return_val_if_fail (event != NULL, FALSE);
 
        gtkgis = GTK_GIS (widget);
        priv = GTK_GIS_GET_PRIVATE (gtkgis);
 
+       allocation = priv->canvas->allocation;
+
+       canvas_x = (0 - allocation.x) + event->x;
+       canvas_y = (0 - allocation.y) + event->y;
+
+       new_canvas_x = canvas_x;
+       new_canvas_y = canvas_y;
+
+       goo_canvas_convert_from_pixels (GOO_CANVAS (priv->canvas), &new_canvas_x, &new_canvas_y);
+
        scale = gtk_gis_get_scale (gtkgis);
 
        if (event->direction == GDK_SCROLL_UP)
@@ -1359,6 +1377,13 @@ gtk_gis_scroll_event (GtkWidget *widget,
 
        gtk_gis_set_scale (gtkgis, scale);
 
+       /* returns to the mouse */
+       goo_canvas_convert_to_pixels (GOO_CANVAS (priv->canvas), &new_canvas_x, &new_canvas_y);
+
+       gtk_layout_move (GTK_LAYOUT (priv->scroll_win), priv->canvas,
+                        allocation.x - (new_canvas_x - canvas_x),
+                        allocation.y - (new_canvas_y - canvas_y));
+
        return TRUE;
 }