From 3d5d5f4e66440a393a790f57aa9be840022da7f8 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Fri, 5 Sep 2008 21:50:37 -0400 Subject: [PATCH] Fix low level zoom --- champlain/champlainview.c | 40 ++++++++++++++++++++++++--------------- champlain/map.c | 5 +++++ champlain/tile.c | 10 +++++----- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/champlain/champlainview.c b/champlain/champlainview.c index 27712dd..fbdf400 100644 --- a/champlain/champlainview.c +++ b/champlain/champlainview.c @@ -127,25 +127,33 @@ resize_viewport(ChamplainView *champlainView) tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (priv->viewport), &hadjust, &vadjust); //tidy_adjustment_get_values (hadjust, NULL, &lower, &upper, NULL, NULL, NULL); - lower = 0; if (priv->map->current_level->level < 8) - upper = zoom_level_get_width(priv->map->current_level) - priv->viewportSize.width; + { + lower = -priv->viewportSize.width / 2; + upper = zoom_level_get_width(priv->map->current_level) - priv->viewportSize.width / 2; + } else - upper = G_MAXINT16; + { + lower = 0; + upper = G_MAXINT16; + } g_object_set (hadjust, "lower", lower, "upper", upper, "step-increment", 1.0, "elastic", TRUE, NULL); //tidy_adjustment_get_values (vadjust, NULL, &lower, &upper, NULL, NULL, NULL); - lower = 0; + if (priv->map->current_level->level < 8) - upper = zoom_level_get_height(priv->map->current_level) - priv->viewportSize.height; + { + lower = -priv->viewportSize.height / 2; + upper = zoom_level_get_height(priv->map->current_level) - priv->viewportSize.height / 2; + } else - upper = G_MAXINT16; + { + lower = 0; + upper = G_MAXINT16; + } g_object_set (vadjust, "lower", lower, "upper", upper, "step-increment", 1.0, "elastic", TRUE, NULL); - - g_print("Level: %d\n", priv->map->current_level->level); - g_print("Upper: %f\n", upper); } static void @@ -413,8 +421,7 @@ viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *champla GdkPoint rect; tidy_viewport_get_origin(TIDY_VIEWPORT(priv->viewport), &rect.x, &rect.y, NULL); - if (rect.x < 0 || rect.y < 0) - return; + if (rect.x == priv->viewportSize.x && rect.y == priv->viewportSize.y) return; @@ -543,10 +550,13 @@ champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdoub } //FIXME: Inform tiles that there is a new anchor - - g_print("Anchor: %d, %d\n", anchor->x, anchor->y); - g_print("Center: %f, %f\n", x, y); - + int i; + for (i = 0; i < priv->map->current_level->tiles->len; i++) + { + Tile* tile = g_ptr_array_index(priv->map->current_level->tiles, i); + if (!tile->loading) + tile_set_position(priv->map, tile); + } tidy_viewport_set_origin(TIDY_VIEWPORT(priv->viewport), x - priv->viewportSize.width / 2.0, diff --git a/champlain/map.c b/champlain/map.c index 3538cc8..a68e03f 100644 --- a/champlain/map.c +++ b/champlain/map.c @@ -69,6 +69,11 @@ map_load_level(Map* map, gint zoom_level) void map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline) { + if (viewport.x < 0) + viewport.x = 0; + if (viewport.y < 0) + viewport.y = 0; + gint x_count = ceil((float)viewport.width / map->tile_size) + 1; gint y_count = ceil((float)viewport.height / map->tile_size) + 1; diff --git a/champlain/tile.c b/champlain/tile.c index 44f5acd..bcc4ad9 100644 --- a/champlain/tile.c +++ b/champlain/tile.c @@ -34,9 +34,9 @@ typedef struct { #define CACHE_DIR "champlain" static SoupSession * soup_session; - + void -tile_set(Map* map, Tile* tile) +tile_set_position(Map* map, Tile* tile) { clutter_actor_set_position (tile->actor, (tile->x * tile->size) - map->current_level->anchor.x, @@ -58,7 +58,7 @@ create_error_tile(Map* map, Tile* tile) { tile->actor = clutter_texture_new_from_file("error.svg", NULL); - tile_set(map, tile); + tile_set_position(map, tile); clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); tile_setup_animation(tile); @@ -159,7 +159,7 @@ file_loaded_cb (SoupSession *session, gdk_pixbuf_get_rowstride (pixbuf), 3, 0, NULL); - tile_set(map, tile); + tile_set_position(map, tile); clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); tile_setup_animation(tile); @@ -198,7 +198,7 @@ tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline) if (g_file_test (filename, G_FILE_TEST_EXISTS)) { tile->actor = clutter_texture_new_from_file(filename, NULL); - tile_set(map, tile); + tile_set_position(map, tile); clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); // Do not animate since it is local and fast -- 2.39.5