Skip to content

Commit

Permalink
SDLx::Surface::draw_polygon should return $self
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer committed Jul 1, 2011
1 parent fa867d3 commit 0cff9b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/SDLx/Surface.xs
Expand Up @@ -202,13 +202,14 @@ surfacex_draw_rect ( surface, rt, color )

#ifdef HAVE_SDL_GFX_PRIMITIVES

int
surfacex_draw_polygon(surface, vectors, color, antialias=0)
SDL_Surface * surface
SV *
surfacex_draw_polygon ( surface, vectors, color, antialias=0 )
SV* surface
AV* vectors
Uint32 color
int antialias
CODE:
SDL_Surface * _surface = (SDL_Surface *)bag2obj(surface);
AV* vx = newAV();
AV* vy = newAV();
AV* vertex;
Expand All @@ -222,11 +223,13 @@ surfacex_draw_polygon(surface, vectors, color, antialias=0)

Sint16 * _vx = av_to_sint16(vx);
Sint16 * _vy = av_to_sint16(vy);
RETVAL = antialias
? aapolygonColor(surface, _vx, _vy, n, color)
: polygonColor(surface, _vx, _vy, n, color);
if (antialias)
aapolygonColor( _surface, _vx, _vy, n, color );
else
polygonColor( _surface, _vx, _vy, n, color );
_svinta_free( _vx, av_len(vx) );
_svinta_free( _vy, av_len(vy) );
RETVAL = SvREFCNT_inc(surface);
OUTPUT:
RETVAL

Expand Down
8 changes: 8 additions & 0 deletions t/sdlx_surface.t
Expand Up @@ -170,6 +170,9 @@ pass 'draw_rect works';
SKIP:
{
skip( 'SDL_gfx_primitives needed', 2 ) unless SDL::Config->has('SDL_gfx_primitives');

is( $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ffff ), $surfs[1], 'draw_line returns self' );

$surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ff );
$surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ffff );
$surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ffff, 1 );
Expand All @@ -189,6 +192,7 @@ SKIP:
pass 'draw_gfx_text works';
my @colors_t = ( [ 255, 0, 0, 255 ], 0xFF0000FF, 0xFF00FF, [ 255, 0, 255 ] );

is( $surfs[0]->draw_circle( [ 100, 10 ], 20, [ 0, 0, 0, 0] ), $surfs[0], 'draw_circle returns self' );
foreach my $cir_color (@colors_t) {
my $cir_color = [ 255, 0, 0, 255 ];
$surfs[0]->draw_circle( [ 100, 10 ], 20, $cir_color ); #no fill
Expand All @@ -199,6 +203,8 @@ SKIP:
pass 'draw_circle_filled works';
}

is( $surfs[0]->draw_trigon( [ [100, 10], [110, 10], [110, 20] ], [ 255, 0, 0, 255 ] ), $surfs[0], 'draw_trigon returns self' );
is( $surfs[0]->draw_trigon_filled( [ [100, 10], [110, 10], [110, 20] ], [ 255, 0, 0, 255 ] ), $surfs[0], 'draw_trigon_filled returns self' );
foreach my $color (@colors_t) {
my $color = [ 255, 0, 0, 255 ];
my $verts = [ [100, 10], [110, 10], [110, 20] ];
Expand All @@ -210,6 +216,8 @@ SKIP:
pass 'draw_trigon_filled works';
}

is( $surfs[0]->draw_polygon( [ [100, 10], [110, 10], [110, 20] ], [ 255, 0, 0, 255 ] ), $surfs[0], 'draw_polygon returns self' );
is( $surfs[0]->draw_polygon_filled( [ [100, 10], [110, 10], [110, 20] ], [ 255, 0, 0, 255 ] ), $surfs[0], 'draw_polygon_filled returns self' );
foreach my $color (@colors_t) {
my $color = [ 255, 0, 0, 255 ];
my $verts = [ [100, 10], [110, 10], [110, 20], [100, 20] ];
Expand Down

0 comments on commit 0cff9b4

Please sign in to comment.