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