Permalink
Browse files

Use SDLx::App in the menu example

  • Loading branch information...
jtpalmer committed Sep 11, 2011
1 parent e00db75 commit 6eb33623438bc7d96221e7949aed035a88320968
Showing with 14 additions and 21 deletions.
  1. +14 −21 examples/menu.pl
View
@@ -1,44 +1,37 @@
use strict;
use warnings;
-use Carp 'croak';
-use SDL;
-use SDL::Events;
-use SDL::Video;
-use SDL::Surface;
+use SDLx::App;
use lib 'lib';
-use SDLx::Controller;
use SDLx::Widget::Menu;
-croak 'Cannot init ' . SDL::get_error() if SDL::init(SDL_INIT_VIDEO) == -1;
-
-# Create our display window
-my $display
- = SDL::Video::set_video_mode( 800, 600, 32,
- SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL )
- or croak 'Cannot create display: ' . SDL::get_error();
+my $app = SDLx::App->new(
+ w => 800,
+ h => 600,
+ eoq => 1,
+);
-my $game = SDLx::Controller->new( eoq => 1 );
my $menu = SDLx::Widget::Menu->new( topleft => [ 0, 400 ], mouse => 1 );
$menu->items(
'New Game' => sub { },
'Load Game' => sub { },
'Options' => sub { },
- 'Quit' => sub { $menu->{exit} = 1; }, #return the of this in event loop
+ 'Quit' => sub { $menu->{exit} = 1; },
);
-$game->add_event_handler(
+$app->add_event_handler(
sub {
$menu->event_hook( $_[0] );
- $game->stop if $menu->{exit};
+ $app->stop if $menu->{exit};
}
);
-$game->add_show_handler(
+$app->add_show_handler(
sub {
- $menu->render($display);
- SDL::Video::flip($display);
+ $app->draw_rect( undef, undef );
+ $menu->render($app);
+ $app->update;
}
);
-$game->run;
+$app->run;

0 comments on commit 6eb3362

Please sign in to comment.