From: Kaj-Michael Lang Date: Wed, 7 May 2008 20:24:32 +0000 (+0300) Subject: Map widget: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96856d4dab71416f4092135512950ef22c117fce;p=mapper Map widget: - Add simple click and double-click handling - Start to add support for context menu - Fix warnings --- diff --git a/src/gtkmap.c b/src/gtkmap.c index 64cbf26..f182151 100644 --- a/src/gtkmap.c +++ b/src/gtkmap.c @@ -70,6 +70,8 @@ struct _GtkMapPriv cairo_t *ct; #endif + GtkMenu *menu; + PangoContext *context; PangoLayout *layout; PangoFontDescription *fontdesc; @@ -164,6 +166,8 @@ struct _GtkMapPriv gboolean show_velvec; gboolean show_markers; gboolean show_speed; + gboolean click_to_center; + gboolean zoom_in_on_2button; gboolean rotate_view; gfloat rotate_angle; @@ -393,6 +397,9 @@ priv->show_velvec=TRUE; priv->show_markers=TRUE; priv->show_location=TRUE; +priv->click_to_center=FALSE; +priv->zoom_in_on_2button=FALSE; + priv->rotate_angle=M_PI; priv->rotate_view=FALSE; @@ -603,7 +610,7 @@ if (priv->gl_config) { g_print("OpenGL version: %s\n", glGetString (GL_VERSION)); g_print("OpenGL vendor: %s\n", glGetString (GL_VENDOR)); g_print("OpenGL renderer: %s\n", glGetString (GL_RENDERER)); - gtk_widget_set_gl_capability(widget->window, priv->gl_config, NULL, TRUE, GDK_GL_RGBA_TYPE); + gtk_widget_set_gl_capability(widget, priv->gl_config, NULL, TRUE, GDK_GL_RGBA_TYPE); priv->gl=TRUE; } #endif @@ -767,6 +774,8 @@ g_return_if_fail(GTK_IS_MAP(widget)); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); +gc=priv->gc_waypoint; + if ((x1 > priv->buf_width_pixels) || (y1 > priv->buf_height_pixels)) return; gdk_draw_arc(widget->window, gc, FALSE, x1 - priv->draw_width, y1 - priv->draw_width, 2 * priv->draw_width, 2 * priv->draw_width, 0, 360 * 64); @@ -889,6 +898,7 @@ g_return_val_if_fail(path, FALSE); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); priv->paths=g_slist_remove(priv->paths, path); +return TRUE; } static void @@ -1404,7 +1414,7 @@ priv=GTK_MAP_GET_PRIVATE(map); gtk_map_set_center(widget, priv->center.unitx + delta_x*GTK_MAP_PAN_UNITS, priv->center.unity + delta_y*GTK_MAP_PAN_UNITS); } -static void +void gtk_map_refresh(GtkWidget *widget) { GtkMap *map; @@ -1550,7 +1560,7 @@ gtk_map_scroll_event_cb(GtkWidget *widget, GdkEventScroll *event) GtkMap *map; GtkMapPriv *priv; -g_return_if_fail(GTK_IS_MAP(widget)); +g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); @@ -1563,13 +1573,56 @@ return FALSE; static gboolean gtk_map_button_press_cb(GtkWidget *widget, GdkEventButton *event) { +GtkMap *map; +GtkMapPriv *priv; + +g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); +switch (event->button) { +case 1: + if (priv->click_to_center) { + gtk_map_set_center(widget, x2unit((gint) (event->x+0.5)), y2unit((gint) (event->y+0.5))); + return FALSE; + } else if (event->type==GDK_2BUTTON_PRESS) { + gtk_map_set_center(widget, x2unit((gint) (event->x+0.5)), y2unit((gint) (event->y+0.5))); + if (priv->zoom_in_on_2button) + gtk_map_zoom_in(widget); + return FALSE; + } +break; +case 2: + +break; +case 3: + if (priv->menu) + gtk_menu_popup(GTK_MENU(priv->menu), NULL, NULL, NULL, NULL, event->button, gtk_get_current_event_time()); +break; +} return FALSE; } static gboolean gtk_map_button_release_cb(GtkWidget *widget, GdkEventButton *event) { +GtkMap *map; +GtkMapPriv *priv; +g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); + +switch (event->button) { +case 1: + +break; +case 2: + +break; +case 3: + +break; +} return FALSE; }