/lib/SDLx/TTF.pm
Perl | 61 lines | 44 code | 17 blank | 0 comment | 4 complexity | 2e8415dfc0f59c959dad4a917ecff3f6 MD5 | raw file
1package SDLx::TTF; 2use strict; 3use warnings; 4use Carp; 5 6use SDL; 7use SDL::TTF; 8use SDL::TTF::Font; 9 10our $VERSION = 2.548; 11 12sub new 13{ 14 my ($class, $font) = @_; 15 16 my $self = {}; 17 18 unless ( SDL::Config->has('SDL_ttf') ) { 19 Carp::cluck("SDL_ttf support has not been compiled"); 20 } 21 unless ( SDL::TTF::was_init() ) 22 { 23 Carp::cluck ("Cannot init TTF: " . SDL::get_error() ) unless SDL::TTF::init() == 0; 24 $self->{inited} = 1; 25 $self->{style} = { 26 normal => TTF_STYLE_NORMAL, 27 bold => TTF_STYLE_BOLD, 28 italic => TTF_STYLE_ITALIC, 29 underline => TTF_STYLE_UNDERLINE, 30 strikethrough => TTF_STYLE_STRIKETHROUGH 31 }; 32 } 33 34 my $ttf_font; 35 unless ( $ttf_font = SDL::TTF::open_font($font, $size )) 36 { 37 38 Carp::cluck ("Cannot make a TTF font from location ($font) or size($size), due to: ". SDL::get_error ); 39 40 } 41 42 $self->{ttf_font} = $ttf_font; 43 44 if ( $style && ( my $t_style = $self->{style}->{$style} ) ) 45 { 46 SDL::TTF::set_font_style($ttf_font, $t_style); 47 } 48 49 50 return bless $self, $class; 51 52} 53 54 55sub DESTROY { 56 my $self = shift; 57 SDL::TTF::quit if $self->{inited}; 58 59} 60 611;