0fdf4359fabe2ae9bbe720ac2269e7e4ddbb4bc5
[sdlgit/SDL_perl.git] / lib / SDL.pm
1 #
2 # Copyright (C) 2004 David J. Goehrig
3 # Copyright (C) 2009 Kartik Thakore
4
5 package SDL;
6
7 use strict;
8 use warnings;
9 use Carp;
10
11 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
12
13 require Exporter;
14 require DynaLoader;
15
16 use SDL_perl;
17 use SDL::Constants;
18
19 BEGIN {
20         @ISA = qw(Exporter DynaLoader);
21         @EXPORT = qw( in verify &NULL );
22         # reexport all SDL constants
23         for (@SDL::Constants::EXPORT) {
24                 push @EXPORT,$_;
25         }
26 };
27
28
29 $VERSION = '2.1.3';
30
31 print "$VERSION" if (defined($ARGV[0]) && ($ARGV[0] eq '--SDLperl'));
32
33 $SDL::DEBUG=1;
34
35 sub NULL {
36         return 0;
37 }
38
39 sub in {
40         my ($k,@t) = @_;
41         (scalar grep { defined $_ && $_ eq $k } @t) <=> 0;
42
43
44 sub verify (\%@) {
45         my ($options,@valid_options) = @_;
46         for (keys %$options) {
47                 croak "Invalid option $_\n" unless in ($_, @valid_options);
48         }
49 }
50
51
52 1;
53 __END__
54
55 =head1 NAME
56
57 SDL_perl - Simple DirectMedia Layer for Perl
58
59 =head1 SYNOPSIS
60
61   use SDL;
62
63 =head1 DESCRIPTION
64
65 SDL_perl is a package of perl modules that provides both functional and object orient
66 interfaces to the Simple DirectMedia Layer for Perl 5.  This package does take some
67 liberties with the SDL API, and attempts to adhere to the spirit of both the SDL
68 and Perl.  This document describes the low-level functional SDL_perl API.  For the
69 object oriented programming interface please see the documentation provided on a
70 per class basis.
71
72 =head2 Init(flags) 
73
74 As with the C language API, SDL_perl initializes the SDL environment through
75 the C<SDL::Init> subroutine.  This routine takes a mode flag constructed through
76 the bitwise OR product of the following functions:  
77
78 =over 4
79
80 =item *
81 INIT_AUDIO()
82
83 =item *
84 INIT_VIDEO()
85
86 =item *
87 INIT_CDROM()
88
89 =item *
90 INIT_EVERYTHING()
91
92 =item *
93 INIT_NOPARACHUTE() 
94
95 =item *
96 INIT_JOYSTICK()
97
98 =item *
99 INIT_TIMER()
100
101 =back
102
103 C<SDL::Init> returns 0 on success, or -1 on error.
104
105 =head2 GetError()
106
107 The last error message set by the SDL library can be retrieved using the subroutine
108 C<SDL::GetError>, which returns a scalar containing the text of the message if any.
109
110 =head2 Delay(ms)
111
112 This subroutine allows an application to delay further operations for atleast a
113 number of milliseconds provided as the argument.  The actual delay may be longer
114 than the specified depending on the underlying OS.
115
116 =head2 GetTicks() 
117
118 An application may retrieve the number of milliseconds expired since the initilization
119 of the application through this subroutine.  This value resets rougly ever 49 days.
120
121 =head2 AddTimer(interval,callback,param)
122
123 C<AddTimer> will register a SDL_NewTimerCallback function to be executed after
124 C<interval> milliseconds, with parameter C<param>.  SDL_NewTimerCallback objects
125 can be constructed with the C<NewTimer> subroutine.   C<SDL::PerlTimerCallback>
126 will return a valid callback for executing a perl subroutine or closure.
127 This subroutine returns a SDL_TimerID for the newly registered callback, or NULL 
128 on error.
129
130 =head2 NewTimer(interval,subroutine)
131
132 The C<NewTimer> takes an interval in milliseconds and a reference to a subroutine
133 to call at that interval.  The subroutine will be invoked in a void context
134 and accepts no parameters.  The callback used is that returned by C<SDL::PerlTimerCallback>.
135 C<NewTimer> returns the SDL_TimerID for the new timer or NULL on error.
136
137 =head2 RemoveTimer(id)
138
139 This subroutine taks a SDL_TimerID and removes it from the list of active callbacks.
140 RemoveTimer returns false on failure.
141
142 =head2 SetTimer 
143
144 This subroutine is depreciated, please use C<NewTimer> or C<AddTimer> instead.
145
146 =head2 CDNumDrives() 
147
148 C<SDL::CDNumDrives> returns the number of available CD-ROM drives in the system.
149
150 =head2 CDName(drive)
151
152 The subroutine C<SDL::CDName> returns the system specific human readable device name
153 for the given CD-ROM drive.
154
155 =head2 CDOpen(drive)
156
157 This subroutine opens a CD-ROM drive for access, returning NULL if the drive is busy 
158 or otherwise unavailable.  On success this subroutine returns a handle to the CD-ROM
159 drive.
160
161 =head2 CDTrackListing(cd)
162
163 C<SDL::CDTrackListing> returns a human readable description of a CD-ROM.  For each
164 track one line will be produced with the following format:
165
166         Track index: %d, id %d, %2d.%2d 
167
168 This is provided to ease the creation of human readable descriptions and debugging.
169
170 =head2 CDTrackId(track) 
171
172 C<CDTrackId> returns the id field of the given SDL_CDtrack structure.
173
174 =head2 CDTrackType(track)
175
176 C<CDTrackType> returns the type field of the given SDL_CDtrack structure.
177
178 =head2 CDTrackLength(track)
179
180 C<CDTrackLength> returns the length field of the given SDL_CDtrack structure.
181
182 =head2 CDTrackOffset(track)
183
184 C<CDTrackOffset> returns the offset field of the given SDL_CDtrack structure.
185
186 =head2 CDStatus(cd)
187
188 The function C<CDStatus> returns the current status of the given SDL_CDrom.
189 C<CDStatus>'s return values are:
190
191 =over 4
192
193 =item *
194 CD_TRAYEMPTY 
195
196 =item *
197 CD_PLAYING 
198
199 =item *
200 CD_STOPPED
201
202 =item *
203 CD_PAUSED 
204
205 =item *
206 CD_ERROR 
207
208 =back
209
210 =head2 CDPlayTracks(cd,track,tracks,frame,frames)
211
212 To start playing from an arbitrary portion of a CD, one can provide
213 C<SDL::CDPlayTracks> with a CD, a starting track, the number of tracks,
214 a starting frame, and the number of frames to be played. 
215
216 =head2 CDPlay(cd,track,length) 
217
218 C<SDL::CDPlay> plays the next C<length> tracks starting from C<track>
219
220 =head2 CDPause(cd) 
221
222 This function will pause CD playback until resume is called.
223
224 =head2 CDResume(cd) 
225
226 This function will resume CD playback if paused.
227
228 =head2 CDStop(cd) 
229
230 C<SDL::CDStop> will stop CD playback if playing.
231
232 =head2 CDEject(cd) 
233
234 This function will eject the CD
235
236 =head2 CDClose(cd) 
237
238 This function will release an opened CD. 
239
240 =head2 CDNumTracks 
241
242 =head2 CDCurTrack 
243
244 =head2 CDCurFrame 
245
246 =head2 CDTrack 
247
248 =head2 PumpEvents 
249
250 =head2 NewEvent 
251
252 =head2 FreeEvent
253
254 =head2 PollEvent 
255
256 =head2 WaitEvent 
257
258 =head2 EventState 
259
260 =head2 IGNORE 
261
262 =head2 ENABLE 
263
264 =head2 QUERY 
265
266 =head2 ACTIVEEVENT
267
268 =head2 KEYDOWN 
269
270 =head2 KEYUP 
271
272 =head2 MOUSEMOTION 
273
274 =head2 MOUSEBUTTONDOWN 
275
276 =head2 MOUSEBUTTONUP 
277
278 =head2 QUIT 
279
280 =head2 SYSWMEVENT 
281
282 =head2 EventType 
283
284 =head2 ActiveEventGain 
285
286 =head2 ActiveEventState 
287
288 =head2 APPMOUSEFOCUS 
289
290 =head2 APPINPUTFOCUS 
291
292 =head2 APPACTIVE 
293
294 =head2 KeyEventState
295
296 =head2 SDLK_BACKSPACE 
297
298 =head2 SDLK_TAB 
299
300 =head2 SDLK_CLEAR 
301
302 =head2 SDLK_RETURN 
303
304 =head2 SDLK_PAUSE 
305
306 =head2 SDLK_ESCAPE 
307
308 =head2 SDLK_SPACE 
309
310 =head2 SDLK_EXCLAIM 
311
312 =head2 SDLK_QUOTEDBL 
313
314 =head2 SDLK_HASH 
315
316 =head2 SDLK_DOLLAR 
317
318 =head2 SDLK_AMPERSAND 
319
320 =head2 SDLK_QUOTE 
321
322 =head2 SDLK_LEFTPAREN 
323
324 =head2 SDLK_RIGHTPAREN 
325
326 =head2 SDLK_ASTERISK 
327
328 =head2 SDLK_PLUS 
329
330 =head2 SDLK_COMMA 
331
332 =head2 SDLK_MINUS 
333
334 =head2 SDLK_PERIOD 
335
336 =head2 SDLK_SLASH 
337
338 =head2 SDLK_0 
339
340 =head2 SDLK_1 
341
342 =head2 SDLK_2 
343
344 =head2 SDLK_3 
345
346 =head2 SDLK_4 
347
348 =head2 SDLK_5 
349
350 =head2 SDLK_6 
351
352 =head2 SDLK_7 
353
354 =head2 SDLK_8 
355
356 =head2 SDLK_9 
357
358 =head2 SDLK_COLON 
359
360 =head2 SDLK_SEMICOLON 
361
362 =head2 SDLK_LESS 
363
364 =head2 SDLK_EQUALS 
365
366 =head2 SDLK_GREATER 
367
368 =head2 SDLK_QUESTION 
369
370 =head2 SDLK_AT 
371
372 =head2 SDLK_LEFTBRACKET 
373
374 =head2 SDLK_BACKSLASH 
375
376 =head2 SDLK_RIGHTBRACKET 
377
378 =head2 SDLK_CARET 
379
380 =head2 SDLK_UNDERSCORE 
381
382 =head2 SDLK_BACKQUOTE 
383
384 =head2 SDLK_a 
385
386 =head2 SDLK_b 
387
388 =head2 SDLK_c 
389
390 =head2 SDLK_d 
391
392 =head2 SDLK_e 
393
394 =head2 SDLK_f 
395
396 =head2 SDLK_g 
397
398 =head2 SDLK_h 
399
400 =head2 SDLK_i 
401
402 =head2 SDLK_j 
403
404 =head2 SDLK_k 
405
406 =head2 SDLK_l 
407
408 =head2 SDLK_m 
409
410 =head2 SDLK_n 
411
412 =head2 SDLK_o 
413
414 =head2 SDLK_p 
415
416 =head2 SDLK_q 
417
418 =head2 SDLK_r 
419
420 =head2 SDLK_s 
421
422 =head2 SDLK_t 
423
424 =head2 SDLK_u 
425
426 =head2 SDLK_v 
427
428 =head2 SDLK_w 
429
430 =head2 SDLK_x 
431
432 =head2 SDLK_y 
433
434 =head2 SDLK_z 
435
436 =head2 SDLK_DELETE 
437
438 =head2 SDLK_KP0 
439
440 =head2 SDLK_KP1 
441
442 =head2 SDLK_KP2 
443
444 =head2 SDLK_KP3 
445
446 =head2 SDLK_KP4 
447
448 =head2 SDLK_KP5 
449
450 =head2 SDLK_KP6 
451
452 =head2 SDLK_KP7 
453
454 =head2 SDLK_KP8 
455
456 =head2 SDLK_KP9 
457
458 =head2 SDLK_KP_PERIOD 
459
460 =head2 SDLK_KP_DIVIDE 
461
462 =head2 SDLK_KP_MULTIPLY 
463
464 =head2 SDLK_KP_MINUS 
465
466 =head2 SDLK_KP_PLUS 
467
468 =head2 SDLK_KP_ENTER 
469
470 =head2 SDLK_KP_EQUALS 
471
472 =head2 SDLK_UP 
473
474 =head2 SDLK_DOWN 
475
476 =head2 SDLK_RIGHT 
477
478 =head2 SDLK_LEFT 
479
480 =head2 SDLK_INSERT 
481
482 =head2 SDLK_HOME 
483
484 =head2 SDLK_END 
485
486 =head2 SDLK_PAGEUP 
487
488 =head2 SDLK_PAGEDOWN 
489
490 =head2 SDLK_F1 
491
492 =head2 SDLK_F2 
493
494 =head2 SDLK_F3 
495
496 =head2 SDLK_F4 
497
498 =head2 SDLK_F5 
499
500 =head2 SDLK_F6 
501
502 =head2 SDLK_F7 
503
504 =head2 SDLK_F8 
505
506 =head2 SDLK_F9 
507
508 =head2 SDLK_F10 
509
510 =head2 SDLK_F11 
511
512 =head2 SDLK_F12 
513
514 =head2 SDLK_F13 
515
516 =head2 SDLK_F14 
517
518 =head2 SDLK_F15 
519
520 =head2 SDLK_NUMLOCK 
521
522 =head2 SDLK_CAPSLOCK 
523
524 =head2 SDLK_SCROLLOCK 
525
526 =head2 SDLK_RSHIFT 
527
528 =head2 SDLK_LSHIFT 
529
530 =head2 SDLK_RCTRL 
531
532 =head2 SDLK_LCTRL 
533
534 =head2 SDLK_RALT 
535
536 =head2 SDLK_LALT 
537
538 =head2 SDLK_RMETA 
539
540 =head2 SDLK_LMETA 
541
542 =head2 SDLK_LSUPER 
543
544 =head2 SDLK_RSUPER 
545
546 =head2 SDLK_MODE 
547
548 =head2 SDLK_HELP 
549
550 =head2 SDLK_PRINT 
551
552 =head2 SDLK_SYSREQ 
553
554 =head2 SDLK_BREAK 
555
556 =head2 SDLK_MENU 
557
558 =head2 SDLK_POWER 
559
560 =head2 SDLK_EURO 
561
562 =head2 KMOD_NONE 
563
564 =head2 KMOD_NUM 
565
566 =head2 KMOD_CAPS 
567
568 =head2 KMOD_LCTRL 
569
570 =head2 KMOD_RCTRL 
571
572 =head2 KMOD_RSHIFT 
573
574 =head2 KMOD_LSHIFT 
575
576 =head2 KMOD_RALT 
577
578 =head2 KMOD_LALT 
579
580 =head2 KMOD_CTRL 
581
582 =head2 KMOD_SHIFT 
583
584 =head2 KMOD_ALT 
585
586 =head2 KeyEventSym 
587
588 =head2 KeyEventMod 
589
590 =head2 KeyEventUnicode 
591
592 =head2 KeyEventScanCode 
593
594 =head2 MouseMotionState 
595
596 =head2 MouseMotionX 
597
598 =head2 MouseMotionY 
599
600 =head2 MouseMotionXrel
601
602 =head2 MouseMotionYrel 
603
604 =head2 MouseButtonState 
605
606 =head2 MouseButton 
607
608 =head2 MouseButtonX 
609
610 =head2 MouseButtonY 
611
612 =head2 SysWMEventMsg 
613
614 =head2 EnableUnicode 
615
616 =head2 EnableKeyRepeat 
617
618 =head2 GetKeyName 
619
620 =head2 PRESSED 
621
622 =head2 RELEASED 
623
624 =head2 CreateRGBSurface 
625
626 =head2 CreateRGBSurfaceFrom 
627
628 =head2 IMG_Load 
629
630 =head2 FreeSurface 
631
632 =head2 SurfacePalette 
633
634 =head2 SurfaceBitsPerPixel 
635
636 =head2 SurfaceBytesPerPixel 
637
638 =head2 SurfaceRshift 
639
640 =head2 SurfaceGshift 
641
642 =head2 SurfaceBshift 
643
644 =head2 SurfaceAshift 
645
646 =head2 SurfaceRmask
647
648 =head2 SurfaceGmask 
649
650 =head2 SurfaceBmask 
651
652 =head2 SurfaceAmask 
653
654 =head2 SurfaceColorKey 
655
656 =head2 SurfaceAlpha
657
658 =head2 SurfaceW 
659
660 =head2 SurfaceH 
661
662 =head2 SurfacePitch 
663
664 =head2 SurfacePixels 
665
666 =head2 SurfacePixel 
667
668 =head2 MUSTLOCK 
669
670 =head2 SurfaceLock 
671
672 =head2 SurfaceUnlock 
673
674 =head2 GetVideoSurface 
675
676 =head2 VideoInfo 
677
678 =head2 NewRect 
679
680 =head2 FreeRect 
681
682 =head2 RectX 
683
684 =head2 RectY 
685
686 =head2 RectW 
687
688 =head2 RectH 
689
690 =head2 NewColor 
691
692 =head2 ColorR 
693
694 =head2 ColorG 
695
696 =head2 CologB 
697
698 =head2 FreeColor 
699
700 =head2 NewPalette 
701
702 =head2 PaletteNColors 
703
704 =head2 PaletteColors 
705
706 =head2 SWSURFACE 
707
708 =head2 HWSURFACE 
709
710 =head2 ANYFORMAT 
711
712 =head2 HWPALETTE 
713
714 =head2 DOUBLEBUF 
715
716 =head2 FULLSCREEN 
717
718 =head2 ASYNCBLIT 
719
720 =head2 OPENGL 
721
722 =head2 HWACCEL 
723
724 =head2 VideoModeOK 
725
726 =head2 SetVideoMode 
727
728 =head2 UpdateRects 
729
730 =head2 Flip 
731
732 =head2 SetColors 
733
734 =head2 MapRGB (surface,r,g,b)
735
736 C<SDL::MapRGB> translates the composite red (r), green (g), blue (b)
737 colors according to the given surface to a interger color value.  This
738 integer can be used in functions like C<SDL::FillRect>, and is not
739 the same as the format independent Color object returned by C<SDL::NewColor>.
740
741 =head2 MapRGBA (surface,r,g,b,a)
742
743 C<SDL::MapRGBA> works as C<SDL::MapRGB> but takes an additional alpha (a)
744 component for semi-transperant colors.
745
746 =head2 GetRGB 
747
748 =head2 GetRGBA 
749
750 =head2 SaveBMP 
751
752 =head2 SetColorKey 
753
754 =head2 SRCCOLORKEY 
755
756 =head2 RLEACCEL 
757
758 =head2 SRCALPHA 
759
760 =head2 SetAlpha 
761
762 =head2 DisplayFormat 
763
764 =head2 BlitSurface 
765
766 =head2 FillRect(surface,rect,color)
767         
768 C<SDL::FillRect> draws a solid rectangle of color on the given surface.
769 If the rectangle is NULL, the entire surface will be painted.
770
771 =head2 WMSetCaption 
772
773 =head2 WMGetCaption 
774
775 =head2 WMSetIcon 
776
777 =head2 WarpMouse 
778
779 =head2 NewCursor 
780
781 =head2 FreeCursor 
782
783 =head2 SetCursor 
784
785 =head2 GetCursor 
786
787 =head2 ShowCursor 
788
789 =head2 NewAudioSpec 
790
791 =head2 FreeAudioSpec 
792
793 =head2 AUDIO_U8 
794
795 =head2 AUDIO_S8 
796
797 =head2 AUDIO_U16 
798
799 =head2 AUDIO_S16 
800
801 =head2 AUDIO_U16MSB 
802
803 =head2 AUDIO_S16MSB 
804
805 =head2 NewAudioCVT 
806
807 =head2 FreeAudioCVT 
808
809 =head2 ConvertAudioData 
810
811 =head2 OpenAudio 
812
813 =head2 PauseAudio 
814
815 =head2 UnlockAudio 
816
817 =head2 CloseAudio 
818
819 =head2 FreeWAV 
820
821 =head2 LoadWAV 
822
823 =head2 MixAudio 
824
825 =head2 MIX_MAX_VOLUME 
826
827 =head2 MIX_DEFAULT_FREQUENCY 
828
829 =head2 MIX_DEFAULT_FORMAT 
830
831 =head2 MIX_DEFAULT_CHANNELS 
832
833 =head2 MIX_NO_FADING 
834
835 =head2 MIX_FADING_OUT 
836
837 =head2 MIX_FADING_IN 
838
839 =head2 MixOpenAudio 
840
841 =head2 MixAllocateChannels 
842
843 =head2 MixQuerySpec 
844
845 =head2 MixLoadWAV 
846
847 =head2 MixLoadMusic 
848
849 =head2 MixQuickLoadWAV 
850
851 =head2 MixFreeChunk
852
853 =head2 MixFreeMusic 
854
855 =head2 MixSetPostMixCallback 
856
857 =head2 MixSetMusicHook 
858
859 =head2 MixSetMusicFinishedHook 
860
861 =head2 MixGetMusicHookData 
862
863 =head2 MixReverseChannels 
864
865 =head2 MixGroupChannel 
866
867 =head2 MixGroupChannels 
868
869 =head2 MixGroupAvailable 
870
871 =head2 MixGroupCount 
872
873 =head2 MixGroupOldest 
874
875 =head2 MixGroupNewer 
876
877 =head2 MixPlayChannel 
878
879 =head2 MixPlayChannelTimed 
880
881 =head2 MixPlayMusic 
882
883 =head2 MixFadeInChannel 
884
885 =head2 MixFadeInChannelTimed 
886
887 =head2 MixFadeInMusic 
888
889 =head2 MixVolume 
890
891 =head2 MixVolumeChunk 
892
893 =head2 MixVolumeMusic 
894
895 =head2 MixHaltChannel 
896
897 =head2 MixHaltGroup 
898
899 =head2 MixHaltMusic 
900
901 =head2 MixExpireChannel 
902
903 =head2 MixFadeOutChannel 
904
905 =head2 MixFadeOutGroup 
906
907 =head2 MixFadeOutMusic 
908
909 =head2 MixFadingMusic
910
911 =head2 MixFadingChannel
912
913 =head2 MixPause 
914
915 =head2 MixResume 
916
917 =head2 MixPaused 
918
919 =head2 MixPauseMusic 
920
921 =head2 MixResumeMusic 
922
923 =head2 MixRewindMusic 
924
925 =head2 MixPausedMusic 
926
927 =head2 MixPlaying
928
929 =head2 MixPlayingMusic
930
931 =head2 MixCloseAudio 
932
933 =head2 NewFont 
934
935 =head2 UseFont 
936
937 =head2 PutString 
938
939 =head2 TextWidth 
940
941 =head2 GL_RED_SIZE 
942
943 =head2 GL_GREEN_SIZE 
944
945 =head2 GL_BLUE_SIZE 
946
947 =head2 GL_ALPHA_SIZE 
948
949 =head2 GL_ACCUM_RED_SIZE 
950
951 =head2 GL_ACCUM_GREEN_SIZE 
952
953 =head2 GL_ACCUM_BLUE_SIZE 
954
955 =head2 GL_ACCUM_ALPHA_SIZE 
956
957 =head2 GL_BUFFER_SIZE 
958
959 =head2 GL_DEPTH_SIZE 
960
961 =head2 GL_STENCIL_SIZE 
962
963 =head2 GL_DOUBLEBUFFER 
964
965 =head2 GL_SetAttribute 
966
967 =head2 GL_GetAttribute 
968
969 =head2 GL_SwapBuffers 
970
971 =head2 BigEndian 
972
973 =head2 NumJoysticks 
974
975 =head2 JoystickName 
976
977 =head2 JoystickOpen 
978
979 =head2 JoystickOpened 
980
981 =head2 JoystickIndex 
982
983 =head2 JoystickNumAxes 
984
985 =head2 JoystickNumBalls 
986
987 =head2 JoystickNumHats 
988
989 =head2 JoystickNumButtons 
990
991 =head2 JoystickUpdate 
992
993 =head2 JoystickGetAxis 
994
995 =head2 JoystickGetHat 
996
997 =head2 JoystickGetButton 
998
999 =head2 JoystickGetBall 
1000
1001 =head2 JoystickClose 
1002
1003 =head1 AUTHOR
1004
1005 David J. Goehrig
1006
1007 =head1 CONTRIBUTORS
1008
1009 David J. Goehrig, Wayne Keenan, Guillaume Cottenceau
1010
1011 =head1 SEE ALSO
1012
1013         perl(1) SDL::App(3) SDL::Surface(3) SDL::Event(3) SDL::Rect(3) 
1014         SDL::Palette(3) SDL::Mixer(3) SDL::Cdrom(3)
1015
1016 =cut
1017