#!/usr/bin/env perl # # graywin.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::Rect; use SDL::Event; use SDL::Color; my %options; $options{-flags} = SDL::SWSURFACE; $options{-title} = $0; $options{-width} ||= 640; $options{-height} ||= 480; $options{-depth} ||= $options{-bpp} || 8; my $app = new SDL::App %options; sub DrawBox { my ($x,$y) = @_; my ($w, $h) = ( int(rand(640)), int(rand(480)) ); my $rect = new SDL::Rect -width => $w, -height => $h, -x => ($x - int($w/2)), -y => ($y - int($h/2)); my $color = new SDL::Color -r => rand(256), -g => rand(256), -b => rand(256); $app->fill($rect,$color); $app->update($rect); }; $app->loop( { SDL_MOUSEBUTTONDOWN() => sub { my ($event) = @_; DrawBox($event->button_x(),$event->button_y()); }, SDL_KEYDOWN() => sub { my ($event) = @_; $app->warp($options{-width}/2,$options{-height}/2) if ($event->key_sym() == SDLK_SPACE); $app->fullscreen() if ($event->key_sym() == SDLK_f); exit(0) if ($event->key_sym() == SDLK_ESCAPE); }, SDL_QUIT() => sub { exit(0); } } );