]> git.etc.gen.nz Git - picture-display.git/commitdiff
First cut at adding an object for displaying notifications.
authorAndrew Ruthven <andrew@etc.gen.nz>
Sun, 21 Sep 2008 21:33:05 +0000 (09:33 +1200)
committerAndrew Ruthven <andrew@cerberus.etc.gen.nz>
Sun, 21 Sep 2008 21:33:05 +0000 (09:33 +1200)
lib/Display/Notifications.pm [new file with mode: 0644]

diff --git a/lib/Display/Notifications.pm b/lib/Display/Notifications.pm
new file mode 100644 (file)
index 0000000..934677d
--- /dev/null
@@ -0,0 +1,65 @@
+package Display::Notifications;
+
+use Clutter;
+use Set::Object;
+
+my $delay = 15;
+
+sub new {
+  my $proto = shift;
+  my $class = ref($proto) || $proto;
+
+  my $self = {};
+
+  $self->{'blocks'} = Set::Object->new();
+
+  bless ($self, $class);
+  return $self;
+}
+
+sub add {
+  my ($self, $notification) = @_;
+
+  my $block = Clutter::Group->new();
+
+  my $bg = Clutter::Rectangle->new(Clutter::Color->parse('Black'));
+  $bg->set_width($self->{'stage'}->get_width() - 40);
+  $bg->set_opacity(100);
+
+  $block->add($bg);
+  $block->add($notification);
+
+  $bg->set_height($notification->get_height() + 10);
+  $bg->set_anchor_point(1, $bg->get_height());
+  $bg->set_position(10, $self->{'stage'}->get_height() - 10);
+
+  $notification->set_anchor_point(1, $notification->get_height());
+  $notification->set_position(20, $self->{'stage'}->get_height() - 20);
+
+  my $expire = time() + $delay;
+
+  $self->{'blocks'}->add( {
+    'expire' => $expire, 
+    'block'  => $block
+  });
+
+  $self->{'stage'}->add($block);
+  my $effect = Clutter::EffectTemplate->new_for_duration(1000, 'main::smoothstep_inc');
+  my $timeline = Clutter::Effect->fade($effect, $block, 255);
+  $timeline->start();
+      
+  $self->{'stage'}->delay_add(notification_expire, $expire, $self);
+}
+
+sub expire {
+  my $self = shift;
+
+  for my $block ($self->{'blocks'}->members()) {
+    if ($block->expire <= time()) {
+      $self->{'stage'}->remove($block->{'block'});
+      $self->{'blocks'}->remove($block);
+    }
+  }
+}
+
+1;