pods::SDLx::App(3pm)
πΈ NAME πΈ
SDLx::App β a SDL perl extension. Bestie, this is pods::SDLx::App(3pm), straight from the User Contributed Perl Documentation, and itβs about to make your SDL app era iconic. π
π CATEGORY π
Extension β thatβs the category, periodt. β¨
β¨ SYNOPSIS β¨
Okay so first, the classic setup:
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. π«Ά
π DESCRIPTION π
SDLx::App controls the root window of your SDL based application. It extends the SDL::Surface class, and provides an interface to the window manager oriented functions. Itβs giving βI run this windowβ energy, ngl. π
β¨ METHODS β¨
π new π
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 800. Shortcut:'w'heightβ Window height, in pixels. Defaults to 600. Shortcut:'h'depthβ Screen depth. Defaults to 16. Shortcut:'d'.flagsβ Any flags you want to pass toSDL::Videoupon initialization. Defaults toSDL_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 aSDL_QUITevent is triggered. Shortcut:'eoq'.
π METHODS π
π title π
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. Nap time, but make it intentional. π΄
β ticks β
SDLx::App::ticks returns the number of ms since the application began. Time check, bestie! β±οΈ
πΈ 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. Main character energy: activated. π₯
π 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_QUERYSDL_GRAB_ONSDL_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 π
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. π«
π«Ά 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. π
π AUTHORS π
See "AUTHORS" in SDL.
π SEE ALSO π
perlSDL::SurfaceSDL::EventSDL::OpenGL
Okay bestie, thatβs the page! π Cute sign-off tea: source/version/date are perl v5.42.0, 2024-05-01, and pods::SDLx::App(3pm). Mwah! π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms