Commit | Line | Data |
8fde61e3 |
1 | # |
2 | # SDL::Tool::Font - format agnostic font tool |
3 | # |
4 | # Copyright (C) 2002 David J. Goehrig |
5 | |
6 | package SDL::Tool::Font; |
7 | |
8 | use SDL; |
9 | use SDL::Font; |
10 | use SDL::TTFont; |
11 | |
12 | sub new { |
13 | my $proto = shift; |
14 | my $class = ref($proto) || $proto; |
15 | $self = {}; |
16 | my %option = @_; |
17 | |
18 | verify (%option, qw/ -sfont -ttfont -size -fg -bg -foreground -background |
19 | -normal -bold -italic -underline / ) if $SDL::DEBUG; |
20 | |
21 | if ($option{-sfont}) { |
22 | $$self{-font} = new SDL::Font $option{-sfont}; |
23 | } elsif ($option{-ttfont} || $option{-t}) { |
24 | $option{-size} ||= 12; |
25 | $$self{-font} = new SDL::TTFont |
26 | -name => $option{-ttfont} || $option{-t}, |
27 | -size => $option{-size} || $option{-s}, |
28 | -fg => $option{-foreground} || $option{-fg} , |
29 | -bg => $option{-background} || $option{-bg}; |
30 | for (qw/ normal bold italic underline / ) { |
31 | if ($option{"-$_"}) { |
32 | &{"SDL::TTFont::$_"}($$self{-font}); |
33 | } |
34 | } |
35 | } else { |
36 | die "SDL::Tool::Font requires either a -sfont or -ttfont"; |
37 | } |
38 | bless $self,$class; |
39 | $self; |
40 | } |
41 | |
42 | sub DESTROY { |
43 | |
44 | } |
45 | |
46 | sub print { |
47 | my ($self,$surface,$x,$y,@text) = @_; |
48 | die "Tool::Font::print requires a SDL::Surface\n" |
e00a4871 |
49 | unless ($surface->isa('SDL::Surface')); |
8fde61e3 |
50 | if ($$self{-font}->isa('SDL::Font')) { |
51 | $$self{-font}->use(); |
52 | SDL::SFont::PutString( $$surface, $x, $y, join('',@text)); |
53 | } else { |
54 | $$self{-font}->print($surface,$x,$y,@text); |
55 | } |
56 | } |
57 | |
58 | 1; |
59 | |
60 | __END__; |
61 | |
62 | =pod |
63 | |
64 | =head1 NAME |
65 | |
66 | SDL::Tool::Font - a perl extension |
67 | |
68 | =head1 DESCRIPTION |
69 | |
70 | L<SDL::Tool::Font> provides a unified interface for applying |
71 | True Type and SFont fonts to various surfaces. |
72 | |
73 | =head1 METHODS |
74 | |
75 | =head2 print ( surface, x, y, text ... ) |
76 | |
77 | C<SDL::Tool::Font::print> print the given text on the supplied surface |
78 | with the upper left hand corner starting at the specified coordinates. |
79 | |
80 | =head1 AUTHOR |
81 | |
82 | David J. Goehrig |
83 | |
84 | =head1 SEE ALSO |
85 | |
86 | L<perl> L<SDL::Font> L<SDL::TTFont> L<SDL::Surface> |
87 | |
88 | =cut |