updated docs for layermanager and layer
[sdlgit/SDL-Site.git] / pages / SDLx-Layer.html-inc
CommitLineData
285d0cd2 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>
9<li><a href="#METHODS">METHODS</a>
10<ul><li><a href="#new">new</a></li>
11<li><a href="#index">index</a></li>
12<li><a href="#x">x</a></li>
13<li><a href="#y">y</a></li>
14<li><a href="#w">w</a></li>
15<li><a href="#h">h</a></li>
16<li><a href="#surface">surface</a></li>
285d0cd2 17<li><a href="#pos">pos</a></li>
3030a264 18<li><a href="#clip">clip</a></li>
285d0cd2 19<li><a href="#data">data</a></li>
20<li><a href="#ahead">ahead</a></li>
21<li><a href="#behind">behind</a></li>
22<li><a href="#attach">attach</a></li>
23<li><a href="#detach_xy">detach_xy</a></li>
24<li><a href="#foreground">foreground</a></li>
25</ul>
26</li>
27<li><a href="#BUGS">BUGS</a></li>
28<li><a href="#SUPPORT">SUPPORT</a></li>
d5943b68 29<li><a href="#AUTHORS">AUTHORS</a></li>
285d0cd2 30<li><a href="#COPYRIGHT">COPYRIGHT</a></li>
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">
38<p>SDLx::Layer - Extension ...</p>
39
40</div>
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>
46<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
47<div id="SYNOPSIS_CONTENT">
48<pre> use SDLx::Layer;
49 use SDLx::LayerManager;
50
3030a264 51 use SDL::Image;
52 use SDL::Surface;
53 use SDL::Video;
285d0cd2 54
3030a264 55 # creating layers
56 my $layer1 = SDLx::Layer-&gt;new( SDL::Image::load('image1.png'), {userdata =&gt; '7'} );
57 my $layer2 = SDLx::Layer-&gt;new( SDL::Image::load('image2.png'), 100, 200, {userdata =&gt; '42'} );
58
59 # creating the manager that holds the layers
60 my $layermanager = SDLx::LayerManager-&gt;new();
61 $layermanager-&gt;add( $layer1 );
62 $layermanager-&gt;add( $layer2 );
285d0cd2 63
3030a264 64 my $display = # create your video surface here
285d0cd2 65
3030a264 66 $layer1-&gt;foreground;
67 printf( &quot;%s\n&quot;, $layer1-&gt;behind-&gt;[0]-&gt;data-&gt;{userdata} ); # prints 42
285d0cd2 68
3030a264 69</pre>
285d0cd2 70
3030a264 71</div>
72<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
73<div id="DESCRIPTION_CONTENT">
74<p>A layer (see SDLx::Layer) is an SDL::Surface, the position of the surface on screen and some additional information, e.g. ingame states.</p>
285d0cd2 75
76</div>
77<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
78<div id="METHODS_CONTENT">
79
80</div>
81<h2 id="new">new</h2>
82<div id="new_CONTENT">
3030a264 83<pre> my $layer = SDLx::Layer-&gt;new( $surface );
84 my $layer = SDLx::Layer-&gt;new( $surface, %data );
85 my $layer = SDLx::Layer-&gt;new( $surface, $pos_x, %data );
86 my $layer = SDLx::Layer-&gt;new( $surface, $pos_x, $pos_y, %data );
87 my $layer = SDLx::Layer-&gt;new( $surface, $pos_x, $pos_y, $clip_w, %data );
88 my $layer = SDLx::Layer-&gt;new( $surface, $pos_x, $pos_y, $clip_w, $clip_h, %data );
89
90</pre>
91<p>This constructs the layer object. See how you can omit the position and dimension of the layer. The hash <code>%data</code> is for your use only.
92The layer object just pass it through.</p>
285d0cd2 93
94</div>
95<h2 id="index">index</h2>
96<div id="index_CONTENT">
3030a264 97<pre> my $index = $layer-&gt;index;
98
99</pre>
100<p>The method <code>index</code> represents the z-index ot this layer within its layermanager.</p>
285d0cd2 101
102</div>
103<h2 id="x">x</h2>
104<div id="x_CONTENT">
3030a264 105<pre> my $x = $layer-&gt;x;
106
107</pre>
108<p>This is a shortcut for $layer-&gt;pos-&gt;x.</p>
285d0cd2 109
110</div>
111<h2 id="y">y</h2>
112<div id="y_CONTENT">
3030a264 113<pre> my $y = $layer-&gt;y;
114
115</pre>
116<p>This is a shortcut for $layer-&gt;pos-&gt;y.</p>
285d0cd2 117
118</div>
119<h2 id="w">w</h2>
120<div id="w_CONTENT">
3030a264 121<pre> my $w = $layer-&gt;w;
122
123</pre>
124<p>This is a shortcut for $layer-&gt;clip-&gt;w.</p>
285d0cd2 125
126</div>
127<h2 id="h">h</h2>
128<div id="h_CONTENT">
3030a264 129<pre> my $h = $layer-&gt;h;
130
131</pre>
132<p>This is a shortcut for $layer-&gt;pos-&gt;h.</p>
285d0cd2 133
134</div>
135<h2 id="surface">surface</h2>
136<div id="surface_CONTENT">
3030a264 137<pre> my $surface = $layer-&gt;surface;
138 my $surface = $layer-&gt;surface( $new_surface );
285d0cd2 139
3030a264 140</pre>
141<p><strong>Example</strong>:</p>
142<pre> SDL::Video::blit_surface( $layer-&gt;surface, $layer-&gt;clip, $destination_surface, $layer-&gt;pos );
143
144</pre>
145<p>This method let you retrive the current or set a new surface.</p>
285d0cd2 146
147</div>
148<h2 id="pos">pos</h2>
149<div id="pos_CONTENT">
3030a264 150<pre> my $rect = $layer-&gt;pos;
151
152</pre>
153<p>The method <code>pos</code> returns an SDL::Rect object. The pos x and y are stored there.</p>
154<p><strong>Example</strong>:</p>
155<pre> SDL::Video::blit_surface( $layer-&gt;surface, $layer-&gt;clip, $destination_surface, $layer-&gt;pos );
156
157</pre>
158
159</div>
160<h2 id="clip">clip</h2>
161<div id="clip_CONTENT">
162<pre> my $rect = $layer-&gt;clip;
163
164</pre>
165<p>The method <code>clip</code> returns an SDL::Rect object. The clip width and height are stored there.</p>
166<p><strong>Example</strong>:</p>
167<pre> SDL::Video::blit_surface( $layer-&gt;surface, $layer-&gt;clip, $destination_surface, $layer-&gt;pos );
168
169</pre>
285d0cd2 170
171</div>
172<h2 id="data">data</h2>
173<div id="data_CONTENT">
3030a264 174<pre> my %data = %{ $layer-&gt;data };
175 my %data = %{ $layer-&gt;data( %new_data) };
176
177</pre>
178<p>This method returns the hash <code>%data</code>. You can set <code>%data</code> by passing a hash.</p>
285d0cd2 179
180</div>
181<h2 id="ahead">ahead</h2>
182<div id="ahead_CONTENT">
3030a264 183<pre> my @layers = $layer-&gt;ahead;
184
185</pre>
186<p>This method returns all layers that are ahead of the given layer.
187Ahead means that a layer has a higher z-index and is blitted over the given layer.</p>
188<p><strong>Note</strong>: This method doesn't check for transparency. This will change in future versions.</p>
285d0cd2 189
190</div>
191<h2 id="behind">behind</h2>
192<div id="behind_CONTENT">
3030a264 193<pre> my @layers = $layer-&gt;behind;
194
195</pre>
196<p>This method returns all layers that are behind of the given layer.
197Behind means that a layer has a lower z-index and is blitted over the given layer.</p>
198<p><strong>Note</strong>: This method doesn't check for transparency. This will change in future versions.</p>
285d0cd2 199
200</div>
201<h2 id="attach">attach</h2>
202<div id="attach_CONTENT">
3030a264 203<pre> $layer-&gt;attach( $x, $y );
204
205</pre>
206<p>This function makes the given layer sticky to the mouse. If you move the mouse the layer will follow.
207The layermanager blits this layer at last, so they will appear on top of all layers.</p>
208<p><code>$x</code> and <code>$y</code> should be set to the coords of the mouse, e.g. the coords of the mouse click.
209If you omit <code>$x</code> and <code>$y</code> the layer obtains them via SDL::Events::get_mouse_state.</p>
210<p><strong>Note</strong>: The z-index is not changed for the given layer.</p>
285d0cd2 211
212</div>
213<h2 id="detach_xy">detach_xy</h2>
214<div id="detach_xy_CONTENT">
3030a264 215<pre> $layer-&gt;detach_xy( $x, $y );
216
217</pre>
218<p><code>detach_xy</code> detaches the prevously attached layer to the given coords. The upper left corner of this layer will be at <code>$x</code> and <code>$y</code>.</p>
285d0cd2 219
220</div>
221<h2 id="foreground">foreground</h2>
222<div id="foreground_CONTENT">
3030a264 223<pre> $layer-&gt;foreground;
224
225</pre>
226<p>This method moves the given layer to the foreground so that it is blittet on top of the other layers.</p>
285d0cd2 227
228</div>
229<h1 id="BUGS">BUGS</h1><p><a href="#TOP" class="toplink">Top</a></p>
230<div id="BUGS_CONTENT">
231<p>Report at sdlperl.ath.cx</p>
232
233</div>
234<h1 id="SUPPORT">SUPPORT</h1><p><a href="#TOP" class="toplink">Top</a></p>
235<div id="SUPPORT_CONTENT">
236<p>#sdl irc.perl.org</p>
237
238</div>
d5943b68 239<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
240<div id="AUTHORS_CONTENT">
241<p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
285d0cd2 242
243</div>
244<h1 id="COPYRIGHT">COPYRIGHT</h1><p><a href="#TOP" class="toplink">Top</a></p>
245<div id="COPYRIGHT_CONTENT">
246<p>This program is free software; you can redistribute
247it and/or modify it under the same terms as Perl itself.</p>
248<p>The full text of the license can be found in the
249LICENSE file included with this module.</p>
250
251
252
253
254
255</div>
256<h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
257<div id="SEE_ALSO_CONTENT">
258<p>perl(1), SDL(2).</p>
259
260</div>
261</div>