Skip to content
Browse files

fixes, tests and docs for SDLx::SFont->new( $rwops )

  • Loading branch information...
1 parent faf2655 commit 43c3ba807758b078c016ac78df78492c0d420aeb @FROGGS FROGGS committed Jul 21, 2011
Showing with 33 additions and 24 deletions.
  1. +18 −16 lib/pods/SDLx/SFont.pod
  2. +9 −8 src/SDLx/SFont.xs
  3. +6 −0 t/sdlx_sfont.t
View
34 lib/pods/SDLx/SFont.pod
@@ -11,30 +11,32 @@ Extension
use SDLx::SFont;
use SDLx::App;
+
+ # in case you want to load fonts from an scalar
+ use SDL::RWOps;
- #Make a surface
- #Select a font
- my $d = SDLx::App->new( title => 'app', width => 200, height => 200, depth => 32 );
+ # Make a surface
+ # Select a font
+ my $d = SDLx::App->new( title => 'app', width => 200, height => 200, depth => 32 );
- my $font = SDLx::SFont->new('t/font.png');
+ my $font = SDLx::SFont->new('t/font.png');
- #print using $font
-
- SDLx::SFont::print_text( $d, 10, 10, 'Huh' );
-
- my $font2 = SDLx::SFont->new('t/font2.png');
+ # print using $font
+ SDLx::SFont::print_text( $d, 10, 10, 'Huh' );
- #print using font2
+ # print using font2
+ SDLx::SFont::print_text( $d, 10, 10, 'Huh' );
- SDLx::SFont::print_text( $d, 10, 10, 'Huh' );
+ # print using a font from an SDL::RWOps object
+ my $font3 = SDLx::SFont->new( SDL::RWOps->new_file( 't/font2.png', 'r' ) );
+ SDLx::SFont::print_text( $d, 10, 10, 'Huh' );
- $font->use();
+ $font->use();
- #print using $font
-
- SDLx::SFont::print_text( $d, 10, 10, 'Huh' );
+ # print using $font
+ SDLx::SFont::print_text( $d, 10, 10, 'Huh' );
- #that is it folks ..
+ # that is it folks ..
=head1 DESCRIPTION
View
17 src/SDLx/SFont.xs
@@ -31,6 +31,7 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
+#include "helper.h"
#include "ppport.h"
#ifndef aTHX_
@@ -278,19 +279,19 @@ st_new ( CLASS, sv )
SV *sv
CODE:
#ifdef HAVE_SDL_IMAGE
- STRLEN len;
- unsigned char *scalar = SvPV(sv, len);
if(SvOK(sv) && sv_isobject(sv) && sv_derived_from(sv, "SDL::RWOps"))
+ RETVAL = IMG_LoadTyped_RW((SDL_RWops *)bag2obj(sv), 1, NULL);
+ else
{
- SDL_RWops *rwops = SDL_RWFromConstMem((const void*)scalar, len);
- if(rwops)
- RETVAL = IMG_LoadTyped_RW(rwops, 1, NULL);
+ STRLEN len;
+ unsigned char *text = SvPV(sv, len);
+ RETVAL = IMG_Load(text);
}
- else
- RETVAL = IMG_Load(scalar);
#else
SDL_SetError("SDL_image not available for SFont. Using SDL_loadBMP instead of IMG_Load.");
- RETVAL = SDL_LoadBMP(scalar);
+ STRLEN len;
+ unsigned char *text = SvPV(sv, len);
+ RETVAL = SDL_LoadBMP(text);
#endif
SFont_InitFont(RETVAL);
OUTPUT:
View
6 t/sdlx_sfont.t
@@ -4,6 +4,7 @@ use Test::More;
use SDL;
use SDL::Config;
use SDL::Video;
+use SDL::RWOps;
use SDL::Surface;
use SDLx::SFont;
use lib 't/lib';
@@ -30,6 +31,11 @@ my $font = SDLx::SFont->new( 'test/data/font.' . ( SDL::Config->has('png') ? 'pn
isa_ok( $font, 'SDL::Surface', '[new] makes surface' );
+my $rwops = SDL::RWOps->new_file( 'test/data/font.' . ( SDL::Config->has('png') ? 'png' : 'bmp' ), 'rw' );
+my $font2 = SDLx::SFont->new( $rwops );
+
+isa_ok( $font2, 'SDL::Surface', '[new] makes surface from SDL::RWOps' );
+
#print using $font
SDLx::SFont::print_text( $d, 10, 10, 'Huh' );

0 comments on commit 43c3ba8

Please sign in to comment.
Something went wrong with that request. Please try again.