NAME
SDLx::Widget::Menu - create menus for your SDL apps easily
SYNOPSIS
Create a simple SDL menu for your game/app:
my $menu = SDLx::Widget::Menu->new->items(
'New Game' => \&play,
'Options' => \&settings,
'Quit' => \&quit,
);
Or customize it at will:
my $menu = SDLx::Widget::Menu->new(
topleft => [100, 120],
font => 'game/data/menu_font.ttf',
font_size => 20,
font_color => [255, 0, 0], # RGB (in this case, 'red')
select_color => [0, 255, 0],
change_sound => 'game/data/menu_select.ogg',
)->items(
'New Game' => \&play,
'Options' => \&settings,
'Quit' => \&quit,
);
After that, all you have to do is make sure your menu object's hooks are called at the right time in your game loop:
# in the event loop
$menu->event_hook( $event ); # $event is a SDL::Event
# in the rendering loop
$menu->render( $screen ); # $screen is a SDL::Surface
DESCRIPTION
Main menus are a very common thing in games. They let the player choose between a new game, loading games, setting up controls, among lots of other stuff. This menu widget is meant to aid developers create menus quickly and easily, so they can concentrate in their game's logic rather than on such a repetitive task. Simple menus, easy. Complex menus, possible!
WARNING! VOLATILE CODE AHEAD
This is a new module and the API is subject to change without notice. If you care, please join the discussion on the #sdl IRC channel in irc.perl.org. All thoughts on further improving the API are welcome.
You have been warned :)
METHODS
new
new( %options )
Creates a new SDLx::Widget::Menu object. No option is mandatory. Available options are:
topleft => [ $top, $left ]
Determines topmost and leftmost positions for the menu.
font => $filename
File name of the font used to render menu text.
font_size => $size
Size of the font used to render menu text.
font_color => [ $red, $green, $blue ]
RGB value to set the font color.
select_color => [ $red, $green, $blue ]
RGB value for the font color of the select item
change_sound => $filename
File name of the sound to play when the selected item changes
items( 'Item 1' => \&sub1, 'Item 2' => \&sub2, ... )
Creates menu items, setting up callbacks for each item.
BUGS AND LIMITATIONS
Mouse doesn't work (yet)
Doesn't let you setup other keys to change current selection (yet)
Doesn't let you handle menu changes yourself (yet)
AUTHORS
Breno G. de Oliveira, <garu at cpan.org>
Kartik thakore <kthakore at cpan.org>