Added last two objects (Overlay and VideoInfo) XS files for Video
[sdlgit/SDL_perl.git] / test / testfonttool.pl
CommitLineData
8fde61e3 1#!/usr/bin/env perl
2
3use strict;
4use SDL;
5use SDL::App;
6use SDL::Event;
7use SDL::Tool::Font;
8use SDL::Color;
9
10my (%options,$app,$mode);
11
12die "usage: $0 [-hw] [-fullscreen] [-width 640] [-height 480] [-bpp 24]\n"
13 if ( SDL::in ($ARGV[0], qw/ -h -? --help/ ));
14
15chdir 'test' if -d 'test';
16die "$0 must be run in the SDL_perl/test/ directory!"
17 unless (-d 'data');
18
19for ( 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
34$app = new SDL::App %options;
35
36my %ttfonts = (
37 'aircut3.ttf' => 0,
38 'electrohar.ttf' => 0,
39);
40
41my %sfonts = (
42 '24P_Arial_NeonYellow.png' => 0,
43 '24P_Copperplate_Blue.png' => 0,
44);
45
46my @fonts;
47
48for ( reverse keys %ttfonts ) {
49 for $mode ( qw/ -normal -bold -italic -underline / ) {
50 if (-e "data/$_") {
51 print STDERR "Loading $_\n";
52 $ttfonts{"$_$mode"} = new SDL::Tool::Font
53 $mode => 1,
54 -ttfont => "data/$_",
55 -size => 20,
56 -fg => $SDL::Color::black,
57 -bg => $SDL::Color::black;
58 push @fonts, $ttfonts{"$_$mode"};
59 }
60 }
61}
62
63%ttfonts = reverse %ttfonts;
64
65for ( reverse keys %sfonts) {
66 if (-e "data/$_") {
67 print STDERR "Loading $_\n";
68 $sfonts{$_} = new SDL::Tool::Font -sfont => "data/$_";
69 push @fonts, $sfonts{$_};
70 }
71}
72
73%sfonts = reverse %sfonts;
74
75sub 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
86DrawFonts(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