]> err.no Git - libchamplain/commitdiff
Marker objects
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Tue, 26 Aug 2008 01:55:00 +0000 (21:55 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 6 Sep 2008 02:38:09 +0000 (22:38 -0400)
champlain/Makefile.am
champlain/champlain.h
champlain/champlain_defines.h
champlain/champlain_private.h [new file with mode: 0644]
champlain/champlainview.c
champlain/champlainview.h

index a0c3cca347f9af6f979d9ee7dc4f3577181754a9..c20263849b2817a94040e7733a1e53d5677cc114 100644 (file)
@@ -13,6 +13,7 @@ lib_LTLIBRARIES = libchamplain-1.0.la
 libchamplain_1_0_la_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \
                                        $(BUILT_SOURCES) \
                                        champlainview.c \
+                                       champlainmarker.c \
                                        map.c  \
                                        zoomlevel.c \
                                        tile.c \
@@ -35,7 +36,7 @@ champlain-marshal.c: $(CHAMPLAIN_MARSHAL_LIST)
        @GLIB_GENMARSHAL@ --body --prefix=champlain_marshal $< > $(CHAMPLAIN_MARSHAL).c
 
 libchamplain_includedir=$(includedir)/libchamplain-1.0/champlain
-libchamplain_include_HEADERS = champlain.h champlainview.h champlain_defines.h
+libchamplain_include_HEADERS = champlain.h champlainview.h champlain_defines.h champlainmarker.h
 
 libchamplain_1_0_la_LDFLAGS= -version-info $(LIBRARY_VERSION)
 
index e1380df83d8ae0f12fe0ad9c36ae3b5f81d17405..2617f73277d2d090d46671555ef9c20e79746ff1 100644 (file)
@@ -29,5 +29,6 @@
 
 #include <champlain/champlain_defines.h>
 #include <champlain/champlainview.h>
+#include <champlain/champlainmarker.h>
 
 #endif
index c03696129f99230cd246fbecdae119eadde820e5..6e133f55574c5c08bf0ff885091608d17b8a65ec 100644 (file)
 typedef struct _ChamplainView ChamplainView;
 typedef struct _ChamplainViewClass ChamplainViewClass;
 
+typedef struct _ChamplainMarker ChamplainMarker;
+typedef struct _ChamplainMarkerClass ChamplainMarkerClass;
+
 typedef struct _Map Map;
 
+#define CHAMPLAIN_PARAM_READABLE     \
+        (G_PARAM_READABLE |     \
+         G_PARAM_STATIC_NICK | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)
+
+#define CHAMPLAIN_PARAM_READWRITE    \
+        (G_PARAM_READABLE | G_PARAM_WRITABLE | \
+         G_PARAM_STATIC_NICK | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)
+         
 #endif
diff --git a/champlain/champlain_private.h b/champlain/champlain_private.h
new file mode 100644 (file)
index 0000000..b4fe8a2
--- /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_PRIVATE_H
+#define CHAMPLAIN_PRIVATE_H
+
+#include <glib.h>
+#include <gdk/gdk.h>
+
+#define CHAMPLAIN_MARKER_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_MARKER, ChamplainMarkerPrivate))
+
+struct _ChamplainMarkerPrivate
+{
+  gdouble lon;
+  gdouble lat;
+  
+  GdkPoint anchor;
+};
+
+#endif
index fbdf400a86cb42fa556c38edf546708a86e26e01..a8c47a542fcaf3e6e7bd6bfbbf1b2e032049f664 100644 (file)
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include "champlain_defines.h"
+#include "champlain_private.h"
 #include "champlain.h"
 #include "champlain-marshal.h"
 #include "champlainview.h"
@@ -61,24 +62,20 @@ static guint champlain_view_signals[LAST_SIGNAL] = { 0, };
 
 #define CHAMPLAIN_VIEW_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_VIEW, ChamplainViewPrivate))
 
-#define CHAMPLAIN_PARAM_READABLE     \
-        (G_PARAM_READABLE |     \
-         G_PARAM_STATIC_NICK | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)
-
-#define CHAMPLAIN_PARAM_READWRITE    \
-        (G_PARAM_READABLE | G_PARAM_WRITABLE | \
-         G_PARAM_STATIC_NICK | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)
-
 struct _ChamplainViewPrivate
 {
-  GtkWidget *clutterEmbed;
+  GtkWidget *clutter_embed;
   
-  ChamplainMapSource mapSource;
+  ChamplainMapSource map_source;
   gint zoomLevel; // only used when the zoom-level property is set before map is created
   
+  ClutterActor *map_layer;
   ClutterActor *viewport;
-  ClutterActor *fingerScroll;
-  GdkRectangle viewportSize;
+  ClutterActor *finger_scroll;
+  GdkRectangle viewport_size;
+  
+  ClutterActor *user_layers;
+  
   Map *map;
 
   gboolean offline;
@@ -113,15 +110,15 @@ resize_viewport(ChamplainView *champlainView)
   
   if(priv->map == NULL)
     {
-      priv->map = map_new(priv->mapSource);
+      priv->map = map_new(priv->map_source);
       map_load_level(priv->map, priv->zoomLevel);
-      clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group);
+      clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
       
       g_object_notify(G_OBJECT(champlainView), "zoom-level");
       g_object_notify(G_OBJECT(champlainView), "map-source");
     }
   
-  clutter_actor_set_size (priv->fingerScroll, priv->viewportSize.width, priv->viewportSize.height);
+  clutter_actor_set_size (priv->finger_scroll, priv->viewport_size.width, priv->viewport_size.height);
   
   
   tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (priv->viewport), &hadjust, &vadjust);
@@ -139,7 +136,7 @@ resize_viewport(ChamplainView *champlainView)
     }
   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);
   
   if (priv->map->current_level->level < 8)
@@ -183,7 +180,7 @@ champlain_view_get_property(GObject* object, guint prop_id, GValue* value, GPara
             break;
           }
         case PROP_MAP_SOURCE:
-          g_value_set_int(value, priv->mapSource);
+          g_value_set_int(value, priv->map_source);
           break;
         case PROP_OFFLINE:
           g_value_set_boolean(value, priv->offline);
@@ -250,14 +247,14 @@ champlain_view_set_property(GObject* object, guint prop_id, const GValue* value,
       case PROP_MAP_SOURCE:
         {
           ChamplainMapSource source = g_value_get_int(value);
-          if (priv->mapSource != source)
+          if (priv->map_source != source)
             {
-              priv->mapSource = source;
+              priv->map_source = source;
               if (priv->map) {
                 gint currentLevel = priv->map->current_level->level;
                 GdkPoint anchor = priv->map->current_level->anchor;
                 map_free(priv->map);
-                priv->map = map_new(priv->mapSource);
+                priv->map = map_new(priv->map_source);
                 
                 // Keep same zoom level
                 if (currentLevel > priv->map->zoom_levels)
@@ -409,7 +406,7 @@ champlain_view_init (ChamplainView *champlainView)
 {
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView);
 
-  priv->mapSource = CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP;
+  priv->map_source = CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP;
   priv->zoomLevel = 0;
   priv->offline = FALSE;
 }
@@ -426,10 +423,10 @@ viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *champla
       rect.y == priv->viewportSize.y)
       return;
 
-  priv->viewportSize.x = rect.x;
-  priv->viewportSize.y = rect.y;
+  priv->viewport_size.x = rect.x;
+  priv->viewport_size.y = rect.y;
   
-  map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline);
+  map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
   
   g_object_notify(G_OBJECT(champlainView), "longitude");
   g_object_notify(G_OBJECT(champlainView), "latitude");
@@ -440,11 +437,11 @@ view_size_allocated_cb (GtkWidget *view, GtkAllocation *allocation, ChamplainVie
 {
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView);
   
-  priv->viewportSize.width = allocation->width;
-  priv->viewportSize.height = allocation->height;
+  priv->viewport_size.width = allocation->width;
+  priv->viewport_size.height = allocation->height;
   
   resize_viewport(champlainView);
-  map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline);
+  map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
 }
 
 /**
@@ -464,17 +461,17 @@ champlain_view_new (ChamplainViewMode mode)
   view = CHAMPLAIN_VIEW (g_object_new (CHAMPLAIN_TYPE_VIEW, NULL));
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
   
-  priv->clutterEmbed = gtk_clutter_embed_new ();
-  g_signal_connect (priv->clutterEmbed,
+  priv->clutter_embed = gtk_clutter_embed_new ();
+  g_signal_connect (priv->clutter_embed,
                     "size-allocate",
                     G_CALLBACK (view_size_allocated_cb),
                     view);
 
   // Setup stage
-  stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed));
+  stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutter_embed));
   
   clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
-  gtk_container_add (GTK_CONTAINER (view), priv->clutterEmbed);
+  gtk_container_add (GTK_CONTAINER (view), priv->clutter_embed);
   
   // Setup viewport
   priv->viewport = tidy_viewport_new ();
@@ -502,6 +499,16 @@ champlain_view_new (ChamplainViewMode mode)
   clutter_container_add_actor (CLUTTER_CONTAINER (priv->fingerScroll), priv->viewport);
   clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->fingerScroll);
 
+  // Map Layer
+  priv->map_layer = clutter_group_new();
+  clutter_actor_show(priv->map_layer);
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map_layer);
+  
+  // Setup user_layers
+  priv->user_layers = clutter_group_new();
+  clutter_actor_show(priv->user_layers);
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->user_layers);
+  clutter_actor_raise(priv->user_layers, priv->map_layer);
   
   return GTK_WIDGET (view);
 }
@@ -566,7 +573,34 @@ champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdoub
   g_object_notify(G_OBJECT(champlainView), "longitude");
   g_object_notify(G_OBJECT(champlainView), "latitude");
   
-  map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline);
+  map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
+}
+
+static void 
+for_each_marker (ChamplainMarker *marker, ChamplainView* champlainView)
+{
+  ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView);
+  ChamplainMarkerPrivate *marker_priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
+  
+  gint x, y;
+  
+  x = priv->map->longitude_to_x(priv->map, marker_priv->lon, priv->map->current_level->level);
+  y = priv->map->latitude_to_y(priv->map, marker_priv->lat, priv->map->current_level->level);
+  
+  clutter_actor_set_position(CLUTTER_ACTOR(marker), x - marker_priv->anchor.x, y - marker_priv->anchor.y);
+}
+
+static void 
+for_each_layer (ClutterActor *layer, ChamplainView* champlainView)
+{
+  clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(for_each_marker), champlainView);
+}
+                                                         
+static void
+marker_reposition (ChamplainView* champlainView) 
+{
+  ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView);
+  clutter_container_foreach(CLUTTER_CONTAINER(priv->user_layers), CLUTTER_CALLBACK(for_each_layer), champlainView);
 }
 
 /**
@@ -590,11 +624,11 @@ champlain_view_zoom_in (ChamplainView *champlainView)
       clutter_container_remove_actor (CLUTTER_CONTAINER (priv->viewport), group);
       clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group);
       champlain_view_center_on(champlainView, lon, lat);
+      marker_reposition(champlainView);
       
       g_object_notify(G_OBJECT(champlainView), "zoom-level");
     }
 }
-
 /**
  * champlain_view_zoom_out:
  * @view: a #ChamplainView
@@ -616,7 +650,18 @@ champlain_view_zoom_out (ChamplainView *champlainView)
       clutter_container_remove_actor (CLUTTER_CONTAINER (priv->viewport), group);
       clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group);
       champlain_view_center_on(champlainView, lon, lat);
+      marker_reposition(champlainView);
       
       g_object_notify(G_OBJECT(champlainView), "zoom-level");
     }
 }
+
+void 
+champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer)
+{
+  ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView);
+  clutter_container_add(CLUTTER_CONTAINER(priv->user_layers), layer, NULL);
+  clutter_actor_raise_top(layer);
+  
+  marker_reposition(champlainView);
+}
index f9d1a0b6c0e20e7f2c8a094188ef9aa4c3ba8185..af55ede52ee49f9d43007bfdbf27c6a20fb5abe1 100644 (file)
@@ -24,6 +24,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
+#include <clutter/clutter.h>
 
 typedef enum
 {
@@ -38,11 +39,11 @@ typedef enum
 } ChamplainMapSource;
 
 #define CHAMPLAIN_TYPE_VIEW     (champlain_view_get_type())
-#define CHAMPLAIN_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), CHAMPLAIN_TYPE_VIEW, ChamplainView))
-#define CHAMPLAIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  CHAMPLAIN_TYPE_VIEW, ChamplainViewClass))
+#define CHAMPLAIN_VIEW(obj)     (G_TYPE_CHECK_INSTANCE_CAST((obj), CHAMPLAIN_TYPE_VIEW, ChamplainView))
+#define CHAMPLAIN_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST((klass),  CHAMPLAIN_TYPE_VIEW, ChamplainViewClass))
 #define CHAMPLAIN_IS_VIEW(obj)  (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHAMPLAIN_TYPE_VIEW))
 #define CHAMPLAIN_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  CHAMPLAIN_TYPE_VIEW))
-#define CHAMPLAIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  CHAMPLAIN_TYPE_VIEW, ChamplainViewClass))
+#define CHAMPLAIN_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  CHAMPLAIN_TYPE_VIEW, ChamplainViewClass))
 
 typedef struct _ChamplainViewPrivate ChamplainViewPrivate;
 
@@ -81,4 +82,6 @@ CHAMPLAIN_API void champlain_view_zoom_in (ChamplainView *champlainView);
 
 CHAMPLAIN_API void champlain_view_zoom_out (ChamplainView *champlainView);
 
+CHAMPLAIN_API void champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer);
+
 #endif