]> err.no Git - libchamplain/commitdiff
Reposition markers on set_position
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 6 Sep 2008 05:04:30 +0000 (01:04 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 6 Sep 2008 05:04:30 +0000 (01:04 -0400)
champlain/champlainmarker.c
champlain/champlainview.c

index cf55026963969915b5fc2cce11ea04889a8e332c..bef0329b3874cc23281f67984ba98ca2563409b3 100644 (file)
@@ -121,7 +121,7 @@ champlain_marker_class_init (ChamplainMarkerClass *champlainMarkerClass)
   *
   * The longitude coordonate of the map
   *
-  * Since: 0.3
+  * Since: 0.2
   */
   g_object_class_install_property(objectClass, PROP_LONGITUDE,
                                   g_param_spec_double("longitude",
@@ -137,7 +137,7 @@ champlain_marker_class_init (ChamplainMarkerClass *champlainMarkerClass)
   *
   * The latitude coordonate of the map
   *
-  * Since: 0.3
+  * Since: 0.2
   */
   g_object_class_install_property(objectClass, PROP_LATITUDE,
                                   g_param_spec_double("latitude",
@@ -164,7 +164,7 @@ champlain_marker_init (ChamplainMarker *champlainMarker)
  *
  * Returns a new #ChamplainWidget ready to be used as a #ClutterActor.
  *
- * Since: 0.3
+ * Since: 0.2
  */
 ClutterActor *
 champlain_marker_new ()
@@ -185,7 +185,7 @@ champlain_marker_new ()
  *
  * Positions the marker on the map at the coordinates
  *
- * Since: 0.3
+ * Since: 0.2
  */
 void
 champlain_marker_set_position (ChamplainMarker *champlainMarker, gdouble longitude, gdouble latitude)
@@ -208,7 +208,7 @@ champlain_marker_set_position (ChamplainMarker *champlainMarker, gdouble longitu
  *
  * Marks the point (x, y) as the place where the #ChamplainMarker position is at (longitude, latitude).
  *
- * Since: 0.3
+ * Since: 0.2
  */
 void 
 champlain_marker_set_anchor (ChamplainMarker *champlainMarker, gint x, gint y)
index 88e516bffead0a14d5f749c430de07241848b69e..f089a30dba82363a3cd6c5ce27fb3b1ca4a1c026 100644 (file)
@@ -101,32 +101,35 @@ viewport_get_current_latitude(ChamplainViewPrivate *priv)
 }
 
 static void 
-for_each_marker (ChamplainMarker *marker, ChamplainView* champlainView)
+marker_reposition_cb (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 - priv->map->current_level->anchor.x, 
-    y - marker_priv->anchor.y - priv->map->current_level->anchor.y);
+
+  if(priv->map)
+    {
+      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 - priv->map->current_level->anchor.x,
+        y - marker_priv->anchor.y - priv->map->current_level->anchor.y);
+    }
 }
 
 static void 
-for_each_layer (ClutterActor *layer, ChamplainView* champlainView)
+layer_reposition_cb (ClutterActor *layer, ChamplainView* champlainView)
 {
-  clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(for_each_marker), champlainView);
+  clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(marker_reposition_cb), 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);
+  clutter_container_foreach(CLUTTER_CONTAINER(priv->user_layers), CLUTTER_CALLBACK(layer_reposition_cb), champlainView);
 }
 
 static void
@@ -632,6 +635,7 @@ champlain_view_zoom_in (ChamplainView *champlainView)
       g_object_notify(G_OBJECT(champlainView), "zoom-level");
     }
 }
+
 /**
  * champlain_view_zoom_out:
  * @view: a #ChamplainView
@@ -659,6 +663,39 @@ champlain_view_zoom_out (ChamplainView *champlainView)
     }
 }
 
+static void
+notify_marker_reposition_cb(ChamplainMarker *marker, GParamSpec *arg1, ChamplainView *champlainView)
+{
+  marker_reposition_cb(marker, champlainView);
+}
+
+static void
+layer_add_marker (ClutterGroup *layer, ChamplainMarker *marker, ChamplainView *champlainView)
+{
+  g_signal_connect (marker,
+                    "notify::longitude",
+                    G_CALLBACK (notify_marker_reposition_cb),
+                    champlainView);
+}
+
+static void 
+connect_marker_notify_cb (ChamplainMarker *marker, ChamplainView* champlainView)
+{
+  g_signal_connect (marker,
+                    "notify::longitude",
+                    G_CALLBACK (notify_marker_reposition_cb),
+                    champlainView);
+}
+
+/**
+ * champlain_view_add_layer:
+ * @champlainView: a #ChamplainView
+ * @layer: a #ClutterActor
+ *
+ * Adds a new layer to the view
+ *
+ * Since: 0.2
+ */
 void 
 champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer)
 {
@@ -668,4 +705,11 @@ champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer)
   
   if(priv->map)
     marker_reposition(champlainView);
+  
+  g_signal_connect (layer,
+                    "add",
+                    G_CALLBACK (layer_add_marker),
+                    champlainView);
+
+  clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(connect_marker_notify_cb), champlainView);
 }