Remove update_rect from Surface.xs, enable it in SDL.xs
[sdlgit/SDL_perl.git] / src / Core / objects / Surface.xs
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
11 MODULE = SDL::Surface   PACKAGE = SDL::Surface    PREFIX = surface_
12
13 =for documentation
14
15 SDL_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
31 SDL_Surface *
32 surface_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
48 SDL_PixelFormat *
49 surface_format ( surface )
50         SDL_Surface *surface
51         CODE:
52                 char* CLASS = "SDL::PixelFormat";
53                 RETVAL = surface->format;
54         OUTPUT:
55                 RETVAL
56
57 void
58 surface_update_rects ( surface, ... )
59         SDL_Surface *surface
60         CODE:
61                 SDL_Rect *rects, *temp;
62                 int num_rects,i;
63                 if ( items < 2 ) return;
64                 num_rects = items - 1;
65                         
66                 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
67                 for(i=0;i<num_rects;i++) {
68                         temp = (SDL_Rect *)SvIV(ST(i+1));
69                         rects[i].x = temp->x;
70                         rects[i].y = temp->y;
71                         rects[i].w = temp->w;
72                         rects[i].h = temp->h;
73                 } 
74                 SDL_UpdateRects(surface,num_rects,rects);
75                 safefree(rects);
76
77 SDL_Surface *
78 surface_display ( surface )
79         SDL_Surface *surface
80         CODE:
81                 char* CLASS = "SDL::Surface";
82                 RETVAL = SDL_DisplayFormat(surface);
83         OUTPUT:
84                 RETVAL
85
86 SDL_Surface *
87 surface_display_alpha ( surface )
88         SDL_Surface *surface
89         CODE:
90                 char* CLASS = "SDL::Surface";
91                 RETVAL = SDL_DisplayFormatAlpha(surface);
92         OUTPUT:
93                 RETVAL
94
95 Uint16
96 surface_pitch( surface )
97         SDL_Surface *surface
98         CODE:
99                 RETVAL = surface->pitch;
100         OUTPUT:
101                 RETVAL
102
103 Uint16
104 surface_w ( surface )
105         SDL_Surface *surface
106         CODE:
107                 RETVAL = surface->w;
108         OUTPUT:
109                 RETVAL
110
111 Uint16
112 surface_h ( surface )
113         SDL_Surface *surface
114         CODE:
115                 RETVAL = surface->h;
116         OUTPUT:
117                 RETVAL
118
119 IV
120 surface_get_pixels(surface)
121         SDL_Surface *surface
122         CODE:
123           if(!surface->pixels) croak("Incomplete surface");
124           RETVAL = PTR2IV(surface->pixels);
125         OUTPUT:
126           RETVAL
127
128 void
129 surface_set_pixels(surface, pixels)
130         SDL_Surface *surface
131
132         SV *pixels
133
134         PREINIT:
135           STRLEN len;
136           void *p;
137
138         CODE:
139           p = SvPV(pixels, len);
140           if (len > surface->pitch*surface->h)
141                 len = surface->pitch*surface->h;
142           memcpy(surface->pixels, p, len);
143
144 void
145 surface_DESTROY(surface)
146         SDL_Surface *surface
147         CODE:
148                 Uint8* pixels = surface->pixels;
149                 Uint32 flags = surface->flags;
150                 SDL_FreeSurface(surface);
151                 if (flags & SDL_PREALLOC)
152                         Safefree(pixels);