Added set_video_mode at test
[sdlgit/SDL_perl.git] / src / Core / Video.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::Video     PACKAGE = SDL::Video    PREFIX = video_
12
13 =for documentation
14
15 The Following are XS bindings to the Video category in the SDL API v2.1.13
16
17 Describe on the SDL API site.
18
19 See: L<http://www.libsdl.org/cgi/docwiki.cgi/SDL_API#head-813f033ec44914f267f32195aba7d9aff8c410c0>
20
21 =cut
22
23 SDL_Surface *
24 video_get_video_surface()
25         PREINIT:
26                 char* CLASS = "SDL::Surface";
27         CODE:
28                 RETVAL = SDL_GetVideoSurface();
29         OUTPUT:
30                 RETVAL
31
32
33 SDL_VideoInfo*
34 video_get_video_info()
35         PREINIT:
36                 char* CLASS = "SDL::VideoInfo";
37         CODE:
38                 RETVAL = (SDL_VideoInfo *) SDL_GetVideoInfo();
39
40         OUTPUT:
41                 RETVAL
42
43 SV *
44 video_video_driver_name( )
45         
46         CODE:
47                 char buffer[1024];
48                 if ( SDL_VideoDriverName(buffer, 1024) != NULL ) 
49                 { 
50                         RETVAL =  newSVpv(buffer, 0);
51                 } 
52                 else 
53                          XSRETURN_UNDEF;        
54         OUTPUT:
55                 RETVAL
56
57 AV*
58 list_modes ( format, flags )
59         Uint32 flags
60         SDL_PixelFormat *format
61
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
79 int
80 video_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
89
90
91 SDL_Surface *
92 video_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
105 void
106 video_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
115 void
116 video_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
130