Mare Overlay an object with new and DESTROY. Bootstrapper made to
[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 Uint16
58 surface_pitch( surface )
59         SDL_Surface *surface
60         CODE:
61                 RETVAL = surface->pitch;
62         OUTPUT:
63                 RETVAL
64
65 Uint16
66 surface_w ( surface )
67         SDL_Surface *surface
68         CODE:
69                 RETVAL = surface->w;
70         OUTPUT:
71                 RETVAL
72
73 Uint16
74 surface_h ( surface )
75         SDL_Surface *surface
76         CODE:
77                 RETVAL = surface->h;
78         OUTPUT:
79                 RETVAL
80
81 IV
82 surface_get_pixels(surface)
83         SDL_Surface *surface
84         CODE:
85           if(!surface->pixels) croak("Incomplete surface");
86           RETVAL = PTR2IV(surface->pixels);
87         OUTPUT:
88           RETVAL
89
90 void
91 surface_set_pixels(surface, pixels)
92         SDL_Surface *surface
93
94         SV *pixels
95
96         PREINIT:
97           STRLEN len;
98           void *p;
99
100         CODE:
101           p = SvPV(pixels, len);
102           if (len > surface->pitch*surface->h)
103                 len = surface->pitch*surface->h;
104           memcpy(surface->pixels, p, len);
105
106 void
107 surface_DESTROY(surface)
108         SDL_Surface *surface
109         CODE:
110                 Uint8* pixels = surface->pixels;
111                 Uint32 flags = surface->flags;
112                 SDL_FreeSurface(surface);
113                 if (flags & SDL_PREALLOC)
114                         Safefree(pixels);