Commit | Line | Data |
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 | |
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 | |
49 | SDL_Surface * |
50 | surface_load (CLASS, filename ) |
51 | char* CLASS |
52 | char* filename |
53 | CODE: |
54 | RETVAL = IMG_Load(filename); |
55 | OUTPUT: |
56 | RETVAL |
57 | |
58 | int |
59 | surface_blit ( src, src_rect, dest, dest_rect ) |
60 | SDL_Surface *src |
61 | SDL_Surface *dest |
62 | SDL_Rect *src_rect |
63 | SDL_Rect *dest_rect |
64 | CODE: |
65 | RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect); |
66 | OUTPUT: |
67 | RETVAL |
68 | |
69 | int |
70 | surface_fill_rect ( dest, dest_rect, color ) |
71 | SDL_Surface *dest |
72 | SDL_Color *color |
73 | SDL_Rect *dest_rect |
74 | CODE: |
75 | Uint32 pixel = SDL_MapRGB(dest->format,color->r,color->g,color->b); |
76 | RETVAL = SDL_FillRect(dest,dest_rect,pixel); |
77 | OUTPUT: |
78 | RETVAL |
79 | |
80 | void |
81 | surface_update_rect ( surface, x, y, w ,h ) |
82 | SDL_Surface *surface |
83 | int x |
84 | int y |
85 | int w |
86 | int h |
87 | CODE: |
88 | SDL_UpdateRect(surface,x,y,w,h); |
89 | |
90 | void |
91 | surface_update_rects ( surface, ... ) |
92 | SDL_Surface *surface |
93 | CODE: |
94 | SDL_Rect *rects, *temp; |
95 | int num_rects,i; |
96 | if ( items < 2 ) return; |
97 | num_rects = items - 1; |
98 | |
99 | rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items); |
100 | for(i=0;i<num_rects;i++) { |
101 | temp = (SDL_Rect *)SvIV(ST(i+1)); |
102 | rects[i].x = temp->x; |
103 | rects[i].y = temp->y; |
104 | rects[i].w = temp->w; |
105 | rects[i].h = temp->h; |
106 | } |
107 | SDL_UpdateRects(surface,num_rects,rects); |
108 | safefree(rects); |
109 | |
110 | SDL_Surface * |
111 | surface_display ( surface ) |
112 | SDL_Surface *surface |
113 | CODE: |
114 | char* CLASS = 'SDL::Surface\0'; |
115 | RETVAL = SDL_DisplayFormat(surface); |
116 | OUTPUT: |
117 | RETVAL |
118 | |
119 | Uint16 |
120 | surface_w ( surface ) |
121 | SDL_Surface *surface |
122 | CODE: |
123 | RETVAL = surface->w; |
124 | OUTPUT: |
125 | RETVAL |
126 | |
127 | Uint16 |
128 | surface_h ( surface ) |
129 | SDL_Surface *surface |
130 | CODE: |
131 | RETVAL = surface->h; |
132 | OUTPUT: |
133 | RETVAL |
134 | |
135 | void |
136 | surface_DESTROY(surface) |
137 | SDL_Surface *surface |
138 | CODE: |
139 | Uint8* pixels = surface->pixels; |
140 | Uint32 flags = surface->flags; |
141 | SDL_FreeSurface(surface); |
142 | if (flags & SDL_PREALLOC) |
143 | Safefree(pixels); |