From 16fa2de8bff3e6c1591d55bd513173a0961ad9b9 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Sat, 11 Apr 2009 19:13:24 -0400 Subject: [PATCH] Have all the demos use the same markers --- demos/Makefile.am | 4 +-- demos/launcher.c | 89 +++++------------------------------------------ demos/markers.c | 71 +++++++++++++++++++++++++++++++++++++ demos/markers.h | 26 ++++++++++++++ 4 files changed, 108 insertions(+), 82 deletions(-) create mode 100644 demos/markers.c create mode 100644 demos/markers.h diff --git a/demos/Makefile.am b/demos/Makefile.am index 1d01fd8..2d539ce 100644 --- a/demos/Makefile.am +++ b/demos/Makefile.am @@ -5,7 +5,7 @@ INCLUDES = -I$(top_srcdir) AM_CPPFLAGS = $(DEPS_CFLAGS) $(WARN_CFLAGS) AM_LDFLAGS = $(DEPS_LIBS) -launcher_SOURCES = launcher.c +launcher_SOURCES = launcher.c markers.c launcher_LDADD = $(DEPS_LIBS) ../champlain/libchamplain-0.3.la animated_marker_SOURCES = animated-marker.c @@ -13,7 +13,7 @@ animated_marker_LDADD = $(DEPS_LIBS) ../champlain/libchamplain-0.3.la if ENABLE_GTK noinst_PROGRAMS += launcher-gtk -launcher_gtk_SOURCES = launcher-gtk.c +launcher_gtk_SOURCES = launcher-gtk.c markers.c launcher_gtk_CPPFLAGS = $(GTK_DEPS_CFLAGS) launcher_gtk_LDADD = $(GTK_DEPS_LIBS) $(DEPS_LIBS) \ ../champlain-gtk/libchamplain-gtk-0.3.la \ diff --git a/demos/launcher.c b/demos/launcher.c index 16edeec..f967e99 100644 --- a/demos/launcher.c +++ b/demos/launcher.c @@ -17,14 +17,14 @@ */ #include +#include "markers.h" #define PADDING 10 -ChamplainBaseMarker *markers [4]; static gboolean map_view_button_release_cb (ClutterActor *actor, - ClutterButtonEvent *event, - ChamplainView * view) + ClutterButtonEvent *event, + ChamplainView * view) { gdouble lat, lon; @@ -34,28 +34,15 @@ map_view_button_release_cb (ClutterActor *actor, g_print("Map was clicked at "); if (champlain_view_get_coords_from_event (view, (ClutterEvent*)event, &lat, &lon)) - g_print("%f, %f \n", lat, lon); - - return TRUE; -} - -static gboolean -marker_button_release_cb (ClutterActor *actor, - ClutterButtonEvent *event, - ChamplainView * view) -{ - if (event->button != 1 || event->click_count > 1) - return FALSE; - - g_print("Montreal was clicked\n"); + g_print("Map clicked at %f, %f \n", lat, lon); return TRUE; } static gboolean zoom_in (ClutterActor *actor, - ClutterButtonEvent *event, - ChamplainView * view) + ClutterButtonEvent *event, + ChamplainView * view) { champlain_view_zoom_in (view); return TRUE; @@ -63,61 +50,13 @@ zoom_in (ClutterActor *actor, static gboolean zoom_out (ClutterActor *actor, - ClutterButtonEvent *event, - ChamplainView * view) + ClutterButtonEvent *event, + ChamplainView * view) { champlain_view_zoom_out (view); return TRUE; } -static gboolean -center (ClutterActor *actor, - ClutterButtonEvent *event, - ChamplainView * view) -{ - champlain_view_ensure_markers_visible (view, markers, TRUE); - return TRUE; -} - -static ChamplainLayer * -create_marker_layer (ChamplainView *view) -{ - ClutterActor *marker; - ChamplainLayer *layer; - //ClutterColor orange = { 0xf3, 0x94, 0x07, 0xbb }; - //ClutterColor white = { 0xff, 0xff, 0xff, 0xff }; - - layer = champlain_layer_new (); - - marker = champlain_marker_new_with_text ("Montréal\nQuébec", - "Airmole 14", NULL, NULL); - champlain_marker_set_use_markup (CHAMPLAIN_MARKER (marker), TRUE); - - markers[0] = CHAMPLAIN_BASE_MARKER (marker); - champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), - 45.528178, -73.563788); - clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); - clutter_actor_set_reactive (marker, TRUE); - g_signal_connect_after (marker, "button-release-event", - G_CALLBACK (marker_button_release_cb), view); - - marker = champlain_marker_new_full ("New York", "/usr/share/icons/Tango/32x32/apps/system-users.png", NULL); - markers[1] = CHAMPLAIN_BASE_MARKER (marker); - champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), 40.77, -73.98); - clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); - - marker = champlain_marker_new_with_image ("/usr/share/icons/Tango/32x32/apps/system-users.png", NULL); - markers[2] = CHAMPLAIN_BASE_MARKER (marker); - champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), 47.130885, - -70.764141); - clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); - - markers[3] = NULL; - - clutter_actor_show (CLUTTER_ACTOR (layer)); - return layer; -} - static ClutterActor * make_button (char *text) { @@ -145,7 +84,7 @@ make_button (char *text) int main (int argc, - char *argv[]) + char *argv[]) { ClutterActor* actor, *stage, *buttons, *button; ChamplainLayer *layer; @@ -185,16 +124,6 @@ main (int argc, G_CALLBACK (zoom_out), actor); - button = make_button ("Center on markers"); - clutter_container_add_actor (CLUTTER_CONTAINER (buttons), button); - clutter_actor_set_reactive (button, TRUE); - clutter_actor_set_position (button, total_width, 0); - clutter_actor_get_size (button, &width, NULL); - total_width += width + PADDING; - g_signal_connect (button, "button-release-event", - G_CALLBACK (center), - actor); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), buttons); /* Create the markers and marker layer */ diff --git a/demos/markers.c b/demos/markers.c new file mode 100644 index 0000000..070f49e --- /dev/null +++ b/demos/markers.c @@ -0,0 +1,71 @@ +/* + * 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 Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +static gboolean +marker_button_release_cb (ClutterActor *actor, + ClutterButtonEvent *event, + ChamplainView * view) +{ + if (event->button != 1 || event->click_count > 1) + return FALSE; + + g_print("Montreal was clicked\n"); + + return TRUE; +} + +ChamplainLayer * +create_marker_layer (ChamplainView *view) +{ + ClutterActor *marker; + ChamplainLayer *layer; + + layer = champlain_layer_new (); + + marker = champlain_marker_new_with_text ("Montréal\nQuébec", + "Airmole 14", NULL, NULL); + champlain_marker_set_use_markup (CHAMPLAIN_MARKER (marker), TRUE); + + champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), + 45.528178, -73.563788); + clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); + clutter_actor_set_reactive (marker, TRUE); + g_signal_connect_after (marker, "button-release-event", + G_CALLBACK (marker_button_release_cb), view); + + marker = champlain_marker_new_full ("New York", "/usr/share/icons/gnome/32x32/emblems/emblem-generic.png", NULL); + champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), 40.77, -73.98); + clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); + + marker = champlain_marker_new_with_image ("/usr/share/icons/Tango/32x32/emblems/emblem-important.png", NULL); + champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), 47.130885, + -70.764141); + clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); + + marker = champlain_marker_new_with_image ("/usr/share/icons/Tango/32x32/emblems/emblem-urgent.png", NULL); + champlain_marker_set_draw_background (CHAMPLAIN_MARKER (marker), FALSE); + champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), 47, + -80); + clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); + + clutter_actor_show (CLUTTER_ACTOR (layer)); + return layer; +} diff --git a/demos/markers.h b/demos/markers.h new file mode 100644 index 0000000..5d1e16f --- /dev/null +++ b/demos/markers.h @@ -0,0 +1,26 @@ +/* + * 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 Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#ifndef MARKERS_H +#define MARKERS_H + +ChamplainLayer * create_marker_layer (ChamplainView *view); + +#endif -- 2.39.5