X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSDL%2FSurface.pm;h=897234c555705fa6742dd5a0d9b8fc23c38a2ed4;hb=d99c96f664d4845fc2b4fe3d03a5d859b4f724ba;hp=1348875f6c4e272836fc213c57b79b41d732f7f5;hpb=8fde61e3e900d5000c94503679d735221acc1882;p=sdlgit%2FSDL_perl.git diff --git a/lib/SDL/Surface.pm b/lib/SDL/Surface.pm index 1348875..897234c 100644 --- a/lib/SDL/Surface.pm +++ b/lib/SDL/Surface.pm @@ -1,18 +1,43 @@ +#!/usr/bin/env perl +# +# Surface.pm +# +# Copyright (C) 2005 David J. Goehrig +# +# ------------------------------------------------------------------------------ +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # -# Surface.pm +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# ------------------------------------------------------------------------------ # -# A package for manipulating SDL_Surface * +# Please feel free to send questions, suggestions or improvements to: +# +# David J. Goehrig +# dgoehrig@cpan.org # -# Copyright (C) 2003 David J. Goehrig package SDL::Surface; use strict; +use warnings; +use Carp; use SDL; use SDL::SFont; use SDL::Color; use SDL::Rect; - +use Data::Dumper; sub new { my $proto = shift; my $class = ref($proto) || $proto; @@ -47,7 +72,7 @@ sub new { $self = \SDL::CreateRGBSurface($f,$w,$h,$d,$r,$g,$b,$a); } } - die "SDL::Surface::new failed. ", SDL::GetError() + croak "SDL::Surface::new failed. ", SDL::GetError() unless ( $$self); bless $self,$class; return $self; @@ -130,7 +155,7 @@ sub pixels { } sub pixel { - die "SDL::Surface::pixel requires a SDL::Color" + croak "SDL::Surface::pixel requires a SDL::Color" if $_[3] && $SDL::DEBUG && !$_[3]->isa("SDL::Color"); $_[3] ? new SDL::Color -color => SDL::SurfacePixel(${$_[0]},$_[1],$_[2],${$_[3]}) : @@ -138,14 +163,10 @@ sub pixel { } sub fill { - die "SDL::Surface::fill requires a SDL::Rect object" - unless !$SDL::DEBUG || $_[1] == 0 || $_[1]->isa('SDL::Rect'); - die "SDL::Surface::fill requires a SDL::Color object" - unless !$SDL::DEBUG || $_[2]->isa('SDL::Color'); if ($_[1] == 0 ) { SDL::FillRect(${$_[0]},0,${$_[2]}); } else { - SDL::FillRect(${$_[0]},${$_[1]},${$_[2]}); + SDL::FillRect(${$_[0]},$_[1],${$_[2]}); } } @@ -165,7 +186,7 @@ sub update { my $self = shift;; if ($SDL::DEBUG) { for (@_) { - die "SDL::Surface::update requires SDL::Rect objects" + croak "SDL::Surface::update requires SDL::Rect objects" unless $_->isa('SDL::Rect'); } } @@ -177,28 +198,31 @@ sub flip { } sub blit { + $_[1] = 0 unless defined $_[1]; + $_[3] = 0 unless defined $_[3]; + if ($SDL::DEBUG) { - die "SDL::Surface::blit requires SDL::Rect objects" + croak "SDL::Surface::blit requires SDL::Rect objects" unless ($_[1] == 0 || $_[1]->isa('SDL::Rect')) && ($_[3] == 0 || $_[3]->isa('SDL::Rect')); - die "SDL::Surface::blit requires SDL::Surface objects" + croak "SDL::Surface::blit requires SDL::Surface objects" unless $_[2]->isa('SDL::Surface'); } - SDL::BlitSurface(map { $_ != 0 ? ${$_} : $_ } @_); + SDL::BlitSurface( $_[0], $_[1], ${$_[2]}, $_[3]); } sub set_colors { my $self = shift; my $start = shift; for (@_) { - die "SDL::Surface::set_colors requires SDL::Color objects" + croak "SDL::Surface::set_colors requires SDL::Color objects" unless !$SDL::DEBUG || $_->isa('SDL::Color'); } return SDL::SetColors($$self, $start, map { ${$_} } @_); } sub set_color_key { - die "SDL::Surface::set_color_key requires a SDL::Color object" + croak "SDL::Surface::set_color_key requires a SDL::Color object" unless !$SDL::DEBUG || (ref($_[2]) && $_[2]->isa('SDL::Color')); SDL::SetColorKey(${$_[0]},$_[1],${$_[2]}); } @@ -502,12 +526,12 @@ C converts the surface to the same format as the current screen. =head2 rgb () -C converts the surface to a 24 bit rgb format regardless of the -initial format. + +C converts the surface to a 24 bit rgb format regardless of the initial format. =head2 rgba () -C converts the surface to a 32 bit rgba format regarless of the -initial format. + +C converts the surface to a 32 bit rgba format regarless of the initial format. =head2 print (x,y,text...)