5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6 # Copyright (C) 2009 Kartik Thakore <kthakore@cpan.org>
7 # ------------------------------------------------------------------------------
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.
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.
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
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
37 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
46 @ISA = qw(Exporter DynaLoader);
47 @EXPORT = qw( in verify &NULL );
50 # Give our caller SDL::Constant's stuff as well as ours.
54 $self->export_to_level(1, @_);
55 SDL::Constants->export_to_level(1);
59 print "$VERSION" if (defined($ARGV[0]) && ($ARGV[0] eq '--SDLperl'));
69 return 0 unless defined $k;
70 my $r = ((scalar grep { defined $_ && $_ eq $k } @t) <=> 0);
77 my ($options,@valid_options) = @_;
78 for (keys %$options) {
79 croak "Invalid option $_\n" unless in ($_, @valid_options);
89 SDL_perl - Simple DirectMedia Layer for Perl
97 SDL_perl is a package of perl modules that provides both functional and object orient
98 interfaces to the Simple DirectMedia Layer for Perl 5. This package does take some
99 liberties with the SDL API, and attempts to adhere to the spirit of both the SDL
100 and Perl. This document describes the low-level functional SDL_perl API. For the
101 object oriented programming interface please see the documentation provided on a
104 =head1 The SDL Perl 2009 Development Team
110 =head2 Perl Development
113 Name: Breno G. de Oliveira
126 =head1 MacOSX Experimental Usage
128 Please get libsdl packages from Fink
135 =head2 Running SDL Perl Scripts in MacOSX
137 First set the PERL5LIB environment variable to the dependencies of your script
139 %export PERL5LIB=$PERL5LIB:./lib
141 Use the SDLPerl executable made in the bundle and call your scripts
143 %SDLPerl.app/Contents/MacOS/SDLPerl yourScript.pl
145 =head1 Functions exported by SDL.pm
149 As with the C language API, SDL_perl initializes the SDL environment through
150 the C<SDL::Init> subroutine. This routine takes a mode flag constructed through
151 the bitwise OR product of the following functions:
178 C<SDL::Init> returns 0 on success, or -1 on error.
182 The last error message set by the SDL library can be retrieved using the subroutine
183 C<SDL::GetError>, which returns a scalar containing the text of the message if any.
187 This subroutine allows an application to delay further operations for atleast a
188 number of milliseconds provided as the argument. The actual delay may be longer
189 than the specified depending on the underlying OS.
193 An application may retrieve the number of milliseconds expired since the initilization
194 of the application through this subroutine. This value resets rougly ever 49 days.
196 =head2 AddTimer(interval,callback,param)
198 C<AddTimer> will register a SDL_NewTimerCallback function to be executed after
199 C<interval> milliseconds, with parameter C<param>. SDL_NewTimerCallback objects
200 can be constructed with the C<NewTimer> subroutine. C<SDL::PerlTimerCallback>
201 will return a valid callback for executing a perl subroutine or closure.
202 This subroutine returns a SDL_TimerID for the newly registered callback, or NULL
205 =head2 NewTimer(interval,subroutine)
207 The C<NewTimer> takes an interval in milliseconds and a reference to a subroutine
208 to call at that interval. The subroutine will be invoked in a void context
209 and accepts no parameters. The callback used is that returned by C<SDL::PerlTimerCallback>.
210 C<NewTimer> returns the SDL_TimerID for the new timer or NULL on error.
212 =head2 RemoveTimer(id)
214 This subroutine taks a SDL_TimerID and removes it from the list of active callbacks.
215 RemoveTimer returns false on failure.
219 This subroutine is depreciated, please use C<NewTimer> or C<AddTimer> instead.
223 C<SDL::CDNumDrives> returns the number of available CD-ROM drives in the system.
227 The subroutine C<SDL::CDName> returns the system specific human readable device name
228 for the given CD-ROM drive.
232 This subroutine opens a CD-ROM drive for access, returning NULL if the drive is busy
233 or otherwise unavailable. On success this subroutine returns a handle to the CD-ROM
236 =head2 CDTrackListing(cd)
238 C<SDL::CDTrackListing> returns a human readable description of a CD-ROM. For each
239 track one line will be produced with the following format:
241 Track index: %d, id %d, %2d.%2d
243 This is provided to ease the creation of human readable descriptions and debugging.
245 =head2 CDTrackId(track)
247 C<CDTrackId> returns the id field of the given SDL_CDtrack structure.
249 =head2 CDTrackType(track)
251 C<CDTrackType> returns the type field of the given SDL_CDtrack structure.
253 =head2 CDTrackLength(track)
255 C<CDTrackLength> returns the length field of the given SDL_CDtrack structure.
257 =head2 CDTrackOffset(track)
259 C<CDTrackOffset> returns the offset field of the given SDL_CDtrack structure.
263 The function C<CDStatus> returns the current status of the given SDL_CDrom.
264 C<CDStatus>'s return values are:
285 =head2 CDPlayTracks(cd,track,tracks,frame,frames)
287 To start playing from an arbitrary portion of a CD, one can provide
288 C<SDL::CDPlayTracks> with a CD, a starting track, the number of tracks,
289 a starting frame, and the number of frames to be played.
291 =head2 CDPlay(cd,track,length)
293 C<SDL::CDPlay> plays the next C<length> tracks starting from C<track>
297 This function will pause CD playback until resume is called.
301 This function will resume CD playback if paused.
305 C<SDL::CDStop> will stop CD playback if playing.
309 This function will eject the CD.
313 This function will release an opened CD.
317 This function return the number of tracks on a CD,
318 it take a SDL_CD as first parameter.
322 This function return the number of the current track on a CD,
323 it take a SDL_CD as first parameter.
327 this function return the frame offset within the current track on a CD.
328 it take a SDL_CD as first parameter.
332 CDtrack stores data on each track on a CD, its fields should be pretty self explainatory.
333 CDtrack take a SDL::CD as input and return a SDL_CDTrack.
337 Pumps the event loop, gathering events from the input devices.
339 PumpEvents gathers all the pending input information from devices and places
340 it on the event queue.
341 Without calls to PumpEvents no events would ever be placed on the queue.
342 Often the need for calls to PumpEvents is hidden from the user
343 since L</ PollEvent> and WaitEvent implicitly call PumpEvents.
344 However, if you are not polling or waiting for events (e.g. you are filtering them),
345 then you must call PumpEvents to force an event queue update.
346 PumpEvents doesn't return any value and doesn't take any parameters.
348 Note: You can only call this function in the thread that set the video mode.
352 Create a new event.It return a SDL::Event.
356 FreeEvent delete the SDL::Event given as first parameter.
357 it doesn't return anything.
361 Polls for currently pending events.
362 If event is not undef, the next event is removed from the queue and returned as a L< SDL::Event>.
363 As this function implicitly calls L</ PumpEvents>, you can only call this function in the thread that set the video mode.
364 it take a SDL::Event as first parameter.
368 Waits indefinitely for the next available event, returning undef if there was an error while waiting for events,
369 a L< SDL::Event> otherwise.
370 If event is not NULL, the next event is removed.
371 As this function implicitly calls L</ PumpEvents>, you can only call this function in the thread that set the video mode.
372 WaitEvent take a SDL::Event as first parameter.
376 This function allows you to set the state of processing certain event types.
378 it take an event type as first argument, and a state as second.
380 If state is set to SDL_IGNORE, that event type will be automatically
381 dropped from the event queue and will not be filtered.
382 If state is set to SDL_ENABLE, that event type will be processed
384 If state is set to SDL_QUERY, SDL_EventState will return the current
385 processing state of the specified event type.
387 A list of event types can be found in the L</ SDL_Event section>.
389 it returns a state(?).
405 =head2 MOUSEBUTTONDOWN
415 EventType return the type of the SDL::Event given as first parameter.
417 =head2 ActiveEventGain
419 ActiveEventGain return the active gain from the SDL::Event given as first parameter.
420 see L</ SDL::Event> for more informations about the active state.
422 =head2 ActiveEventState
424 ActiveEventState return the active state from the SDL::Event given as first parameter.
425 see L</ SDL::Event> for more informations about the active state.
435 KeyEventState return the active key state from the SDL::Event given as first parameter.
436 see L</ SDL::Event> for me more informations about the active key.
438 =head2 SDLK_BACKSPACE
460 =head2 SDLK_AMPERSAND
464 =head2 SDLK_LEFTPAREN
466 =head2 SDLK_RIGHTPAREN
502 =head2 SDLK_SEMICOLON
514 =head2 SDLK_LEFTBRACKET
516 =head2 SDLK_BACKSLASH
518 =head2 SDLK_RIGHTBRACKET
522 =head2 SDLK_UNDERSCORE
524 =head2 SDLK_BACKQUOTE
600 =head2 SDLK_KP_PERIOD
602 =head2 SDLK_KP_DIVIDE
604 =head2 SDLK_KP_MULTIPLY
612 =head2 SDLK_KP_EQUALS
666 =head2 SDLK_SCROLLOCK
730 KeyEventSym return the key pressed/released information from the SDL::Event given as first parameter.
731 see L</ SDL::Event> for more informations about the keyboard events.
735 KeyEventMod return the mod keys pressed information from the SDL::Event given as first parameter.
736 see L</ SDL::Event> for more informations about the keyboard events.
738 =head2 KeyEventUnicode
740 KeyEventMod return the unicode translated keys pressed/released information from the SDL::Event given as first parameter.
741 see L</ SDL::Event> for more informations about the keyboard events.
743 =head2 KeyEventScanCode
745 =head2 MouseMotionState
751 =head2 MouseMotionXrel
753 =head2 MouseMotionYrel
755 =head2 MouseButtonState
767 =head2 EnableKeyRepeat
775 =head2 CreateRGBSurface
777 =head2 CreateRGBSurfaceFrom
783 =head2 SurfacePalette
785 =head2 SurfaceBitsPerPixel