Merge branch 'master' of git.shadowcat.co.uk:SDL-Site
[sdlgit/SDL-Site.git] / pages / SDLx-App.html-inc
CommitLineData
162a0989 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
5<ul><li><a href="#NAME">NAME</a></li>
bfdd9c2e 6<li><a href="#CATEGORY">CATEGORY</a></li>
162a0989 7<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
a3de8488 8<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
162a0989 9<li><a href="#METHODS">METHODS</a>
10<ul><li><a href="#new">new</a></li>
e1ec9f6e 11</ul>
12</li>
13<li><a href="#METHODS-2">METHODS</a>
14<ul><li><a href="#title">title()</a></li>
285d0cd2 15<li><a href="#title_new_title">title( $new_title )</a></li>
16<li><a href="#title_window_title_icon_title">title( $window_title, $icon_title )</a></li>
17<li><a href="#delay_ms">delay( $ms )</a></li>
162a0989 18<li><a href="#ticks">ticks</a></li>
19<li><a href="#error">error</a></li>
285d0cd2 20<li><a href="#resize_width_height">resize( $width, $height )</a></li>
162a0989 21<li><a href="#fullscreen">fullscreen</a></li>
22<li><a href="#iconify">iconify</a></li>
285d0cd2 23<li><a href="#grab_input_CONSTANT">grab_input( $CONSTANT )</a></li>
162a0989 24<li><a href="#sync">sync</a></li>
285d0cd2 25<li><a href="#attribute_attr">attribute( $attr )</a></li>
26<li><a href="#attribute_attr_value">attribute( $attr, $value )</a></li>
162a0989 27</ul>
28</li>
e1ec9f6e 29<li><a href="#CALLBACKS">CALLBACKS</a></li>
c7e8d3c6 30<li><a href="#AUTHORS">AUTHORS</a></li>
162a0989 31<li><a href="#SEE_ALSO">SEE ALSO</a>
32</li>
33</ul><hr />
34<!-- INDEX END -->
35
36<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
37<div id="NAME_CONTENT">
ca0a3441 38<p>SDLx::App - a SDL perl extension</p>
162a0989 39
40</div>
bfdd9c2e 41<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
42<div id="CATEGORY_CONTENT">
43<p>Extension</p>
44
45</div>
162a0989 46<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
47<div id="SYNOPSIS_CONTENT">
f373167e 48<pre> use SDL;
ca0a3441 49 use SDLx::App;
f373167e 50 use SDL::Event;
51 use SDL::Events;
52
ca0a3441 53 my $app = SDLx::App-&gt;new(
505f308d 54 title =&gt; 'Application Title',
55 width =&gt; 640,
56 height =&gt; 480,
57 depth =&gt; 32
f373167e 58 );
162a0989 59
60</pre>
285d0cd2 61<p>This is the manual way of doing things</p>
f373167e 62<pre> my $event = SDL::Event-&gt;new; # create a new event
162a0989 63
f373167e 64 SDL::Events::pump_events();
162a0989 65
f373167e 66 while ( SDL::Events::poll_event($event) ) {
67 my $type = $event-&gt;type(); # get event type
68 print $type;
69 exit if $type == SDL_QUIT;
70 }
162a0989 71
72</pre>
1dbe1697 73<p>An alternative to the manual Event processing is through the <a href="SDLx-Controller.html">SDLx::Controller</a> module. <a href="SDLx-App.html">SDLx::App</a> is a Controller so see the CALLBACKS section below.</p>
a3de8488 74
75</div>
76<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
77<div id="DESCRIPTION_CONTENT">
1dbe1697 78<p><a href="SDLx-App.html">SDLx::App</a> controls the root window of the of your SDL based application.
55bbf7a2 79It extends the <a href="SDL-Surface.html">SDL::Surface</a> class, and provides an interface to the window
162a0989 80manager oriented functions.</p>
81
82</div>
83<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
84<div id="METHODS_CONTENT">
85
86</div>
87<h2 id="new">new</h2>
88<div id="new_CONTENT">
ca0a3441 89<p><code>SDLx::App::new</code> initializes the SDL, creates a new screen,
162a0989 90and initializes some of the window manager properties.
ca0a3441 91<code>SDLx::App::new</code> takes a series of named parameters:</p>
285d0cd2 92<dl>
c7e8d3c6 93 <dt>* title
94the window title. Defaults to the file name. Shorter alias: 't'</dt>
95 <dt>* icon_title
96the icon title. Defaults to file name. Shortcut: 'it'</dt>
97 <dt>* icon
98the icon itself. Defaults to none. Shortcut: 'i'</dt>
99 <dt>* width
100Window width, in pixels. Defaults to 800. Shortcut: 'w'</dt>
101 <dt>* height
102Window height, in pixels. Defaults to 600. Shortcut: 'h'</dt>
103 <dt>* depth
104Screen depth. Defaults to 16. Shortcut: 'd'.</dt>
105 <dt>* flags
106Any flags you want to pass to <a href="SDL-Video.html">SDL::Video</a> upon initialization. Defaults to SDL_ANYFORMAT. Flags should be <i>or'ed</i> together if you're passing more than one (flags =&gt; FOO|BAR). Shortcut: 'f'.</dt>
107 <dt>* resizeable
108Set this to a true value to make the window resizeable by the user. Default is off.</dt>
4769fd12 109 <dt>* exit_on_quit
110Set this to a true value to make the app exit if a SDL_QUIT event is triggered. Shortcut: 'eoq'.</dt>
285d0cd2 111</dl>
112
e1ec9f6e 113</div>
114<h1 id="METHODS-2">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
115<div id="METHODS_CONTENT-2">
162a0989 116
117</div>
285d0cd2 118<h2 id="title">title()</h2>
162a0989 119<div id="title_CONTENT">
162a0989 120
121</div>
285d0cd2 122<h2 id="title_new_title">title( $new_title )</h2>
123<div id="title_new_title_CONTENT">
124
125</div>
126<h2 id="title_window_title_icon_title">title( $window_title, $icon_title )</h2>
127<div id="title_window_title_icon_title_CONTEN">
128<p><code>SDLx::App::title</code> takes 0, 1, or 2 arguments. If no parameter is given,
129it returns the current application window title. If one parameter is
130passed, both the window title and icon title will be set to its value.
131If two parameters are passed the window title will be set to the first,
132and the icon title to the second.</p>
133
134</div>
135<h2 id="delay_ms">delay( $ms )</h2>
136<div id="delay_ms_CONTENT">
ca0a3441 137<p><code>SDLx::App::delay</code> takes 1 argument, and will sleep the application for
162a0989 138that many ms.</p>
139
140</div>
141<h2 id="ticks">ticks</h2>
142<div id="ticks_CONTENT">
ca0a3441 143<p><code>SDLx::App::ticks</code> returns the number of ms since the application began.</p>
162a0989 144
145</div>
146<h2 id="error">error</h2>
147<div id="error_CONTENT">
ca0a3441 148<p><code>SDLx::App::error</code> returns the last error message set by the SDL.</p>
162a0989 149
150</div>
285d0cd2 151<h2 id="resize_width_height">resize( $width, $height )</h2>
152<div id="resize_width_height_CONTENT">
153<p><code>SDLx::App::resize</code> takes a new width and height of the application. Only
154works if the application was originally created with the resizable option.</p>
162a0989 155
156</div>
157<h2 id="fullscreen">fullscreen</h2>
158<div id="fullscreen_CONTENT">
ca0a3441 159<p><code>SDLx::App::fullscreen</code> toggles the application in and out of fullscreen mode.</p>
162a0989 160
161</div>
162<h2 id="iconify">iconify</h2>
163<div id="iconify_CONTENT">
285d0cd2 164<p><code>SDLx::App::iconify</code> iconifies the application window.</p>
162a0989 165
166</div>
285d0cd2 167<h2 id="grab_input_CONSTANT">grab_input( $CONSTANT )</h2>
168<div id="grab_input_CONSTANT_CONTENT">
ca0a3441 169<p><code>SDLx::App::grab_input</code> can be used to change the input focus behavior of
285d0cd2 170the application. It takes one argument, which should be one of the following:</p>
162a0989 171<dl>
285d0cd2 172 <dt>* SDL_GRAB_QUERY</dt>
173 <dt>* SDL_GRAB_ON</dt>
174 <dt>* SDL_GRAB_OFF</dt>
162a0989 175</dl>
176
177</div>
162a0989 178<h2 id="sync">sync</h2>
179<div id="sync_CONTENT">
ca0a3441 180<p><code>SDLx::App::sync</code> encapsulates the various methods of syncronizing the screen with the
285d0cd2 181current video buffer. <code>SDLx::App::sync</code> will do a fullscreen update, using the double buffer
182or OpenGL buffer if applicable. This is prefered to calling flip on the application window.</p>
183
184</div>
185<h2 id="attribute_attr">attribute( $attr )</h2>
186<div id="attribute_attr_CONTENT">
162a0989 187
188</div>
285d0cd2 189<h2 id="attribute_attr_value">attribute( $attr, $value )</h2>
162a0989 190<div id="attribute_attr_value_CONTENT">
285d0cd2 191<p><code>SDLx::App::attribute</code> allows one to get and set GL attributes. By passing a value
192in addition to the attribute selector, the value will be set. <code>SDL:::App::attribute</code>
3afd3fb0 193always returns the current value of the given attribute, or Carp::confesss on failure.</p>
162a0989 194
195</div>
e1ec9f6e 196<h1 id="CALLBACKS">CALLBACKS</h1><p><a href="#TOP" class="toplink">Top</a></p>
197<div id="CALLBACKS_CONTENT">
198<p><code>SDLx::App</code> is a <code>SDLx::Controller</code>. Use the event, show and handlers to run the app.</p>
199<pre> use SDL;
200 use SDLx::App;
201
202 use SDL::Event; #Where ever the event call back is processed
203
204 my $app = SDLx::App-&gt;new( width =&gt; 200, height =&gt; 200);
205
206 $app-&gt;add_event_handler( sub{ return 0 if $_[0]-&gt;type == SDL_QUIT; return 1});
207
208 $app-&gt;add_show_handler( sub{ $app-&gt;update() } );
209
210 $app-&gt;add_move_handler(
211 sub{
212 #calc your physics here
213 } );
214
215 $app-&gt;run();
216
217</pre>
1dbe1697 218<p>see <a href="SDLx-Controller.html">SDLx::Controller</a> for more details.</p>
e1ec9f6e 219
220</div>
c7e8d3c6 221<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
222<div id="AUTHORS_CONTENT">
1dbe1697 223<p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>
162a0989 224
225</div>
226<h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
227<div id="SEE_ALSO_CONTENT">
55bbf7a2 228<p><a href="http://search.cpan.org/perldoc?perl">perl</a> <a href="SDL-Surface.html">SDL::Surface</a> <a href="SDL-Event.html">SDL::Event</a> <a href="SDL-OpenGL.html">SDL::OpenGL</a></p>
162a0989 229
230</div>
231</div>