From 9cf0603bdcc6a85445c7cf569f0a043f6b055e0b Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 5 May 2008 10:44:23 +0300 Subject: [PATCH] More map widget fixes --- src/gtkmap.c | 191 +++++++++++++++++++++++++++++---------------------- 1 file changed, 109 insertions(+), 82 deletions(-) diff --git a/src/gtkmap.c b/src/gtkmap.c index 09a5f58..3f29222 100644 --- a/src/gtkmap.c +++ b/src/gtkmap.c @@ -153,6 +153,7 @@ struct _GtkMapPriv gint show_paths; gboolean show_scale; + gboolean show_location; gboolean show_velvec; gboolean show_markers; @@ -225,6 +226,7 @@ static void gtk_map_scale_draw(GtkWidget *widget, GdkEventExpose *event); static void gtk_map_mark_draw(GtkWidget *widget, GdkEventExpose *event); static gboolean gtk_map_update_buffer_size(GtkWidget *widget, gint new_width, gint new_height); +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); @@ -351,6 +353,10 @@ priv->speed_gc=priv->speed_gc1; priv->icache=image_cache_new(64); +priv->show_scale=TRUE; +priv->show_velvec=TRUE; +priv->show_markers=TRUE; +priv->show_location=TRUE; priv->gl=FALSE; @@ -445,7 +451,7 @@ G_OBJECT_CLASS(gtk_map_parent_class)->finalize(object); } static void -gtk_map_size_allocate(GtkWidget *widget, GtkAllocation *allocation) +gtk_map_update_size(GtkWidget *widget, gint width, gint height) { GtkMap *map; GtkMapPriv *priv; @@ -454,28 +460,25 @@ guint tw, th; g_return_if_fail(GTK_IS_MAP(widget)); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); -widget->allocation = *allocation; - -g_debug("GTKMAP: Size allocate (%d, %d)", widget->allocation.width, widget->allocation.height); -if (GTK_WIDGET_REALIZED(widget)) - gdk_window_move_resize(widget->window, allocation->x, allocation->y, allocation->width, allocation->height); - -tw=GTK_MAP_TILE_SIZE_PIXELS*((widget->allocation.width/GTK_MAP_TILE_SIZE_PIXELS)+2); -th=GTK_MAP_TILE_SIZE_PIXELS*((widget->allocation.height/GTK_MAP_TILE_SIZE_PIXELS)+2); +tw=GTK_MAP_TILE_SIZE_PIXELS*((width/GTK_MAP_TILE_SIZE_PIXELS)+2); +th=GTK_MAP_TILE_SIZE_PIXELS*((height/GTK_MAP_TILE_SIZE_PIXELS)+2); gtk_map_update_buffer_size(GTK_MAP(widget), tw, th); if (!priv->buffer) { return; } +map->width=width; +map->height=height; + priv->buf_width_pixels=tw; priv->buf_height_pixels=th; priv->buf_width_tiles=priv->buf_width_pixels/GTK_MAP_TILE_SIZE_PIXELS; priv->buf_height_tiles=priv->buf_height_pixels/GTK_MAP_TILE_SIZE_PIXELS; -priv->screen_width_pixels = widget->allocation.width; -priv->screen_height_pixels = widget->allocation.height; +priv->screen_width_pixels = width; +priv->screen_height_pixels = height; priv->screen_grids_halfwidth = pixel2grid(priv->screen_width_pixels) / 2; priv->screen_grids_halfheight = pixel2grid(priv->screen_height_pixels) / 2; @@ -492,6 +495,25 @@ priv->max_center.unitx = GTK_MAP_WORLD_SIZE_UNITS - grid2unit(priv->screen_grids priv->max_center.unity = GTK_MAP_WORLD_SIZE_UNITS - grid2unit(priv->screen_grids_halfheight) - 1; } +static void +gtk_map_size_allocate(GtkWidget *widget, GtkAllocation *allocation) +{ +GtkMap *map; +GtkMapPriv *priv; + +g_return_if_fail(GTK_IS_MAP(widget)); +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); +widget->allocation = *allocation; + +g_debug("GTKMAP: Size allocate (%d, %d)", widget->allocation.width, widget->allocation.height); + +if (GTK_WIDGET_REALIZED(widget)) + gdk_window_move_resize(widget->window, allocation->x, allocation->y, allocation->width, allocation->height); + +gtk_map_update_size(widget, allocation->width, allocation->height); +} + static void gtk_map_size_request(GtkWidget *widget, GtkRequisition *requisition) { @@ -506,6 +528,7 @@ g_debug("GTKMAP: Size request"); requisition->width=GTK_MAP_TILE_SIZE_PIXELS/2; requisition->height=GTK_MAP_TILE_SIZE_PIXELS/2; +gtk_map_update_size(widget, requisition->width, requisition->height); } static gboolean @@ -523,7 +546,9 @@ priv=GTK_MAP_GET_PRIVATE(map); g_debug("GTKMAP: %s (%d, %d)", __PRETTY_FUNCTION__, new_width, new_height); if (priv->buffer==NULL) { - priv->buffer=gdk_pixmap_new(widget->window, new_width, new_height, -1); + priv->buffer=gdk_pixmap_new(widget->window, + new_widthpriv->buf_width_pixels || new_height>priv->buf_height_pixels || new_widthbuf_width_pixels-(GTK_MAP_TILE_SIZE_PIXELS*2) || new_heightbuf_height_pixels-(GTK_MAP_TILE_SIZE_PIXELS*2) ) { @@ -628,13 +653,18 @@ gdk_draw_drawable(widget->window, #if 0 gtk_map_paths_draw(widget, event); -gtk_map_markers_draw(widget, event); +if (priv->show_markers) + gtk_map_markers_draw(widget, event); -gtk_map_speed_draw(widget, event); +if (priv->show_speed) + gtk_map_speed_draw(widget, event); #endif -gtk_map_mark_draw(widget, event); -gtk_map_scale_draw(widget, event); +if (priv->show_location) + gtk_map_mark_draw(widget, event); + +if (priv->show_scale) + gtk_map_scale_draw(widget, event); return TRUE; } @@ -648,14 +678,11 @@ GtkMapPriv *priv; map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); -#if 0 -if (!priv->draw_mark) - return; -#endif - if (!gdk_rectangle_intersect(&event->area, &priv->mark_rect, &event->area)) return; +g_debug("GTKMAP: %s", __PRETTY_FUNCTION__); + #ifdef WITH_CAIRO cairo_arc(priv->ct, priv->mark_x1, priv->marky1, priv->draw_width*2, 0, 2 * M_PI); cairo_set_source_rgb(priv->ct, 1, 1, 1); @@ -721,71 +748,71 @@ g_return_if_fail(GTK_IS_MAP(widget)); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); +g_debug("GTKMAP: %s", __PRETTY_FUNCTION__); + pango_layout_set_text(priv->scale_layout, "0", -1); pango_layout_get_pixel_size(priv->scale_layout, NULL, &priv->scale_rect.height); priv->scale_rect.y = priv->screen_height_pixels - priv->scale_rect.height - 1; -gdk_rectangle_intersect(&event->area, &priv->scale_rect, &event->area); - -if (event->area.width && event->area.height) { - gdk_draw_rectangle(widget->window, - widget->style->bg_gc[GTK_WIDGET_STATE(widget)], - TRUE, priv->scale_rect.x, priv->scale_rect.y, - priv->scale_rect.width, - priv->scale_rect.height); - gdk_draw_rectangle(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - FALSE, priv->scale_rect.x, priv->scale_rect.y, - priv->scale_rect.width, - priv->scale_rect.height); - - /* Now calculate and draw the distance. */ - unit2latlon(priv->center.unitx - pixel2unit(SCALE_WIDTH / 2 - 4), priv->center.unity, lat1, lon1); - unit2latlon(priv->center.unitx + pixel2unit(SCALE_WIDTH / 2 - 4), priv->center.unity, lat2, lon2); - distance=calculate_distance(lat1, lon1, lat2, lon2) * priv->units_conv; - - if (distance < 1.f) - g_snprintf(buffer, sizeof(buffer), "%0.2f %s", distance, priv->units_str); - else if (distance < 10.f) - g_snprintf(buffer, sizeof(buffer), "%0.1f %s", distance, priv->units_str); - else - g_snprintf(buffer, sizeof(buffer), "%0.f %s", distance, priv->units_str); - - pango_layout_set_text(priv->scale_layout, buffer, -1); - pango_layout_get_pixel_size(priv->scale_layout, &width, NULL); - - /* Draw the layout itself. */ - gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + (priv->scale_rect.width - width) / 2, - priv->scale_rect.y, priv->scale_layout); - - /* Draw little hashes on the ends. */ - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + 4, - priv->scale_rect.y + priv->scale_rect.height / 2 - 4, - priv->scale_rect.x + 4, - priv->scale_rect.y + priv->scale_rect.height / 2 + 4); - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + 4, - priv->scale_rect.y + priv->scale_rect.height / 2, - priv->scale_rect.x + (priv->scale_rect.width - width) / 2 - 4, - priv->scale_rect.y + priv->scale_rect.height / 2); - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + priv->scale_rect.width - 4, - priv->scale_rect.y + priv->scale_rect.height / 2 - 4, - priv->scale_rect.x + priv->scale_rect.width - 4, - priv->scale_rect.y + priv->scale_rect.height / 2 + 4); - gdk_draw_line(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + priv->scale_rect.width - 4, - priv->scale_rect.y + priv->scale_rect.height / 2, - priv->scale_rect.x + (priv->scale_rect.width + width) / 2 + 4, - priv->scale_rect.y + priv->scale_rect.height / 2); - } +g_debug("GTKMAP: Scale (%d, %d)-(%d, %d)", priv->scale_rect.x, priv->scale_rect.y, priv->scale_rect.width, priv->scale_rect.height); + +if (!gdk_rectangle_intersect(&event->area, &priv->scale_rect, &event->area)) + return; + +gdk_draw_rectangle(widget->window, widget->style->bg_gc[GTK_WIDGET_STATE(widget)], + TRUE, priv->scale_rect.x, priv->scale_rect.y, + priv->scale_rect.width, priv->scale_rect.height); + +gdk_draw_rectangle(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + FALSE, priv->scale_rect.x, priv->scale_rect.y, + priv->scale_rect.width, priv->scale_rect.height); + +/* Now calculate and draw the distance. */ +unit2latlon(priv->center.unitx - pixel2unit(SCALE_WIDTH / 2 - 4), priv->center.unity, lat1, lon1); +unit2latlon(priv->center.unitx + pixel2unit(SCALE_WIDTH / 2 - 4), priv->center.unity, lat2, lon2); +distance=calculate_distance(lat1, lon1, lat2, lon2) * priv->units_conv; + +if (distance < 1.f) + g_snprintf(buffer, sizeof(buffer), "%0.2f %s", distance, priv->units_str); +else if (distance < 10.f) + g_snprintf(buffer, sizeof(buffer), "%0.1f %s", distance, priv->units_str); +else + g_snprintf(buffer, sizeof(buffer), "%0.f %s", distance, priv->units_str); + +pango_layout_set_text(priv->scale_layout, buffer, -1); +pango_layout_get_pixel_size(priv->scale_layout, &width, NULL); + +/* Draw the layout itself. */ +gdk_draw_layout(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + priv->scale_rect.x + (priv->scale_rect.width - width) / 2, + priv->scale_rect.y, priv->scale_layout); + +/* Draw little hashes on the ends. */ +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + priv->scale_rect.x + 4, + priv->scale_rect.y + priv->scale_rect.height / 2 - 4, + priv->scale_rect.x + 4, + priv->scale_rect.y + priv->scale_rect.height / 2 + 4); +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + priv->scale_rect.x + 4, + priv->scale_rect.y + priv->scale_rect.height / 2, + priv->scale_rect.x + (priv->scale_rect.width - width) / 2 - 4, + priv->scale_rect.y + priv->scale_rect.height / 2); +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + priv->scale_rect.x + priv->scale_rect.width - 4, + priv->scale_rect.y + priv->scale_rect.height / 2 - 4, + priv->scale_rect.x + priv->scale_rect.width - 4, + priv->scale_rect.y + priv->scale_rect.height / 2 + 4); +gdk_draw_line(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + priv->scale_rect.x + priv->scale_rect.width - 4, + priv->scale_rect.y + priv->scale_rect.height / 2, + priv->scale_rect.x + (priv->scale_rect.width + width) / 2 + 4, + priv->scale_rect.y + priv->scale_rect.height / 2); } static void -- 2.39.5