File: Palette.pm

package info (click to toggle)
sdlperl 1.20.3dfsg-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,796 kB
  • ctags: 2,171
  • sloc: perl: 7,394; ansic: 232; makefile: 75; sh: 1
file content (133 lines) | stat: -rw-r--r-- 2,424 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
#	Palette.pm
#
#	a module for manipulating SDL_Palette *
#
#	Copyright (C) 2000,2002 David J. Goehrig

package SDL::Palette;
use strict;
use SDL;

# NB: there is no palette destructor because most of the time the 
# palette will be owned by a surface, so any palettes you create 
# with new, won't be destroyed until the program ends!

sub new {
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self = {};
	my $image;
	if (@_) { 
		$image = shift;
		$self->{-palette} = $image->palette(); 
	} else { $self->{-palette} = SDL::NewPalette(256); }
	bless $self, $class;
	return $self;
}

sub size {
	my $self = shift;
	return SDL::PaletteNColors($self->{-palette});
}

sub color {
	my $self = shift;
	my $index = shift;
	my ($r,$g,$b);
	if (@_) { 
		$r = shift; $g = shift; $b = shift; 
		return SDL::PaletteColors($self->{-palette},$index,$r,$g,$b);
	} else {
		return SDL::PaletteColors($self->{-palette},$index);
	}
}

sub red {
	my $self = shift;
	my $index = shift;
	my $c;
	if (@_) {
		$c = shift;
		return SDL::ColorR(
			SDL::PaletteColors($self->{-palette},$index),$c);
	} else {	
		return SDL::ColorR(
			SDL::PaletteColors($self->{-palette},$index));
	}
}

sub green {
	my $self = shift;
	my $index = shift;
	my $c;
	if (@_) {
		$c = shift;
		return SDL::ColorG(
			SDL::PaletteColors($self->{-palette},$index),$c);
	} else {	
		return SDL::ColorG(
			SDL::PaletteColors($self->{-palette},$index));
	}
}

sub blue {
	my $self = shift;
	my $index = shift;
	my $c;
	if (@_) {
		$c = shift;
		return SDL::ColorB(
			SDL::PaletteColors($self->{-palette},$index),$c);
	} else {	
		return SDL::ColorB(
			SDL::PaletteColors($self->{-palette},$index));
	}
}

1;

__END__;

=pod

=head1 NAME

SDL::Palette - a perl extension

=head1 DESCRIPTION

L<SDL::Palette> provides an interface to the SDL_Palette structures,
and can be used to set the color values of an existing palette's indexes.

=head1 METHODS

=head2 blue ( index, [value] )

Fetches and sets the blue component of the color at index.

=head2 green ( index, [value] )

Fetches and sets the green component of the color at index.

=head2 red ( index, [value] )

Fetches and sets the red component of the color at index.

=head2 color ( index, [ r, g, b ] )

Fetches and sets the RGB, returns an SDL_Color *.

=head2 size

Returns the size of the palette.

=head1 AUTHOR

David J. Goehrig

=head1 SEE ALSO

L<perl> L<SDL::Color> L<SDL::Surface>

=cut