From 362caa84a050d202b69763e74a3a51f1a63f93a4 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 5 Aug 2008 16:14:25 +0300 Subject: [PATCH] MapWidget: Do a full buffer redraw if view is rotated or if we can't use any of the old buffer --- libs/libgtkmap/gtkmap.c | 66 +++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/libs/libgtkmap/gtkmap.c b/libs/libgtkmap/gtkmap.c index 1ed9887..f135fce 100644 --- a/libs/libgtkmap/gtkmap.c +++ b/libs/libgtkmap/gtkmap.c @@ -1,6 +1,6 @@ /* * MapWidget: Display a map - * Copyright (C) 2007 Kaj-Michael Lang + * Copyright (C) 2007-2008 Kaj-Michael Lang * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,7 +28,6 @@ * */ - #include "config.h" #include @@ -979,8 +978,10 @@ if (!priv->buffer) { } /* XXX: WTF, scale is not drawn properly with cairo without this thing slowing us down ????*/ +#if 1 g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH"); g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH"); +#endif #ifdef WITH_CAIRO cairo_save(priv->ct); @@ -1831,9 +1832,8 @@ g_debug("LOAD: %u, %u @ (%d+%d): %s", tilex, tiley, priv->zoom, zoff, buffer); pixbuf=image_cache_get(priv->icache, key, buffer); if (!pixbuf) { -#if 0 g_unlink(buffer); - +#if 0 if (_auto_download && _curr_repo->type != REPOTYPE_NONE && !((_zoom + zoff - (_curr_repo->double_size ? 1 : 0)) % _curr_repo->dl_zoom_steps)) { if (download) map_initiate_download(tilex >> zoff, tiley >> zoff, _zoom + zoff, -INITIAL_DOWNLOAD_RETRIES); @@ -1895,6 +1895,22 @@ priv->curr_repo=rd; gtk_map_refresh(widget); } + +/** + * gtk_map_render_tile: + * @widget + * @tilex + * @tiley + * @destx + * @desty + * @fast_fail + * + * Renders given tile x,y on buffer pixmap at dest x,y. If an exact tile is not found then it tries to load a + * tile for a another zoom level and scale it to match. + * If no suitable tile is found, a black box will be drawn on the buffer at dest x,y instead. + * + * Returns: TRUE if a tile is found. FALSE on error. + */ static gboolean gtk_map_render_tile(GtkWidget *widget, guint tilex, guint tiley, guint destx, guint desty, gboolean fast_fail) { @@ -1936,21 +1952,15 @@ for (zoff = (priv->curr_repo->double_size ? 1 : 0); !pixbuf && (priv->zoom + zof } if (pixbuf) { - gdk_draw_pixbuf(priv->buffer, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - pixbuf, 0, 0, destx, desty, - GTK_MAP_TILE_SIZE_PIXELS, - GTK_MAP_TILE_SIZE_PIXELS, + gdk_draw_pixbuf(priv->buffer, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + pixbuf, 0, 0, destx, desty, GTK_MAP_TILE_SIZE_PIXELS, GTK_MAP_TILE_SIZE_PIXELS, GDK_RGB_DITHER_NONE, 0, 0); g_object_unref(pixbuf); return TRUE; } -gdk_draw_rectangle(priv->buffer, - widget->style->black_gc, TRUE, - destx, desty, - GTK_MAP_TILE_SIZE_PIXELS, - GTK_MAP_TILE_SIZE_PIXELS); -return TRUE; + +gdk_draw_rectangle(priv->buffer, widget->style->black_gc, TRUE, destx, desty, GTK_MAP_TILE_SIZE_PIXELS, GTK_MAP_TILE_SIZE_PIXELS); +return FALSE; } /******************************************************************************/ @@ -2034,19 +2044,18 @@ map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); style=widget->style; -/* Assure that _center.unitx/y are bounded. */ +/* Assure that the given unitx/y are inside our world. */ BOUND(unitx, priv->min_center.unitx, priv->max_center.unitx); BOUND(unity, priv->min_center.unity, priv->max_center.unity); -priv->center.unitx = unitx; -priv->center.unity = unity; +priv->center.unitx=unitx; +priv->center.unity=unity; -new_base_tilex = grid2tile((gint) pixel2grid((gint)unit2pixel((gint) priv->center.unitx)) - (gint)priv->screen_grids_halfwidth); -new_base_tiley = grid2tile(pixel2grid(unit2pixel(priv->center.unity)) - priv->screen_grids_halfheight); +new_base_tilex=grid2tile((gint) pixel2grid((gint)unit2pixel((gint) priv->center.unitx)) - (gint)priv->screen_grids_halfwidth); +new_base_tiley=grid2tile(pixel2grid(unit2pixel(priv->center.unity)) - priv->screen_grids_halfheight); /* Same zoom level, so it's likely that we can reuse some of the old buffer's pixels. */ - -if (new_base_tilex != priv->base_tilex || new_base_tiley != priv->base_tiley) { +if ((new_base_tilex != priv->base_tilex || new_base_tiley != priv->base_tiley) && priv->rotate_view==FALSE) { /* If copying from old parts to new parts, we need to make sure we * don't overwrite the old parts when copying, so set up new_x, * new_y, old_x, old_y, iox, and ioy with that in mind. */ @@ -2102,11 +2111,17 @@ if (new_base_tilex != priv->base_tilex || new_base_tiley != priv->base_tiley) { } } } + gtk_map_recalc_offset(priv); + gtk_map_recalc_focus_base(priv); + gtk_widget_queue_draw(widget); +} else { + priv->base_tilex=new_base_tilex; + priv->base_tiley=new_base_tiley; + gtk_map_recalc_offset(priv); + gtk_map_recalc_focus_base(priv); + gtk_map_refresh(widget); } -gtk_map_recalc_offset(priv); -gtk_map_recalc_focus_base(priv); -gtk_map_refresh(widget); g_signal_emit(widget, gtk_map_signals[MAP_LOCATION_CHANGED], 0, priv->zoom); } @@ -2225,6 +2240,7 @@ return FALSE; /** * gtk_map_refresh: + * @widget * * Force a redraw of the map view. */ -- 2.39.5