Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perltidy

  • Loading branch information...
commit 05989be043db0154c66c1dfc151bd5a0ae6f6214 1 parent 468e319
@kthakore kthakore authored
View
659 Build.PL
@@ -41,335 +41,336 @@ eval "require $package" or croak "Require '$package' failed: $@\n";
# <to> = location of build file to get name right
# <libraries> = list reqiured libraries, names the same as keys to hash %libraries
my %subsystems = (
- SDL => {
- file => {
- from => 'src/SDL.xs',
- to => 'lib/SDL_perl.xs',
- },
- libraries => [qw( SDL )],
- },
- Time => {
- file => {
- from => 'src/Core/Time.xs',
- to => 'lib/SDL/Time.xs',
- },
- libraries => [qw( SDL )],
- },
- Events => {
- file => {
- from => 'src/Core/Events.xs',
- to => 'lib/SDL/Events.xs',
- },
- libraries => [qw( SDL )],
- },
- Event => {
- file => {
- from => 'src/Core/objects/Event.xs',
- to => 'lib/SDL/Event.xs',
- },
- libraries => [qw( SDL )],
- },
- GFX => {
- file => {
- from => 'src/GFX/GFX.xs',
- to => 'lib/SDL/GFX.xs',
- },
- libraries => [qw( SDL SDL_gfx_primitives )],
- },
- BlitFunc => {
- file => {
- from => 'src/GFX/BlitFunc.xs',
- to => 'lib/SDL/GFX/BlitFunc.xs',
- },
- libraries => [qw( SDL SDL_gfx_blitfunc )],
- },
- Framerate => {
- file => {
- from => 'src/GFX/Framerate.xs',
- to => 'lib/SDL/GFX/Framerate.xs',
- },
- libraries => [qw( SDL SDL_gfx_framerate )],
- },
- FPSManager => {
- file => {
- from => 'src/GFX/FPSManager.xs',
- to => 'lib/SDL/GFX/FPSManager.xs',
- },
- libraries => [qw( SDL SDL_gfx_framerate )],
- },
- ImageFilter => {
- file => {
- from => 'src/GFX/ImageFilter.xs',
- to => 'lib/SDL/GFX/ImageFilter.xs',
- },
- libraries => [qw( SDL SDL_gfx_imagefilter )],
- },
- Primitives => {
- file => {
- from => 'src/GFX/Primitives.xs',
- to => 'lib/SDL/GFX/Primitives.xs',
- },
- libraries => [qw( SDL SDL_gfx_primitives )],
- },
- Rotozoom => {
- file => {
- from => 'src/GFX/Rotozoom.xs',
- to => 'lib/SDL/GFX/Rotozoom.xs',
- },
- libraries => [qw( SDL SDL_gfx_rotozoom )],
- },
- MultiThread => {
- file => {
- from => 'src/Core/MultiThread.xs',
- to => 'lib/SDL/MultiThread.xs',
- },
- libraries => [qw( SDL )],
- },
- Video => {
- file => {
- from => 'src/Core/Video.xs',
- to => 'lib/SDL/Video.xs',
- },
- libraries => [qw( SDL )],
- },
- Audio => {
- file => {
- from => 'src/Core/Audio.xs',
- to => 'lib/SDL/Audio.xs',
- },
- libraries => [qw( SDL )],
- },
- Rect => {
- file => {
- from => 'src/Core/objects/Rect.xs',
- to => 'lib/SDL/Rect.xs',
- },
- libraries => [qw( SDL )],
- },
- Color => {
- file => {
- from => 'src/Core/objects/Color.xs',
- to => 'lib/SDL/Color.xs',
- },
- libraries => [qw( SDL )],
- },
- Surface => {
- file => {
- from => 'src/Core/objects/Surface.xs',
- to => 'lib/SDL/Surface.xs',
- },
- libraries => [qw( SDL )],
- },
- SurfaceX => {
- file => {
- from => 'src/SDLx/Surface.xs',
- to => 'lib/SDLx/Surface.xs',
- },
- libraries => [qw( SDL )],
- },
- TimerX => {
- file => {
- from => 'src/SDLx/Timer.xs',
- to => 'lib/SDLx/Controller/Timer.xs',
- },
- libraries => [qw( SDL )],
- },
- Overlay => {
- file => {
- from => 'src/Core/objects/Overlay.xs',
- to => 'lib/SDL/Overlay.xs',
- },
- libraries => [qw( SDL )],
- },
- RWOps => {
- file => {
- from => 'src/Core/objects/RWOps.xs',
- to => 'lib/SDL/RWOps.xs',
- },
- libraries => [qw( SDL )],
- },
- PixelFormat => {
- file => {
- from => 'src/Core/objects/PixelFormat.xs',
- to => 'lib/SDL/PixelFormat.xs',
- },
- libraries => [qw( SDL )],
- },
- LayerManagerX => {
- file => {
- from => 'src/SDLx/LayerManager.xs',
- to => 'lib/SDLx/LayerManager.xs',
- },
- libraries => [qw( SDL )],
- },
- LayerX => {
- file => {
- from => 'src/SDLx/Layer.xs',
- to => 'lib/SDLx/Layer.xs',
- },
- libraries => [qw( SDL SDL_image )],
- },
- AudioSpec => {
- file => {
- from => 'src/Core/objects/AudioSpec.xs',
- to => 'lib/SDL/AudioSpec.xs',
- },
- libraries => [qw( SDL )],
- },
- AudioCVT => {
- file => {
- from => 'src/Core/objects/AudioCVT.xs',
- to => 'lib/SDL/AudioCVT.xs',
- },
- libraries => [qw( SDL )],
- },
- Mixer => {
- file => {
- from => 'src/Mixer/Mixer.xs',
- to => 'lib/SDL/Mixer.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- MixerSamples => {
- file => {
- from => 'src/Mixer/Samples.xs',
- to => 'lib/SDL/Mixer/Samples.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- MixerChannels => {
- file => {
- from => 'src/Mixer/Channels.xs',
- to => 'lib/SDL/Mixer/Channels.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- MixerGroups => {
- file => {
- from => 'src/Mixer/Groups.xs',
- to => 'lib/SDL/Mixer/Groups.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- MixerMusic => {
- file => {
- from => 'src/Mixer/Music.xs',
- to => 'lib/SDL/Mixer/Music.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- MixerEffects => {
- file => {
- from => 'src/Mixer/Effects.xs',
- to => 'lib/SDL/Mixer/Effects.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- MixChunk => {
- file => {
- from => 'src/Mixer/objects/MixChunk.xs',
- to => 'lib/SDL/Mixer/MixChunk.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- MixMusic => {
- file => {
- from => 'src/Mixer/objects/MixMusic.xs',
- to => 'lib/SDL/Mixer/MixMusic.xs',
- },
- libraries => [qw( SDL SDL_mixer )],
- },
- Palette => {
- file => {
- from => 'src/Core/objects/Palette.xs',
- to => 'lib/SDL/Palette.xs',
- },
- libraries => [qw( SDL )],
- },
- VideoInfo => {
- file => {
- from => 'src/Core/objects/VideoInfo.xs',
- to => 'lib/SDL/VideoInfo.xs',
- },
- libraries => [qw( SDL )],
- },
- Mouse => {
- file => {
- from => 'src/Core/Mouse.xs',
- to => 'lib/SDL/Mouse.xs',
- },
- libraries => [qw( SDL )],
- },
- Cursor => {
- file => {
- from => 'src/Core/objects/Cursor.xs',
- to => 'lib/SDL/Cursor.xs',
- },
- libraries => [qw( SDL )],
- },
- Joystick => {
- file => {
- from => 'src/Core/Joystick.xs',
- to => 'lib/SDL/Joystick.xs',
- },
- libraries => [qw( SDL )],
- },
- CDROM => {
- file => {
- from => 'src/Core/CDROM.xs',
- to => 'lib/SDL/CDROM.xs',
- },
- libraries => [qw( SDL )],
- },
- CDTrack => {
- file => {
- from => 'src/Core/objects/CDTrack.xs',
- to => 'lib/SDL/CDTrack.xs',
- },
- libraries => [qw( SDL )],
- },
- CD => {
- file => {
- from => 'src/Core/objects/CD.xs',
- to => 'lib/SDL/CD.xs',
- },
- libraries => [qw( SDL )],
- },
- TTF => {
- file => {
- from => 'src/TTF/TTF.xs',
- to => 'lib/SDL/TTF.xs',
- },
- libraries => [qw( SDL SDL_ttf )],
- },
- TTF_Font => {
- file => {
- from => 'src/TTF/objects/Font.xs',
- to => 'lib/SDL/TTF/Font.xs',
- },
- libraries => [qw( SDL SDL_ttf )],
- },
- Version => {
- file => {
- from => 'src/Core/objects/Version.xs',
- to => 'lib/SDL/Version.xs',
- },
- libraries => [qw( SDL )],
- },
- Image => {
- file => {
- from => 'src/Image.xs',
- to => 'lib/SDL/Image.xs',
- },
- libraries => [qw( SDL SDL_image )],
- },
- SFont => {
- file => {
- from => 'src/SDLx/SFont.xs',
- to => 'lib/SDLx/SFont.xs',
- },
- libraries => [qw( SDL SDL_image )],
- },
+ SDL => {
+ file => {
+ from => 'src/SDL.xs',
+ to => 'lib/SDL_perl.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Time => {
+ file => {
+ from => 'src/Core/Time.xs',
+ to => 'lib/SDL/Time.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Events => {
+ file => {
+ from => 'src/Core/Events.xs',
+ to => 'lib/SDL/Events.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Event => {
+ file => {
+ from => 'src/Core/objects/Event.xs',
+ to => 'lib/SDL/Event.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ GFX => {
+ file => {
+ from => 'src/GFX/GFX.xs',
+ to => 'lib/SDL/GFX.xs',
+ },
+ libraries => [qw( SDL SDL_gfx_primitives )],
+ },
+ BlitFunc => {
+ file => {
+ from => 'src/GFX/BlitFunc.xs',
+ to => 'lib/SDL/GFX/BlitFunc.xs',
+ },
+ libraries => [qw( SDL SDL_gfx_blitfunc )],
+ },
+ Framerate => {
+ file => {
+ from => 'src/GFX/Framerate.xs',
+ to => 'lib/SDL/GFX/Framerate.xs',
+ },
+ libraries => [qw( SDL SDL_gfx_framerate )],
+ },
+ FPSManager => {
+ file => {
+ from => 'src/GFX/FPSManager.xs',
+ to => 'lib/SDL/GFX/FPSManager.xs',
+ },
+ libraries => [qw( SDL SDL_gfx_framerate )],
+ },
+ ImageFilter => {
+ file => {
+ from => 'src/GFX/ImageFilter.xs',
+ to => 'lib/SDL/GFX/ImageFilter.xs',
+ },
+ libraries => [qw( SDL SDL_gfx_imagefilter )],
+ },
+ Primitives => {
+ file => {
+ from => 'src/GFX/Primitives.xs',
+ to => 'lib/SDL/GFX/Primitives.xs',
+ },
+ libraries => [qw( SDL SDL_gfx_primitives )],
+ },
+ Rotozoom => {
+ file => {
+ from => 'src/GFX/Rotozoom.xs',
+ to => 'lib/SDL/GFX/Rotozoom.xs',
+ },
+ libraries => [qw( SDL SDL_gfx_rotozoom )],
+ },
+ MultiThread => {
+ file => {
+ from => 'src/Core/MultiThread.xs',
+ to => 'lib/SDL/MultiThread.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Video => {
+ file => {
+ from => 'src/Core/Video.xs',
+ to => 'lib/SDL/Video.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Audio => {
+ file => {
+ from => 'src/Core/Audio.xs',
+ to => 'lib/SDL/Audio.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Rect => {
+ file => {
+ from => 'src/Core/objects/Rect.xs',
+ to => 'lib/SDL/Rect.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Color => {
+ file => {
+ from => 'src/Core/objects/Color.xs',
+ to => 'lib/SDL/Color.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Surface => {
+ file => {
+ from => 'src/Core/objects/Surface.xs',
+ to => 'lib/SDL/Surface.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ SurfaceX => {
+ file => {
+ from => 'src/SDLx/Surface.xs',
+ to => 'lib/SDLx/Surface.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ TimerX => {
+ file => {
+ from => 'src/SDLx/Timer.xs',
+ to => 'lib/SDLx/Controller/Timer.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Overlay => {
+ file => {
+ from => 'src/Core/objects/Overlay.xs',
+ to => 'lib/SDL/Overlay.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ RWOps => {
+ file => {
+ from => 'src/Core/objects/RWOps.xs',
+ to => 'lib/SDL/RWOps.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ PixelFormat => {
+ file => {
+ from => 'src/Core/objects/PixelFormat.xs',
+ to => 'lib/SDL/PixelFormat.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ LayerManagerX => {
+ file => {
+ from => 'src/SDLx/LayerManager.xs',
+ to => 'lib/SDLx/LayerManager.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ LayerX => {
+ file => {
+ from => 'src/SDLx/Layer.xs',
+ to => 'lib/SDLx/Layer.xs',
+ },
+ libraries => [qw( SDL SDL_image )],
+ },
+ AudioSpec => {
+ file => {
+ from => 'src/Core/objects/AudioSpec.xs',
+ to => 'lib/SDL/AudioSpec.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ AudioCVT => {
+ file => {
+ from => 'src/Core/objects/AudioCVT.xs',
+ to => 'lib/SDL/AudioCVT.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Mixer => {
+ file => {
+ from => 'src/Mixer/Mixer.xs',
+ to => 'lib/SDL/Mixer.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ MixerSamples => {
+ file => {
+ from => 'src/Mixer/Samples.xs',
+ to => 'lib/SDL/Mixer/Samples.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ MixerChannels => {
+ file => {
+ from => 'src/Mixer/Channels.xs',
+ to => 'lib/SDL/Mixer/Channels.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ MixerGroups => {
+ file => {
+ from => 'src/Mixer/Groups.xs',
+ to => 'lib/SDL/Mixer/Groups.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ MixerMusic => {
+ file => {
+ from => 'src/Mixer/Music.xs',
+ to => 'lib/SDL/Mixer/Music.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ MixerEffects => {
+ file => {
+ from => 'src/Mixer/Effects.xs',
+ to => 'lib/SDL/Mixer/Effects.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ MixChunk => {
+ file => {
+ from => 'src/Mixer/objects/MixChunk.xs',
+ to => 'lib/SDL/Mixer/MixChunk.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ MixMusic => {
+ file => {
+ from => 'src/Mixer/objects/MixMusic.xs',
+ to => 'lib/SDL/Mixer/MixMusic.xs',
+ },
+ libraries => [qw( SDL SDL_mixer )],
+ },
+ Palette => {
+ file => {
+ from => 'src/Core/objects/Palette.xs',
+ to => 'lib/SDL/Palette.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ VideoInfo => {
+ file => {
+ from => 'src/Core/objects/VideoInfo.xs',
+ to => 'lib/SDL/VideoInfo.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Mouse => {
+ file => {
+ from => 'src/Core/Mouse.xs',
+ to => 'lib/SDL/Mouse.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Cursor => {
+ file => {
+ from => 'src/Core/objects/Cursor.xs',
+ to => 'lib/SDL/Cursor.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Joystick => {
+ file => {
+ from => 'src/Core/Joystick.xs',
+ to => 'lib/SDL/Joystick.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ CDROM => {
+ file => {
+ from => 'src/Core/CDROM.xs',
+ to => 'lib/SDL/CDROM.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ CDTrack => {
+ file => {
+ from => 'src/Core/objects/CDTrack.xs',
+ to => 'lib/SDL/CDTrack.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ CD => {
+ file => {
+ from => 'src/Core/objects/CD.xs',
+ to => 'lib/SDL/CD.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ TTF => {
+ file => {
+ from => 'src/TTF/TTF.xs',
+ to => 'lib/SDL/TTF.xs',
+ },
+ libraries => [qw( SDL SDL_ttf )],
+ },
+ TTF_Font => {
+ file => {
+ from => 'src/TTF/objects/Font.xs',
+ to => 'lib/SDL/TTF/Font.xs',
+ },
+ libraries => [qw( SDL SDL_ttf )],
+ },
+ Version => {
+ file => {
+ from => 'src/Core/objects/Version.xs',
+ to => 'lib/SDL/Version.xs',
+ },
+ libraries => [qw( SDL )],
+ },
+ Image => {
+ file => {
+ from => 'src/Image.xs',
+ to => 'lib/SDL/Image.xs',
+ },
+ libraries => [qw( SDL SDL_image )],
+ },
+ SFont => {
+ file => {
+ from => 'src/SDLx/SFont.xs',
+ to => 'lib/SDLx/SFont.xs',
+ },
+ libraries => [qw( SDL SDL_image )],
+ },
+
# SMPEG => {
# file => {
# from => 'src/SMPEG.xs',
View
3  examples/SDLx/SDLx_controller_two_squares.pl
@@ -83,8 +83,7 @@ sub on_event {
my $key = $event->key_sym;
if ( $key == SDLK_PRINT ) {
my $screen_shot_index = 1;
- map { $screen_shot_index = $1 + 1 if $_ =~ /Shot(\d+)\.bmp/ && $1 >= $screen_shot_index }
- <Shot*\.bmp>;
+ map { $screen_shot_index = $1 + 1 if $_ =~ /Shot(\d+)\.bmp/ && $1 >= $screen_shot_index } <Shot*\.bmp>;
SDL::Video::save_BMP(
$app,
sprintf( "Shot%04d.bmp", $screen_shot_index )
View
3  examples/SDLx/pong.pl
@@ -128,8 +128,7 @@ sub on_event {
my $key = $event->key_sym;
if ( $key == SDLK_PRINT ) {
my $screen_shot_index = 1;
- map { $screen_shot_index = $1 + 1 if $_ =~ /Shot(\d+)\.bmp/ && $1 >= $screen_shot_index }
- <Shot*\.bmp>;
+ map { $screen_shot_index = $1 + 1 if $_ =~ /Shot(\d+)\.bmp/ && $1 >= $screen_shot_index } <Shot*\.bmp>;
SDL::Video::save_BMP(
$app,
sprintf( "Shot%04d.bmp", $screen_shot_index )
View
426 lib/SDLx/LayerManager.pm
@@ -5,6 +5,7 @@ use SDL;
use SDLx::Surface;
use SDLx::Sprite;
use SDL::Events;
+
#use overload ( '@{}' => \&_array, );
our @ISA = qw(Exporter DynaLoader);
@@ -18,14 +19,14 @@ my @layers = ();
my @attached_layers = ();
my @attached_distance = ();
my @attached_position = ();
-my $snapshot = SDLx::Sprite->new(width => 800, height => 600);
+my $snapshot = SDLx::Sprite->new( width => 800, height => 600 );
my $must_redraw = 1;
#sub new {
# my $class = shift;
# my %options = @_;
# my $self = \%options;
-#
+#
# bless( $self, $class );
#
# return $self;
@@ -37,19 +38,19 @@ my $must_redraw = 1;
# my @layer = @_;
#
# push @layers, {layer => $_, options => $options} for @layer;
-#
+#
# $must_redraw = 1;
# return $self;
#}
sub set {
- my $self = shift;
- my $index = shift;
- my $layer = shift;
- my $options = shift;
+ my $self = shift;
+ my $index = shift;
+ my $layer = shift;
+ my $options = shift;
- $layers[$index] = {layer => $layer, options => $options};
- return $self;
+ $layers[$index] = { layer => $layer, options => $options };
+ return $self;
}
#sub length {
@@ -66,16 +67,16 @@ sub set {
#sub blit {
# my $self = shift;
# my $dest = shift;
-#
+#
# return 0 unless (scalar @attached_layers || $must_redraw);
-#
+#
# my $did_redraw = (scalar @attached_layers || $must_redraw);
#
# #print("$must_redraw\n");
# my ( $mask, $x, $y ) = @{ SDL::Events::get_mouse_state() };
-#
+#
# #$snapshot->blit_by($dest) if $must_redraw;
-#
+#
# if(scalar @attached_layers || $must_redraw) {
# my $layer_index = 0;
# foreach (@layers) {
@@ -86,239 +87,238 @@ sub set {
# $snapshot->blit_by($dest);
# #print("2\n");
# }
-#
+#
# foreach (@attached_layers) {
# $layers[$_]->{layer}->draw_xy($dest, $x + @{$attached_distance[$_]}[0], $y + @{$attached_distance[$_]}[1]);
# }
-#
+#
# #unless (scalar @attached_layers && defined $snapshot) {
# # $snapshot = SDLx::Sprite->new(width => $self->{dest}->w, height => $self->{dest}->h);
# # $snapshot->blit_by($self->{dest});
# #}
-#
+#
# $must_redraw = 0;
# return $did_redraw;
#}
sub attach {
- my $self = shift;
- #my $dest = shift;
- my $y = pop;
- my $x = pop;
-
- #$snapshot = SDLx::Sprite->new(width => $self->{dest}->w, height => $self->{dest}->h);
- #$snapshot->blit_by($self->{dest});
- $must_redraw = 1;
- @attached_distance = ();
- @attached_position = ();
- @attached_layers = @_;
- foreach (@layers) {
- push( @attached_distance, [$_->{layer}->x - $x, $_->{layer}->y - $y] );
- push( @attached_position, [$_->{layer}->x, $_->{layer}->y] );
- }
+ my $self = shift;
+
+ #my $dest = shift;
+ my $y = pop;
+ my $x = pop;
+
+ #$snapshot = SDLx::Sprite->new(width => $self->{dest}->w, height => $self->{dest}->h);
+ #$snapshot->blit_by($self->{dest});
+ $must_redraw = 1;
+ @attached_distance = ();
+ @attached_position = ();
+ @attached_layers = @_;
+ foreach (@layers) {
+ push( @attached_distance, [ $_->{layer}->x - $x, $_->{layer}->y - $y ] );
+ push( @attached_position, [ $_->{layer}->x, $_->{layer}->y ] );
+ }
}
sub detach {
- my $self = shift;
- $must_redraw = 1;
- @attached_distance = ();
- @attached_position = ();
- @attached_layers = ();
+ my $self = shift;
+ $must_redraw = 1;
+ @attached_distance = ();
+ @attached_position = ();
+ @attached_layers = ();
}
sub detach_back {
- my $self = shift;
- foreach (@attached_layers) {
- $layers[$_]->{layer}->x(@{$attached_position[$_]}[0]);
- $layers[$_]->{layer}->y(@{$attached_position[$_]}[1]);
- }
- $must_redraw = 1;
- @attached_distance = ();
- @attached_position = ();
- @attached_layers = ();
+ my $self = shift;
+ foreach (@attached_layers) {
+ $layers[$_]->{layer}->x( @{ $attached_position[$_] }[0] );
+ $layers[$_]->{layer}->y( @{ $attached_position[$_] }[1] );
+ }
+ $must_redraw = 1;
+ @attached_distance = ();
+ @attached_position = ();
+ @attached_layers = ();
}
sub detach_xy {
- my $self = shift;
- my $x = shift;
- my $y = shift;
- my $offset_x;
- my $offset_y;
- foreach (@attached_layers) {
- $offset_x = @{$attached_position[$_]}[0] - $x unless defined $offset_x;
- $offset_y = @{$attached_position[$_]}[1] - $y unless defined $offset_y;
-
- $layers[$_]->{layer}->x(@{$attached_position[$_]}[0] - $offset_x);
- $layers[$_]->{layer}->y(@{$attached_position[$_]}[1] - $offset_y);
- }
- my @position_before = @{$attached_position[$attached_layers[0]]};
-
- $must_redraw = 1;
- @attached_distance = ();
- @attached_position = ();
- @attached_layers = ();
-
- return @position_before;
+ my $self = shift;
+ my $x = shift;
+ my $y = shift;
+ my $offset_x;
+ my $offset_y;
+ foreach (@attached_layers) {
+ $offset_x = @{ $attached_position[$_] }[0] - $x unless defined $offset_x;
+ $offset_y = @{ $attached_position[$_] }[1] - $y unless defined $offset_y;
+
+ $layers[$_]->{layer}->x( @{ $attached_position[$_] }[0] - $offset_x );
+ $layers[$_]->{layer}->y( @{ $attached_position[$_] }[1] - $offset_y );
+ }
+ my @position_before = @{ $attached_position[ $attached_layers[0] ] };
+
+ $must_redraw = 1;
+ @attached_distance = ();
+ @attached_position = ();
+ @attached_layers = ();
+
+ return @position_before;
}
sub foreground {
- my $self = shift;
- my @layers_ = @_;
- @attached_layers = ();
-
- for(@layers_) {
- push(@layers, $layers[$_]);
- push(@attached_distance, $attached_distance[$_]);
- push(@attached_position, $attached_position[$_]);
- }
-
- for(sort { $b <=> $a } @layers_) {
- splice(@layers, $_, 1);
- splice(@attached_distance, $_, 1);
- splice(@attached_position, $_, 1);
- }
-
- for(my $i = $#layers - $#layers_; $layers[$i]; $i++) {
- push(@attached_layers, $i);
- }
- $must_redraw = 1;
-
- return @attached_layers;
+ my $self = shift;
+ my @layers_ = @_;
+ @attached_layers = ();
+
+ for (@layers_) {
+ push( @layers, $layers[$_] );
+ push( @attached_distance, $attached_distance[$_] );
+ push( @attached_position, $attached_position[$_] );
+ }
+
+ for ( sort { $b <=> $a } @layers_ ) {
+ splice( @layers, $_, 1 );
+ splice( @attached_distance, $_, 1 );
+ splice( @attached_position, $_, 1 );
+ }
+
+ for ( my $i = $#layers - $#layers_; $layers[$i]; $i++ ) {
+ push( @attached_layers, $i );
+ }
+ $must_redraw = 1;
+
+ return @attached_layers;
}
sub get_layer_by_position {
- my $self = shift;
- my ( $x, $y ) = @_;
-
- for ( my $i = $#layers ; $i > 0 ; $i-- ) {
- if ( $layers[$i]->{layer}->x <= $x
- && $x <= $layers[$i]->{layer}->x + $layers[$i]->{layer}->clip()->w
- && $layers[$i]->{layer}->y <= $y
- && $y <= $layers[$i]->{layer}->y + $layers[$i]->{layer}->clip()->h )
- {
- my $pixel =
- $layers[$i]->{layer}->[ $x - $layers[$i]->{layer}->x ][ $y - $layers[$i]->{layer}->y ];
- my ( $r, $g, $b, $a ) =
- @{ SDL::Video::get_RGBA( $layers[$i]->{layer}->surface->format, $pixel ) };
-
- return $i if $a > 0;
- }
- }
-
- return -1;
+ my $self = shift;
+ my ( $x, $y ) = @_;
+
+ for ( my $i = $#layers; $i > 0; $i-- ) {
+ if ( $layers[$i]->{layer}->x <= $x
+ && $x <= $layers[$i]->{layer}->x + $layers[$i]->{layer}->clip()->w
+ && $layers[$i]->{layer}->y <= $y
+ && $y <= $layers[$i]->{layer}->y + $layers[$i]->{layer}->clip()->h )
+ {
+ my $pixel = $layers[$i]->{layer}->[ $x - $layers[$i]->{layer}->x ][ $y - $layers[$i]->{layer}->y ];
+ my ( $r, $g, $b, $a ) = @{ SDL::Video::get_RGBA( $layers[$i]->{layer}->surface->format, $pixel ) };
+
+ return $i if $a > 0;
+ }
+ }
+
+ return -1;
}
sub get_layers_ahead_layer {
- my $self = shift;
- my $index = shift;
- #my $map = SDLx::Surface->new( surface => $self->{dest} );
- my @matches = ();
- #my @intersections = ();
- my $layer_index = 0;
-
- for (@layers) {
- if (
- $layer_index > $index
-
- && (
-
- # upper left point inside layer
- ( $layers[$index]->{layer}->x <= $_->{layer}->x
- && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y
- && $_->{layer}->y <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h
- )
-
- # upper right point inside layer
- || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
- && $_->{layer}->x + $_->{layer}->clip->w <=
- $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y
- && $_->{layer}->y <=
- $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
-
- # lower left point inside layer
- || ( $layers[$index]->{layer}->x <= $_->{layer}->x
- && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
- && $_->{layer}->y + $_->{layer}->clip->h <=
- $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h)
-
- # lower right point inside layer
- || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
- && $_->{layer}->x + $_->{layer}->clip->w <=
- $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
- && $_->{layer}->y + $_->{layer}->clip->h <=
- $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
- )
- )
- {
- push( @matches, $layer_index ); # TODO checking transparency
- }
- $layer_index++;
- }
-
- my @more_matches = ();
- while(scalar(@matches) && (@more_matches = $self->get_layers_ahead_layer($matches[$#matches]))) {
- push @matches, @more_matches;
- }
-
- return @matches;
+ my $self = shift;
+ my $index = shift;
+
+ #my $map = SDLx::Surface->new( surface => $self->{dest} );
+ my @matches = ();
+
+ #my @intersections = ();
+ my $layer_index = 0;
+
+ for (@layers) {
+ if ($layer_index > $index
+
+ && (
+
+ # upper left point inside layer
+ ( $layers[$index]->{layer}->x <= $_->{layer}->x
+ && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y
+ && $_->{layer}->y <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h
+ )
+
+ # upper right point inside layer
+ || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
+ && $_->{layer}->x + $_->{layer}->clip->w
+ <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y
+ && $_->{layer}->y <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
+
+ # lower left point inside layer
+ || ( $layers[$index]->{layer}->x <= $_->{layer}->x
+ && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
+ && $_->{layer}->y + $_->{layer}->clip->h
+ <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
+
+ # lower right point inside layer
+ || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
+ && $_->{layer}->x + $_->{layer}->clip->w
+ <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
+ && $_->{layer}->y + $_->{layer}->clip->h
+ <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
+ )
+ )
+ {
+ push( @matches, $layer_index ); # TODO checking transparency
+ }
+ $layer_index++;
+ }
+
+ my @more_matches = ();
+ while ( scalar(@matches) && ( @more_matches = $self->get_layers_ahead_layer( $matches[$#matches] ) ) ) {
+ push @matches, @more_matches;
+ }
+
+ return @matches;
}
sub get_layers_behind_layer {
- my $self = shift;
- my $index = shift;
- #my $map = SDLx::Surface->new( surface => $self->{dest} );
- my @matches = ();
- #my @intersections = ();
- my $layer_index = $#layers;
-
- for (reverse @layers) {
- if (
- $layer_index < $index
-
- && (
-
- # upper left point inside layer
- ( $layers[$index]->{layer}->x <= $_->{layer}->x
- && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y
- && $_->{layer}->y <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h
- )
-
- # upper right point inside layer
- || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
- && $_->{layer}->x + $_->{layer}->clip->w <=
- $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y
- && $_->{layer}->y <=
- $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
-
- # lower left point inside layer
- || ( $layers[$index]->{layer}->x <= $_->{layer}->x
- && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
- && $_->{layer}->y + $_->{layer}->clip->h <=
- $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h)
-
- # lower right point inside layer
- || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
- && $_->{layer}->x + $_->{layer}->clip->w <=
- $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
- && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
- && $_->{layer}->y + $_->{layer}->clip->h <=
- $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
- )
- )
- {
- push( @matches, $layer_index ); # TODO checking transparency
- }
- $layer_index--;
- }
-
- return @matches;
+ my $self = shift;
+ my $index = shift;
+
+ #my $map = SDLx::Surface->new( surface => $self->{dest} );
+ my @matches = ();
+
+ #my @intersections = ();
+ my $layer_index = $#layers;
+
+ for ( reverse @layers ) {
+ if ($layer_index < $index
+
+ && (
+
+ # upper left point inside layer
+ ( $layers[$index]->{layer}->x <= $_->{layer}->x
+ && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y
+ && $_->{layer}->y <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h
+ )
+
+ # upper right point inside layer
+ || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
+ && $_->{layer}->x + $_->{layer}->clip->w
+ <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y
+ && $_->{layer}->y <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
+
+ # lower left point inside layer
+ || ( $layers[$index]->{layer}->x <= $_->{layer}->x
+ && $_->{layer}->x <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
+ && $_->{layer}->y + $_->{layer}->clip->h
+ <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
+
+ # lower right point inside layer
+ || ( $layers[$index]->{layer}->x <= $_->{layer}->x + $_->{layer}->clip->w
+ && $_->{layer}->x + $_->{layer}->clip->w
+ <= $layers[$index]->{layer}->x + $layers[$index]->{layer}->clip->w
+ && $layers[$index]->{layer}->y <= $_->{layer}->y + $_->{layer}->clip->h
+ && $_->{layer}->y + $_->{layer}->clip->h
+ <= $layers[$index]->{layer}->y + $layers[$index]->{layer}->clip->h )
+ )
+ )
+ {
+ push( @matches, $layer_index ); # TODO checking transparency
+ }
+ $layer_index--;
+ }
+
+ return @matches;
}
1;
View
1  lib/SDLx/Validate.pm
@@ -52,6 +52,7 @@ sub _make_color {
$t += 3 if $t < 3; #$t is 3 if rgb and 4 if rgba
my $list = $list_rgb || $list_rgba;
if ( !defined $arg or Scalar::Util::looks_like_number($arg) ) {
+
if ( !defined $arg or $arg < 0 ) {
Carp::carp("Color was a negative number")
if defined $arg and $arg < 0;
View
85 t/sdlx_layermanager.t
@@ -19,7 +19,7 @@ my $videodriver = $ENV{SDL_VIDEODRIVER};
$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
- plan( skip_all => 'Failed to init video' );
+ plan( skip_all => 'Failed to init video' );
}
my $display = SDL::Video::set_video_mode( 800, 600, 32, SDL_SWSURFACE );
@@ -28,54 +28,54 @@ my $surface = SDL::Image::load('test/data/picture.bmp');
############# SDLx::Layer ###########################################################
my $hash = { id => 7 };
-my $layer = SDLx::Layer->new( $surface, 20, 40, 0, 5, 100, 120, $hash );
-my $layer2 = SDLx::Layer->new( $surface, 60, 60 );
-
-isa_ok( $layer, 'SDLx::Layer', 'SDLx::Layer->new');
-is ( $layer->x, 20, 'SDLx::Layer->x' );
-is ( $layer->y, 40, 'SDLx::Layer->y' );
-is ( $layer->w, 100, 'SDLx::Layer->w' );
-is ( $layer->h, 120, 'SDLx::Layer->h' );
-isa_ok( $layer->surface, 'SDL::Surface', 'SDLx::Layer->surface' );
-is ( $layer->surface->w, 180, 'SDLx::Layer->surface->w' );
-is ( $layer->surface->h, 200, 'SDLx::Layer->surface->h' );
-isa_ok( $layer->clip, 'SDL::Rect', 'SDLx::Layer->clip' );
-is ( $layer->clip->x, 0, 'SDLx::Layer->clip->x' );
-is ( $layer->clip->y, 5, 'SDLx::Layer->clip->y' );
-is ( $layer->clip->w, 100, 'SDLx::Layer->clip->w' );
-is ( $layer->clip->h, 120, 'SDLx::Layer->clip->h' );
-isa_ok( $layer->pos, 'SDL::Rect', 'SDLx::Layer->pos' );
-is ( $layer->pos->x, 20, 'SDLx::Layer->pos->x' );
-is ( $layer->pos->y, 40, 'SDLx::Layer->pos->y' );
-is ( $layer->pos->w, 180, 'SDLx::Layer->pos->w' );
-is ( $layer->pos->h, 200, 'SDLx::Layer->pos->h' );
-isa_ok( $layer->data, 'HASH', 'SDLx::Layer->data' );
-is ( $layer2->data, undef, 'SDLx::Layer->data' );
-is ( $layer->data->{id}, 7, 'SDLx::Layer->data->{}' );
+my $layer = SDLx::Layer->new( $surface, 20, 40, 0, 5, 100, 120, $hash );
+my $layer2 = SDLx::Layer->new( $surface, 60, 60 );
+
+isa_ok( $layer, 'SDLx::Layer', 'SDLx::Layer->new' );
+is( $layer->x, 20, 'SDLx::Layer->x' );
+is( $layer->y, 40, 'SDLx::Layer->y' );
+is( $layer->w, 100, 'SDLx::Layer->w' );
+is( $layer->h, 120, 'SDLx::Layer->h' );
+isa_ok( $layer->surface, 'SDL::Surface', 'SDLx::Layer->surface' );
+is( $layer->surface->w, 180, 'SDLx::Layer->surface->w' );
+is( $layer->surface->h, 200, 'SDLx::Layer->surface->h' );
+isa_ok( $layer->clip, 'SDL::Rect', 'SDLx::Layer->clip' );
+is( $layer->clip->x, 0, 'SDLx::Layer->clip->x' );
+is( $layer->clip->y, 5, 'SDLx::Layer->clip->y' );
+is( $layer->clip->w, 100, 'SDLx::Layer->clip->w' );
+is( $layer->clip->h, 120, 'SDLx::Layer->clip->h' );
+isa_ok( $layer->pos, 'SDL::Rect', 'SDLx::Layer->pos' );
+is( $layer->pos->x, 20, 'SDLx::Layer->pos->x' );
+is( $layer->pos->y, 40, 'SDLx::Layer->pos->y' );
+is( $layer->pos->w, 180, 'SDLx::Layer->pos->w' );
+is( $layer->pos->h, 200, 'SDLx::Layer->pos->h' );
+isa_ok( $layer->data, 'HASH', 'SDLx::Layer->data' );
+is( $layer2->data, undef, 'SDLx::Layer->data' );
+is( $layer->data->{id}, 7, 'SDLx::Layer->data->{}' );
############ SDLx::LayerManager #####################################################
my $manager = SDLx::LayerManager->new();
-isa_ok( $manager, 'SDLx::LayerManager', 'SDLx::LayerManager->new' );
-is( $manager->length, 0, 'SDLx::LayerManager->length');
- $manager->add( $layer ); pass( 'SDLx::LayerManager->add' );
- $manager->add( $layer2 ); pass( 'SDLx::LayerManager->add' );
-is( $manager->length, 2, 'SDLx::LayerManager->length');
-isa_ok( $manager->layer(0), 'SDLx::Layer', 'SDLx::LayerManager->layer' );
-isa_ok( $manager->layer(1), 'SDLx::Layer', 'SDLx::LayerManager->layer' );
-is( $manager->layer(2), undef, 'SDLx::LayerManager->layer' );
-is( $manager->layer(-3), undef, 'SDLx::LayerManager->layer' );
-is( $manager->layer(0)->h, 120, 'SDLx::LayerManager->layer->h' );
-isa_ok( $manager->layer(0)->surface, 'SDL::Surface', 'SDLx::LayerManager->layer->surface' );
-is( $manager->layer(0)->surface->w, 180, 'SDLx::LayerManager->layer->surface->w' );
+isa_ok( $manager, 'SDLx::LayerManager', 'SDLx::LayerManager->new' );
+is( $manager->length, 0, 'SDLx::LayerManager->length' );
+$manager->add($layer); pass('SDLx::LayerManager->add');
+$manager->add($layer2); pass('SDLx::LayerManager->add');
+is( $manager->length, 2, 'SDLx::LayerManager->length' );
+isa_ok( $manager->layer(0), 'SDLx::Layer', 'SDLx::LayerManager->layer' );
+isa_ok( $manager->layer(1), 'SDLx::Layer', 'SDLx::LayerManager->layer' );
+is( $manager->layer(2), undef, 'SDLx::LayerManager->layer' );
+is( $manager->layer(-3), undef, 'SDLx::LayerManager->layer' );
+is( $manager->layer(0)->h, 120, 'SDLx::LayerManager->layer->h' );
+isa_ok( $manager->layer(0)->surface, 'SDL::Surface', 'SDLx::LayerManager->layer->surface' );
+is( $manager->layer(0)->surface->w, 180, 'SDLx::LayerManager->layer->surface->w' );
#isa_ok( $manager->layers, 'ARRAY', '[layers] returns an ARRAY' );
#is( $manager->layer(0)->x, 10, '[layer(0)->x] is 10' );
# $manager->layer(0)->x(42); pass( '[layer(0)->x(42)] set to 42' );
#is( $manager->layer(0)->x, 42, '[layer(0)->x] is 42 now' );
- $manager->blit($display); pass( '[blit] ran' );
-SDL::Video::update_rect($display, 0, 0, 0, 0);
+$manager->blit($display); pass('[blit] ran');
+SDL::Video::update_rect( $display, 0, 0, 0, 0 );
#is( $manager->get_layer_by_position( 20, 130 ), 2 );
@@ -91,10 +91,9 @@ SDL::Video::update_rect($display, 0, 0, 0, 0);
sleep(2);
if ($videodriver) {
- $ENV{SDL_VIDEODRIVER} = $videodriver;
-}
-else {
- delete $ENV{SDL_VIDEODRIVER};
+ $ENV{SDL_VIDEODRIVER} = $videodriver;
+} else {
+ delete $ENV{SDL_VIDEODRIVER};
}
pass 'Final SegFault test';
Please sign in to comment.
Something went wrong with that request. Please try again.