5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
38 Right click on any pixel to get its color values
39 Left click on any pixel to set its value to the last selected
42 SDL::Init(SDL_INIT_ALL);
44 $app = new SDL::App -width => 320, -height => 240, -depth => 8;
47 red => (new SDL::Color -r => 255, -g => 0, -b => 0 ),
48 green => (new SDL::Color -r => 0, -g => 255, -b => 0),
49 blue => (new SDL::Color -r => 0, -g => 0, -b => 255),
50 yellow => (new SDL::Color -r => 255, -g => 255, -b => 0),
51 purple => (new SDL::Color -r => 255, -g => 0, -b => 255),
52 white => (new SDL::Color -r => 255, -g => 255, -b => 255)
57 $rect = new SDL::Rect -x => $x, -y => $y,
58 -w => $app->width / scalar(keys %colors), -h => $app->height();
60 print "Sorted colors:\n";
62 for ( sort keys %colors ) {
63 print "$_ " . join (",",$colors{$_}->r(), $colors{$_}->g(),
64 $colors{$_}->b()) . "\n";
67 for ( sort keys %colors ) {
70 $app->fill($rect,$colors{$_});
75 $last = new SDL::Color -r => 128, -g => 128, -b => 128;
79 SDL_QUIT() => sub { exit(0); },
80 SDL_KEYDOWN() => sub { $app->fullscreen(); },
81 SDL_MOUSEBUTTONDOWN() => sub {
83 if ($e->button == 3) {
84 $last = $app->pixel($e->button_x(),$e->button_y());
85 print STDERR "X: ", $e->button_x(), " Y: ", $e->button_y(),
86 " R: ", $last->r(), " G: ", $last->g(),
87 " B: ", $last->b(), "\n";
89 $app->pixel($e->button_x(),$e->button_y(),$last);