1SDLx::Surface(3)      User Contributed Perl Documentation     SDLx::Surface(3)
2
3
4

NAME

6       SDLx::Surface - Graphic surface matrix extension
7

CATEGORY

9       Extension
10

SYNOPSIS

12        use SDL;
13        use SDL::Video;
14        use SDLx::Surface;
15
16        # Create the main surface (display)
17        SDL::init(SDL_INIT_VIDEO);
18        my $display = SDL::Video::set_video_mode(640, 480, 16, SDL_SWSURFACE);
19
20        my $surf_matrix = SDLx::Surface->new( surface => $display);
21
22        $surf_matrix->[10][10] = 0xFFFF; #for 16bpp write white at x = 10 and y=10
23
24        $surf_matrix->surface( $new_surface );
25
26        my $orig_surface = $surf_matrix->surface();
27

DESCRIPTION

29       An "SDLx::Surface" allows matrix read and write to a surface, safely.
30

CONSTRUCTOR

32   new
33       Takes a SDL::Surface in hash format.
34
35       If a surface is passed to 'surface =>' that is loaded. Otherwise you
36       can define at least a width and a height.
37
38               SDLx::Surface->new(  surface => $surface) # The $surface is loaded
39
40               SDLx::Surface->new( width=> 400, height=>200)
41                       # A SDL::Surface->new( SDL_ANYFORMAT, 400, 200, 32) is loaded
42
43               SDLx::Surface->new( width=> 400, height=>200, flags=> SDL_SWSURFACE, depth=>24 )
44                       # A SDL::Surface->new( SDL_SWSURFACE, 400, 200, 24) is loaded
45
46               SDLx::Surface->new( width=> 400, height=>200, flags=> SDL_SWSURFACE, depth=>32, greenmask=>0xFF000000 )
47                       # A SDL::Surface->new( SDL_ANYFORMAT, 400, 200, 32, 0, 0xFF000000,0, 0, 0 ) is loaded
48               SDLx::Surface->new( w => 1, h => 1, color => 0xFF0000FF )
49                       # A SDL::Surface->new( SDL_ANYFORMAT, 1, 1, 32, 0, 0, 0, 0 ) is loaded
50                       all pixels are colored with color (red)
51
52   display
53       If SDLx::App::new or SDL::Video::get_video_mode called before then:
54
55        my $appx = SDLx::Surface::display();
56
57       gets the display if it is already made. Passed options are ignored.
58       Otherwise you can quickly make the display with :
59
60        SDLx::Surface::display( width => 20, height => 20) #depth => 32 and SDL_ANYFORMAT used
61
62       or you can also pass flags and depth.
63
64        SDLx::Surface::display( width => 20, height => 20, flags=> SDL_HWSURFACE, depth=>24)
65
66       You can also use the keys "w" and "h" in place of "width" and "height",
67       as with "new".
68
69       Get or create the main display surface and attach to a "SDLx::Surface".
70
71   duplicate
72       Does a attributes only, no pixel, copy of another SDLx::Surface.
73

ATTRIBUTES

75   surface
76       If a SDL::Surface is passed it is attached to the matrix. Returns the
77       SDL::Surface that is currently attached to this SDLx::Surface
78
79   w, h, format, pitch, flags
80       Returns the inner SDL::Surface's respective attribute. See
81       "SDL::Surface".
82
83   clip_rect
84       Sets the passed "SDL::Rect" as the new clip_rect for the surface.
85       Returns the SDL::Surface's clip_rect. See SDL::Video::get_clip_rect and
86       SDL::Video::set_clip_rect.  =head1 EXTENSIONS
87
88   load
89        my $surface = SDLx::Surface->load( 'hero.png' );
90        my $surface = SDLx::Surface->load( 'hero.dat', 'bmp' );
91
92       Loads the given image file into a new SDLx::Surface surface. A new
93       surface is always created, even if you call it from an already crafted
94       object. Croaks on errors such as no support built for that image
95       extension or a file reading error (the error message is SDL::get_error
96       and should give more details).
97
98       Note that load() will automatically figure out the extension based on
99       the filename you provide. If you wish to force an extension for
100       whatever reason (like having a filename with a different extension or
101       none at all), you can optionally pass the file type as a second
102       parameter. Case is not relevant.
103
104       If you don't have SDL_image in your build, only bitmap images will be
105       supported.
106
107       Returns the new Surface.
108
109   blit
110        $sdlx_surface->blit( $dest, $src_rect, $dest_rect );
111
112       Blits "SDLx::Surface" onto $dest surface.  $src_rect or $dest_rect are
113       optional. If $src_rect is omitted, it will be the size of the entire
114       surface. If $dest_rect is omitted, it will be blitted at "(0, 0)".
115       $src_rect or $dest_rect can be array refs or "SDL::Rect". $dest can be
116       "SDLx::Surface" or "SDL::Surface".
117
118       Note that the final blit rectangle is stored in $dest_rect after
119       clipping is performed.
120
121       Returns $self
122
123   blit_by
124        $sdlx_surface->blit_by( $src, $src_rect, $dest_rect );
125
126       Does the same as "blit" but the "SDLx::Surface" is the one being
127       blitted to.  This is useful when the surface you have isn't an
128       "SDLx::Surface", but the surface it is being blitted to is.
129
130       Note that the final blit rectangle is stored in $dest_rect after
131       clipping is performed.
132
133   flip
134       Applies SDL::Video::flip to the Surface, with error checking.
135
136       Returns $self
137
138   update
139        $sdlx_surface->update(); # whole surface is updated
140        $sdlx_surface->update([0,0,1,1]); # only that area (0,0,1,1) is updated
141
142        $sdlx_surface->update( [ SDL::Rect->new(0,0,1,2) ... ]); # defined rects are updated
143
144       Applies SDL::Video::update_rect for no rect or 1 array ref. Applies
145       SDL::Video::update_rects for array of SDL::Rects.
146
147       Returns $self
148
149   draw_rect
150        $sdlx_surface->draw_rect( [$x,$y,$w,$h], 0xFFFF00FF );
151        $sdlx_surface->draw_rect( SDL::Rect->new($x,$y,$w,$h), 0xFFFF00FF );
152
153       Draws a rect on the surface with the given color. If the rect is
154       omitted, the colored rect will be drawn to the entire surface.
155
156       Returns $self
157
158   draw_line
159        $sdlx_surface->draw_line( [$x1, $y1], [$x2, $y2], $color, $antialias); # $color is a number
160        $sdlx_surface->draw_line( [$x1, $y1], [$x2, $y2], \@color, $antialias); #
161
162       Draws a line on the surface. Antialias is turned on if $antialias is
163       true.
164
165       Returns $self
166
167   draw_circle
168        $sdlx_surface->draw_circle( [$x1, $y1], $radius, \@color, $antialias );
169
170       Draws an unfilled circle at "($x1,$y1)" of size $radius and $color.
171       Antialias is turned on if $antialias is true.  Returns $self
172
173   draw_circle_filled
174        $sdlx_surface->draw_circle_filled( [$x1, $y1], $radius, \@color );
175
176       Draws an filled circle at "($x1,$y1)" of size $radius and $color.
177       Antialias is turned on automatically.  Returns $self
178
179   draw_trigon
180        $sdlx_surface->draw_trigon( [ [$x1, $y1], [$x2, $y2], [$x3, y3] ], \@color, $antialias );
181
182       Draws an unfilled trigon (triangle) with vertices "($x1,$y1)",
183       "($x2,$y2)", "($x3,$y3)" and $color.  Antialias is turned on if
184       $antialias is true.  Returns $self
185
186   draw_trigon_filled
187        $sdlx_surface->draw_trigon_filled( [ [$x1, $y1], [$x2, $y2], [$x3, y3] ], \@color );
188
189       Draws an filled trigon (triangle) with vertices "($x1,$y1)",
190       "($x2,$y2)", "($x3,$y3)" and $color.  Antialias is turned on
191       automatically.  Returns $self
192
193   draw_polygon
194        $sdlx_surface->draw_polygon( [ [$x1, $y1], [$x2, $y2], [$x3, y3], ... ], \@color, $antialias );
195
196       Draws an unfilled polygon with vertices "($xN,$yN)" and $color.
197       Antialias is turned on if $antialias is true.  Returns $self
198
199   draw_polygon_filled
200        $sdlx_surface->draw_polygon_filled( [ [$x1, $y1], [$x2, $y2], [$x3, y3], ... ], \@color );
201
202       Draws an filled polygon with vertices "($xN,$yN)" and $color.
203       Antialias is turned on automatically.  Returns $self
204
205   draw_arc
206        $sdlx_surface->draw_arc( [ $x, $y ], $radius, $start, $end, $color );
207
208       Draws an arc around "($x,$y)" with $radius, $start radius, $end radius
209       and $color.
210
211       Returns $self
212
213   draw_ellipse
214        $sdlx_surface->draw_ellipse( [ $x, $y ], $rx, $ry, $color );
215
216       Draws an unfilled ellipse centered at "($x,$y)" with horizontal radius
217       $rx, vertical radius $ry and $color.  Antialias is turned on if
218       $antialias is true.
219
220       Returns $self
221
222   draw_ellipse_filled
223        $sdlx_surface->draw_ellipse_filled( [ $x, $y ], $rx, $ry, $color );
224
225       Draws an filled ellipse centered at "($x,$y)" with horizontal radius
226       $rx, vertical radius $ry and $color.  Antialias is turned on
227       automatically.
228
229       Returns $self
230
231   draw_bezier
232        $sdlx_surface->draw_bezier( [ [$x1, $y1], [$x2, $y2], [$x3, y3], ... ], $s, $color );
233
234       Draws a bezier curve of points "($xN,$yN)" using $s steps for
235       interpolation and $color.  Antialias is turned on automatically.
236
237       Returns $self
238
239   draw_gfx_text
240       Draw text using gfx (not pretty but fast) at give vector, color.
241
242        $surf->draw_gfx_text( [0,0], 0xffffffff, "fooo");
243        $surf->draw_gfx_text( [10,10], [20,20,20,20], "fooo");
244
245       You can also set the gfx font but passing a hash reference as shown
246       below.
247
248        my $f = '';
249        open( my $FH, '<', 'test/data/5x7.fnt');
250        binmode ($FH);
251        read($FH, $f, 4096);
252        close ($FH);
253
254        my $font =  {data=>$f, cw => 5, ch => 7};
255        $surf->draw_gfx_text( [0,0], 0xffffffff, "fooo", $font );
256
257       Returns $self
258

AUTHORS

260       See "AUTHORS" in SDL.
261
262
263
264perl v5.32.1                      2021-01-27                  SDLx::Surface(3)
Impressum