From OrganicDesign Wiki
#!/usr/bin/perl -w
#
use strict;
use SDL;
use SDL::App;
use SDL::Constants;
use SDL::Surface;
use SDL::Rect;
use SDL::Event;
use Image::Info qw(image_info dim);
# name to display in the process table and in the window header (if present)
$0 = "Imagine this is a very big TV";
#my $ROOT = `pwd`;
#chomp $ROOT;
#my $imgdir = "$ROOT/src/ui/png/";
my $imgdir = 'L:';
# build a hash of ui objects
my ( %symbol, $info );
opendir(DIR, $imgdir) or die "Can't open PNG folder: $!";
while ( my $file = readdir(DIR) ) {
# process only png files
next unless $file =~ /\.png$/;
print "Processing: $file\n";
$file =~ /(.*?)\.png/;
my $basename = $1;
# get file dimensions
$info = image_info("$imgdir/$file");
$symbol{$basename}{x} = 0;
$symbol{$basename}{y} = 0;
$symbol{$basename}{width} = $info->{width};
$symbol{$basename}{height} = $info->{height};
# init rect
$symbol{$basename}{rect} = SDL::Rect->new(
-width => $info->{width},
-height => $info->{height},
);
# init surface
$symbol{$basename}{surface} = SDL::Surface->new(
-name => "$imgdir/$file",
);
}
# init app
my $app = new SDL::App (
-fullscreen => 1,
-width => 1024,
-height => 768,
-depth => 24,
);
# event loop
my %events = (
SDL_QUIT() => sub { exit(0); },
SDL_KEYDOWN() => sub {
$app->sync();
#$app->blit( NULL, $app, NULL );
#$background->blit( $background, $frame_rect, $dest_rect);
},
SDL_MOUSEMOTION() => sub {
my ($e) = @_;
my $dest_rect = SDL::Rect->new(
-x => $symbol{'logo-grey'}{x} += $e->motion_x(),
-y => $symbol{'logo-grey'}{y} += $e->motion_y(),
-width => $symbol{'logo-grey'}{width},
-height => $symbol{'logo-grey'}{height}
);
# composite surfaces
$symbol{'logo-grey'}{surface}->blit( NULL, $app, $dest_rect );
#$symbol{'logo-green'}{surface}->blit( NULL, $app, NULL );
$app->sync();
#print "a\n";
}
);
$app->loop(\%events);