435d644272eec976397093e769bc558839871c93
[picture-display.git] / lib / Display / Plugins / Clock.pm
1 package Display::Plugins::Clock;
2
3 use Clutter;
4 use POSIX qw/strftime/;
5
6 sub new {
7   my ($class,$stage) = @_;
8
9   my $self = {
10     'stage' => $stage,
11   };
12
13   bless ($self, $class);
14   $self->init();
15   return $self;
16 }
17
18 sub display {
19   my $self = shift;
20
21   $self->{'clock'}->set_text(strftime("%H:%M %d/%m/%Y", localtime(time)));
22
23   Glib::Timeout->add_seconds(60 - strftime(%s, localtime()), $self->can('display'), $self);
24
25   return 0;
26 }
27
28 sub init {
29   my $self = shift;
30
31   $self->{'clock'} = Clutter::Label->new('Sans 20', strftime("%H:%M %d/%m/%Y", localtime(time)));
32   $self->{'clock'}->set_anchor_point($self->{'clock'}->get_width(), 1);
33   $self->{'clock'}->set_position($self->{'stage'}->get_width() - 20, 15);
34   $self->{'clock'}->set_color(Clutter::Color->parse('White'));
35
36   $self->{'bg'} = Clutter::Rectangle->new(Clutter::Color->parse('Black'));
37   $self->{'bg'}->set_width($self->{'clock'}->get_width() + 20);
38   $self->{'bg'}->set_height($self->{'clock'}->get_height() + 10);
39   $self->{'bg'}->set_anchor_point($self->{'bg'}->get_width(), 1);
40   $self->{'bg'}->set_position($self->{'stage'}->get_width() - 10, 10);
41   $self->{'bg'}->set_opacity(100);
42
43   $self->{'stage'}->add($self->{'bg'});
44   $self->{'stage'}->add($self->{'clock'});
45
46   Glib::Timeout->add_seconds(60 - strftime(%s, localtime()), $self->can('display'), $self);
47 }
48
49 1;