PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/t_backcompat/testcolor.spl

http://github.com/PerlGameDev/SDL
Perl | 67 lines | 53 code | 12 blank | 2 comment | 5 complexity | 41239adf803ccc56b1b77c1fe136a573 MD5 | raw file
 1#!/usr/bin/env perl
 2#
 3
 4use SDL;
 5use SDLx::App;
 6use SDL::Event;
 7
 8use vars qw/ $app /;
 9
10print 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
13USAGE
14
15$app = SDLx::App->new( -width => 320, -height => 240, -depth => 8 );
16
17my %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$x    = 0;
27$y    = 0;
28$rect = SDL::Rect->new(
29	-x => $x,
30	-y => $y,
31	-w => $app->width / scalar( keys %colors ),
32	-h => $app->height()
33);
34
35print "Sorted colors:\n";
36
37for ( sort keys %colors ) {
38	print "$_ " . join( ",", $colors{$_}->r(), $colors{$_}->g(), $colors{$_}->b() ) . "\n";
39}
40
41for ( sort keys %colors ) {
42	$rect->x($x);
43	$x += $rect->width();
44	$app->fill( $rect, $colors{$_} );
45}
46
47$app->sync();
48
49$last = SDL::Color->new( -r => 128, -g => 128, -b => 128 );
50
51$app->sync();
52$app->loop(
53	{   SDL_QUIT()            => sub { exit(0); },
54		SDL_KEYDOWN()         => sub { $app->fullscreen(); },
55		SDL_MOUSEBUTTONDOWN() => sub {
56			my $e = shift;
57			if ( $e->button == 3 ) {
58				$last = $app->pixel( $e->button_x(), $e->button_y() );
59				print STDERR "X: ", $e->button_x(), " Y: ", $e->button_y(),
60					" R: ", $last->r(), " G: ", $last->g(),
61					" B: ", $last->b(), "\n";
62			} else {
63				$app->pixel( $e->button_x(), $e->button_y(), $last );
64			}
65		},
66	}
67);