]> err.no Git - libchamplain/commitdiff
Add an animated marker demo
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 11 Feb 2009 18:22:29 +0000 (20:22 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 11 Feb 2009 18:22:29 +0000 (20:22 +0200)
and various code clean-up to demos

demos/Makefile.am
demos/animated-marker.c [new file with mode: 0644]
demos/launcher.c

index 58249964e3419921ceeb950480dcdf0a89549572..fc18784ddd3648fe6e7c1832a56d4fabb252cab8 100644 (file)
@@ -1,10 +1,13 @@
 
-noinst_PROGRAMS = launcher
+noinst_PROGRAMS = launcher animated-marker
 
 INCLUDES = -I$(top_srcdir)
 
-AM_CPPFLAGS = $(DEPS_CFLAGS) 
+AM_CPPFLAGS = $(DEPS_CFLAGS)
 AM_LDFLAGS = $(DEPS_LIBS)
 
 launcher_SOURCES = launcher.c
 launcher_LDADD = $(DEPS_LIBS) ../champlain/libchamplain-0.3.la
+
+animated_marker_SOURCES = animated-marker.c
+animated_marker_LDADD = $(DEPS_LIBS) ../champlain/libchamplain-0.3.la
diff --git a/demos/animated-marker.c b/demos/animated-marker.c
new file mode 100644 (file)
index 0000000..9559750
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ *
+ * 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 <config.h>
+
+#include <champlain/champlain.h>
+#include <clutter-cairo/clutter-cairo.h>
+#include <math.h>
+
+#define MARKER_SIZE 10
+
+/* The marker is drawn with cairo.  It is composed of 1 static filled circle
+ * and 1 stroked circle animated as an echo.
+ */
+static ClutterActor*
+create_marker ()
+{
+  ClutterActor *marker;
+  ClutterColor orange = { 0xf3, 0x94, 0x07, 0xbb };
+  ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
+  ClutterActor *actor, *bg;
+  ClutterTimeline *timeline;
+  ClutterBehaviour *behaviour;
+  ClutterAlpha *alpha;
+  cairo_t *cr;
+
+  /* Create the marker */
+  marker = champlain_marker_new ();
+
+  /* Static filled cercle ----------------------------------------------- */
+  bg = clutter_cairo_new (MARKER_SIZE, MARKER_SIZE);
+  cr = clutter_cairo_create (CLUTTER_CAIRO (bg));
+
+  /* Draw the circle */
+  cairo_set_source_rgb (cr, 0, 0, 0);
+  cairo_arc (cr, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, 0, 2 * M_PI);
+  cairo_close_path (cr);
+
+  /* Fill the circle */
+  cairo_set_source_rgba (cr, 0.1, 0.1, 0.9, 1.0);
+  cairo_fill (cr);
+
+  cairo_destroy (cr);
+
+  /* Add the circle to the marker */
+  clutter_container_add_actor (CLUTTER_CONTAINER (marker), bg);
+  clutter_actor_set_anchor_point_from_gravity (bg, CLUTTER_GRAVITY_CENTER);
+  clutter_actor_set_position (bg, 0, 0);
+
+  /* Echo cercle -------------------------------------------------------- */
+  bg = clutter_cairo_new (2 * MARKER_SIZE, 2 * MARKER_SIZE);
+  cr = clutter_cairo_create (CLUTTER_CAIRO (bg));
+
+  /* Draw the circle */
+  cairo_set_source_rgb (cr, 0, 0, 0);
+  cairo_arc (cr, MARKER_SIZE, MARKER_SIZE, 0.9 * MARKER_SIZE, 0, 2 * M_PI);
+  cairo_close_path (cr);
+
+  /* Stroke the circle */
+  cairo_set_line_width (cr, 2.0);
+  cairo_set_source_rgba (cr, 0.1, 0.1, 0.7, 1.0);
+  cairo_stroke (cr);
+
+  cairo_destroy (cr);
+
+  /* Add the circle to the marker */
+  clutter_container_add_actor (CLUTTER_CONTAINER (marker), bg);
+  clutter_actor_lower_bottom (bg); /* Ensure it is under the previous circle */
+  clutter_actor_set_position (bg, 0, 0);
+  clutter_actor_set_anchor_point_from_gravity (bg, CLUTTER_GRAVITY_CENTER);
+
+  /* Animate the echo cercle */
+  timeline = clutter_timeline_new_for_duration (1000);
+  clutter_timeline_set_loop (timeline, TRUE);
+  alpha = clutter_alpha_new_full (timeline, CLUTTER_ALPHA_SINE_INC, NULL, g_object_unref);
+
+  behaviour = clutter_behaviour_scale_new (alpha, 0.5, 0.5, 2.0, 2.0);
+  clutter_behaviour_apply (behaviour, bg);
+
+  behaviour = clutter_behaviour_opacity_new (alpha, 255, 0);
+  clutter_behaviour_apply (behaviour, bg);
+
+  clutter_timeline_start (timeline);
+
+  /* Sets marker position on the map */
+  champlain_marker_set_position (CHAMPLAIN_MARKER (marker),
+      45.528178, -73.563788);
+
+  return marker;
+}
+
+int
+main (int argc, char *argv[])
+{
+  ClutterActor* actor, *layer, *marker, *stage;
+
+  g_thread_init (NULL);
+  clutter_init (&argc, &argv);
+
+  stage = clutter_stage_get_default ();
+  clutter_actor_set_size (stage, 800, 600);
+
+  /* Create the map view */
+  actor = champlain_view_new ();
+  champlain_view_set_size (CHAMPLAIN_VIEW (actor), 800, 600);
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
+
+  /* Create the marker layer */
+  layer = champlain_layer_new ();
+  clutter_actor_show (layer);
+  champlain_view_add_layer (CHAMPLAIN_VIEW (actor), layer);
+
+  /* Create a marker */
+  marker = create_marker ();
+  clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
+
+  /* Finish initialising the map view */
+  g_object_set (G_OBJECT (actor), "zoom-level", 5,
+      "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, NULL);
+  champlain_view_center_on (CHAMPLAIN_VIEW (actor), 45.466, -73.75);
+
+  clutter_actor_show (stage);
+  clutter_main ();
+
+  return 0;
+}
index 0d565bc389246a8816e41894b1f01233be5518e3..37afa6a9fbc4fbfe0c0f08c40f4df44536c0ff87 100644 (file)
@@ -29,7 +29,8 @@ map_view_button_release_cb (ClutterActor *actor,
     return;
 
   g_print("Map was clicked at ");
-  if (champlain_view_get_coords_from_event (view, (ClutterEvent*)event, &lat, &lon))
+  if (champlain_view_get_coords_from_event (view, (ClutterEvent*)event, &lat,
+         &lon))
     g_print("%f, %f \n", lat, lon);
 
   return TRUE;
@@ -78,7 +79,6 @@ create_marker_layer (ChamplainView *view)
   clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
 
   clutter_actor_show (layer);
-
   return layer;
 }
 
@@ -94,21 +94,19 @@ main (int argc,
   stage = clutter_stage_get_default ();
   clutter_actor_set_size (stage, 800, 600);
 
+  /* Create the map view */
   actor = champlain_view_new ();
-  g_object_set (G_OBJECT (actor), "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
-      "zoom-level", 12, NULL);
-  clutter_actor_set_reactive (actor, TRUE);
-  g_signal_connect_after (actor, "button-release-event",
-      G_CALLBACK (map_view_button_release_cb), actor);
-
-  champlain_view_set_size (CHAMPLAIN_VIEW (actor), 700, 500);
-  clutter_actor_set_position (actor, 50, 50);
+  champlain_view_set_size (CHAMPLAIN_VIEW (actor), 800, 600);
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
 
-  layer = create_marker_layer (actor);
-  champlain_view_add_layer(CHAMPLAIN_VIEW (actor), layer);
+  /* Create the markers and marker layer */
+  layer = create_marker_layer (CHAMPLAIN_VIEW (actor));
+  champlain_view_add_layer (CHAMPLAIN_VIEW (actor), layer);
 
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
-  champlain_view_center_on (CHAMPLAIN_VIEW(actor), 45.466, -73.75);
+  /* Finish initialising the map view */
+  g_object_set (G_OBJECT (actor), "zoom-level", 12,
+      "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, NULL);
+  champlain_view_center_on(CHAMPLAIN_VIEW(actor), 45.466, -73.75);
 
   clutter_actor_show (stage);
   clutter_main ();