From: Kaj-Michael Lang Date: Mon, 5 May 2008 20:59:18 +0000 (+0300) Subject: Add mouse scroller zoom in/out handling and zoom-changed signal X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb3a46fc743b7ca886d30b966af53088176fc884;p=mapper Add mouse scroller zoom in/out handling and zoom-changed signal --- diff --git a/src/gtkmap.c b/src/gtkmap.c index 3fc3948..4022761 100644 --- a/src/gtkmap.c +++ b/src/gtkmap.c @@ -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; +} diff --git a/src/gtkmap.h b/src/gtkmap.h index 47985b4..0504dbf 100644 --- a/src/gtkmap.h +++ b/src/gtkmap.h @@ -49,6 +49,7 @@ struct _GtkMap { struct _GtkMapClass { GtkDrawingAreaClass parent_class; + void (* zoom_changed) (GtkWidget *widget, int zoom); }; G_BEGIN_DECLS