Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 102 lines (77 sloc) 2.071 kb
5597ddb @mantovani files moved to this paste
mantovani authored
1 #!/usr/bin/env perl
2
3 use strict;
4 use SDL;
c3d720d @kthakore Cleaned up all of SDL::App to SDLx::App
kthakore authored
5 use SDLx::App;
5597ddb @mantovani files moved to this paste
mantovani authored
6 use SDL::Event;
7 use SDL::Tool::Font;
8 use SDL::Color;
9
10 my (%options,$app,$mode);
11
12 die "usage: $0 [-hw] [-fullscreen] [-width 640] [-height 480] [-bpp 24]\n"
13 if ( SDL::in ($ARGV[0], qw/ -h -? --help/ ));
14
15 chdir 'test' if -d 'test';
16 die "$0 must be run in the SDL_perl/test/ directory!"
17 unless (-d 'data');
18
19 for ( 0 .. @ARGV-1 )
20 {
21 $options{$ARGV[$_]} = $ARGV[$_ + 1] || 1;
22 }
23
24 $options{-flags} = SDL_SWSURFACE;
25 $options{-flags} |= SDL_HWPALETTE if ( $options{-hw} );
26 $options{-flags} |= SDL_FULLSCREEN if ( $options{-fullscreen} );
27
28 $options{-title} = $0;
29
30 $options{-width} ||= 800;
31 $options{-height} ||= 600;
32 $options{-depth} ||= $options{-bpp} || 24;
33
c3d720d @kthakore Cleaned up all of SDL::App to SDLx::App
kthakore authored
34 $app = SDLx::App->new( %options );
5597ddb @mantovani files moved to this paste
mantovani authored
35
36 my %ttfonts = (
37 'aircut3.ttf' => 0,
38 'electrohar.ttf' => 0,
39 );
40
41 my %sfonts = (
42 '24P_Arial_NeonYellow.png' => 0,
43 '24P_Copperplate_Blue.png' => 0,
44 );
45
46 my @fonts;
47
48 for ( reverse keys %ttfonts ) {
49 for $mode ( qw/ -normal -bold -italic -underline / ) {
50 if (-e "data/$_") {
51 print STDERR "Loading $_\n";
b127760 @bricas fix as many obvious indirect object notation infractions as i can find.
bricas authored
52 $ttfonts{"$_$mode"} = SDL::Tool::Font->new(
5597ddb @mantovani files moved to this paste
mantovani authored
53 $mode => 1,
54 -ttfont => "data/$_",
55 -size => 20,
56 -fg => $SDL::Color::black,
b127760 @bricas fix as many obvious indirect object notation infractions as i can find.
bricas authored
57 -bg => $SDL::Color::black );
5597ddb @mantovani files moved to this paste
mantovani authored
58 push @fonts, $ttfonts{"$_$mode"};
59 }
60 }
61 }
62
63 %ttfonts = reverse %ttfonts;
64
65 for ( reverse keys %sfonts) {
66 if (-e "data/$_") {
67 print STDERR "Loading $_\n";
b127760 @bricas fix as many obvious indirect object notation infractions as i can find.
bricas authored
68 $sfonts{$_} = SDL::Tool::Font->new( -sfont => "data/$_" );
5597ddb @mantovani files moved to this paste
mantovani authored
69 push @fonts, $sfonts{$_};
70 }
71 }
72
73 %sfonts = reverse %sfonts;
74
75 sub DrawFonts {
76 $app->fill(0,$SDL::Color::white);
77 my ($x,$y) = @_;
78 for my $font ( @fonts) {
79 $font->print($app,$x,$y,"SDLperl font test. ",
80 "This is " . ($ttfonts{$font} || $sfonts{$font}));
81 $y += 40;
82 }
83 $app->flip();
84 }
85
86 DrawFonts(10,10);
87
88 $app->loop( {
89 SDL_KEYDOWN() => sub {
90 my ($event) = @_;
91 $app->warp($options{-width}/2,$options{-height}/2) if ($event->key_sym() == SDLK_SPACE);
92 $app->fullscreen() if ($event->key_sym() == SDLK_f);
93 exit(0) if ($event->key_sym() == SDLK_ESCAPE);
94 },
95 SDL_QUIT() => sub { exit(0); }
96 } );
97
98
99
100
101
Something went wrong with that request. Please try again.