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