From: Leon Brocard Date: Sat, 17 Oct 2009 11:10:17 +0000 (+0100) Subject: Wrap TTF_Font with a few calls X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b41abbd6015ec5d9bba526df08193b1deb14c2ec;p=sdlgit%2FSDL_perl.git Wrap TTF_Font with a few calls --- diff --git a/Build.PL b/Build.PL index 142b973..2c40fd2 100644 --- a/Build.PL +++ b/Build.PL @@ -69,6 +69,13 @@ my %subsystems = }, libraries => [qw( SDL SDL_image )], }, + TTF_Font => { + file => { + from => 'src/TTF/objects/TTF_Font.xs', + to => 'lib/SDL/TTF_Font.xs', + }, + libraries => [qw( SDL SDL_ttf )], + }, OpenGL => { file => { from => 'src/OpenGL.xs', diff --git a/MANIFEST b/MANIFEST index 5db5058..4224299 100644 --- a/MANIFEST +++ b/MANIFEST @@ -27,6 +27,7 @@ lib/SDL/Surface.pm lib/SDL/Timer.pm lib/SDL/Tool/Font.pm lib/SDL/Tool/Graphic.pm +lib/SDL/TTF_Font.pm lib/SDL/TTFont.pm lib/SDL/Tutorial.pm lib/SDL/Tutorial/Animation.pm @@ -105,6 +106,7 @@ t/colorpm.t t/constantspm.t t/core_rect.t t/core_surface.t +t/core_ttf.t t/cursorpm.t t/eventpm.t t/extendingrect.t diff --git a/lib/SDL/TTF_Font.pm b/lib/SDL/TTF_Font.pm new file mode 100644 index 0000000..f8d1943 --- /dev/null +++ b/lib/SDL/TTF_Font.pm @@ -0,0 +1,11 @@ +package SDL::TTF_Font; +use strict; +use warnings; +require Exporter; +require DynaLoader; +our @ISA = qw(Exporter DynaLoader); +bootstrap SDL::TTF_Font; + +1; + +__END__ \ No newline at end of file diff --git a/src/SDL.xs b/src/SDL.xs index aa949e0..630e327 100644 --- a/src/SDL.xs +++ b/src/SDL.xs @@ -62,19 +62,6 @@ void (*mix_music_finished_cv)(); #include #endif -#ifdef HAVE_SDL_TTF -#include -#define TEXT_SOLID 1 -#define TEXT_SHADED 2 -#define TEXT_BLENDED 4 -#define UTF8_SOLID 8 -#define UTF8_SHADED 16 -#define UTF8_BLENDED 32 -#define UNICODE_SOLID 64 -#define UNICODE_SHADED 128 -#define UNICODE_BLENDED 256 -#endif - #ifdef HAVE_SMPEG #include #ifdef HAVE_SDL_MIXER @@ -93,6 +80,10 @@ static int sdl_perl_use_smpeg_audio = 0; #include #endif +#ifdef HAVE_SDL_TTF +#include +#endif + #ifdef USE_THREADS #define HAVE_TLS_CONTEXT #endif @@ -2796,390 +2787,6 @@ NetRead32 ( area ) #endif -#ifdef HAVE_SDL_TTF - -int -TTFInit () - CODE: - RETVAL = TTF_Init(); - OUTPUT: - RETVAL - -void -TTFQuit () - CODE: - TTF_Quit(); - -TTF_Font* -TTFOpenFont ( file, ptsize ) - char *file - int ptsize - CODE: - RETVAL = TTF_OpenFont(file,ptsize); - OUTPUT: - RETVAL - -int -TTFGetFontStyle ( font ) - TTF_Font *font - CODE: - RETVAL = TTF_GetFontStyle(font); - OUTPUT: - RETVAL - -void -TTFSetFontStyle ( font, style ) - TTF_Font *font - int style - CODE: - TTF_SetFontStyle(font,style); - -int -TTFFontHeight ( font ) - TTF_Font *font - CODE: - RETVAL = TTF_FontHeight(font); - OUTPUT: - RETVAL - -int -TTFFontAscent ( font ) - TTF_Font *font - CODE: - RETVAL = TTF_FontAscent(font); - OUTPUT: - RETVAL - -int -TTFFontDescent ( font ) - TTF_Font *font - CODE: - RETVAL = TTF_FontDescent(font); - OUTPUT: - RETVAL - -int -TTFFontLineSkip ( font ) - TTF_Font *font - CODE: - RETVAL = TTF_FontLineSkip(font); - OUTPUT: - RETVAL - -AV* -TTFGlyphMetrics ( font, ch ) - TTF_Font *font - Uint16 ch - CODE: - int minx, miny, maxx, maxy, advance; - RETVAL = newAV(); - TTF_GlyphMetrics(font, ch, &minx, &miny, &maxx, &maxy, &advance); - av_push(RETVAL,newSViv(minx)); - av_push(RETVAL,newSViv(miny)); - av_push(RETVAL,newSViv(maxx)); - av_push(RETVAL,newSViv(maxy)); - av_push(RETVAL,newSViv(advance)); - OUTPUT: - RETVAL - -AV* -TTFSizeText ( font, text ) - TTF_Font *font - char *text - CODE: - int w,h; - RETVAL = newAV(); - if(TTF_SizeText(font,text,&w,&h)) - { - printf("TTF error at TTFSizeText: %s \n", TTF_GetError()); - Perl_croak (aTHX_ "TTF error \n"); - } - else - { - av_push(RETVAL,newSViv(w)); - av_push(RETVAL,newSViv(h)); - sv_2mortal((SV*)RETVAL); - } - - - OUTPUT: - RETVAL - -AV* -TTFSizeUTF8 ( font, text ) - TTF_Font *font - char *text - CODE: - int w,h; - RETVAL = newAV(); - if(TTF_SizeUTF8(font,text,&w,&h)) - { - av_push(RETVAL,newSViv(w)); - av_push(RETVAL,newSViv(h)); - sv_2mortal((SV*)RETVAL); - - } - else - { - printf("TTF error at TTFSizeUTF8 with : %s \n", TTF_GetError()); - Perl_croak (aTHX_ "TTF error \n"); - } - - OUTPUT: - RETVAL - -AV* -TTFSizeUNICODE ( font, text ) - TTF_Font *font - const Uint16 *text - CODE: - int w,h; - RETVAL = newAV(); - if(TTF_SizeUNICODE(font,text,&w,&h)) - { - av_push(RETVAL,newSViv(w)); - av_push(RETVAL,newSViv(h)); - sv_2mortal((SV*)RETVAL); - - } - else - { - printf("TTF error at TTFSizeUNICODE : %s \n", TTF_GetError()); - Perl_croak (aTHX_ "TTF error \n"); - } - - OUTPUT: - RETVAL - -=for comment - -SDL_Surface* -TTFRenderTextSolid ( font, text, fg ) - TTF_Font *font - char *text - SDL_Color *fg - CODE: - RETVAL = TTF_RenderText_Solid(font,text,*fg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderUTF8Solid ( font, text, fg ) - TTF_Font *font - char *text - SDL_Color *fg - CODE: - RETVAL = TTF_RenderUTF8_Solid(font,text,*fg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderUNICODESolid ( font, text, fg ) - TTF_Font *font - const Uint16 *text - SDL_Color *fg - CODE: - RETVAL = TTF_RenderUNICODE_Solid(font,text,*fg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderGlyphSolid ( font, ch, fg ) - TTF_Font *font - Uint16 ch - SDL_Color *fg - CODE: - RETVAL = TTF_RenderGlyph_Solid(font,ch,*fg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderTextShaded ( font, text, fg, bg ) - TTF_Font *font - char *text - SDL_Color *fg - SDL_Color *bg - CODE: - RETVAL = TTF_RenderText_Shaded(font,text,*fg,*bg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderUTF8Shaded( font, text, fg, bg ) - TTF_Font *font - char *text - SDL_Color *fg - SDL_Color *bg - CODE: - RETVAL = TTF_RenderUTF8_Shaded(font,text,*fg,*bg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderUNICODEShaded( font, text, fg, bg ) - TTF_Font *font - const Uint16 *text - SDL_Color *fg - SDL_Color *bg - CODE: - RETVAL = TTF_RenderUNICODE_Shaded(font,text,*fg,*bg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderGlyphShaded ( font, ch, fg, bg ) - TTF_Font *font - Uint16 ch - SDL_Color *fg - SDL_Color *bg - CODE: - RETVAL = TTF_RenderGlyph_Shaded(font,ch,*fg,*bg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderTextBlended( font, text, fg ) - TTF_Font *font - char *text - SDL_Color *fg - CODE: - RETVAL = TTF_RenderText_Blended(font,text,*fg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderUTF8Blended( font, text, fg ) - TTF_Font *font - char *text - SDL_Color *fg - CODE: - RETVAL = TTF_RenderUTF8_Blended(font,text,*fg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderUNICODEBlended( font, text, fg ) - TTF_Font *font - const Uint16 *text - SDL_Color *fg - CODE: - RETVAL = TTF_RenderUNICODE_Blended(font,text,*fg); - OUTPUT: - RETVAL - -SDL_Surface* -TTFRenderGlyphBlended( font, ch, fg ) - TTF_Font *font - Uint16 ch - SDL_Color *fg - CODE: - RETVAL = TTF_RenderGlyph_Blended(font,ch,*fg); - OUTPUT: - RETVAL - -void -TTFCloseFont ( font ) - TTF_Font *font - CODE: - TTF_CloseFont(font); - font=NULL; //to be safe http://sdl.beuc.net/sdl.wiki/SDL_ttf_copy_Functions_Management_TTF_CloseFont - -SDL_Surface* -TTFPutString ( font, mode, surface, x, y, fg, bg, text ) - TTF_Font *font - int mode - SDL_Surface *surface - int x - int y - SDL_Color *fg - SDL_Color *bg - char *text - CODE: - SDL_Surface *img; - SDL_Rect dest; - int w,h; - dest.x = x; - dest.y = y; - RETVAL = NULL; - switch (mode) { - case TEXT_SOLID: - img = TTF_RenderText_Solid(font,text,*fg); - TTF_SizeText(font,text,&w,&h); - dest.w = w; - dest.h = h; - break; - case TEXT_SHADED: - img = TTF_RenderText_Shaded(font,text,*fg,*bg); - TTF_SizeText(font,text,&w,&h); - dest.w = w; - dest.h = h; - break; - case TEXT_BLENDED: - img = TTF_RenderText_Blended(font,text,*fg); - TTF_SizeText(font,text,&w,&h); - dest.w = w; - dest.h = h; - break; - case UTF8_SOLID: - img = TTF_RenderUTF8_Solid(font,text,*fg); - TTF_SizeUTF8(font,text,&w,&h); - dest.w = w; - dest.h = h; - break; - case UTF8_SHADED: - img = TTF_RenderUTF8_Shaded(font,text,*fg,*bg); - TTF_SizeUTF8(font,text,&w,&h); - dest.w = w; - dest.h = h; - break; - case UTF8_BLENDED: - img = TTF_RenderUTF8_Blended(font,text,*fg); - TTF_SizeUTF8(font,text,&w,&h); - dest.w = w; - dest.h = h; - break; - case UNICODE_SOLID: - img = TTF_RenderUNICODE_Solid(font,(Uint16*)text,*fg); - TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); - dest.w = w; - dest.h = h; - break; - case UNICODE_SHADED: - img = TTF_RenderUNICODE_Shaded(font,(Uint16*)text,*fg,*bg); - TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); - dest.w = w; - dest.h = h; - break; - case UNICODE_BLENDED: - img = TTF_RenderUNICODE_Blended(font,(Uint16*)text,*fg); - TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); - dest.w = w; - dest.h = h; - break; - default: - img = TTF_RenderText_Shaded(font,text,*fg,*bg); - TTF_SizeText(font,text,&w,&h); - dest.w = w; - dest.h = h; - } - if ( img && img->format && img->format->palette ) { - SDL_Color *c = &img->format->palette->colors[0]; - Uint32 key = SDL_MapRGB( img->format, c->r, c->g, c->b ); - SDL_SetColorKey(img,SDL_SRCCOLORKEY,key ); - if (0 > SDL_BlitSurface(img,NULL,surface,&dest)) { - SDL_FreeSurface(img); - RETVAL = NULL; - } else { - RETVAL = img; - } - } - OUTPUT: - RETVAL - -=cut - -#endif - SDL_Overlay* CreateYUVOverlay ( width, height, format, display ) int width @@ -4514,6 +4121,64 @@ Sound_Seek ( sample, ms ) #endif +#ifdef HAVE_SDL_TTF + +int +TTF_Init () + CODE: + RETVAL = TTF_Init(); + OUTPUT: + RETVAL + +void +TTF_Quit () + CODE: + TTF_Quit(); + +TTF_Font* +TTF_OpenFont ( file, ptsize ) + char *file + int ptsize + CODE: + char* CLASS = "SDL::TTF_Font"; + RETVAL = TTF_OpenFont(file,ptsize); + OUTPUT: + RETVAL + +AV* +TTF_SizeText ( font, text ) + TTF_Font *font + char *text + CODE: + int w,h; + RETVAL = newAV(); + if(TTF_SizeText(font,text,&w,&h)) + { + printf("TTF error at TTFSizeText: %s \n", TTF_GetError()); + Perl_croak (aTHX_ "TTF error \n"); + } + else + { + av_push(RETVAL,newSViv(w)); + av_push(RETVAL,newSViv(h)); + sv_2mortal((SV*)RETVAL); + } + OUTPUT: + RETVAL + +SDL_Surface* +TTF_RenderText_Blended ( font, text, fg ) + TTF_Font *font + char *text + SDL_Color *fg + CODE: + char* CLASS = "SDL::Surface"; + RETVAL = TTF_RenderText_Blended(font,text,*fg); + OUTPUT: + RETVAL + +#endif + MODULE = SDL PACKAGE = SDL PROTOTYPES : DISABLE diff --git a/src/TTF/TTF.xs b/src/TTF/TTF.xs index e69de29..4a0df50 100644 --- a/src/TTF/TTF.xs +++ b/src/TTF/TTF.xs @@ -0,0 +1,353 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#ifndef aTHX_ +#define aTHX_ +#endif + +#include +#include + +MODULE = SDL PACKAGE = SDL +PROTOTYPES : DISABLE + + +=for comment + +These are here right now to keep them around with using the code. + +int +TTFGetFontStyle ( font ) + TTF_Font *font + CODE: + RETVAL = TTF_GetFontStyle(font); + OUTPUT: + RETVAL + +void +TTFSetFontStyle ( font, style ) + TTF_Font *font + int style + CODE: + TTF_SetFontStyle(font,style); + +int +TTFFontHeight ( font ) + TTF_Font *font + CODE: + RETVAL = TTF_FontHeight(font); + OUTPUT: + RETVAL + +int +TTFFontAscent ( font ) + TTF_Font *font + CODE: + RETVAL = TTF_FontAscent(font); + OUTPUT: + RETVAL + +int +TTFFontDescent ( font ) + TTF_Font *font + CODE: + RETVAL = TTF_FontDescent(font); + OUTPUT: + RETVAL + +int +TTFFontLineSkip ( font ) + TTF_Font *font + CODE: + RETVAL = TTF_FontLineSkip(font); + OUTPUT: + RETVAL + +AV* +TTFGlyphMetrics ( font, ch ) + TTF_Font *font + Uint16 ch + CODE: + int minx, miny, maxx, maxy, advance; + RETVAL = newAV(); + TTF_GlyphMetrics(font, ch, &minx, &miny, &maxx, &maxy, &advance); + av_push(RETVAL,newSViv(minx)); + av_push(RETVAL,newSViv(miny)); + av_push(RETVAL,newSViv(maxx)); + av_push(RETVAL,newSViv(maxy)); + av_push(RETVAL,newSViv(advance)); + OUTPUT: + RETVAL + + +AV* +TTFSizeUTF8 ( font, text ) + TTF_Font *font + char *text + CODE: + int w,h; + RETVAL = newAV(); + if(TTF_SizeUTF8(font,text,&w,&h)) + { + av_push(RETVAL,newSViv(w)); + av_push(RETVAL,newSViv(h)); + sv_2mortal((SV*)RETVAL); + + } + else + { + printf("TTF error at TTFSizeUTF8 with : %s \n", TTF_GetError()); + Perl_croak (aTHX_ "TTF error \n"); + } + + OUTPUT: + RETVAL + +AV* +TTFSizeUNICODE ( font, text ) + TTF_Font *font + const Uint16 *text + CODE: + int w,h; + RETVAL = newAV(); + if(TTF_SizeUNICODE(font,text,&w,&h)) + { + av_push(RETVAL,newSViv(w)); + av_push(RETVAL,newSViv(h)); + sv_2mortal((SV*)RETVAL); + + } + else + { + printf("TTF error at TTFSizeUNICODE : %s \n", TTF_GetError()); + Perl_croak (aTHX_ "TTF error \n"); + } + + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderTextSolid ( font, text, fg ) + TTF_Font *font + char *text + SDL_Color *fg + CODE: + RETVAL = TTF_RenderText_Solid(font,text,*fg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderUTF8Solid ( font, text, fg ) + TTF_Font *font + char *text + SDL_Color *fg + CODE: + RETVAL = TTF_RenderUTF8_Solid(font,text,*fg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderUNICODESolid ( font, text, fg ) + TTF_Font *font + const Uint16 *text + SDL_Color *fg + CODE: + RETVAL = TTF_RenderUNICODE_Solid(font,text,*fg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderGlyphSolid ( font, ch, fg ) + TTF_Font *font + Uint16 ch + SDL_Color *fg + CODE: + RETVAL = TTF_RenderGlyph_Solid(font,ch,*fg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderTextShaded ( font, text, fg, bg ) + TTF_Font *font + char *text + SDL_Color *fg + SDL_Color *bg + CODE: + RETVAL = TTF_RenderText_Shaded(font,text,*fg,*bg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderUTF8Shaded( font, text, fg, bg ) + TTF_Font *font + char *text + SDL_Color *fg + SDL_Color *bg + CODE: + RETVAL = TTF_RenderUTF8_Shaded(font,text,*fg,*bg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderUNICODEShaded( font, text, fg, bg ) + TTF_Font *font + const Uint16 *text + SDL_Color *fg + SDL_Color *bg + CODE: + RETVAL = TTF_RenderUNICODE_Shaded(font,text,*fg,*bg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderGlyphShaded ( font, ch, fg, bg ) + TTF_Font *font + Uint16 ch + SDL_Color *fg + SDL_Color *bg + CODE: + RETVAL = TTF_RenderGlyph_Shaded(font,ch,*fg,*bg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderTextBlended( font, text, fg ) + TTF_Font *font + char *text + SDL_Color *fg + CODE: + RETVAL = TTF_RenderText_Blended(font,text,*fg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderUTF8Blended( font, text, fg ) + TTF_Font *font + char *text + SDL_Color *fg + CODE: + RETVAL = TTF_RenderUTF8_Blended(font,text,*fg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderUNICODEBlended( font, text, fg ) + TTF_Font *font + const Uint16 *text + SDL_Color *fg + CODE: + RETVAL = TTF_RenderUNICODE_Blended(font,text,*fg); + OUTPUT: + RETVAL + +SDL_Surface* +TTFRenderGlyphBlended( font, ch, fg ) + TTF_Font *font + Uint16 ch + SDL_Color *fg + CODE: + RETVAL = TTF_RenderGlyph_Blended(font,ch,*fg); + OUTPUT: + RETVAL + +void +TTFCloseFont ( font ) + TTF_Font *font + CODE: + TTF_CloseFont(font); + font=NULL; //to be safe http://sdl.beuc.net/sdl.wiki/SDL_ttf_copy_Functions_Management_TTF_CloseFont + +SDL_Surface* +TTFPutString ( font, mode, surface, x, y, fg, bg, text ) + TTF_Font *font + int mode + SDL_Surface *surface + int x + int y + SDL_Color *fg + SDL_Color *bg + char *text + CODE: + SDL_Surface *img; + SDL_Rect dest; + int w,h; + dest.x = x; + dest.y = y; + RETVAL = NULL; + switch (mode) { + case TEXT_SOLID: + img = TTF_RenderText_Solid(font,text,*fg); + TTF_SizeText(font,text,&w,&h); + dest.w = w; + dest.h = h; + break; + case TEXT_SHADED: + img = TTF_RenderText_Shaded(font,text,*fg,*bg); + TTF_SizeText(font,text,&w,&h); + dest.w = w; + dest.h = h; + break; + case TEXT_BLENDED: + img = TTF_RenderText_Blended(font,text,*fg); + TTF_SizeText(font,text,&w,&h); + dest.w = w; + dest.h = h; + break; + case UTF8_SOLID: + img = TTF_RenderUTF8_Solid(font,text,*fg); + TTF_SizeUTF8(font,text,&w,&h); + dest.w = w; + dest.h = h; + break; + case UTF8_SHADED: + img = TTF_RenderUTF8_Shaded(font,text,*fg,*bg); + TTF_SizeUTF8(font,text,&w,&h); + dest.w = w; + dest.h = h; + break; + case UTF8_BLENDED: + img = TTF_RenderUTF8_Blended(font,text,*fg); + TTF_SizeUTF8(font,text,&w,&h); + dest.w = w; + dest.h = h; + break; + case UNICODE_SOLID: + img = TTF_RenderUNICODE_Solid(font,(Uint16*)text,*fg); + TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); + dest.w = w; + dest.h = h; + break; + case UNICODE_SHADED: + img = TTF_RenderUNICODE_Shaded(font,(Uint16*)text,*fg,*bg); + TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); + dest.w = w; + dest.h = h; + break; + case UNICODE_BLENDED: + img = TTF_RenderUNICODE_Blended(font,(Uint16*)text,*fg); + TTF_SizeUNICODE(font,(Uint16*)text,&w,&h); + dest.w = w; + dest.h = h; + break; + default: + img = TTF_RenderText_Shaded(font,text,*fg,*bg); + TTF_SizeText(font,text,&w,&h); + dest.w = w; + dest.h = h; + } + if ( img && img->format && img->format->palette ) { + SDL_Color *c = &img->format->palette->colors[0]; + Uint32 key = SDL_MapRGB( img->format, c->r, c->g, c->b ); + SDL_SetColorKey(img,SDL_SRCCOLORKEY,key ); + if (0 > SDL_BlitSurface(img,NULL,surface,&dest)) { + SDL_FreeSurface(img); + RETVAL = NULL; + } else { + RETVAL = img; + } + } + OUTPUT: + RETVAL + +=cut diff --git a/src/TTF/objects/TTF_Font.xs b/src/TTF/objects/TTF_Font.xs new file mode 100644 index 0000000..e8b9e0d --- /dev/null +++ b/src/TTF/objects/TTF_Font.xs @@ -0,0 +1,24 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#ifndef aTHX_ +#define aTHX_ +#endif + +#include +#include + +MODULE = SDL::TTF_Font PACKAGE = SDL::TTF_Font PREFIX = ttf_font_ + +=for documentation + +SDL_TTF_Font - The opaque holder of a loaded font + +=cut + +void +ttf_font_DESTROY(self) + TTF_Font *self + CODE: + TTF_CloseFont(self); diff --git a/src/TTF/objects/TTF_font.xs b/src/TTF/objects/TTF_font.xs deleted file mode 100644 index e69de29..0000000 diff --git a/t/core_ttf.t b/t/core_ttf.t new file mode 100644 index 0000000..9b8a22f --- /dev/null +++ b/t/core_ttf.t @@ -0,0 +1,32 @@ +#!perl +use strict; +use warnings; +use SDL::Config; +use Test::More; + +if ( SDL::Config->has('SDL_ttf') ) { + plan( tests => 10 ); +} else { + plan( skip_all => 'SDL_ttf support not compiled' ); +} + +use_ok('SDL'); +use_ok('SDL::Color'); +use_ok('SDL::Surface'); +use_ok('SDL::TTF_Font'); + +SDL::TTF_Init(); + +my $ttf_font = SDL::TTF_OpenFont( 'test/data/aircut3.ttf', 12 ); +isa_ok( $ttf_font, 'SDL::TTF_Font' ); +my ( $w, $h ) = @{ SDL::TTF_SizeText( $ttf_font, 'Hello!' ) }; +is( $w, 27, '"Hello!" has width 27' ); +is( $h, 14, '"Hello!" has width 14' ); + +my $surface = SDL::TTF_RenderText_Blended( $ttf_font, 'Hello!', + SDL::Color->new( 255, 0, 0 ) ); +isa_ok( $surface, 'SDL::Surface' ); +is( $surface->w, 27, 'Surface has width 27' ); +is( $surface->h, 14, 'Surface has width 14' ); + +SDL::TTF_Quit(); diff --git a/typemap b/typemap index f457b4d..c0e4469 100644 --- a/typemap +++ b/typemap @@ -42,7 +42,7 @@ UDPpacket * T_PTR UDPpacket ** T_PTR IPaddress* T_PTR SDLNet_GenericSocket T_PTR -TTF_Font * T_PTR +TTF_Font * O_OBJECT SDL_Overlay * T_PTR SMPEG_Info * T_PTR SMPEG * T_PTR