From: Leon Brocard Date: Thu, 15 Oct 2009 06:18:05 +0000 (+0100) Subject: try seperating out surface - not quite working yet X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88a46efcf6e474bacd1399d8dbb590e4a183bff3;p=sdlgit%2FSDL_perl.git try seperating out surface - not quite working yet --- diff --git a/Build.PL b/Build.PL index 55d6148..676c02d 100644 --- a/Build.PL +++ b/Build.PL @@ -55,6 +55,13 @@ my %subsystems = }, libraries => [qw( SDL )], }, + Surface => { + file => { + from => 'src/Surface.xs', + to => 'lib/SDL/Surface.xs', + }, + libraries => [qw( SDL SDL_image )], + }, OpenGL => { file => { from => 'src/OpenGL.xs', diff --git a/lib/SDL/Surface.pm b/lib/SDL/Surface.pm index 35796c9..0d58261 100644 --- a/lib/SDL/Surface.pm +++ b/lib/SDL/Surface.pm @@ -1,3 +1,15 @@ +package SDL::Surface; +use strict; +use warnings; +require Exporter; +require DynaLoader; +our @ISA = qw(Exporter DynaLoader); +bootstrap SDL::Surface; + +1; + +__END__ + #!/usr/bin/env perl # # Surface.pm diff --git a/src/SDL.xs b/src/SDL.xs index a415673..cc0d135 100644 --- a/src/SDL.xs +++ b/src/SDL.xs @@ -858,22 +858,9 @@ GetKeyName ( sym ) OUTPUT: RETVAL -SDL_Surface * -CreateRGBSurface (flags, width, height, depth, Rmask, Gmask, Bmask, Amask ) - Uint32 flags - int width - int height - int depth - Uint32 Rmask - Uint32 Gmask - Uint32 Bmask - Uint32 Amask - CODE: - RETVAL = SDL_CreateRGBSurface ( flags, width, height, - depth, Rmask, Gmask, Bmask, Amask ); - OUTPUT: - RETVAL +=for comment +Comment out for now as it does not compile SDL_Surface * CreateRGBSurfaceFrom (pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask ) @@ -1079,6 +1066,8 @@ SurfacePixels ( surface ) OUTPUT: RETVAL +=cut + =for comment Comment out for now as it does not compile @@ -1147,8 +1136,6 @@ SurfacePixel ( surface, x, y, ... ) OUTPUT: RETVAL -=cut - int MUSTLOCK ( surface ) SDL_Surface *surface @@ -1178,6 +1165,7 @@ GetVideoSurface () OUTPUT: RETVAL +=cut HV * VideoInfo () @@ -1251,6 +1239,28 @@ PaletteNColors ( palette, ... ) OUTPUT: RETVAL +SDL_Surface * +SetVideoMode ( width, height, bpp, flags ) + int width + int height + int bpp + Uint32 flags + + CODE: + char* CLASS; + RETVAL = SDL_SetVideoMode(width,height,bpp,flags); + OUTPUT: + RETVAL + +int +Flip ( surface ) + SDL_Surface *surface + CODE: + RETVAL = SDL_Flip(surface); + OUTPUT: + RETVAL + + =for comment Comment out for now as it does not compile @@ -1269,7 +1279,7 @@ PaletteColors ( palette, index, ... ) OUTPUT: RETVAL -=cut + int VideoModeOK ( width, height, bpp, flags ) @@ -1311,7 +1321,7 @@ UpdateRects ( surface, ... ) int num_rects,i; if ( items < 2 ) return; num_rects = items - 1; - + SDL_UpdateRects(surface,num_rects,rects); rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items); for(i=0;i + +MODULE = SDL::Surface PACKAGE = SDL::Surface PREFIX = surface_ + +=for documentation + +SDL_Surface -- Graphic surface structure + + typedef struct SDL_Surface { + Uint32 flags; /* Read-only */ + SDL_PixelFormat *format; /* Read-only */ + int w, h; /* Read-only */ + Uint16 pitch; /* Read-only */ + void *pixels; /* Read-write */ + SDL_Rect clip_rect; /* Read-only */ + int refcount; /* Read-mostly */ + + /* This structure also contains private fields not shown here */ + } SDL_Surface; + +=cut + +SDL_Surface * +surface_new (CLASS, flags, width, height, depth, Rmask, Gmask, Bmask, Amask ) + char* CLASS + Uint32 flags + int width + int height + int depth + Uint32 Rmask + Uint32 Gmask + Uint32 Bmask + Uint32 Amask + CODE: + RETVAL = SDL_CreateRGBSurface ( flags, width, height, + depth, Rmask, Gmask, Bmask, Amask ); + OUTPUT: + RETVAL + + +SDL_Surface * +surface_load (CLASS, filename ) + char* CLASS + char* filename + CODE: + RETVAL = IMG_Load(filename); + OUTPUT: + RETVAL + +int +surface_blit ( src, src_rect, dest, dest_rect ) + SDL_Surface *src + SDL_Surface *dest + SDL_Rect *src_rect + SDL_Rect *dest_rect + CODE: + RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect); + OUTPUT: + RETVAL + +int +surface_fill_rect ( dest, dest_rect, color ) + SDL_Surface *dest + SDL_Color *color + SDL_Rect *dest_rect + CODE: + Uint32 pixel = SDL_MapRGB(dest->format,color->r,color->g,color->b); + RETVAL = SDL_FillRect(dest,dest_rect,pixel); + OUTPUT: + RETVAL + +void +surface_update_rect ( surface, x, y, w ,h ) + SDL_Surface *surface + int x + int y + int w + int h + CODE: + SDL_UpdateRect(surface,x,y,w,h); + +void +surface_update_rects ( surface, ... ) + SDL_Surface *surface + CODE: + SDL_Rect *rects, *temp; + int num_rects,i; + if ( items < 2 ) return; + num_rects = items - 1; + + rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items); + for(i=0;ix; + rects[i].y = temp->y; + rects[i].w = temp->w; + rects[i].h = temp->h; + } + SDL_UpdateRects(surface,num_rects,rects); + safefree(rects); + +SDL_Surface * +surface_display ( surface ) + SDL_Surface *surface + CODE: + char* CLASS = 'SDL::Surface\0'; + RETVAL = SDL_DisplayFormat(surface); + OUTPUT: + RETVAL + +Uint16 +surface_w ( surface ) + SDL_Surface *surface + CODE: + RETVAL = surface->w; + OUTPUT: + RETVAL + +Uint16 +surface_h ( surface ) + SDL_Surface *surface + CODE: + RETVAL = surface->h; + OUTPUT: + RETVAL + +void +surface_DESTROY(surface) + SDL_Surface *surface + CODE: + Uint8* pixels = surface->pixels; + Uint32 flags = surface->flags; + SDL_FreeSurface(surface); + if (flags & SDL_PREALLOC) + Safefree(pixels); diff --git a/t/intergation1.t b/t/intergation1.t index 7b71d66..69c4e07 100644 --- a/t/intergation1.t +++ b/t/intergation1.t @@ -62,7 +62,7 @@ can_ok ('SDL::App', qw/ my $app = SDL::App->new(-title => "Test", -width => 640, -height => 480, -init => SDL_INIT_VIDEO); - my $rect = SDL::Rect->new( 0,0, $app->width, $app->height); + my $rect = SDL::Rect->new( 0,0, $app->w, $app->h); my $blue = SDL::Color->new( 0x00, @@ -85,12 +85,12 @@ my $app = SDL::App->new(-title => "Test", -width => 640, -height => 480, -init $grect->x($_ ); $grect->centery($_ * 3); $grect->size( ($_ / 40) * $_, ($_/38) * $_ ); - $app->fill($rect, $blue); - $app->fill($grect, $col); + $app->fill_rect($rect, $blue); + $app->fill_rect($grect, $col); - $app->update($rect); - $app->update($grect); + $app->update_rects($rect); + $app->update_rects($grect); $app->sync; } diff --git a/t/surfacepm.t b/t/surfacepm.t index 9e698b3..243af6d 100644 --- a/t/surfacepm.t +++ b/t/surfacepm.t @@ -1,113 +1,33 @@ -#!/usr/bin/perl -w -# -# Copyright (C) 2003 Tels -# Copyright (C) 2004 David J. Goehrig -# -# Copyright (C) 2005 David J. Goehrig -# -# ------------------------------------------------------------------------------ -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# -# ------------------------------------------------------------------------------ -# -# Please feel free to send questions, suggestions or improvements to: -# -# David J. Goehrig -# dgoehrig\@cpan.org -# -# -# basic testing of SDL::Surface - -BEGIN { - unshift @INC, 'blib/lib','blib/arch'; -} - +#!perl use strict; +use warnings; +use Test::More tests => 11; +use_ok('SDL'); +use_ok('SDL::Color'); +use_ok('SDL::Rect'); +use_ok('SDL::Surface'); + +my $surface + = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 0, 0, 0, 0, 0 ); +isa_ok( $surface, 'SDL::Surface' ); +is( $surface->w, 640, 'surface has width' ); +is( $surface->h, 320, 'surface has height' ); + +my $image = SDL::Surface->load('test/data/logo.png'); +is( $image->w, 608, 'image has width' ); +is( $image->h, 126, 'image has height' ); + +$surface->fill_rect( SDL::Rect->new( 0, 0, 32, 32 ), + SDL::Color->new( 200, 200, 200 ) ); +ok( 1, 'Managed to fill_rect' ); + +my $rect = SDL::Rect->new( 0, 0, 64, 64 ); +$image->blit( $rect, $surface, $rect ); +ok( 1, 'Managed to blit' ); + +#my $image_format = $surface->display; +#$surface->update_rect( 0, 0, 32, 32 ); +#ok( 1, 'Managed to update_rect' ); +#$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) ); +#ok( 1, 'Managed to update_rects' ); -use Test::More; - -plan ( tests => 3 ); - -use_ok( 'SDL::Surface' ); - -can_ok ('SDL::Surface', qw/ - new - flags - palette - bpp - bytes_per_pixel - Rshift - Gshift - Bshift - Ashift - Rmask - Bmask - Gmask - Amask - color_key - alpha - width - height - pitch - pixels - pixel - fill - lockp - lock - unlock - update - flip - blit - set_colors - set_color_key - set_alpha - display_format - rgb - rgba - print - save_bmp - video_info /); - -my $surface = SDL::Surface->new(); - -isa_ok($surface,'SDL::Surface'); - -# -# Copyright (C) 2005 David J. Goehrig -# -# ------------------------------------------------------------------------------ -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# -# ------------------------------------------------------------------------------ -# -# Please feel free to send questions, suggestions or improvements to: -# -# David J. Goehrig -# dgoehrig\@cpan.org -# diff --git a/typemap b/typemap index 756be5b..574a878 100644 --- a/typemap +++ b/typemap @@ -14,7 +14,7 @@ Sint16 * T_PTR Sint32 T_IV Sint32 * T_PTR SDL_Event * T_PTR -SDL_Surface * T_PTR +SDL_Surface * O_OBJECT SDL_SysWMmsg * T_PTR SDL_CD * T_PTR SDL_CDtrack * T_PTR