Debian Codegraph @

lib/pods/SDLx/App.pod

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1
2 =pod
3
4 =head1 NAME
5
6 SDLx::App - a SDL perl extension
7
8 =head1 CATEGORY
9
10 Extension
11
12 =head1 SYNOPSIS
13
14 use SDL;
15 use SDLx::App;
16 use SDL::Event;
17 use SDL::Events;
18
19 my $app = SDLx::App->new(
20 title => 'Application Title',
21 width => 640,
22 height => 480,
23 depth => 32
24 );
25
26 This is the manual way of doing things
27
28 my $event = SDL::Event->new; # create a new event
29
30 SDL::Events::pump_events();
31
32 while ( SDL::Events::poll_event($event) ) {
33 my $type = $event->type(); # get event type
34 print $type;
35 exit if $type == SDL_QUIT;
36 }
37
38 An alternative to the manual Event processing is through the L<SDLx::Controller> module. L<SDLx::App> is a Controller so see the CALLBACKS section below.
39
40 =head1 DESCRIPTION
41
42 L<SDLx::App> controls the root window of the of your SDL based application.
43 It extends the L<SDL::Surface> class, and provides an interface to the window
44 manager oriented functions.
45
46 =head1 METHODS
47
48 =head2 new
49
50 C<SDLx::App::new> initializes the SDL, creates a new screen,
51 and initializes some of the window manager properties.
52 C<SDLx::App::new> takes a series of named parameters:
53
54 =over 4
55
56 =item * title
57 the window title. Defaults to the file name. Shorter alias: 't'
58
59 =item * icon_title
60 the icon title. Defaults to file name. Shortcut: 'it'
61
62 =item * icon
63 the icon itself. Defaults to none. Shortcut: 'i'
64
65 =item * width
66 Window width, in pixels. Defaults to 800. Shortcut: 'w'
67
68 =item * height
69 Window height, in pixels. Defaults to 600. Shortcut: 'h'
70
71 =item * depth
72 Screen depth. Defaults to 16. Shortcut: 'd'.
73
74 =item * flags
75 Any flags you want to pass to L<SDL::Video> upon initialization. Defaults to SDL_ANYFORMAT. Flags should be I<or'ed> together if you're passing more than one (flags => FOO|BAR). Shortcut: 'f'.
76
77 =item * resizeable
78 Set this to a true value to make the window resizeable by the user. Default is off.
79
80 =item * exit_on_quit
81 Set this to a true value to make the app exit if a SDL_QUIT event is triggered. Shortcut: 'eoq'.
82
83 =back
84
85 =head1 METHODS
86
87 =head2 title()
88
89 =head2 title( $new_title )
90
91 =head2 title( $window_title, $icon_title )
92
93 C<SDLx::App::title> takes 0, 1, or 2 arguments. If no parameter is given,
94 it returns the current application window title. If one parameter is
95 passed, both the window title and icon title will be set to its value.
96 If two parameters are passed the window title will be set to the first,
97 and the icon title to the second.
98
99 =head2 delay( $ms )
100
101 C<SDLx::App::delay> takes 1 argument, and will sleep the application for
102 that many ms.
103
104 =head2 ticks
105
106 C<SDLx::App::ticks> returns the number of ms since the application began.
107
108 =head2 error
109
110 C<SDLx::App::error> returns the last error message set by the SDL.
111
112 =head2 resize( $width, $height )
113
114 C<SDLx::App::resize> takes a new width and height of the application. Only
115 works if the application was originally created with the resizable option.
116
117 =head2 fullscreen
118
119 C<SDLx::App::fullscreen> toggles the application in and out of fullscreen mode.
120
121 =head2 iconify
122
123 C<SDLx::App::iconify> iconifies the application window.
124
125 =head2 grab_input( $CONSTANT )
126
127 C<SDLx::App::grab_input> can be used to change the input focus behavior of
128 the application. It takes one argument, which should be one of the following:
129
130 =over 4
131
132 =item * SDL_GRAB_QUERY
133
134 =item * SDL_GRAB_ON
135
136 =item * SDL_GRAB_OFF
137
138 =back
139
140 =head2 sync
141
142 C<SDLx::App::sync> encapsulates the various methods of synchronizing the screen with the
143 current video buffer. C<SDLx::App::sync> will do a fullscreen update, using the double buffer
144 or OpenGL buffer if applicable. This is preferred to calling flip on the application window.
145
146 =head2 attribute( $attr )
147
148 =head2 attribute( $attr, $value )
149
150 C<SDLx::App::attribute> allows one to get and set GL attributes. By passing a value
151 in addition to the attribute selector, the value will be set. C<SDL:::App::attribute>
152 always returns the current value of the given attribute, or Carp::confess on failure.
153
154 =head1 CALLBACKS
155
156 C<SDLx::App> is a C<SDLx::Controller>. Use the event, show and handlers to run the app.
157
158 use SDL;
159 use SDLx::App;
160
161 use SDL::Event; #Where ever the event call back is processed
162
163 my $app = SDLx::App->new( width => 200, height => 200);
164
165 $app->add_event_handler( sub{
166 my ($event, $app) = @_;
167 return $_[0]->type == SDL_QUIT ? 0 : 1;
168 });
169
170 $app->add_show_handler( sub{
171 my ($delta, $app) = @_;
172 $app->update;
173 } );
174
175 $app->add_move_handler( sub{
176 my ($step, $app, $t) = @_;
177 #calc your physics here
178 } );
179
180 $app->run();
181
182 see L<SDLx::Controller> for more details.
183
184 =head1 AUTHORS
185
186 See L<SDL/AUTHORS>.
187
188 =head1 SEE ALSO
189
190 L<perl> L<SDL::Surface> L<SDL::Event> L<SDL::OpenGL>
191
192 =cut