3 # A package for handling SDL_Event *
5 # Copyright (C) 2000,2001,2002 David J. Goehrig
6 # Copyright (C) 2009 Kartik Thakore
7 # see the file COPYING for terms of use
19 my $class = ref($proto) || $proto;
21 $self = \SDL::NewEvent();
28 SDL::FreeEvent($$self);
34 SDL::SetEventType($$self,$_[0]);
36 return SDL::EventType($$self);
45 return SDL::PollEvent($$self);
50 my ($event, $numEvents, $action, $mask) = @_;
51 return SDL::PeepEvents($$event, $numEvents, $action, $mask);
56 return SDL::PushEvent($$self);
61 return SDL::WaitEvent($$self);
67 return SDL::EventState($self->type(),$state);
73 return SDL::EnableUnicode($toggle);
80 return SDL::EnableKeyRepeat($delay,$interval);
85 return SDL::ActiveEventGain($$self);
90 return SDL::ActiveEventState($$self);
95 return SDL::KeyEventState($$self);
100 return SDL::KeyEventSym($$self);
105 return SDL::GetKeyName(SDL::KeyEventSym($$self));
110 return SDL::KeyEventMod($$self);
115 return SDL::KeyEventUnicode($$self);
120 return SDL::KeyEventScanCode($$self);
125 return SDL::MouseMotionState($$self);
130 return SDL::MouseMotionX($$self);
135 return SDL::MouseMotionY($$self);
140 return SDL::MouseMotionXrel($$self);
145 return SDL::MouseMotionYrel($$self);
150 return SDL::MouseButtonState($$self);
155 return SDL::MouseButtonX($$self);
160 return SDL::MouseButtonY($$self);
165 return SDL::MouseButton($$self);
170 SDL::ResizeEventW($$self);
175 SDL::ResizeEventH($$self);
186 SDL::Event - a SDL perl extension
191 my $event = new SDL::Event; # create a new event
192 while ($event->wait()) {
193 my $type = $event->type(); # get event type
195 exit if $type == SDL_QUIT;
200 C<SDL::Event> offers an object-oriented approach to SDL events. By creating
201 an instance of SDL::Event via new() you can wait for events, and then determine
202 the type of the event and take an appropriate action.
206 Here is an example of a simple event handler loop routine.
207 See also L<SDL::App::loop>.
210 my ($self,$href) = @_;
211 my $event = new SDL::Event;
212 while ( $event->wait() ) {
213 # ... insert here your event handling like:
214 if ( ref($$href{$event->type()}) eq "CODE" ) {
215 &{$$href{$event->type()}}($event);
225 Create a new event object.
229 Returns the type of the event, see list of exported symbols for which are
234 Pumps the event loop, gathering events from the input devices.
238 Polls for currently pending events
242 Checks the event queue for messages and optionally returns them.
244 If action is SDL_ADDEVENT, up to numevents events will be added to the back of the event queue.
246 If action is SDL_PEEKEVENT, up to numevents events at the front of the event queue, matching mask, will be returned and will not be removed from the queue.
248 If action is SDL_GETEVENT, up to numevents events at the front of the event queue, matching mask, will be returned and will be removed from the queue.
250 The mask parameter is a bitwise OR of SDL_EVENTMASK(event_type), for all event types you are interested in
255 Waits for an event end returns then. Always returns true.
257 =head2 set( type, state )
259 Set the state for all events of the given event's type
261 =head2 set_unicode( toggle )
263 Toggle unicode on the event.
265 =head2 set_key_repeat( delay, interval)
267 Sets the delay and intervall of the key repeat rate (e.g. when a user
268 holds down a key on the keyboard).
272 =head2 active_state()
284 =head2 key_scancode()
286 =head2 motion_state()
290 Returns the motion of the mouse in X direction as an absolute value.
294 Returns the motion of the mouse in Y direction as an absolute value.
298 Returns the motion of the mouse in X direction as a relative value.
302 Returns the motion of the mouse in Y direction as a relative value.
304 =head2 button_state()
306 Returns the state of the mouse buttons.
317 Documentation by Tels <http://bloodgate.com/>