40ea970da3bd63029fcba767ed8baf1138425da6
[sdlgit/SDL_perl.git] / lib / SDL / Palette.pm
1 #
2 #       Palette.pm
3 #
4 #       a module for manipulating SDL_Palette *
5 #
6 #       Copyright (C) 2000,2002 David J. Goehrig
7
8 package SDL::Palette;
9 use strict;
10 use warnings;
11 use Carp;
12
13 # NB: there is no palette destructor because most of the time the 
14 # palette will be owned by a surface, so any palettes you create 
15 # with new, won't be destroyed until the program ends!
16
17 sub new {
18         my $proto = shift;
19         my $class = ref($proto) || $proto;
20         my $image;
21         my $self;
22         if (@_) { 
23                 $image = shift;
24                 $self = \$image->palette(); 
25         } else { 
26                 $self = \SDL::NewPalette(256); 
27         }
28         bless $self, $class;
29         return $self;
30 }
31
32 sub size {
33         my $self = shift;
34         return SDL::PaletteNColors($$self);
35 }
36
37 sub color {
38         my $self = shift;
39         my $index = shift;
40         my ($r,$g,$b);
41         if (@_) { 
42                 $r = shift; $g = shift; $b = shift; 
43                 return SDL::PaletteColors($$self,$index,$r,$g,$b);
44         } else {
45                 return SDL::PaletteColors($$self,$index);
46         }
47 }
48
49 sub red {
50         my $self = shift;
51         my $index = shift;
52         my $c;
53         if (@_) {
54                 $c = shift;
55                 return SDL::ColorR(
56                         SDL::PaletteColors($$self,$index),$c);
57         } else {        
58                 return SDL::ColorR(
59                         SDL::PaletteColors($$self,$index));
60         }
61 }
62
63 sub green {
64         my $self = shift;
65         my $index = shift;
66         my $c;
67         if (@_) {
68                 $c = shift;
69                 return SDL::ColorG(
70                         SDL::PaletteColors($$self,$index),$c);
71         } else {        
72                 return SDL::ColorG(
73                         SDL::PaletteColors($$self,$index));
74         }
75 }
76
77 sub blue {
78         my $self = shift;
79         my $index = shift;
80         my $c;
81         if (@_) {
82                 $c = shift;
83                 return SDL::ColorB(
84                         SDL::PaletteColors($$self,$index),$c);
85         } else {        
86                 return SDL::ColorB(
87                         SDL::PaletteColors($$self,$index));
88         }
89 }
90
91 1;
92
93 __END__;
94
95 =pod
96
97 =head1 NAME
98
99 SDL::Palette - a perl extension
100
101 =head1 DESCRIPTION
102
103 L<SDL::Palette> provides an interface to the SDL_Palette structures,
104 and can be used to set the color values of an existing palette's indexes.
105
106 =head1 METHODS
107
108 =head2 blue ( index, [value] )
109
110 Fetches and sets the blue component of the color at index.
111
112 =head2 green ( index, [value] )
113
114 Fetches and sets the green component of the color at index.
115
116 =head2 red ( index, [value] )
117
118 Fetches and sets the red component of the color at index.
119
120 =head2 color ( index, [ r, g, b ] )
121
122 Fetches and sets the RGB, returns an SDL_Color *.
123
124 =head2 size
125
126 Returns the size of the palette.
127
128 =head1 AUTHOR
129
130 David J. Goehrig
131
132 =head1 SEE ALSO
133
134 L<perl> L<SDL::Color> L<SDL::Surface>
135
136 =cut