Mercurial > sdl-ios-xcode
annotate include/SDL_events.h @ 1294:1760ceb23bc6
Date: Fri, 18 Feb 2005 20:49:35 +0200 (EET)
From: ville
Subject: [SDL] Changing, at least some, anonymous enums to named enums.
Howdy,
Could, some if not all, enums be named rather than being anonymous enums?
I ran into troubles with the enum describing event types in SDL_events.h.
The problem is that an anonymous enum cannot be used in C++ templates like
so:
enum { C };
template< typename T >
void
f( T ) {
}
f( C );
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 29 Jan 2006 23:14:04 +0000 |
parents | b2283b0ded26 |
children | 7b32c7a586c9 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
577
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
251
b8688cfdc232
Updated the headers with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Include file for SDL event handling */ | |
29 | |
30 #ifndef _SDL_events_h | |
31 #define _SDL_events_h | |
32 | |
33 #include "SDL_types.h" | |
34 #include "SDL_active.h" | |
35 #include "SDL_keyboard.h" | |
36 #include "SDL_mouse.h" | |
37 #include "SDL_joystick.h" | |
38 #include "SDL_quit.h" | |
39 | |
40 #include "begin_code.h" | |
41 /* Set up for C function definitions, even when using C++ */ | |
42 #ifdef __cplusplus | |
43 extern "C" { | |
44 #endif | |
45 | |
46 /* Event enumerations */ | |
1294
1760ceb23bc6
Date: Fri, 18 Feb 2005 20:49:35 +0200 (EET)
Sam Lantinga <slouken@libsdl.org>
parents:
1258
diff
changeset
|
47 typedef enum { |
1760ceb23bc6
Date: Fri, 18 Feb 2005 20:49:35 +0200 (EET)
Sam Lantinga <slouken@libsdl.org>
parents:
1258
diff
changeset
|
48 SDL_NOEVENT = 0, /* Unused (do not remove) */ |
0 | 49 SDL_ACTIVEEVENT, /* Application loses/gains visibility */ |
50 SDL_KEYDOWN, /* Keys pressed */ | |
51 SDL_KEYUP, /* Keys released */ | |
52 SDL_MOUSEMOTION, /* Mouse moved */ | |
53 SDL_MOUSEBUTTONDOWN, /* Mouse button pressed */ | |
54 SDL_MOUSEBUTTONUP, /* Mouse button released */ | |
55 SDL_JOYAXISMOTION, /* Joystick axis motion */ | |
56 SDL_JOYBALLMOTION, /* Joystick trackball motion */ | |
57 SDL_JOYHATMOTION, /* Joystick hat position change */ | |
58 SDL_JOYBUTTONDOWN, /* Joystick button pressed */ | |
59 SDL_JOYBUTTONUP, /* Joystick button released */ | |
60 SDL_QUIT, /* User-requested quit */ | |
61 SDL_SYSWMEVENT, /* System specific event */ | |
62 SDL_EVENT_RESERVEDA, /* Reserved for future use.. */ | |
63 SDL_EVENT_RESERVEDB, /* Reserved for future use.. */ | |
64 SDL_VIDEORESIZE, /* User resized video mode */ | |
65 SDL_VIDEOEXPOSE, /* Screen needs to be redrawn */ | |
66 SDL_EVENT_RESERVED2, /* Reserved for future use.. */ | |
67 SDL_EVENT_RESERVED3, /* Reserved for future use.. */ | |
68 SDL_EVENT_RESERVED4, /* Reserved for future use.. */ | |
69 SDL_EVENT_RESERVED5, /* Reserved for future use.. */ | |
70 SDL_EVENT_RESERVED6, /* Reserved for future use.. */ | |
71 SDL_EVENT_RESERVED7, /* Reserved for future use.. */ | |
72 /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */ | |
73 SDL_USEREVENT = 24, | |
74 /* This last event is only for bounding internal arrays | |
75 It is the number of bits in the event mask datatype -- Uint32 | |
76 */ | |
77 SDL_NUMEVENTS = 32 | |
1294
1760ceb23bc6
Date: Fri, 18 Feb 2005 20:49:35 +0200 (EET)
Sam Lantinga <slouken@libsdl.org>
parents:
1258
diff
changeset
|
78 } SDL_EventType; |
0 | 79 |
80 /* Predefined event masks */ | |
81 #define SDL_EVENTMASK(X) (1<<(X)) | |
1294
1760ceb23bc6
Date: Fri, 18 Feb 2005 20:49:35 +0200 (EET)
Sam Lantinga <slouken@libsdl.org>
parents:
1258
diff
changeset
|
82 typedef enum { |
0 | 83 SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT), |
84 SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN), | |
85 SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP), | |
86 SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION), | |
87 SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN), | |
88 SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONUP), | |
89 SDL_MOUSEEVENTMASK = SDL_EVENTMASK(SDL_MOUSEMOTION)| | |
90 SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)| | |
91 SDL_EVENTMASK(SDL_MOUSEBUTTONUP), | |
92 SDL_JOYAXISMOTIONMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION), | |
93 SDL_JOYBALLMOTIONMASK = SDL_EVENTMASK(SDL_JOYBALLMOTION), | |
94 SDL_JOYHATMOTIONMASK = SDL_EVENTMASK(SDL_JOYHATMOTION), | |
95 SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK(SDL_JOYBUTTONDOWN), | |
96 SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP), | |
97 SDL_JOYEVENTMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION)| | |
98 SDL_EVENTMASK(SDL_JOYBALLMOTION)| | |
99 SDL_EVENTMASK(SDL_JOYHATMOTION)| | |
100 SDL_EVENTMASK(SDL_JOYBUTTONDOWN)| | |
101 SDL_EVENTMASK(SDL_JOYBUTTONUP), | |
102 SDL_VIDEORESIZEMASK = SDL_EVENTMASK(SDL_VIDEORESIZE), | |
103 SDL_VIDEOEXPOSEMASK = SDL_EVENTMASK(SDL_VIDEOEXPOSE), | |
104 SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT), | |
105 SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT) | |
1294
1760ceb23bc6
Date: Fri, 18 Feb 2005 20:49:35 +0200 (EET)
Sam Lantinga <slouken@libsdl.org>
parents:
1258
diff
changeset
|
106 } SDL_EventMask ; |
0 | 107 #define SDL_ALLEVENTS 0xFFFFFFFF |
108 | |
109 /* Application visibility event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
110 typedef struct SDL_ActiveEvent { |
0 | 111 Uint8 type; /* SDL_ACTIVEEVENT */ |
112 Uint8 gain; /* Whether given states were gained or lost (1/0) */ | |
113 Uint8 state; /* A mask of the focus states */ | |
114 } SDL_ActiveEvent; | |
115 | |
116 /* Keyboard event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
117 typedef struct SDL_KeyboardEvent { |
0 | 118 Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */ |
119 Uint8 which; /* The keyboard device index */ | |
120 Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ | |
121 SDL_keysym keysym; | |
122 } SDL_KeyboardEvent; | |
123 | |
124 /* Mouse motion event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
125 typedef struct SDL_MouseMotionEvent { |
0 | 126 Uint8 type; /* SDL_MOUSEMOTION */ |
127 Uint8 which; /* The mouse device index */ | |
128 Uint8 state; /* The current button state */ | |
129 Uint16 x, y; /* The X/Y coordinates of the mouse */ | |
130 Sint16 xrel; /* The relative motion in the X direction */ | |
131 Sint16 yrel; /* The relative motion in the Y direction */ | |
132 } SDL_MouseMotionEvent; | |
133 | |
134 /* Mouse button event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
135 typedef struct SDL_MouseButtonEvent { |
0 | 136 Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ |
137 Uint8 which; /* The mouse device index */ | |
138 Uint8 button; /* The mouse button index */ | |
139 Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ | |
140 Uint16 x, y; /* The X/Y coordinates of the mouse at press time */ | |
141 } SDL_MouseButtonEvent; | |
142 | |
143 /* Joystick axis motion event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
144 typedef struct SDL_JoyAxisEvent { |
0 | 145 Uint8 type; /* SDL_JOYAXISMOTION */ |
146 Uint8 which; /* The joystick device index */ | |
147 Uint8 axis; /* The joystick axis index */ | |
148 Sint16 value; /* The axis value (range: -32768 to 32767) */ | |
149 } SDL_JoyAxisEvent; | |
150 | |
151 /* Joystick trackball motion event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
152 typedef struct SDL_JoyBallEvent { |
0 | 153 Uint8 type; /* SDL_JOYBALLMOTION */ |
154 Uint8 which; /* The joystick device index */ | |
155 Uint8 ball; /* The joystick trackball index */ | |
156 Sint16 xrel; /* The relative motion in the X direction */ | |
157 Sint16 yrel; /* The relative motion in the Y direction */ | |
158 } SDL_JoyBallEvent; | |
159 | |
160 /* Joystick hat position change event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
161 typedef struct SDL_JoyHatEvent { |
0 | 162 Uint8 type; /* SDL_JOYHATMOTION */ |
163 Uint8 which; /* The joystick device index */ | |
164 Uint8 hat; /* The joystick hat index */ | |
165 Uint8 value; /* The hat position value: | |
577
f7596a8a3b8b
Fixed header docs for the joystick hat position
Sam Lantinga <slouken@libsdl.org>
parents:
337
diff
changeset
|
166 SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP |
f7596a8a3b8b
Fixed header docs for the joystick hat position
Sam Lantinga <slouken@libsdl.org>
parents:
337
diff
changeset
|
167 SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT |
f7596a8a3b8b
Fixed header docs for the joystick hat position
Sam Lantinga <slouken@libsdl.org>
parents:
337
diff
changeset
|
168 SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN |
0 | 169 Note that zero means the POV is centered. |
170 */ | |
171 } SDL_JoyHatEvent; | |
172 | |
173 /* Joystick button event structure */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
174 typedef struct SDL_JoyButtonEvent { |
0 | 175 Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */ |
176 Uint8 which; /* The joystick device index */ | |
177 Uint8 button; /* The joystick button index */ | |
178 Uint8 state; /* SDL_PRESSED or SDL_RELEASED */ | |
179 } SDL_JoyButtonEvent; | |
180 | |
181 /* The "window resized" event | |
182 When you get this event, you are responsible for setting a new video | |
183 mode with the new width and height. | |
184 */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
185 typedef struct SDL_ResizeEvent { |
0 | 186 Uint8 type; /* SDL_VIDEORESIZE */ |
187 int w; /* New width */ | |
188 int h; /* New height */ | |
189 } SDL_ResizeEvent; | |
190 | |
191 /* The "screen redraw" event */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
192 typedef struct SDL_ExposeEvent { |
0 | 193 Uint8 type; /* SDL_VIDEOEXPOSE */ |
194 } SDL_ExposeEvent; | |
195 | |
196 /* The "quit requested" event */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
197 typedef struct SDL_QuitEvent { |
0 | 198 Uint8 type; /* SDL_QUIT */ |
199 } SDL_QuitEvent; | |
200 | |
201 /* A user-defined event type */ | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
202 typedef struct SDL_UserEvent { |
0 | 203 Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */ |
204 int code; /* User defined event code */ | |
205 void *data1; /* User defined data pointer */ | |
206 void *data2; /* User defined data pointer */ | |
207 } SDL_UserEvent; | |
208 | |
209 /* If you want to use this event, you should include SDL_syswm.h */ | |
210 struct SDL_SysWMmsg; | |
211 typedef struct SDL_SysWMmsg SDL_SysWMmsg; | |
911
04a403e4ccf5
Date: Mon, 3 May 2004 03:15:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
844
diff
changeset
|
212 typedef struct SDL_SysWMEvent { |
0 | 213 Uint8 type; |
214 SDL_SysWMmsg *msg; | |
215 } SDL_SysWMEvent; | |
216 | |
217 /* General event structure */ | |
1258
b2283b0ded26
Date: Thu, 19 Jan 2006 20:02:29 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
930
diff
changeset
|
218 typedef union SDL_Event { |
0 | 219 Uint8 type; |
220 SDL_ActiveEvent active; | |
221 SDL_KeyboardEvent key; | |
222 SDL_MouseMotionEvent motion; | |
223 SDL_MouseButtonEvent button; | |
224 SDL_JoyAxisEvent jaxis; | |
225 SDL_JoyBallEvent jball; | |
226 SDL_JoyHatEvent jhat; | |
227 SDL_JoyButtonEvent jbutton; | |
228 SDL_ResizeEvent resize; | |
229 SDL_ExposeEvent expose; | |
230 SDL_QuitEvent quit; | |
231 SDL_UserEvent user; | |
232 SDL_SysWMEvent syswm; | |
233 } SDL_Event; | |
234 | |
235 | |
236 /* Function prototypes */ | |
237 | |
238 /* Pumps the event loop, gathering events from the input devices. | |
239 This function updates the event queue and internal input device state. | |
240 This should only be run in the thread that sets the video mode. | |
241 */ | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
242 extern DECLSPEC void SDLCALL SDL_PumpEvents(void); |
0 | 243 |
244 /* Checks the event queue for messages and optionally returns them. | |
245 If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to | |
246 the back of the event queue. | |
247 If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front | |
248 of the event queue, matching 'mask', will be returned and will not | |
249 be removed from the queue. | |
250 If 'action' is SDL_GETEVENT, up to 'numevents' events at the front | |
251 of the event queue, matching 'mask', will be returned and will be | |
252 removed from the queue. | |
253 This function returns the number of events actually stored, or -1 | |
254 if there was an error. This function is thread-safe. | |
255 */ | |
256 typedef enum { | |
257 SDL_ADDEVENT, | |
258 SDL_PEEKEVENT, | |
259 SDL_GETEVENT | |
260 } SDL_eventaction; | |
261 /* */ | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
262 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents, |
0 | 263 SDL_eventaction action, Uint32 mask); |
264 | |
265 /* Polls for currently pending events, and returns 1 if there are any pending | |
266 events, or 0 if there are none available. If 'event' is not NULL, the next | |
267 event is removed from the queue and stored in that area. | |
268 */ | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
269 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event *event); |
0 | 270 |
271 /* Waits indefinitely for the next available event, returning 1, or 0 if there | |
272 was an error while waiting for events. If 'event' is not NULL, the next | |
273 event is removed from the queue and stored in that area. | |
274 */ | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
275 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event *event); |
0 | 276 |
277 /* Add an event to the event queue. | |
844
cd0c77df70a4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
278 This function returns 0 on success, or -1 if the event queue was full |
cd0c77df70a4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
279 or there was some other error. |
0 | 280 */ |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
281 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event); |
0 | 282 |
283 /* | |
284 This function sets up a filter to process all events before they | |
285 change internal state and are posted to the internal event queue. | |
286 | |
287 The filter is protypted as: | |
288 */ | |
930
02759105b989
Date: Fri, 20 Aug 2004 08:31:20 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
911
diff
changeset
|
289 typedef int (SDLCALL *SDL_EventFilter)(const SDL_Event *event); |
0 | 290 /* |
291 If the filter returns 1, then the event will be added to the internal queue. | |
292 If it returns 0, then the event will be dropped from the queue, but the | |
293 internal state will still be updated. This allows selective filtering of | |
294 dynamically arriving events. | |
295 | |
296 WARNING: Be very careful of what you do in the event filter function, as | |
297 it may run in a different thread! | |
298 | |
299 There is one caveat when dealing with the SDL_QUITEVENT event type. The | |
300 event filter is only called when the window manager desires to close the | |
301 application window. If the event filter returns 1, then the window will | |
302 be closed, otherwise the window will remain open if possible. | |
303 If the quit event is generated by an interrupt signal, it will bypass the | |
304 internal queue and be delivered to the application at the next event poll. | |
305 */ | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
306 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter); |
0 | 307 |
308 /* | |
309 Return the current event filter - can be used to "chain" filters. | |
310 If there is no event filter set, this function returns NULL. | |
311 */ | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
312 extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter(void); |
0 | 313 |
314 /* | |
315 This function allows you to set the state of processing certain events. | |
316 If 'state' is set to SDL_IGNORE, that event will be automatically dropped | |
317 from the event queue and will not event be filtered. | |
318 If 'state' is set to SDL_ENABLE, that event will be processed normally. | |
319 If 'state' is set to SDL_QUERY, SDL_EventState() will return the | |
320 current processing state of the specified event. | |
321 */ | |
322 #define SDL_QUERY -1 | |
323 #define SDL_IGNORE 0 | |
324 #define SDL_DISABLE 0 | |
325 #define SDL_ENABLE 1 | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
326 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint8 type, int state); |
0 | 327 |
328 | |
329 /* Ends C function definitions when using C++ */ | |
330 #ifdef __cplusplus | |
331 } | |
332 #endif | |
333 #include "close_code.h" | |
334 | |
335 #endif /* _SDL_events_h */ |