Move blit out of Surface.xs, enable BlitSurface
[sdlgit/SDL_perl.git] / src / Core / objects / Surface.xs
CommitLineData
88a46efc 1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4
5#ifndef aTHX_
6#define aTHX_
7#endif
8
9#include <SDL.h>
10
11MODULE = SDL::Surface PACKAGE = SDL::Surface PREFIX = surface_
12
13=for documentation
14
15SDL_Surface -- Graphic surface structure
16
17 typedef struct SDL_Surface {
18 Uint32 flags; /* Read-only */
19 SDL_PixelFormat *format; /* Read-only */
20 int w, h; /* Read-only */
21 Uint16 pitch; /* Read-only */
22 void *pixels; /* Read-write */
23 SDL_Rect clip_rect; /* Read-only */
24 int refcount; /* Read-mostly */
25
26 /* This structure also contains private fields not shown here */
27 } SDL_Surface;
28
29=cut
30
31SDL_Surface *
32surface_new (CLASS, flags, width, height, depth, Rmask, Gmask, Bmask, Amask )
33 char* CLASS
34 Uint32 flags
35 int width
36 int height
37 int depth
38 Uint32 Rmask
39 Uint32 Gmask
40 Uint32 Bmask
41 Uint32 Amask
42 CODE:
43 RETVAL = SDL_CreateRGBSurface ( flags, width, height,
44 depth, Rmask, Gmask, Bmask, Amask );
45 OUTPUT:
46 RETVAL
47
88a46efc 48int
88a46efc 49surface_fill_rect ( dest, dest_rect, color )
50 SDL_Surface *dest
51 SDL_Color *color
52 SDL_Rect *dest_rect
53 CODE:
54 Uint32 pixel = SDL_MapRGB(dest->format,color->r,color->g,color->b);
55 RETVAL = SDL_FillRect(dest,dest_rect,pixel);
56 OUTPUT:
57 RETVAL
58
59void
60surface_update_rect ( surface, x, y, w ,h )
61 SDL_Surface *surface
62 int x
63 int y
64 int w
65 int h
66 CODE:
67 SDL_UpdateRect(surface,x,y,w,h);
68
69void
70surface_update_rects ( surface, ... )
71 SDL_Surface *surface
72 CODE:
73 SDL_Rect *rects, *temp;
74 int num_rects,i;
75 if ( items < 2 ) return;
76 num_rects = items - 1;
77
78 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
79 for(i=0;i<num_rects;i++) {
80 temp = (SDL_Rect *)SvIV(ST(i+1));
81 rects[i].x = temp->x;
82 rects[i].y = temp->y;
83 rects[i].w = temp->w;
84 rects[i].h = temp->h;
85 }
86 SDL_UpdateRects(surface,num_rects,rects);
87 safefree(rects);
88
89SDL_Surface *
90surface_display ( surface )
91 SDL_Surface *surface
92 CODE:
41a5a9ee 93 char* CLASS = "SDL::Surface";
88a46efc 94 RETVAL = SDL_DisplayFormat(surface);
95 OUTPUT:
96 RETVAL
97
41a5a9ee 98SDL_Surface *
99surface_display_alpha ( surface )
100 SDL_Surface *surface
101 CODE:
102 char* CLASS = "SDL::Surface";
103 RETVAL = SDL_DisplayFormatAlpha(surface);
104 OUTPUT:
105 RETVAL
106
88a46efc 107Uint16
18ef5a29 108surface_pitch( surface )
109 SDL_Surface *surface
110 CODE:
111 RETVAL = surface->pitch;
112 OUTPUT:
113 RETVAL
114
115Uint16
88a46efc 116surface_w ( surface )
117 SDL_Surface *surface
118 CODE:
119 RETVAL = surface->w;
120 OUTPUT:
121 RETVAL
122
123Uint16
124surface_h ( surface )
125 SDL_Surface *surface
126 CODE:
127 RETVAL = surface->h;
128 OUTPUT:
129 RETVAL
130
18ef5a29 131IV
132surface_get_pixels(surface)
133 SDL_Surface *surface
134 CODE:
b7ed9095 135 if(!surface->pixels) croak("Incomplete surface");
793e8806 136 RETVAL = PTR2IV(surface->pixels);
18ef5a29 137 OUTPUT:
793e8806 138 RETVAL
18ef5a29 139
140void
141surface_set_pixels(surface, pixels)
142 SDL_Surface *surface
143
144 SV *pixels
145
146 PREINIT:
147 STRLEN len;
148 void *p;
149
150 CODE:
151 p = SvPV(pixels, len);
152 if (len > surface->pitch*surface->h)
153 len = surface->pitch*surface->h;
154 memcpy(surface->pixels, p, len);
155
88a46efc 156void
157surface_DESTROY(surface)
158 SDL_Surface *surface
159 CODE:
160 Uint8* pixels = surface->pixels;
161 Uint32 flags = surface->flags;
162 SDL_FreeSurface(surface);
163 if (flags & SDL_PREALLOC)
164 Safefree(pixels);