]> err.no Git - libchamplain/commitdiff
Sort markers
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Wed, 24 Sep 2008 09:43:37 +0000 (05:43 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Wed, 24 Sep 2008 09:43:37 +0000 (05:43 -0400)
Markers ought to be sorted so that they overlap in a nice way to
produce a false 3D plane (with north being far and south being close)

champlain/Makefile.am
champlain/champlainlayer.c [new file with mode: 0644]
champlain/champlainlayer.h [new file with mode: 0644]
champlain/launcher.c

index f111c0595f2c02611016ab7a4bcf5ce6a55c6826..e1bfd52b921f5092d009cf1d4da74c3e2e74aec7 100644 (file)
@@ -13,6 +13,7 @@ lib_LTLIBRARIES = libchamplain-1.0.la
 libchamplain_1_0_la_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \
                                        $(BUILT_SOURCES) \
                                        champlainview.c \
+                                       champlainlayer.c \
                                        champlainmarker.c \
                                        map.c  \
                                        zoomlevel.c \
@@ -26,7 +27,7 @@ libchamplain_1_0_la_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \
                                        sources/debugmap.c
 
 noinst_HEADERS = champlainview.h \
-                                       champlainmarker.h \
+                                       champlainmarker.c \
                                        champlain_private.h \
                                        map.h  \
                                        zoomlevel.h \
@@ -48,7 +49,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 champlainmarker.h
+libchamplain_include_HEADERS = champlain.h champlainview.h champlain_defines.h champlainlayer.h champlainmarker.h
 
 libchamplain_1_0_la_LDFLAGS= -version-info $(LIBRARY_VERSION)
 
diff --git a/champlain/champlainlayer.c b/champlain/champlainlayer.c
new file mode 100644 (file)
index 0000000..e9ecbf0
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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 "config.h"
+
+#include "champlain_defines.h"
+
+#include <clutter/clutter.h>
+#include <glib.h>
+
+/* This callback serves to keep the markers ordered by their latitude.
+ * Markers that are up north on the map should be lowered in the list so that
+ * they are drawn the first. This is to make the illusion of a semi-3d plane
+ * where the most north you are, the farther you are.
+ */
+static void
+layer_add_cb (ClutterGroup *layer, ClutterActor *marker, gpointer data)
+{
+
+  GList* markers = clutter_container_get_children (CLUTTER_CONTAINER(layer));
+  gint size, i;
+  gdouble y, tmp_y, low_y;
+  ChamplainMarker *lowest = NULL;
+
+  size = g_list_length (markers);
+  g_object_get(G_OBJECT(marker), "latitude", &y, NULL);
+  y = 90 - y;
+  low_y = G_MAXDOUBLE;
+
+  for (i = 0; i < size; i++)
+    {
+      ChamplainMarker *prev_marker = (ChamplainMarker*) g_list_nth_data (markers, i);
+      g_object_get(G_OBJECT(prev_marker), "latitude", &tmp_y, NULL);
+      tmp_y = 90 - tmp_y;
+
+      if (prev_marker == marker)
+        continue;
+
+      if (y < tmp_y && tmp_y < low_y)
+        {
+          lowest = prev_marker;
+          low_y = tmp_y;
+        }
+    }
+
+  if (lowest)
+    clutter_container_lower_child(CLUTTER_CONTAINER(layer), CLUTTER_ACTOR(marker), CLUTTER_ACTOR(lowest));
+}
+
+
+/**
+ * champlain_layer_new:
+ *
+ * Returns a new #ClutterActor ready to be used as a #ClutterContainer for the markers.
+ *
+ * Since: 0.2.2
+ */
+ClutterActor *
+champlain_layer_new ()
+{
+  ClutterGroup *layer;
+
+  layer = clutter_group_new();
+  g_signal_connect_after(G_OBJECT(layer), "actor-added", G_CALLBACK(layer_add_cb), NULL);
+
+  return layer;
+}
diff --git a/champlain/champlainlayer.h b/champlain/champlainlayer.h
new file mode 100644 (file)
index 0000000..1bdf4cb
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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_LAYER_H
+#define CHAMPLAIN_LAYER_H
+
+#include <champlain/champlain_defines.h>
+#include <glib-object.h>
+#include <clutter/clutter.h>
+
+ClutterActor *champlain_layer_new ();
+
+#endif
index 5d9f928ae79ec4eefbb139cee01191be9f3ed623..b9dc86a790e420c50e2ba82d21bd681f3d342de4 100644 (file)
@@ -26,7 +26,7 @@ create_marker_layer ()
 {
   ClutterActor *layer, *marker;
   
-  layer = clutter_group_new();
+  layer = champlain_layer_new();
   
   ClutterColor orange = { 0xf3, 0x94, 0x07, 0xbb };
   ClutterColor white = { 0xff, 0xff, 0xff, 0xff };