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