File: Event.pm

package info (click to toggle)
sdlperl 1.20.3dfsg-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,796 kB
  • ctags: 2,171
  • sloc: perl: 7,394; ansic: 232; makefile: 75; sh: 1
file content (400 lines) | stat: -rw-r--r-- 8,426 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#	Event.pm
#
#	A package for handling SDL_Event *
#
#	Copyright (C) 2000,2001,2002 David J. Goehrig
#
#	see the file COPYING for terms of use
#

package SDL::Event;
use strict;
use SDL;
use SDL::Constants;	# whoever uses us, will get the constants

sub new {
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self = {};
	$self->{-event} = SDL::NewEvent();
	bless $self, $class;
	return $self;
}

sub DESTROY {
	my $self = shift;
	SDL::FreeEvent($self->{-event});
}

sub type {
	my $self = shift;
	return SDL::EventType($self->{-event});
}

sub pump {
	SDL::PumpEvents();
}

sub poll {
	my $self = shift;
	return SDL::PollEvent($self->{-event});
}

sub wait {
	my $self = shift;
	return SDL::WaitEvent($self->{-event});
}

sub set { 
	my $self = shift;
	my $type = shift;
	my $state = shift;
	return SDL::EventState($type,$state);
}

sub set_unicode {
	my $self = shift;
	my $toggle = shift;
	return SDL::EnableUnicode($toggle);
}

sub set_key_repeat {
	my $self = shift;
	my $delay = shift;
	my $interval = shift;
	return SDL::EnableKeyRepeat($delay,$interval);
}

sub active_gain {
	my $self = shift;
	return SDL::ActiveEventGain($self->{-event});
}

sub active_state {
	my $self = shift;
	return SDL::ActiveEventState($self->{-event});
}

sub key_state {
	my $self = shift;
	return SDL::KeyEventState($self->{-event});
}

sub key_sym {
	my $self = shift;
	return SDL::KeyEventSym($self->{-event});
}

sub key_name {
	my $self = shift;
	return SDL::GetKeyName(SDL::KeyEventSym($self->{-event}));
}

sub key_mod {
	my $self = shift;
	return SDL::KeyEventMod($self->{-event});
}

sub key_unicode {
	my $self = shift;
	return SDL::KeyEventUnicode($self->{-event});
}

sub key_scancode {
	my $self = shift;
	return SDL::KeyEventScanCode($self->{-event});
}

sub motion_state {
	my $self = shift;
	return SDL::MouseMotionState($self->{-event});
}

sub motion_x {
	my $self = shift;
	return SDL::MouseMotionX($self->{-event});
}

sub motion_y {
	my $self = shift;
	return SDL::MouseMotionY($self->{-event});
}

sub motion_xrel {
	my $self = shift;
	return SDL::MouseMotionXrel($self->{-event});
}

sub motion_yrel {
	my $self = shift;
	return SDL::MouseMotionYrel($self->{-event});
}

sub button_state {
	my $self = shift;
	return SDL::MouseButtonState($self->{-event});
}

sub button_x {
	my $self = shift;
	return SDL::MouseButtonX($self->{-event});
}

sub button_y {
	my $self = shift;
	return SDL::MouseButtonY($self->{-event});
}

sub button {
	my $self = shift;
	return SDL::MouseButton($self->{-event});
}

sub resize_w {
	my $self = shift;
	SDL::ResizeEventW($$self{-event});
}

sub resize_h {
	my $self = shift;
	SDL::ResizeEventH($$self{-event});
}


1;

__END__;

=pod

=head1 NAME

SDL::Event - a SDL perl extension

=head1 SYNOPSIS

 use SDL::Event;
 my $event = new SDL::Event;             # create a new event
 while ($event->wait()) {
 	my $type = $event->type();      # get event type
 	# ... handle event
 	exit if $type == SDL_QUIT;
 }
 
=head1 EXPORTS

       SDL_IGNORE              SDL_ENABLE
       SDL_QUERY               SDL_ACTIVEEVENT
       SDL_KEYDOWN             SDL_KEYUP
       SDL_MOUSEMOTION         SDL_MOUSEBUTTONDOWN
       SDL_MOUSEBUTTONUP       SDL_QUIT
       SDL_SYSWMEVENT          SDL_APPMOUSEFOCUS
       SDL_APPINPUTFOCUS       SDL_APPACTIVE
       SDL_PRESSED             SDL_RELEASED
       SDL_VIDEORESIZE         

       SDLK_BACKSPACE          SDLK_TAB
       SDLK_CLEAR              SDLK_RETURN
       SDLK_PAUSE              SDLK_ESCAPE
       SDLK_SPACE              SDLK_EXCLAIM
       SDLK_QUOTEDBL           SDLK_HASH
       SDLK_DOLLAR             SDLK_AMPERSAND
       SDLK_QUOTE              SDLK_LEFTPAREN
       SDLK_RIGHTPAREN         SDLK_ASTERISK
       SDLK_PLUS               SDLK_COMMA
       SDLK_MINUS              SDLK_PERIOD
       SDLK_SLASH              SDLK_0
       SDLK_1                  SDLK_2
       SDLK_3                  SDLK_4
       SDLK_5                  SDLK_6
       SDLK_7                  SDLK_8
       SDLK_9                  SDLK_COLON
       SDLK_SEMICOLON          SDLK_LESS
       SDLK_EQUALS             SDLK_GREATER
       SDLK_QUESTION           SDLK_AT
       SDLK_LEFTBRACKET        SDLK_BACKSLASH
       SDLK_RIGHTBRACKET       SDLK_CARET
       SDLK_UNDERSCORE         SDLK_BACKQUOTE

       SDLK_a                  SDLK_b
       SDLK_c                  SDLK_d
       SDLK_e                  SDLK_f
       SDLK_g                  SDLK_h
       SDLK_i                  SDLK_j
       SDLK_k                  SDLK_l
       SDLK_m                  SDLK_n
       SDLK_o                  SDLK_p
       SDLK_q                  SDLK_r
       SDLK_s                  SDLK_t
       SDLK_u                  SDLK_v
       SDLK_w                  SDLK_x
       SDLK_y                  SDLK_z
       SDLK_DELETE             SDLK_KP0
       SDLK_KP1                SDLK_KP2
       SDLK_KP3                SDLK_KP4
       SDLK_KP5                SDLK_KP6
       SDLK_KP7                SDLK_KP8
       SDLK_KP9                SDLK_KP_PERIOD
       SDLK_KP_DIVIDE          SDLK_KP_MULTIPLY
       SDLK_KP_MINUS           SDLK_KP_PLUS
       SDLK_KP_ENTER           SDLK_KP_EQUALS
       SDLK_UP                 SDLK_DOWN
       SDLK_RIGHT              SDLK_LEFT
       SDLK_INSERT             SDLK_HOME
       SDLK_END                SDLK_PAGEUP

       SDLK_PAGEDOWN           SDLK_F1
       SDLK_F2                 SDLK_F3
       SDLK_F4                 SDLK_F5
       SDLK_F6                 SDLK_F7
       SDLK_F8                 SDLK_F9
       SDLK_F10                SDLK_F11
       SDLK_F12                SDLK_F13
       SDLK_F14                SDLK_F15
       SDLK_NUMLOCK            SDLK_CAPSLOCK
       SDLK_SCROLLOCK          SDLK_RSHIFT
       SDLK_LSHIFT             SDLK_RCTRL
       SDLK_LCTRL              SDLK_RALT
       SDLK_LALT               SDLK_RMETA
       SDLK_LMETA

=head1 DESCRIPTION

C<SDL::Event> offers an object-oriented approach to SDL events. By creating
an instance of SDL::Event via new() you can wait for events, and then determine
the type of the event and take an appropriate action.

=head1 EXAMPLE

Here is an example of a simple event handler loop routine.
See also L<SDL::App::loop>.

       sub loop {
               my ($self,$href) = @_;
               my $event = new SDL::Event;
               while ( $event->wait() ) {
                       # ... insert here your event handling like:
                       if ( ref($$href{$event->type()}) eq "CODE" ) {
                               &{$$href{$event->type()}}($event);
                               $self->sync();
                       }
               }
       }

=head1 METHODS

=head2 new()

Create a new event object.

=head2 type()

Returns the type of the event, see list of exported symbols for which are
available.

=head2 pump()

=head2 poll()

=head2 wait()

Waits for an event end returns then. Always returns true.

=head2 set( type, state )

Set type and state of the event.

=head2 set_unicode( toggle )

Toggle unicode on the event.

=head2 set_key_repeat( delay, interval)

Sets the delay and intervall of the key repeat rate (e.g. when a user
holds down a key on the keyboard).

=head2 active_gain()

=head2 active_state()

=head2 key_state()

=head2 key_sym()

=head2 key_name()

=head2 key_mod()

=head2 key_unicode()

=head2 key_scancode()

=head2 motion_state()

=head2 motion_x()

Returns the motion of the mouse in X direction as an absolute value.

=head2 motion_y()

Returns the motion of the mouse in Y direction as an absolute value.

=head2 motion_xrel()

Returns the motion of the mouse in X direction as a relative value.

=head2 motion_yrel()

Returns the motion of the mouse in Y direction as a relative value.

=head2 button_state()

Returns the state of the mouse buttons, C<SDL::PRESSED>, C<SDL_RELEASED>.

=head2 button_x()

Returns the x position within the application window that the button was activated in

=head2 button_y()

Returns the y position within the application window that the button was activated in

=head2 button()

Returns the numeric id of the button pushed.

=over 4

=item 1

left

=item 2

middle

=item 3

right

=back

=head2 resize_w()

Returns the width of the resized window.

=head2 resize_h()

Returns the height of the resized window.

=head1 AUTHOR

David J. Goehrig
Documentation by Tels <http://bloodgate.com/>

=head1 SEE ALSO

L<perl> L<SDL::App>

=cut