#!/usr/bin/env perl # # testcolor.pl # # Copyright (C) 2005 David J. Goehrig # # ------------------------------------------------------------------------------ # # 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 # use SDL; use SDL::App; use SDL::Event; use vars qw/ $app /; print STDERR < 320, -height => 240, -depth => 8; my %colors = ( red => (new SDL::Color -r => 255, -g => 0, -b => 0 ), green => (new SDL::Color -r => 0, -g => 255, -b => 0), blue => (new SDL::Color -r => 0, -g => 0, -b => 255), yellow => (new SDL::Color -r => 255, -g => 255, -b => 0), purple => (new SDL::Color -r => 255, -g => 0, -b => 255), white => (new SDL::Color -r => 255, -g => 255, -b => 255) ); $x = 0; $y = 0; $rect = new SDL::Rect -x => $x, -y => $y, -w => $app->width / scalar(keys %colors), -h => $app->height(); print "Sorted colors:\n"; for ( sort keys %colors ) { print "$_ " . join (",",$colors{$_}->r(), $colors{$_}->g(), $colors{$_}->b()) . "\n"; } for ( sort keys %colors ) { $rect->x($x); $x += $rect->width(); $app->fill($rect,$colors{$_}); } $app->sync(); $last = new SDL::Color -r => 128, -g => 128, -b => 128; $app->sync(); $app->loop( { SDL_QUIT() => sub { exit(0); }, SDL_KEYDOWN() => sub { $app->fullscreen(); }, SDL_MOUSEBUTTONDOWN() => sub { my $e = shift; if ($e->button == 3) { $last = $app->pixel($e->button_x(),$e->button_y()); print STDERR "X: ", $e->button_x(), " Y: ", $e->button_y(), " R: ", $last->r(), " G: ", $last->g(), " B: ", $last->b(), "\n"; } else { $app->pixel($e->button_x(),$e->button_y(),$last); } }, });