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