-# 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;
use strict;
+use warnings;
+use Carp;
use SDL;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
- my $self;
+ return bless \SDL::NewColor(@_), $class if (@_ == 3);
+ my $self;
+
my (%options) = @_;
verify (%options, qw/ -color -surface -pixel -r -g -b /) if $SDL::DEBUG;
if ($options{-color}) {
$self = \$options{-color};
} elsif ($options{-pixel} && $options{-surface}) {
- die "SDL::Color::new requires an SDL::Surface"
+ croak "SDL::Color::new requires an SDL::Surface"
unless !$SDL::DEBUG || $options{-surface}->isa("SDL::Surface");
$self = \SDL::NewColor(SDL::GetRGB(${$options{-surface}}, $options{-pixel}));
} else {
push @color, $options{-blue} || $options{-b} || 0;
$self = \SDL::NewColor(@color);
}
- die "Could not create color, ", SDL::GetError(), "\n"
+ croak "Could not create color, ", SDL::GetError(), "\n"
unless ($$self);
bless $self,$class;
return $self;
SDL::ColorB($$self,@_);
}
+sub rgb {
+ my $self = shift;
+ SDL::ColorRGB($$self,@_);
+}
+
sub pixel {
- die "SDL::Color::pixel requires an SDL::Surface"
+ croak "SDL::Color::pixel requires an SDL::Surface"
unless !$SDL::DEBUG || $_[1]->isa("SDL::Surface");
SDL::MapRGB(${$_[1]},$_[0]->r(),$_[0]->g(),$_[0]->b());
}