From: Pierre-Luc Beaudoin Date: Wed, 24 Sep 2008 09:43:37 +0000 (-0400) Subject: Sort markers X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=493607a5959ddd086e81eabe5ff055a91bba4f13;p=libchamplain Sort markers 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) --- diff --git a/champlain/Makefile.am b/champlain/Makefile.am index f111c05..e1bfd52 100644 --- a/champlain/Makefile.am +++ b/champlain/Makefile.am @@ -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 index 0000000..e9ecbf0 --- /dev/null +++ b/champlain/champlainlayer.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * 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 +#include + +/* 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 index 0000000..1bdf4cb --- /dev/null +++ b/champlain/champlainlayer.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * 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 +#include +#include + +ClutterActor *champlain_layer_new (); + +#endif diff --git a/champlain/launcher.c b/champlain/launcher.c index 5d9f928..b9dc86a 100644 --- a/champlain/launcher.c +++ b/champlain/launcher.c @@ -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 };