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