fixed links to methods
[sdlgit/SDL-Site.git] / pages / SDLx-LayerManager.html-inc
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="#add">add</a></li>
12 <li><a href="#layers">layers</a></li>
13 <li><a href="#layer">layer</a></li>
14 <li><a href="#length">length</a></li>
15 <li><a href="#blit">blit</a></li>
16 <li><a href="#by_position">by_position</a></li>
17 <li><a href="#ahead">ahead</a></li>
18 <li><a href="#behind">behind</a></li>
19 <li><a href="#attach">attach</a></li>
20 <li><a href="#detach_xy">detach_xy</a></li>
21 <li><a href="#detach_back">detach_back</a></li>
22 <li><a href="#foreground">foreground</a></li>
23 </ul>
24 </li>
25 <li><a href="#BUGS">BUGS</a></li>
26 <li><a href="#SUPPORT">SUPPORT</a></li>
27 <li><a href="#AUTHORS">AUTHORS</a></li>
28 <li><a href="#COPYRIGHT">COPYRIGHT</a></li>
29 <li><a href="#SEE_ALSO">SEE ALSO</a>
30 </li>
31 </ul><hr />
32 <!-- INDEX END -->
33
34 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
35 <div id="NAME_CONTENT">
36 <p>SDLx::LayerManager - Extension for managing layers in a 2D world</p>
37
38 </div>
39 <h1 id="CATEGORY">CATEGORY </h1><p><a href="#TOP" class="toplink">Top</a></p>
40 <div id="CATEGORY_CONTENT">
41 <p>Extension</p>
42
43 </div>
44 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
45 <div id="SYNOPSIS_CONTENT">
46 <pre>  use SDLx::Layer;
47   use SDLx::LayerManager;
48
49   use SDL::Image;
50   use SDL::Surface;
51   use SDL::Video;
52
53   # creating layers
54   my $layer1 = SDLx::Layer-&gt;new( SDL::Image::load('image1.png'), {userdata =&gt; '7'} );
55   my $layer2 = SDLx::Layer-&gt;new( SDL::Image::load('image2.png'), 100, 200, {userdata =&gt; '42'} );
56
57   # creating the manager that holds the layers
58   my $layermanager = SDLx::LayerManager-&gt;new();
59   $layermanager-&gt;add( $layer1 );
60   $layermanager-&gt;add( $layer2 );
61
62   my $display = # create your video surface here
63
64   $layermanager-&gt;blit( $display );
65
66   # accessing the layer at point(x,y)
67   print( $layermanager-&gt;by_position( 150, 200 )-&gt;data-&gt;{userdata} ); # should print '42'
68
69 </pre>
70
71 </div>
72 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
73 <div id="DESCRIPTION_CONTENT">
74 <p>SDLx::LayerManager is a package to handle a bunch of layers. A layer (see SDLx::Layer) is an SDL::Surface, the position of the surface on screen and some additional information.</p>
75 <p>The layermanager gives you the opportunity to obtain the layer at a given point on screen and get the layers that are ahead or behind a layer.</p>
76 <p>You will even be able to attach one or more layers to the mouse, e.g. for simulation some drag&amp;drop functionality.</p>
77
78 </div>
79 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
80 <div id="METHODS_CONTENT">
81
82 </div>
83 <h2 id="new">new</h2>
84 <div id="new_CONTENT">
85 <pre>  my $layermanager = SDLx::LayerManager-&gt;new();
86
87 </pre>
88 <p>This creates your layermanager object. It doesn't take any parameters.</p>
89
90 </div>
91 <h2 id="add">add</h2>
92 <div id="add_CONTENT">
93 <pre>  $layermanager-&gt;add( $layer );
94   $layermanager-&gt;add( SDLx::Layer-&gt;new( $surface, $x, $y, $options ) );
95
96 </pre>
97 <p>Call <code>add</code> to push an SDLx::Layer object to the layermanager.</p>
98
99 </div>
100 <h2 id="layers">layers</h2>
101 <div id="layers_CONTENT">
102 <pre>  my @layers = @{ $layermanager-&gt;layers };
103   my $first_layer = $layermanager-&gt;layers-&gt;[0];
104
105 </pre>
106 <p>The method <code>layers</code> returns all layers that were added before.</p>
107
108 </div>
109 <h2 id="layer">layer</h2>
110 <div id="layer_CONTENT">
111 <pre>  my $layer = $layermanager-&gt;layer( $index );
112
113 </pre>
114 <p>To obtain only one layer at index <code>$index</code> use this function. <code>$index</code> ranges from <code>0</code> to <code>lenght - 1</code>.</p>
115
116 </div>
117 <h2 id="length">length</h2>
118 <div id="length_CONTENT">
119 <pre>  my $length = $layermanager-&gt;length();
120
121 </pre>
122 <p>This method returns the count of the added layers.</p>
123
124 </div>
125 <h2 id="blit">blit</h2>
126 <div id="blit_CONTENT">
127 <pre>  $layermanager-&gt;blit( $surface );
128
129 </pre>
130 <p>This method blits all layers to the surface (e.g. your video surface).</p>
131
132 </div>
133 <h2 id="by_position">by_position</h2>
134 <div id="by_position_CONTENT">
135 <pre>  my $layer = $layermanager-&gt;by_position( $x, $y );
136
137 </pre>
138 <p><code>by_position</code> returns the <code>SDLx::Layer</code> object at point <code>$x $y</code>, which is not fully transparent at this pixel.</p>
139
140 </div>
141 <h2 id="ahead">ahead</h2>
142 <div id="ahead_CONTENT">
143 <pre>  my @layers = @{ $layermanager-&gt;ahead( $index ) };
144
145 </pre>
146 <p>This method returns all layers that are ahead of the given layer indicated by <code>$index</code>.
147 Ahead means that a layer has a higher z-index and is blitted over the given layer.</p>
148 <p><strong>Note</strong>: This method doesn't check for transparency. This will change in future versions.</p>
149
150 </div>
151 <h2 id="behind">behind</h2>
152 <div id="behind_CONTENT">
153 <pre>  my @layers = @{ $layermanager-&gt;behind( $index ) };
154
155 </pre>
156 <p>This method returns all layers that are behind of the given layer indicated by <code>$index</code>.
157 Behind means that a layer has a lower z-index and is blitted before the given layer.</p>
158 <p><strong>Note</strong>: This method doesn't check for transparency. This will change in future versions.</p>
159
160 </div>
161 <h2 id="attach">attach</h2>
162 <div id="attach_CONTENT">
163 <pre>  $layermanager-&gt;attach( $layer,  $x, $y );
164   $layermanager-&gt;attach( @layers, $x, $y );
165
166 </pre>
167 <p>This function makes the given layer(s) sticky to the mouse. If you move the mouse the layer(s) will follow.
168 The layermanager blits these layers at last, so they will appear on top of all layers.</p>
169 <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.
170 If you omit <code>$x</code> and <code>$y</code> the layermanager obtains them via SDL::Events::get_mouse_state.</p>
171 <p><strong>Note</strong>: The z-index is not changed for the given layers.</p>
172
173 </div>
174 <h2 id="detach_xy">detach_xy</h2>
175 <div id="detach_xy_CONTENT">
176 <pre>  $layermanager-&gt;detach_xy( $x, $y );
177
178 </pre>
179 <p><code>detach_xy</code> detaches the prevously attached layers to the given coords. The upper left corner of the backmost layer will be at <code>$x</code> and <code>$y</code>.
180 The other layers are positioned relative to the backmost layer just like before.</p>
181
182 </div>
183 <h2 id="detach_back">detach_back</h2>
184 <div id="detach_back_CONTENT">
185 <pre>  $layermanager-&gt;detach_back( );
186
187 </pre>
188 <p><code>detach_back</code> detaches the prevously attached layers back to the position where they were attached.</p>
189
190 </div>
191 <h2 id="foreground">foreground</h2>
192 <div id="foreground_CONTENT">
193 <pre>  $layermanager-&gt;foreground( $layer );
194   $layermanager-&gt;foreground( @layers );
195
196 </pre>
197 <p>This method moves the given layer(s) to the foreground so that they are blittet on top of the other layers.</p>
198
199 </div>
200 <h1 id="BUGS">BUGS</h1><p><a href="#TOP" class="toplink">Top</a></p>
201 <div id="BUGS_CONTENT">
202 <p>Report at sdlperl.ath.cx</p>
203
204 </div>
205 <h1 id="SUPPORT">SUPPORT</h1><p><a href="#TOP" class="toplink">Top</a></p>
206 <div id="SUPPORT_CONTENT">
207 <p>#sdl irc.perl.org</p>
208
209 </div>
210 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
211 <div id="AUTHORS_CONTENT">
212 <p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>
213
214 </div>
215 <h1 id="COPYRIGHT">COPYRIGHT</h1><p><a href="#TOP" class="toplink">Top</a></p>
216 <div id="COPYRIGHT_CONTENT">
217 <p>This program is free software; you can redistribute
218 it and/or modify it under the same terms as Perl itself.</p>
219 <p>The full text of the license can be found in the
220 LICENSE file included with this module.</p>
221
222
223
224
225
226 </div>
227 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
228 <div id="SEE_ALSO_CONTENT">
229 <p>perl(1), SDL(2).</p>
230
231 </div>
232 </div>