Permalink
Browse files

Fixed SDL::Video::list_modes(), it returns now arrayref to SDL::Rects

  • Loading branch information...
1 parent 9caba57 commit 1c9142938a329e70419d02ec0ca67ba47a9e5147 Tobias Leich committed May 6, 2010
Showing with 61 additions and 18 deletions.
  1. +3 −0 CHANGELOG
  2. +20 −6 lib/pods/SDL/Video.pod
  3. +16 −2 src/Core/Video.xs
  4. +22 −10 t/core_video.t
View
@@ -1,5 +1,8 @@
Revision history for Perl extension SDL_perl.
+* 2.406 TBD
+ - Fixed SDL::Video::list_modes(), it returns now arrayref to SDL::Rects [FROGGS]
+
* 2.405 Wed May 05 2010
- Conditional compile on glu.h header [kthakore] {ticket 131}
- Documentation cleanup [bricas, kthakore]
View
@@ -10,8 +10,8 @@ Core, Video
=head1 SYNOPSIS
- use SDL ':init';
- use SDL::Video ':all';
+ use SDL;
+ use SDL::Video;
use SDL::Surface;
use SDL::Rect;
@@ -176,8 +176,22 @@ Example:
my @modes = @{ SDL::Video::list_modes( $pixel_format, $flags ) };
-Returns a ref to an array of available screen dimensions for the given format and video flags,
-or it return undef if no modes are available.
+Returns a reference to an array:
+
+=over 4
+
+=item *
+of available screen dimensions (as C<SDL::Rect>'s) for the given format and video flags.
+
+=item *
+with first array element 'all'. In this case you can set all modes.
+
+=item *
+with first array element 'none' if no mode is available.
+
+=back
+
+B<Note>: <list_modes> should be called before the video_mode ist set. Otherwise you will always get 'all'.
Example:
@@ -196,9 +210,9 @@ Example:
if($#modes > 0)
{
print("available modes:\n");
- foreach my $index ( @modes )
+ foreach my $mode ( @modes )
{
- printf("%03d: %d x %d\n", $index, $modes[$index]->w, $modes[$index]->h );
+ printf("%d x %d\n", $mode->w, $mode->h );
}
}
elsif($#modes == 0)
View
@@ -8,6 +8,8 @@
#include <SDL.h>
+PerlInterpreter * perl = NULL;
+
void _uinta_free(Uint16* av, int len_from_av_len)
{
if( av != NULL)
@@ -101,6 +103,8 @@ video_list_modes ( format, flags )
SDL_PixelFormat *format
CODE:
+ if(!perl)
+ perl = PERL_GET_CONTEXT;
SDL_Rect **mode;
RETVAL = newAV();
sv_2mortal((SV*)RETVAL);
@@ -110,8 +114,18 @@ video_list_modes ( format, flags )
} else if (! mode ) {
av_push(RETVAL,newSVpv("none",0));
} else {
- for (;*mode;mode++) {
- av_push(RETVAL,newSViv(PTR2IV(*mode)));
+ int i;
+ for (i=0; mode[i]; ++i)
+ {
+ SV *rectref = newSV( sizeof(SDL_Rect *) );
+ void *copyRect = safemalloc( sizeof(SDL_Rect) );
+ memcpy( copyRect, mode[i], sizeof(SDL_Rect) );
+
+ void** pointers = malloc(2 * sizeof(void*));
+ pointers[0] = (void*)copyRect;
+ pointers[1] = (void*)perl;
+
+ av_push(RETVAL, newSVsv(sv_setref_pv(rectref, "SDL::Rect", (void *)pointers)));
}
}
OUTPUT:
View
@@ -19,10 +19,6 @@ $ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
plan( skip_all => 'Failed to init video' );
}
-else
-{
- plan( tests => 115);
-}
my @done =
qw/
@@ -156,6 +152,25 @@ SDL::Video::GL_swap_buffers(); pass ( '[GL_swap_buffers] should work because Dou
};
+my $video_info = SDL::Video::get_video_info();
+isa_ok($video_info, 'SDL::VideoInfo', '[get_video_info] Checking if we get videoinfo ref back');
+
+my $list_modes = SDL::Video::list_modes($video_info->vfmt, SDL_NOFRAME | SDL_HWSURFACE | SDL_FULLSCREEN);
+is( ref( $list_modes ), 'ARRAY', '[list_modes] Returned an ARRAY! ');
+
+my @modes = @{ $list_modes };
+
+if($#modes > 0)
+{
+ foreach my $mode ( @modes )
+ {
+ ok($mode->w > 0 && $mode->h > 0, '[list_modes] available mode: ' . $mode->w . ' x ' . $mode->h);
+ }
+}
+elsif($#modes == 0)
+{
+ is($modes[0], 'all', '[list_modes] available mode: all');
+}
my $display = SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE );
@@ -167,14 +182,9 @@ if(!$display){
isa_ok(SDL::Video::get_video_surface(), 'SDL::Surface', '[get_video_surface] Checking if we get a surface ref back');
-my $video_info = SDL::Video::get_video_info();
-isa_ok($video_info, 'SDL::VideoInfo', '[get_video_info] Checking if we get videoinfo ref back');
-
my $driver_name = SDL::Video::video_driver_name();
pass '[video_driver_name] This is your driver name: '.$driver_name;
-is( ref( SDL::Video::list_modes( $display->format , SDL_SWSURFACE )), 'ARRAY', '[list_modes] Returned an ARRAY! ');
-
cmp_ok(SDL::Video::video_mode_ok( 100, 100, 16, SDL_SWSURFACE), '>=', 0, "[video_mode_ok] Checking if an integer was return");
$display = SDL::Video::set_video_mode( 100, 100 ,16, SDL_SWSURFACE);
@@ -362,4 +372,6 @@ $ENV{SDL_VIDEODRIVER} = $videodriver;
pass 'Are we still alive? Checking for segfaults';
-sleep(2);
+sleep(1);
+
+done_testing();

0 comments on commit 1c91429

Please sign in to comment.