]> err.no Git - libchamplain/commitdiff
The current capital has a different color
authorEmmanuel Rodriguez <emmanuel.rodriguez@gmail.com>
Tue, 31 Mar 2009 19:26:07 +0000 (21:26 +0200)
committerEmmanuel Rodriguez <emmanuel.rodriguez@gmail.com>
Tue, 31 Mar 2009 19:26:07 +0000 (21:26 +0200)
bindings/perl/Champlain/examples/capitals.pl

index b63bd7230fc838eabf0269ff1364639310e6531f..97d6960a1c9c6fe8c456a388d3a55c6696f0e3ea 100755 (executable)
@@ -127,15 +127,39 @@ sub capital_callback {
                        $data->{current}{latitude} = $latitude;
                        $data->{current}{longitude} = $longitude;
                        printf "$name %.4f, %.4f\n", $latitude, $longitude;
+                       
+                       my $font = "Sans 15";
+                       my $layer = $data->{layer};
+                       my @markers = @{ $data->{markers} };
        
-                       my $marker = Champlain::Marker->new_with_label($name, "Sans 15", undef, undef);
-                       $marker->set_position($latitude, $longitude);
-                       if (@{ $data->{markers} } == 5) {
-                               my $old = shift @{ $data->{markers} };
-                               $data->{layer}->remove($old);
+                       # Keep only a few capitals at each iteration we remove a capital
+                       if (@markers == 5) {
+                               my $marker = shift @markers;
+                               $layer->remove($marker);
+                       }
+                       
+                       # Reset the color of the previous marker
+                       if (@markers) {
+                               # We first remove the marker
+                               my $last = pop @markers;
+                               $layer->remove($last);
+                               
+                               # And then recreate it with another color
+                               my $marker = Champlain::Marker->new_with_label($last->{name}, $font, undef, undef);
+                               $marker->set_position($last->get('latitude', 'longitude'));
+                               push @markers, $marker;
+                               $layer->add($marker);
                        }
-                       push @{ $data->{markers} }, $marker;
-                       $data->{layer}->add($marker);
+                       $data->{markers} = \@markers;
+
+                       
+                       my $white = Clutter::Color->new(0xff, 0xff, 0xff, 0xff);
+                       my $orange = Clutter::Color->new(0xf3, 0x94, 0x07, 0xbb);
+                       my $marker = Champlain::Marker->new_with_label($name, $font, $white, $orange);
+                       $marker->{name} = $name;
+                       $marker->set_position($latitude, $longitude);
+                       push @markers, $marker;
+                       $layer->add($marker);
                        $data->{map}->go_to($latitude, $longitude);
                }
        }