[libchamplain/libchamplain-0-2: 5/12] Add an animated marker demo



commit 450c80b18038193897dabc04e4500678b86eb1a4
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date:   Mon Feb 9 22:28:02 2009 +0200

    Add an animated marker demo
    and various code clean-up to demos
---
 demos/Makefile.am       |    7 ++-
 demos/animated-marker.c |  145 +++++++++++++++++++++++++++++++++++++++++++++++
 demos/launcher.c        |   44 ++++++++-------
 3 files changed, 173 insertions(+), 23 deletions(-)

diff --git a/demos/Makefile.am b/demos/Makefile.am
index 429bc75..654ff7d 100644
--- a/demos/Makefile.am
+++ b/demos/Makefile.am
@@ -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.2.la
+
+animated_marker_SOURCES = animated-marker.c
+animated_marker_LDADD = $(DEPS_LIBS) ../champlain/libchamplain-0.2.la
diff --git a/demos/animated-marker.c b/demos/animated-marker.c
new file mode 100644
index 0000000..1e287cf
--- /dev/null
+++ b/demos/animated-marker.c
@@ -0,0 +1,145 @@
+/*
+ * 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>
+
+#define MARKER_SIZE 20
+
+/* 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_move_to (cr, MARKER_SIZE / 4.0, MARKER_SIZE / 4.0);
+  cairo_line_to (cr, MARKER_SIZE / 4.0, 3*MARKER_SIZE / 4.0);
+  cairo_line_to (cr, 3*MARKER_SIZE / 4.0, 3*MARKER_SIZE / 4.0);
+  cairo_line_to (cr, 3*MARKER_SIZE / 4.0, MARKER_SIZE / 4.0);
+  cairo_close_path (cr);
+
+  /* Fill the circle */
+  cairo_set_source_rgba (cr, 0.1, 0.1, 0.9, 1.0);
+  cairo_fill_preserve (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 (MARKER_SIZE, MARKER_SIZE);
+  cr = clutter_cairo_create (CLUTTER_CAIRO (bg));
+
+  /* Draw the circle */
+  cairo_set_source_rgb (cr, 0, 0, 0);
+  cairo_move_to (cr, MARKER_SIZE / 4.0, MARKER_SIZE / 4.0);
+  cairo_line_to (cr, MARKER_SIZE / 4.0, 3*MARKER_SIZE / 4.0);
+  cairo_line_to (cr, 3*MARKER_SIZE / 4.0, 3*MARKER_SIZE / 4.0);
+  cairo_line_to (cr, 3*MARKER_SIZE / 4.0, MARKER_SIZE / 4.0);
+  cairo_close_path (cr);
+
+  /* Stroke the circle */
+  cairo_set_line_width (cr, 1.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, 1.0, 1.0, 4.0, 4.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_MODE_KINETIC);
+  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, NULL);
+  champlain_view_center_on (CHAMPLAIN_VIEW (actor), 45.466, -73.75);
+
+  clutter_actor_show (stage);
+  clutter_main ();
+
+  return 0;
+}
diff --git a/demos/launcher.c b/demos/launcher.c
index 3f45562..55acb5d 100644
--- a/demos/launcher.c
+++ b/demos/launcher.c
@@ -24,21 +24,21 @@ static gboolean
 montreal_click (ClutterActor *actor,
                 ClutterButtonEvent *event,
                 ChamplainView * view)
-{	
-	g_print("Montreal was clicked!\n");
-	gdouble lat, lon;
-	if (champlain_view_get_coords_from_event (view, event, &lat, &lon))
-	  g_print("%f, %f \n", lat, lon);
-	return TRUE;
+{
+  g_print("Montreal was clicked!\n");
+  gdouble lat, lon;
+  if (champlain_view_get_coords_from_event (view, (ClutterEvent*)(event), &lat, &lon))
+    g_print("%f, %f \n", lat, lon);
+  return TRUE;
 }
 
 static ClutterActor*
 create_marker_layer (ChamplainView *view)
 {
   ClutterActor *layer, *marker;
-  
+
   layer = champlain_layer_new();
-  
+
   ClutterColor orange = { 0xf3, 0x94, 0x07, 0xbb };
   ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
   marker = champlain_marker_new_with_label("Montréal", "Airmole 14", NULL, NULL);
@@ -49,15 +49,15 @@ create_marker_layer (ChamplainView *view)
                     "button-release-event",
                     G_CALLBACK (montreal_click),
                     view);
-  
+
   marker = champlain_marker_new_with_label("New York", "Sans 25", &white, NULL);
   champlain_marker_set_position(CHAMPLAIN_MARKER(marker), 40.77, -73.98);
   clutter_container_add(CLUTTER_CONTAINER(layer), marker, NULL);
-  
+
   marker = champlain_marker_new_with_label("Saint-Tite-des-Caps", "Serif 12", NULL, &orange);
   champlain_marker_set_position(CHAMPLAIN_MARKER(marker), 47.130885, -70.764141);
   clutter_container_add(CLUTTER_CONTAINER(layer), marker, NULL);
-  
+
   clutter_actor_show(layer);
   return layer;
 }
@@ -66,24 +66,26 @@ int
 main (int argc, char *argv[])
 {
   ClutterActor* actor, *layer, *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_MODE_KINETIC);
-  
   champlain_view_set_size (CHAMPLAIN_VIEW (actor), 800, 600);
-  
-  layer = create_marker_layer(actor);
-  champlain_view_add_layer(CHAMPLAIN_VIEW (actor), layer);
-
   clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
-  g_object_set (G_OBJECT (actor), "zoom-level", 12, NULL);  
+
+  /* Create the markers and marker layer */
+  layer = create_marker_layer (CHAMPLAIN_VIEW (actor));
+  champlain_view_add_layer (CHAMPLAIN_VIEW (actor), layer);
+
+  /* Finish initialising the map view */
+  g_object_set (G_OBJECT (actor), "zoom-level", 12, NULL);
   champlain_view_center_on(CHAMPLAIN_VIEW(actor), 45.466, -73.75);
-  
+
   clutter_actor_show (stage);
   clutter_main ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]