From ee00e2499be667f1326ff8fd4ef31c9cccb73aff Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 5 May 2008 11:08:40 +0300 Subject: [PATCH] Map widget scale draw works now --- src/gtkmap.c | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/src/gtkmap.c b/src/gtkmap.c index 3f29222..b0b7446 100644 --- a/src/gtkmap.c +++ b/src/gtkmap.c @@ -351,6 +351,8 @@ priv->draw_width=4; priv->speed=-1; priv->speed_gc=priv->speed_gc1; +priv->units_conv=1.85200; + priv->icache=image_cache_new(64); priv->show_scale=TRUE; @@ -578,12 +580,15 @@ GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); attributes.window_type=GDK_WINDOW_CHILD; attributes.x=widget->allocation.x; attributes.y=widget->allocation.y; -attributes.width=512; -attributes.height=512; +attributes.width=widget->allocation.width; +attributes.height=widget->allocation.height; attributes.wclass=GDK_INPUT_OUTPUT; -attributes.event_mask=gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK; -attributes_mask=GDK_WA_X | GDK_WA_Y; +attributes.event_mask=gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK; +attributes_mask=GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + +attributes.visual=gtk_widget_get_visual(widget); +attributes.colormap=gtk_widget_get_colormap(widget); widget->window=gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask); @@ -592,33 +597,32 @@ gdk_window_set_user_data(widget->window, widget); widget->style=gtk_style_attach(widget->style, widget->window); gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); -priv->scale_context=gtk_widget_get_pango_context(GTK_WIDGET(map)); +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(); pango_font_description_set_size(priv->scale_font, 12 * PANGO_SCALE); pango_layout_set_font_description(priv->scale_layout, priv->scale_font); /* Speed limit, over limit color */ -priv->speed_gc1=gdk_gc_new(GTK_WIDGET(map)->window); +priv->speed_gc1=gdk_gc_new(widget->window); color.red=0xffff; color.green=0; color.blue=0; gdk_gc_set_rgb_fg_color(priv->speed_gc1, &color); /* Speed limit, under limit color */ -priv->speed_gc2=gdk_gc_new(GTK_WIDGET(map)->window); +priv->speed_gc2=gdk_gc_new(widget->window); color.red=0; color.green=0x1000; color.blue=0; gdk_gc_set_rgb_fg_color(priv->speed_gc2, &color); -priv->speed_context=gtk_widget_get_pango_context(GTK_WIDGET(map)); +priv->speed_context=gtk_widget_get_pango_context(widget); priv->speed_layout=pango_layout_new(priv->speed_context); priv->speed_font=pango_font_description_new(); pango_font_description_set_size(priv->speed_font, 48 * PANGO_SCALE); pango_layout_set_font_description(priv->speed_layout, priv->speed_font); pango_layout_set_alignment(priv->speed_layout, PANGO_ALIGN_LEFT); - } static gboolean @@ -626,7 +630,6 @@ gtk_map_expose(GtkWidget *widget, GdkEventExpose *event) { GtkMap *map; GtkMapPriv *priv; -GtkStyle *style; g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); g_return_val_if_fail(event != NULL, FALSE); @@ -634,21 +637,12 @@ g_return_val_if_fail(event != NULL, FALSE); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); -g_return_val_if_fail(priv->buffer, FALSE); - g_debug("GTKMAP: expose (%d, %d)-(%d, %d)", event->area.x, event->area.y, event->area.width, event->area.height); -style=widget->style; - -gdk_draw_drawable(widget->window, - style->fg_gc[GTK_STATE_NORMAL], - priv->buffer, - event->area.x + priv->offsetx, - event->area.y + priv->offsety, - event->area.x, - event->area.y, - event->area.width, - event->area.height); +if (priv->buffer) + gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], priv->buffer, + event->area.x + priv->offsetx, event->area.y + priv->offsety, + event->area.x, event->area.y, event->area.width, event->area.height); #if 0 gtk_map_paths_draw(widget, event); @@ -678,11 +672,11 @@ GtkMapPriv *priv; map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); -if (!gdk_rectangle_intersect(&event->area, &priv->mark_rect, &event->area)) - return; - g_debug("GTKMAP: %s", __PRETTY_FUNCTION__); +if (!gdk_rectangle_intersect(&event->area, &priv->mark_rect, NULL)) + return; + #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); @@ -754,9 +748,7 @@ 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; -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)) +if (!gdk_rectangle_intersect(&event->area, &priv->scale_rect, NULL)) return; gdk_draw_rectangle(widget->window, widget->style->bg_gc[GTK_WIDGET_STATE(widget)], @@ -779,6 +771,8 @@ else if (distance < 10.f) else g_snprintf(buffer, sizeof(buffer), "%0.f %s", distance, priv->units_str); +g_debug("SCALE: %s", buffer); + pango_layout_set_text(priv->scale_layout, buffer, -1); pango_layout_get_pixel_size(priv->scale_layout, &width, NULL); -- 2.39.5