5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@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:
38 my $class = ref($proto) || $proto;
40 $self = \SDL::NewEvent();
47 SDL::FreeEvent($$self);
53 SDL::SetEventType($$self,$_[0]);
55 return SDL::EventType($$self);
64 return SDL::PollEvent($$self);
69 return SDL::PushEvent($$self);
74 return SDL::WaitEvent($$self);
80 return SDL::EventState($self->type(),$state);
86 return SDL::EnableUnicode($toggle);
93 return SDL::EnableKeyRepeat($delay,$interval);
98 return SDL::ActiveEventGain($$self);
103 return SDL::ActiveEventState($$self);
108 return SDL::KeyEventState($$self);
113 return SDL::KeyEventSym($$self);
118 return SDL::GetKeyName(SDL::KeyEventSym($$self));
123 return SDL::KeyEventMod($$self);
128 return SDL::KeyEventUnicode($$self);
133 return SDL::KeyEventScanCode($$self);
138 return SDL::MouseMotionState($$self);
143 return SDL::MouseMotionX($$self);
148 return SDL::MouseMotionY($$self);
153 return SDL::MouseMotionXrel($$self);
158 return SDL::MouseMotionYrel($$self);
163 return SDL::MouseButtonState($$self);
168 return SDL::MouseButtonX($$self);
173 return SDL::MouseButtonY($$self);
178 return SDL::MouseButton($$self);
183 SDL::ResizeEventW($$self);
188 SDL::ResizeEventH($$self);
199 SDL::Event - a SDL perl extension
204 my $event = new SDL::Event; # create a new event
205 while ($event->wait()) {
206 my $type = $event->type(); # get event type
208 exit if $type == SDL_QUIT;
213 C<SDL::Event> offers an object-oriented approach to SDL events. By creating
214 an instance of SDL::Event via new() you can wait for events, and then determine
215 the type of the event and take an appropriate action.
219 Here is an example of a simple event handler loop routine.
220 See also L<SDL::App::loop>.
223 my ($self,$href) = @_;
224 my $event = new SDL::Event;
225 while ( $event->wait() ) {
226 # ... insert here your event handling like:
227 if ( ref($$href{$event->type()}) eq "CODE" ) {
228 &{$$href{$event->type()}}($event);
238 Create a new event object.
242 Returns the type of the event, see list of exported symbols for which are
251 Waits for an event end returns then. Always returns true.
253 =head2 set( type, state )
255 Set the state for all events of the given event's type
257 =head2 set_unicode( toggle )
259 Toggle unicode on the event.
261 =head2 set_key_repeat( delay, interval)
263 Sets the delay and intervall of the key repeat rate (e.g. when a user
264 holds down a key on the keyboard).
268 =head2 active_state()
280 =head2 key_scancode()
282 =head2 motion_state()
286 Returns the motion of the mouse in X direction as an absolute value.
290 Returns the motion of the mouse in Y direction as an absolute value.
294 Returns the motion of the mouse in X direction as a relative value.
298 Returns the motion of the mouse in Y direction as a relative value.
300 =head2 button_state()
302 Returns the state of the mouse buttons.
313 Documentation by Tels <http://bloodgate.com/>