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