From 11914b068199d01dc62237ebbebebca76280e973 Mon Sep 17 00:00:00 2001 From: Tobias Leich Date: Mon, 30 Nov 2009 23:09:28 +0100 Subject: [PATCH] xs for SDL::GFX::Primitives done, test and docs open [Ticket #73] --- src/GFX/Primitives.xs | 779 ++++++++++++++++++++++++++++++++++++++++++ t/gfx_primitives.t | 91 ++++- typemap | 2 + 3 files changed, 863 insertions(+), 9 deletions(-) diff --git a/src/GFX/Primitives.xs b/src/GFX/Primitives.xs index 96cc983b..b1c271d8 100644 --- a/src/GFX/Primitives.xs +++ b/src/GFX/Primitives.xs @@ -21,6 +21,8 @@ See: L =cut +#ifdef HAVE_SDL_GFX + int gfx_prim_pixel_color(dst, x, y, color) SDL_Surface *dst @@ -32,4 +34,781 @@ gfx_prim_pixel_color(dst, x, y, color) OUTPUT: RETVAL +int +gfx_prim_pixel_RGBA(dst, x, y, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = pixelRGBA(dst, x, y, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_hline_color(dst, x1, x2, y, color) + SDL_Surface * dst + Sint16 x1 + Sint16 x2 + Sint16 y + Uint32 color + CODE: + RETVAL = hlineColor(dst, x1, x2, y, color); + OUTPUT: + RETVAL + +int +gfx_prim_hline_RGBA(dst, x1, x2, y, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 x2 + Sint16 y + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = hlineRGBA(dst, x1, x2, y, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_vline_color(dst, x, y1, y2, color) + SDL_Surface * dst + Sint16 x + Sint16 y1 + Sint16 y2 + Uint32 color + CODE: + RETVAL = vlineColor(dst, x, y1, y2, color); + OUTPUT: + RETVAL + +int +gfx_prim_vline_RGBA(dst, x, y1, y2, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y1 + Sint16 y2 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = vlineRGBA(dst, x, y1, y2, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_rectangle_color(dst, x1, y1, x2, y2, color) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint32 color + CODE: + RETVAL = rectangleColor(dst, x1, y1, x2, y2, color); + OUTPUT: + RETVAL + +int +gfx_prim_rectangle_RGBA(dst, x1, y1, x2, y2, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = rectangleRGBA(dst, x1, y1, x2, y2, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_box_color(dst, x1, y1, x2, y2, color) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint32 color + CODE: + RETVAL = boxColor(dst, x1, y1, x2, y2, color); + OUTPUT: + RETVAL + +int +gfx_prim_box_RGBA(dst, x1, y1, x2, y2, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = boxRGBA(dst, x1, y1, x2, y2, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_line_color(dst, x1, y1, x2, y2, color) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint32 color + CODE: + RETVAL = lineColor(dst, x1, y1, x2, y2, color); + OUTPUT: + RETVAL +int +gfx_prim_line_RGBA(dst, x1, y1, x2, y2, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = lineRGBA(dst, x1, y1, x2, y2, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_aaline_color(dst, x1, y1, x2, y2, color) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint32 color + CODE: + RETVAL = aalineColor(dst, x1, y1, x2, y2, color); + OUTPUT: + RETVAL + +int +gfx_prim_aaline_RGBA(dst, x1, y1, x2, y2, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = aalineRGBA(dst, x1, y1, x2, y2, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_circle_color(dst, x, y, r, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 r + Uint32 color + CODE: + RETVAL = circleColor(dst, x, y, r, color); + OUTPUT: + RETVAL + +int +gfx_prim_circle_RGBA(dst, x, y, rad, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = circleRGBA(dst, x, y, rad, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_arc_color(dst, x, y, r, start, end, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 r + Sint16 start + Sint16 end + Uint32 color + CODE: + RETVAL = arcColor(dst, x, y, r, start, end, color); + OUTPUT: + RETVAL + +int +gfx_prim_arc_RGBA(dst, x, y, rad, start, end, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Sint16 start + Sint16 end + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = arcRGBA(dst, x, y, rad, start, end, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_aacircle_color(dst, x, y, r, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 r + Uint32 color + CODE: + RETVAL = aacircleColor(dst, x, y, r, color); + OUTPUT: + RETVAL + +int +gfx_prim_aacircle_RGBA(dst, x, y, rad, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = aacircleRGBA(dst, x, y, rad, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_filled_circle_color(dst, x, y, r, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 r + Uint32 color + CODE: + RETVAL = filledCircleColor(dst, x, y, r, color); + OUTPUT: + RETVAL + +int +gfx_prim_filled_circle_RGBA(dst, x, y, rad, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = filledCircleRGBA(dst, x, y, rad, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_ellipse_color(dst, x, y, rx, ry, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rx + Sint16 ry + Uint32 color + CODE: + RETVAL = ellipseColor(dst, x, y, rx, ry, color); + OUTPUT: + RETVAL + +int +gfx_prim_ellipse_RGBA(dst, x, y, rx, ry, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rx + Sint16 ry + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = ellipseRGBA(dst, x, y, rx, ry, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_aaellipse_color(dst, xc, yc, rx, ry, color) + SDL_Surface * dst + Sint16 xc + Sint16 yc + Sint16 rx + Sint16 ry + Uint32 color + CODE: + RETVAL = aaellipseColor(dst, xc, yc, rx, ry, color); + OUTPUT: + RETVAL + +int +gfx_prim_aaellipse_RGBA(dst, x, y, rx, ry, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rx + Sint16 ry + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = aaellipseRGBA(dst, x, y, rx, ry, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_filled_ellipse_color(dst, x, y, rx, ry, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rx + Sint16 ry + Uint32 color + CODE: + RETVAL = filledEllipseColor(dst, x, y, rx, ry, color); + OUTPUT: + RETVAL + +int +gfx_prim_filled_ellipse_RGBA(dst, x, y, rx, ry, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rx + Sint16 ry + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = filledEllipseRGBA(dst, x, y, rx, ry, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_pie_color(dst, x, y, rad, start, end, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Sint16 start + Sint16 end + Uint32 color + CODE: + RETVAL = pieColor(dst, x, y, rad, start, end, color); + OUTPUT: + RETVAL + +int +gfx_prim_pie_RGBA(dst, x, y, rad, start, end, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Sint16 start + Sint16 end + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = pieRGBA(dst, x, y, rad, start, end, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_filled_pie_color(dst, x, y, rad, start, end, color) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Sint16 start + Sint16 end + Uint32 color + CODE: + RETVAL = filledPieColor(dst, x, y, rad, start, end, color); + OUTPUT: + RETVAL + +int +gfx_prim_filled_pie_RGBA(dst, x, y, rad, start, end, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + Sint16 rad + Sint16 start + Sint16 end + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = filledPieRGBA(dst, x, y, rad, start, end, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_trigon_color(dst, x1, y1, x2, y2, x3, y3, color) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Sint16 x3 + Sint16 y3 + Uint32 color + CODE: + RETVAL = trigonColor(dst, x1, y1, x2, y2, x3, y3, color); + OUTPUT: + RETVAL + +int +gfx_prim_trigon_RGBA(dst, x1, y1, x2, y2, x3, y3, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Sint16 x3 + Sint16 y3 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = trigonRGBA(dst, x1, y1, x2, y2, x3, y3, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_aatrigon_color(dst, x1, y1, x2, y2, x3, y3, color) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Sint16 x3 + Sint16 y3 + Uint32 color + CODE: + RETVAL = aatrigonColor(dst, x1, y1, x2, y2, x3, y3, color); + OUTPUT: + RETVAL + +int +gfx_prim_aatrigon_RGBA(dst, x1, y1, x2, y2, x3, y3, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Sint16 x3 + Sint16 y3 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = aatrigonRGBA(dst, x1, y1, x2, y2, x3, y3, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_filled_trigon_color(dst, x1, y1, x2, y2, x3, y3, color) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Sint16 x3 + Sint16 y3 + Uint32 color + CODE: + RETVAL = filledTrigonColor(dst, x1, y1, x2, y2, x3, y3, color); + OUTPUT: + RETVAL + +int +gfx_prim_filled_trigon_RGBA(dst, x1, y1, x2, y2, x3, y3, r, g, b, a) + SDL_Surface * dst + Sint16 x1 + Sint16 y1 + Sint16 x2 + Sint16 y2 + Sint16 x3 + Sint16 y3 + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = filledTrigonRGBA(dst, x1, y1, x2, y2, x3, y3, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_polygon_color(dst, vx, vy, n, color) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint32 color + CODE: + RETVAL = polygonColor(dst, vx, vy, n, color); + OUTPUT: + RETVAL + +int +gfx_prim_polygon_RGBA(dst, vx, vy, n, r, g, b, a) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = polygonRGBA(dst, vx, vy, n, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_aapolygon_color(dst, vx, vy, n, color) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint32 color + CODE: + RETVAL = aapolygonColor(dst, vx, vy, n, color); + OUTPUT: + RETVAL + +int +gfx_prim_aapolygon_RGBA(dst, vx, vy, n, r, g, b, a) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = aapolygonRGBA(dst, vx, vy, n, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_filled_polygon_color(dst, vx, vy, n, color) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint32 color + CODE: + RETVAL = filledPolygonColor(dst, vx, vy, n, color); + OUTPUT: + RETVAL + +int +gfx_prim_filled_polygon_RGBA(dst, vx, vy, n, r, g, b, a) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = filledPolygonRGBA(dst, vx, vy, n, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_textured_polygon(dst, vx, vy, n, texture, texture_dx, texture_dy) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + SDL_Surface * texture + int texture_dx + int texture_dy + CODE: + RETVAL = texturedPolygon(dst, vx, vy, n, texture, texture_dx, texture_dy); + OUTPUT: + RETVAL + +int +gfx_prim_filled_polygon_color_MT(dst, vx, vy, n, color, polyInts, polyAllocated) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint32 color + int **polyInts + int *polyAllocated + CODE: + RETVAL = filledPolygonColorMT(dst, vx, vy, n, color, polyInts, polyAllocated); + OUTPUT: + RETVAL + +int +gfx_prim_filled_polygon_RGBA_MT(dst, vx, vy, n, r, g, b, a, polyInts, polyAllocated) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + Uint8 r + Uint8 g + Uint8 b + Uint8 a + int **polyInts + int *polyAllocated + CODE: + RETVAL = filledPolygonRGBAMT(dst, vx, vy, n, r, g, b, a, polyInts, polyAllocated); + OUTPUT: + RETVAL + +int +gfx_prim_textured_polygon_MT(dst, vx, vy, n, texture, texture_dx, texture_dy, polyInts, polyAllocated) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + SDL_Surface * texture + int texture_dx + int texture_dy + int **polyInts + int *polyAllocated + CODE: + RETVAL = texturedPolygonMT(dst, vx, vy, n, texture, texture_dx, texture_dy, polyInts, polyAllocated); + OUTPUT: + RETVAL + +int +gfx_prim_bezier_color(dst, vx, vy, n, s, color) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + int s + Uint32 color + CODE: + RETVAL = bezierColor(dst, vx, vy, n, s, color); + OUTPUT: + RETVAL + +int +gfx_prim_bezier_RGBA(dst, vx, vy, n, s, r, g, b, a) + SDL_Surface * dst + const Sint16 * vx + const Sint16 * vy + int n + int s + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = bezierRGBA(dst, vx, vy, n, s, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_character_color(dst, x, y, c, color) + SDL_Surface * dst + Sint16 x + Sint16 y + char c + Uint32 color + CODE: + RETVAL = characterColor(dst, x, y, c, color); + OUTPUT: + RETVAL + +int +gfx_prim_character_RGBA(dst, x, y, c, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + char c + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = characterRGBA(dst, x, y, c, r, g, b, a); + OUTPUT: + RETVAL + +int +gfx_prim_string_color(dst, x, y, c, color) + SDL_Surface * dst + Sint16 x + Sint16 y + const char *c + Uint32 color + CODE: + RETVAL = stringColor(dst, x, y, c, color); + OUTPUT: + RETVAL + +int +gfx_prim_string_RGBA(dst, x, y, c, r, g, b, a) + SDL_Surface * dst + Sint16 x + Sint16 y + const char *c + Uint8 r + Uint8 g + Uint8 b + Uint8 a + CODE: + RETVAL = stringRGBA(dst, x, y, c, r, g, b, a); + OUTPUT: + RETVAL + +void +gfx_prim_set_font(fontdata, cw, ch) + void *fontdata + int cw + int ch + CODE: + gfxPrimitivesSetFont(fontdata, cw, ch); + +#endif diff --git a/t/gfx_primitives.t b/t/gfx_primitives.t index 7518a82b..a1f37944 100644 --- a/t/gfx_primitives.t +++ b/t/gfx_primitives.t @@ -22,15 +22,19 @@ elsif( !SDL::Config->has('SDL_gfx') ) } else { - plan( tests => 5 ); + plan( tests => 6 ); } +my @done =qw/ +pixel_color +/; + use_ok('SDL'); use_ok('SDL::Surface'); use_ok('SDL::GFX::Primitives'); -my $display = SDL::Video::set_video_mode(640,480,32, SDL_HWSURFACE ); -my $pixel = SDL::Video::map_RGB( $display->format, 127, 127, 127 ); +my $display = SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE ); +my $pixel = SDL::Video::map_RGB( $display->format, 0, 0, 0 ); SDL::Video::fill_rect( $display, SDL::Rect->new( 0, 0, $display->w, $display->h ), $pixel ); @@ -40,22 +44,91 @@ if(!$display) } -#SDL::Video::lock_surface($display) if(SDL::Video::MUSTLOCK($display)); +SDL::Video::lock_surface($display) if(SDL::Video::MUSTLOCK($display)); my $col = 0xFF00FF00; for(0..256) -{ - $col++; -SDL::GFX::Primitives::pixel_color($display, 5+$_, 5+$_, $col) +{ + $col++; + SDL::GFX::Primitives::pixel_color($display, 5 + $_, 5 + $_, $col); } is( SDL::GFX::Primitives::pixel_color($display, 5, 5, 0xFF00FFFF), 0, 'pixel_color' ); -#SDL::Video::unlock_surface($display) if(SDL::Video::MUSTLOCK($display)); +SDL::Video::unlock_surface($display) if(SDL::Video::MUSTLOCK($display)); SDL::Video::update_rect($display, 0, 0, 640, 480); -SDL::delay(2000); +SDL::delay(100); + +my @left = qw/ +pixel_RGBA +hline_color +hline_RGBA +vline_color +vline_RGBA +rectangle_color +rectangle_RGBA +box_color +box_RGBA +line_color +line_RGBA +aaline_color +aaline_RGBA +circle_color +circle_RGBA +arc_color +arc_RGBA +aacircle_color +aacircle_RGBA +filled_circle_color +filled_circle_RGBA +ellipse_color +ellipse_RGBA +aaellipse_color +aaellipse_RGBA +filled_ellipse_color +filled_ellipse_RGBA +pie_color +pie_RGBA +filled_pie_color +filled_pie_RGBA +trigon_color +trigon_RGBA +aatrigon_color +aatrigon_RGBA +filled_trigon_color +filled_trigon_RGBA +polygon_color +polygon_RGBA +aapolygon_color +aapolygon_RGBA +filled_polygon_color +filled_polygon_RGBA +textured_polygon +filled_polygon_color_MT +filled_polygon_RGBA_MT +textured_polygon_MT +bezier_color +bezier_RGBA +character_color +character_RGBA +string_color +string_RGBA +set_font +/; + +my $why = '[Percentage Completion] '.int( 100 * ($#done +1 ) / ($#done + $#left + 2 ) ) .'% implementation. '.($#done +1 ).'/'.($#done+$#left + 2 ); + +TODO: +{ + local $TODO = $why; + pass "\nThe following functions:\n".join ",", @left; +} +if( $done[0] eq 'none'){ diag '0% done 0/'.$#left } else { diag $why} pass 'Are we still alive? Checking for segfaults'; +done_testing; + + diff --git a/typemap b/typemap index 89d1f986..fe1f8929 100644 --- a/typemap +++ b/typemap @@ -1,5 +1,6 @@ TYPEMAP const Uint16 * T_PTR +const Sint16 * T_PTR Uint8 T_U_CHAR Uint8 * T_PTR const Uint8* T_PTR @@ -52,6 +53,7 @@ Mix_Chunk * O_OBJECT Mix_Music * O_OBJECT SDL_GLattr T_IV int * T_PTR +int ** T_PTR void * T_PTR SDL_TimerID T_PTR SDL_NewTimerCallback T_PTR