]> err.no Git - libchamplain/commitdiff
Add ZoomLevel and Tile
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Fri, 15 Aug 2008 02:48:41 +0000 (22:48 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Fri, 15 Aug 2008 02:48:41 +0000 (22:48 -0400)
src/Makefile.am
src/champlain_map.c
src/champlain_map_zoom_level.c [new file with mode: 0644]
src/champlain_map_zoom_level.h
src/champlain_private.h
src/champlain_widget.c

index 27962a30ff3450835bb8abab992597faef9b00c9..77d7ce5e426a4368fe18b6a3ef3842183a3fde93 100644 (file)
@@ -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
                                        
 
index 584846a7d696b8a56dfc19d3c863542267bda096..7d2ddc05d65d7629365e0a28f3c9417f2b8ac982 100644 (file)
@@ -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 (file)
index 0000000..5f68109
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@squidy.info>
+ *
+ * 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 <champlain_map_zoom_level.h>
+#include <champlain_map_tile.h>
+#include <champlain_private.h>
+#include <clutter/clutter.h>
+
+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);
+                               }
+               }
+}
index 9a3138b82616903f34a7cbe83af6376dd65bc992..e9194df8ee690851e854fe489d103e6291ec9438 100644 (file)
 typedef struct
 {
        int level;
-  ClutterActor* group;
   int row_count;
   int column_count;
   int tile_size;
+  
   GPtrArray  *tiles;
+  ClutterActor* group;
+  
 } ChamplainMapZoomLevel;
 
 #endif
index a86815059e0cff5dcaa7605754629eb7807acfa9..c986b4eef899a5e14205add31d360006dedd8264 100644 (file)
@@ -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
index 2aaa153147ee3e8ef1705713ad6db50384d812fe..bb8bfa925079bf94a4c2efa3db8eaf36f569413d 100644 (file)
@@ -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);