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