]> git.etc.gen.nz Git - picture-display.git/commitdiff
Start adding code to fade images in and out. Don't redisplay the same image.
authorAndrew Ruthven <puck@catalyst.net.nz>
Thu, 18 Sep 2008 02:45:43 +0000 (14:45 +1200)
committerAndrew Ruthven <puck@dirk.wgtn.cat-it.co.nz>
Thu, 18 Sep 2008 02:45:43 +0000 (14:45 +1200)
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
picture.pl

index 437a11df8d6aec29ec5a121caf7f6b689a945717..fe3f2d22a8c3dcb7b9a764c1f1e0dd5b0cf2ba14 100644 (file)
@@ -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);
 }
index 9d1a71ecb2c6107b478db1cafa4ab9a8cf74c70c..aee5a09d107b95eaecaa0c639e1916044bc65a71 100755 (executable)
@@ -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]);
+}
+