Commit | Line | Data |
3a32e86d |
1 | #!/usr/bin/env perl |
2 | # |
3 | |
4 | use SDL; |
5 | use SDL::App; |
6 | use SDL::Event; |
7 | |
8 | use vars qw/ $app /; |
9 | |
10 | print STDERR <<USAGE; |
11 | Right click on any pixel to get its color values |
12 | Left click on any pixel to set its value to the last selected |
13 | USAGE |
14 | |
15 | $app = new SDL::App -width => 320, -height => 240, -depth => 8; |
16 | |
17 | my %colors = ( |
18 | red => (new SDL::Color -r => 255, -g => 0, -b => 0 ), |
19 | green => (new SDL::Color -r => 0, -g => 255, -b => 0), |
20 | blue => (new SDL::Color -r => 0, -g => 0, -b => 255), |
21 | yellow => (new SDL::Color -r => 255, -g => 255, -b => 0), |
22 | purple => (new SDL::Color -r => 255, -g => 0, -b => 255), |
23 | white => (new SDL::Color -r => 255, -g => 255, -b => 255) |
24 | ); |
25 | |
26 | |
27 | $x = 0; $y = 0; |
28 | $rect = new SDL::Rect -x => $x, -y => $y, |
29 | -w => $app->width / scalar(keys %colors), -h => $app->height(); |
30 | |
31 | print "Sorted colors:\n"; |
32 | |
33 | for ( sort keys %colors ) { |
34 | print "$_ " . join (",",$colors{$_}->r(), $colors{$_}->g(), |
35 | $colors{$_}->b()) . "\n"; |
36 | } |
37 | |
38 | for ( sort keys %colors ) { |
39 | $rect->x($x); |
40 | $x += $rect->width(); |
41 | $app->fill($rect,$colors{$_}); |
42 | } |
43 | |
44 | $app->sync(); |
45 | |
46 | $last = new SDL::Color -r => 128, -g => 128, -b => 128; |
47 | |
48 | $app->sync(); |
49 | $app->loop( { |
50 | SDL_QUIT() => sub { exit(0); }, |
51 | SDL_KEYDOWN() => sub { $app->fullscreen(); }, |
52 | SDL_MOUSEBUTTONDOWN() => sub { |
53 | my $e = shift; |
54 | if ($e->button == 3) { |
55 | $last = $app->pixel($e->button_x(),$e->button_y()); |
56 | print STDERR "X: ", $e->button_x(), " Y: ", $e->button_y(), |
57 | " R: ", $last->r(), " G: ", $last->g(), |
58 | " B: ", $last->b(), "\n"; |
59 | } else { |
60 | $app->pixel($e->button_x(),$e->button_y(),$last); |
61 | } |
62 | }, |
63 | }); |