SDLx::App - The root window of an SDL application
Extension
use SDL;
use SDLx::App;
use SDL::Event;
use SDL::Events;
# this is all the code we need to have a working app!
my $app = SDLx::App->new;
# we can also specify many useful things in the constructor
my $app = SDLx::App->new(
title => 'My Great Game',
width => 1024,
height => 600,
centered => 1,
no_frame => 1,
async_blit => 1,
);
# our app also comes with an SDLx::Controller
# add a handler handle events such as keypresses
$app->add_event_handler(
sub {
my ($event) = @_;
# handle the event here
}
);
# add a handler to move our objects in response to time
$app->add_move_handler(
sub {
# handle moving objects here
}
);
# add a handler to show our objects on the screen
$app->add_show_handler(
sub {
# handle drawing objects here
}
);
# finally, start the app run loop with the added handlers
$app->run();
For a full explanation of the run loop and other Controller related methods, please see SDLx::Controller.
The SDLx::App
provides methods for the root window of your SDL application, as well as many related convenience methods. It is a subclass of both SDLx::Surface and SDLx::Controller, providing all the methods they both provide.
SDLx::App::new
initializes the SDL, creates a new screen, and initializes some of the window manager properties. SDLx::App::new
takes a series of named parameters:
title the window title. Defaults to the file name. Shorter alias: 't'
icon_title the icon title. Defaults to file name. Shortcut: 'it'
icon the icon itself. Defaults to none. Shortcut: 'i'
width Window width, in pixels. Defaults to 640. Shortcut: 'w'
height Window height, in pixels. Defaults to 480. Shortcut: 'h'
depth Screen depth. Defaults to 16. Shortcut: 'd'.
flags Any flags you want to pass to SDL::Video upon initialization. Defaults to SDL_ANYFORMAT. Flags should be or'ed together if you're passing more than one (flags => FOO|BAR). Shortcut: 'f'.
resizeable Set this to a true value to make the window resizeable by the user. Default is off.
exit_on_quit Set this to a true value to make the app exit if a SDL_QUIT event is triggered. Shortcut: 'eoq'.
SDLx::App::title
takes 0, 1, or 2 arguments. If no parameter is given, it returns the current application window title. If one parameter is passed, both the window title and icon title will be set to its value. If two parameters are passed the window title will be set to the first, and the icon title to the second.
SDLx::App::error
returns the last error message set by the SDL.
SDLx::App::resize
takes a new width and height of the application. Only works if the application was originally created with the resizable option.
SDLx::App::fullscreen
toggles the application in and out of fullscreen mode.
SDLx::App::iconify
iconifies the application window.
SDLx::App::grab_input
can be used to change the input focus behavior of the application. It takes one argument, which should be one of the following:
SDL_GRAB_QUERY
SDL_GRAB_ON
SDL_GRAB_OFF
SDLx::App::sync
encapsulates the various methods of syncronizing the screen with the current video buffer. SDLx::App::sync
will do a fullscreen update, using the double buffer or OpenGL buffer if applicable. This is prefered to calling flip on the application window.
SDLx::App::attribute
allows one to get and set GL attributes. By passing a value in addition to the attribute selector, the value will be set. SDL:::App::attribute
always returns the current value of the given attribute, or Carp::confesss on failure.
See "AUTHORS" in SDL.
SDLx::Controller, SDLx::Surface, SDL::Video, SDL::Event, SDL::Mouse, SDL::OpenGL