Fixed test. But the returned value for the fuction SDL::TTFSizeUTF8 seems weird
[sdlgit/SDL_perl.git] / src / SDL.xs
1 //
2 // SDL.xs
3 //
4 // Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
5 //
6 // ------------------------------------------------------------------------------
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // 
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // Lesser General Public License for more details.
17 // 
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 //
22 // ------------------------------------------------------------------------------
23 //
24 // Please feel free to send questions, suggestions or improvements to:
25 //
26 //      David J. Goehrig
27 //      dgoehrig@cpan.org
28 //
29
30 #include "EXTERN.h"
31 #include "perl.h"
32 #include "XSUB.h"
33
34 #ifndef aTHX_
35 #define aTHX_
36 #endif
37
38 #include <SDL.h>
39
40 #ifdef HAVE_GL
41 #include <gl.h>
42 #endif
43
44 #ifdef HAVE_GLU
45 #include <glu.h>
46 #endif
47
48 #ifdef HAVE_SDL_IMAGE
49 #include <SDL_image.h>
50 #endif 
51
52 #ifdef HAVE_SDL_MIXER
53 #include <SDL_mixer.h>
54 void (*mix_music_finished_cv)();
55 #endif
56
57 #ifdef HAVE_SDL_SOUND
58 #include <SDL_sound.h>
59 #endif
60
61 #ifdef HAVE_SDL_NET
62 #include <SDL_net.h>
63 #endif
64
65 #ifdef HAVE_SDL_TTF
66 #include <SDL_ttf.h>
67 #define TEXT_SOLID      1
68 #define TEXT_SHADED     2
69 #define TEXT_BLENDED    4
70 #define UTF8_SOLID      8
71 #define UTF8_SHADED     16      
72 #define UTF8_BLENDED    32
73 #define UNICODE_SOLID   64
74 #define UNICODE_SHADED  128
75 #define UNICODE_BLENDED 256
76 #endif
77
78 #ifdef HAVE_SMPEG
79 #include <smpeg/smpeg.h>
80 #ifdef HAVE_SDL_MIXER
81 static int sdl_perl_use_smpeg_audio = 0;
82 #endif
83 #endif
84
85 #ifdef HAVE_SDL_GFX
86 #include <SDL_rotozoom.h>
87 #include <SDL_gfxPrimitives.h>
88 #include <SDL_framerate.h>
89 #include <SDL_imageFilter.h>
90 #endif
91
92 #ifdef HAVE_SDL_SVG
93 #include <SDL_svg.h>
94 #endif
95
96 #ifdef USE_THREADS
97 #define HAVE_TLS_CONTEXT
98 #endif
99
100 /* For windows  */
101 #ifndef SDL_PERL_DEFINES_H
102 #define SDL_PERL_DEFINES_H
103
104 #ifdef HAVE_TLS_CONTEXT
105 PerlInterpreter *parent_perl = NULL;
106 extern PerlInterpreter *parent_perl;
107 #define GET_TLS_CONTEXT parent_perl =  PERL_GET_CONTEXT;
108 #define ENTER_TLS_CONTEXT \
109         PerlInterpreter *current_perl = PERL_GET_CONTEXT; \
110                 PERL_SET_CONTEXT(parent_perl); { \
111                                         PerlInterpreter *my_perl = parent_perl;
112 #define LEAVE_TLS_CONTEXT \
113                                                 } PERL_SET_CONTEXT(current_perl);
114 #else
115 #define GET_TLS_CONTEXT         /* TLS context not enabled */
116 #define ENTER_TLS_CONTEXT       /* TLS context not enabled */
117 #define LEAVE_TLS_CONTEXT       /* TLS context not enabled */
118 #endif
119
120 #endif
121
122 Uint32 
123 sdl_perl_timer_callback ( Uint32 interval, void* param )
124 {
125         Uint32 retval;
126         int back;
127         SV* cmd;
128         ENTER_TLS_CONTEXT
129         dSP;
130
131         cmd = (SV*)param;
132
133         ENTER;
134         SAVETMPS;
135         PUSHMARK(SP);
136         XPUSHs(sv_2mortal(newSViv(interval)));
137         PUTBACK;
138
139         if (0 != (back = call_sv(cmd,G_SCALAR))) {
140                 SPAGAIN;
141                 if (back != 1 ) Perl_croak (aTHX_ "Timer Callback failed!");
142                 retval = POPi;  
143         } else {
144                 Perl_croak(aTHX_ "Timer Callback failed!");
145         }
146
147         FREETMPS;
148         LEAVE;
149
150         LEAVE_TLS_CONTEXT
151         
152         return retval;
153 }
154
155 void
156 sdl_perl_audio_callback ( void* data, Uint8 *stream, int len )
157 {
158         SV *cmd;
159         ENTER_TLS_CONTEXT
160         dSP;
161
162         cmd = (SV*)data;
163
164         ENTER;
165         SAVETMPS;
166         PUSHMARK(SP);
167         XPUSHs(sv_2mortal(newSViv(PTR2IV(stream))));
168         XPUSHs(sv_2mortal(newSViv(len)));
169         PUTBACK;
170
171         call_sv(cmd,G_VOID|G_DISCARD);
172         
173         PUTBACK;
174         FREETMPS;
175         LEAVE;
176
177         LEAVE_TLS_CONTEXT       
178 }
179
180 #ifdef HAVE_SDL_MIXER
181
182 void
183 sdl_perl_music_callback ( void ) 
184 {
185         SV *cmd;
186         ENTER_TLS_CONTEXT
187         dSP;
188
189         cmd = (SV*)Mix_GetMusicHookData();
190
191         ENTER;
192         SAVETMPS;
193         PUSHMARK(SP);
194         PUTBACK;
195         
196         call_sv(cmd,G_VOID|G_DISCARD);
197
198         PUTBACK;
199         FREETMPS;
200         LEAVE;
201
202         LEAVE_TLS_CONTEXT
203 }
204
205 void
206 sdl_perl_music_finished_callback ( void )
207 {
208         SV *cmd;
209         ENTER_TLS_CONTEXT
210         dSP;
211
212         cmd = (SV*)mix_music_finished_cv;
213         if ( cmd == NULL ) return;
214
215         ENTER;
216         SAVETMPS;
217         PUSHMARK(SP);
218         PUTBACK;
219         
220         call_sv(cmd,G_VOID|G_DISCARD);
221         
222         PUTBACK;
223         FREETMPS;
224         LEAVE;
225
226         LEAVE_TLS_CONTEXT
227 }
228
229 #endif
230
231 #define INIT_NS_APPLICATION
232 #define QUIT_NS_APPLICATION
233
234
235 void
236 sdl_perl_atexit (void)
237 {
238         QUIT_NS_APPLICATION     
239         SDL_Quit();
240 }
241
242 void boot_SDL();
243 void boot_SDL__OpenGL();
244
245 XS(boot_SDL_perl)
246 {
247         GET_TLS_CONTEXT
248         boot_SDL();
249 }
250
251 MODULE = SDL_perl       PACKAGE = SDL
252 PROTOTYPES : DISABLE
253
254 char *
255 GetError ()
256         CODE:
257                 RETVAL = SDL_GetError();
258         OUTPUT:
259                 RETVAL
260
261 int
262 Init ( flags )
263         Uint32 flags
264         CODE:
265                 INIT_NS_APPLICATION
266                 RETVAL = SDL_Init(flags);
267 #ifdef HAVE_TLS_CONTEXT
268                 Perl_call_atexit(PERL_GET_CONTEXT, (void*)sdl_perl_atexit,0);
269 #else
270                 atexit(sdl_perl_atexit);
271 #endif
272         OUTPUT:
273                 RETVAL
274
275 int
276 InitSubSystem ( flags )
277         Uint32 flags
278         CODE:
279                 RETVAL = SDL_InitSubSystem(flags);
280         OUTPUT:
281                 RETVAL
282
283 void
284 QuitSubSystem ( flags )
285         Uint32 flags
286         CODE:
287                 SDL_QuitSubSystem(flags);
288
289 void
290 Quit ()
291         CODE:
292                 QUIT_NS_APPLICATION
293                 SDL_Quit();
294
295 int
296 WasInit ( flags )
297         Uint32 flags
298         CODE:
299                 RETVAL = SDL_WasInit(flags);
300         OUTPUT:
301                 RETVAL
302
303 void
304 Delay ( ms )
305         int ms
306         CODE:
307                 SDL_Delay(ms);
308
309 Uint32
310 GetTicks ()
311         CODE:
312                 RETVAL = SDL_GetTicks();
313         OUTPUT:
314                 RETVAL
315
316 int
317 SetTimer ( interval, callback )
318         Uint32 interval
319         SDL_TimerCallback callback
320         CODE:
321                 RETVAL = SDL_SetTimer(interval,callback);
322         OUTPUT:
323                 RETVAL
324
325 SDL_TimerID
326 AddTimer ( interval, callback, param )
327         Uint32 interval
328         SDL_NewTimerCallback callback
329         void *param
330         CODE:
331                 RETVAL = SDL_AddTimer(interval,callback,param);
332         OUTPUT:
333                 RETVAL
334
335 SDL_NewTimerCallback
336 PerlTimerCallback ()
337         CODE:
338                 RETVAL = sdl_perl_timer_callback;
339         OUTPUT:
340                 RETVAL  
341
342 SDL_TimerID
343 NewTimer ( interval, cmd )
344         Uint32 interval
345         void *cmd
346         CODE:
347                 RETVAL = SDL_AddTimer(interval,sdl_perl_timer_callback,cmd);
348         OUTPUT:
349                 RETVAL
350
351 Uint32
352 RemoveTimer ( id )
353         SDL_TimerID id
354         CODE:
355                 RETVAL = SDL_RemoveTimer(id);
356         OUTPUT:
357                 RETVAL
358
359 SDL_RWops*
360 RWFromFile ( file, mode )
361         char* file
362         char * mode
363         CODE:
364                 RETVAL = SDL_RWFromFile(file,mode);
365         OUTPUT:
366                 RETVAL
367
368 SDL_RWops*
369 RWFromFP ( fp, autoclose )
370         FILE* fp
371         int autoclose
372         CODE:
373                 RETVAL = SDL_RWFromFP(fp,autoclose);
374         OUTPUT:
375                 RETVAL
376
377 SDL_RWops*
378 RWFromMem ( mem, size )
379         char* mem
380         int size
381         CODE:
382                 RETVAL = SDL_RWFromMem((void*)mem,size);
383         OUTPUT:
384                 RETVAL
385
386 SDL_RWops*
387 RWFromConstMem ( mem, size )
388         const char* mem
389         int size
390         CODE:
391                 RETVAL = SDL_RWFromConstMem((const void*)mem,size);
392         OUTPUT:
393                 RETVAL
394
395 SDL_RWops*
396 AllocRW ()
397         CODE:
398                 RETVAL = SDL_AllocRW();
399         OUTPUT:
400                 RETVAL
401
402 void
403 FreeRW ( rw )
404         SDL_RWops* rw
405         CODE:
406                 SDL_FreeRW(rw);
407
408 int
409 RWseek ( rw, off, whence )
410         SDL_RWops* rw
411         int off
412         int whence
413         CODE:
414                 RETVAL = SDL_RWseek(rw,off,whence);
415         OUTPUT:
416                 RETVAL
417
418 int
419 RWtell ( rw )
420         SDL_RWops* rw
421         CODE:
422                 RETVAL = SDL_RWtell(rw);
423         OUTPUT:
424                 RETVAL
425
426 int
427 RWread ( rw, mem, size, n )
428         SDL_RWops* rw
429         char* mem
430         int size
431         int n
432         CODE:
433                 RETVAL = SDL_RWread(rw,mem,size,n);
434         OUTPUT:
435                 RETVAL
436
437 int
438 RWwrite ( rw, mem, size, n )
439         SDL_RWops* rw
440         char* mem
441         int size
442         int n
443         CODE:
444                 RETVAL = SDL_RWwrite(rw,mem,size,n);
445         OUTPUT:
446                 RETVAL
447
448 int
449 RWclose ( rw )
450         SDL_RWops* rw
451         CODE:
452                 RETVAL = SDL_RWclose(rw);
453         OUTPUT:
454                 RETVAL
455
456 int
457 CDNumDrives ()
458         CODE:
459                 RETVAL = SDL_CDNumDrives();
460         OUTPUT:
461                 RETVAL
462
463 char *
464 CDName ( drive )
465         int drive
466         CODE:
467                 RETVAL = strdup(SDL_CDName(drive));
468         OUTPUT:
469                 RETVAL
470
471 SDL_CD *
472 CDOpen ( drive )
473         int drive
474         CODE:
475                 RETVAL = SDL_CDOpen(drive);
476         OUTPUT:
477                 RETVAL
478
479 Uint8
480 CDTrackId ( track )
481         SDL_CDtrack *track
482         CODE:
483                 RETVAL = track->id;
484         OUTPUT:
485                 RETVAL
486
487 Uint8
488 CDTrackType ( track )
489         SDL_CDtrack *track
490         CODE:
491                 RETVAL = track->type;
492         OUTPUT:
493                 RETVAL
494
495 Uint16
496 CDTrackLength ( track )
497         SDL_CDtrack *track
498         CODE:
499                 RETVAL = track->length;
500         OUTPUT:
501                 RETVAL
502
503 Uint32
504 CDTrackOffset ( track )
505         SDL_CDtrack *track
506         CODE:
507                 RETVAL = track->offset;
508         OUTPUT: 
509                 RETVAL
510
511 Uint32
512 CDStatus ( cd )
513         SDL_CD *cd 
514         CODE:
515                 RETVAL = SDL_CDStatus(cd);
516         OUTPUT:
517                 RETVAL
518
519 int
520 CDPlayTracks ( cd, start_track, ntracks, start_frame, nframes )
521         SDL_CD *cd
522         int start_track
523         int ntracks
524         int start_frame
525         int nframes
526         CODE:
527                 RETVAL = SDL_CDPlayTracks(cd,start_track,start_frame,ntracks,nframes);
528         OUTPUT:
529                 RETVAL
530
531 int
532 CDPlay ( cd, start, length )
533         SDL_CD *cd
534         int start
535         int length
536         CODE:
537                 RETVAL = SDL_CDPlay(cd,start,length);
538         OUTPUT:
539                 RETVAL
540
541 int
542 CDPause ( cd )
543         SDL_CD *cd
544         CODE:
545                 RETVAL = SDL_CDPause(cd);
546         OUTPUT:
547                 RETVAL
548
549 int
550 CDResume ( cd )
551         SDL_CD *cd
552         CODE:
553                 RETVAL = SDL_CDResume(cd);
554         OUTPUT:
555                 RETVAL
556
557 int
558 CDStop ( cd )
559         SDL_CD *cd
560         CODE:
561                 RETVAL = SDL_CDStop(cd);
562         OUTPUT:
563                 RETVAL
564
565 int
566 CDEject ( cd )
567         SDL_CD *cd
568         CODE:
569                 RETVAL = SDL_CDEject(cd);
570         OUTPUT:
571                 RETVAL
572
573 void
574 CDClose ( cd )
575         SDL_CD *cd
576         CODE:
577                 SDL_CDClose(cd);
578         
579 int
580 CDId ( cd )
581         SDL_CD *cd
582         CODE:
583                 RETVAL = cd->id;
584         OUTPUT: 
585                 RETVAL
586
587 int
588 CDNumTracks ( cd )
589         SDL_CD *cd
590         CODE:
591                 RETVAL = cd->numtracks;
592         OUTPUT:
593                 RETVAL
594
595 int
596 CDCurTrack ( cd )
597         SDL_CD *cd
598         CODE:
599                 RETVAL = cd->cur_track;
600         OUTPUT:
601                 RETVAL
602
603 int
604 CDCurFrame ( cd )
605         SDL_CD *cd
606         CODE:
607                 RETVAL = cd->cur_frame;
608         OUTPUT:
609                 RETVAL
610
611 SDL_CDtrack *
612 CDTrack ( cd, number )
613         SDL_CD *cd
614         int number
615         CODE:
616                 RETVAL = (SDL_CDtrack *)(cd->track + number);
617         OUTPUT:
618                 RETVAL
619
620 void
621 PumpEvents ()
622         CODE:
623                 SDL_PumpEvents();
624
625 int
626 PushEvent( e )
627         SDL_Event *e
628         CODE:
629                 RETVAL = SDL_PushEvent( e );
630         OUTPUT:
631                 RETVAL
632
633 SDL_Event *
634 NewEvent ()
635         CODE:   
636                 RETVAL = (SDL_Event *) safemalloc (sizeof(SDL_Event));
637         OUTPUT:
638                 RETVAL
639
640 void
641 FreeEvent ( e )
642         SDL_Event *e
643         CODE:
644                 safefree(e);
645
646 int
647 PollEvent ( e )
648         SDL_Event *e
649         CODE:
650                 RETVAL = SDL_PollEvent(e);
651         OUTPUT:
652                 RETVAL
653
654 int
655 WaitEvent ( e )
656         SDL_Event *e
657         CODE:
658                 RETVAL = SDL_WaitEvent(e);
659         OUTPUT:
660                 RETVAL
661
662 Uint8
663 EventState ( type, state )
664         Uint8 type
665         int state
666         CODE:
667                 RETVAL = SDL_EventState(type,state);
668         OUTPUT:
669                 RETVAL 
670
671 Uint8
672 EventType ( e )
673         SDL_Event *e
674         CODE:
675                 RETVAL = e->type;
676         OUTPUT:
677                 RETVAL
678
679 Uint8
680 SetEventType ( e, type )
681         SDL_Event *e
682         Uint8 type
683         CODE:
684                 RETVAL = e->type;
685                 e->type = type;
686         OUTPUT:
687                 RETVAL
688
689 Uint8
690 ActiveEventGain ( e )
691         SDL_Event *e
692         CODE:
693                 RETVAL = e->active.gain;
694         OUTPUT: 
695                 RETVAL
696
697 Uint8
698 ActiveEventState ( e )
699         SDL_Event *e
700         CODE:
701                 RETVAL = e->active.state;
702         OUTPUT:
703                 RETVAL
704
705 Uint8
706 KeyEventState( e )
707         SDL_Event *e
708         CODE:
709                 RETVAL = e->key.state;
710         OUTPUT:
711                 RETVAL
712
713 int
714 KeyEventSym ( e )
715         SDL_Event *e
716         CODE:
717                 RETVAL = e->key.keysym.sym;
718         OUTPUT:
719                 RETVAL
720
721 int 
722 KeyEventMod ( e )
723         SDL_Event *e
724         CODE:
725                 RETVAL = e->key.keysym.mod;
726         OUTPUT:
727                 RETVAL
728
729 Uint16
730 KeyEventUnicode ( e )
731         SDL_Event *e
732         CODE:
733                 RETVAL = e->key.keysym.unicode;
734         OUTPUT:
735                 RETVAL
736
737 Uint8
738 KeyEventScanCode ( e )
739         SDL_Event *e
740         CODE:
741                 RETVAL = e->key.keysym.scancode;
742         OUTPUT:
743                 RETVAL
744
745 Uint8
746 MouseMotionState ( e )
747         SDL_Event *e
748         CODE:
749                 RETVAL = e->motion.state;
750         OUTPUT: 
751                 RETVAL
752
753 Uint16
754 MouseMotionX ( e )
755         SDL_Event *e
756         CODE:
757                 RETVAL = e->motion.x;
758         OUTPUT:
759                 RETVAL
760
761 Uint16
762 MouseMotionY ( e )
763         SDL_Event *e
764         CODE:
765                 RETVAL = e->motion.y;
766         OUTPUT:
767                 RETVAL
768
769 Sint16
770 MouseMotionXrel( e )
771         SDL_Event *e
772         CODE:
773                 RETVAL = e->motion.xrel;
774         OUTPUT:
775                 RETVAL
776
777 Sint16
778 MouseMotionYrel ( e )
779         SDL_Event *e
780         CODE:
781                 RETVAL = e->motion.yrel;
782         OUTPUT:
783                 RETVAL
784
785 Uint8
786 MouseButtonState ( e )
787         SDL_Event *e
788         CODE:
789                 RETVAL = e->button.state;
790         OUTPUT:
791                 RETVAL
792
793 Uint8
794 MouseButton ( e )
795         SDL_Event *e
796         CODE:
797                 RETVAL = e->button.button;
798         OUTPUT:
799                 RETVAL
800
801 Uint16
802 MouseButtonX ( e )
803         SDL_Event *e
804         CODE:
805                 RETVAL = e->button.x;
806         OUTPUT:
807                 RETVAL
808
809 Uint16
810 MouseButtonY ( e )
811         SDL_Event *e
812         CODE:
813                 RETVAL = e->button.y;
814         OUTPUT:
815                 RETVAL
816
817 SDL_SysWMmsg *
818 SysWMEventMsg ( e )
819         SDL_Event *e
820         CODE:
821                 RETVAL = e->syswm.msg;
822         OUTPUT:
823                 RETVAL
824
825 int
826 EnableUnicode ( enable )
827         int enable
828         CODE:
829                 RETVAL = SDL_EnableUNICODE(enable);
830         OUTPUT:
831                 RETVAL
832
833 void
834 EnableKeyRepeat ( delay, interval )
835         int delay
836         int interval
837         CODE:
838                 SDL_EnableKeyRepeat(delay,interval);
839
840 Uint32
841 GetModState ()
842         CODE:
843                 RETVAL = SDL_GetModState();
844         OUTPUT:
845                 RETVAL
846
847 void
848 SetModState ( state )
849         Uint32 state
850         CODE:
851                 SDL_SetModState(state);
852
853 char *
854 GetKeyName ( sym )
855         int sym
856         CODE:
857                 RETVAL = SDL_GetKeyName(sym);
858         OUTPUT:
859                 RETVAL
860
861 SDL_Surface *
862 CreateRGBSurface (flags, width, height, depth, Rmask, Gmask, Bmask, Amask )
863         Uint32 flags
864         int width
865         int height
866         int depth
867         Uint32 Rmask
868         Uint32 Gmask
869         Uint32 Bmask
870         Uint32 Amask
871         CODE:
872                 RETVAL = SDL_CreateRGBSurface ( flags, width, height,
873                                 depth, Rmask, Gmask, Bmask, Amask );
874         OUTPUT: 
875                 RETVAL
876
877
878 SDL_Surface *
879 CreateRGBSurfaceFrom (pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask )
880         char *pixels
881         int width
882         int height
883         int depth
884         int pitch
885         Uint32 Rmask
886         Uint32 Gmask
887         Uint32 Bmask
888         Uint32 Amask
889         CODE:
890                 Uint8* pixeldata;
891                 Uint32 len = pitch * height;
892                 New(0,pixeldata,len,Uint8);
893                 Copy(pixels,pixeldata,len,Uint8);
894                 RETVAL = SDL_CreateRGBSurfaceFrom ( pixeldata, width, height,
895                                 depth, pitch, Rmask, Gmask, Bmask, Amask );
896         OUTPUT: 
897                 RETVAL
898
899 #ifdef HAVE_SDL_IMAGE
900
901 SDL_Surface *
902 IMGLoad ( fname )
903         char *fname
904         CODE:
905                 RETVAL = IMG_Load(fname);
906         OUTPUT:
907                 RETVAL
908
909 #endif
910
911 SDL_Surface*
912 SurfaceCopy ( surface )
913         SDL_Surface *surface
914         CODE:
915                 Uint8* pixels;
916                 Uint32 size = surface->pitch * surface->h;
917                 New(0,pixels,size,Uint8);
918                 Copy(surface->pixels,pixels,size,Uint8);
919                 RETVAL = SDL_CreateRGBSurfaceFrom(pixels,surface->w,surface->h,
920                         surface->format->BitsPerPixel, surface->pitch,
921                         surface->format->Rmask, surface->format->Gmask,
922                         surface->format->Bmask, surface->format->Amask);
923         OUTPUT:
924                 RETVAL
925
926 void
927 FreeSurface ( surface )
928         SDL_Surface *surface
929         CODE:
930                 if (surface) {
931                         Uint8* pixels = surface->pixels;
932                         Uint32 flags = surface->flags;
933                         SDL_FreeSurface(surface);
934                         if (flags & SDL_PREALLOC)
935                                 Safefree(pixels);
936                 }
937         
938 Uint32
939 SurfaceFlags ( surface )
940         SDL_Surface *surface
941         CODE:
942                 RETVAL = surface->flags;
943         OUTPUT:
944                 RETVAL
945
946 SDL_Palette *
947 SurfacePalette ( surface )
948         SDL_Surface *surface
949         CODE:
950                 RETVAL = surface->format->palette;
951         OUTPUT:
952                 RETVAL
953
954 Uint8
955 SurfaceBitsPerPixel ( surface )
956         SDL_Surface *surface
957         CODE:
958                 RETVAL = surface->format->BitsPerPixel;
959         OUTPUT:
960                 RETVAL
961
962 Uint8
963 SurfaceBytesPerPixel ( surface )
964         SDL_Surface *surface
965         CODE:   
966                 RETVAL = surface->format->BytesPerPixel;
967         OUTPUT:
968                 RETVAL
969
970 Uint8
971 SurfaceRshift ( surface )
972         SDL_Surface *surface
973         CODE:
974                 RETVAL = surface->format->Rshift;
975         OUTPUT:
976                 RETVAL
977
978 Uint8
979 SurfaceGshift ( surface )
980         SDL_Surface *surface
981         CODE:
982                 RETVAL = surface->format->Gshift;
983         OUTPUT:
984                 RETVAL
985
986 Uint8
987 SurfaceBshift ( surface )
988         SDL_Surface *surface
989         CODE:
990                 RETVAL = surface->format->Bshift;
991         OUTPUT:
992                 RETVAL
993
994 Uint8
995 SurfaceAshift ( surface )
996         SDL_Surface *surface
997         CODE:
998                 RETVAL = surface->format->Ashift;
999         OUTPUT:
1000                 RETVAL
1001
1002 Uint32
1003 SurfaceRmask( surface )
1004         SDL_Surface *surface
1005         CODE:
1006                 RETVAL = surface->format->Rmask;
1007         OUTPUT:
1008                 RETVAL
1009
1010 Uint32
1011 SurfaceGmask ( surface )
1012         SDL_Surface *surface
1013         CODE:
1014                 RETVAL = surface->format->Gmask;
1015         OUTPUT:
1016                 RETVAL
1017
1018 Uint32
1019 SurfaceBmask ( surface )
1020         SDL_Surface *surface
1021         CODE:
1022                 RETVAL = surface->format->Bmask;
1023         OUTPUT:
1024                 RETVAL
1025
1026 Uint32
1027 SurfaceAmask ( surface )
1028         SDL_Surface *surface
1029         CODE:
1030                 RETVAL = surface->format->Amask;
1031         OUTPUT:
1032                 RETVAL
1033
1034 Uint32
1035 SurfaceColorKey ( surface )
1036         SDL_Surface *surface
1037         CODE:
1038                 RETVAL = surface->format->colorkey;
1039         OUTPUT:
1040                 RETVAL
1041
1042 Uint32
1043 SurfaceAlpha( surface )
1044         SDL_Surface *surface
1045         CODE:
1046                 RETVAL = surface->format->alpha;
1047         OUTPUT:
1048                 RETVAL
1049
1050 int
1051 SurfaceW ( surface )
1052         SDL_Surface *surface
1053         CODE:   
1054                 RETVAL = surface->w;
1055         OUTPUT:
1056                 RETVAL
1057
1058 int
1059 SurfaceH ( surface )
1060         SDL_Surface *surface
1061         CODE:   
1062                 RETVAL = surface->h;
1063         OUTPUT:
1064                 RETVAL
1065
1066 Uint16
1067 SurfacePitch ( surface )
1068         SDL_Surface *surface
1069         CODE:   
1070                 RETVAL = surface->pitch;
1071         OUTPUT:
1072                 RETVAL
1073
1074 SV*
1075 SurfacePixels ( surface )
1076         SDL_Surface *surface
1077         CODE:   
1078                 RETVAL = newSVpvn(surface->pixels,surface->pitch*surface->h);
1079         OUTPUT:
1080                 RETVAL
1081
1082 SDL_Color*
1083 SurfacePixel ( surface, x, y, ... )
1084         SDL_Surface *surface
1085         Sint32 x
1086         Sint32 y
1087         CODE:
1088                 SDL_Color* color;
1089                 int pix,index;
1090                 Uint8 r,g,b,a;
1091                 int bpp = surface->format->BytesPerPixel;
1092                 Uint8* p = (Uint8*)surface->pixels + bpp*x + surface->pitch*y;
1093                 if ( items < 3 || items > 4 ) 
1094                         Perl_croak(aTHX_ "usage: SDL::SurfacePixel(surface,x,y,[color])");
1095                 if ( items == 4) {
1096                         color = (SDL_Color*)SvIV(ST(3));
1097                         pix = SDL_MapRGB(surface->format,color->r,color->g,color->b);
1098                         switch(bpp) {
1099                                 case 1:
1100                                         *(Uint8*)p = pix;
1101                                         break;
1102                                 case 2:
1103                                         *(Uint16*)p = pix;
1104                                         break;
1105                                 case 3:
1106                                         if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
1107                                                 p[0] = (pix >> 16) & 0xff;
1108                                                 p[1] = (pix >> 8) & 0xff;
1109                                                 p[2] = pix & 0xff;
1110                                         } else {
1111                                                 p[0] = pix & 0xff;
1112                                                 p[1] = (pix >> 8) & 0xff;
1113                                                 p[2] = (pix >> 16) & 0xff;
1114                                         }
1115                                         break;
1116                                 case 4:
1117                                         *(Uint32*)p = pix;
1118                                         break;
1119                         }
1120                 }
1121                 RETVAL = (SDL_Color *) safemalloc(sizeof(SDL_Color));
1122                 switch(bpp) {
1123                         case 1:
1124                                 index = *(Uint8*)p;
1125                                 memcpy(RETVAL,&surface->format->palette[index],sizeof(SDL_Color));
1126                                 break;
1127                         case 2:
1128                                 pix = *(Uint16*)p;
1129                                 SDL_GetRGB(pix,surface->format,&r,&g,&b);
1130                                 RETVAL->r = r;
1131                                 RETVAL->g = g;
1132                                 RETVAL->b = b;
1133                                 break;
1134                         case 3:
1135                         case 4:
1136                                 pix = *(Uint32*)p;
1137                                 SDL_GetRGB(pix,surface->format,&r,&g,&b);
1138                                 RETVAL->r = r;
1139                                 RETVAL->g = g;
1140                                 RETVAL->b = b;
1141                                 break;
1142                 }
1143         OUTPUT:
1144                 RETVAL
1145
1146 int
1147 MUSTLOCK ( surface )
1148         SDL_Surface *surface
1149         CODE:
1150                 RETVAL = SDL_MUSTLOCK(surface);
1151         OUTPUT:
1152                 RETVAL          
1153
1154 int
1155 SurfaceLock ( surface )
1156         SDL_Surface *surface
1157         CODE:
1158                 RETVAL = SDL_LockSurface(surface);
1159         OUTPUT:
1160                 RETVAL
1161
1162 void
1163 SurfaceUnlock ( surface )
1164         SDL_Surface *surface
1165         CODE:
1166                 SDL_UnlockSurface(surface);
1167
1168 SDL_Surface *
1169 GetVideoSurface ()
1170         CODE:
1171                 RETVAL = SDL_GetVideoSurface();
1172         OUTPUT:
1173                 RETVAL
1174
1175
1176 HV *
1177 VideoInfo ()
1178         CODE:
1179                 HV *hv;
1180                 SDL_VideoInfo *info;
1181                 info = (SDL_VideoInfo *) safemalloc ( sizeof(SDL_VideoInfo));
1182                 memcpy(info,SDL_GetVideoInfo(),sizeof(SDL_VideoInfo));
1183                 hv = newHV();
1184                 hv_store(hv,"hw_available",strlen("hw_available"),
1185                         newSViv(info->hw_available),0);
1186                 hv_store(hv,"wm_available",strlen("wm_available"),
1187                         newSViv(info->wm_available),0);
1188                 hv_store(hv,"blit_hw",strlen("blit_hw"),
1189                         newSViv(info->blit_hw),0);
1190                 hv_store(hv,"blit_hw_CC",strlen("blit_hw_CC"),
1191                         newSViv(info->blit_hw_CC),0);
1192                 hv_store(hv,"blit_hw_A",strlen("blit_hw_A"),
1193                         newSViv(info->blit_hw_A),0);
1194                 hv_store(hv,"blit_sw",strlen("blit_sw"),
1195                         newSViv(info->blit_sw),0);
1196                 hv_store(hv,"blit_sw_CC",strlen("blit_sw_CC"),
1197                         newSViv(info->blit_sw_CC),0);
1198                 hv_store(hv,"blit_sw_A",strlen("blit_sw_A"),
1199                         newSViv(info->blit_sw_A),0);
1200                 hv_store(hv,"blit_fill",strlen("blit_fill"),
1201                         newSViv(info->blit_fill),0);
1202                 hv_store(hv,"video_mem",strlen("video_mem"),
1203                         newSViv(info->video_mem),0);
1204                 RETVAL = hv;
1205         OUTPUT:
1206                 RETVAL
1207
1208 SDL_Rect *
1209 NewRect ( x, y, w, h )
1210         Sint16 x
1211         Sint16 y
1212         Uint16 w
1213         Uint16 h
1214         CODE:
1215                 RETVAL = (SDL_Rect *) safemalloc (sizeof(SDL_Rect));
1216                 RETVAL->x = x;
1217                 RETVAL->y = y;
1218                 RETVAL->w = w;
1219                 RETVAL->h = h;
1220         OUTPUT:
1221                 RETVAL
1222
1223 void
1224 FreeRect ( rect )
1225         SDL_Rect *rect
1226         CODE:
1227                 safefree(rect);
1228
1229 Sint16
1230 RectX ( rect, ... )
1231         SDL_Rect *rect
1232         CODE:
1233                 if (items > 1 ) rect->x = SvIV(ST(1)); 
1234                 RETVAL = rect->x;
1235         OUTPUT:
1236                 RETVAL
1237
1238 Sint16
1239 RectY ( rect, ... )
1240         SDL_Rect *rect
1241         CODE:
1242                 if (items > 1 ) rect->y = SvIV(ST(1)); 
1243                 RETVAL = rect->y;
1244         OUTPUT:
1245                 RETVAL
1246
1247 Uint16
1248 RectW ( rect, ... )
1249         SDL_Rect *rect
1250         CODE:
1251                 if (items > 1 ) rect->w = SvIV(ST(1)); 
1252                 RETVAL = rect->w;
1253         OUTPUT:
1254                 RETVAL
1255
1256 Uint16
1257 RectH ( rect, ... )
1258         SDL_Rect *rect
1259         CODE:
1260                 if (items > 1 ) rect->h = SvIV(ST(1)); 
1261                 RETVAL = rect->h;
1262         OUTPUT:
1263                 RETVAL
1264
1265 AV*
1266 ListModes ( format, flags )
1267         Uint32 flags
1268         SDL_PixelFormat *format
1269         CODE:
1270                 SDL_Rect **mode;
1271                 RETVAL = newAV();
1272                 mode = SDL_ListModes(format,flags);
1273                 if (mode == (SDL_Rect**)-1 ) {
1274                         av_push(RETVAL,newSVpv("all",0));
1275                 } else if (! mode ) {
1276                         av_push(RETVAL,newSVpv("none",0));
1277                 } else {
1278                         for (;*mode;mode++) {
1279                                 av_push(RETVAL,newSViv(PTR2IV(*mode)));
1280                         }
1281                 }
1282         OUTPUT:
1283                 RETVAL
1284
1285
1286 SDL_Color *
1287 NewColor ( r, g, b )
1288         Uint8 r
1289         Uint8 g
1290         Uint8 b
1291         CODE:
1292                 RETVAL = (SDL_Color *) safemalloc(sizeof(SDL_Color));
1293                 RETVAL->r = r;
1294                 RETVAL->g = g;
1295                 RETVAL->b = b;
1296         OUTPUT:
1297                 RETVAL
1298
1299 Uint8
1300 ColorR ( color, ... )
1301         SDL_Color *color
1302         CODE:
1303                 if (items > 1 ) color->r = SvIV(ST(1)); 
1304                 RETVAL = color->r;
1305         OUTPUT:
1306                 RETVAL
1307
1308 Uint8
1309 ColorG ( color, ... )
1310         SDL_Color *color
1311         CODE:
1312                 if (items > 1 ) color->g = SvIV(ST(1)); 
1313                 RETVAL = color->g;
1314         OUTPUT:
1315                 RETVAL
1316
1317 Uint8
1318 ColorB ( color, ... )
1319         SDL_Color *color
1320         CODE:
1321                 if (items > 1 ) color->b = SvIV(ST(1)); 
1322                 RETVAL = color->b;
1323         OUTPUT:
1324                 RETVAL
1325
1326
1327 void
1328 ColorRGB ( color, ... )
1329  SDL_Color *color
1330  PPCODE:
1331  if (items > 1 ) {
1332  color->r = SvIV(ST(1));
1333  color->g = SvIV(ST(2));
1334  color->b = SvIV(ST(3));
1335  }
1336  mXPUSHi( color->r );
1337  mXPUSHi( color->g );
1338  mXPUSHi( color->b );
1339  XSRETURN(3);
1340
1341 void
1342 FreeColor ( color )
1343         SDL_Color *color
1344         CODE:
1345                 return; safefree(color);
1346
1347 SDL_Palette *
1348 NewPalette ( number )
1349         int number
1350         CODE:
1351                 RETVAL = (SDL_Palette *)safemalloc(sizeof(SDL_Palette));
1352                 RETVAL->colors = (SDL_Color *)safemalloc(number * 
1353                                                 sizeof(SDL_Color));
1354                 RETVAL->ncolors = number;
1355         OUTPUT:
1356                 RETVAL
1357
1358 int
1359 PaletteNColors ( palette, ... )
1360         SDL_Palette *palette
1361         CODE:
1362                 if ( items > 1 ) palette->ncolors = SvIV(ST(1));
1363                 RETVAL = palette->ncolors;
1364         OUTPUT:
1365                 RETVAL
1366
1367 SDL_Color *
1368 PaletteColors ( palette, index, ... )
1369         SDL_Palette *palette
1370         int index
1371         CODE:
1372                 if ( items > 2 ) {
1373                         palette->colors[index].r = SvUV(ST(2)); 
1374                         palette->colors[index].g = SvUV(ST(3)); 
1375                         palette->colors[index].b = SvUV(ST(4)); 
1376                 }
1377                 RETVAL = (SDL_Color *)(palette->colors + index);
1378         OUTPUT:
1379                 RETVAL
1380
1381 int
1382 VideoModeOK ( width, height, bpp, flags )
1383         int width
1384         int height
1385         int bpp
1386         Uint32 flags
1387         CODE:
1388                 RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
1389         OUTPUT:
1390                 RETVAL
1391
1392 SDL_Surface *
1393 SetVideoMode ( width, height, bpp, flags )
1394         int width
1395         int height
1396         int bpp
1397         Uint32 flags
1398         CODE:
1399                 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
1400         OUTPUT:
1401                 RETVAL
1402
1403 void
1404 UpdateRect ( surface, x, y, w ,h )
1405         SDL_Surface *surface
1406         int x
1407         int y
1408         int w
1409         int h
1410         CODE:
1411                 SDL_UpdateRect(surface,x,y,w,h);
1412
1413 void
1414 UpdateRects ( surface, ... )
1415         SDL_Surface *surface
1416         CODE:
1417                 SDL_Rect *rects, *temp;
1418                 int num_rects,i;
1419                 if ( items < 2 ) return;
1420                 num_rects = items - 1;  
1421                 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
1422                 for(i=0;i<num_rects;i++) {
1423                         temp = (SDL_Rect *)SvIV(ST(i+1));
1424                         rects[i].x = temp->x;
1425                         rects[i].y = temp->y;
1426                         rects[i].w = temp->w;
1427                         rects[i].h = temp->h;
1428                 } 
1429                 SDL_UpdateRects(surface,num_rects,rects);
1430                 safefree(rects);
1431
1432 int
1433 Flip ( surface )
1434         SDL_Surface *surface
1435         CODE:
1436                 RETVAL = SDL_Flip(surface);
1437         OUTPUT:
1438                 RETVAL
1439
1440 int
1441 SetColors ( surface, start, ... )
1442         SDL_Surface *surface
1443         int start
1444         CODE:
1445                 SDL_Color *colors,*temp;
1446                 int i, length;
1447                 if ( items < 3 ) { RETVAL = 0;  goto all_done; }
1448                 length = items - 2;
1449                 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
1450                 for ( i = 0; i < length ; i++ ) {
1451                         temp = (SDL_Color *)SvIV(ST(i+2));
1452                         colors[i].r = temp->r;
1453                         colors[i].g = temp->g;
1454                         colors[i].b = temp->b;
1455                 }
1456                 RETVAL = SDL_SetColors(surface, colors, start, length );
1457                 safefree(colors);
1458 all_done:
1459         OUTPUT: 
1460                 RETVAL
1461
1462 Uint32
1463 MapRGB ( surface, r, g, b )
1464         SDL_Surface *surface
1465         Uint8 r
1466         Uint8 g
1467         Uint8 b
1468         CODE:
1469                 RETVAL = SDL_MapRGB(surface->format,r,g,b);
1470         OUTPUT:
1471                 RETVAL
1472
1473 Uint32
1474 MapRGBA ( surface, r, g, b, a )
1475         SDL_Surface *surface
1476         Uint8 r
1477         Uint8 g
1478         Uint8 b
1479         Uint8 a
1480         CODE:
1481                 RETVAL = SDL_MapRGBA(surface->format,r,g,b,a);
1482         OUTPUT:
1483                 RETVAL
1484
1485 AV *
1486 GetRGB ( surface, pixel )
1487         SDL_Surface *surface
1488         Uint32 pixel
1489         CODE:
1490                 Uint8 r,g,b;
1491                 SDL_GetRGB(pixel,surface->format,&r,&g,&b);
1492                 RETVAL = newAV();
1493                 av_push(RETVAL,newSViv(r));
1494                 av_push(RETVAL,newSViv(g));
1495                 av_push(RETVAL,newSViv(b));
1496         OUTPUT:
1497                 RETVAL
1498
1499 AV *
1500 GetRGBA ( surface, pixel )
1501         SDL_Surface *surface
1502         Uint32 pixel
1503         CODE:
1504                 Uint8 r,g,b,a;
1505                 SDL_GetRGBA(pixel,surface->format,&r,&g,&b,&a);
1506                 RETVAL = newAV();
1507                 av_push(RETVAL,newSViv(r));
1508                 av_push(RETVAL,newSViv(g));
1509                 av_push(RETVAL,newSViv(b));
1510                 av_push(RETVAL,newSViv(a));
1511         OUTPUT:
1512                 RETVAL
1513
1514 int
1515 SaveBMP ( surface, filename )
1516         SDL_Surface *surface
1517         char *filename
1518         CODE:
1519                 RETVAL = SDL_SaveBMP(surface,filename);
1520         OUTPUT:
1521                 RETVAL  
1522
1523 int
1524 SetColorKey ( surface, flag, key )
1525         SDL_Surface *surface
1526         Uint32 flag
1527         SDL_Color *key
1528         CODE:
1529                 Uint32 pixel = SDL_MapRGB(surface->format,key->r,key->g,key->b);
1530                 RETVAL = SDL_SetColorKey(surface,flag,pixel);
1531         OUTPUT:
1532                 RETVAL
1533
1534 int
1535 SetAlpha ( surface, flag, alpha )
1536         SDL_Surface *surface
1537         Uint32 flag
1538         Uint8 alpha
1539         CODE:
1540                 RETVAL = SDL_SetAlpha(surface,flag,alpha);
1541         OUTPUT:
1542                 RETVAL
1543
1544 SDL_Surface *
1545 DisplayFormat ( surface )
1546         SDL_Surface *surface
1547         CODE:
1548                 RETVAL = SDL_DisplayFormat(surface);
1549         OUTPUT:
1550                 RETVAL
1551
1552 SDL_Surface*
1553 DisplayFormatAlpha ( surface )
1554         SDL_Surface *surface
1555         CODE:
1556                 RETVAL = SDL_DisplayFormatAlpha(surface);
1557         OUTPUT:
1558                 RETVAL
1559
1560 SDL_Surface*
1561 ConvertRGB ( surface )
1562         SDL_Surface * surface
1563         CODE:
1564                 SDL_PixelFormat fmt;
1565                 fmt.palette = NULL;
1566                 fmt.BitsPerPixel = 24;
1567                 fmt.BytesPerPixel = 3;
1568                 fmt.Rmask = 0x000000ff;
1569                 fmt.Gmask = 0x0000ff00;
1570                 fmt.Bmask = 0x00ff0000;
1571                 fmt.Amask = 0x00000000;
1572                 fmt.Rloss = 0;
1573                 fmt.Gloss = 0;
1574                 fmt.Bloss = 0;
1575                 fmt.Aloss = 0;
1576                 fmt.Rshift = 0;
1577                 fmt.Gshift = 8;
1578                 fmt.Bshift = 16;
1579                 fmt.Ashift = 24;
1580                 fmt.colorkey = 0;
1581                 fmt.alpha = 0;
1582                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1583         OUTPUT:
1584                 RETVAL
1585
1586 SDL_Surface* 
1587 ConvertRGBA ( surface )
1588         SDL_Surface * surface
1589         CODE:
1590                 SDL_PixelFormat fmt;
1591                 fmt.palette = NULL;
1592                 fmt.BitsPerPixel = 32;
1593                 fmt.BytesPerPixel = 4;
1594                 fmt.Rmask = 0x000000ff;
1595                 fmt.Gmask = 0x0000ff00;
1596                 fmt.Bmask = 0x00ff0000;
1597                 fmt.Amask = 0xff000000;
1598                 fmt.Rloss = 0;
1599                 fmt.Gloss = 0;
1600                 fmt.Bloss = 0;
1601                 fmt.Aloss = 0;
1602                 fmt.Rshift = 0;
1603                 fmt.Gshift = 8;
1604                 fmt.Bshift = 16;
1605                 fmt.Ashift = 24;
1606                 fmt.colorkey = 0;
1607                 fmt.alpha = 0;
1608                 RETVAL = SDL_ConvertSurface(surface,&fmt,surface->flags);
1609         OUTPUT:
1610                 RETVAL
1611
1612 int
1613 BlitSurface ( src, src_rect, dest, dest_rect )
1614         SDL_Surface *src
1615         SDL_Rect *src_rect
1616         SDL_Surface *dest
1617         SDL_Rect *dest_rect
1618         CODE:
1619                 RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect);
1620         OUTPUT:
1621                 RETVAL
1622
1623 int
1624 FillRect ( dest, dest_rect, color )
1625         SDL_Surface *dest
1626         SDL_Rect *dest_rect
1627         SDL_Color *color
1628         CODE:
1629                 Uint32 pixel = SDL_MapRGB(dest->format,color->r,color->g,color->b);
1630                 RETVAL = SDL_FillRect(dest,dest_rect,pixel);
1631         OUTPUT:
1632                 RETVAL
1633
1634 Uint8
1635 GetAppState ()
1636         CODE:
1637                 RETVAL = SDL_GetAppState();
1638         OUTPUT:
1639                 RETVAL
1640
1641
1642 void
1643 WMSetCaption ( title, icon )
1644         char *title
1645         char *icon
1646         CODE:
1647                 SDL_WM_SetCaption(title,icon);
1648
1649 AV *
1650 WMGetCaption ()
1651         CODE:
1652                 char *title,*icon;
1653                 SDL_WM_GetCaption(&title,&icon);
1654                 RETVAL = newAV();
1655                 av_push(RETVAL,newSVpv(title,0));
1656                 av_push(RETVAL,newSVpv(icon,0));
1657         OUTPUT:
1658                 RETVAL
1659
1660 void
1661 WMSetIcon ( icon )
1662         SDL_Surface *icon
1663         CODE:
1664                 SDL_WM_SetIcon(icon,NULL);
1665
1666 void
1667 WarpMouse ( x, y )
1668         Uint16 x
1669         Uint16 y
1670         CODE:
1671                 SDL_WarpMouse(x,y);
1672
1673 AV*
1674 GetMouseState ()
1675         CODE:
1676                 Uint8 mask;
1677                 int x;
1678                 int y;
1679                 mask = SDL_GetMouseState(&x,&y);
1680                 RETVAL = newAV();
1681                 av_push(RETVAL,newSViv(mask));
1682                 av_push(RETVAL,newSViv(x));
1683                 av_push(RETVAL,newSViv(y));
1684         OUTPUT:
1685                 RETVAL  
1686
1687 AV*
1688 GetRelativeMouseState ()
1689         CODE:
1690                 Uint8 mask;
1691                 int x;
1692                 int y;
1693                 mask = SDL_GetRelativeMouseState(&x,&y);
1694                 RETVAL = newAV();
1695                 av_push(RETVAL,newSViv(mask));
1696                 av_push(RETVAL,newSViv(x));
1697                 av_push(RETVAL,newSViv(y));
1698         OUTPUT:
1699                 RETVAL  
1700
1701 SDL_Cursor *
1702 NewCursor ( data, mask, x ,y )
1703         SDL_Surface *data
1704         SDL_Surface *mask
1705         int x
1706         int y
1707         CODE:
1708                 RETVAL = SDL_CreateCursor((Uint8*)data->pixels,
1709                                 (Uint8*)mask->pixels,data->w,data->h,x,y);
1710         OUTPUT:
1711                 RETVAL
1712
1713 void
1714 FreeCursor ( cursor )
1715         SDL_Cursor *cursor
1716         CODE:
1717                 SDL_FreeCursor(cursor);
1718
1719 void
1720 SetCursor ( cursor )
1721         SDL_Cursor *cursor
1722         CODE:
1723                 SDL_SetCursor(cursor);
1724
1725 SDL_Cursor *
1726 GetCursor ()
1727         CODE:
1728                 RETVAL = SDL_GetCursor();
1729         OUTPUT:
1730                 RETVAL
1731
1732 int
1733 ShowCursor ( toggle )
1734         int toggle
1735         CODE:
1736                 RETVAL = SDL_ShowCursor(toggle);
1737         OUTPUT: 
1738                 RETVAL
1739
1740 SDL_AudioSpec *
1741 NewAudioSpec ( freq, format, channels, samples )
1742         int freq
1743         Uint16 format
1744         Uint8 channels
1745         Uint16 samples
1746         CODE:
1747                 RETVAL = (SDL_AudioSpec *)safemalloc(sizeof(SDL_AudioSpec));
1748                 RETVAL->freq = freq;
1749                 RETVAL->format = format;
1750                 RETVAL->channels = channels;
1751                 RETVAL->samples = samples;
1752         OUTPUT:
1753                 RETVAL
1754
1755 void
1756 FreeAudioSpec ( spec )
1757         SDL_AudioSpec *spec
1758         CODE:
1759                 safefree(spec);
1760
1761 SDL_AudioCVT *
1762 NewAudioCVT ( src_format, src_channels, src_rate, dst_format, dst_channels, dst_rate)
1763         Uint16 src_format
1764         Uint8 src_channels
1765         int src_rate
1766         Uint16 dst_format
1767         Uint8 dst_channels
1768         int dst_rate
1769         CODE:
1770                 RETVAL = (SDL_AudioCVT *)safemalloc(sizeof(SDL_AudioCVT));
1771                 if (SDL_BuildAudioCVT(RETVAL,src_format, src_channels, src_rate,
1772                         dst_format, dst_channels, dst_rate)) { 
1773                         safefree(RETVAL); RETVAL = NULL; }
1774         OUTPUT:
1775                 RETVAL
1776
1777 void
1778 FreeAudioCVT ( cvt )
1779         SDL_AudioCVT *cvt
1780         CODE:
1781                 safefree(cvt);
1782
1783 int
1784 ConvertAudioData ( cvt, data, len )
1785         SDL_AudioCVT *cvt
1786         Uint8 *data
1787         int len
1788         CODE:
1789                 cvt->len = len;
1790                 cvt->buf = (Uint8*) safemalloc(cvt->len*cvt->len_mult);
1791                 memcpy(cvt->buf,data,cvt->len);
1792                 RETVAL = SDL_ConvertAudio(cvt);
1793         OUTPUT:
1794                 RETVAL                  
1795
1796 int
1797 OpenAudio ( spec, callback )
1798         SDL_AudioSpec *spec
1799         SV* callback
1800         CODE:
1801                 spec->userdata = (void*)callback;
1802                 spec->callback = sdl_perl_audio_callback;
1803                 RETVAL = SDL_OpenAudio(spec,NULL);
1804         OUTPUT:
1805                 RETVAL
1806
1807 Uint32
1808 GetAudioStatus ()
1809         CODE:
1810                 RETVAL = SDL_GetAudioStatus ();
1811         OUTPUT:
1812                 RETVAL
1813
1814 void
1815 PauseAudio ( p_on )
1816         int p_on
1817         CODE:
1818                 SDL_PauseAudio(p_on);
1819         
1820 void
1821 LockAudio ()
1822         CODE:
1823                 SDL_LockAudio();
1824
1825 void
1826 UnlockAudio ()
1827         CODE:
1828                 SDL_UnlockAudio();
1829
1830 void
1831 CloseAudio ()
1832         CODE:
1833                 SDL_CloseAudio();
1834
1835 void
1836 FreeWAV ( buf )
1837         Uint8 *buf
1838         CODE:
1839                 SDL_FreeWAV(buf);
1840
1841 AV *
1842 LoadWAV ( filename, spec )
1843         char *filename
1844         SDL_AudioSpec *spec
1845         CODE:
1846                 SDL_AudioSpec *temp;
1847                 Uint8 *buf;
1848                 Uint32 len;
1849
1850                 RETVAL = newAV();
1851                 temp = SDL_LoadWAV(filename,spec,&buf,&len);
1852                 if ( ! temp ) goto error;
1853                 av_push(RETVAL,newSViv(PTR2IV(temp)));
1854                 av_push(RETVAL,newSViv(PTR2IV(buf)));
1855                 av_push(RETVAL,newSViv(len));
1856 error:
1857         OUTPUT:
1858                 RETVAL
1859         
1860 #ifdef HAVE_SDL_MIXER
1861
1862 void
1863 MixAudio ( dst, src, len, volume )
1864         Uint8 *dst
1865         Uint8 *src
1866         Uint32 len
1867         int volume
1868         CODE:
1869                 SDL_MixAudio(dst,src,len,volume);
1870
1871 int
1872 MixOpenAudio ( frequency, format, channels, chunksize )
1873         int frequency
1874         Uint16 format
1875         int channels
1876         int chunksize   
1877         CODE:
1878                 RETVAL = Mix_OpenAudio(frequency, format, channels, chunksize);
1879         OUTPUT:
1880                 RETVAL
1881
1882 int
1883 MixAllocateChannels ( number )
1884         int number
1885         CODE:
1886                 RETVAL = Mix_AllocateChannels(number);
1887         OUTPUT:
1888                 RETVAL
1889
1890 AV *
1891 MixQuerySpec ()
1892         CODE:
1893                 int freq, channels, status;
1894                 Uint16 format;
1895                 status = Mix_QuerySpec(&freq,&format,&channels);
1896                 RETVAL = newAV();
1897                 av_push(RETVAL,newSViv(status));
1898                 av_push(RETVAL,newSViv(freq));
1899                 av_push(RETVAL,newSViv(format));
1900                 av_push(RETVAL,newSViv(channels));
1901         OUTPUT:
1902                 RETVAL
1903
1904 Mix_Chunk *
1905 MixLoadWAV ( filename )
1906         char *filename
1907         CODE:
1908                 RETVAL = Mix_LoadWAV(filename);
1909         OUTPUT:
1910                 RETVAL
1911
1912 Mix_Music *
1913 MixLoadMusic ( filename )
1914         char *filename
1915         CODE:
1916                 RETVAL = Mix_LoadMUS(filename);
1917         OUTPUT:
1918                 RETVAL
1919
1920 Mix_Chunk *
1921 MixQuickLoadWAV ( buf )
1922         Uint8 *buf
1923         CODE:
1924                 RETVAL = Mix_QuickLoad_WAV(buf);
1925         OUTPUT:
1926                 RETVAL
1927
1928 void
1929 MixFreeChunk( chunk )
1930         Mix_Chunk *chunk
1931         CODE:
1932                 Mix_FreeChunk(chunk);
1933
1934 void
1935 MixFreeMusic ( music )
1936         Mix_Music *music
1937         CODE:
1938                 Mix_FreeMusic(music);
1939
1940 void
1941 MixSetPostMixCallback ( func, arg )
1942         void *func
1943         void *arg
1944         CODE:
1945                 Mix_SetPostMix(func,arg);
1946
1947 void*
1948 PerlMixMusicHook ()
1949         CODE:
1950                 RETVAL = sdl_perl_music_callback;
1951         OUTPUT:
1952                 RETVAL
1953
1954 void
1955 MixSetMusicHook ( func, arg )
1956         void *func
1957         void *arg
1958         CODE:
1959                 Mix_HookMusic(func,arg);
1960
1961 void
1962 MixSetMusicFinishedHook ( func )
1963         void *func
1964         CODE:
1965                 mix_music_finished_cv = func;
1966                 Mix_HookMusicFinished(sdl_perl_music_finished_callback);
1967
1968 void *
1969 MixGetMusicHookData ()
1970         CODE:
1971                 RETVAL = Mix_GetMusicHookData();
1972         OUTPUT:
1973                 RETVAL
1974
1975 int
1976 MixReverseChannels ( number )
1977         int number
1978         CODE:
1979                 RETVAL = Mix_ReserveChannels ( number );
1980         OUTPUT:
1981                 RETVAL
1982
1983 int
1984 MixGroupChannel ( which, tag )
1985         int which
1986         int tag
1987         CODE:
1988                 RETVAL = Mix_GroupChannel(which,tag);
1989         OUTPUT:
1990                 RETVAL
1991
1992 int
1993 MixGroupChannels ( from, to, tag )
1994         int from
1995         int to
1996         int tag
1997         CODE:
1998                 RETVAL = Mix_GroupChannels(from,to,tag);
1999         OUTPUT:
2000                 RETVAL
2001
2002 int
2003 MixGroupAvailable ( tag )
2004         int tag
2005         CODE:
2006                 RETVAL = Mix_GroupAvailable(tag);
2007         OUTPUT:
2008                 RETVAL
2009
2010 int
2011 MixGroupCount ( tag )
2012         int tag
2013         CODE:
2014                 RETVAL = Mix_GroupCount(tag);
2015         OUTPUT:
2016                 RETVAL
2017
2018 int
2019 MixGroupOldest ( tag )
2020         int tag
2021         CODE:
2022                 RETVAL = Mix_GroupOldest(tag);
2023         OUTPUT:
2024                 RETVAL
2025
2026 int
2027 MixGroupNewer ( tag )
2028         int tag
2029         CODE:
2030                 RETVAL = Mix_GroupNewer(tag);
2031         OUTPUT:
2032                 RETVAL
2033
2034 int
2035 MixPlayChannel ( channel, chunk, loops )
2036         int channel
2037         Mix_Chunk *chunk
2038         int loops
2039         CODE:
2040                 RETVAL = Mix_PlayChannel(channel,chunk,loops);
2041         OUTPUT:
2042                 RETVAL
2043
2044 int
2045 MixPlayChannelTimed ( channel, chunk, loops, ticks )
2046         int channel
2047         Mix_Chunk *chunk
2048         int loops
2049         int ticks
2050         CODE:
2051                 RETVAL = Mix_PlayChannelTimed(channel,chunk,loops,ticks);
2052         OUTPUT:
2053                 RETVAL
2054
2055 int
2056 MixPlayMusic ( music, loops )
2057         Mix_Music *music
2058         int loops
2059         CODE:
2060                 RETVAL = Mix_PlayMusic(music,loops);
2061         OUTPUT:
2062                 RETVAL
2063
2064 int
2065 MixFadeInChannel ( channel, chunk, loops, ms )
2066         int channel
2067         Mix_Chunk *chunk
2068         int loops
2069         int ms
2070         CODE:
2071                 RETVAL = Mix_FadeInChannel(channel,chunk,loops,ms);
2072         OUTPUT:
2073                 RETVAL
2074
2075 int
2076 MixFadeInChannelTimed ( channel, chunk, loops, ms, ticks )
2077         int channel
2078         Mix_Chunk *chunk
2079         int loops
2080         int ticks
2081         int ms
2082         CODE:
2083                 RETVAL = Mix_FadeInChannelTimed(channel,chunk,loops,ms,ticks);
2084         OUTPUT:
2085                 RETVAL
2086
2087 int
2088 MixFadeInMusic ( music, loops, ms )
2089         Mix_Music *music
2090         int loops
2091         int ms
2092         CODE:
2093                 RETVAL = Mix_FadeInMusic(music,loops,ms);
2094         OUTPUT:
2095                 RETVAL
2096
2097 int
2098 MixVolume ( channel, volume )
2099         int channel
2100         int volume
2101         CODE:   
2102                 RETVAL = Mix_Volume(channel,volume);
2103         OUTPUT:
2104                 RETVAL
2105
2106 int
2107 MixVolumeChunk ( chunk, volume )
2108         Mix_Chunk *chunk
2109         int volume
2110         CODE:
2111                 RETVAL = Mix_VolumeChunk(chunk,volume);
2112         OUTPUT:
2113                 RETVAL
2114
2115 int
2116 MixVolumeMusic ( volume )
2117         int volume
2118         CODE:
2119                 RETVAL = Mix_VolumeMusic(volume);
2120         OUTPUT:
2121                 RETVAL
2122
2123 int
2124 MixHaltChannel ( channel )
2125         int channel
2126         CODE:
2127                 RETVAL = Mix_HaltChannel(channel);
2128         OUTPUT:
2129                 RETVAL
2130
2131 int
2132 MixHaltGroup ( tag )
2133         int tag
2134         CODE:
2135                 RETVAL = Mix_HaltGroup(tag);
2136         OUTPUT:
2137                 RETVAL
2138
2139 int
2140 MixHaltMusic ()
2141         CODE:
2142                 RETVAL = Mix_HaltMusic();
2143         OUTPUT:
2144                 RETVAL
2145
2146 int
2147 MixExpireChannel ( channel, ticks )
2148         int channel
2149         int ticks
2150         CODE:
2151                 RETVAL = Mix_ExpireChannel ( channel,ticks);
2152         OUTPUT:
2153                 RETVAL
2154
2155 int
2156 MixFadeOutChannel ( which, ms )
2157         int which
2158         int ms
2159         CODE:
2160                 RETVAL = Mix_FadeOutChannel(which,ms);
2161         OUTPUT:
2162                 RETVAL
2163
2164 int
2165 MixFadeOutGroup ( which, ms )
2166         int which
2167         int ms
2168         CODE:
2169                 RETVAL = Mix_FadeOutGroup(which,ms);
2170         OUTPUT:
2171                 RETVAL
2172
2173 int
2174 MixFadeOutMusic ( ms )
2175         int ms
2176         CODE:
2177                 RETVAL = Mix_FadeOutMusic(ms);
2178         OUTPUT:
2179                 RETVAL
2180
2181 Mix_Fading
2182 MixFadingMusic()
2183         CODE:
2184                 RETVAL = Mix_FadingMusic();
2185         OUTPUT:
2186                 RETVAL
2187
2188 Mix_Fading
2189 MixFadingChannel( which )
2190         int which
2191         CODE:
2192                 RETVAL = Mix_FadingChannel(which);
2193         OUTPUT:
2194                 RETVAL
2195
2196 void
2197 MixPause ( channel )
2198         int channel
2199         CODE:
2200                 Mix_Pause(channel);
2201
2202 void
2203 MixResume ( channel )
2204         int channel
2205         CODE:
2206                 Mix_Resume(channel);
2207
2208 int
2209 MixPaused ( channel )
2210         int channel
2211         CODE:
2212                 RETVAL = Mix_Paused(channel);
2213         OUTPUT:
2214                 RETVAL
2215
2216 void
2217 MixPauseMusic ()
2218         CODE:
2219                 Mix_PauseMusic();
2220
2221 void
2222 MixResumeMusic ()
2223         CODE:
2224                 Mix_ResumeMusic();
2225
2226 void
2227 MixRewindMusic ()
2228         CODE:
2229                 Mix_RewindMusic();
2230
2231 int
2232 MixPausedMusic ()
2233         CODE:
2234                 RETVAL = Mix_PausedMusic();
2235         OUTPUT:
2236                 RETVAL
2237
2238 int
2239 MixPlaying( channel )
2240         int channel     
2241         CODE:
2242                 RETVAL = Mix_Playing(channel);
2243         OUTPUT:
2244                 RETVAL
2245
2246 int
2247 MixPlayingMusic()
2248         CODE:
2249                 RETVAL = Mix_PlayingMusic();
2250         OUTPUT:
2251                 RETVAL
2252
2253
2254 void
2255 MixCloseAudio ()
2256         CODE:
2257                 Mix_CloseAudio();
2258
2259 #endif
2260
2261 int
2262 GLLoadLibrary ( path )
2263         char *path
2264         CODE:
2265                 RETVAL = SDL_GL_LoadLibrary(path);
2266         OUTPUT:
2267                 RETVAL
2268
2269 void*
2270 GLGetProcAddress ( proc )
2271         char *proc
2272         CODE:
2273                 RETVAL = SDL_GL_GetProcAddress(proc);
2274         OUTPUT:
2275                 RETVAL
2276
2277 int
2278 GLSetAttribute ( attr,  value )
2279         int        attr
2280         int        value
2281         CODE:
2282                 RETVAL = SDL_GL_SetAttribute(attr, value);
2283         OUTPUT:
2284                 RETVAL
2285
2286 AV *
2287 GLGetAttribute ( attr )
2288         int        attr
2289         CODE:
2290                 int value;
2291                 RETVAL = newAV();
2292                 av_push(RETVAL,newSViv(SDL_GL_GetAttribute(attr, &value)));
2293                 av_push(RETVAL,newSViv(value));
2294         OUTPUT:
2295                 RETVAL
2296
2297 void
2298 GLSwapBuffers ()
2299         CODE:
2300                 SDL_GL_SwapBuffers ();
2301
2302
2303 int
2304 BigEndian ()
2305         CODE:
2306                 RETVAL = (SDL_BYTEORDER == SDL_BIG_ENDIAN);
2307         OUTPUT:
2308                 RETVAL
2309
2310 int
2311 NumJoysticks ()
2312         CODE:
2313                 RETVAL = SDL_NumJoysticks();
2314         OUTPUT:
2315                 RETVAL
2316
2317 char *
2318 JoystickName ( index )
2319         int index
2320         CODE:
2321                 RETVAL = (char*)SDL_JoystickName(index);
2322         OUTPUT:
2323                 RETVAL
2324
2325 SDL_Joystick *
2326 JoystickOpen ( index ) 
2327         int index
2328         CODE:
2329                 RETVAL = SDL_JoystickOpen(index);
2330         OUTPUT:
2331                 RETVAL
2332
2333 int
2334 JoystickOpened ( index )
2335         int index
2336         CODE:
2337                 RETVAL = SDL_JoystickOpened(index);
2338         OUTPUT:
2339                 RETVAL
2340
2341 int
2342 JoystickIndex ( joystick )
2343         SDL_Joystick *joystick
2344         CODE:
2345                 RETVAL = SDL_JoystickIndex(joystick);
2346         OUTPUT:
2347                 RETVAL
2348
2349 int
2350 JoystickNumAxes ( joystick )
2351         SDL_Joystick *joystick
2352         CODE:
2353                 RETVAL = SDL_JoystickNumAxes(joystick);
2354         OUTPUT:
2355                 RETVAL
2356
2357 int
2358 JoystickNumBalls ( joystick )
2359         SDL_Joystick *joystick
2360         CODE:
2361                 RETVAL = SDL_JoystickNumBalls(joystick);
2362         OUTPUT:
2363                 RETVAL
2364
2365 int
2366 JoystickNumHats ( joystick )
2367         SDL_Joystick *joystick
2368         CODE:
2369                 RETVAL = SDL_JoystickNumHats(joystick);
2370         OUTPUT:
2371                 RETVAL
2372
2373 int
2374 JoystickNumButtons ( joystick )
2375         SDL_Joystick *joystick
2376         CODE:
2377                 RETVAL = SDL_JoystickNumButtons(joystick);
2378         OUTPUT:
2379                 RETVAL
2380
2381 void
2382 JoystickUpdate ()
2383         CODE:
2384                 SDL_JoystickUpdate();
2385
2386 Sint16
2387 JoystickGetAxis ( joystick, axis )
2388         SDL_Joystick *joystick
2389         int axis
2390         CODE:
2391                 RETVAL = SDL_JoystickGetAxis(joystick,axis);
2392         OUTPUT:
2393                 RETVAL
2394
2395 Uint8
2396 JoystickGetHat ( joystick, hat )
2397         SDL_Joystick *joystick
2398         int hat 
2399         CODE:
2400                 RETVAL = SDL_JoystickGetHat(joystick,hat);
2401         OUTPUT:
2402                 RETVAL
2403
2404 Uint8
2405 JoystickGetButton ( joystick, button)
2406         SDL_Joystick *joystick
2407         int button 
2408         CODE:
2409                 RETVAL = SDL_JoystickGetButton(joystick,button);
2410         OUTPUT:
2411                 RETVAL
2412
2413 AV *
2414 JoystickGetBall ( joystick, ball )
2415         SDL_Joystick *joystick
2416         int ball 
2417         CODE:
2418                 int success,dx,dy;
2419                 success = SDL_JoystickGetBall(joystick,ball,&dx,&dy);
2420                 RETVAL = newAV();
2421                 av_push(RETVAL,newSViv(success));
2422                 av_push(RETVAL,newSViv(dx));
2423                 av_push(RETVAL,newSViv(dy));
2424         OUTPUT:
2425                 RETVAL  
2426
2427 void
2428 JoystickClose ( joystick )
2429         SDL_Joystick *joystick
2430         CODE:
2431                 SDL_JoystickClose(joystick);
2432
2433 Sint16
2434 JoyAxisEventWhich ( e )
2435         SDL_Event *e
2436         CODE:
2437                 RETVAL = e->jaxis.which;
2438         OUTPUT:
2439                 RETVAL
2440
2441 Uint8
2442 JoyAxisEventAxis ( e )
2443         SDL_Event *e
2444         CODE:
2445                 RETVAL = e->jaxis.axis;
2446         OUTPUT:
2447                 RETVAL
2448
2449 Sint16
2450 JoyAxisEventValue ( e )
2451         SDL_Event *e
2452         CODE:
2453                 RETVAL = e->jaxis.value;
2454         OUTPUT:
2455                 RETVAL
2456
2457 Uint8
2458 JoyButtonEventWhich ( e )
2459         SDL_Event *e
2460         CODE:
2461                 RETVAL = e->jbutton.which;
2462         OUTPUT:
2463                 RETVAL
2464
2465 Uint8
2466 JoyButtonEventButton ( e )
2467         SDL_Event *e
2468         CODE:
2469                 RETVAL = e->jbutton.button;
2470         OUTPUT:
2471                 RETVAL
2472
2473 Uint8
2474 JoyButtonEventState ( e )
2475         SDL_Event *e
2476         CODE:
2477                 RETVAL = e->jbutton.state;
2478         OUTPUT:
2479                 RETVAL
2480         
2481 Uint8
2482 JoyHatEventWhich ( e )
2483         SDL_Event *e
2484         CODE:
2485                 RETVAL = e->jhat.which;
2486         OUTPUT:
2487                 RETVAL
2488
2489 Uint8
2490 JoyHatEventHat ( e )
2491         SDL_Event *e
2492         CODE:
2493                 RETVAL = e->jhat.hat;
2494         OUTPUT:
2495                 RETVAL
2496
2497 Uint8
2498 JoyHatEventValue ( e )
2499         SDL_Event *e
2500         CODE:
2501                 RETVAL = e->jhat.value;
2502         OUTPUT:
2503                 RETVAL
2504
2505 Uint8
2506 JoyBallEventWhich ( e )
2507         SDL_Event *e
2508         CODE: 
2509                 RETVAL = e->jball.which;
2510         OUTPUT:
2511                 RETVAL
2512
2513 Uint8
2514 JoyBallEventBall ( e )
2515         SDL_Event *e
2516         CODE:
2517                 RETVAL = e->jball.ball;
2518         OUTPUT:
2519                 RETVAL
2520
2521 Sint16
2522 JoyBallEventXrel ( e )
2523         SDL_Event *e
2524         CODE:
2525                 RETVAL = e->jball.xrel;
2526         OUTPUT:
2527                 RETVAL
2528
2529 Sint16
2530 JoyBallEventYrel ( e )
2531         SDL_Event *e
2532         CODE:
2533                 RETVAL = e->jball.yrel;
2534         OUTPUT:
2535                 RETVAL
2536
2537 void
2538 SetClipRect ( surface, rect )
2539         SDL_Surface *surface
2540         SDL_Rect *rect
2541         CODE:
2542                 SDL_SetClipRect(surface,rect);
2543         
2544 SDL_Rect*
2545 GetClipRect ( surface )
2546         SDL_Surface *surface
2547         CODE:
2548                 RETVAL = (SDL_Rect*) safemalloc(sizeof(SDL_Rect));
2549                 SDL_GetClipRect(surface,RETVAL);
2550         OUTPUT:
2551                 RETVAL
2552
2553
2554 #ifdef HAVE_SDL_NET
2555
2556 int
2557 NetInit ()
2558         CODE:
2559                 RETVAL = SDLNet_Init();
2560         OUTPUT:
2561                 RETVAL
2562
2563 void
2564 NetQuit ()
2565         CODE:
2566                 SDLNet_Quit();
2567
2568 IPaddress*
2569 NetNewIPaddress ( host, port )
2570         Uint32 host
2571         Uint16 port
2572         CODE:
2573                 RETVAL = (IPaddress*) safemalloc(sizeof(IPaddress));
2574                 RETVAL->host = host;
2575                 RETVAL->port = port;
2576         OUTPUT:
2577                 RETVAL
2578
2579 Uint32
2580 NetIPaddressHost ( ip )
2581         IPaddress *ip
2582         CODE:
2583                 RETVAL = ip->host;
2584         OUTPUT:
2585                 RETVAL
2586
2587 Uint16
2588 NetIPaddressPort ( ip )
2589         IPaddress *ip
2590         CODE:
2591                 RETVAL = ip->port;
2592         OUTPUT:
2593                 RETVAL
2594
2595 void
2596 NetFreeIPaddress ( ip )
2597         IPaddress *ip
2598         CODE:
2599                 safefree(ip);
2600
2601 const char*
2602 NetResolveIP ( address )
2603         IPaddress *address
2604         CODE:
2605                 RETVAL = SDLNet_ResolveIP(address);
2606         OUTPUT:
2607                 RETVAL
2608
2609 int
2610 NetResolveHost ( address, host, port )
2611         IPaddress *address
2612         const char *host
2613         Uint16 port
2614         CODE:
2615                 RETVAL = SDLNet_ResolveHost(address,host,port);
2616         OUTPUT:
2617                 RETVAL
2618         
2619 TCPsocket
2620 NetTCPOpen ( ip )
2621         IPaddress *ip
2622         CODE:
2623                 RETVAL = SDLNet_TCP_Open(ip);
2624         OUTPUT:
2625                 RETVAL
2626
2627 TCPsocket
2628 NetTCPAccept ( server )
2629         TCPsocket server
2630         CODE:
2631                 RETVAL = SDLNet_TCP_Accept(server);
2632         OUTPUT:
2633                 RETVAL
2634
2635 IPaddress*
2636 NetTCPGetPeerAddress ( sock )
2637         TCPsocket sock
2638         CODE:
2639                 RETVAL = SDLNet_TCP_GetPeerAddress(sock);
2640         OUTPUT:
2641                 RETVAL
2642
2643 int
2644 NetTCPSend ( sock, data, len  )
2645         TCPsocket sock
2646         void *data
2647         int len
2648         CODE:
2649                 RETVAL = SDLNet_TCP_Send(sock,data,len);
2650         OUTPUT:
2651                 RETVAL
2652
2653 AV*
2654 NetTCPRecv ( sock, maxlen )
2655         TCPsocket sock
2656         int maxlen
2657         CODE:
2658                 int status;
2659                 void *buffer;
2660                 buffer = safemalloc(maxlen);
2661                 RETVAL = newAV();
2662                 status = SDLNet_TCP_Recv(sock,buffer,maxlen);
2663                 av_push(RETVAL,newSViv(status));
2664                 av_push(RETVAL,newSVpvn((char*)buffer,maxlen));
2665         OUTPUT:
2666                 RETVAL  
2667         
2668 void
2669 NetTCPClose ( sock )
2670         TCPsocket sock
2671         CODE:
2672                 SDLNet_TCP_Close(sock);
2673
2674 UDPpacket*
2675 NetAllocPacket ( size )
2676         int size
2677         CODE:
2678                 RETVAL = SDLNet_AllocPacket(size);
2679         OUTPUT:
2680                 RETVAL
2681
2682 UDPpacket**
2683 NetAllocPacketV ( howmany, size )
2684         int howmany
2685         int size
2686         CODE:
2687                 RETVAL = SDLNet_AllocPacketV(howmany,size);
2688         OUTPUT:
2689                 RETVAL
2690
2691 int
2692 NetResizePacket ( packet, newsize )
2693         UDPpacket *packet
2694         int newsize
2695         CODE:
2696                 RETVAL = SDLNet_ResizePacket(packet,newsize);
2697         OUTPUT:
2698                 RETVAL
2699
2700 void
2701 NetFreePacket ( packet )
2702         UDPpacket *packet
2703         CODE:
2704                 SDLNet_FreePacket(packet);
2705
2706 void
2707 NetFreePacketV ( packet )
2708         UDPpacket **packet
2709         CODE:
2710                 SDLNet_FreePacketV(packet);
2711
2712 UDPsocket
2713 NetUDPOpen ( port )
2714         Uint16 port
2715         CODE:
2716                 RETVAL = SDLNet_UDP_Open(port);
2717         OUTPUT:
2718                 RETVAL
2719
2720 int
2721 NetUDPBind ( sock, channel, address )
2722         UDPsocket sock
2723         int channel
2724         IPaddress *address
2725         CODE:
2726                 RETVAL = SDLNet_UDP_Bind(sock,channel,address);
2727         OUTPUT:
2728                 RETVAL
2729
2730 void
2731 NetUDPUnbind ( sock, channel )
2732         UDPsocket sock
2733         int channel
2734         CODE:
2735                 SDLNet_UDP_Unbind(sock,channel);
2736
2737 IPaddress*
2738 NetUDPGetPeerAddress ( sock, channel )
2739         UDPsocket sock
2740         int channel
2741         CODE:
2742                 RETVAL = SDLNet_UDP_GetPeerAddress(sock,channel);
2743         OUTPUT:
2744                 RETVAL
2745
2746 int
2747 NetUDPSendV ( sock, packets, npackets )
2748         UDPsocket sock
2749         UDPpacket **packets
2750         int npackets
2751         CODE:
2752                 RETVAL = SDLNet_UDP_SendV(sock,packets,npackets);
2753         OUTPUT:
2754                 RETVAL
2755
2756 int
2757 NetUDPSend ( sock, channel, packet )
2758         UDPsocket sock
2759         int channel
2760         UDPpacket *packet 
2761         CODE:
2762                 RETVAL = SDLNet_UDP_Send(sock,channel,packet);
2763         OUTPUT:
2764                 RETVAL
2765
2766 int
2767 NetUDPRecvV ( sock, packets )
2768         UDPsocket sock
2769         UDPpacket **packets
2770         CODE:
2771                 RETVAL = SDLNet_UDP_RecvV(sock,packets);
2772         OUTPUT:
2773                 RETVAL
2774
2775 int
2776 NetUDPRecv ( sock, packet )
2777         UDPsocket sock
2778         UDPpacket *packet
2779         CODE:
2780                 RETVAL = SDLNet_UDP_Recv(sock,packet);
2781         OUTPUT:
2782                 RETVAL
2783
2784 void
2785 NetUDPClose ( sock )
2786         UDPsocket sock
2787         CODE:
2788                 SDLNet_UDP_Close(sock);
2789
2790 SDLNet_SocketSet
2791 NetAllocSocketSet ( maxsockets )
2792         int maxsockets
2793         CODE:
2794                 RETVAL = SDLNet_AllocSocketSet(maxsockets);
2795         OUTPUT:
2796                 RETVAL
2797
2798 int
2799 NetTCP_AddSocket ( set, sock )
2800         SDLNet_SocketSet set
2801         TCPsocket sock
2802         CODE:
2803                 RETVAL = SDLNet_TCP_AddSocket(set,sock);
2804         OUTPUT:
2805                 RETVAL
2806
2807 int
2808 NetUDP_AddSocket ( set, sock )
2809         SDLNet_SocketSet set
2810         UDPsocket sock
2811         CODE:
2812                 RETVAL = SDLNet_UDP_AddSocket(set,sock);
2813         OUTPUT:
2814                 RETVAL
2815
2816 int
2817 NetTCP_DelSocket ( set, sock )
2818         SDLNet_SocketSet set
2819         TCPsocket sock
2820         CODE:
2821                 RETVAL = SDLNet_TCP_DelSocket(set,sock);
2822         OUTPUT:
2823                 RETVAL
2824
2825 int
2826 NetUDP_DelSocket ( set, sock )
2827         SDLNet_SocketSet set
2828         UDPsocket sock
2829         CODE:
2830                 RETVAL = SDLNet_UDP_DelSocket(set,sock);
2831         OUTPUT:
2832                 RETVAL
2833
2834 int
2835 NetCheckSockets ( set, timeout )
2836         SDLNet_SocketSet set
2837         Uint32 timeout
2838         CODE:
2839                 RETVAL = SDLNet_CheckSockets(set,timeout);
2840         OUTPUT:
2841                 RETVAL
2842
2843 int
2844 NetSocketReady ( sock )
2845         SDLNet_GenericSocket sock
2846         CODE:
2847                 RETVAL = SDLNet_SocketReady(sock);
2848         OUTPUT:
2849                 RETVAL
2850
2851 void
2852 NetFreeSocketSet ( set )
2853         SDLNet_SocketSet set
2854         CODE:
2855                 SDLNet_FreeSocketSet(set);
2856
2857 void
2858 NetWrite16 ( value, area )
2859         Uint16 value
2860         void *area
2861         CODE:
2862                 SDLNet_Write16(value,area);
2863
2864 void
2865 NetWrite32 ( value, area )
2866         Uint32 value
2867         void *area
2868         CODE:
2869                 SDLNet_Write32(value,area);
2870         
2871 Uint16
2872 NetRead16 ( area )
2873         void *area
2874         CODE:
2875                 RETVAL = SDLNet_Read16(area);
2876         OUTPUT:
2877                 RETVAL
2878
2879 Uint32
2880 NetRead32 ( area )
2881         void *area
2882         CODE:
2883                 RETVAL = SDLNet_Read32(area);
2884         OUTPUT:
2885                 RETVAL
2886
2887 #endif 
2888
2889 #ifdef HAVE_SDL_TTF
2890
2891 int
2892 TTFInit ()
2893         CODE:
2894                 RETVAL = TTF_Init();
2895         OUTPUT:
2896                 RETVAL
2897
2898 void
2899 TTFQuit ()
2900         CODE:
2901                 TTF_Quit();
2902
2903 TTF_Font*
2904 TTFOpenFont ( file, ptsize )
2905         char *file
2906         int ptsize
2907         CODE:
2908                 RETVAL = TTF_OpenFont(file,ptsize);
2909         OUTPUT:
2910                 RETVAL
2911
2912 int
2913 TTFGetFontStyle ( font )
2914         TTF_Font *font
2915         CODE:
2916                 RETVAL = TTF_GetFontStyle(font);
2917         OUTPUT:
2918                 RETVAL
2919
2920 void
2921 TTFSetFontStyle ( font, style )
2922         TTF_Font *font
2923         int style
2924         CODE:
2925                 TTF_SetFontStyle(font,style);
2926         
2927 int
2928 TTFFontHeight ( font )
2929         TTF_Font *font
2930         CODE:
2931                 RETVAL = TTF_FontHeight(font);
2932         OUTPUT:
2933                 RETVAL
2934
2935 int
2936 TTFFontAscent ( font )
2937         TTF_Font *font
2938         CODE:
2939                 RETVAL = TTF_FontAscent(font);
2940         OUTPUT:
2941                 RETVAL
2942
2943 int
2944 TTFFontDescent ( font )
2945         TTF_Font *font
2946         CODE:
2947                 RETVAL = TTF_FontDescent(font);
2948         OUTPUT:
2949                 RETVAL
2950
2951 int
2952 TTFFontLineSkip ( font )
2953         TTF_Font *font
2954         CODE:
2955                 RETVAL = TTF_FontLineSkip(font);
2956         OUTPUT:
2957                 RETVAL
2958
2959 AV*
2960 TTFGlyphMetrics ( font, ch )
2961         TTF_Font *font
2962         Uint16 ch
2963         CODE:
2964                 int minx, miny, maxx, maxy, advance;
2965                 RETVAL = newAV();
2966                 TTF_GlyphMetrics(font, ch, &minx, &miny, &maxx, &maxy, &advance);
2967                 av_push(RETVAL,newSViv(minx));
2968                 av_push(RETVAL,newSViv(miny));
2969                 av_push(RETVAL,newSViv(maxx));
2970                 av_push(RETVAL,newSViv(maxy));
2971                 av_push(RETVAL,newSViv(advance));
2972         OUTPUT:
2973                 RETVAL
2974
2975 AV*
2976 TTFSizeText ( font, text )
2977         TTF_Font *font
2978         char *text
2979         CODE:
2980                 int w,h;
2981                 RETVAL = newAV();
2982                 TTF_SizeText(font,text,&w,&h);
2983                 av_push(RETVAL,newSViv(w));
2984                 av_push(RETVAL,newSViv(h));
2985         OUTPUT:
2986                 RETVAL
2987
2988 AV*
2989 TTFSizeUTF8 ( font, text )
2990         TTF_Font *font
2991         char *text
2992         CODE:
2993                 int w,h;
2994                 RETVAL = newAV();
2995                 TTF_SizeUTF8(font,text,&w,&h);
2996                         av_push(RETVAL,newSViv(w));
2997                         av_push(RETVAL,newSViv(h));
2998                 
2999                 sv_2mortal((SV*)RETVAL);
3000                 
3001         OUTPUT:
3002                 RETVAL
3003
3004 AV*
3005 TTFSizeUNICODE ( font, text )
3006         TTF_Font *font
3007         const Uint16 *text
3008         CODE:
3009                 int w,h;
3010                 RETVAL = newAV();
3011                 TTF_SizeUNICODE(font,text,&w,&h);
3012                 av_push(RETVAL,newSViv(w));
3013                 av_push(RETVAL,newSViv(h));
3014         OUTPUT:
3015                 RETVAL
3016
3017 SDL_Surface*
3018 TTFRenderTextSolid ( font, text, fg )
3019         TTF_Font *font
3020         char *text
3021         SDL_Color *fg
3022         CODE:
3023                 RETVAL = TTF_RenderText_Solid(font,text,*fg);
3024         OUTPUT:
3025                 RETVAL
3026
3027 SDL_Surface*
3028 TTFRenderUTF8Solid ( font, text, fg )
3029         TTF_Font *font
3030         char *text
3031         SDL_Color *fg
3032         CODE:
3033                 RETVAL = TTF_RenderUTF8_Solid(font,text,*fg);
3034         OUTPUT:
3035                 RETVAL
3036
3037 SDL_Surface*
3038 TTFRenderUNICODESolid ( font, text, fg )
3039         TTF_Font *font
3040         const Uint16 *text
3041         SDL_Color *fg
3042         CODE:
3043                 RETVAL = TTF_RenderUNICODE_Solid(font,text,*fg);
3044         OUTPUT:
3045                 RETVAL
3046
3047 SDL_Surface*
3048 TTFRenderGlyphSolid ( font, ch, fg )
3049         TTF_Font *font
3050         Uint16 ch
3051         SDL_Color *fg
3052         CODE:
3053                 RETVAL = TTF_RenderGlyph_Solid(font,ch,*fg);
3054         OUTPUT:
3055                 RETVAL
3056
3057 SDL_Surface*
3058 TTFRenderTextShaded ( font, text, fg, bg )
3059         TTF_Font *font
3060         char *text
3061         SDL_Color *fg
3062         SDL_Color *bg
3063         CODE:
3064                 RETVAL = TTF_RenderText_Shaded(font,text,*fg,*bg);
3065         OUTPUT:
3066                 RETVAL
3067
3068 SDL_Surface*
3069 TTFRenderUTF8Shaded( font, text, fg, bg )
3070         TTF_Font *font
3071         char *text
3072         SDL_Color *fg
3073         SDL_Color *bg
3074         CODE:
3075                 RETVAL = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3076         OUTPUT:
3077                 RETVAL
3078
3079 SDL_Surface*
3080 TTFRenderUNICODEShaded( font, text, fg, bg )
3081         TTF_Font *font
3082         const Uint16 *text
3083         SDL_Color *fg
3084         SDL_Color *bg
3085         CODE:
3086                 RETVAL = TTF_RenderUNICODE_Shaded(font,text,*fg,*bg);
3087         OUTPUT:
3088                 RETVAL
3089
3090 SDL_Surface*
3091 TTFRenderGlyphShaded ( font, ch, fg, bg )
3092         TTF_Font *font
3093         Uint16 ch
3094         SDL_Color *fg
3095         SDL_Color *bg
3096         CODE:
3097                 RETVAL = TTF_RenderGlyph_Shaded(font,ch,*fg,*bg);
3098         OUTPUT:
3099                 RETVAL
3100
3101 SDL_Surface*
3102 TTFRenderTextBlended( font, text, fg )
3103         TTF_Font *font
3104         char *text
3105         SDL_Color *fg
3106         CODE:
3107                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
3108         OUTPUT:
3109                 RETVAL
3110
3111 SDL_Surface*
3112 TTFRenderUTF8Blended( font, text, fg )
3113         TTF_Font *font
3114         char *text
3115         SDL_Color *fg
3116         CODE:
3117                 RETVAL = TTF_RenderUTF8_Blended(font,text,*fg);
3118         OUTPUT:
3119                 RETVAL
3120
3121 SDL_Surface*
3122 TTFRenderUNICODEBlended( font, text, fg )
3123         TTF_Font *font
3124         const Uint16 *text
3125         SDL_Color *fg
3126         CODE:
3127                 RETVAL = TTF_RenderUNICODE_Blended(font,text,*fg);
3128         OUTPUT:
3129                 RETVAL
3130
3131 SDL_Surface*
3132 TTFRenderGlyphBlended( font, ch, fg )
3133         TTF_Font *font
3134         Uint16 ch
3135         SDL_Color *fg
3136         CODE:
3137                 RETVAL = TTF_RenderGlyph_Blended(font,ch,*fg);
3138         OUTPUT:
3139                 RETVAL
3140
3141 void
3142 TTFCloseFont ( font )
3143         TTF_Font *font
3144         CODE:
3145                 TTF_CloseFont(font);
3146                 font=NULL; //to be safe http://sdl.beuc.net/sdl.wiki/SDL_ttf_copy_Functions_Management_TTF_CloseFont
3147
3148 SDL_Surface*
3149 TTFPutString ( font, mode, surface, x, y, fg, bg, text )
3150         TTF_Font *font
3151         int mode
3152         SDL_Surface *surface
3153         int x
3154         int y
3155         SDL_Color *fg
3156         SDL_Color *bg
3157         char *text
3158         CODE:
3159                 SDL_Surface *img;
3160                 SDL_Rect dest;
3161                 int w,h;
3162                 dest.x = x;
3163                 dest.y = y;
3164                 RETVAL = NULL;
3165                 switch (mode) {
3166                         case TEXT_SOLID:
3167                                 img = TTF_RenderText_Solid(font,text,*fg);
3168                                 TTF_SizeText(font,text,&w,&h);
3169                                 dest.w = w;
3170                                 dest.h = h;
3171                                 break;
3172                         case TEXT_SHADED:
3173                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3174                                 TTF_SizeText(font,text,&w,&h);
3175                                 dest.w = w;
3176                                 dest.h = h;
3177                                 break;
3178                         case TEXT_BLENDED:
3179                                 img = TTF_RenderText_Blended(font,text,*fg);
3180                                 TTF_SizeText(font,text,&w,&h);
3181                                 dest.w = w;
3182                                 dest.h = h;
3183                                 break;
3184                         case UTF8_SOLID:
3185                                 img = TTF_RenderUTF8_Solid(font,text,*fg);
3186                                 TTF_SizeUTF8(font,text,&w,&h);
3187                                 dest.w = w;
3188                                 dest.h = h;
3189                                 break;
3190                         case UTF8_SHADED:
3191                                 img = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3192                                 TTF_SizeUTF8(font,text,&w,&h);
3193                                 dest.w = w;
3194                                 dest.h = h;
3195                                 break;
3196                         case UTF8_BLENDED:
3197                                 img = TTF_RenderUTF8_Blended(font,text,*fg);
3198                                 TTF_SizeUTF8(font,text,&w,&h);
3199                                 dest.w = w;
3200                                 dest.h = h;
3201                                 break;
3202                         case UNICODE_SOLID:
3203                                 img = TTF_RenderUNICODE_Solid(font,(Uint16*)text,*fg);
3204                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3205                                 dest.w = w;
3206                                 dest.h = h;
3207                                 break;
3208                         case UNICODE_SHADED:
3209                                 img = TTF_RenderUNICODE_Shaded(font,(Uint16*)text,*fg,*bg);
3210                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3211                                 dest.w = w;
3212                                 dest.h = h;
3213                                 break;
3214                         case UNICODE_BLENDED:
3215                                 img = TTF_RenderUNICODE_Blended(font,(Uint16*)text,*fg);
3216                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3217                                 dest.w = w;
3218                                 dest.h = h;
3219                                 break;
3220                         default:
3221                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3222                                 TTF_SizeText(font,text,&w,&h);
3223                                 dest.w = w;
3224                                 dest.h = h;
3225                 }
3226                 if ( img && img->format && img->format->palette ) {
3227                         SDL_Color *c = &img->format->palette->colors[0];
3228                         Uint32 key = SDL_MapRGB( img->format, c->r, c->g, c->b );
3229                         SDL_SetColorKey(img,SDL_SRCCOLORKEY,key );
3230                         if (0 > SDL_BlitSurface(img,NULL,surface,&dest)) {
3231                                 SDL_FreeSurface(img);
3232                                 RETVAL = NULL;  
3233                         } else {
3234                                 RETVAL = img;
3235                         }
3236                 }
3237         OUTPUT:
3238                 RETVAL
3239
3240 #endif
3241
3242 SDL_Overlay*
3243 CreateYUVOverlay ( width, height, format, display )
3244         int width
3245         int height
3246         Uint32 format
3247         SDL_Surface *display
3248         CODE:
3249                 RETVAL = SDL_CreateYUVOverlay ( width, height, format, display );
3250         OUTPUT:
3251                 RETVAL
3252
3253 int
3254 LockYUVOverlay ( overlay )
3255         SDL_Overlay *overlay
3256         CODE:
3257                 RETVAL = SDL_LockYUVOverlay(overlay);
3258         OUTPUT:
3259                 RETVAL
3260
3261 void
3262 UnlockYUVOverlay ( overlay )
3263         SDL_Overlay *overlay
3264         CODE:
3265                 SDL_UnlockYUVOverlay(overlay);
3266
3267 int
3268 DisplayYUVOverlay ( overlay, dstrect )
3269         SDL_Overlay *overlay
3270         SDL_Rect *dstrect
3271         CODE:
3272                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
3273         OUTPUT:
3274                 RETVAL
3275
3276 void
3277 FreeYUVOverlay ( overlay )
3278         SDL_Overlay *overlay
3279         CODE:
3280                 SDL_FreeYUVOverlay ( overlay );
3281
3282 Uint32
3283 OverlayFormat ( overlay, ... )
3284         SDL_Overlay *overlay
3285         CODE:
3286                 if ( items > 1 ) 
3287                         overlay->format = SvIV(ST(1));
3288                 RETVAL = overlay->format;
3289         OUTPUT:
3290                 RETVAL
3291
3292 int 
3293 OverlayW ( overlay, ... )
3294         SDL_Overlay *overlay
3295         CODE:
3296                 if ( items > 1 ) 
3297                         overlay->w = SvIV(ST(1));
3298                 RETVAL = overlay->w;
3299         OUTPUT:
3300                 RETVAL
3301
3302 int
3303 OverlayH ( overlay, ... )
3304         SDL_Overlay *overlay
3305         CODE:
3306                 if ( items > 1 )
3307                         overlay->h = SvIV(ST(1));
3308                 RETVAL = overlay->h;
3309         OUTPUT:
3310                 RETVAL 
3311
3312 int
3313 OverlayPlanes ( overlay, ... )
3314         SDL_Overlay *overlay
3315         CODE:
3316                 if ( items > 1 )
3317                         overlay->planes = SvIV(ST(1));
3318                 RETVAL = overlay->planes;
3319         OUTPUT:
3320                 RETVAL
3321
3322 Uint32
3323 OverlayHW ( overlay )
3324         SDL_Overlay *overlay
3325         CODE:
3326                 RETVAL = overlay->hw_overlay;
3327         OUTPUT:
3328                 RETVAL
3329
3330 Uint16*
3331 OverlayPitches ( overlay )
3332         SDL_Overlay *overlay
3333         CODE:
3334                 RETVAL = overlay->pitches;
3335         OUTPUT:
3336                 RETVAL
3337
3338 Uint8**
3339 OverlayPixels ( overlay )
3340         SDL_Overlay *overlay
3341         CODE:
3342                 RETVAL = overlay->pixels;
3343         OUTPUT:
3344                 RETVAL
3345
3346 int
3347 WMToggleFullScreen ( surface )
3348         SDL_Surface *surface
3349         CODE:
3350                 RETVAL = SDL_WM_ToggleFullScreen(surface);
3351         OUTPUT:
3352                 RETVAL
3353
3354 Uint32
3355 WMGrabInput ( mode )
3356         Uint32 mode
3357         CODE:
3358                 RETVAL = SDL_WM_GrabInput(mode);
3359         OUTPUT:
3360                 RETVAL
3361
3362 int
3363 WMIconifyWindow ()
3364         CODE:
3365                 RETVAL = SDL_WM_IconifyWindow();
3366         OUTPUT:
3367                 RETVAL
3368
3369 int
3370 ResizeEventW ( e )
3371         SDL_Event *e
3372         CODE:
3373                 RETVAL = e->resize.w;
3374         OUTPUT:
3375                 RETVAL
3376
3377 int
3378 ResizeEventH ( e )
3379         SDL_Event *e
3380         CODE:
3381                 RETVAL = e->resize.h;
3382         OUTPUT:
3383                 RETVAL
3384
3385 char*
3386 AudioDriverName ()
3387         CODE:
3388                 char name[32];
3389                 RETVAL = SDL_AudioDriverName(name,32);
3390         OUTPUT:
3391                 RETVAL
3392
3393 Uint32
3394 GetKeyState ( k )
3395         SDLKey k
3396         CODE:
3397                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
3398                 RETVAL = SDL_GetKeyState(NULL)[k];
3399         OUTPUT:
3400                 RETVAL
3401
3402 #ifdef HAVE_SMPEG
3403
3404 SMPEG_Info *
3405 NewSMPEGInfo()
3406         CODE:   
3407                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3408         OUTPUT:
3409                 RETVAL
3410
3411 void
3412 FreeSMPEGInfo ( info )
3413         SMPEG_Info *info
3414         CODE:   
3415                 safefree(info);
3416
3417 int
3418 SMPEGInfoHasAudio ( info )
3419         SMPEG_Info* info
3420         CODE:
3421                 RETVAL = info->has_audio;
3422         OUTPUT:
3423                 RETVAL
3424
3425 int
3426 SMPEGInfoHasVideo ( info )
3427         SMPEG_Info* info
3428         CODE:
3429                 RETVAL = info->has_video;
3430         OUTPUT:
3431                 RETVAL
3432
3433 int
3434 SMPEGInfoWidth ( info )
3435         SMPEG_Info* info
3436         CODE:
3437                 RETVAL = info->width;
3438         OUTPUT:
3439                 RETVAL
3440
3441 int
3442 SMPEGInfoHeight ( info )
3443         SMPEG_Info* info
3444         CODE:
3445                 RETVAL = info->height;
3446         OUTPUT:
3447                 RETVAL
3448
3449 int
3450 SMPEGInfoCurrentFrame ( info )
3451         SMPEG_Info* info
3452         CODE:
3453                 RETVAL = info->current_frame;
3454         OUTPUT:
3455                 RETVAL
3456
3457 double
3458 SMPEGInfoCurrentFPS ( info )
3459         SMPEG_Info* info
3460         CODE:
3461                 RETVAL = info->current_fps;
3462         OUTPUT:
3463                 RETVAL
3464
3465 int
3466 SMPEGInfoCurrentAudioFrame ( info )
3467         SMPEG_Info* info
3468         CODE:
3469                 RETVAL = info->audio_current_frame;
3470         OUTPUT:
3471                 RETVAL
3472
3473 int
3474 SMPEGInfoCurrentOffset ( info )
3475         SMPEG_Info* info
3476         CODE:
3477                 RETVAL = info->current_offset;
3478         OUTPUT:
3479                 RETVAL
3480
3481 int
3482 SMPEGInfoTotalSize ( info )
3483         SMPEG_Info* info
3484         CODE:
3485                 RETVAL = info->total_size;
3486         OUTPUT:
3487                 RETVAL
3488
3489 double
3490 SMPEGInfoCurrentTime ( info )
3491         SMPEG_Info* info
3492         CODE:
3493                 RETVAL = info->current_time;
3494         OUTPUT:
3495                 RETVAL
3496
3497 double
3498 SMPEGInfoTotalTime ( info )
3499         SMPEG_Info* info
3500         CODE:
3501                 RETVAL = info->total_time;
3502         OUTPUT:
3503                 RETVAL
3504
3505 char *
3506 SMPEGError ( mpeg )
3507         SMPEG* mpeg
3508         CODE:   
3509                 RETVAL = SMPEG_error(mpeg);
3510         OUTPUT:
3511                 RETVAL
3512
3513 SMPEG*
3514 NewSMPEG ( filename, info, use_audio )
3515         char* filename
3516         SMPEG_Info* info
3517         int use_audio
3518         CODE:   
3519 #ifdef HAVE_SDL_MIXER
3520                 RETVAL = SMPEG_new(filename,info,0);
3521 #else
3522                 RETVAL = SMPEG_new(filename,info,use_audio);
3523 #endif
3524         OUTPUT:
3525                 RETVAL
3526
3527 void
3528 FreeSMPEG ( mpeg )
3529         SMPEG* mpeg
3530         CODE:
3531                 SMPEG_delete(mpeg);
3532
3533 void
3534 SMPEGEnableAudio ( mpeg , flag )
3535         SMPEG* mpeg
3536         int flag
3537         CODE:   
3538                 SMPEG_enableaudio(mpeg,flag);
3539 #ifdef HAVE_SDL_MIXER
3540                 sdl_perl_use_smpeg_audio = flag;
3541 #endif
3542
3543 void
3544 SMPEGEnableVideo ( mpeg , flag )
3545         SMPEG* mpeg
3546         int flag
3547         CODE:   
3548                 SMPEG_enablevideo(mpeg,flag);
3549
3550 void
3551 SMPEGSetVolume ( mpeg , volume )
3552         SMPEG* mpeg
3553         int volume
3554         CODE:   
3555                 SMPEG_setvolume(mpeg,volume);
3556
3557 void
3558 SMPEGSetDisplay ( mpeg, dest, surfLock )
3559         SMPEG* mpeg
3560         SDL_Surface* dest
3561         SDL_mutex*  surfLock
3562         CODE:
3563                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3564
3565 void
3566 SMPEGScaleXY ( mpeg, w, h)
3567         SMPEG* mpeg
3568         int w
3569         int h
3570         CODE:
3571                 SMPEG_scaleXY(mpeg,w,h);
3572
3573 void
3574 SMPEGScale ( mpeg, scale )
3575         SMPEG* mpeg
3576         int scale
3577         CODE:
3578                 SMPEG_scale(mpeg,scale);
3579
3580 void
3581 SMPEGPlay ( mpeg )
3582         SMPEG* mpeg
3583         CODE:
3584                 SDL_AudioSpec audiofmt;
3585                 Uint16 format;
3586                 int freq, channels;
3587 #ifdef HAVE_SDL_MIXER
3588                 if  (sdl_perl_use_smpeg_audio ) {
3589                         SMPEG_enableaudio(mpeg, 0);
3590                         Mix_QuerySpec(&freq, &format, &channels);
3591                         audiofmt.format = format;
3592                         audiofmt.freq = freq;
3593                         audiofmt.channels = channels;
3594                         SMPEG_actualSpec(mpeg, &audiofmt);
3595                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3596                         SMPEG_enableaudio(mpeg, 1);
3597                 }
3598 #endif
3599                 SMPEG_play(mpeg);
3600
3601 SMPEGstatus
3602 SMPEGStatus ( mpeg )
3603         SMPEG* mpeg
3604         CODE:
3605                 RETVAL = SMPEG_status(mpeg);
3606         OUTPUT:
3607                 RETVAL
3608
3609 void
3610 SMPEGPause ( mpeg )
3611         SMPEG* mpeg
3612         CODE:
3613                 SMPEG_pause(mpeg);
3614
3615 void
3616 SMPEGLoop ( mpeg, repeat )
3617         SMPEG* mpeg
3618         int repeat
3619         CODE:
3620                 SMPEG_loop(mpeg,repeat);
3621
3622 void
3623 SMPEGStop ( mpeg )
3624         SMPEG* mpeg
3625         CODE:
3626                 SMPEG_stop(mpeg);
3627 #ifdef HAVE_SDL_MIXER
3628                 Mix_HookMusic(NULL, NULL);
3629 #endif
3630
3631 void
3632 SMPEGRewind ( mpeg )
3633         SMPEG* mpeg
3634         CODE:
3635                 SMPEG_rewind(mpeg);
3636
3637 void
3638 SMPEGSeek ( mpeg, bytes )
3639         SMPEG* mpeg
3640         int bytes
3641         CODE:
3642                 SMPEG_seek(mpeg,bytes);
3643
3644 void
3645 SMPEGSkip ( mpeg, seconds )
3646         SMPEG* mpeg
3647         float seconds
3648         CODE:
3649                 SMPEG_skip(mpeg,seconds);
3650
3651 void
3652 SMPEGSetDisplayRegion ( mpeg, rect )
3653         SMPEG* mpeg
3654         SDL_Rect* rect
3655         CODE:
3656                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3657
3658 void
3659 SMPEGRenderFrame ( mpeg, frame )
3660         SMPEG* mpeg
3661         int frame
3662         CODE:
3663                 SMPEG_renderFrame(mpeg,frame);
3664
3665 SMPEG_Info *
3666 SMPEGGetInfo ( mpeg )
3667         SMPEG* mpeg
3668         CODE:
3669                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3670                 SMPEG_getinfo(mpeg,RETVAL);
3671         OUTPUT:
3672                 RETVAL
3673         
3674
3675 #endif
3676
3677 #ifdef HAVE_SDL_GFX
3678
3679 SDL_Surface *
3680 GFXRotoZoom ( src, angle, zoom, smooth)
3681         SDL_Surface * src
3682         double angle
3683         double zoom
3684         int smooth
3685         CODE:
3686                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3687         OUTPUT:
3688                 RETVAL
3689
3690 SDL_Surface *
3691 GFXZoom ( src, zoomx, zoomy, smooth)
3692         SDL_Surface *src
3693         double zoomx
3694         double zoomy
3695         int smooth
3696         CODE:
3697                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3698         OUTPUT:
3699                 RETVAL
3700
3701 int
3702 GFXPixelColor ( dst, x, y, color )
3703         SDL_Surface* dst
3704         Sint16 x
3705         Sint16 y
3706         Uint32 color
3707         CODE:
3708                 RETVAL = pixelColor( dst, x, y, color);
3709         OUTPUT:
3710                 RETVAL
3711
3712 int
3713 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3714         SDL_Surface* dst
3715         Sint16 x
3716         Sint16 y
3717         Uint8 r
3718         Uint8 g
3719         Uint8 b
3720         Uint8 a
3721         CODE:
3722                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3723         OUTPUT:
3724                 RETVAL
3725
3726 int
3727 GFXHlineColor ( dst, x1, x2, y, color )
3728         SDL_Surface* dst
3729         Sint16 x1
3730         Sint16 x2
3731         Sint16 y
3732         Uint32 color
3733         CODE:
3734                 RETVAL = hlineColor( dst, x1, x2, y, color );
3735         OUTPUT:
3736                 RETVAL
3737
3738 int
3739 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3740         SDL_Surface* dst
3741         Sint16 x1
3742         Sint16 x2
3743         Sint16 y
3744         Uint8 r
3745         Uint8 g
3746         Uint8 b
3747         Uint8 a
3748         CODE:
3749                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3750         OUTPUT:
3751                 RETVAL
3752
3753 int
3754 GFXVlineColor ( dst, x, y1, y2, color )
3755         SDL_Surface* dst
3756         Sint16 x
3757         Sint16 y1
3758         Sint16 y2
3759         Uint32 color
3760         CODE:
3761                 RETVAL = vlineColor( dst, x, y1, y2, color );
3762         OUTPUT:
3763                 RETVAL
3764
3765 int
3766 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3767         SDL_Surface* dst
3768         Sint16 x
3769         Sint16 y1
3770         Sint16 y2
3771         Uint8 r
3772         Uint8 g
3773         Uint8 b
3774         Uint8 a
3775         CODE:
3776                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3777         OUTPUT:
3778                 RETVAL
3779
3780 int
3781 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3782         SDL_Surface* dst
3783         Sint16 x1
3784         Sint16 y1
3785         Sint16 x2
3786         Sint16 y2
3787         Uint32 color
3788         CODE:
3789                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3790         OUTPUT:
3791                 RETVAL
3792
3793 int
3794 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3795         SDL_Surface* dst
3796         Sint16 x1
3797         Sint16 y1
3798         Sint16 x2
3799         Sint16 y2
3800         Uint8 r
3801         Uint8 g
3802         Uint8 b
3803         Uint8 a
3804         CODE:
3805                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3806         OUTPUT:
3807                 RETVAL
3808
3809 int
3810 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3811         SDL_Surface* dst
3812         Sint16 x1
3813         Sint16 y1
3814         Sint16 x2
3815         Sint16 y2
3816         Uint32 color
3817         CODE:
3818                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3819         OUTPUT:
3820                 RETVAL
3821
3822 int
3823 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3824         SDL_Surface* dst;
3825         Sint16 x1
3826         Sint16 y1
3827         Sint16 x2
3828         Sint16 y2
3829         Uint8 r
3830         Uint8 g
3831         Uint8 b
3832         Uint8 a
3833         CODE:
3834                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3835         OUTPUT:
3836                 RETVAL
3837
3838 int
3839 GFXLineColor ( dst, x1, y1, x2, y2, color )
3840         SDL_Surface* dst
3841         Sint16 x1
3842         Sint16 y1
3843         Sint16 x2
3844         Sint16 y2
3845         Uint32 color
3846         CODE:
3847                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3848         OUTPUT:
3849                 RETVAL
3850
3851 int
3852 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3853         SDL_Surface* dst
3854         Sint16 x1
3855         Sint16 y1
3856         Sint16 x2
3857         Sint16 y2
3858         Uint8 r
3859         Uint8 g
3860         Uint8 b
3861         Uint8 a
3862         CODE:
3863                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3864         OUTPUT:
3865                 RETVAL
3866
3867 int
3868 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3869         SDL_Surface* dst
3870         Sint16 x1
3871         Sint16 y1
3872         Sint16 x2
3873         Sint16 y2
3874         Uint32 color
3875         CODE:
3876                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3877         OUTPUT:
3878                 RETVAL
3879
3880 int
3881 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3882         SDL_Surface* dst
3883         Sint16 x1
3884         Sint16 y1
3885         Sint16 x2
3886         Sint16 y2
3887         Uint8 r
3888         Uint8 g
3889         Uint8 b
3890         Uint8 a
3891         CODE:
3892                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3893         OUTPUT:
3894                 RETVAL
3895
3896 int
3897 GFXCircleColor ( dst, x, y, r, color )
3898         SDL_Surface* dst
3899         Sint16 x
3900         Sint16 y
3901         Sint16 r
3902         Uint32 color
3903         CODE:
3904                 RETVAL = circleColor( dst, x, y, r, color );
3905         OUTPUT:
3906                 RETVAL
3907
3908 int
3909 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3910         SDL_Surface* dst
3911         Sint16 x
3912         Sint16 y
3913         Sint16 rad
3914         Uint8 r
3915         Uint8 g
3916         Uint8 b
3917         Uint8 a
3918         CODE:
3919                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3920         OUTPUT:
3921                 RETVAL
3922
3923 int
3924 GFXAacircleColor ( dst, x, y, r, color )
3925         SDL_Surface* dst
3926         Sint16 x
3927         Sint16 y
3928         Sint16 r
3929         Uint32 color
3930         CODE:
3931                 RETVAL = aacircleColor( dst, x, y, r, color );
3932         OUTPUT:
3933                 RETVAL
3934
3935 int
3936 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3937         SDL_Surface* dst
3938         Sint16 x
3939         Sint16 y
3940         Sint16 rad
3941         Uint8 r
3942         Uint8 g
3943         Uint8 b
3944         Uint8 a
3945         CODE:
3946                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3947         OUTPUT:
3948                 RETVAL
3949
3950 int
3951 GFXFilledCircleColor ( dst, x, y, r, color )
3952         SDL_Surface* dst
3953         Sint16 x
3954         Sint16 y
3955         Sint16 r
3956         Uint32 color
3957         CODE:
3958                 RETVAL = filledCircleColor( dst, x, y, r, color );
3959         OUTPUT:
3960                 RETVAL
3961
3962 int
3963 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3964         SDL_Surface* dst
3965         Sint16 x
3966         Sint16 y
3967         Sint16 rad
3968         Uint8 r
3969         Uint8 g
3970         Uint8 b
3971         Uint8 a
3972         CODE:
3973                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3974         OUTPUT:
3975                 RETVAL
3976
3977 int
3978 GFXEllipseColor ( dst, x, y, rx, ry, color )
3979         SDL_Surface* dst
3980         Sint16 x
3981         Sint16 y
3982         Sint16 rx
3983         Sint16 ry
3984         Uint32 color
3985         CODE:
3986                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3987         OUTPUT:
3988                 RETVAL
3989
3990 int
3991 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3992         SDL_Surface* dst
3993         Sint16 x
3994         Sint16 y
3995         Sint16  rx
3996         Sint16 ry
3997         Uint8 r
3998         Uint8 g
3999         Uint8 b
4000         Uint8 a
4001         CODE:
4002                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4003         OUTPUT:
4004                 RETVAL
4005
4006 int
4007 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
4008         SDL_Surface* dst
4009         Sint16 xc
4010         Sint16 yc
4011         Sint16 rx
4012         Sint16 ry
4013         Uint32 color
4014         CODE:
4015                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
4016         OUTPUT:
4017                 RETVAL
4018
4019 int
4020 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4021         SDL_Surface* dst
4022         Sint16 x
4023         Sint16 y
4024         Sint16 rx
4025         Sint16 ry
4026         Uint8 r
4027         Uint8 g
4028         Uint8 b
4029         Uint8 a
4030         CODE:
4031                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4032         OUTPUT:
4033                 RETVAL
4034
4035 int
4036 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
4037         SDL_Surface* dst
4038         Sint16 x
4039         Sint16 y
4040         Sint16 rx
4041         Sint16 ry
4042         Uint32 color
4043         CODE:
4044                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
4045         OUTPUT:
4046                 RETVAL
4047
4048 int
4049 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4050         SDL_Surface* dst
4051         Sint16 x
4052         Sint16 y
4053         Sint16 rx
4054         Sint16 ry
4055         Uint8 r
4056         Uint8 g
4057         Uint8 b
4058         Uint8 a
4059         CODE:
4060                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4061         OUTPUT:
4062                 RETVAL
4063
4064 int
4065 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
4066         SDL_Surface* dst
4067         Sint16 x
4068         Sint16 y
4069         Sint16 rad
4070         Sint16 start
4071         Sint16 end
4072         Uint32 color
4073         CODE:
4074                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
4075         OUTPUT:
4076                 RETVAL
4077
4078 int
4079 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
4080         SDL_Surface* dst
4081         Sint16 x
4082         Sint16 y
4083         Sint16 rad
4084         Sint16 start
4085         Sint16 end
4086         Uint8 r
4087         Uint8 g
4088         Uint8 b
4089         Uint8 a
4090         CODE:
4091                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
4092         OUTPUT:
4093                 RETVAL
4094
4095 int
4096 GFXPolygonColor ( dst, vx, vy, n, color )
4097         SDL_Surface* dst
4098         Sint16* vx
4099         Sint16* vy
4100         int n
4101         Uint32 color;
4102         CODE:
4103                 RETVAL = polygonColor( dst, vx, vy, n, color );
4104         OUTPUT:
4105                 RETVAL
4106
4107 int
4108 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4109         SDL_Surface* dst
4110         Sint16* vx
4111         Sint16* vy
4112         int n
4113         Uint8 r
4114         Uint8 g
4115         Uint8 b
4116         Uint8 a
4117         CODE:
4118                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
4119         OUTPUT:
4120                 RETVAL
4121
4122 int
4123 GFXAapolygonColor ( dst, vx, vy, n, color )
4124         SDL_Surface* dst
4125         Sint16* vx
4126         Sint16* vy
4127         int n
4128         Uint32 color
4129         CODE:
4130                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
4131         OUTPUT:
4132                 RETVAL
4133
4134 int
4135 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4136         SDL_Surface* dst
4137         Sint16* vx
4138         Sint16* vy
4139         int n
4140         Uint8 r
4141         Uint8 g
4142         Uint8 b
4143         Uint8 a
4144         CODE:
4145                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
4146         OUTPUT:
4147                 RETVAL
4148
4149 int
4150 GFXFilledPolygonColor ( dst, vx, vy, n, color )
4151         SDL_Surface* dst
4152         Sint16* vx
4153         Sint16* vy
4154         int n
4155         int color
4156         CODE:
4157                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
4158         OUTPUT:
4159                 RETVAL
4160
4161 int
4162 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4163         SDL_Surface* dst
4164         Sint16* vx
4165         Sint16* vy
4166         int n
4167         Uint8 r
4168         Uint8 g
4169         Uint8 b
4170         Uint8 a
4171         CODE:
4172                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
4173         OUTPUT:
4174                 RETVAL
4175
4176 int
4177 GFXCharacterColor ( dst, x, y, c, color )
4178         SDL_Surface* dst
4179         Sint16 x
4180         Sint16 y
4181         char c
4182         Uint32 color
4183         CODE:
4184                 RETVAL = characterColor( dst, x, y, c, color );
4185         OUTPUT:
4186                 RETVAL
4187
4188 int
4189 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
4190         SDL_Surface* dst
4191         Sint16 x
4192         Sint16 y
4193         char c
4194         Uint8 r
4195         Uint8 g
4196         Uint8 b
4197         Uint8 a
4198         CODE:
4199                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
4200         OUTPUT:
4201                 RETVAL
4202
4203 int
4204 GFXStringColor ( dst, x, y, c, color )
4205         SDL_Surface* dst
4206         Sint16 x
4207         Sint16 y
4208         char* c
4209         Uint32 color
4210         CODE:
4211                 RETVAL = stringColor( dst, x, y, c, color );
4212         OUTPUT:
4213                 RETVAL
4214
4215 int
4216 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
4217         SDL_Surface* dst
4218         Sint16 x
4219         Sint16 y
4220         char* c
4221         Uint8 r
4222         Uint8 g
4223         Uint8 b
4224         Uint8 a
4225         CODE:
4226                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
4227         OUTPUT:
4228                 RETVAL
4229
4230 #endif
4231
4232
4233 #ifdef HAVE_SDL_SVG
4234
4235 SDL_svg_context *
4236 SVG_Load ( filename )
4237         char* filename
4238         CODE:
4239                 RETVAL = SVG_Load(filename);
4240         OUTPUT:
4241                 RETVAL
4242
4243 SDL_svg_context *
4244 SVG_LoadBuffer ( data, len )
4245         char* data
4246         int len
4247         CODE:
4248                 RETVAL = SVG_LoadBuffer(data,len);
4249         OUTPUT:
4250                 RETVAL
4251
4252 int
4253 SVG_SetOffset ( source, xoff, yoff )
4254         SDL_svg_context* source
4255         double xoff
4256         double yoff
4257         CODE:
4258                 RETVAL = SVG_SetOffset(source,xoff,yoff);
4259         OUTPUT:
4260                 RETVAL
4261
4262 int
4263 SVG_SetScale ( source, xscale, yscale )
4264         SDL_svg_context* source
4265         double xscale
4266         double yscale
4267         CODE:
4268                 RETVAL = SVG_SetScale(source,xscale,yscale);
4269         OUTPUT:
4270                 RETVAL
4271
4272 int
4273 SVG_RenderToSurface ( source, x, y, dest )
4274         SDL_svg_context* source
4275         int x
4276         int y
4277         SDL_Surface* dest;
4278         CODE:
4279                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
4280         OUTPUT:
4281                 RETVAL
4282
4283 void
4284 SVG_Free ( source )
4285         SDL_svg_context* source
4286         CODE:
4287                 SVG_Free(source);       
4288
4289 void
4290 SVG_Set_Flags ( source, flags )
4291         SDL_svg_context* source
4292         Uint32 flags
4293         CODE:
4294                 SVG_Set_Flags(source,flags);
4295
4296 float
4297 SVG_Width ( source )
4298         SDL_svg_context* source
4299         CODE:
4300                 RETVAL = SVG_Width(source);
4301         OUTPUT:
4302                 RETVAL
4303
4304 float
4305 SVG_HEIGHT ( source )
4306         SDL_svg_context* source
4307         CODE:
4308                 RETVAL = SVG_Height(source);
4309         OUTPUT:
4310                 RETVAL
4311
4312 void
4313 SVG_SetClipping ( source, minx, miny, maxx, maxy )
4314         SDL_svg_context* source
4315         int minx
4316         int miny
4317         int maxx
4318         int maxy
4319         CODE:
4320                 SVG_SetClipping(source,minx,miny,maxx,maxy);
4321
4322 int
4323 SVG_Version ( )
4324         CODE:
4325                 RETVAL = SVG_Version();
4326         OUTPUT:
4327                 RETVAL
4328
4329
4330 #endif
4331
4332 #ifdef HAVE_SDL_SOUND
4333
4334 Uint16
4335 SoundAudioInfoFormat ( audioinfo )
4336         Sound_AudioInfo* audioinfo
4337         CODE:
4338                 RETVAL = audioinfo->format;
4339         OUTPUT:
4340                 RETVAL
4341
4342 Uint8
4343 SoundAudioInfoChannels ( audioinfo )
4344         Sound_AudioInfo* audioinfo
4345         CODE:
4346                 RETVAL = audioinfo->channels;
4347         OUTPUT:
4348                 RETVAL
4349
4350 Uint32
4351 SoundAudioInforate ( audioinfo )
4352         Sound_AudioInfo* audioinfo
4353         CODE:
4354                 RETVAL = audioinfo->rate;
4355         OUTPUT:
4356                 RETVAL
4357
4358 AV*
4359 SoundDecoderInfoExtensions ( decoderinfo )
4360         Sound_DecoderInfo* decoderinfo
4361         CODE:
4362                 const char **ext;
4363                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
4364                         av_push(RETVAL,newSVpv(*ext,0));
4365                 }
4366         OUTPUT:
4367                 RETVAL
4368
4369 const char*
4370 SoundDecoderInfoDescription ( decoderinfo )
4371         Sound_DecoderInfo* decoderinfo
4372         CODE:
4373                 RETVAL = decoderinfo->description;
4374         OUTPUT:
4375                 RETVAL
4376
4377 const char*
4378 SoundDecoderInfoAuthor ( decoderinfo )
4379         Sound_DecoderInfo* decoderinfo
4380         CODE:
4381                 RETVAL = decoderinfo->author;
4382         OUTPUT:
4383                 RETVAL
4384
4385 const char*
4386 SoundDecoderInfoUrl ( decoderinfo )
4387         Sound_DecoderInfo* decoderinfo
4388         CODE:
4389                 RETVAL = decoderinfo->url;
4390         OUTPUT:
4391                 RETVAL
4392
4393 const Sound_DecoderInfo*
4394 SoundSampleDecoder ( sample ) 
4395         Sound_Sample* sample
4396         CODE:
4397                 RETVAL = sample->decoder;
4398         OUTPUT:
4399                 RETVAL
4400
4401 Sound_AudioInfo* 
4402 SoundSampleDesired ( sample )
4403         Sound_Sample* sample
4404         CODE:
4405                 RETVAL = &sample->desired;
4406         OUTPUT:
4407                 RETVAL
4408
4409 Sound_AudioInfo*
4410 SoundSampleAcutal ( sample )
4411         Sound_Sample* sample
4412         CODE:
4413                 RETVAL = &sample->actual;
4414         OUTPUT:
4415                 RETVAL
4416
4417 char*
4418 SoundSampleBuffer ( sample )
4419         Sound_Sample* sample
4420         CODE:
4421                 RETVAL = sample->buffer;
4422         OUTPUT:
4423                 RETVAL
4424
4425 Uint32
4426 SoundSampleBufferSize ( sample )
4427         Sound_Sample* sample
4428         CODE:
4429                 RETVAL = sample->buffer_size;
4430         OUTPUT:
4431                 RETVAL
4432
4433 Uint32
4434 SoundSampleFlags ( sample )
4435         Sound_Sample* sample
4436         CODE:
4437                 RETVAL = (Uint32)sample->flags;
4438         OUTPUT:
4439                 RETVAL
4440
4441 int
4442 Sound_Init ( )
4443         CODE:
4444                 RETVAL = Sound_Init();
4445         OUTPUT:
4446                 RETVAL
4447
4448 int
4449 Sound_Quit ( )
4450         CODE:
4451                 RETVAL = Sound_Quit();
4452         OUTPUT:
4453                 RETVAL
4454
4455 AV*
4456 Sound_AvailableDecoders ( )
4457         CODE:
4458                 RETVAL = newAV();
4459                 const Sound_DecoderInfo** sdi;
4460                 sdi = Sound_AvailableDecoders();
4461                 if (sdi != NULL)  {
4462                         for (;*sdi != NULL; ++sdi) {
4463                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
4464                         }
4465                 }
4466         OUTPUT:
4467                 RETVAL
4468
4469 const char*
4470 Sound_GetError ( )
4471         CODE:
4472                 RETVAL = Sound_GetError();
4473         OUTPUT:
4474                 RETVAL
4475
4476 void
4477 Sound_ClearError ( )
4478         CODE:
4479                 Sound_ClearError();
4480
4481 Sound_Sample*
4482 Sound_NewSample ( rw, ext, desired, buffsize )
4483         SDL_RWops* rw
4484         const char* ext
4485         Sound_AudioInfo* desired
4486         Uint32 buffsize
4487         CODE:
4488                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4489         OUTPUT:
4490                 RETVAL
4491
4492 Sound_Sample*
4493 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4494         const Uint8 *data
4495         Uint32 size
4496         const char* ext
4497         Sound_AudioInfo* desired
4498         Uint32 buffsize
4499         CODE:
4500                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4501         OUTPUT:
4502                 RETVAL
4503
4504 Sound_Sample*
4505 Sound_NewSampleFromFile ( fname, desired, buffsize )
4506         const char* fname
4507         Sound_AudioInfo* desired
4508         Uint32 buffsize
4509         CODE:
4510                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4511         OUTPUT:
4512                 RETVAL
4513
4514 void
4515 Sound_FreeSample ( sample )
4516         Sound_Sample* sample
4517         CODE:
4518                 Sound_FreeSample(sample);
4519
4520 Sint32
4521 Sound_GetDuration ( sample )
4522         Sound_Sample* sample
4523         CODE:
4524                 RETVAL = Sound_GetDuration(sample);
4525         OUTPUT:
4526                 RETVAL
4527
4528 int
4529 Sound_SetBufferSize ( sample, size )
4530         Sound_Sample* sample
4531         Uint32 size
4532         CODE:
4533                 RETVAL = Sound_SetBufferSize(sample,size);
4534         OUTPUT:
4535                 RETVAL
4536
4537 Uint32
4538 Sound_Decode ( sample )
4539         Sound_Sample* sample
4540         CODE:
4541                 RETVAL = Sound_Decode(sample);
4542         OUTPUT:
4543                 RETVAL
4544
4545 Uint32
4546 Sound_DecodeAll ( sample ) 
4547         Sound_Sample* sample
4548         CODE:
4549                 RETVAL = Sound_DecodeAll(sample);
4550         OUTPUT:
4551                 RETVAL
4552
4553 int
4554 Sound_Rewind ( sample )
4555         Sound_Sample* sample
4556         CODE:
4557                 RETVAL = Sound_Rewind(sample);
4558         OUTPUT:
4559                 RETVAL
4560
4561 int
4562 Sound_Seek ( sample, ms )
4563         Sound_Sample* sample
4564         Uint32 ms
4565         CODE:
4566                 RETVAL = Sound_Seek(sample,ms);
4567         OUTPUT:
4568                 RETVAL
4569
4570 #endif
4571
4572 MODULE = SDL            PACKAGE = SDL
4573 PROTOTYPES : DISABLE
4574
4575