Added test files for SDL::Events.pm
[sdlgit/SDL_perl.git] / src / Core / Video.xs
CommitLineData
70fd0f8d 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::Video PACKAGE = SDL::Video PREFIX = video_
12
13=for documentation
14
15The Following are XS bindings to the Video category in the SDL API v2.1.13
16
17Describe on the SDL API site.
18
19See: L<http://www.libsdl.org/cgi/docwiki.cgi/SDL_API#head-813f033ec44914f267f32195aba7d9aff8c410c0>
20
21=cut
22
23SDL_Surface *
95f5be30 24video_get_video_surface()
25 PREINIT:
26 char* CLASS = "SDL::Surface";
70fd0f8d 27 CODE:
28 RETVAL = SDL_GetVideoSurface();
29 OUTPUT:
30 RETVAL
31
32
20f544ea 33SDL_VideoInfo*
95f5be30 34video_get_video_info()
20f544ea 35 PREINIT:
36 char* CLASS = "SDL::VideoInfo";
95f5be30 37 CODE:
babb07ed 38 RETVAL = (SDL_VideoInfo *) SDL_GetVideoInfo();
8a2411d0 39
40 OUTPUT:
babb07ed 41 RETVAL
8a2411d0 42
7fa192d4 43SV *
44video_video_driver_name( )
45
8a2411d0 46 CODE:
7fa192d4 47 char buffer[1024];
48 if ( SDL_VideoDriverName(buffer, 1024) != NULL )
49 {
50 RETVAL = newSVpv(buffer, 0);
51 }
52 else
53 XSRETURN_UNDEF;
8a2411d0 54 OUTPUT:
55 RETVAL
7dda1934 56
57AV*
58list_modes ( format, flags )
59 Uint32 flags
60 SDL_PixelFormat *format
4510df28 61
7dda1934 62 CODE:
63 SDL_Rect **mode;
64 RETVAL = newAV();
65 mode = SDL_ListModes(format,flags);
66 if (mode == (SDL_Rect**)-1 ) {
67 av_push(RETVAL,newSVpv("all",0));
68 } else if (! mode ) {
69 av_push(RETVAL,newSVpv("none",0));
70 } else {
71 for (;*mode;mode++) {
72 av_push(RETVAL,newSViv(PTR2IV(*mode)));
73 }
74 }
75 OUTPUT:
76 RETVAL
77
78
218b5471 79int
80video_video_mode_ok ( width, height, bpp, flags )
81 int width
82 int height
83 int bpp
84 Uint32 flags
85 CODE:
86 RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
87 OUTPUT:
88 RETVAL
7dda1934 89
bbe5d2f5 90
91SDL_Surface *
92video_set_video_mode ( width, height, bpp, flags )
93 int width
94 int height
95 int bpp
96 Uint32 flags
97 PREINIT:
98 char* CLASS = "SDL::Surface";
99 CODE:
100 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
101 OUTPUT:
102 RETVAL
103
104
eaf32d63 105void
106video_update_rect ( surface, x, y, w ,h )
107 SDL_Surface *surface
108 int x
109 int y
110 int w
111 int h
112 CODE:
113 SDL_UpdateRect(surface,x,y,w,h);
114
115void
116video_update_rects ( surface, ... )
117 SDL_Surface *surface
118 CODE:
119 SDL_Rect *rects;
120 int num_rects,i;
121 if ( items < 2 ) return;
122 num_rects = items - 1;
123 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
124 for(i=0;i<num_rects;i++) {
125 rects[i] = *(SDL_Rect *)SvIV((SV*)SvRV( ST(i + 1) ));
126 }
127 SDL_UpdateRects(surface,num_rects,rects);
128 safefree(rects);
129
7dda1934 130
19f3ee7b 131int
132video_flip ( surface )
133 SDL_Surface *surface
134 CODE:
135 RETVAL = SDL_Flip(surface);
136 OUTPUT:
137 RETVAL
138
2739f940 139int
140video_set_colors ( surface, start, ... )
141 SDL_Surface *surface
142 int start
143 CODE:
144 SDL_Color *colors,*temp;
145 int i, length;
69341787 146 if ( items < 3 ) { RETVAL = 0;}
147 else
148 {
2739f940 149 length = items - 2;
150 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
151 for ( i = 0; i < length ; i++ ) {
152 temp = (SDL_Color *)SvIV(ST(i+2));
153 colors[i].r = temp->r;
154 colors[i].g = temp->g;
155 colors[i].b = temp->b;
156 }
157 RETVAL = SDL_SetColors(surface, colors, start, length );
158 safefree(colors);
69341787 159 }
2739f940 160
2739f940 161 OUTPUT:
162 RETVAL
0a01cb9e 163
69341787 164int
165video_set_palette ( surface, flags, start, ... )
166 SDL_Surface *surface
167 int flags
168 int start
169
170 CODE:
171 SDL_Color *colors,*temp;
172 int i, length;
173 if ( items < 4 ) {
174 RETVAL = 0;
175 }
176 else
177 {
178 length = items - 3;
179 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
180 for ( i = 0; i < length ; i++ ){
181 temp = (SDL_Color *)SvIV(ST(i+3));
182 colors[i].r = temp->r;
183 colors[i].g = temp->g;
184 colors[i].b = temp->b;
185 }
186 RETVAL = SDL_SetPalette(surface, flags, colors, start, length );
187 safefree(colors);
188 }
189 OUTPUT:
190 RETVAL
0a01cb9e 191