more mem leak fixes
[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                 sv_2mortal((SV*)RETVAL);
2986         
2987         OUTPUT:
2988                 RETVAL
2989
2990 AV*
2991 TTFSizeUTF8 ( font, text )
2992         TTF_Font *font
2993         char *text
2994         CODE:
2995                 int w,h;
2996                 RETVAL = newAV();
2997                 TTF_SizeUTF8(font,text,&w,&h);
2998                         av_push(RETVAL,newSViv(w));
2999                         av_push(RETVAL,newSViv(h));
3000                 
3001                 sv_2mortal((SV*)RETVAL);
3002                 
3003         OUTPUT:
3004                 RETVAL
3005
3006 AV*
3007 TTFSizeUNICODE ( font, text )
3008         TTF_Font *font
3009         const Uint16 *text
3010         CODE:
3011                 int w,h;
3012                 RETVAL = newAV();
3013                 TTF_SizeUNICODE(font,text,&w,&h);
3014                 av_push(RETVAL,newSViv(w));
3015                 av_push(RETVAL,newSViv(h));
3016                 sv_2mortal((SV*)RETVAL);
3017
3018         OUTPUT:
3019                 RETVAL
3020
3021 SDL_Surface*
3022 TTFRenderTextSolid ( font, text, fg )
3023         TTF_Font *font
3024         char *text
3025         SDL_Color *fg
3026         CODE:
3027                 RETVAL = TTF_RenderText_Solid(font,text,*fg);
3028         OUTPUT:
3029                 RETVAL
3030
3031 SDL_Surface*
3032 TTFRenderUTF8Solid ( font, text, fg )
3033         TTF_Font *font
3034         char *text
3035         SDL_Color *fg
3036         CODE:
3037                 RETVAL = TTF_RenderUTF8_Solid(font,text,*fg);
3038         OUTPUT:
3039                 RETVAL
3040
3041 SDL_Surface*
3042 TTFRenderUNICODESolid ( font, text, fg )
3043         TTF_Font *font
3044         const Uint16 *text
3045         SDL_Color *fg
3046         CODE:
3047                 RETVAL = TTF_RenderUNICODE_Solid(font,text,*fg);
3048         OUTPUT:
3049                 RETVAL
3050
3051 SDL_Surface*
3052 TTFRenderGlyphSolid ( font, ch, fg )
3053         TTF_Font *font
3054         Uint16 ch
3055         SDL_Color *fg
3056         CODE:
3057                 RETVAL = TTF_RenderGlyph_Solid(font,ch,*fg);
3058         OUTPUT:
3059                 RETVAL
3060
3061 SDL_Surface*
3062 TTFRenderTextShaded ( font, text, fg, bg )
3063         TTF_Font *font
3064         char *text
3065         SDL_Color *fg
3066         SDL_Color *bg
3067         CODE:
3068                 RETVAL = TTF_RenderText_Shaded(font,text,*fg,*bg);
3069         OUTPUT:
3070                 RETVAL
3071
3072 SDL_Surface*
3073 TTFRenderUTF8Shaded( font, text, fg, bg )
3074         TTF_Font *font
3075         char *text
3076         SDL_Color *fg
3077         SDL_Color *bg
3078         CODE:
3079                 RETVAL = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3080         OUTPUT:
3081                 RETVAL
3082
3083 SDL_Surface*
3084 TTFRenderUNICODEShaded( font, text, fg, bg )
3085         TTF_Font *font
3086         const Uint16 *text
3087         SDL_Color *fg
3088         SDL_Color *bg
3089         CODE:
3090                 RETVAL = TTF_RenderUNICODE_Shaded(font,text,*fg,*bg);
3091         OUTPUT:
3092                 RETVAL
3093
3094 SDL_Surface*
3095 TTFRenderGlyphShaded ( font, ch, fg, bg )
3096         TTF_Font *font
3097         Uint16 ch
3098         SDL_Color *fg
3099         SDL_Color *bg
3100         CODE:
3101                 RETVAL = TTF_RenderGlyph_Shaded(font,ch,*fg,*bg);
3102         OUTPUT:
3103                 RETVAL
3104
3105 SDL_Surface*
3106 TTFRenderTextBlended( font, text, fg )
3107         TTF_Font *font
3108         char *text
3109         SDL_Color *fg
3110         CODE:
3111                 RETVAL = TTF_RenderText_Blended(font,text,*fg);
3112         OUTPUT:
3113                 RETVAL
3114
3115 SDL_Surface*
3116 TTFRenderUTF8Blended( font, text, fg )
3117         TTF_Font *font
3118         char *text
3119         SDL_Color *fg
3120         CODE:
3121                 RETVAL = TTF_RenderUTF8_Blended(font,text,*fg);
3122         OUTPUT:
3123                 RETVAL
3124
3125 SDL_Surface*
3126 TTFRenderUNICODEBlended( font, text, fg )
3127         TTF_Font *font
3128         const Uint16 *text
3129         SDL_Color *fg
3130         CODE:
3131                 RETVAL = TTF_RenderUNICODE_Blended(font,text,*fg);
3132         OUTPUT:
3133                 RETVAL
3134
3135 SDL_Surface*
3136 TTFRenderGlyphBlended( font, ch, fg )
3137         TTF_Font *font
3138         Uint16 ch
3139         SDL_Color *fg
3140         CODE:
3141                 RETVAL = TTF_RenderGlyph_Blended(font,ch,*fg);
3142         OUTPUT:
3143                 RETVAL
3144
3145 void
3146 TTFCloseFont ( font )
3147         TTF_Font *font
3148         CODE:
3149                 TTF_CloseFont(font);
3150                 font=NULL; //to be safe http://sdl.beuc.net/sdl.wiki/SDL_ttf_copy_Functions_Management_TTF_CloseFont
3151
3152 SDL_Surface*
3153 TTFPutString ( font, mode, surface, x, y, fg, bg, text )
3154         TTF_Font *font
3155         int mode
3156         SDL_Surface *surface
3157         int x
3158         int y
3159         SDL_Color *fg
3160         SDL_Color *bg
3161         char *text
3162         CODE:
3163                 SDL_Surface *img;
3164                 SDL_Rect dest;
3165                 int w,h;
3166                 dest.x = x;
3167                 dest.y = y;
3168                 RETVAL = NULL;
3169                 switch (mode) {
3170                         case TEXT_SOLID:
3171                                 img = TTF_RenderText_Solid(font,text,*fg);
3172                                 TTF_SizeText(font,text,&w,&h);
3173                                 dest.w = w;
3174                                 dest.h = h;
3175                                 break;
3176                         case TEXT_SHADED:
3177                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3178                                 TTF_SizeText(font,text,&w,&h);
3179                                 dest.w = w;
3180                                 dest.h = h;
3181                                 break;
3182                         case TEXT_BLENDED:
3183                                 img = TTF_RenderText_Blended(font,text,*fg);
3184                                 TTF_SizeText(font,text,&w,&h);
3185                                 dest.w = w;
3186                                 dest.h = h;
3187                                 break;
3188                         case UTF8_SOLID:
3189                                 img = TTF_RenderUTF8_Solid(font,text,*fg);
3190                                 TTF_SizeUTF8(font,text,&w,&h);
3191                                 dest.w = w;
3192                                 dest.h = h;
3193                                 break;
3194                         case UTF8_SHADED:
3195                                 img = TTF_RenderUTF8_Shaded(font,text,*fg,*bg);
3196                                 TTF_SizeUTF8(font,text,&w,&h);
3197                                 dest.w = w;
3198                                 dest.h = h;
3199                                 break;
3200                         case UTF8_BLENDED:
3201                                 img = TTF_RenderUTF8_Blended(font,text,*fg);
3202                                 TTF_SizeUTF8(font,text,&w,&h);
3203                                 dest.w = w;
3204                                 dest.h = h;
3205                                 break;
3206                         case UNICODE_SOLID:
3207                                 img = TTF_RenderUNICODE_Solid(font,(Uint16*)text,*fg);
3208                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3209                                 dest.w = w;
3210                                 dest.h = h;
3211                                 break;
3212                         case UNICODE_SHADED:
3213                                 img = TTF_RenderUNICODE_Shaded(font,(Uint16*)text,*fg,*bg);
3214                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3215                                 dest.w = w;
3216                                 dest.h = h;
3217                                 break;
3218                         case UNICODE_BLENDED:
3219                                 img = TTF_RenderUNICODE_Blended(font,(Uint16*)text,*fg);
3220                                 TTF_SizeUNICODE(font,(Uint16*)text,&w,&h);
3221                                 dest.w = w;
3222                                 dest.h = h;
3223                                 break;
3224                         default:
3225                                 img = TTF_RenderText_Shaded(font,text,*fg,*bg);
3226                                 TTF_SizeText(font,text,&w,&h);
3227                                 dest.w = w;
3228                                 dest.h = h;
3229                 }
3230                 if ( img && img->format && img->format->palette ) {
3231                         SDL_Color *c = &img->format->palette->colors[0];
3232                         Uint32 key = SDL_MapRGB( img->format, c->r, c->g, c->b );
3233                         SDL_SetColorKey(img,SDL_SRCCOLORKEY,key );
3234                         if (0 > SDL_BlitSurface(img,NULL,surface,&dest)) {
3235                                 SDL_FreeSurface(img);
3236                                 RETVAL = NULL;  
3237                         } else {
3238                                 RETVAL = img;
3239                         }
3240                 }
3241         OUTPUT:
3242                 RETVAL
3243
3244 #endif
3245
3246 SDL_Overlay*
3247 CreateYUVOverlay ( width, height, format, display )
3248         int width
3249         int height
3250         Uint32 format
3251         SDL_Surface *display
3252         CODE:
3253                 RETVAL = SDL_CreateYUVOverlay ( width, height, format, display );
3254         OUTPUT:
3255                 RETVAL
3256
3257 int
3258 LockYUVOverlay ( overlay )
3259         SDL_Overlay *overlay
3260         CODE:
3261                 RETVAL = SDL_LockYUVOverlay(overlay);
3262         OUTPUT:
3263                 RETVAL
3264
3265 void
3266 UnlockYUVOverlay ( overlay )
3267         SDL_Overlay *overlay
3268         CODE:
3269                 SDL_UnlockYUVOverlay(overlay);
3270
3271 int
3272 DisplayYUVOverlay ( overlay, dstrect )
3273         SDL_Overlay *overlay
3274         SDL_Rect *dstrect
3275         CODE:
3276                 RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
3277         OUTPUT:
3278                 RETVAL
3279
3280 void
3281 FreeYUVOverlay ( overlay )
3282         SDL_Overlay *overlay
3283         CODE:
3284                 SDL_FreeYUVOverlay ( overlay );
3285
3286 Uint32
3287 OverlayFormat ( overlay, ... )
3288         SDL_Overlay *overlay
3289         CODE:
3290                 if ( items > 1 ) 
3291                         overlay->format = SvIV(ST(1));
3292                 RETVAL = overlay->format;
3293         OUTPUT:
3294                 RETVAL
3295
3296 int 
3297 OverlayW ( overlay, ... )
3298         SDL_Overlay *overlay
3299         CODE:
3300                 if ( items > 1 ) 
3301                         overlay->w = SvIV(ST(1));
3302                 RETVAL = overlay->w;
3303         OUTPUT:
3304                 RETVAL
3305
3306 int
3307 OverlayH ( overlay, ... )
3308         SDL_Overlay *overlay
3309         CODE:
3310                 if ( items > 1 )
3311                         overlay->h = SvIV(ST(1));
3312                 RETVAL = overlay->h;
3313         OUTPUT:
3314                 RETVAL 
3315
3316 int
3317 OverlayPlanes ( overlay, ... )
3318         SDL_Overlay *overlay
3319         CODE:
3320                 if ( items > 1 )
3321                         overlay->planes = SvIV(ST(1));
3322                 RETVAL = overlay->planes;
3323         OUTPUT:
3324                 RETVAL
3325
3326 Uint32
3327 OverlayHW ( overlay )
3328         SDL_Overlay *overlay
3329         CODE:
3330                 RETVAL = overlay->hw_overlay;
3331         OUTPUT:
3332                 RETVAL
3333
3334 Uint16*
3335 OverlayPitches ( overlay )
3336         SDL_Overlay *overlay
3337         CODE:
3338                 RETVAL = overlay->pitches;
3339         OUTPUT:
3340                 RETVAL
3341
3342 Uint8**
3343 OverlayPixels ( overlay )
3344         SDL_Overlay *overlay
3345         CODE:
3346                 RETVAL = overlay->pixels;
3347         OUTPUT:
3348                 RETVAL
3349
3350 int
3351 WMToggleFullScreen ( surface )
3352         SDL_Surface *surface
3353         CODE:
3354                 RETVAL = SDL_WM_ToggleFullScreen(surface);
3355         OUTPUT:
3356                 RETVAL
3357
3358 Uint32
3359 WMGrabInput ( mode )
3360         Uint32 mode
3361         CODE:
3362                 RETVAL = SDL_WM_GrabInput(mode);
3363         OUTPUT:
3364                 RETVAL
3365
3366 int
3367 WMIconifyWindow ()
3368         CODE:
3369                 RETVAL = SDL_WM_IconifyWindow();
3370         OUTPUT:
3371                 RETVAL
3372
3373 int
3374 ResizeEventW ( e )
3375         SDL_Event *e
3376         CODE:
3377                 RETVAL = e->resize.w;
3378         OUTPUT:
3379                 RETVAL
3380
3381 int
3382 ResizeEventH ( e )
3383         SDL_Event *e
3384         CODE:
3385                 RETVAL = e->resize.h;
3386         OUTPUT:
3387                 RETVAL
3388
3389 char*
3390 AudioDriverName ()
3391         CODE:
3392                 char name[32];
3393                 RETVAL = SDL_AudioDriverName(name,32);
3394         OUTPUT:
3395                 RETVAL
3396
3397 Uint32
3398 GetKeyState ( k )
3399         SDLKey k
3400         CODE:
3401                 if (k >= SDLK_LAST) Perl_croak (aTHX_ "Key out of range");      
3402                 RETVAL = SDL_GetKeyState(NULL)[k];
3403         OUTPUT:
3404                 RETVAL
3405
3406 #ifdef HAVE_SMPEG
3407
3408 SMPEG_Info *
3409 NewSMPEGInfo()
3410         CODE:   
3411                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3412         OUTPUT:
3413                 RETVAL
3414
3415 void
3416 FreeSMPEGInfo ( info )
3417         SMPEG_Info *info
3418         CODE:   
3419                 safefree(info);
3420
3421 int
3422 SMPEGInfoHasAudio ( info )
3423         SMPEG_Info* info
3424         CODE:
3425                 RETVAL = info->has_audio;
3426         OUTPUT:
3427                 RETVAL
3428
3429 int
3430 SMPEGInfoHasVideo ( info )
3431         SMPEG_Info* info
3432         CODE:
3433                 RETVAL = info->has_video;
3434         OUTPUT:
3435                 RETVAL
3436
3437 int
3438 SMPEGInfoWidth ( info )
3439         SMPEG_Info* info
3440         CODE:
3441                 RETVAL = info->width;
3442         OUTPUT:
3443                 RETVAL
3444
3445 int
3446 SMPEGInfoHeight ( info )
3447         SMPEG_Info* info
3448         CODE:
3449                 RETVAL = info->height;
3450         OUTPUT:
3451                 RETVAL
3452
3453 int
3454 SMPEGInfoCurrentFrame ( info )
3455         SMPEG_Info* info
3456         CODE:
3457                 RETVAL = info->current_frame;
3458         OUTPUT:
3459                 RETVAL
3460
3461 double
3462 SMPEGInfoCurrentFPS ( info )
3463         SMPEG_Info* info
3464         CODE:
3465                 RETVAL = info->current_fps;
3466         OUTPUT:
3467                 RETVAL
3468
3469 int
3470 SMPEGInfoCurrentAudioFrame ( info )
3471         SMPEG_Info* info
3472         CODE:
3473                 RETVAL = info->audio_current_frame;
3474         OUTPUT:
3475                 RETVAL
3476
3477 int
3478 SMPEGInfoCurrentOffset ( info )
3479         SMPEG_Info* info
3480         CODE:
3481                 RETVAL = info->current_offset;
3482         OUTPUT:
3483                 RETVAL
3484
3485 int
3486 SMPEGInfoTotalSize ( info )
3487         SMPEG_Info* info
3488         CODE:
3489                 RETVAL = info->total_size;
3490         OUTPUT:
3491                 RETVAL
3492
3493 double
3494 SMPEGInfoCurrentTime ( info )
3495         SMPEG_Info* info
3496         CODE:
3497                 RETVAL = info->current_time;
3498         OUTPUT:
3499                 RETVAL
3500
3501 double
3502 SMPEGInfoTotalTime ( info )
3503         SMPEG_Info* info
3504         CODE:
3505                 RETVAL = info->total_time;
3506         OUTPUT:
3507                 RETVAL
3508
3509 char *
3510 SMPEGError ( mpeg )
3511         SMPEG* mpeg
3512         CODE:   
3513                 RETVAL = SMPEG_error(mpeg);
3514         OUTPUT:
3515                 RETVAL
3516
3517 SMPEG*
3518 NewSMPEG ( filename, info, use_audio )
3519         char* filename
3520         SMPEG_Info* info
3521         int use_audio
3522         CODE:   
3523 #ifdef HAVE_SDL_MIXER
3524                 RETVAL = SMPEG_new(filename,info,0);
3525 #else
3526                 RETVAL = SMPEG_new(filename,info,use_audio);
3527 #endif
3528         OUTPUT:
3529                 RETVAL
3530
3531 void
3532 FreeSMPEG ( mpeg )
3533         SMPEG* mpeg
3534         CODE:
3535                 SMPEG_delete(mpeg);
3536
3537 void
3538 SMPEGEnableAudio ( mpeg , flag )
3539         SMPEG* mpeg
3540         int flag
3541         CODE:   
3542                 SMPEG_enableaudio(mpeg,flag);
3543 #ifdef HAVE_SDL_MIXER
3544                 sdl_perl_use_smpeg_audio = flag;
3545 #endif
3546
3547 void
3548 SMPEGEnableVideo ( mpeg , flag )
3549         SMPEG* mpeg
3550         int flag
3551         CODE:   
3552                 SMPEG_enablevideo(mpeg,flag);
3553
3554 void
3555 SMPEGSetVolume ( mpeg , volume )
3556         SMPEG* mpeg
3557         int volume
3558         CODE:   
3559                 SMPEG_setvolume(mpeg,volume);
3560
3561 void
3562 SMPEGSetDisplay ( mpeg, dest, surfLock )
3563         SMPEG* mpeg
3564         SDL_Surface* dest
3565         SDL_mutex*  surfLock
3566         CODE:
3567                 SMPEG_setdisplay(mpeg,dest,surfLock,NULL);
3568
3569 void
3570 SMPEGScaleXY ( mpeg, w, h)
3571         SMPEG* mpeg
3572         int w
3573         int h
3574         CODE:
3575                 SMPEG_scaleXY(mpeg,w,h);
3576
3577 void
3578 SMPEGScale ( mpeg, scale )
3579         SMPEG* mpeg
3580         int scale
3581         CODE:
3582                 SMPEG_scale(mpeg,scale);
3583
3584 void
3585 SMPEGPlay ( mpeg )
3586         SMPEG* mpeg
3587         CODE:
3588                 SDL_AudioSpec audiofmt;
3589                 Uint16 format;
3590                 int freq, channels;
3591 #ifdef HAVE_SDL_MIXER
3592                 if  (sdl_perl_use_smpeg_audio ) {
3593                         SMPEG_enableaudio(mpeg, 0);
3594                         Mix_QuerySpec(&freq, &format, &channels);
3595                         audiofmt.format = format;
3596                         audiofmt.freq = freq;
3597                         audiofmt.channels = channels;
3598                         SMPEG_actualSpec(mpeg, &audiofmt);
3599                         Mix_HookMusic(SMPEG_playAudioSDL, mpeg);
3600                         SMPEG_enableaudio(mpeg, 1);
3601                 }
3602 #endif
3603                 SMPEG_play(mpeg);
3604
3605 SMPEGstatus
3606 SMPEGStatus ( mpeg )
3607         SMPEG* mpeg
3608         CODE:
3609                 RETVAL = SMPEG_status(mpeg);
3610         OUTPUT:
3611                 RETVAL
3612
3613 void
3614 SMPEGPause ( mpeg )
3615         SMPEG* mpeg
3616         CODE:
3617                 SMPEG_pause(mpeg);
3618
3619 void
3620 SMPEGLoop ( mpeg, repeat )
3621         SMPEG* mpeg
3622         int repeat
3623         CODE:
3624                 SMPEG_loop(mpeg,repeat);
3625
3626 void
3627 SMPEGStop ( mpeg )
3628         SMPEG* mpeg
3629         CODE:
3630                 SMPEG_stop(mpeg);
3631 #ifdef HAVE_SDL_MIXER
3632                 Mix_HookMusic(NULL, NULL);
3633 #endif
3634
3635 void
3636 SMPEGRewind ( mpeg )
3637         SMPEG* mpeg
3638         CODE:
3639                 SMPEG_rewind(mpeg);
3640
3641 void
3642 SMPEGSeek ( mpeg, bytes )
3643         SMPEG* mpeg
3644         int bytes
3645         CODE:
3646                 SMPEG_seek(mpeg,bytes);
3647
3648 void
3649 SMPEGSkip ( mpeg, seconds )
3650         SMPEG* mpeg
3651         float seconds
3652         CODE:
3653                 SMPEG_skip(mpeg,seconds);
3654
3655 void
3656 SMPEGSetDisplayRegion ( mpeg, rect )
3657         SMPEG* mpeg
3658         SDL_Rect* rect
3659         CODE:
3660                 SMPEG_setdisplayregion(mpeg,rect->x,rect->y,rect->w,rect->h);
3661
3662 void
3663 SMPEGRenderFrame ( mpeg, frame )
3664         SMPEG* mpeg
3665         int frame
3666         CODE:
3667                 SMPEG_renderFrame(mpeg,frame);
3668
3669 SMPEG_Info *
3670 SMPEGGetInfo ( mpeg )
3671         SMPEG* mpeg
3672         CODE:
3673                 RETVAL = (SMPEG_Info *) safemalloc (sizeof(SMPEG_Info));
3674                 SMPEG_getinfo(mpeg,RETVAL);
3675         OUTPUT:
3676                 RETVAL
3677         
3678
3679 #endif
3680
3681 #ifdef HAVE_SDL_GFX
3682
3683 SDL_Surface *
3684 GFXRotoZoom ( src, angle, zoom, smooth)
3685         SDL_Surface * src
3686         double angle
3687         double zoom
3688         int smooth
3689         CODE:
3690                 RETVAL = rotozoomSurface( src, angle, zoom, smooth);
3691         OUTPUT:
3692                 RETVAL
3693
3694 SDL_Surface *
3695 GFXZoom ( src, zoomx, zoomy, smooth)
3696         SDL_Surface *src
3697         double zoomx
3698         double zoomy
3699         int smooth
3700         CODE:
3701                 RETVAL = zoomSurface( src, zoomx, zoomy, smooth);
3702         OUTPUT:
3703                 RETVAL
3704
3705 int
3706 GFXPixelColor ( dst, x, y, color )
3707         SDL_Surface* dst
3708         Sint16 x
3709         Sint16 y
3710         Uint32 color
3711         CODE:
3712                 RETVAL = pixelColor( dst, x, y, color);
3713         OUTPUT:
3714                 RETVAL
3715
3716 int
3717 GFXPixelRGBA ( dst, x, y, r, g, b, a )
3718         SDL_Surface* dst
3719         Sint16 x
3720         Sint16 y
3721         Uint8 r
3722         Uint8 g
3723         Uint8 b
3724         Uint8 a
3725         CODE:
3726                 RETVAL = pixelRGBA( dst, x, y, r, g, b, a );
3727         OUTPUT:
3728                 RETVAL
3729
3730 int
3731 GFXHlineColor ( dst, x1, x2, y, color )
3732         SDL_Surface* dst
3733         Sint16 x1
3734         Sint16 x2
3735         Sint16 y
3736         Uint32 color
3737         CODE:
3738                 RETVAL = hlineColor( dst, x1, x2, y, color );
3739         OUTPUT:
3740                 RETVAL
3741
3742 int
3743 GFXHlineRGBA ( dst, x1, x2, y, r, g, b, a )
3744         SDL_Surface* dst
3745         Sint16 x1
3746         Sint16 x2
3747         Sint16 y
3748         Uint8 r
3749         Uint8 g
3750         Uint8 b
3751         Uint8 a
3752         CODE:
3753                 RETVAL = hlineRGBA( dst, x1, x2, y, r, g, b, a );
3754         OUTPUT:
3755                 RETVAL
3756
3757 int
3758 GFXVlineColor ( dst, x, y1, y2, color )
3759         SDL_Surface* dst
3760         Sint16 x
3761         Sint16 y1
3762         Sint16 y2
3763         Uint32 color
3764         CODE:
3765                 RETVAL = vlineColor( dst, x, y1, y2, color );
3766         OUTPUT:
3767                 RETVAL
3768
3769 int
3770 GFXVlineRGBA ( dst, x, y1, y2, r, g, b, a )
3771         SDL_Surface* dst
3772         Sint16 x
3773         Sint16 y1
3774         Sint16 y2
3775         Uint8 r
3776         Uint8 g
3777         Uint8 b
3778         Uint8 a
3779         CODE:
3780                 RETVAL = vlineRGBA( dst, x, y1, y2, r, g, b, a );
3781         OUTPUT:
3782                 RETVAL
3783
3784 int
3785 GFXRectangleColor ( dst, x1, y1, x2, y2, color )
3786         SDL_Surface* dst
3787         Sint16 x1
3788         Sint16 y1
3789         Sint16 x2
3790         Sint16 y2
3791         Uint32 color
3792         CODE:
3793                 RETVAL = rectangleColor( dst, x1, y1, x2, y2, color );
3794         OUTPUT:
3795                 RETVAL
3796
3797 int
3798 GFXRectangleRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3799         SDL_Surface* dst
3800         Sint16 x1
3801         Sint16 y1
3802         Sint16 x2
3803         Sint16 y2
3804         Uint8 r
3805         Uint8 g
3806         Uint8 b
3807         Uint8 a
3808         CODE:
3809                 RETVAL = rectangleRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3810         OUTPUT:
3811                 RETVAL
3812
3813 int
3814 GFXBoxColor ( dst, x1, y1, x2, y2, color )
3815         SDL_Surface* dst
3816         Sint16 x1
3817         Sint16 y1
3818         Sint16 x2
3819         Sint16 y2
3820         Uint32 color
3821         CODE:
3822                 RETVAL = boxColor( dst, x1, y1, x2, y2, color );
3823         OUTPUT:
3824                 RETVAL
3825
3826 int
3827 GFXBoxRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3828         SDL_Surface* dst;
3829         Sint16 x1
3830         Sint16 y1
3831         Sint16 x2
3832         Sint16 y2
3833         Uint8 r
3834         Uint8 g
3835         Uint8 b
3836         Uint8 a
3837         CODE:
3838                 RETVAL = boxRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3839         OUTPUT:
3840                 RETVAL
3841
3842 int
3843 GFXLineColor ( dst, x1, y1, x2, y2, color )
3844         SDL_Surface* dst
3845         Sint16 x1
3846         Sint16 y1
3847         Sint16 x2
3848         Sint16 y2
3849         Uint32 color
3850         CODE:
3851                 RETVAL = lineColor( dst, x1, y1, x2, y2, color );
3852         OUTPUT:
3853                 RETVAL
3854
3855 int
3856 GFXLineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3857         SDL_Surface* dst
3858         Sint16 x1
3859         Sint16 y1
3860         Sint16 x2
3861         Sint16 y2
3862         Uint8 r
3863         Uint8 g
3864         Uint8 b
3865         Uint8 a
3866         CODE:
3867                 RETVAL = lineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3868         OUTPUT:
3869                 RETVAL
3870
3871 int
3872 GFXAalineColor ( dst, x1, y1, x2, y2, color )
3873         SDL_Surface* dst
3874         Sint16 x1
3875         Sint16 y1
3876         Sint16 x2
3877         Sint16 y2
3878         Uint32 color
3879         CODE:
3880                 RETVAL = aalineColor( dst, x1, y1, x2, y2, color );
3881         OUTPUT:
3882                 RETVAL
3883
3884 int
3885 GFXAalineRGBA ( dst, x1, y1, x2, y2, r, g, b, a )
3886         SDL_Surface* dst
3887         Sint16 x1
3888         Sint16 y1
3889         Sint16 x2
3890         Sint16 y2
3891         Uint8 r
3892         Uint8 g
3893         Uint8 b
3894         Uint8 a
3895         CODE:
3896                 RETVAL = aalineRGBA( dst, x1, y1, x2, y2, r, g, b, a );
3897         OUTPUT:
3898                 RETVAL
3899
3900 int
3901 GFXCircleColor ( dst, x, y, r, color )
3902         SDL_Surface* dst
3903         Sint16 x
3904         Sint16 y
3905         Sint16 r
3906         Uint32 color
3907         CODE:
3908                 RETVAL = circleColor( dst, x, y, r, color );
3909         OUTPUT:
3910                 RETVAL
3911
3912 int
3913 GFXCircleRGBA ( dst, x, y, rad, r, g, b, a )
3914         SDL_Surface* dst
3915         Sint16 x
3916         Sint16 y
3917         Sint16 rad
3918         Uint8 r
3919         Uint8 g
3920         Uint8 b
3921         Uint8 a
3922         CODE:
3923                 RETVAL = circleRGBA( dst, x, y, rad, r, g, b, a );
3924         OUTPUT:
3925                 RETVAL
3926
3927 int
3928 GFXAacircleColor ( dst, x, y, r, color )
3929         SDL_Surface* dst
3930         Sint16 x
3931         Sint16 y
3932         Sint16 r
3933         Uint32 color
3934         CODE:
3935                 RETVAL = aacircleColor( dst, x, y, r, color );
3936         OUTPUT:
3937                 RETVAL
3938
3939 int
3940 GFXAacircleRGBA ( dst, x, y, rad, r, g, b, a )
3941         SDL_Surface* dst
3942         Sint16 x
3943         Sint16 y
3944         Sint16 rad
3945         Uint8 r
3946         Uint8 g
3947         Uint8 b
3948         Uint8 a
3949         CODE:
3950                 RETVAL = aacircleRGBA( dst, x, y, rad, r, g, b, a );
3951         OUTPUT:
3952                 RETVAL
3953
3954 int
3955 GFXFilledCircleColor ( dst, x, y, r, color )
3956         SDL_Surface* dst
3957         Sint16 x
3958         Sint16 y
3959         Sint16 r
3960         Uint32 color
3961         CODE:
3962                 RETVAL = filledCircleColor( dst, x, y, r, color );
3963         OUTPUT:
3964                 RETVAL
3965
3966 int
3967 GFXFilledCircleRGBA ( dst, x, y, rad, r, g, b, a )
3968         SDL_Surface* dst
3969         Sint16 x
3970         Sint16 y
3971         Sint16 rad
3972         Uint8 r
3973         Uint8 g
3974         Uint8 b
3975         Uint8 a
3976         CODE:
3977                 RETVAL = filledCircleRGBA( dst, x, y, rad, r, g, b, a );
3978         OUTPUT:
3979                 RETVAL
3980
3981 int
3982 GFXEllipseColor ( dst, x, y, rx, ry, color )
3983         SDL_Surface* dst
3984         Sint16 x
3985         Sint16 y
3986         Sint16 rx
3987         Sint16 ry
3988         Uint32 color
3989         CODE:
3990                 RETVAL = ellipseColor( dst, x, y, rx, ry, color );
3991         OUTPUT:
3992                 RETVAL
3993
3994 int
3995 GFXEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
3996         SDL_Surface* dst
3997         Sint16 x
3998         Sint16 y
3999         Sint16  rx
4000         Sint16 ry
4001         Uint8 r
4002         Uint8 g
4003         Uint8 b
4004         Uint8 a
4005         CODE:
4006                 RETVAL = ellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4007         OUTPUT:
4008                 RETVAL
4009
4010 int
4011 GFXAaellipseColor ( dst, xc, yc, rx, ry, color )
4012         SDL_Surface* dst
4013         Sint16 xc
4014         Sint16 yc
4015         Sint16 rx
4016         Sint16 ry
4017         Uint32 color
4018         CODE:
4019                 RETVAL = aaellipseColor( dst, xc, yc, rx, ry, color );
4020         OUTPUT:
4021                 RETVAL
4022
4023 int
4024 GFXAaellipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4025         SDL_Surface* dst
4026         Sint16 x
4027         Sint16 y
4028         Sint16 rx
4029         Sint16 ry
4030         Uint8 r
4031         Uint8 g
4032         Uint8 b
4033         Uint8 a
4034         CODE:
4035                 RETVAL = aaellipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4036         OUTPUT:
4037                 RETVAL
4038
4039 int
4040 GFXFilledEllipseColor ( dst, x, y, rx, ry, color )
4041         SDL_Surface* dst
4042         Sint16 x
4043         Sint16 y
4044         Sint16 rx
4045         Sint16 ry
4046         Uint32 color
4047         CODE:
4048                 RETVAL = filledEllipseColor( dst, x, y, rx, ry, color );
4049         OUTPUT:
4050                 RETVAL
4051
4052 int
4053 GFXFilledEllipseRGBA ( dst, x, y, rx, ry, r, g, b, a )
4054         SDL_Surface* dst
4055         Sint16 x
4056         Sint16 y
4057         Sint16 rx
4058         Sint16 ry
4059         Uint8 r
4060         Uint8 g
4061         Uint8 b
4062         Uint8 a
4063         CODE:
4064                 RETVAL = filledEllipseRGBA( dst, x, y, rx, ry, r, g, b, a );
4065         OUTPUT:
4066                 RETVAL
4067
4068 int
4069 GFXFilledPieColor ( dst, x, y, rad, start, end, color )
4070         SDL_Surface* dst
4071         Sint16 x
4072         Sint16 y
4073         Sint16 rad
4074         Sint16 start
4075         Sint16 end
4076         Uint32 color
4077         CODE:
4078                 RETVAL = filledPieColor( dst, x, y, rad, start, end, color );
4079         OUTPUT:
4080                 RETVAL
4081
4082 int
4083 GFXFilledPieRGBA ( dst, x, y, rad, start, end, r, g, b, a )
4084         SDL_Surface* dst
4085         Sint16 x
4086         Sint16 y
4087         Sint16 rad
4088         Sint16 start
4089         Sint16 end
4090         Uint8 r
4091         Uint8 g
4092         Uint8 b
4093         Uint8 a
4094         CODE:
4095                 RETVAL = filledPieRGBA( dst, x, y, rad, start, end, r, g, b, a );
4096         OUTPUT:
4097                 RETVAL
4098
4099 int
4100 GFXPolygonColor ( dst, vx, vy, n, color )
4101         SDL_Surface* dst
4102         Sint16* vx
4103         Sint16* vy
4104         int n
4105         Uint32 color;
4106         CODE:
4107                 RETVAL = polygonColor( dst, vx, vy, n, color );
4108         OUTPUT:
4109                 RETVAL
4110
4111 int
4112 GFXPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4113         SDL_Surface* dst
4114         Sint16* vx
4115         Sint16* vy
4116         int n
4117         Uint8 r
4118         Uint8 g
4119         Uint8 b
4120         Uint8 a
4121         CODE:
4122                 RETVAL = polygonRGBA( dst, vx, vy, n, r, g, b, a );
4123         OUTPUT:
4124                 RETVAL
4125
4126 int
4127 GFXAapolygonColor ( dst, vx, vy, n, color )
4128         SDL_Surface* dst
4129         Sint16* vx
4130         Sint16* vy
4131         int n
4132         Uint32 color
4133         CODE:
4134                 RETVAL = aapolygonColor( dst, vx, vy, n, color );
4135         OUTPUT:
4136                 RETVAL
4137
4138 int
4139 GFXAapolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4140         SDL_Surface* dst
4141         Sint16* vx
4142         Sint16* vy
4143         int n
4144         Uint8 r
4145         Uint8 g
4146         Uint8 b
4147         Uint8 a
4148         CODE:
4149                 RETVAL = aapolygonRGBA( dst, vx, vy, n, r, g, b, a );
4150         OUTPUT:
4151                 RETVAL
4152
4153 int
4154 GFXFilledPolygonColor ( dst, vx, vy, n, color )
4155         SDL_Surface* dst
4156         Sint16* vx
4157         Sint16* vy
4158         int n
4159         int color
4160         CODE:
4161                 RETVAL = filledPolygonColor( dst, vx, vy, n, color );
4162         OUTPUT:
4163                 RETVAL
4164
4165 int
4166 GFXFilledPolygonRGBA ( dst, vx, vy, n, r, g, b, a )
4167         SDL_Surface* dst
4168         Sint16* vx
4169         Sint16* vy
4170         int n
4171         Uint8 r
4172         Uint8 g
4173         Uint8 b
4174         Uint8 a
4175         CODE:
4176                 RETVAL = filledPolygonRGBA( dst, vx, vy, n, r, g, b, a );
4177         OUTPUT:
4178                 RETVAL
4179
4180 int
4181 GFXCharacterColor ( dst, x, y, c, color )
4182         SDL_Surface* dst
4183         Sint16 x
4184         Sint16 y
4185         char c
4186         Uint32 color
4187         CODE:
4188                 RETVAL = characterColor( dst, x, y, c, color );
4189         OUTPUT:
4190                 RETVAL
4191
4192 int
4193 GFXCharacterRGBA ( dst, x, y, c, r, g, b, a )
4194         SDL_Surface* dst
4195         Sint16 x
4196         Sint16 y
4197         char c
4198         Uint8 r
4199         Uint8 g
4200         Uint8 b
4201         Uint8 a
4202         CODE:
4203                 RETVAL = characterRGBA( dst, x, y, c, r, g, b, a );
4204         OUTPUT:
4205                 RETVAL
4206
4207 int
4208 GFXStringColor ( dst, x, y, c, color )
4209         SDL_Surface* dst
4210         Sint16 x
4211         Sint16 y
4212         char* c
4213         Uint32 color
4214         CODE:
4215                 RETVAL = stringColor( dst, x, y, c, color );
4216         OUTPUT:
4217                 RETVAL
4218
4219 int
4220 GFXStringRGBA ( dst, x, y, c, r, g, b, a )
4221         SDL_Surface* dst
4222         Sint16 x
4223         Sint16 y
4224         char* c
4225         Uint8 r
4226         Uint8 g
4227         Uint8 b
4228         Uint8 a
4229         CODE:
4230                 RETVAL = stringRGBA( dst, x, y, c, r, g, b, a );
4231         OUTPUT:
4232                 RETVAL
4233
4234 #endif
4235
4236
4237 #ifdef HAVE_SDL_SVG
4238
4239 SDL_svg_context *
4240 SVG_Load ( filename )
4241         char* filename
4242         CODE:
4243                 RETVAL = SVG_Load(filename);
4244         OUTPUT:
4245                 RETVAL
4246
4247 SDL_svg_context *
4248 SVG_LoadBuffer ( data, len )
4249         char* data
4250         int len
4251         CODE:
4252                 RETVAL = SVG_LoadBuffer(data,len);
4253         OUTPUT:
4254                 RETVAL
4255
4256 int
4257 SVG_SetOffset ( source, xoff, yoff )
4258         SDL_svg_context* source
4259         double xoff
4260         double yoff
4261         CODE:
4262                 RETVAL = SVG_SetOffset(source,xoff,yoff);
4263         OUTPUT:
4264                 RETVAL
4265
4266 int
4267 SVG_SetScale ( source, xscale, yscale )
4268         SDL_svg_context* source
4269         double xscale
4270         double yscale
4271         CODE:
4272                 RETVAL = SVG_SetScale(source,xscale,yscale);
4273         OUTPUT:
4274                 RETVAL
4275
4276 int
4277 SVG_RenderToSurface ( source, x, y, dest )
4278         SDL_svg_context* source
4279         int x
4280         int y
4281         SDL_Surface* dest;
4282         CODE:
4283                 RETVAL = SVG_RenderToSurface(source,x,y,dest);
4284         OUTPUT:
4285                 RETVAL
4286
4287 void
4288 SVG_Free ( source )
4289         SDL_svg_context* source
4290         CODE:
4291                 SVG_Free(source);       
4292
4293 void
4294 SVG_Set_Flags ( source, flags )
4295         SDL_svg_context* source
4296         Uint32 flags
4297         CODE:
4298                 SVG_Set_Flags(source,flags);
4299
4300 float
4301 SVG_Width ( source )
4302         SDL_svg_context* source
4303         CODE:
4304                 RETVAL = SVG_Width(source);
4305         OUTPUT:
4306                 RETVAL
4307
4308 float
4309 SVG_HEIGHT ( source )
4310         SDL_svg_context* source
4311         CODE:
4312                 RETVAL = SVG_Height(source);
4313         OUTPUT:
4314                 RETVAL
4315
4316 void
4317 SVG_SetClipping ( source, minx, miny, maxx, maxy )
4318         SDL_svg_context* source
4319         int minx
4320         int miny
4321         int maxx
4322         int maxy
4323         CODE:
4324                 SVG_SetClipping(source,minx,miny,maxx,maxy);
4325
4326 int
4327 SVG_Version ( )
4328         CODE:
4329                 RETVAL = SVG_Version();
4330         OUTPUT:
4331                 RETVAL
4332
4333
4334 #endif
4335
4336 #ifdef HAVE_SDL_SOUND
4337
4338 Uint16
4339 SoundAudioInfoFormat ( audioinfo )
4340         Sound_AudioInfo* audioinfo
4341         CODE:
4342                 RETVAL = audioinfo->format;
4343         OUTPUT:
4344                 RETVAL
4345
4346 Uint8
4347 SoundAudioInfoChannels ( audioinfo )
4348         Sound_AudioInfo* audioinfo
4349         CODE:
4350                 RETVAL = audioinfo->channels;
4351         OUTPUT:
4352                 RETVAL
4353
4354 Uint32
4355 SoundAudioInforate ( audioinfo )
4356         Sound_AudioInfo* audioinfo
4357         CODE:
4358                 RETVAL = audioinfo->rate;
4359         OUTPUT:
4360                 RETVAL
4361
4362 AV*
4363 SoundDecoderInfoExtensions ( decoderinfo )
4364         Sound_DecoderInfo* decoderinfo
4365         CODE:
4366                 const char **ext;
4367                 for ( ext = decoderinfo->extensions; *ext != NULL; ext++ ){
4368                         av_push(RETVAL,newSVpv(*ext,0));
4369                 }
4370         OUTPUT:
4371                 RETVAL
4372
4373 const char*
4374 SoundDecoderInfoDescription ( decoderinfo )
4375         Sound_DecoderInfo* decoderinfo
4376         CODE:
4377                 RETVAL = decoderinfo->description;
4378         OUTPUT:
4379                 RETVAL
4380
4381 const char*
4382 SoundDecoderInfoAuthor ( decoderinfo )
4383         Sound_DecoderInfo* decoderinfo
4384         CODE:
4385                 RETVAL = decoderinfo->author;
4386         OUTPUT:
4387                 RETVAL
4388
4389 const char*
4390 SoundDecoderInfoUrl ( decoderinfo )
4391         Sound_DecoderInfo* decoderinfo
4392         CODE:
4393                 RETVAL = decoderinfo->url;
4394         OUTPUT:
4395                 RETVAL
4396
4397 const Sound_DecoderInfo*
4398 SoundSampleDecoder ( sample ) 
4399         Sound_Sample* sample
4400         CODE:
4401                 RETVAL = sample->decoder;
4402         OUTPUT:
4403                 RETVAL
4404
4405 Sound_AudioInfo* 
4406 SoundSampleDesired ( sample )
4407         Sound_Sample* sample
4408         CODE:
4409                 RETVAL = &sample->desired;
4410         OUTPUT:
4411                 RETVAL
4412
4413 Sound_AudioInfo*
4414 SoundSampleAcutal ( sample )
4415         Sound_Sample* sample
4416         CODE:
4417                 RETVAL = &sample->actual;
4418         OUTPUT:
4419                 RETVAL
4420
4421 char*
4422 SoundSampleBuffer ( sample )
4423         Sound_Sample* sample
4424         CODE:
4425                 RETVAL = sample->buffer;
4426         OUTPUT:
4427                 RETVAL
4428
4429 Uint32
4430 SoundSampleBufferSize ( sample )
4431         Sound_Sample* sample
4432         CODE:
4433                 RETVAL = sample->buffer_size;
4434         OUTPUT:
4435                 RETVAL
4436
4437 Uint32
4438 SoundSampleFlags ( sample )
4439         Sound_Sample* sample
4440         CODE:
4441                 RETVAL = (Uint32)sample->flags;
4442         OUTPUT:
4443                 RETVAL
4444
4445 int
4446 Sound_Init ( )
4447         CODE:
4448                 RETVAL = Sound_Init();
4449         OUTPUT:
4450                 RETVAL
4451
4452 int
4453 Sound_Quit ( )
4454         CODE:
4455                 RETVAL = Sound_Quit();
4456         OUTPUT:
4457                 RETVAL
4458
4459 AV*
4460 Sound_AvailableDecoders ( )
4461         CODE:
4462                 RETVAL = newAV();
4463                 const Sound_DecoderInfo** sdi;
4464                 sdi = Sound_AvailableDecoders();
4465                 if (sdi != NULL)  {
4466                         for (;*sdi != NULL; ++sdi) {
4467                                 av_push(RETVAL,sv_2mortal(newSViv(PTR2IV(*sdi))));
4468                         }
4469                 }
4470         OUTPUT:
4471                 RETVAL
4472
4473 const char*
4474 Sound_GetError ( )
4475         CODE:
4476                 RETVAL = Sound_GetError();
4477         OUTPUT:
4478                 RETVAL
4479
4480 void
4481 Sound_ClearError ( )
4482         CODE:
4483                 Sound_ClearError();
4484
4485 Sound_Sample*
4486 Sound_NewSample ( rw, ext, desired, buffsize )
4487         SDL_RWops* rw
4488         const char* ext
4489         Sound_AudioInfo* desired
4490         Uint32 buffsize
4491         CODE:
4492                 RETVAL = Sound_NewSample(rw,ext,desired,buffsize);
4493         OUTPUT:
4494                 RETVAL
4495
4496 Sound_Sample*
4497 Sound_NewSampleFromMem ( data, size, ext, desired, buffsize )
4498         const Uint8 *data
4499         Uint32 size
4500         const char* ext
4501         Sound_AudioInfo* desired
4502         Uint32 buffsize
4503         CODE:
4504                 RETVAL = Sound_NewSampleFromMem(data,size,ext,desired,buffsize);
4505         OUTPUT:
4506                 RETVAL
4507
4508 Sound_Sample*
4509 Sound_NewSampleFromFile ( fname, desired, buffsize )
4510         const char* fname
4511         Sound_AudioInfo* desired
4512         Uint32 buffsize
4513         CODE:
4514                 RETVAL = Sound_NewSampleFromFile(fname,desired,buffsize);
4515         OUTPUT:
4516                 RETVAL
4517
4518 void
4519 Sound_FreeSample ( sample )
4520         Sound_Sample* sample
4521         CODE:
4522                 Sound_FreeSample(sample);
4523
4524 Sint32
4525 Sound_GetDuration ( sample )
4526         Sound_Sample* sample
4527         CODE:
4528                 RETVAL = Sound_GetDuration(sample);
4529         OUTPUT:
4530                 RETVAL
4531
4532 int
4533 Sound_SetBufferSize ( sample, size )
4534         Sound_Sample* sample
4535         Uint32 size
4536         CODE:
4537                 RETVAL = Sound_SetBufferSize(sample,size);
4538         OUTPUT:
4539                 RETVAL
4540
4541 Uint32
4542 Sound_Decode ( sample )
4543         Sound_Sample* sample
4544         CODE:
4545                 RETVAL = Sound_Decode(sample);
4546         OUTPUT:
4547                 RETVAL
4548
4549 Uint32
4550 Sound_DecodeAll ( sample ) 
4551         Sound_Sample* sample
4552         CODE:
4553                 RETVAL = Sound_DecodeAll(sample);
4554         OUTPUT:
4555                 RETVAL
4556
4557 int
4558 Sound_Rewind ( sample )
4559         Sound_Sample* sample
4560         CODE:
4561                 RETVAL = Sound_Rewind(sample);
4562         OUTPUT:
4563                 RETVAL
4564
4565 int
4566 Sound_Seek ( sample, ms )
4567         Sound_Sample* sample
4568         Uint32 ms
4569         CODE:
4570                 RETVAL = Sound_Seek(sample,ms);
4571         OUTPUT:
4572                 RETVAL
4573
4574 #endif
4575
4576 MODULE = SDL            PACKAGE = SDL
4577 PROTOTYPES : DISABLE
4578
4579