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