added 20 more tests for new API
[sdlgit/SDL_perl.git] / lib / SDL / Color.pm
index 6a8f36f..2c426e4 100644 (file)
@@ -1,8 +1,32 @@
-#      Color.pm
+#!/usr/bin/env perl
 #
-#      A package for manipulating SDL_Color *
+# Color.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.
+# 
+# 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
+#
+# ------------------------------------------------------------------------------
+#
+# Please feel free to send questions, suggestions or improvements to:
+#
+#      David J. Goehrig
+#      dgoehrig@cpan.org
 #
-#      Copyright (C) 2002,2003,2004 David J. Goehrig
 
 package SDL::Color;
 
@@ -14,11 +38,10 @@ use SDL;
 sub new {
        my $proto = shift;
        my $class = ref($proto) || $proto;
-
-       # called like SDL::Color->new($red,$green,$blue);
        return bless \SDL::NewColor(@_), $class if (@_ == 3);
 
        my $self;
+       
        my (%options) = @_;
 
        verify (%options, qw/ -color -surface -pixel -r -g -b /) if $SDL::DEBUG;
@@ -38,7 +61,8 @@ sub new {
        } 
        croak "Could not create color, ", SDL::GetError(), "\n"
                unless ($$self);
-       bless $self, $class;
+       bless $self,$class;
+       return $self;
 }
 
 sub DESTROY {
@@ -61,8 +85,8 @@ sub b {
 }
 
 sub rgb {
-       my $self = shift;
-       SDL::ColorRGB($$self,@_);
+ my $self = shift;
+ SDL::ColorRGB($$self,@_);
 }
 
 sub pixel {
@@ -71,13 +95,13 @@ sub pixel {
        SDL::MapRGB(${$_[1]},$_[0]->r(),$_[0]->g(),$_[0]->b());
 }
 
-$SDL::Color::black = SDL::Color->new(0,0,0);
-$SDL::Color::white = SDL::Color->new(255,255,255);
-$SDL::Color::red = SDL::Color->new(255,0,0);
-$SDL::Color::blue = SDL::Color->new(0,0,255);
-$SDL::Color::green = SDL::Color->new(0,255,0);
-$SDL::Color::purple = SDL::Color->new(255,0,255);
-$SDL::Color::yellow = SDL::Color->new(255,255,0);
+$SDL::Color::black = new SDL::Color -r => 0, -g => 0, -b => 0;
+$SDL::Color::white = new SDL::Color -r => 255, -g => 255, -b => 255;
+$SDL::Color::red = new SDL::Color -r => 255, -g => 0, -b => 0;
+$SDL::Color::blue = new SDL::Color -r => 0, -g => 0, -b => 255;
+$SDL::Color::green = new SDL::Color -r => 0, -g => 255, -b => 0;
+$SDL::Color::purple = new SDL::Color -r => 255, -g => 0, -b => 255;
+$SDL::Color::yellow = new SDL::Color -r => 255, -g => 255, -b => 0;
 
 1;
 
@@ -91,8 +115,6 @@ SDL::Color - a SDL perl extension
 
 =head1 SYNOPSIS
 
-  $color = SDL::Color->new($red,$green,$blue);         # fastest
-
   $color = new SDL::Color ( -r => 0xde, -g => 0xad, -b =>c0 );
   $color = new SDL::Color -surface => $app, -pixel => $app->pixel($x,$y);
   $color = new SDL::Color -color => SDL::NewColor(0xff,0xaa,0xdd);
@@ -100,18 +122,13 @@ SDL::Color - a SDL perl extension
 =head1 DESCRIPTION
 
 C<SDL::Color> is a wrapper for display format independent color
-representations.
+representations, with the same interface as L<SDL::Color>.  
 
 =head2 new ( -color => )
 
 C<SDL::Color::new> with a C<-color> option will construct a new object
 referencing the passed SDL_Color*.
 
-=head2 new ($r, $g, $b)
-
-C<SDL::Color::new> with three color values will construct both a SDL_Color
-structure, and the associated object with the specified values.
-
 =head2 new (-r => , -g => , -b => )
 
 C<SDL::Color::new> with C<-r,-g,-b> options will construct both a SDL_Color
@@ -129,13 +146,6 @@ C<SDL::Color::r, SDL::Color::g, SDL::Color::b> are accessor methods for
 the red, green, and blue components respectively.  The color value can be set
 by passing a byte value (0-255) to each function.
 
-=head2 rgb ( $red, $green, $blue )
-
-C<SDL::Color::rgb> is an accessor method for the red, green, and blue components
-in one go. It will return a list of three values.
-
-The color value can be set by passing a byte value (0-255) for each color component.
-
 =head2 pixel ( surface )
 
 C<SDL::Color::pixel> takes a C<SDL::Surface> object and r,g,b values, and
@@ -145,10 +155,8 @@ returns the integer representation of the closest color for the given surface.
 
 David J. Goehrig
 
-Additions by Tels 2006.
-
 =head1 SEE ALSO
 
-L<perl> and L<SDL::Surface>.
+L<perl> L<SDL::Surface> 
 
 =cut