Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 96 lines (77 sloc) 2.071 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#!/usr/bin/env perl

use strict;
use SDL;
use SDLx::App;
use SDL::Event;
use SDL::Tool::Font;
use SDL::Color;

my (%options,$app,$mode);

die "usage: $0 [-hw] [-fullscreen] [-width 640] [-height 480] [-bpp 24]\n"
if ( SDL::in ($ARGV[0], qw/ -h -? --help/ ));

chdir 'test' if -d 'test';
die "$0 must be run in the SDL_perl/test/ directory!"
unless (-d 'data');

for ( 0 .. @ARGV-1 )
{
$options{$ARGV[$_]} = $ARGV[$_ + 1] || 1;
}

$options{-flags} = SDL_SWSURFACE;
$options{-flags} |= SDL_HWPALETTE if ( $options{-hw} );
$options{-flags} |= SDL_FULLSCREEN if ( $options{-fullscreen} );

$options{-title} = $0;

$options{-width} ||= 800;
$options{-height} ||= 600;
$options{-depth} ||= $options{-bpp} || 24;

$app = SDLx::App->new( %options );

my %ttfonts = (
'aircut3.ttf' => 0,
'electrohar.ttf' => 0,
);

my %sfonts = (
'24P_Arial_NeonYellow.png' => 0,
'24P_Copperplate_Blue.png' => 0,
);

my @fonts;

for ( reverse keys %ttfonts ) {
for $mode ( qw/ -normal -bold -italic -underline / ) {
if (-e "data/$_") {
print STDERR "Loading $_\n";
$ttfonts{"$_$mode"} = SDL::Tool::Font->new(
$mode => 1,
-ttfont => "data/$_",
-size => 20,
-fg => $SDL::Color::black,
-bg => $SDL::Color::black );
push @fonts, $ttfonts{"$_$mode"};
}
}
}

%ttfonts = reverse %ttfonts;

for ( reverse keys %sfonts) {
if (-e "data/$_") {
print STDERR "Loading $_\n";
$sfonts{$_} = SDL::Tool::Font->new( -sfont => "data/$_" );
push @fonts, $sfonts{$_};
}
}

%sfonts = reverse %sfonts;

sub DrawFonts {
$app->fill(0,$SDL::Color::white);
my ($x,$y) = @_;
for my $font ( @fonts) {
$font->print($app,$x,$y,"SDLperl font test. ",
"This is " . ($ttfonts{$font} || $sfonts{$font}));
$y += 40;
}
$app->flip();
}

DrawFonts(10,10);

$app->loop( {
SDL_KEYDOWN() => sub {
my ($event) = @_;
$app->warp($options{-width}/2,$options{-height}/2) if ($event->key_sym() == SDLK_SPACE);
$app->fullscreen() if ($event->key_sym() == SDLK_f);
exit(0) if ($event->key_sym() == SDLK_ESCAPE);
},
SDL_QUIT() => sub { exit(0); }
} );
Something went wrong with that request. Please try again.