From c7198c53d2da9e5a5f34ebccbdff241b23ab6057 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Thu, 18 Sep 2008 14:45:43 +1200 Subject: [PATCH] Start adding code to fade images in and out. Don't redisplay the same image. The code for fading between images is currently commented out until a bug in the Perl Clutter bindings is fixed. --- lib/Display/Plugins/FSpot.pm | 46 +++++++++++++++++++++++++++++------- picture.pl | 14 +++++++++++ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lib/Display/Plugins/FSpot.pm b/lib/Display/Plugins/FSpot.pm index 437a11d..fe3f2d2 100644 --- a/lib/Display/Plugins/FSpot.pm +++ b/lib/Display/Plugins/FSpot.pm @@ -9,7 +9,8 @@ sub new { my ($class,$stage) = @_; my $self = { - 'stage' => $stage + 'stage' => $stage, + 'last_file' => '', }; bless ($self, $class); @@ -24,11 +25,31 @@ sub display { # Keep on looking until we find a file that exists. do { $file = $self->find_photo(); - } until (-f $file); + } until (-f $file && $file ne $self->{'last_file'}); - $self->{'picture'}->set_from_file($file); + $self->{'new'}->set_from_file($file); + + if ($self->{'last_file'} eq '') { + fade_in($self->{'new'}); +# } else { +#warn "Fade out old\n"; +# my $old_effect = Clutter::EffectTemplate->new_for_duration(1000, 'smoothstep_dec' ); +# my $old = Clutter::Effect->fade($old_effect, $self->{'old'}, 0, $self->can('fade_in'), $self->{'new'}); +# $old->start(); + } + +# my $temp = $self->{'old'}; +# $self->{'old'} = $self->{'new'}; +# $self->{'new'} = $temp; + $self->{'last_file'} = $file; +} + +sub fade_in { + my $new_pic = shift; - return $file; + my $new_effect = Clutter::EffectTemplate->new_for_duration(1000, 'smoothstep_inc'); + my $new = Clutter::Effect->fade($new_effect, $new_pic, 255); + $new->start(); } sub find_photo { @@ -68,12 +89,19 @@ LIMIT 1 $self->{'sth'} = $self->{'dbh'}->prepare($sql) || die "Failed to prepare statement: $DBI::errstr\n"; - $self->{'picture'} = Clutter::Texture->new(); - $self->{'picture'}->set_size($self->{'stage'}->get_size()); - $self->{'picture'}->set('keep-aspect-ratio' => 1); - $self->{'picture'}->set('sync-size' => 1); + for my $age ('new', 'old') { + $self->{$age} = Clutter::Texture->new(); + $self->{$age}->set_size($self->{'stage'}->get_size()); + $self->{$age}->set('keep-aspect-ratio' => 1); + $self->{$age}->set('sync-size' => 1); + $self->{$age}->set_opacity(0); + } + $self->display(); - $self->{'stage'}->add($self->{'picture'}); + + for my $age ('new', 'old') { + $self->{'stage'}->add($self->{$age}); + } Glib::Timeout->add_seconds(30, $self->can('display'), $self); } diff --git a/picture.pl b/picture.pl index 9d1a71e..aee5a09 100755 --- a/picture.pl +++ b/picture.pl @@ -52,3 +52,17 @@ sub loadModules { return @modules; } +sub linear { + my $alpha = shift; + my $timeline = $alpha->get_timeline(); + + return int($timeline->get_progress() * Clutter::Alpha->MAX_ALPHA); +} + +sub smoothstep_dec { + return Clutter::Alpha->smoothstep_dec($_[0]); +} +sub smoothstep_inc { + return Clutter::Alpha->smoothstep_inc($_[0]); +} + -- 2.30.2