Commit | Line | Data |
8fde61e3 |
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; |
43a05747 |
28 | $rect = SDL::Rect->new( $x, $y, $app->width / scalar(keys %colors), $app->height()); |
8fde61e3 |
29 | |
30 | print "Sorted colors:\n"; |
31 | |
32 | for ( sort keys %colors ) { |
33 | print "$_ " . join (",",$colors{$_}->r(), $colors{$_}->g(), |
34 | $colors{$_}->b()) . "\n"; |
35 | } |
36 | |
37 | for ( sort keys %colors ) { |
38 | $rect->x($x); |
39 | $x += $rect->width(); |
40 | $app->fill($rect,$colors{$_}); |
41 | } |
42 | |
43 | $app->sync(); |
44 | |
45 | $last = new SDL::Color -r => 128, -g => 128, -b => 128; |
46 | |
47 | $app->sync(); |
48 | $app->loop( { |
49 | SDL_QUIT() => sub { exit(0); }, |
50 | SDL_KEYDOWN() => sub { $app->fullscreen(); }, |
51 | SDL_MOUSEBUTTONDOWN() => sub { |
52 | my $e = shift; |
53 | if ($e->button == 3) { |
54 | $last = $app->pixel($e->button_x(),$e->button_y()); |
55 | print STDERR "X: ", $e->button_x(), " Y: ", $e->button_y(), |
56 | " R: ", $last->r(), " G: ", $last->g(), |
57 | " B: ", $last->b(), "\n"; |
58 | } else { |
59 | $app->pixel($e->button_x(),$e->button_y(),$last); |
60 | } |
61 | }, |
62 | }); |