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

index 0a518bb1c3fd2a58d1c35481ee524de31ba96deb..27962a30ff3450835bb8abab992597faef9b00c9 100644 (file)
@@ -1,7 +1,7 @@
 
 BUILT_SOURCES = \
        champlain-marshal.h \
-       champlain-marshal.c
+       champlain-marshal.c 
 
 CLEANFILES = $(BUILT_SOURCES)
 
@@ -15,7 +15,9 @@ nodist_champlain_SOURCES = \
 
 champlain_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \
                                        champlain_widget.c \
-                                       launcher.c 
+                                       champlain_map.c  \
+                                       launcher.c
+                                       
 
 champlain_LDADD = $(DEPS_LIBS)
 AM_CPPFLAGS = $(DEPS_CFLAGS)
index 5551c757e3b232e1f42bac1e90264d5b81f40914..248f64783c1d23d41329e1982568f941208aa276 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef CHAMPLAIN_H
 #define CHAMPLAIN_H
 
+#include "champlain_defines.h"
 #include "champlain_widget.h"
+#include "champlain_map.h"
 
 #endif
diff --git a/src/champlain_map.c b/src/champlain_map.c
new file mode 100644 (file)
index 0000000..584846a
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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.h>
+ChamplainMap* 
+champlain_map_new (ChamplainMapSource source)
+{
+       ChamplainMap* map = g_new0(ChamplainMap, 1);
+       map->name = "OpenStreetMap";
+       map->zoom_levels = 1;
+       return map;
+}
+
+void 
+champlain_map_create_tiles(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);
+                               }
+               }
+}
diff --git a/src/champlain_map.h b/src/champlain_map.h
new file mode 100644 (file)
index 0000000..a84ea63
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+#ifndef CHAMPLAIN_MAP_H
+#define CHAMPLAIN_MAP_H
+
+#include "champlain_defines.h"
+#include "champlain_map_zoom_level.h"
+#include <glib.h>
+#include <clutter/clutter.h>
+
+typedef enum
+{
+  CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP,
+  CHAMPLAIN_MAP_SOURCE_GOOGLE
+} ChamplainMapSource;
+
+typedef struct
+{
+  int zoom_levels;
+  const gchar* name;
+  ChamplainMapZoomLevel* current_level;
+  
+} ChamplainMap;
+
+
+CHAMPLAIN_API ChamplainMap* champlain_map_new (ChamplainMapSource source);
+
+
+#endif
diff --git a/src/champlain_map_tile.h b/src/champlain_map_tile.h
new file mode 100644 (file)
index 0000000..aab6bd9
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+#ifndef CHAMPLAIN_MAP_TILE_H
+#define CHAMPLAIN_MAP_TILE_H
+
+#include <glib.h>
+#include <clutter/clutter.h>
+
+typedef struct
+{
+  ClutterActor* actor;
+  int x;
+  int y;
+  
+} ChamplainMapTile;
+
+#endif
diff --git a/src/champlain_map_zoom_level.h b/src/champlain_map_zoom_level.h
new file mode 100644 (file)
index 0000000..9a3138b
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+#ifndef CHAMPLAIN_MAP_ZOOM_LEVEL_H
+#define CHAMPLAIN_MAP_ZOOM_LEVEL_H
+
+#include <glib.h>
+#include <clutter/clutter.h>
+
+typedef struct
+{
+       int level;
+  ClutterActor* group;
+  int row_count;
+  int column_count;
+  int tile_size;
+  GPtrArray  *tiles;
+} ChamplainMapZoomLevel;
+
+#endif
diff --git a/src/champlain_private.h b/src/champlain_private.h
new file mode 100644 (file)
index 0000000..a868150
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+#ifndef CHAMPLAIN_PRIVATE_H
+#define CHAMPLAIN_PRIVATE_H
+
+void champlain_map_create_tiles(gint zoom_level);
+
+#endif
index e577ba088a34b86f6282b5f88938430197004a3b..2aaa153147ee3e8ef1705713ad6db50384d812fe 100644 (file)
 #include "config.h"
 
 #include "champlain_defines.h"
+#include "champlain_map_tile.h"
+#include "champlain_map.h"
 #include "champlain_widget.h"
 #include "champlain-marshal.h"
 
-#include <stdio.h>
+#include <math.h>
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk-clutter-embed.h>
@@ -64,6 +66,8 @@ struct _ChamplainWidgetPrivate
   // Scrolling  
   ScrollMotion position;
   ScrollMotion hitPoint;
+  
+  ChamplainMap* map;
 };
 
 
@@ -189,6 +193,55 @@ champlain_widget_init (ChamplainWidget * champlainWidget)
 
 }
 
+static void
+champlain_widget_verify_tiles (ChamplainWidget * champlainWidget)
+{
+  ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget);
+  ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed));
+  
+  // Check for tiles that left the viewport
+  ClutterColor red;
+  clutter_color_parse ("red", &red);
+  ClutterColor white;
+  clutter_color_parse ("white", &white);
+  ClutterColor blue;
+  clutter_color_parse ("blue", &blue);
+  int i;
+  /*for (i = 0; i < priv->tiles->len; i++) 
+               {
+                       int x = i % ROW_SIZE;
+                       int y = i / ROW_SIZE;
+               ClutterActor * tile = CLUTTER_ACTOR(g_ptr_array_index (priv->tiles, i));
+               ClutterUnit actor_x, actor_y, stage_w, stage_h;
+               clutter_actor_get_sizeu(stage, &stage_w, &stage_h);
+               clutter_actor_get_positionu(tile, &actor_x, &actor_y);
+               if( (actor_x + CLUTTER_UNITS_FROM_INT(TILE_SIZE) + priv->position.x < 0 || actor_x + priv->position.x > stage_w) ||
+                               (actor_y + CLUTTER_UNITS_FROM_INT(TILE_SIZE) + priv->position.y < 0 || actor_y + priv->position.y > stage_h))
+                       {
+                               //clutter_rectangle_set_color(CLUTTER_RECTANGLE(tile), &red);
+                       } 
+               else
+                       {
+                               clutter_rectangle_set_color(CLUTTER_RECTANGLE(tile), ( (y  + x) % 2 % 2 ? &blue : &white));
+                       }
+               }*/
+               
+               
+  // Check for missing tiles in the viewport
+  /*if ( priv->position.x > 0 )
+       {
+               gboolean exist = FALSE;
+                       for (i = 0; i < 20; i++) 
+                               {
+                                       ClutterActor * tile = CLUTTER_ACTOR(g_ptr_array_index (priv->tiles, i));
+                                       ClutterUnit actor_x, actor_y;
+                               clutter_actor_get_positionu(tile, &actor_x, &actor_y);
+                                       //if (actor_x < 0
+                               }
+  
+       }*/
+}
+
 static gboolean
 viewport_motion_event_cb (ClutterActor * actor, ClutterMotionEvent * event, ChamplainWidget * champlainWidget)
 {
@@ -214,6 +267,7 @@ viewport_motion_event_cb (ClutterActor * actor, ClutterMotionEvent * event, Cham
       priv->position.y += dy - priv->hitPoint.y;
 
       clutter_actor_set_positionu (priv->viewport, priv->position.x, priv->position.y);
+      champlain_widget_verify_tiles(champlainWidget);
     }
 
   return TRUE;
@@ -302,47 +356,11 @@ champlain_widget_load_map (ChamplainWidget * champlainWidget)
 {
   ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget);
 
-  ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed));
-
-  ClutterActor *viewport = clutter_group_new ();
-  clutter_actor_set_reactive (CLUTTER_ACTOR (viewport), TRUE);
-  g_signal_connect (CLUTTER_ACTOR (viewport),
-                   "captured-event", G_CALLBACK (viewport_captured_event_cb), champlainWidget);
-
-  ClutterColor white;
-  clutter_color_parse ("white", &white);
-  ClutterColor blue;
-  clutter_color_parse ("blue", &blue);
-  ClutterActor *group = clutter_group_new ();
-
-  ClutterActor *rect = clutter_rectangle_new_with_color (&blue);
-  clutter_actor_set_position (rect, 0, 0);
-  clutter_actor_set_size (rect, 100, 100);
-  clutter_actor_show (rect);
-  clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL);
-
-  rect = clutter_rectangle_new_with_color (&white);
-  clutter_actor_set_position (rect, 0, 100);
-  clutter_actor_set_size (rect, 100, 100);
-  clutter_actor_show (rect);
-  clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL);
-
-  rect = clutter_rectangle_new_with_color (&blue);
-  clutter_actor_set_position (rect, 100, 100);
-  clutter_actor_set_size (rect, 100, 100);
-  clutter_actor_show (rect);
-  clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL);
-
-  rect = clutter_rectangle_new_with_color (&white);
-  clutter_actor_set_position (rect, 100, 0);
-  clutter_actor_set_size (rect, 100, 100);
-  clutter_actor_show (rect);
-  clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL);
-
-  priv->viewport = viewport;
-  clutter_container_add (CLUTTER_CONTAINER (viewport), group, NULL);
-
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), viewport);
+       priv->map = champlain_map_new(CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP);
+       
+       champlain_map_create_tiles(priv->map, 1);
+       
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group);
 
 }
 
@@ -353,14 +371,22 @@ champlain_widget_new ()
   ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (widget);
 
   priv->clutterEmbed = gtk_clutter_embed_new ();
-  ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed));
 
+       /* Setup stage */
+  ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed));
   ClutterColor black;
   clutter_color_parse ("black", &black);
   clutter_stage_set_color (CLUTTER_STAGE (stage), &black);
   gtk_container_add (GTK_CONTAINER (widget), priv->clutterEmbed);
 
+       /* Setup viewport */
+       priv->viewport = clutter_group_new ();
+  clutter_actor_set_reactive (CLUTTER_ACTOR (priv->viewport), TRUE);
+  g_signal_connect (CLUTTER_ACTOR (priv->viewport),
+                   "captured-event", G_CALLBACK (viewport_captured_event_cb), widget);
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->viewport);
+  
   champlain_widget_load_map (widget);
-
+  
   return GTK_WIDGET (widget);
 }
index 019b5221bc2be1ea2e2b2a490e14be361956cb68..7eaeebdf92a19571a96a75d776fbf8ba6babded8 100644 (file)
@@ -25,7 +25,6 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
-
 G_BEGIN_DECLS
 #define CHAMPLAIN_TYPE_WIDGET     (champlain_widget_get_type())
 #define CHAMPLAIN_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), CHAMPLAIN_TYPE_WIDGET, ChamplainWidget))
@@ -46,7 +45,6 @@ struct _ChamplainWidgetClass
 {
   GtkBinClass parent_class;
 
-
   ChamplainWidget *(*create_widget) (ChamplainWidget * widget);
 
   void (*set_scroll_adjustments) (ChamplainWidget * widget, GtkAdjustment * hadjustment, GtkAdjustment * vadjustment);
@@ -57,4 +55,7 @@ CHAMPLAIN_API GType champlain_widget_get_type (void);
 
 CHAMPLAIN_API GtkWidget *champlain_widget_new (void);
 
+#define TILE_SIZE 100  
+#define ROW_SIZE 5 
+
 #endif