From 225d27e7f51b542765c114fba0f0031dfbccc211 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 20 May 2008 16:59:18 +0300 Subject: [PATCH] MapWidget: - Add a simple rectangle on map center - Add missing methods: gtk_map_get_menu_latlon(), gtk_map_set_center_mode() --- src/gtkmap.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/gtkmap.h | 2 + 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/gtkmap.c b/src/gtkmap.c index 80b4dea..2660ae3 100644 --- a/src/gtkmap.c +++ b/src/gtkmap.c @@ -111,6 +111,7 @@ struct _GtkMapPriv gboolean gl; GdkRectangle scale_rect; + GdkRectangle center_rect; RepoData *curr_repo; @@ -179,6 +180,7 @@ struct _GtkMapPriv gboolean show_markers; gboolean show_marker_labels; gboolean show_speed; + gboolean show_center; gboolean click_to_center; gboolean zoom_in_on_2button; @@ -275,6 +277,8 @@ static void gtk_map_scale_draw(GtkWidget *widget, GdkEventExpose *event); static void gtk_map_mark_draw(GtkWidget *widget, GdkEventExpose *event); static void gtk_map_speed_draw(GtkWidget *widget, GdkEventExpose *event); +static void gtk_map_center_mark_draw(GtkWidget *widget, GdkEventExpose *event); + static void gtk_map_render_buffer(GtkWidget *widget, GdkEventExpose *event); static void gtk_map_render_markers(GtkWidget *widget, GdkEventExpose *event); static void gtk_map_render_paths(GtkWidget *widget, GdkEventExpose *event); @@ -398,8 +402,13 @@ priv->max_center.unitx=GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_hal priv->max_center.unity=GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_halfheight) - 1; BOUND(priv->center.unitx, priv->min_center.unitx, priv->max_center.unitx); BOUND(priv->center.unity, priv->min_center.unity, priv->max_center.unity); -priv->base_tilex = grid2tile((gint) pixel2grid((gint) unit2pixel((gint) priv->center.unitx)) - (gint) priv->screen_grids_halfwidth); -priv->base_tiley = grid2tile(pixel2grid(unit2pixel(priv->center.unity)) - priv->screen_grids_halfheight); +priv->base_tilex=grid2tile((gint) pixel2grid((gint) unit2pixel((gint) priv->center.unitx)) - (gint) priv->screen_grids_halfwidth); +priv->base_tiley=grid2tile(pixel2grid(unit2pixel(priv->center.unity)) - priv->screen_grids_halfheight); + +priv->center_rect.x=(priv->screen_width_pixels/2)-8; +priv->center_rect.y=(priv->screen_height_pixels/2)-8; +priv->center_rect.width=16; +priv->center_rect.height=16; } /******************************************************************************/ @@ -497,6 +506,7 @@ priv->show_scale=TRUE; priv->show_velvec=TRUE; priv->show_markers=TRUE; priv->show_location=TRUE; +priv->show_center=TRUE; priv->button_down=FALSE; priv->click_to_center=FALSE; @@ -530,7 +540,7 @@ priv=GTK_MAP_GET_PRIVATE(map); switch (prop_id) { case PROP_CENTER_MODE: - priv->center_mode=g_value_get_int(value); + gtk_map_set_center_mode(map, g_value_get_int(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -823,6 +833,12 @@ color.green=0; color.blue=0xffff; gdk_gc_set_rgb_fg_color(priv->gc_break, &color); +priv->gc_mark=gdk_gc_new(widget->window); +color.red=0; +color.green=0; +color.blue=0xffff; +gdk_gc_set_rgb_fg_color(priv->gc_mark, &color); + g_signal_connect(G_OBJECT(map), "button_press_event", G_CALLBACK(gtk_map_button_press_cb), NULL); g_signal_connect(G_OBJECT(map), "button_release_event",G_CALLBACK(gtk_map_button_release_cb), NULL); g_signal_connect(G_OBJECT(map), "scroll_event", G_CALLBACK(gtk_map_scroll_event_cb), NULL); @@ -908,7 +924,7 @@ g_return_val_if_fail(event != NULL, FALSE); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); -g_debug("Expose"); +g_debug("Expose: %d,%d %d,%d", event->area.x, event->area.y, event->area.width, event->area.height); #ifdef WITH_CAIRO priv->ct=gdk_cairo_create(widget->window); @@ -931,6 +947,9 @@ if (priv->show_location) if (priv->show_scale) gtk_map_scale_draw(widget, event); +if (priv->show_center) + gtk_map_center_mark_draw(widget, event); + #ifdef WITH_CAIRO cairo_destroy(priv->ct); priv->ct=NULL; @@ -1095,6 +1114,33 @@ g_object_unref(path); return TRUE; } +static void +gtk_map_center_mark_draw(GtkWidget *widget, GdkEventExpose *event) +{ +GtkMap *map; +GtkMapPriv *priv; + +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); + +g_debug("CenterMark: %d %d %d %d", priv->center_rect.x, priv->center_rect.y, priv->center_rect.width, priv->center_rect.height); + +if (!gdk_rectangle_intersect(&event->area, &priv->center_rect, NULL)) + return; + +#ifdef WITH_CAIRO +cairo_save(priv->ct); +cairo_rectangle(priv->ct, priv->center_rect.x, priv->center_rect.y, priv->center_rect.width, priv->center_rect.height); +cairo_set_source_rgb(priv->ct, 0.8, 0.8, 1); +cairo_fill_preserve(priv->ct); +cairo_set_source_rgba(priv->ct, 1, 1, 1, 0.5); +cairo_stroke(priv->ct); +cairo_restore(priv->ct); +#else +gdk_draw_rectangle(widget->window, priv->gc_mark, FALSE, priv->center_rect.x, priv->center_rect.y, priv->center_rect.width, priv->center_rect.height); +#endif +} + static void gtk_map_mark_draw(GtkWidget *widget, GdkEventExpose *event) { @@ -1691,6 +1737,40 @@ return TRUE; /******************************************************************************/ +gboolean +gtk_map_set_center_mode(GtkWidget *widget, GtkMapCenterMode mode) +{ +GtkMap *map; +GtkMapPriv *priv; +GtkMapCenterMode omode; + +g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); + +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); + +omode=priv->center_mode; + +/* If we have a track, then we can center on it */ +if (priv->current_track) { + priv->center_mode=mode; + if (omode!=mode) + g_signal_emit(widget, gtk_map_signals[MAP_CENTER_MODE_CHANGED], 0, NULL); + return TRUE; +} else if (mode==CENTER_MANUAL) { + priv->center_mode=mode; + if (omode!=mode) + g_signal_emit(widget, gtk_map_signals[MAP_CENTER_MODE_CHANGED], 0, NULL); + return TRUE; +} else { + priv->center_mode=CENTER_MANUAL; + if (omode!=CENTER_MANUAL) + g_signal_emit(widget, gtk_map_signals[MAP_CENTER_MODE_CHANGED], 0, NULL); + return FALSE; +} + +} + void gtk_map_set_center(GtkWidget *widget, guint unitx, guint unity) { @@ -1701,7 +1781,7 @@ gint new_base_tilex, new_base_tiley; guint new_x, new_y; guint j, k, base_new_x, base_old_x, old_x, old_y, iox, ioy; -g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); +g_return_if_fail(GTK_IS_MAP(widget)); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); @@ -2007,6 +2087,20 @@ g_object_unref(priv->menu); priv->menu=NULL; } +void +gtk_map_get_menu_latlon(GtkWidget *widget, gdouble *lat, gdouble *lon) +{ +GtkMap *map; +GtkMapPriv *priv; + +g_return_if_fail(GTK_IS_MAP(widget)); +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); + +*lat=priv->menu_lat; +*lat=priv->menu_lon; +} + /******************************************************************************/ void diff --git a/src/gtkmap.h b/src/gtkmap.h index 2bfbe91..29fd9e6 100644 --- a/src/gtkmap.h +++ b/src/gtkmap.h @@ -115,6 +115,8 @@ void gtk_map_get_center(GtkWidget *map, guint *unitx, guint *unity); void gtk_map_set_center_latlon(GtkWidget *map, gdouble lat, gdouble lon); void gtk_map_get_center_latlon(GtkWidget *map, gdouble *lat, gdouble *lon); +gboolean gtk_map_set_center_mode(GtkWidget *widget, GtkMapCenterMode mode); + void gtk_map_pan(GtkWidget *map, gint delta_unitx, gint delta_unity); /* Map rotation */ -- 2.39.5