BUILT_SOURCES = \
champlain-marshal.h \
- champlain-marshal.c
+ champlain-marshal.c
CLEANFILES = $(BUILT_SOURCES)
champlain_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \
champlain_widget.c \
- launcher.c
+ champlain_map.c \
+ launcher.c
+
champlain_LDADD = $(DEPS_LIBS)
AM_CPPFLAGS = $(DEPS_CFLAGS)
#ifndef CHAMPLAIN_H
#define CHAMPLAIN_H
+#include "champlain_defines.h"
#include "champlain_widget.h"
+#include "champlain_map.h"
#endif
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
#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>
// Scrolling
ScrollMotion position;
ScrollMotion hitPoint;
+
+ ChamplainMap* map;
};
}
+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)
{
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;
{
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);
}
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);
}
#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))
{
GtkBinClass parent_class;
-
ChamplainWidget *(*create_widget) (ChamplainWidget * widget);
void (*set_scroll_adjustments) (ChamplainWidget * widget, GtkAdjustment * hadjustment, GtkAdjustment * vadjustment);
CHAMPLAIN_API GtkWidget *champlain_widget_new (void);
+#define TILE_SIZE 100
+#define ROW_SIZE 5
+
#endif