From: Kartik Thakore Date: Tue, 3 Nov 2009 19:30:07 +0000 (-0500) Subject: Added setters to SDL::Surface set_pixel_RGB and set_pixel_RGBA. Deprecreating SDL... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cb87a7bf27eac9e7bbead7dc2bf2ddddf022c144;p=sdlgit%2FSDL_perl.git Added setters to SDL::Surface set_pixel_RGB and set_pixel_RGBA. Deprecreating SDL::SurfacePixel --- diff --git a/src/Core/objects/Surface.xs b/src/Core/objects/Surface.xs index 74f5244..8e3816f 100644 --- a/src/Core/objects/Surface.xs +++ b/src/Core/objects/Surface.xs @@ -129,6 +129,39 @@ surface_set_pixels(surface, pixels) memcpy(surface->pixels, p, len); void +surface_set_pixel_RGB(screen, x, y, r, g, b ) + SDL_Surface *screen + int x + int y + Uint8 r + Uint8 g + Uint8 b + + CODE: + Uint32 *pixmem32; + Uint32 colour; + colour = SDL_MapRGB( screen->format, r, g, b ); + pixmem32 = screen->pixels + y + x; + *pixmem32 = colour; + +void +surface_set_pixel_RGBA(screen, x, y, r, g, b, a ) + SDL_Surface *screen + int x + int y + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + Uint32 *pixmem32; + Uint32 colour; + colour = SDL_MapRGBA( screen->format, r, g, b, a ); + pixmem32 = screen->pixels + y + x; + *pixmem32 = colour; + + +void surface_DESTROY(surface) SDL_Surface *surface CODE: @@ -137,3 +170,4 @@ surface_DESTROY(surface) SDL_FreeSurface(surface); if (flags & SDL_PREALLOC) Safefree(pixels); + diff --git a/t/core_surface.t b/t/core_surface.t index a695d07..056d6a1 100644 --- a/t/core_surface.t +++ b/t/core_surface.t @@ -17,7 +17,7 @@ use SDL::Rect; use SDL::Color; use SDL::Video; use SDL::PixelFormat; -use Test::More tests => 35; +use Test::More tests => 37; my $surface = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 ); @@ -98,7 +98,13 @@ SDL::Video::update_rects( $app, $small_rect ); diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) ); -SDL::SurfacePixel($app, 20, 20 , SDL::Color->new(20, 20, 20) ); +#depreceated +# SDL::SurfacePixel($app, 20, 20 , SDL::Color->new(20, 20, 20) ); + +$app->set_pixel_RGB( 20, 20, 100, 100, 100); pass '[set_pixel_RGB] ran!'; + +$app->set_pixel_RGBA( 20, 20, 100, 100, 10, 100); pass '[set_pixel_RGBA] ran!'; + pass 'did this pass';