SDLx::App - a SDL perl extension
Contents
Callbacks
"SDLx::App" is a "SDLx::Controller". Use the event, show and handlers to run the app.
use SDL;
use SDLx::App;
use SDL::Event; #Where ever the event call back is processed
my $app = SDLx::App->new( width => 200, height => 200);
$app->add_event_handler( sub{
my ($event, $app) = @_;
return $_[0]->type == SDL_QUIT ? 0 : 1;
});
$app->add_show_handler( sub{
my ($delta, $app) = @_;
$app->update;
} );
$app->add_move_handler( sub{
my ($step, $app, $t) = @_;
#calc your physics here
} );
$app->run();
see SDLx::Controller for more details.
Category
Extension
Description
SDLx::App controls the root window of the of your SDL based application. It extends the SDL::Surface
class, and provides an interface to the window manager oriented functions.
Methods
title()title($new_title)title($window_title,$icon_title)
"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.
delay($ms)
"SDLx::App::delay" takes 1 argument, and will sleep the application for that many ms.
ticks
"SDLx::App::ticks" returns the number of ms since the application began.
error
"SDLx::App::error" returns the last error message set by the SDL.
resize($width,$height)
"SDLx::App::resize" takes a new width and height of the application. Only works if the application was
originally created with the resizable option.
fullscreen
"SDLx::App::fullscreen" toggles the application in and out of fullscreen mode.
iconify
"SDLx::App::iconify" iconifies the application window.
grab_input($CONSTANT)
"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
sync
"SDLx::App::sync" encapsulates the various methods of synchronizing 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 preferred to calling flip on the application window.
attribute($attr)attribute($attr,$value)
"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::confess on failure.
Name
SDLx::App - a SDL perl extension
See Also
perl SDL::Surface SDL::Event SDL::OpenGL
perl v5.40.0 2024-10-20 pods::SDLx::App(3pm)
Synopsis
use SDL;
use SDLx::App;
use SDL::Event;
use SDL::Events;
my $app = SDLx::App->new(
title => 'Application Title',
width => 640,
height => 480,
depth => 32
);
This is the manual way of doing things
my $event = SDL::Event->new; # create a new event
SDL::Events::pump_events();
while ( SDL::Events::poll_event($event) ) {
my $type = $event->type(); # get event type
print $type;
exit if $type == SDL_QUIT;
}
An alternative to the manual Event processing is through the SDLx::Controller module. SDLx::App is a
Controller so see the CALLBACKS section below.
