(no commit message)
[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}
f53193aa 57$VERSION = '2.2.2.17';
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
24379be6 111
bfd90409 112=item *
113INIT_AUDIO()
114
115=item *
116INIT_VIDEO()
117
118=item *
119INIT_CDROM()
120
121=item *
122INIT_EVERYTHING()
123
124=item *
125INIT_NOPARACHUTE()
126
127=item *
128INIT_JOYSTICK()
129
130=item *
131INIT_TIMER()
132
133=back
134
135C<SDL::Init> returns 0 on success, or -1 on error.
136
137=head2 GetError()
138
139The last error message set by the SDL library can be retrieved using the subroutine
140C<SDL::GetError>, which returns a scalar containing the text of the message if any.
141
142=head2 Delay(ms)
143
144This subroutine allows an application to delay further operations for atleast a
145number of milliseconds provided as the argument. The actual delay may be longer
146than the specified depending on the underlying OS.
147
148=head2 GetTicks()
149
150An application may retrieve the number of milliseconds expired since the initilization
151of the application through this subroutine. This value resets rougly ever 49 days.
152
153=head2 AddTimer(interval,callback,param)
154
155C<AddTimer> will register a SDL_NewTimerCallback function to be executed after
156C<interval> milliseconds, with parameter C<param>. SDL_NewTimerCallback objects
157can be constructed with the C<NewTimer> subroutine. C<SDL::PerlTimerCallback>
158will return a valid callback for executing a perl subroutine or closure.
159This subroutine returns a SDL_TimerID for the newly registered callback, or NULL
160on error.
161
162=head2 NewTimer(interval,subroutine)
163
164The C<NewTimer> takes an interval in milliseconds and a reference to a subroutine
165to call at that interval. The subroutine will be invoked in a void context
166and accepts no parameters. The callback used is that returned by C<SDL::PerlTimerCallback>.
167C<NewTimer> returns the SDL_TimerID for the new timer or NULL on error.
168
169=head2 RemoveTimer(id)
170
171This subroutine taks a SDL_TimerID and removes it from the list of active callbacks.
172RemoveTimer returns false on failure.
173
174=head2 SetTimer
175
176This subroutine is depreciated, please use C<NewTimer> or C<AddTimer> instead.
177
178=head2 CDNumDrives()
179
180C<SDL::CDNumDrives> returns the number of available CD-ROM drives in the system.
181
182=head2 CDName(drive)
183
184The subroutine C<SDL::CDName> returns the system specific human readable device name
185for the given CD-ROM drive.
186
187=head2 CDOpen(drive)
188
189This subroutine opens a CD-ROM drive for access, returning NULL if the drive is busy
190or otherwise unavailable. On success this subroutine returns a handle to the CD-ROM
191drive.
192
193=head2 CDTrackListing(cd)
194
195C<SDL::CDTrackListing> returns a human readable description of a CD-ROM. For each
196track one line will be produced with the following format:
197
198 Track index: %d, id %d, %2d.%2d
199
200This is provided to ease the creation of human readable descriptions and debugging.
201
202=head2 CDTrackId(track)
203
204C<CDTrackId> returns the id field of the given SDL_CDtrack structure.
205
206=head2 CDTrackType(track)
207
208C<CDTrackType> returns the type field of the given SDL_CDtrack structure.
209
210=head2 CDTrackLength(track)
211
212C<CDTrackLength> returns the length field of the given SDL_CDtrack structure.
213
214=head2 CDTrackOffset(track)
215
216C<CDTrackOffset> returns the offset field of the given SDL_CDtrack structure.
217
218=head2 CDStatus(cd)
219
220The function C<CDStatus> returns the current status of the given SDL_CDrom.
221C<CDStatus>'s return values are:
222
223=over 4
224
225=item *
226CD_TRAYEMPTY
227
228=item *
229CD_PLAYING
230
231=item *
232CD_STOPPED
233
234=item *
235CD_PAUSED
236
237=item *
238CD_ERROR
239
240=back
241
242=head2 CDPlayTracks(cd,track,tracks,frame,frames)
243
244To start playing from an arbitrary portion of a CD, one can provide
245C<SDL::CDPlayTracks> with a CD, a starting track, the number of tracks,
246a starting frame, and the number of frames to be played.
247
248=head2 CDPlay(cd,track,length)
249
250C<SDL::CDPlay> plays the next C<length> tracks starting from C<track>
251
252=head2 CDPause(cd)
253
254This function will pause CD playback until resume is called.
255
256=head2 CDResume(cd)
257
258This function will resume CD playback if paused.
259
260=head2 CDStop(cd)
261
262C<SDL::CDStop> will stop CD playback if playing.
263
264=head2 CDEject(cd)
265
266This function will eject the CD
267
268=head2 CDClose(cd)
269
270This function will release an opened CD.
271
272=head2 CDNumTracks
273
274=head2 CDCurTrack
275
276=head2 CDCurFrame
277
278=head2 CDTrack
279
280=head2 PumpEvents
281
282=head2 NewEvent
283
284=head2 FreeEvent
285
286=head2 PollEvent
287
288=head2 WaitEvent
289
290=head2 EventState
291
292=head2 IGNORE
293
294=head2 ENABLE
295
296=head2 QUERY
297
298=head2 ACTIVEEVENT
299
300=head2 KEYDOWN
301
302=head2 KEYUP
303
304=head2 MOUSEMOTION
305
306=head2 MOUSEBUTTONDOWN
307
308=head2 MOUSEBUTTONUP
309
310=head2 QUIT
311
312=head2 SYSWMEVENT
313
314=head2 EventType
315
316=head2 ActiveEventGain
317
318=head2 ActiveEventState
319
320=head2 APPMOUSEFOCUS
321
322=head2 APPINPUTFOCUS
323
324=head2 APPACTIVE
325
326=head2 KeyEventState
327
328=head2 SDLK_BACKSPACE
329
330=head2 SDLK_TAB
331
332=head2 SDLK_CLEAR
333
334=head2 SDLK_RETURN
335
336=head2 SDLK_PAUSE
337
338=head2 SDLK_ESCAPE
339
340=head2 SDLK_SPACE
341
342=head2 SDLK_EXCLAIM
343
344=head2 SDLK_QUOTEDBL
345
346=head2 SDLK_HASH
347
348=head2 SDLK_DOLLAR
349
350=head2 SDLK_AMPERSAND
351
352=head2 SDLK_QUOTE
353
354=head2 SDLK_LEFTPAREN
355
356=head2 SDLK_RIGHTPAREN
357
358=head2 SDLK_ASTERISK
359
360=head2 SDLK_PLUS
361
362=head2 SDLK_COMMA
363
364=head2 SDLK_MINUS
365
366=head2 SDLK_PERIOD
367
368=head2 SDLK_SLASH
369
370=head2 SDLK_0
371
372=head2 SDLK_1
373
374=head2 SDLK_2
375
376=head2 SDLK_3
377
378=head2 SDLK_4
379
380=head2 SDLK_5
381
382=head2 SDLK_6
383
384=head2 SDLK_7
385
386=head2 SDLK_8
387
388=head2 SDLK_9
389
390=head2 SDLK_COLON
391
392=head2 SDLK_SEMICOLON
393
394=head2 SDLK_LESS
395
396=head2 SDLK_EQUALS
397
398=head2 SDLK_GREATER
399
400=head2 SDLK_QUESTION
401
402=head2 SDLK_AT
403
404=head2 SDLK_LEFTBRACKET
405
406=head2 SDLK_BACKSLASH
407
408=head2 SDLK_RIGHTBRACKET
409
410=head2 SDLK_CARET
411
412=head2 SDLK_UNDERSCORE
413
414=head2 SDLK_BACKQUOTE
415
416=head2 SDLK_a
417
418=head2 SDLK_b
419
420=head2 SDLK_c
421
422=head2 SDLK_d
423
424=head2 SDLK_e
425
426=head2 SDLK_f
427
428=head2 SDLK_g
429
430=head2 SDLK_h
431
432=head2 SDLK_i
433
434=head2 SDLK_j
435
436=head2 SDLK_k
437
438=head2 SDLK_l
439
440=head2 SDLK_m
441
442=head2 SDLK_n
443
444=head2 SDLK_o
445
446=head2 SDLK_p
447
448=head2 SDLK_q
449
450=head2 SDLK_r
451
452=head2 SDLK_s
453
454=head2 SDLK_t
455
456=head2 SDLK_u
457
458=head2 SDLK_v
459
460=head2 SDLK_w
461
462=head2 SDLK_x
463
464=head2 SDLK_y
465
466=head2 SDLK_z
467
468=head2 SDLK_DELETE
469
470=head2 SDLK_KP0
471
472=head2 SDLK_KP1
473
474=head2 SDLK_KP2
475
476=head2 SDLK_KP3
477
478=head2 SDLK_KP4
479
480=head2 SDLK_KP5
481
482=head2 SDLK_KP6
483
484=head2 SDLK_KP7
485
486=head2 SDLK_KP8
487
488=head2 SDLK_KP9
489
490=head2 SDLK_KP_PERIOD
491
492=head2 SDLK_KP_DIVIDE
493
494=head2 SDLK_KP_MULTIPLY
495
496=head2 SDLK_KP_MINUS
497
498=head2 SDLK_KP_PLUS
499
500=head2 SDLK_KP_ENTER
501
502=head2 SDLK_KP_EQUALS
503
504=head2 SDLK_UP
505
506=head2 SDLK_DOWN
507
508=head2 SDLK_RIGHT
509
510=head2 SDLK_LEFT
511
512=head2 SDLK_INSERT
513
514=head2 SDLK_HOME
515
516=head2 SDLK_END
517
518=head2 SDLK_PAGEUP
519
520=head2 SDLK_PAGEDOWN
521
522=head2 SDLK_F1
523
524=head2 SDLK_F2
525
526=head2 SDLK_F3
527
528=head2 SDLK_F4
529
530=head2 SDLK_F5
531
532=head2 SDLK_F6
533
534=head2 SDLK_F7
535
536=head2 SDLK_F8
537
538=head2 SDLK_F9
539
540=head2 SDLK_F10
541
542=head2 SDLK_F11
543
544=head2 SDLK_F12
545
546=head2 SDLK_F13
547
548=head2 SDLK_F14
549
550=head2 SDLK_F15
551
552=head2 SDLK_NUMLOCK
553
554=head2 SDLK_CAPSLOCK
555
556=head2 SDLK_SCROLLOCK
557
558=head2 SDLK_RSHIFT
559
560=head2 SDLK_LSHIFT
561
562=head2 SDLK_RCTRL
563
564=head2 SDLK_LCTRL
565
566=head2 SDLK_RALT
567
568=head2 SDLK_LALT
569
570=head2 SDLK_RMETA
571
572=head2 SDLK_LMETA
573
574=head2 SDLK_LSUPER
575
576=head2 SDLK_RSUPER
577
578=head2 SDLK_MODE
579
580=head2 SDLK_HELP
581
582=head2 SDLK_PRINT
583
584=head2 SDLK_SYSREQ
585
586=head2 SDLK_BREAK
587
588=head2 SDLK_MENU
589
590=head2 SDLK_POWER
591
592=head2 SDLK_EURO
593
594=head2 KMOD_NONE
595
596=head2 KMOD_NUM
597
598=head2 KMOD_CAPS
599
600=head2 KMOD_LCTRL
601
602=head2 KMOD_RCTRL
603
604=head2 KMOD_RSHIFT
605
606=head2 KMOD_LSHIFT
607
608=head2 KMOD_RALT
609
610=head2 KMOD_LALT
611
612=head2 KMOD_CTRL
613
614=head2 KMOD_SHIFT
615
616=head2 KMOD_ALT
617
618=head2 KeyEventSym
619
620=head2 KeyEventMod
621
622=head2 KeyEventUnicode
623
624=head2 KeyEventScanCode
625
626=head2 MouseMotionState
627
628=head2 MouseMotionX
629
630=head2 MouseMotionY
631
632=head2 MouseMotionXrel
633
634=head2 MouseMotionYrel
635
636=head2 MouseButtonState
637
638=head2 MouseButton
639
640=head2 MouseButtonX
641
642=head2 MouseButtonY
643
644=head2 SysWMEventMsg
645
646=head2 EnableUnicode
647
648=head2 EnableKeyRepeat
649
650=head2 GetKeyName
651
652=head2 PRESSED
653
654=head2 RELEASED
655
656=head2 CreateRGBSurface
657
658=head2 CreateRGBSurfaceFrom
659
660=head2 IMG_Load
661
662=head2 FreeSurface
663
664=head2 SurfacePalette
665
666=head2 SurfaceBitsPerPixel
667
f53193aa 668=head2 SurfaceBy