File: testfonttool.pl

package info (click to toggle)
sdlperl 1.20.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,804 kB
  • ctags: 2,169
  • sloc: perl: 7,397; ansic: 232; makefile: 72; sh: 1
file content (102 lines) | stat: -rwxr-xr-x 2,126 bytes parent folder | download
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
97
98
99
100
101
102
#!/usr/bin/env perl

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

my %options;

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

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 = new SDL::App  %options;

my %ttfonts = (
	'/usr/share/fonts/truetype/freefont/FreeSerif.ttf' => 0,
	'/usr/share/fonts/truetype/freefont/FreeSans.ttf' => 0,
	'/usr/share/fonts/truetype/freefont/FreeMono.ttf' => 0,
);

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

my @fonts;

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

%ttfonts = reverse %ttfonts;

for ( reverse keys %sfonts) {
	if (-e "$_") {
		print STDERR "Loading $_\n";
		$sfonts{$_} = new SDL::Tool::Font -sfont => "$_";
		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); }
} );