Added CreateRGBSurfaceFrom as an new constructor of SDL::Surface. Need to test it
[sdlgit/SDL_perl.git] / test / graywin.pl
CommitLineData
8fde61e3 1#!/usr/bin/env perl
2#
3# graywin.pl
4#
5# adapted from SDL-1.2.x/test/graywin.c
6#
7
8use SDL;
9use SDL::App;
10use SDL::Rect;
11use SDL::Event;
12use SDL::Color;
13
14my %options;
15
16die <<USAGE if in($ARGV[0], qw/ -h --help -? /);
17usage: $0 [-hw] [-fullscreen] [-width 640] [-height 480] [-bpp 24]
18USAGE
19
20for ( 0 .. @ARGV-1 )
21{
22 $options{$ARGV[$_]} = $ARGV[$_ + 1] || 1;
23}
24
25$options{-flags} = SDL_SWSURFACE;
26$options{-flags} |= SDL_HWPALETTE if ( $options{-hw} );
27$options{-flags} |= SDL_FULLSCREEN if ( $options{-fullscreen} );
28
29$options{-title} = $0;
30
31$options{-width} ||= 640;
32$options{-height} ||= 480;
33$options{-depth} ||= $options{-bpp} || 8;
34
35my $app = new SDL::App %options;
36
37sub DrawBox {
38 my ($x,$y) = @_;
39
40 my ($w, $h) = ( int(rand(640)), int(rand(480)) );
41
42 my $rect = new SDL::Rect -width => $w, -height => $h,
43 -x => ($x - int($w/2)), -y => ($y - int($h/2));
44
45 my $color = new SDL::Color -r => rand(256), -g => rand(256), -b => rand(256);
46
47 $app->fill($rect,$color);
48 $app->update($rect);
49};
50
51$app->loop( {
52 SDL_MOUSEBUTTONDOWN() => sub {
53 my ($event) = @_;
54 DrawBox($event->button_x(),$event->button_y());
55 },
56 SDL_KEYDOWN() => sub {
57 my ($event) = @_;
58 $app->warp($options{-width}/2,$options{-height}/2)
59 if ($event->key_sym() == SDLK_SPACE);
60 $app->fullscreen()
61 if ($event->key_sym() == SDLK_f);
62 exit(0) if ($event->key_sym() == SDLK_ESCAPE);
63 },
64 SDL_QUIT() => sub { exit(0); }
65} );
66
67