Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calling SDLx::Surface draw methods with blessed vectors #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions lib/SDLx/Surface.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use vars qw(@ISA @EXPORT @EXPORT_OK);
require Exporter;
require DynaLoader;
use Carp ();
use Scalar::Util ();
use SDL;
use SDL::Rect;
use SDL::Video;
Expand Down Expand Up @@ -219,9 +220,9 @@ sub flip {
sub update {
my ( $surface, $rects ) = @_;

if ( !defined($rects) || ( ref($rects) eq 'ARRAY' && !ref( $rects->[0] ) ) ) {
my @rect;
@rect = @{$rects} if $rects;
if ( !defined($rects) || ( Scalar::Util::reftype $rects eq 'ARRAY' && !ref( $rects->[0] ) ) ) {
my @rect;
@rect = @{$rects} if $rects;
$rect[0] ||= 0;
$rect[1] ||= 0;
$rect[2] ||= $surface->w;
Expand All @@ -239,9 +240,10 @@ sub draw_line {
my ( $self, $start, $end, $color, $antialias ) = @_;

Carp::confess "Error start needs an array ref [x,y]"
unless ref($start) eq 'ARRAY';
unless Scalar::Util::reftype $start eq 'ARRAY';

Carp::confess "Error end needs an array ref [x,y]"
unless ref($end) eq 'ARRAY';
unless Scalar::Util::reftype $end eq 'ARRAY';

unless ( SDL::Config->has('SDL_gfx_primitives') ) {
Carp::cluck("SDL_gfx_primitives support has not been compiled");
Expand Down Expand Up @@ -270,7 +272,9 @@ sub draw_circle {
return;
}

Carp::cluck "Center needs to be an array of format [x,y]" unless ( ref $center eq 'ARRAY' && scalar @$center == 2 );
Carp::cluck "Center needs to be an array of format [x,y]"
unless Scalar::Util::reftype $center eq 'ARRAY' && scalar @$center == 2;

$color = SDLx::Validate::num_rgba($color);

unless( $antialias )
Expand All @@ -292,7 +296,9 @@ sub draw_circle_filled {
return;
}

Carp::cluck "Center needs to be an array of format [x,y]" unless ( ref $center eq 'ARRAY' && scalar @$center == 2 );
Carp::cluck "Center needs to be an array of format [x,y]"
unless Scalar::Util::reftype $center eq 'ARRAY' && scalar @$center == 2;

$color = SDLx::Validate::num_rgba($color);

SDL::GFX::Primitives::filled_circle_color( $self, @{$center}, $radius, $color );
Expand Down Expand Up @@ -341,7 +347,9 @@ sub draw_polygon_filled {
sub draw_arc {
my ( $self, $center, $radius, $start, $end, $color ) = @_;

Carp::cluck "Center needs to be an array of format [x,y]" unless ( ref $center eq 'ARRAY' && scalar @$center == 2 );
Carp::cluck "Center needs to be an array of format [x,y]"
unless Scalar::Util::reftype $center eq 'ARRAY' && scalar @$center == 2;

$color = SDLx::Validate::num_rgba($color);

SDL::GFX::Primitives::arc_color( $self, @$center, $radius, $start, $end, $color );
Expand All @@ -352,7 +360,9 @@ sub draw_arc {
sub draw_ellipse {
my ( $self, $center, $rx, $ry, $color, $antialias ) = @_;

Carp::cluck "Center needs to be an array of format [x,y]" unless ( ref $center eq 'ARRAY' && scalar @$center == 2 );
Carp::cluck "Center needs to be an array of format [x,y]"
unless Scalar::Util::reftype $center eq 'ARRAY' && scalar @$center == 2;

$color = SDLx::Validate::num_rgba($color);

if ($antialias)
Expand All @@ -370,7 +380,9 @@ sub draw_ellipse {
sub draw_ellipse_filled {
my ( $self, $center, $rx, $ry, $color ) = @_;

Carp::cluck "Center needs to be an array of format [x,y]" unless ( ref $center eq 'ARRAY' && scalar @$center == 2 );
Carp::cluck "Center needs to be an array of format [x,y]"
unless Scalar::Util::reftype $center eq 'ARRAY' && scalar @$center == 2;

$color = SDLx::Validate::num_rgba($color);

SDL::GFX::Primitives::filled_ellipse_color( $self, @$center, $rx, $ry, $color );
Expand Down