Split out SDL_Color into its own C-level class
[sdlgit/SDL_perl.git] / lib / SDL / Surface.pm
index 95b07f1..35796c9 100644 (file)
@@ -1,9 +1,32 @@
+#!/usr/bin/env perl
+#
+# Surface.pm
+#
+# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
+#
+# ------------------------------------------------------------------------------
+#
+# 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;
 
@@ -14,7 +37,7 @@ use SDL;
 use SDL::SFont;
 use SDL::Color;
 use SDL::Rect;
-
+use Data::Dumper;
 sub new {
        my $proto = shift;      
        my $class = ref($proto) || $proto;
@@ -140,14 +163,10 @@ sub pixel {
 }
 
 sub fill {
-       croak "SDL::Surface::fill requires a SDL::Rect object"
-               unless !$SDL::DEBUG || $_[1] == 0 || $_[1]->isa('SDL::Rect');
-       croak "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]);
        }
 }
 
@@ -179,6 +198,9 @@ sub flip {
 }
 
 sub blit {
+               $_[1] = 0 unless defined $_[1];
+               $_[3] = 0 unless defined $_[3];
+
        if ($SDL::DEBUG) {
                croak "SDL::Surface::blit requires SDL::Rect objects"
                        unless ($_[1] == 0 || $_[1]->isa('SDL::Rect'))
@@ -186,7 +208,9 @@ sub blit {
                croak "SDL::Surface::blit requires SDL::Surface objects"
                        unless $_[2]->isa('SDL::Surface'); 
        }
-       SDL::BlitSurface(map { $_ != 0 ? ${$_} : $_ } @_);
+       #BlitSurface ( src, src_rect, dest, dest_rect )
+
+               SDL::BlitSurface( ${$_[0]}, $_[1], ${$_[2]}, $_[3]);
 }
 
 sub set_colors {
@@ -217,6 +241,14 @@ sub display_format {
        $self;
 }
 
+sub display_format_alpha {
+       my $self = shift;
+       my $tmp = SDL::DisplayFormatAlpha($$self);
+       SDL::FreeSurface ($$self);
+       $$self = $tmp;
+       $self;
+}
+
 sub rgb {
        my $self = shift;
        my $tmp = SDL::ConvertRGB($$self);
@@ -503,13 +535,18 @@ C<alpha> takes a value from 0x00 to 0xff.
 C<SDL::Surface::display_format> converts the surface to the same format as the
 current screen.
 
+=head2 display_format_alpha ()
+
+C<SDL::Surface::display_format_alpha> converts the surface to the same format as the
+current screen, plus an alpha channel.
+
 =head2 rgb ()
-C<SDL::Surface::rgb> converts the surface to a 24 bit rgb format regardless of the 
-initial format.
+
+C<SDL::Surface::rgb> converts the surface to a 24 bit rgb format regardless of the initial format.
 
 =head2 rgba ()
-C<SDL::Surface::rgba> converts the surface to a 32 bit rgba format regarless of the
-initial format.
+
+C<SDL::Surface::rgba> converts the surface to a 32 bit rgba format regarless of the initial format.
 
 =head2 print (x,y,text...)