3 <h3 id="TOP">Index</h3>
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
9 <li><a href="#CONSTRUCTION">CONSTRUCTION</a>
10 <ul><li><a href="#new">new</a></li>
11 <li><a href="#new_attributes">new ( %attributes )</a></li>
14 <li><a href="#ACCESSORS">ACCESSORS</a>
15 <ul><li><a href="#x">x</a></li>
16 <li><a href="#y">y</a></li>
17 <li><a href="#h_align">h_align</a></li>
18 <li><a href="#color">color</a></li>
19 <li><a href="#size">size</a></li>
20 <li><a href="#font">font</a></li>
23 <li><a href="#METHODS">METHODS</a>
24 <ul><li><a href="#text_some_text">text( $some_text )</a></li>
25 <li><a href="#write_to_target_surface">write_to( $target_surface )</a></li>
26 <li><a href="#write_to_target_surface_quot_text_to">write_to( $target_surface, "text to write" )</a></li>
27 <li><a href="#write_xy_target_surface_x_y">write_xy( $target_surface, $x, $y )</a></li>
28 <li><a href="#write_xy_target_surface_x_y_text">write_xy( $target_surface, $x, $y, $text )</a></li>
31 <li><a href="#READ_ONLY_ATTRIBUTES">READ-ONLY ATTRIBUTES</a>
32 <ul><li><a href="#surface">surface</a></li>
33 <li><a href="#w">w</a></li>
34 <li><a href="#h">h</a></li>
37 <li><a href="#ERRORS_AND_DIAGNOSTICS">ERRORS AND DIAGNOSTICS</a></li>
38 <li><a href="#BUGS">BUGS</a></li>
39 <li><a href="#SUPPORT">SUPPORT</a></li>
40 <li><a href="#AUTHORS">AUTHORS</a></li>
41 <li><a href="#COPYRIGHT_amp_LICENSE">COPYRIGHT & LICENSE</a></li>
42 <li><a href="#SEE_ALSO">SEE ALSO</a>
47 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
48 <div id="NAME_CONTENT">
49 <p>SDLx::Text - SDL extension for manipulating text</p>
52 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
53 <div id="CATEGORY_CONTENT">
57 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
58 <div id="SYNOPSIS_CONTENT">
63 my $app = SDLx::App->new;
65 my $message = SDLx::Text->new;
67 $message->write_to( $app, "Hello, World!" );
76 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
77 <div id="DESCRIPTION_CONTENT">
78 <p>The standard SDL API for handling fonts and rendering text is full of quirks
79 and and low-level functions scattered all over the place. This is a sugar
80 layer meant to let you easily handle text in your SDL apps.</p>
83 <h1 id="CONSTRUCTION">CONSTRUCTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
84 <div id="CONSTRUCTION_CONTENT">
88 <div id="new_CONTENT">
91 <h2 id="new_attributes">new ( %attributes )</h2>
92 <div id="new_attributes_CONTENT">
93 <p>Instantiates a new SDLx::Text object. All attributes are optional:</p>
94 <pre> my $text = SDLx::Text->new(
95 font => '/path/to/my/font.ttf',
96 color => [255, 255, 255], # "white"
100 h_align => 'left',
101 text => 'All your base are belong to us.'
105 <p>Please check the accessors below for more information on each attribute.
106 All values shown above are the <strong>default values</strong>, except for "text",
107 which defaults to <code>undef</code>; and "font", which if not provided will load
108 the <code>Gentium Basic</code> free font (see "<a href="http://search.cpan.org/perldoc?">http://search.cpan.org/perldoc?</a>" for more
112 <h1 id="ACCESSORS">ACCESSORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
113 <div id="ACCESSORS_CONTENT">
114 <p>All accessors below can be used to get and set their respective attributes.
116 <pre> my $font_name = $self->font; # gets the font filename
117 $self->font( 'somefont.ttf' ); # sets a new font
120 <p>All accessors return their current value, after being set.</p>
125 <p>Gets/sets the left (x) positioning of the text to be rendered, relative
126 to whatever surface you are placing it into.</p>
131 <p>Gets/sets the top (y) positioning of the text to be rendered, relative
132 to whatever surface you are placing it into.</p>
135 <h2 id="h_align">h_align</h2>
136 <div id="h_align_CONTENT">
137 <p>Gets/sets the horizontal alignment of the text to be rendered relative to
138 whatever surface you are placing it into. Available alignments are '<code>left</code>',
139 '<code>right</code>' and '<code>center</code>'. Default is '<code>left</code>'.</p>
142 <h2 id="color">color</h2>
143 <div id="color_CONTENT">
144 <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>
147 <h2 id="size">size</h2>
148 <div id="size_CONTENT">
149 <p>Gets/sets the font size.</p>
152 <h2 id="font">font</h2>
153 <div id="font_CONTENT">
154 <p>Pass it a string containing the path to your desired font to use it. Fonts
155 can be in TTF, OTF or FON formats. Generates an exception if the font
156 cannot be loaded.</p>
157 <p>Returns the <a href="SDL-TTF-Font.html">SDL::TTF::Font</a> object representing the font.</p>
164 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
165 <div id="METHODS_CONTENT">
168 <h2 id="text_some_text">text( $some_text )</h2>
169 <div id="text_some_text_CONTENT">
170 <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>
171 <pre> my $obj = SDLx::Text->new->text( "Hello, Dave." );
174 <p>Text will always be rendered as utf8, so you can pass any string containing
175 regular ASCII or valid utf8 characters.</p>
178 <h2 id="write_to_target_surface">write_to( $target_surface )</h2>
179 <div id="write_to_target_surface_CONTENT">
182 <h2 id="write_to_target_surface_quot_text_to">write_to( $target_surface, "text to write" )</h2>
183 <div id="write_to_target_surface_quot_text_to-2">
184 <p>Renders the text onto <code>$target_surface</code> (usually the app itself). The
185 text string may be passed as a parameter, otherwise it will use whatever
186 is already set (via the <code>new()</code> or <code>text()</code> methods.</p>
189 <h2 id="write_xy_target_surface_x_y">write_xy( $target_surface, $x, $y )</h2>
190 <div id="write_xy_target_surface_x_y_CONTENT">
193 <h2 id="write_xy_target_surface_x_y_text">write_xy( $target_surface, $x, $y, $text )</h2>
194 <div id="write_xy_target_surface_x_y_text_CON">
195 <p>Same as <code>write_to()</code>, but will render the text using the given top (y) and
196 left (x) coordinates.</p>
203 <h1 id="READ_ONLY_ATTRIBUTES">READ-ONLY ATTRIBUTES</h1><p><a href="#TOP" class="toplink">Top</a></p>
204 <div id="READ_ONLY_ATTRIBUTES_CONTENT">
205 <p>As you set or update your text, font or size, SDLx::Text updates the surface
206 that represents it. You don't usually need to worry about this at all, and
207 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>
208 <p>If however you need to know how tall or wide the rendered text will be
209 (in pixels), or if you want to retrieve the surface so you can manipulate and
210 render it yourself, you can use the following getters:</p>
213 <h2 id="surface">surface</h2>
214 <div id="surface_CONTENT">
215 <p>Returns the underlying surface representing the text itself. You probably don't need this, unless you're doing something really funky.</p>
220 <p>Shortcut to see the width of the underlying surface representing the text.</p>
225 <p>Shortcut to see the height of the underlying surface representing the text.</p>
228 <h1 id="ERRORS_AND_DIAGNOSTICS">ERRORS AND DIAGNOSTICS</h1><p><a href="#TOP" class="toplink">Top</a></p>
229 <div id="ERRORS_AND_DIAGNOSTICS_CONTENT">
231 <dt>* "SDL_ttf support has not been compiled"</dt>
233 <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>
235 <dt>* "Cannot init TTF: <some error>"</dt>
237 <p>In order to load fonts and render text, we need to initialize <a href="SDL-TTF.html">SDL::TTF</a>
238 - that is, in case it hasn't been initialized already. The error above will
239 appear in the rare event of any problem during initialization.</p>
241 <dt>* "Error opening font: <some error>"</dt>
243 <p>The font file you set either via <code>font( 'font.ttf' )</code> or during
244 construction could not be loaded. The file may not exist in the given path,
245 have wrong permissions, be corrupted, or of an unsupported format. Please
246 refer the <code><some error></code> message in the message itself for further
249 <dt>* "TTF rendering error: <some error>"</dt>
251 <p>When you call <code>text()</code>, it renders the provided string onto an internal
252 <a href="SDL-Surface.html">SDL::Surface</a> object. If there was any problem rendering the text, this
253 message will appear.</p>
258 <h1 id="BUGS">BUGS</h1><p><a href="#TOP" class="toplink">Top</a></p>
259 <div id="BUGS_CONTENT">
260 <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>
267 <h1 id="SUPPORT">SUPPORT</h1><p><a href="#TOP" class="toplink">Top</a></p>
268 <div id="SUPPORT_CONTENT">
269 <p>You can find documentation for this module with the perldoc command.</p>
270 <pre> perldoc SDLx::Text
278 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
279 <div id="AUTHORS_CONTENT">
280 <p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>
287 <h1 id="COPYRIGHT_amp_LICENSE">COPYRIGHT & LICENSE</h1><p><a href="#TOP" class="toplink">Top</a></p>
288 <div id="COPYRIGHT_amp_LICENSE_CONTENT">
289 <p>This program is free software; you can redistribute it and/or modify it
290 under the same terms as Perl itself.</p>
291 <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>
294 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
295 <div id="SEE_ALSO_CONTENT">
296 <p><a href="SDL.html">SDL</a>, <a href="SDLx-App.html">SDLx::App</a>, <a href="SDL-TTF.html">SDL::TTF</a>