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