Update .gitignore
[sdlgit/SDL_perl.git] / lib / SDL / Event.pm
CommitLineData
8fde61e3 1# Event.pm
2#
3# A package for handling SDL_Event *
4#
5# Copyright (C) 2000,2001,2002 David J. Goehrig
6#
7# see the file COPYING for terms of use
8#
9
10package SDL::Event;
11use strict;
12use SDL;
13
14sub new {
15 my $proto = shift;
16 my $class = ref($proto) || $proto;
17 my $self;
18 $self = \SDL::NewEvent();
19 bless $self, $class;
20 return $self;
21}
22
23sub DESTROY {
24 my $self = shift;
25 SDL::FreeEvent($$self);
26}
27
28sub type {
29 my $self = shift;
30 if (@_) {
31 SDL::SetEventType($$self,$_[0]);
32 }
33 return SDL::EventType($$self);
34}
35
36sub pump {
37 SDL::PumpEvents();
38}
39
40sub poll {
41 my $self = shift;
42 return SDL::PollEvent($$self);
43}
44
45sub push {
46 my $self = shift;
47 return SDL::PushEvent($$self);
48}
49
50sub wait {
51 my $self = shift;
52 return SDL::WaitEvent($$self);
53}
54
55sub set {
56 my $self = shift;
57 my $state = shift;
58 return SDL::EventState($self->type(),$state);
59}
60
61sub set_unicode {
62 my $self = shift;
63 my $toggle = shift;
64 return SDL::EnableUnicode($toggle);
65}
66
67sub set_key_repeat {
68 my $self = shift;
69 my $delay = shift;
70 my $interval = shift;
71 return SDL::EnableKeyRepeat($delay,$interval);
72}
73
74sub active_gain {
75 my $self = shift;
76 return SDL::ActiveEventGain($$self);
77}
78
79sub active_state {
80 my $self = shift;
81 return SDL::ActiveEventState($$self);
82}
83
84sub key_state {
85 my $self = shift;
86 return SDL::KeyEventState($$self);
87}
88
89sub key_sym {
90 my $self = shift;
91 return SDL::KeyEventSym($$self);
92}
93
94sub key_name {
95 my $self = shift;
96 return SDL::GetKeyName(SDL::KeyEventSym($$self));
97}
98
99sub key_mod {
100 my $self = shift;
101 return SDL::KeyEventMod($$self);
102}
103
104sub key_unicode {
105 my $self = shift;
106 return SDL::KeyEventUnicode($$self);
107}
108
109sub key_scancode {
110 my $self = shift;
111 return SDL::KeyEventScanCode($$self);
112}
113
114sub motion_state {
115 my $self = shift;
116 return SDL::MouseMotionState($$self);
117}
118
119sub motion_x {
120 my $self = shift;
121 return SDL::MouseMotionX($$self);
122}
123
124sub motion_y {
125 my $self = shift;
126 return SDL::MouseMotionY($$self);
127}
128
129sub motion_xrel {
130 my $self = shift;
131 return SDL::MouseMotionXrel($$self);
132}
133
134sub motion_yrel {
135 my $self = shift;
136 return SDL::MouseMotionYrel($$self);
137}
138
139sub button_state {
140 my $self = shift;
141 return SDL::MouseButtonState($$self);
142}
143
144sub button_x {
145 my $self = shift;
146 return SDL::MouseButtonX($$self);
147}
148
149sub button_y {
150 my $self = shift;
151 return SDL::MouseButtonY($$self);
152}
153
154sub button {
155 my $self = shift;
156 return SDL::MouseButton($$self);
157}
158
159sub resize_w {
160 my $self = shift;
161 SDL::ResizeEventW($$self);
162}
163
164sub resize_h {
165 my $self = shift;
166 SDL::ResizeEventH($$self);
167}
168
1691;
170
171__END__;
172
173=pod
174
175=head1 NAME
176
177SDL::Event - a SDL perl extension
178
179=head1 SYNOPSIS
180
181 use SDL::Event;
182 my $event = new SDL::Event; # create a new event
183 while ($event->wait()) {
184 my $type = $event->type(); # get event type
185 # ... handle event
186 exit if $type == SDL_QUIT;
187 }
188
189=head1 DESCRIPTION
190
191C<SDL::Event> offers an object-oriented approach to SDL events. By creating
192an instance of SDL::Event via new() you can wait for events, and then determine
193the type of the event and take an appropriate action.
194
195=head1 EXAMPLE
196
197Here is an example of a simple event handler loop routine.
198See also L<SDL::App::loop>.
199
200 sub loop {
201 my ($self,$href) = @_;
202 my $event = new SDL::Event;
203 while ( $event->wait() ) {
204 # ... insert here your event handling like:
205 if ( ref($$href{$event->type()}) eq "CODE" ) {
206 &{$$href{$event->type()}}($event);
207 $self->sync();
208 }
209 }
210 }
211
212=head1 METHODS
213
214=head2 new()
215
216Create a new event object.
217
218=head2 type()
219
220Returns the type of the event, see list of exported symbols for which are
221available.
222
223=head2 pump()
224
225=head2 poll()
226
227=head2 wait()
228
229Waits for an event end returns then. Always returns true.
230
231=head2 set( type, state )
232
233Set the state for all events of the given event's type
234
235=head2 set_unicode( toggle )
236
237Toggle unicode on the event.
238
239=head2 set_key_repeat( delay, interval)
240
241Sets the delay and intervall of the key repeat rate (e.g. when a user
242holds down a key on the keyboard).
243
244=head2 active_gain()
245
246=head2 active_state()
247
248=head2 key_state()
249
250=head2 key_sym()
251
252=head2 key_name()
253
254=head2 key_mod()
255
256=head2 key_unicode()
257
258=head2 key_scancode()
259
260=head2 motion_state()
261
262=head2 motion_x()
263
264Returns the motion of the mouse in X direction as an absolute value.
265
266=head2 motion_y()
267
268Returns the motion of the mouse in Y direction as an absolute value.
269
270=head2 motion_xrel()
271
272Returns the motion of the mouse in X direction as a relative value.
273
274=head2 motion_yrel()
275
276Returns the motion of the mouse in Y direction as a relative value.
277
278=head2 button_state()
279
280Returns the state of the mouse buttons.
281
282=head2 button_x()
283
284=head2 button_y()
285
286=head2 button()
287
288=head1 AUTHOR
289
290David J. Goehrig
291Documentation by Tels <http://bloodgate.com/>
292
293=head1 SEE ALSO
294
295L<perl> L<SDL::App>
296
297=cut