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