]> err.no Git - libchamplain/commitdiff
Port of the C demo launcher.c
authorEmmanuel Rodriguez <emmanuel.rodriguez@gmail.com>
Tue, 24 Mar 2009 18:49:24 +0000 (19:49 +0100)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 25 Mar 2009 08:06:21 +0000 (10:06 +0200)
bindings/perl/Champlain/examples/launcher.pl

index 501412e02904821751c5a1d6f433de10a9dc6a16..09bf8a98b821956d37728147a9579d4db552358a 100755 (executable)
@@ -6,10 +6,13 @@ use warnings;
 use Glib qw(TRUE FALSE);
 use Clutter qw(-threads-init -init);
 use Champlain;
-use Data::Dumper;
 use FindBin;
 use File::Spec;
 
+
+my $PADDING = 10;
+
+
 exit main();
 
 
@@ -21,8 +24,26 @@ sub main {
        # Create the map view
        my $map = Champlain::View->new();
        $map->set('scroll-mode', 'kinetic');
-#      $map->set('map-source', 'mapsforfree-relief');
        $map->set_size(800, 600);
+       $stage->add($map);
+       
+       # Create the zoom buttons
+       my $buttons = Clutter::Group->new();
+       $buttons->set_position($PADDING, $PADDING);
+       $stage->add($buttons);
+       
+       my $button = make_button("Zoom in", sub {
+               $map->zoom_in();
+       });
+       $buttons->add($button);
+       my ($width) = $button->get_size();
+       
+       $button = make_button("Zoom out", sub {
+               $map->zoom_out();
+       });
+       $buttons->add($button);
+       $button->set_position($width + $PADDING, 0);
+       
        
        # Create the markers and marker layer
        my $layer = create_marker_layer($map);
@@ -36,7 +57,6 @@ sub main {
        $map->set_reactive(TRUE);
        $map->signal_connect_after("button-release-event", \&map_view_button_release_cb, $map);
 
-       $stage->add($map);
        $stage->show_all();
        
        Clutter->main();
@@ -45,6 +65,37 @@ sub main {
 }
 
 
+#
+# Creates a button and registers the given callback. The callback will be called
+# each time that the button is clicked.
+#
+sub make_button {
+       my ($text, $callback) = @_;
+
+       my $button = Clutter::Group->new();
+
+       my $white = Clutter::Color->new(0xff, 0xff, 0xff, 0xff);
+       my $button_bg = Clutter::Rectangle->new($white);
+       $button->add($button_bg);
+       $button_bg->set_opacity(0xcc);
+
+       my $black = Clutter::Color->new(0x00, 0x00, 0x00, 0xff);
+       my $button_text = Clutter::Label->new("Sans 10", $text, $black);
+       $button->add($button_text);
+       my ($width, $height) = $button_text->get_size();
+
+       $button_bg->set_size($width + $PADDING * 2, $height + $PADDING * 2);
+       $button_bg->set_position(0, 0);
+       $button_text->set_position($PADDING, $PADDING);
+       
+       
+       $button->set_reactive(TRUE);
+       $button->signal_connect('button-release-event', $callback);
+
+       return $button;
+}
+
+
 sub create_marker_layer {
        my ($map) = @_;
        my $layer = Champlain::Layer->new();