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="#CONSTRUCTOR">CONSTRUCTOR </a>
10 <ul><li><a href="#new">new</a></li>
11 <li><a href="#display">display</a></li>
12 <li><a href="#duplicate">duplicate</a></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>
19 <li><a href="#load">load</a></li>
20 <li><a href="#blit">blit </a></li>
21 <li><a href="#blit_by">blit_by</a></li>
22 <li><a href="#flip">flip</a></li>
23 <li><a href="#update">update</a></li>
24 <li><a href="#draw_rect">draw_rect</a></li>
25 <li><a href="#draw_line">draw_line</a></li>
26 <li><a href="#draw_circle">draw_circle</a></li>
27 <li><a href="#draw_circle_filled">draw_circle_filled</a></li>
28 <li><a href="#draw_gfx_text">draw_gfx_text</a></li>
31 <li><a href="#AUTHORS">AUTHORS</a>
36 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
37 <div id="NAME_CONTENT">
38 <p>SDLx::Surface - Graphic surface matrix extension</p>
41 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
42 <div id="CATEGORY_CONTENT">
46 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
47 <div id="SYNOPSIS_CONTENT">
52 # Create the main surface (display)
53 SDL::init(SDL_INIT_VIDEO);
54 my $display = SDL::Video::set_video_mode(640, 480, 16, SDL_SWSURFACE);
56 my $surf_matrix = SDLx::Surface->new( surface => $display);
58 $surf_matrix->[10][10] = 0xFFFF; #for 16bpp write white at x = 10 and y=10
60 $surf_matrix->surface( $new_surface );
62 my $orig_surface = $surf_matrix->surface();
67 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
68 <div id="DESCRIPTION_CONTENT">
69 <p>An <code>SDLx::Surface</code> allows matrix read and write to a surface, safely. </p>
72 <h1 id="CONSTRUCTOR">CONSTRUCTOR </h1><p><a href="#TOP" class="toplink">Top</a></p>
73 <div id="CONSTRUCTOR_CONTENT">
77 <div id="new_CONTENT">
78 <p>Takes a SDL::Surface in hash format.</p>
79 <p>If a surface is passed to 'surface =>' that is loaded. Otherwise you can define at least a width and a height. </p>
80 <pre> SDLx::Surface->new( surface => $surface) # The $surface is loaded
82 SDLx::Surface->new( width=> 400, height=>200)
83 # A SDL::Surface->new( SDL_ANYFORMAT, 400, 200, 32) is loaded
85 SDLx::Surface->new( width=> 400, height=>200, flags=> SDL_SWSURFACE, depth=>24 )
86 # A SDL::Surface->new( SDL_SWSURFACE, 400, 200, 24) is loaded
88 SDLx::Surface->new( width=> 400, height=>200, flags=> SDL_SWSURFACE, depth=>32, greenmask=>0xFF000000 )
89 # A SDL::Surface->new( SDL_ANYFORMAT, 400, 200, 32, 0, 0xFF000000,0, 0, 0 ) is loaded
90 SDLx::Surface->new( w => 1, h => 1, color => 0xFF0000FF )
91 # A SDL::Surface->new( SDL_ANYFORMAT, 1, 1, 32, 0, 0, 0, 0 ) is loaded
92 all pixels are colored with color (red)
97 <h2 id="display">display</h2>
98 <div id="display_CONTENT">
99 <p>If <a href="/SDLx-App.html#new">SDLx::App::new</a> or <a href="/SDL-Video.html#get_video_mode">SDL::Video::get_video_mode</a> called before then:</p>
100 <pre> my $appx = SDLx::Surface::display();
103 <p>gets the display if it is already made. Passed options are ignored. Otherwise you can quickly make the display with :</p>
104 <pre> SDLx::Surface::display( width => 20, height => 20) #depth => 32 and SDL_ANYFORMAT used
107 <p>or you can also pass flags and depth. </p>
108 <pre> SDLx::Surface::display( width => 20, height => 20, flags=> SDL_HWSURFACE, depth=>24)
111 <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>
112 <p>Get or create the main display surface and attach to a <code>SDLx::Surface</code>.</p>
115 <h2 id="duplicate">duplicate</h2>
116 <div id="duplicate_CONTENT">
117 <p>Does a attributes only, no pixel, copy of another SDLx::Surface. </p>
120 <h1 id="ATTRIBUTES">ATTRIBUTES</h1><p><a href="#TOP" class="toplink">Top</a></p>
121 <div id="ATTRIBUTES_CONTENT">
124 <h2 id="surface">surface</h2>
125 <div id="surface_CONTENT">
126 <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>
129 <h2 id="w_h_format_pitch_flags">w, h, format, pitch, flags</h2>
130 <div id="w_h_format_pitch_flags_CONTENT">
131 <p>Returns the inner SDL::Surface's respective attribute. See <code>SDL::Surface</code>.</p>
134 <h2 id="clip_rect">clip_rect</h2>
135 <div id="clip_rect_CONTENT">
136 <p>Sets the passed <code>SDL::Rect</code> as the new clip_rect for the surface. Returns the SDL::Surface's clip_rect. See
137 <a href="/SDL-Video.html#get_clip_rect">SDL::Video::get_clip_rect</a> and <a href="/SDL-Video.html#set_clip_rect">SDL::Video::set_clip_rect</a>.
138 =head1 EXTENSIONS</p>
141 <h2 id="load">load</h2>
142 <div id="load_CONTENT">
143 <pre> my $surface = SDLx::Surface->load( 'hero.png' );
144 my $surface = SDLx::Surface->load( 'hero.dat', 'bmp' );
147 <p>Loads the given image file into a <i>new</i> SDLx::Surface surface. A new
148 surface is <strong>always</strong> created, even if you call it from an already crafted
149 object. Croaks on errors such as no support built for that image extension
150 or a file reading error (the error message is SDL::get_error and should
151 give more details).</p>
152 <p>Note that load() will automatically figure out the extension based on the
153 filename you provide. If you wish to force an extension for whatever reason
154 (like having a filename with a different extension or none at all), you can
155 optionally pass the file type as a second parameter. Case is not relevant.</p>
156 <p>If you don't have SDL_image in your build, only bitmap images will be
158 <p>Returns the new Surface.</p>
165 <h2 id="blit">blit </h2>
166 <div id="blit_CONTENT">
167 <pre> $sdlx_surface->blit( $dest, $src_rect, $dest_rect );
170 <p>Blits <code>SDLx::Surface</code> onto $dest surface.
171 $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,
172 it will be blitted at <code>(0, 0)</code>. $src_rect or $dest_rect can be array refs or <code>SDL::Rect</code>. $dest can be <code>SDLx::Surface</code> or <code>SDL::Surface</code>.</p>
176 <h2 id="blit_by">blit_by</h2>
177 <div id="blit_by_CONTENT">
178 <pre> $sdlx_surface->blit_by( $src, $src_rect, $dest_rect );
181 <p>Does the same as <code>blit</code> but the <code>SDLx::Surface</code> is the one being blitted to.
182 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 <h2 id="flip">flip</h2>
186 <div id="flip_CONTENT">
187 <p>Applies <a href="/SDL-Video.html#flip">SDL::Video::flip</a> to the Surface, with error checking.</p>
191 <h2 id="update">update</h2>
192 <div id="update_CONTENT">
193 <pre> $sdlx_surface->update(); # whole surface is updated
194 $sdlx_surface->update([0,0,1,1]); # only that area (0,0,1,1) is updated
196 $sdlx_surface->update( [ SDL::Rect->new(0,0,1,2) ... ]); # defined rects are updated
199 <p>Applies <a href="/SDL-Video.html#update_rect">SDL::Video::update_rect</a> for no rect or 1 array ref. Applies
200 <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>
208 <h2 id="draw_rect">draw_rect</h2>
209 <div id="draw_rect_CONTENT">
210 <pre> $sdlx_surface->draw_rect( [$x,$y,$w,$h], 0xFFFF00FF );
211 $sdlx_surface->draw_rect( SDL::Rect->new($x,$y,$w,$h), 0xFFFF00FF );
214 <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>
218 <h2 id="draw_line">draw_line</h2>
219 <div id="draw_line_CONTENT">
220 <pre> $sdlx_surface->draw_line( [$x1, $y1], [$x2, $y2], $color, $antialias); # $color is a number
221 $sdlx_surface->draw_line( [$x1, $y1], [$x2, $y2], \@color, $antialias); #
224 <p>Draws a line on the surface. Antialias is turned on if $antialias is true. </p>
228 <h2 id="draw_circle">draw_circle</h2>
229 <div id="draw_circle_CONTENT">
230 <pre> $sdlx_surface->draw_circle( [$x1, $y1], $radius, \@color );
233 <p>Draws an unfilled circle at <code>($x1,$y1)</code> of size $radius and $color.</p>
237 <h2 id="draw_circle_filled">draw_circle_filled</h2>
238 <div id="draw_circle_filled_CONTENT">
239 <pre> $sdlx_surface->draw_filled_circle( [$x1, $y1], $radius, \@color );
242 <p>Draws an <strong>filled</strong> circle at <code>($x1,$y1)</code> of size $radius and $color.</p>
253 <h2 id="draw_gfx_text">draw_gfx_text</h2>
254 <div id="draw_gfx_text_CONTENT">
255 <p>Draw text using gfx (not pretty but fast) at give vector, color.</p>
256 <pre> $surf->draw_gfx_text( [0,0], 0xffffffff, "fooo");
257 $surf->draw_gfx_text( [10,10], [20,20,20,20], "fooo");
260 <p>You can also set the gfx font but passing a hash reference as shown below.</p>
262 open( my $FH, '<', 'test/data/5x7.fnt');
267 my $font = {data=>$f, cw => 5, ch => 7};
268 $surf->draw_gfx_text( [0,0], 0xffffffff, "fooo", $font );
274 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
275 <div id="AUTHORS_CONTENT">
276 <p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>