[libchamplain/libchamplain-0-4] Add the launcher demo implemented in Vala



commit f38f8562c661269daa21ea82025f9ad6949e48bb
Author: Simon Wenner <simon wenner ch>
Date:   Sun May 9 23:42:36 2010 +0200

    Add the launcher demo implemented in Vala

 bindings/vala/Makefile.am         |    4 +-
 bindings/vala/demos/.gitignore    |    2 +
 bindings/vala/demos/Makefile.am   |   16 +++++
 bindings/vala/demos/launcher.vala |  133 +++++++++++++++++++++++++++++++++++++
 bindings/vala/demos/markers.vala  |   66 ++++++++++++++++++
 configure.ac                      |   15 ++++
 6 files changed, 234 insertions(+), 2 deletions(-)
---
diff --git a/bindings/vala/Makefile.am b/bindings/vala/Makefile.am
index 608bf2b..a505be3 100644
--- a/bindings/vala/Makefile.am
+++ b/bindings/vala/Makefile.am
@@ -1,7 +1,7 @@
-SUBDIRS = champlain
+SUBDIRS = champlain demos
 
 if ENABLE_GTK
   SUBDIRS += champlain-gtk
 endif
 
-DIST_SUBDIRS = champlain champlain-gtk
+DIST_SUBDIRS = champlain champlain-gtk demos
diff --git a/bindings/vala/demos/.gitignore b/bindings/vala/demos/.gitignore
new file mode 100644
index 0000000..2cd96c0
--- /dev/null
+++ b/bindings/vala/demos/.gitignore
@@ -0,0 +1,2 @@
+*.c
+launcher
diff --git a/bindings/vala/demos/Makefile.am b/bindings/vala/demos/Makefile.am
new file mode 100644
index 0000000..f584489
--- /dev/null
+++ b/bindings/vala/demos/Makefile.am
@@ -0,0 +1,16 @@
+noinst_PROGRAMS = launcher
+
+launcher_SOURCES = \
+	launcher.vala \
+	markers.vala
+
+INCLUDES = \
+	$(LAUNCHER_CFLAGS)
+
+VALAFLAGS = \
+	--vapidir=$(srcdir)/../champlain \
+	$(LAUNCHER_PACKAGES)
+
+launcher_LDADD = \
+	$(LAUNCHER_LIBS) \
+	$(top_builddir)/champlain/libchamplain-0.4.la
diff --git a/bindings/vala/demos/launcher.vala b/bindings/vala/demos/launcher.vala
new file mode 100644
index 0000000..0391c95
--- /dev/null
+++ b/bindings/vala/demos/launcher.vala
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2010 Simon Wenner <simon wenner ch>
+ *
+ * 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
+ */
+
+using GLib;
+using Clutter;
+using Champlain;
+
+public class Launcher : GLib.Object
+{
+  private const int PADDING = 10;
+  private Champlain.View view;
+  private Clutter.Stage stage;
+
+  public Launcher ()
+  {
+    float width, total_width = 0;
+
+    stage = Clutter.Stage.get_default ();
+    stage.title = "Champlain Vala Example";
+    stage.set_size (800, 600);
+
+    /* Create the map view */
+    view = new Champlain.View ();
+    view.set_size (800, 600);
+    stage.add_actor (view);
+
+    /* Create the buttons */
+    var buttons = new Clutter.Group ();
+    buttons.set_position (PADDING, PADDING);
+
+    var button = make_button ("Zoom in");
+    buttons.add_actor (button);
+    button.reactive = true;
+    button.get_size (out width, null);
+    total_width += width + PADDING;
+    button.button_release_event.connect ((event) => {
+        view.zoom_in ();
+        return true;
+      });
+
+    button = make_button ("Zoom out");
+    buttons.add_actor (button);
+    button.reactive = true;
+    button.set_position (total_width, 0);
+    button.get_size (out width, null);
+    total_width += width + PADDING;
+    button.button_release_event.connect ((event) => {
+        view.zoom_out ();
+        return true;
+      });
+
+    stage.add_actor (buttons);
+
+    /* Create the markers and marker layer */
+    var layer = new  MarkerLayer ();
+    view.add_layer (layer);
+
+    /* Connect to the click event */
+    view.reactive = true;
+    view.button_release_event.connect (button_release_cb);
+
+    /* Finish initialising the map view */
+    view.zoom_level = 7;
+    view.scroll_mode = Champlain.ScrollMode.KINETIC;
+    view.center_on (45.466, -73.75);
+  }
+
+  public void show ()
+  {
+    stage.show ();
+  }
+
+  private bool button_release_cb (Clutter.ButtonEvent event)
+  {
+    double lat, lon;
+
+    if (event.button != 1 || event.click_count > 1)
+      return false;
+
+    if (view.get_coords_at ((uint) event.x, (uint) event.y, out lat, out lon))
+      GLib.print ("Map clicked at %f, %f \n", lat, lon);
+
+    return true;
+  }
+
+  public Clutter.Actor make_button (string text)
+  {
+    Clutter.Color white = { 0xff, 0xff, 0xff, 0xff };
+    Clutter.Color black = { 0x00, 0x00, 0x00, 0xff };
+    float width, height;
+
+    var button = new Clutter.Group ();
+
+    var button_bg = new Clutter.Rectangle.with_color (white);
+    button.add_actor (button_bg);
+    button_bg.opacity = 0xcc;
+
+    var button_text = new Clutter.Text.full ("Sans 10", text, black);
+    button.add_actor (button_text);
+    button_text.get_size (out width, out height);
+
+    button_bg.set_size (width + PADDING * 2, height + PADDING * 2);
+    button_bg.set_position (0, 0);
+    button_text.set_position (PADDING, PADDING);
+
+    return button;
+  }
+
+  public static int main (string[] args)
+  {
+    Clutter.init (ref args);
+    var launcher = new Launcher ();
+    launcher.show ();
+    Clutter.main ();
+    return 0;
+  }
+}
+
diff --git a/bindings/vala/demos/markers.vala b/bindings/vala/demos/markers.vala
new file mode 100644
index 0000000..dea5606
--- /dev/null
+++ b/bindings/vala/demos/markers.vala
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 Simon Wenner <simon wenner ch>
+ *
+ * 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
+ */
+
+using GLib;
+using Clutter;
+
+class MarkerLayer : Champlain.SelectionLayer
+{
+  public MarkerLayer ()
+  {
+    Clutter.Color orange = { 0xf3, 0x94, 0x07, 0xbb };
+    var marker = new Champlain.Marker.with_text (
+        "Montréal\n<span size=\"xx-small\">Québec</span>",
+        "Serif 14", null, null);
+    marker.set_use_markup (true);
+    marker.set_alignment (Pango.Alignment.RIGHT);
+    marker.set_color (orange);
+    marker.set_position (45.528178, -73.563788);
+    add_marker (marker);
+
+    try {
+      marker = new Champlain.Marker.from_file (
+          "/usr/share/icons/gnome/24x24/emblems/emblem-generic.png");
+    } catch (GLib.Error e) {
+      GLib.warning ("%s", e.message);
+    }
+    marker.set_text ("New York");
+    marker.set_position (40.77, -73.98);
+    add_marker (marker);
+
+    try {
+      marker = new Champlain.Marker.from_file (
+          "/usr/share/icons/gnome/24x24/emblems/emblem-important.png");
+    } catch (GLib.Error e) {
+      GLib.warning ("%s", e.message);
+    }
+    marker.set_position (47.130885, -70.764141);
+    add_marker (marker);
+
+    try {
+      marker = new Champlain.Marker.from_file (
+          "/usr/share/icons/gnome/24x24/emblems/emblem-favorite.png");
+    } catch (GLib.Error e) {
+      GLib.warning ("%s", e.message);
+    }
+    marker.set_draw_background (false);
+    marker.set_position (45.41484, -71.918907);
+    add_marker (marker);
+  }
+}
+
diff --git a/configure.ac b/configure.ac
index db2de2f..e3fd0c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -219,6 +219,20 @@ AC_ARG_ENABLE(vala,
   AC_HELP_STRING([--enable-vala],[Include vala champlain (and champlain-gtk)]),
     enable_vala=$enableval, enable_vala=no )
 
+if test x$enable_vala = xyes; then
+  AM_PROG_VALAC([0.8.0])
+
+  LAUNCHER_PACKAGES="--pkg clutter-1.0 --pkg champlain-0.4"
+  PKG_CHECK_MODULES(LAUNCHER,
+  [
+    glib-2.0,
+    clutter-1.0
+  ])
+  AC_SUBST(LAUNCHER_CFLAGS)
+  AC_SUBST(LAUNCHER_LIBS)
+  AC_SUBST(LAUNCHER_PACKAGES)
+fi
+
 AM_CONDITIONAL(ENABLE_VALA, test "x$enable_vala" = "xyes")
 
 # -----------------------------------------------------------
@@ -249,6 +263,7 @@ AC_CONFIG_FILES([Makefile
                  bindings/vala/Makefile
                  bindings/vala/champlain/Makefile
                  bindings/vala/champlain-gtk/Makefile
+                 bindings/vala/demos/Makefile
                  bindings/Makefile])
 AC_OUTPUT
 



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