From: Pierre-Luc Beaudoin Date: Fri, 15 Aug 2008 02:48:41 +0000 (-0400) Subject: Add ZoomLevel and Tile X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f10d833528dec0b213f12248945867098f460e6e;p=libchamplain Add ZoomLevel and Tile --- diff --git a/src/Makefile.am b/src/Makefile.am index 27962a3..77d7ce5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,6 +16,8 @@ nodist_champlain_SOURCES = \ champlain_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \ champlain_widget.c \ champlain_map.c \ + champlain_map_zoom_level.c \ + champlain_map_tile.c \ launcher.c diff --git a/src/champlain_map.c b/src/champlain_map.c index 584846a..7d2ddc0 100644 --- a/src/champlain_map.c +++ b/src/champlain_map.c @@ -29,37 +29,8 @@ champlain_map_new (ChamplainMapSource source) } void -champlain_map_create_tiles(ChamplainMap* map, gint zoom_level) +champlain_map_load(ChamplainMap* map, gint zoom_level) { - if (zoom_level == 1) - { - map->current_level = g_new0(ChamplainMapZoomLevel, 1); - map->current_level->level = zoom_level; - map->current_level->row_count = 5; - map->current_level->column_count = 4; - map->current_level->tile_size = 200; - map->current_level->tiles = g_ptr_array_sized_new (20); - map->current_level->group = clutter_group_new (); - - ClutterColor white; - clutter_color_parse ("white", &white); - ClutterColor blue; - clutter_color_parse ("blue", &blue); - - int i; - for (i = 0; i < 20; i++) - { - int x = i % map->current_level->row_count; - int y = i / map->current_level->row_count; - - ClutterColor * color = ( (y + x) % 2 ? &blue : &white); - ClutterActor * tile = clutter_rectangle_new_with_color (color); - clutter_actor_set_position (tile, x * map->current_level->tile_size, y * map->current_level->tile_size); - clutter_actor_set_size (tile, map->current_level->tile_size, map->current_level->tile_size); - clutter_actor_show (tile); - - clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile, NULL); - g_ptr_array_add (map->current_level->tiles, tile); - } - } + map->current_level = champlain_map_zoom_level_new(zoom_level, 5, 4, 200); + champlain_map_zoom_level_create(map->current_level, zoom_level); } diff --git a/src/champlain_map_zoom_level.c b/src/champlain_map_zoom_level.c new file mode 100644 index 0000000..5f68109 --- /dev/null +++ b/src/champlain_map_zoom_level.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +ChamplainMapZoomLevel* +champlain_map_zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size) +{ + ChamplainMapZoomLevel* level = g_new0(ChamplainMapZoomLevel, 1); + + level->level = zoom_level; + level->row_count = row; + level->column_count = column; + level->tile_size = tile_size; + level->tiles = g_ptr_array_sized_new (row * column); + level->group = clutter_group_new (); + + return level; +} + +void +champlain_map_zoom_level_create(ChamplainMapZoomLevel* level, gint zoom_level) +{ + if (zoom_level == 1) + { + ClutterColor white; + clutter_color_parse ("white", &white); + ClutterColor blue; + clutter_color_parse ("blue", &blue); + + int i; + for (i = 0; i < 20; i++) + { + int x = i % level->row_count; + int y = i / level->row_count; + + ChamplainMapTile* tile = champlain_map_tile_new(x, y); + clutter_actor_set_position (tile->actor, x * level->tile_size, y * level->tile_size); + clutter_actor_set_size (tile->actor, level->tile_size, level->tile_size); + + clutter_container_add (CLUTTER_CONTAINER (level->group), tile->actor, NULL); + g_ptr_array_add (level->tiles, tile); + } + } +} diff --git a/src/champlain_map_zoom_level.h b/src/champlain_map_zoom_level.h index 9a3138b..e9194df 100644 --- a/src/champlain_map_zoom_level.h +++ b/src/champlain_map_zoom_level.h @@ -26,11 +26,13 @@ typedef struct { int level; - ClutterActor* group; int row_count; int column_count; int tile_size; + GPtrArray *tiles; + ClutterActor* group; + } ChamplainMapZoomLevel; #endif diff --git a/src/champlain_private.h b/src/champlain_private.h index a868150..c986b4e 100644 --- a/src/champlain_private.h +++ b/src/champlain_private.h @@ -23,4 +23,8 @@ void champlain_map_create_tiles(gint zoom_level); +ChamplainMapZoomLevel* champlain_map_zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size); + +ChamplainMapTile* champlain_map_tile_new(gint x, gint y); + #endif diff --git a/src/champlain_widget.c b/src/champlain_widget.c index 2aaa153..bb8bfa9 100644 --- a/src/champlain_widget.c +++ b/src/champlain_widget.c @@ -358,7 +358,7 @@ champlain_widget_load_map (ChamplainWidget * champlainWidget) priv->map = champlain_map_new(CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP); - champlain_map_create_tiles(priv->map, 1); + champlain_map_load(priv->map, 1); clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group);