]> err.no Git - mapper/commitdiff
Add mouse scroller zoom in/out handling and zoom-changed signal
authorKaj-Michael Lang <milang@tal.org>
Mon, 5 May 2008 20:59:18 +0000 (23:59 +0300)
committerKaj-Michael Lang <milang@tal.org>
Mon, 5 May 2008 20:59:18 +0000 (23:59 +0300)
src/gtkmap.c
src/gtkmap.h

index 3fc3948b604717aa62cfb22a1c39256f618c0806..40227617f7ffb37afb9aec314cf5a0aa066addb5 100644 (file)
@@ -137,6 +137,7 @@ struct _GtkMapPriv
        gint zoom;
        gint max_zoom;
        gint min_zoom;
+       gboolean zoom_to_mouse;
 
        gfloat units_conv;
        gchar *units_str;
@@ -236,17 +237,16 @@ static void gtk_map_update_size(GtkWidget *widget, gint width, gint height);
 static void gtk_map_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void gtk_map_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 
+static gboolean gtk_map_button_press_cb(GtkWidget *widget, GdkEventButton *event);
+static gboolean gtk_map_button_release_cb(GtkWidget *widget, GdkEventButton *event);
+static gboolean gtk_map_scroll_event_cb(GtkWidget *widget, GdkEventScroll *event); 
+
 /* Signal IDs */
 enum {
        MAP_LOCATION_CHANGED,
-       
-       MAP_ZOOMED_IN,
-       MAP_ZOOMED_OUT,
-
+       MAP_ZOOM_CHANGED,
        MAP_PANNED,
-
        MARKER_CLICK,
-
        LAST_SIGNAL
 };
 
@@ -276,6 +276,11 @@ widget_class->realize = gtk_map_realize;
 widget_class->size_allocate = gtk_map_size_allocate;
 
 g_type_class_add_private (object_class, sizeof(GtkMapPriv));
+
+gtk_map_signals[MAP_ZOOM_CHANGED]=g_signal_new("zoom-changed", G_OBJECT_CLASS_TYPE(object_class),
+     G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkMapClass, zoom_changed),
+     NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
+
 }
 
 static inline void 
@@ -350,6 +355,7 @@ priv->draw_width=4;
 priv->zoom=3;
 priv->min_zoom=0;
 priv->max_zoom=17;
+priv->zoom_to_mouse=TRUE;
 
 priv->center_mode=CENTER_LATLON;
 priv->center.unitx=0;
@@ -581,6 +587,13 @@ if (priv->gl_config) {
 }
 #endif
 
+#if 0
+g_signal_connect(G_OBJECT(map), "button_press_event", G_CALLBACK(map_cb_button_press), NULL);
+g_signal_connect(G_OBJECT(map), "button_release_event",G_CALLBACK(map_cb_button_release), NULL);
+#endif
+
+g_signal_connect(G_OBJECT(map), "scroll_event",  G_CALLBACK(gtk_map_scroll_event_cb), NULL);
+
 priv->scale_context=gtk_widget_get_pango_context(widget);
 priv->scale_layout=pango_layout_new(priv->scale_context);
 priv->scale_font=pango_font_description_new();
@@ -614,25 +627,6 @@ g_signal_connect(G_OBJECT(widget), "button_press_event", G_CALLBACK(gtk_map_pres
 
 }
 
-static void
-draw (GtkWidget *clock, cairo_t *cr)
-{
-       double x, y;
-       double radius;
-       int i;
-       
-       x = clock->allocation.x + clock->allocation.width / 2;
-       y = clock->allocation.y + clock->allocation.height / 2;
-       radius = MIN (clock->allocation.width / 2, clock->allocation.height / 2) - 5;
-
-       /* clock back */
-       cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
-       cairo_set_source_rgb (cr, 1, 1, 1);
-       cairo_fill_preserve (cr);
-       cairo_set_source_rgb (cr, 0, 0, 0);
-       cairo_stroke (cr);
-}
-
 static gboolean
 gtk_map_expose(GtkWidget *widget, GdkEventExpose *event)
 {
@@ -1249,6 +1243,7 @@ gtk_map_recalc_focus_base(priv);
 gtk_map_recalc_focus_size(priv);
 
 gtk_map_refresh(widget);
+g_signal_emit(widget, gtk_map_signals[MAP_ZOOM_CHANGED], 0, priv->zoom);
 
 return TRUE;
 }
@@ -1301,3 +1296,22 @@ if (cache_size>512)
        cache_size=512;
 image_cache_set_size(priv->icache, cache_size);
 }
+
+/**
+ * Mouse scroller zoom in/out callback
+ */
+static gboolean
+gtk_map_scroll_event_cb(GtkWidget *widget, GdkEventScroll *event)
+{
+GtkMap *map;
+GtkMapPriv *priv;
+
+g_return_if_fail(GTK_IS_MAP(widget));
+
+map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
+gtk_map_zoom(widget, event->direction==GDK_SCROLL_UP ? -1 : 1);
+if (priv->zoom_to_mouse)
+       gtk_map_set_center(widget, x2unit((gint) (event->x + 0.5)), y2unit((gint) (event->y + 0.5)));
+return FALSE;
+}
index 47985b44407e1c50b47ea5e8662ac7b07d3e17dd..0504dbf53db67958bc4c52d576e5fa4c57f9ae12 100644 (file)
@@ -49,6 +49,7 @@ struct _GtkMap {
 
 struct _GtkMapClass {
        GtkDrawingAreaClass parent_class;
+       void (* zoom_changed) (GtkWidget *widget, int zoom);
 };
 
 G_BEGIN_DECLS