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