1SDLx::App(3)          User Contributed Perl Documentation         SDLx::App(3)
2
3
4

NAME

6       SDLx::App - a SDL perl extension
7

CATEGORY

9       Extension
10

SYNOPSIS

12           use SDL;
13           use SDLx::App;
14           use SDL::Event;
15           use SDL::Events;
16
17           my $app = SDLx::App->new(
18               title  => 'Application Title',
19               width  => 640,
20               height => 480,
21               depth  => 32
22           );
23
24       This is the manual way of doing things
25
26           my $event = SDL::Event->new; # create a new event
27
28           SDL::Events::pump_events();
29
30           while ( SDL::Events::poll_event($event) ) {
31               my $type = $event->type(); # get event type
32               print $type;
33               exit if $type == SDL_QUIT;
34           }
35
36       An alternative to the manual Event processing is through the
37       SDLx::Controller module. SDLx::App is a Controller so see the CALLBACKS
38       section below.
39

DESCRIPTION

41       SDLx::App controls the root window of the of your SDL based
42       application.  It extends the SDL::Surface class, and provides an
43       interface to the window manager oriented functions.
44

METHODS

46   new
47       "SDLx::App::new" initializes the SDL, creates a new screen, and
48       initializes some of the window manager properties.  "SDLx::App::new"
49       takes a series of named parameters:
50
51       •   title the window title. Defaults to the file name. Shorter alias:
52           't'
53
54       •   icon_title the icon title. Defaults to file name. Shortcut: 'it'
55
56       •   icon the icon itself. Defaults to none. Shortcut: 'i'
57
58       •   width Window width, in pixels. Defaults to 800. Shortcut: 'w'
59
60       •   height Window height, in pixels. Defaults to 600. Shortcut: 'h'
61
62       •   depth Screen depth. Defaults to 16. Shortcut: 'd'.
63
64       •   flags Any flags you want to pass to SDL::Video upon initialization.
65           Defaults to SDL_ANYFORMAT. Flags should be or'ed together if you're
66           passing more than one (flags => FOO|BAR). Shortcut: 'f'.
67
68       •   resizeable Set this to a true value to make the window resizeable
69           by the user. Default is off.
70
71       •   exit_on_quit Set this to a true value to make the app exit if a
72           SDL_QUIT event is triggered. Shortcut: 'eoq'.
73

METHODS

75   title()
76   title( $new_title )
77   title( $window_title, $icon_title )
78       "SDLx::App::title" takes 0, 1, or 2 arguments. If no parameter is
79       given, it returns the current application window title. If one
80       parameter is passed, both the window title and icon title will be set
81       to its value.  If two parameters are passed the window title will be
82       set to the first, and the icon title to the second.
83
84   delay( $ms )
85       "SDLx::App::delay" takes 1 argument, and will sleep the application for
86       that many ms.
87
88   ticks
89       "SDLx::App::ticks" returns the number of ms since the application
90       began.
91
92   error
93       "SDLx::App::error" returns the last error message set by the SDL.
94
95   resize( $width, $height )
96       "SDLx::App::resize" takes a new width and height of the application.
97       Only works if the application was originally created with the resizable
98       option.
99
100   fullscreen
101       "SDLx::App::fullscreen" toggles the application in and out of
102       fullscreen mode.
103
104   iconify
105       "SDLx::App::iconify" iconifies the application window.
106
107   grab_input( $CONSTANT )
108       "SDLx::App::grab_input" can be used to change the input focus behavior
109       of the application. It takes one argument, which should be one of the
110       following:
111
112       •   SDL_GRAB_QUERY
113
114       •   SDL_GRAB_ON
115
116       •   SDL_GRAB_OFF
117
118   sync
119       "SDLx::App::sync" encapsulates the various methods of synchronizing the
120       screen with the current video buffer. "SDLx::App::sync" will do a
121       fullscreen update, using the double buffer or OpenGL buffer if
122       applicable. This is preferred to calling flip on the application
123       window.
124
125   attribute( $attr )
126   attribute( $attr, $value )
127       "SDLx::App::attribute" allows one to get and set GL attributes. By
128       passing a value in addition to the attribute selector, the value will
129       be set. "SDL:::App::attribute" always returns the current value of the
130       given attribute, or Carp::confess on failure.
131

CALLBACKS

133       "SDLx::App" is a "SDLx::Controller". Use the event, show and handlers
134       to run the app.
135
136         use SDL;
137         use SDLx::App;
138
139         use SDL::Event; #Where ever the event call back is processed
140
141         my $app = SDLx::App->new( width => 200, height => 200);
142
143         $app->add_event_handler( sub{
144             my ($event, $app) = @_;
145             return $_[0]->type == SDL_QUIT ? 0 : 1;
146         });
147
148         $app->add_show_handler( sub{
149             my ($delta, $app) = @_;
150             $app->update;
151         } );
152
153         $app->add_move_handler( sub{
154             my ($step, $app, $t) = @_;
155             #calc your physics here
156         } );
157
158         $app->run();
159
160       see SDLx::Controller for more details.
161

AUTHORS

163       See "AUTHORS" in SDL.
164

SEE ALSO

166       perl SDL::Surface SDL::Event  SDL::OpenGL
167
168
169
170perl v5.34.0                      2022-01-21                      SDLx::App(3)
Impressum