Permalink
Browse files

Surface PP test.

  • Loading branch information...
Blaizer committed Jan 13, 2011
1 parent bcd52a0 commit 789f1b306424364026f1efd99d6b314f4268bf31
Showing with 48 additions and 81 deletions.
  1. +48 −7 lib/SDLx/Surface.pm
  2. +0 −74 src/SDLx/Surface.xs
View
@@ -123,9 +123,7 @@ sub get_pixel {
sub set_pixel {
my ( $self, $y, $x, $new_value ) = @_;
-
$new_value = SDLx::Validate::num_rgba($new_value);
-
SDLx::Surface::set_pixel_xs( $self, $x, $y, $new_value );
}
@@ -190,6 +188,8 @@ sub load {
}
}
+
+
my $formated_surface = $surface;
if( SDL::Video::get_video_surface )
{
@@ -201,6 +201,33 @@ sub load {
#EXTENSTIONS
+sub blit {
+ my ( $src, $dest, $src_rect, $dest_rect ) = @_;
+
+ $src = SDLx::Validate::surface($src);
+ $dest = SDLx::Validate::surface($dest);
+
+ if(defined $src_rect) {
+ $src_rect = SDLx::Validate::rect($src_rect);
+ }
+ else {
+ $src_rect = SDL::Rect->new( 0, 0, $src->w, $src->h );
+ }
+ if(defined $dest_rect) {
+ $dest_rect = SDLx::Validate::rect($dest_rect);
+ }
+ else {
+ $dest_rect = SDL::Rect->new( 0, 0, $dest->w, $dest->h );
+ }
+
+ SDL::Video::blit_surface(
+ $src, $src_rect,
+ $dest, $dest_rect
+ );
+
+ return $src;
+}
+
sub blit_by {
my ( $dest, $src, $src_rect, $dest_rect ) = @_;
SDLx::Surface::blit( $src, $dest, $src_rect, $dest_rect );
@@ -218,13 +245,13 @@ sub update {
my ( $surface, $rects ) = @_;
if ( !defined($rects) || ( ref($rects) eq 'ARRAY' && !ref( $rects->[0] ) ) ) {
- my @rect;
- @rect = @{$rects} if $rects;
+ my @rect;
+ @rect = @{$rects} if $rects;
$rect[0] ||= 0;
$rect[1] ||= 0;
$rect[2] ||= $surface->w;
$rect[3] ||= $surface->h;
-
+
SDL::Video::update_rect( $surface, @rect );
} else {
SDL::Video::update_rects( $surface, map { SDLx::Validate::rect($_) } @{$rects} );
@@ -233,6 +260,20 @@ sub update {
return $surface;
}
+sub draw_rect {
+ my ( $self, $rect, $color ) = @_;
+ $color = SDLx::Validate::map_rgba( $color, $self->format );
+ if ( defined $rect ) {
+ $rect = SDLx::Validate::rect($rect);
+ } else {
+ $rect = SDL::Rect->new( 0, 0, $self->w, $self->h );
+ }
+
+ SDL::Video::fill_rect( $self, $rect, $color )
+ and Carp::confess "Error drawing rect: " . SDL::get_error();
+ return $self;
+}
+
sub draw_line {
my ( $self, $start, $end, $color, $antialias ) = @_;
@@ -273,7 +314,7 @@ sub draw_circle {
unless( $antialias )
{
- SDL::GFX::Primitives::circle_color( $self, @{$center}, $radius, $color );
+ SDL::GFX::Primitives::circle_color( $self, @{$center}, $radius, $color );
}
else
{
@@ -283,7 +324,7 @@ sub draw_circle {
}
sub draw_circle_filled {
- my ( $self, $center, $radius, $color) = @_;
+ my ( $self, $center, $radius, $color ) = @_;
unless ( SDL::Config->has('SDL_gfx_primitives') ) {
Carp::cluck("SDL_gfx_primitives support has not been compiled");
View
@@ -172,80 +172,6 @@ surfacex_set_pixel_xs ( surface, x, y, value )
SDL_UnlockSurface(surface);
-void
-surfacex_draw_rect ( surface, rt, color )
- SDL_Surface *surface
- SV* rt
- SV* color
- CODE:
-
- Uint32 m_color = __map_rgba( color, surface->format );
- SDL_Rect r_rect;
- r_rect.x = 0; r_rect.y = 0; r_rect.w = surface->w; r_rect.h = surface->h;
-
- if( SvOK(rt) )
- {
- int newly_created_rect = 0;
- SV* foo = rect( rt, &newly_created_rect );
- SDL_Rect* v_rect = (SDL_Rect*)bag2obj(foo);
- r_rect.x = v_rect->x;
- r_rect.y = v_rect->y;
- r_rect.w = v_rect->w;
- r_rect.h = v_rect->h;
- SDL_FillRect(surface, &r_rect, m_color);
- SvREFCNT_dec(foo);
- //if( newly_created_rect == 1 ) { safefree( v_rect); }
- }
- else
- SDL_FillRect(surface, &r_rect, m_color);
-void
-surfacex_blit( src, dest, ... )
- SV *src
- SV *dest
- CODE:
- src = surface(src);
- dest = surface(dest);
- SDL_Surface *_src = (SDL_Surface *)bag2obj(src);
- SDL_Surface *_dest = (SDL_Surface *)bag2obj(dest);
-
- SDL_Rect _src_rect;
- SDL_Rect _dest_rect;
- int newly_created_rect = 0;
- SV* s_rect_sv, *d_rect_sv;
- int mall_sr = 0; int mall_dr = 0;
- if( items > 2 && SvOK(ST(2)) )
- {
- s_rect_sv = rect(ST(2), &newly_created_rect);
- _src_rect = *(SDL_Rect *)bag2obj( s_rect_sv );
- mall_sr = 1;
- }
- else
- {
- _src_rect.x = 0;
- _src_rect.y = 0;
- _src_rect.w = _src->w;
- _src_rect.h = _src->h;
- }
-
- if( items > 3 && SvOK(ST(3)) )
- {
- d_rect_sv = rect(ST(3), &newly_created_rect);
- _dest_rect = *(SDL_Rect *)bag2obj( d_rect_sv );
- mall_dr = 1;
- }
- else
- {
- _dest_rect.x = 0;
- _dest_rect.y = 0;
- _dest_rect.w = _dest->w;
- _dest_rect.h = _dest->h;
- }
-
- SDL_BlitSurface( _src, &_src_rect, _dest, &_dest_rect );
- if ( mall_sr == 1 )
- SvREFCNT_dec( s_rect_sv);
- if ( mall_dr == 1 )
- SvREFCNT_dec( d_rect_sv );

0 comments on commit 789f1b3

Please sign in to comment.