<li><a href="#run">run</a></li>
<li><a href="#stop">stop</a></li>
<li><a href="#pause">pause</a></li>
+<li><a href="#paused">paused</a></li>
<li><a href="#add_event_handler">add_event_handler</a></li>
<li><a href="#add_move_handler">add_move_handler</a></li>
<li><a href="#add_show_handler">add_show_handler</a></li>
Having the <code>min_t</code> at 1 / 60 ensures that the controller can update the screen at a maximum of 60 times per second.
A "V-Sync" such as this is necessary to prevent video "tear", which occurs when the app is updating faster than the monitor can display.
Setting it to 0, as seen above, will let the app run as fast as it possibly can.</p>
+<p><code>delay</code> specifies a loop delay in millisecs to place on the controller loop. <strong>NOTE:</strong> Picking a good delay based on the needs can help reduce CPU load and pressure.</p>
<p><code>event</code> is a SDL::Event object that events going to the event callbacks are polled in to. It defaults to <code>SDL::Event->new()</code>.</p>
<p>All parameters are optional.</p>
<p>Returns the new object.</p>
<p>Note 2: a pause will be potentially dangerous to the <code>run</code> cycle (even if you implement your own) unless called by an <code>event</code> callback.</p>
</div>
+<h2 id="paused">paused</h2>
+<div id="paused_CONTENT">
+<p>Returns 1 if the app is paused, undef otherwise.
+This is only useful when used within code that will be run by <code>pause</code>:</p>
+<pre> sub pause {
+ # press P to toggle pause
+
+ my ($e, $app) = @_;
+ if($e->type == SDL_QUIT) {
+ $app->stop;
+ # quit handling is here so that the app
+ # can be stopped while paused
+ }
+ elsif($e->type == SDL_KEYDOWN) {
+ if($e->key_sym == SDLK_P) {
+ # We're paused, so end pause
+ return 1 if $app->paused;
+
+ # We're not paused, so pause
+ $app->pause(\&pause);
+ }
+ }
+ return 0;
+ }
+
+
+
+
+</pre>
+
+</div>
<h2 id="add_event_handler">add_event_handler</h2>
<div id="add_event_handler_CONTENT">
<p>Register a callback to handle events. You can add as many subs as you need.
--- /dev/null
+<div class="pod">
+<!-- INDEX START -->
+<h3 id="TOP">Index</h3>
+
+<ul><li><a href="#NAME">NAME</a></li>
+<li><a href="#CATEGORY">CATEGORY</a></li>
+<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
+<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
+<li><a href="#CONSTRUCTION">CONSTRUCTION</a>
+<ul><li><a href="#new">new</a></li>
+<li><a href="#new_attributes">new ( %attributes )</a></li>
+</ul>
+</li>
+<li><a href="#ACCESSORS">ACCESSORS</a>
+<ul><li><a href="#x">x</a></li>
+<li><a href="#y">y</a></li>
+<li><a href="#h_align">h_align</a></li>
+<li><a href="#color">color</a></li>
+<li><a href="#size">size</a></li>
+<li><a href="#font">font</a></li>
+</ul>
+</li>
+<li><a href="#METHODS">METHODS</a>
+<ul><li><a href="#text_some_text">text( $some_text )</a></li>
+<li><a href="#write_to_target_surface">write_to( $target_surface )</a></li>
+<li><a href="#write_to_target_surface_quot_text_to">write_to( $target_surface, "text to write" )</a></li>
+<li><a href="#write_xy_target_surface_x_y">write_xy( $target_surface, $x, $y )</a></li>
+<li><a href="#write_xy_target_surface_x_y_text">write_xy( $target_surface, $x, $y, $text )</a></li>
+</ul>
+</li>
+<li><a href="#READ_ONLY_ATTRIBUTES">READ-ONLY ATTRIBUTES</a>
+<ul><li><a href="#surface">surface</a></li>
+<li><a href="#w">w</a></li>
+<li><a href="#h">h</a></li>
+</ul>
+</li>
+<li><a href="#ERRORS_AND_DIAGNOSTICS">ERRORS AND DIAGNOSTICS</a></li>
+<li><a href="#BUGS">BUGS</a></li>
+<li><a href="#SUPPORT">SUPPORT</a></li>
+<li><a href="#AUTHORS">AUTHORS</a></li>
+<li><a href="#COPYRIGHT_amp_LICENSE">COPYRIGHT & LICENSE</a></li>
+<li><a href="#SEE_ALSO">SEE ALSO</a>
+</li>
+</ul><hr />
+<!-- INDEX END -->
+
+<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="NAME_CONTENT">
+<p>SDLx::Text - SDL extension for manipulating text</p>
+
+</div>
+<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="CATEGORY_CONTENT">
+<p>Extension</p>
+
+</div>
+<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="SYNOPSIS_CONTENT">
+<pre> use SDL;
+ use SDLx::App;
+ use SDLx::Text;
+
+ my $app = SDLx::App->new;
+
+ my $message = SDLx::Text->new;
+
+ $message->write_to( $app, "Hello, World!" );
+ $app->update;
+
+
+
+
+</pre>
+
+</div>
+<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="DESCRIPTION_CONTENT">
+<p>The standard SDL API for handling fonts and rendering text is full of quirks
+and and low-level functions scattered all over the place. This is a sugar
+layer meant to let you easily handle text in your SDL apps.</p>
+
+</div>
+<h1 id="CONSTRUCTION">CONSTRUCTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="CONSTRUCTION_CONTENT">
+
+</div>
+<h2 id="new">new</h2>
+<div id="new_CONTENT">
+
+</div>
+<h2 id="new_attributes">new ( %attributes )</h2>
+<div id="new_attributes_CONTENT">
+<p>Instantiates a new SDLx::Text object. All attributes are optional:</p>
+<pre> my $text = SDLx::Text->new(
+ font => '/path/to/my/font.ttf',
+ color => [255, 255, 255], # "white"
+ size => 24,
+ x => 0,
+ y => 0,
+ h_align => 'left',
+ text => 'All your base are belong to us.'
+ );
+
+</pre>
+<p>Please check the accessors below for more information on each attribute.
+All values shown above are the <strong>default values</strong>, except for "text",
+which defaults to <code>undef</code>; and "font", which if not provided will load
+the <code>Gentium Basic</code> free font (see "<a href="http://search.cpan.org/perldoc?">http://search.cpan.org/perldoc?</a>" for more
+information).</p>
+
+</div>
+<h1 id="ACCESSORS">ACCESSORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="ACCESSORS_CONTENT">
+<p>All accessors below can be used to get and set their respective attributes.
+For example:</p>
+<pre> my $font_name = $self->font; # gets the font filename
+ $self->font( 'somefont.ttf' ); # sets a new font
+
+</pre>
+<p>All accessors return their current value, after being set.</p>
+
+</div>
+<h2 id="x">x</h2>
+<div id="x_CONTENT">
+<p>Gets/sets the left (x) positioning of the text to be rendered, relative
+to whatever surface you are placing it into.</p>
+
+</div>
+<h2 id="y">y</h2>
+<div id="y_CONTENT">
+<p>Gets/sets the top (y) positioning of the text to be rendered, relative
+to whatever surface you are placing it into.</p>
+
+</div>
+<h2 id="h_align">h_align</h2>
+<div id="h_align_CONTENT">
+<p>Gets/sets the horizontal alignment of the text to be rendered relative to
+whatever surface you are placing it into. Available alignments are '<code>left</code>',
+'<code>right</code>' and '<code>center</code>'. Default is '<code>left</code>'.</p>
+
+</div>
+<h2 id="color">color</h2>
+<div id="color_CONTENT">
+<p>Gets/sets the text color. The color is an array reference in <code>[R, G, B]</code> or <code>[R, G, B, A]</code> format. See <a href="SDL-Color.html">SDL::Color</a> for more information on colors.</p>
+
+</div>
+<h2 id="size">size</h2>
+<div id="size_CONTENT">
+<p>Gets/sets the font size.</p>
+
+</div>
+<h2 id="font">font</h2>
+<div id="font_CONTENT">
+<p>Pass it a string containing the path to your desired font to use it. Fonts
+can be in TTF, OTF or FON formats. Generates an exception if the font
+cannot be loaded.</p>
+<p>Returns the <a href="SDL-TTF-Font.html">SDL::TTF::Font</a> object representing the font.</p>
+
+
+
+
+
+</div>
+<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="METHODS_CONTENT">
+
+</div>
+<h2 id="text_some_text">text( $some_text )</h2>
+<div id="text_some_text_CONTENT">
+<p>Sets the text to be displayed by the SDLx::Text object. Return the SDLx::Text object itself, so you can easily chain this method around.</p>
+<pre> my $obj = SDLx::Text->new->text( "Hello, Dave." );
+
+</pre>
+<p>Text will always be rendered as utf8, so you can pass any string containing
+regular ASCII or valid utf8 characters.</p>
+
+</div>
+<h2 id="write_to_target_surface">write_to( $target_surface )</h2>
+<div id="write_to_target_surface_CONTENT">
+
+</div>
+<h2 id="write_to_target_surface_quot_text_to">write_to( $target_surface, "text to write" )</h2>
+<div id="write_to_target_surface_quot_text_to-2">
+<p>Renders the text onto <code>$target_surface</code> (usually the app itself). The
+text string may be passed as a parameter, otherwise it will use whatever
+is already set (via the <code>new()</code> or <code>text()</code> methods.</p>
+
+</div>
+<h2 id="write_xy_target_surface_x_y">write_xy( $target_surface, $x, $y )</h2>
+<div id="write_xy_target_surface_x_y_CONTENT">
+
+</div>
+<h2 id="write_xy_target_surface_x_y_text">write_xy( $target_surface, $x, $y, $text )</h2>
+<div id="write_xy_target_surface_x_y_text_CON">
+<p>Same as <code>write_to()</code>, but will render the text using the given top (y) and
+left (x) coordinates.</p>
+
+
+
+
+
+</div>
+<h1 id="READ_ONLY_ATTRIBUTES">READ-ONLY ATTRIBUTES</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="READ_ONLY_ATTRIBUTES_CONTENT">
+<p>As you set or update your text, font or size, SDLx::Text updates the surface
+that represents it. You don't usually need to worry about this at all, and
+we strongly recommend you use the <a href="http://search.cpan.org/perldoc?">http://search.cpan.org/perldoc?</a> above to render your text.</p>
+<p>If however you need to know how tall or wide the rendered text will be
+(in pixels), or if you want to retrieve the surface so you can manipulate and
+render it yourself, you can use the following getters:</p>
+
+</div>
+<h2 id="surface">surface</h2>
+<div id="surface_CONTENT">
+<p>Returns the underlying surface representing the text itself. You probably don't need this, unless you're doing something really funky.</p>
+
+</div>
+<h2 id="w">w</h2>
+<div id="w_CONTENT">
+<p>Shortcut to see the width of the underlying surface representing the text.</p>
+
+</div>
+<h2 id="h">h</h2>
+<div id="h_CONTENT">
+<p>Shortcut to see the height of the underlying surface representing the text.</p>
+
+</div>
+<h1 id="ERRORS_AND_DIAGNOSTICS">ERRORS AND DIAGNOSTICS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="ERRORS_AND_DIAGNOSTICS_CONTENT">
+<dl>
+ <dt>* "SDL_ttf support has not been compiled"</dt>
+ <dd>
+ <p>In order to render text in SDL you must have enabled SDL_ttf while building <a href="http://search.cpan.org/perldoc?Alien::SDL">Alien::SDL</a>.</p>
+ </dd>
+ <dt>* "Cannot init TTF: <some error>"</dt>
+ <dd>
+ <p>In order to load fonts and render text, we need to initialize <a href="SDL-TTF.html">SDL::TTF</a>
+- that is, in case it hasn't been initialized already. The error above will
+appear in the rare event of any problem during initialization.</p>
+ </dd>
+ <dt>* "Error opening font: <some error>"</dt>
+ <dd>
+ <p>The font file you set either via <code>font( 'font.ttf' )</code> or during
+construction could not be loaded. The file may not exist in the given path,
+have wrong permissions, be corrupted, or of an unsupported format. Please
+refer the <code><some error></code> message in the message itself for further
+information.</p>
+ </dd>
+ <dt>* "TTF rendering error: <some error>"</dt>
+ <dd>
+ <p>When you call <code>text()</code>, it renders the provided string onto an internal
+<a href="SDL-Surface.html">SDL::Surface</a> object. If there was any problem rendering the text, this
+message will appear.</p>
+ </dd>
+</dl>
+
+</div>
+<h1 id="BUGS">BUGS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="BUGS_CONTENT">
+<p>Please report any bugs or feature requests to the bug tracker. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.</p>
+
+
+
+
+
+</div>
+<h1 id="SUPPORT">SUPPORT</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="SUPPORT_CONTENT">
+<p>You can find documentation for this module with the perldoc command.</p>
+<pre> perldoc SDLx::Text
+
+
+
+
+</pre>
+
+</div>
+<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="AUTHORS_CONTENT">
+<p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>
+
+
+
+
+
+</div>
+<h1 id="COPYRIGHT_amp_LICENSE">COPYRIGHT & LICENSE</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="COPYRIGHT_amp_LICENSE_CONTENT">
+<p>This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.</p>
+<p>This module ships with a default font, "<i>Gentium Basic</i>", Copyright 2003-2008 SIL International (http://sil.org), released under the SIL Open Font License 1.1 (OFL). The font is available for use in free and commercial products, with some minor restrictions. Please read the <code>OFL.txt</code> and <code>OFL-FAQ.txt</code> for further information.</p>
+
+</div>
+<h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="SEE_ALSO_CONTENT">
+<p><a href="SDL.html">SDL</a>, <a href="SDLx-App.html">SDLx::App</a>, <a href="SDL-TTF.html">SDL::TTF</a>
+</p>
+
+</div>
+</div>
\ No newline at end of file