update for SDL::Event
[sdlgit/SDL-Site.git] / pages / SDLx-Surface.html-inc
CommitLineData
30fd24c2 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
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>
807ae0cd 9<li><a href="#CONSTRUCTOR">CONSTRUCTOR </a>
30fd24c2 10<ul><li><a href="#new">new</a></li>
807ae0cd 11<li><a href="#display">display</a></li>
12<li><a href="#duplicate">duplicate</a></li>
13</ul>
14</li>
15<li><a href="#ATTRIBUTES">ATTRIBUTES</a>
16<ul><li><a href="#surface">surface</a></li>
17<li><a href="#w_h_format_pitch_flags">w, h, format, pitch, flags</a></li>
18<li><a href="#clip_rect">clip_rect</a></li>
30fd24c2 19</ul>
20</li>
21<li><a href="#EXTENSIONS">EXTENSIONS</a>
33a8f248 22<ul><li><a href="#load">load</a></li>
23<li><a href="#blit">blit </a></li>
505f308d 24<li><a href="#blit_by">blit_by</a></li>
30fd24c2 25<li><a href="#flip">flip</a></li>
26<li><a href="#update">update</a></li>
807ae0cd 27<li><a href="#draw_rect">draw_rect</a></li>
28<li><a href="#draw_line">draw_line</a></li>
c7e8d3c6 29<li><a href="#draw_circle">draw_circle</a></li>
30<li><a href="#draw_circle_filled">draw_circle_filled</a></li>
285d0cd2 31<li><a href="#draw_gfx_text">draw_gfx_text</a></li>
30fd24c2 32</ul>
33</li>
c7e8d3c6 34<li><a href="#AUTHORS">AUTHORS</a>
30fd24c2 35</li>
36</ul><hr />
37<!-- INDEX END -->
38
39<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
40<div id="NAME_CONTENT">
41<p>SDLx::Surface - Graphic surface matrix extension</p>
42
43</div>
44<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
45<div id="CATEGORY_CONTENT">
46<p>Extension</p>
47
48</div>
49<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
50<div id="SYNOPSIS_CONTENT">
51<pre> use SDL;
52 use SDL::Video;
53 use SDLx::Surface;
54
55 # Create the main surface (display)
56 SDL::init(SDL_INIT_VIDEO);
57 my $display = SDL::Video::set_video_mode(640, 480, 16, SDL_SWSURFACE);
58
59 my $surf_matrix = SDLx::Surface-&gt;new( surface =&gt; $display);
60
807ae0cd 61 $surf_matrix-&gt;[10][10] = 0xFFFF; #for 16bpp write white at x = 10 and y=10
30fd24c2 62
63 $surf_matrix-&gt;surface( $new_surface );
64
65 my $orig_surface = $surf_matrix-&gt;surface();
66
67</pre>
68
69</div>
70<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
71<div id="DESCRIPTION_CONTENT">
72<p>An <code>SDLx::Surface</code> allows matrix read and write to a surface, safely. </p>
73
74</div>
807ae0cd 75<h1 id="CONSTRUCTOR">CONSTRUCTOR </h1><p><a href="#TOP" class="toplink">Top</a></p>
76<div id="CONSTRUCTOR_CONTENT">
30fd24c2 77
78</div>
79<h2 id="new">new</h2>
80<div id="new_CONTENT">
81<p>Takes a SDL::Surface in hash format.</p>
82<p>If a surface is passed to 'surface =&gt;' that is loaded. Otherwise you can define at least a width and a height. </p>
83<pre> SDLx::Surface-&gt;new( surface =&gt; $surface) # The $surface is loaded
84
85 SDLx::Surface-&gt;new( width=&gt; 400, height=&gt;200)
86 # A SDL::Surface-&gt;new( SDL_ANYFORMAT, 400, 200, 32) is loaded
87
88 SDLx::Surface-&gt;new( width=&gt; 400, height=&gt;200, flags=&gt; SDL_SWSURFACE, depth=&gt;24 )
89 # A SDL::Surface-&gt;new( SDL_SWSURFACE, 400, 200, 24) is loaded
90
91 SDLx::Surface-&gt;new( width=&gt; 400, height=&gt;200, flags=&gt; SDL_SWSURFACE, depth=&gt;32, greenmask=&gt;0xFF000000 )
92 # A SDL::Surface-&gt;new( SDL_ANYFORMAT, 400, 200, 32, 0, 0xFF000000,0, 0, 0 ) is loaded
505f308d 93 SDLx::Surface-&gt;new( w =&gt; 1, h =&gt; 1, color =&gt; 0xFF0000FF )
94 # A SDL::Surface-&gt;new( SDL_ANYFORMAT, 1, 1, 32, 0, 0, 0, 0 ) is loaded
95 all pixels are colored with color (red)
807ae0cd 96
97</pre>
30fd24c2 98
99</div>
807ae0cd 100<h2 id="display">display</h2>
101<div id="display_CONTENT">
0b221bb4 102<p>If <a href="http://search.cpan.org/perldoc?SDLx::App::new">SDLx::App::new</a> or <a href="SDL-Video::get_video_mode.html">SDL::Video::get_video_mode</a> called before then:</p>
807ae0cd 103<pre> my $appx = SDLx::Surface::display();
30fd24c2 104
105</pre>
106<p>gets the display if it is already made. Passed options are ignored. Otherwise you can quickly make the display with :</p>
807ae0cd 107<pre> SDLx::Surface::display( width =&gt; 20, height =&gt; 20) #depth =&gt; 32 and SDL_ANYFORMAT used
30fd24c2 108
109</pre>
110<p>or you can also pass flags and depth. </p>
807ae0cd 111<pre> SDLx::Surface::display( width =&gt; 20, height =&gt; 20, flags=&gt; SDL_HWSURFACE, depth=&gt;24)
30fd24c2 112
113</pre>
505f308d 114<p>You can also use the keys <code>w</code> and <code>h</code> in place of <code>width</code> and <code>height</code>, as with <code>new</code>.</p>
30fd24c2 115<p>Get or create the main display surface and attach to a SDLx::Surface.</p>
116
117</div>
807ae0cd 118<h2 id="duplicate">duplicate</h2>
119<div id="duplicate_CONTENT">
120<p>Does a attributes only, no pixel, copy of another SDLx::Surface. </p>
121
122</div>
123<h1 id="ATTRIBUTES">ATTRIBUTES</h1><p><a href="#TOP" class="toplink">Top</a></p>
124<div id="ATTRIBUTES_CONTENT">
125
126</div>
127<h2 id="surface">surface</h2>
128<div id="surface_CONTENT">
129<p>If a SDL::Surface is passed it is attached to the matrix. Returns the SDL::Surface that is currently attached to this SDLx::Surface</p>
130
131</div>
132<h2 id="w_h_format_pitch_flags">w, h, format, pitch, flags</h2>
133<div id="w_h_format_pitch_flags_CONTENT">
134<p>Returns the inner SDL::Surface's respective attribute. See <code>SDL::Surface</code>.</p>
135
136</div>
137<h2 id="clip_rect">clip_rect</h2>
138<div id="clip_rect_CONTENT">
139<p>Sets the passed <code>SDL::Rect</code> as the new clip_rect for the surface. Returns the SDL::Surface's clip_rect. See <code>SDL::Video::get_clip_rect</code> and <code>SDL::Video::set_clip_rect</code>.</p>
140
141</div>
30fd24c2 142<h1 id="EXTENSIONS">EXTENSIONS</h1><p><a href="#TOP" class="toplink">Top</a></p>
143<div id="EXTENSIONS_CONTENT">
144
145</div>
33a8f248 146<h2 id="load">load</h2>
147<div id="load_CONTENT">
148<pre> my $surface = SDLx::Surface-&gt;load( 'hero.png' );
149 my $surface = SDLx::Surface-&gt;load( 'hero.dat', 'bmp' );
150
151</pre>
152<p>Loads the given image file into a <i>new</i> SDLx::Surface surface. A new
153surface is <strong>always</strong> created, even if you call it from an already crafted
154object. Croaks on errors such as no support built for that image extension
155or a file reading error (the error message is SDL::get_error and should
156give more details).</p>
157<p>Note that load() will automatically figure out the extension based on the
158filename you provide. If you wish to force an extension for whatever reason
159(like having a filename with a different extension or none at all), you can
160optionally pass the file type as a second parameter. Case is not relevant.</p>
161<p>If you don't have SDL_image in your build, only bitmap images will be
162supported.</p>
163<p>Returns the new Surface.</p>
164
165
166
167
168
169</div>
30fd24c2 170<h2 id="blit">blit </h2>
171<div id="blit_CONTENT">
172<pre> $sdlx_surface-&gt;blit( $dest, $src_rect, $dest_rect );
173
174</pre>
175<p>Blits SDLx::Surface onto $dest surface.
505f308d 176$src_rect or $dest_rect are optional. If $src_rect is ommited, it will be the size of the entire surface. If $dest_rect is ommited, it will be blitted at <code>(0, 0)</code>. $src_rect or $dest_rect can be array refs or SDL::Rect. $dest can be SDLx::Surface or SDL::Surface.</p>
30fd24c2 177<p>Returns $self</p>
178
179</div>
505f308d 180<h2 id="blit_by">blit_by</h2>
181<div id="blit_by_CONTENT">
182<pre> $sdlx_surface-&gt;blit_by( $src, $src_rect, $dest_rect );
183
184</pre>
185<p>Does the same as <code>blit</code> but the <code>SDLx::Surface</code> is the one being blitted to.
186This is useful when the surface you have isn't an <code>SDLx::Surface</code>, but the surface it is being blitted to is.</p>
187
188</div>
30fd24c2 189<h2 id="flip">flip</h2>
190<div id="flip_CONTENT">
0b221bb4 191<p>Applies <a href="SDL-Video::flip.html">SDL::Video::flip</a> to the Surface, with error checking.</p>
30fd24c2 192<p>Returns $self</p>
193
194</div>
195<h2 id="update">update</h2>
196<div id="update_CONTENT">
197<pre> $sdlx_surface-&gt;update(); # whole surface is updated
198 $sdlx_surface-&gt;update([0,0,1,1]); # only that area (0,0,1,1) is updated
199
200 $sdlx_surface-&gt;update( [ SDL::Rect-&gt;new(0,0,1,2) ... ]); # defined rects are updated
201
202</pre>
0b221bb4 203<p>Applies <a href="SDL-Video::update_rect.html">SDL::Video::update_rect</a> for no rect or 1 array ref. Applies <a href="SDL-Video::update_rects.html">SDL::Video::update_rects</a> for array of <a href="SDL-Rect.html">SDL::Rect</a>s. </p>
30fd24c2 204<p>Returns $self</p>
205
807ae0cd 206
207
208
209
30fd24c2 210</div>
807ae0cd 211<h2 id="draw_rect">draw_rect</h2>
212<div id="draw_rect_CONTENT">
213<pre> $sdlx_surface-&gt;draw_rect( [$x,$y,$w,$h], 0xFFFF00FF );
214 $sdlx_surface-&gt;draw_rect( SDL::Rect-&gt;new($x,$y,$w,$h), 0xFFFF00FF );
30fd24c2 215
807ae0cd 216</pre>
505f308d 217<p>Draws a rect on the surface with the given color. If the rect is ommited, the colored rect will be drawn to the entire surface.</p>
807ae0cd 218<p>Returns $self</p>
30fd24c2 219
807ae0cd 220</div>
221<h2 id="draw_line">draw_line</h2>
222<div id="draw_line_CONTENT">
223<pre> $sdlx_surface-&gt;draw_line( [$x1, $y1], [$x2, $y2], $color, $antialias); # $color is a number
224 $sdlx_surface-&gt;draw_line( [$x1, $y1], [$x2, $y2], \@color, $antialias); #
225
226</pre>
505f308d 227<p>Draws a line on the surface. Antialias is turned on if $antialias is true. </p>
807ae0cd 228<p>Returns $self</p>
30fd24c2 229
807ae0cd 230</div>
c7e8d3c6 231<h2 id="draw_circle">draw_circle</h2>
232<div id="draw_circle_CONTENT">
233<pre> $sdlx_surface-&gt;draw_circle( [$x1, $y1], $radius, \@color );
234
235</pre>
236<p>Draws an unfilled circle at <code>($x1,$y1)</code> of size $radius and $color.</p>
237<p>Returns $self</p>
238
239</div>
240<h2 id="draw_circle_filled">draw_circle_filled</h2>
241<div id="draw_circle_filled_CONTENT">
242<pre> $sdlx_surface-&gt;draw_filled_circle( [$x1, $y1], $radius, \@color );
243
244</pre>
245<p>Draws an <strong>filled</strong> circle at <code>($x1,$y1)</code> of size $radius and $color.</p>
246<p>Returns $self</p>
247
248
249
250
251
252
253
254
255</div>
285d0cd2 256<h2 id="draw_gfx_text">draw_gfx_text</h2>
257<div id="draw_gfx_text_CONTENT">
258<p>Draw text using gfx (not pretty but fast) at give vector, color.</p>
259<pre> $surf-&gt;draw_gfx_text( [0,0], 0xffffffff, &quot;fooo&quot;);
260 $surf-&gt;draw_gfx_text( [10,10], [20,20,20,20], &quot;fooo&quot;);
261
262</pre>
263<p>You can also set the gfx font but passing a hash reference as shown below.</p>
264<pre> my $f = '';
265 open( my $FH, '&lt;', 'test/data/5x7.fnt');
266 binmode ($FH);
267 read($FH, $f, 4096);
268 close ($FH);
269
270 my $font = {data=&gt;$f, cw =&gt; 5, ch =&gt; 7};
271 $surf-&gt;draw_gfx_text( [0,0], 0xffffffff, &quot;fooo&quot;, $font );
272
273</pre>
274<p>Returns $self</p>
275
276</div>
c7e8d3c6 277<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
278<div id="AUTHORS_CONTENT">
279<p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
30fd24c2 280
281</div>
282</div>