From: Pierre-Luc Beaudoin Date: Sat, 6 Sep 2008 01:50:37 +0000 (-0400) Subject: Fix low level zoom X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d5d5f4e66440a393a790f57aa9be840022da7f8;p=libchamplain Fix low level zoom --- 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