Permalink
Browse files

rewrote slider to write on a single surface that can be used by Layer…

…Manager. Still broken
  • Loading branch information...
1 parent cd05ec4 commit 251d56f22f9811f44dcbff3bb485ed99ae5b62e3 @dod38fr committed May 13, 2012
View
@@ -2,6 +2,10 @@ package SDLx::SlideShow;
use Any::Moose;
use 5.10.1 ;
+use Carp;
+use SDL ;
+use SDLx::Surface;
+use SDL::Color ;
has slideshow_class => (
is => 'rw',
@@ -29,19 +33,36 @@ sub _new_image {
return unless defined $old_image ;
if ($new_image->w ne $old_image->w or $new_image->h ne $old_image->h) {
- say "building new slider" ;
- $self->{slider} = $self->_build_slider ;
+ croak "new image does not match old image size" ;
}
else {
$self->slider->image($new_image) ;
}
}
+# slider's tick method will blit on this surface
+has surface => (
+ is => 'ro',
+ isa => 'SDLx::Surface',
+ lazy => 1 ,
+ builder => '_build_surface' ,
+);
+
+sub _build_surface {
+ my $self = shift;
+
+ my $s = SDLx::Surface->new( width => $self->width, height => $self->height);
+ SDL::Video::set_color_key( $s, 0, 0 );
+ SDL::Video::set_alpha($s, SDL_RLEACCEL, 0);
+ $self->image->blit($s) ;
+ return $s ;
+}
+
has 'slider' => (
is => 'ro',
isa => 'SDLx::SlideShow::Any',
- handles => [ qw/transition busy/ ] ,
+ handles => [ qw/tick busy/ ] ,
lazy => 1,
builder => '_build_slider' ,
);
@@ -60,7 +81,7 @@ sub _build_slider {
die "Could not parse $file_to_load: $@\n";
}
- $slide_class->new( image => $self->image ) ;
+ $slide_class->new( image => $self->image , surface => $self->surface ) ;
}
View
@@ -17,22 +17,13 @@ use Any::Moose '::Util::TypeConstraints' ;
has max_steps => ( is => 'rw', isa => 'Int', default => 26 );
-has _bg_frame => (
+# tick method will draw on this surface
+has surface => (
is => 'ro',
isa => 'SDLx::Surface',
- lazy => 1,
- builder => '_build_bg_frame',
+ required => 1,
);
-sub _build_bg_frame {
- my $self = shift ;
- my $s = SDLx::Surface->new( width => $self->width, height => $self->height);
- SDL::Video::set_color_key( $s, 0, 0 );
- SDL::Video::set_alpha($s, SDL_RLEACCEL, 0);
- $self->image->blit($s) ;
- return $s ;
-}
-
has image => (
is => 'rw',
isa => 'SDLx::Surface',
@@ -57,6 +48,7 @@ has step => (
sub start {
my $self = shift;
+ say "start ",ref($self) ;
$self->step( 1 ) ;
}
@@ -66,20 +66,21 @@ sub _new_image {
$old->draw($self->_bg_frame->surface);
}
-sub transition {
+sub tick {
my $self = shift;
if ( $self->busy ) {
my $alpha = $self->progress( 0xFF ) ;
say "alpha $alpha, other ", 0xff - $alpha ;
- my $transition = SDLx::Surface->new( width=> $self->width, height=> $self->height) ;
+ my $transition = $self->surface; #SDLx::Surface->new( width=> $self->width, height=> $self->height) ;
$self->image->alpha($alpha) ;
$self->_bg_frame->alpha(0xff - $alpha) ;
# draw fading image on frame
$self->_bg_frame->surface->blit( $transition);
$self->image ->surface->blit( $transition);
+ $transition->update ;
$self->inc_step;
return $transition ;
@@ -18,7 +18,7 @@ use Any::Moose '::Util::TypeConstraints' ;
extends 'SDLx::SlideShow::Any' ;
-sub transition {
+sub tick {
my $self = shift;
if ($self->busy) {
@@ -28,12 +28,12 @@ sub transition {
my $slide_width = int( $self->width / $max_s ) + 1 ;
my $rect_to_blit = [ $slide_mark,0, $slide_width, $self->height ] ;
- $self->image->blit($self->_bg_frame, $rect_to_blit, $rect_to_blit) ;
- $self->_bg_frame->update ;
+ $self->image->blit($self->surface, $rect_to_blit, $rect_to_blit) ;
+ $self->surface->update ;
$self->inc_step ;
}
- return $self->_bg_frame ;
+ return $self->surface ;
}
__PACKAGE__->meta->make_immutable();
@@ -18,6 +18,13 @@ use Any::Moose '::Util::TypeConstraints' ;
extends 'SDLx::SlideShow::Any' ;
+has _bg_frame => (
+ is => 'ro',
+ isa => 'SDLx::Surface',
+ lazy => 1,
+ builder => '_build_bg_frame',
+);
+
sub _build_bg_frame {
my $self = shift ;
my $s = SDLx::Surface->new( width => 2 * $self->width, height => $self->height);
@@ -45,20 +52,19 @@ sub _new_image {
$self->SUPER::_new_image(@_) ;
}
-sub transition {
+sub tick {
my $self = shift;
if ($self->busy) {
- my $transition = SDLx::Surface->new( width=> $self->width, height=> $self->height) ;
- SDL::Video::set_alpha($transition, SDL_RLEACCEL, 0xff);
+ SDL::Video::set_alpha($self->surface, SDL_RLEACCEL, 0xff);
my $slide_mark = $self->progress( $self->width ) ;
- $self->_bg_frame->blit($transition,
+ $self->_bg_frame->blit($self->surface,
[ $slide_mark,0, $self->width + $slide_mark, $self->height ], # source
) ;
- $self->_bg_frame->update ;
+ $self->surface->update ;
$self->inc_step ;
- return $transition ;
+ return $self->surface ;
}
else {
return $self->image ;
View
@@ -31,7 +31,7 @@ while (@slides < 5) {
push @slides, $slide_in;
}
-my $test_only = shift @ARGV ;
+my $test_only = shift @ARGV || '';
# my $slider = SDLx::Slider->new(image => $app) ;
foreach my $s_file (glob("lib/SDLx/SlideShow/*.pm")) {
@@ -42,7 +42,7 @@ foreach my $s_file (glob("lib/SDLx/SlideShow/*.pm")) {
my $s_class = $s_file ;
next if $s_class =~ m!/Any.pm$!;
- say "test $test_only" ;
+ say "test $test_only" if $test_only;
next if $test_only and ($s_class !~ /$test_only/i) ;
$s_class =~ s!.*/!!;
$s_class =~ s!\.pm$!! ;
@@ -53,7 +53,8 @@ foreach my $s_file (glob("lib/SDLx/SlideShow/*.pm")) {
while (@l_slides){
foreach my $i (1.. 30) {
- $slider ->transition ->blit($app) ;
+ $slider ->tick;
+ $slider->surface ->blit($app) ;
$app->sync;
SDL::delay(10) ;
}

0 comments on commit 251d56f

Please sign in to comment.