1 #ifndef __al_included_allegro5_events_h
2 #define __al_included_allegro5_events_h
3 
4 #include "allegro5/altime.h"
5 
6 #ifdef __cplusplus
7    extern "C" {
8 #endif
9 
10 
11 /* Type: ALLEGRO_EVENT_TYPE
12  */
13 typedef unsigned int ALLEGRO_EVENT_TYPE;
14 
15 enum
16 {
17    ALLEGRO_EVENT_JOYSTICK_AXIS               =  1,
18    ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN        =  2,
19    ALLEGRO_EVENT_JOYSTICK_BUTTON_UP          =  3,
20    ALLEGRO_EVENT_JOYSTICK_CONFIGURATION      =  4,
21 
22    ALLEGRO_EVENT_KEY_DOWN                    = 10,
23    ALLEGRO_EVENT_KEY_CHAR                    = 11,
24    ALLEGRO_EVENT_KEY_UP                      = 12,
25 
26    ALLEGRO_EVENT_MOUSE_AXES                  = 20,
27    ALLEGRO_EVENT_MOUSE_BUTTON_DOWN           = 21,
28    ALLEGRO_EVENT_MOUSE_BUTTON_UP             = 22,
29    ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY         = 23,
30    ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY         = 24,
31    ALLEGRO_EVENT_MOUSE_WARPED                = 25,
32 
33    ALLEGRO_EVENT_TIMER                       = 30,
34 
35    ALLEGRO_EVENT_DISPLAY_EXPOSE              = 40,
36    ALLEGRO_EVENT_DISPLAY_RESIZE              = 41,
37    ALLEGRO_EVENT_DISPLAY_CLOSE               = 42,
38    ALLEGRO_EVENT_DISPLAY_LOST                = 43,
39    ALLEGRO_EVENT_DISPLAY_FOUND               = 44,
40    ALLEGRO_EVENT_DISPLAY_SWITCH_IN           = 45,
41    ALLEGRO_EVENT_DISPLAY_SWITCH_OUT          = 46,
42    ALLEGRO_EVENT_DISPLAY_ORIENTATION         = 47,
43    ALLEGRO_EVENT_DISPLAY_HALT_DRAWING        = 48,
44    ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING      = 49,
45 
46    ALLEGRO_EVENT_TOUCH_BEGIN                 = 50,
47    ALLEGRO_EVENT_TOUCH_END                   = 51,
48    ALLEGRO_EVENT_TOUCH_MOVE                  = 52,
49    ALLEGRO_EVENT_TOUCH_CANCEL                = 53,
50 
51    ALLEGRO_EVENT_DISPLAY_CONNECTED           = 60,
52    ALLEGRO_EVENT_DISPLAY_DISCONNECTED        = 61
53 };
54 
55 
56 /* Function: ALLEGRO_EVENT_TYPE_IS_USER
57  *
58  *    1 <= n < 512  - builtin events
59  *  512 <= n < 1024 - reserved user events (for addons)
60  * 1024 <= n        - unreserved user events
61  */
62 #define ALLEGRO_EVENT_TYPE_IS_USER(t)        ((t) >= 512)
63 
64 
65 /* Function: ALLEGRO_GET_EVENT_TYPE
66  */
67 #define ALLEGRO_GET_EVENT_TYPE(a, b, c, d)   AL_ID(a, b, c, d)
68 
69 
70 /* Type: ALLEGRO_EVENT_SOURCE
71  */
72 typedef struct ALLEGRO_EVENT_SOURCE ALLEGRO_EVENT_SOURCE;
73 
74 struct ALLEGRO_EVENT_SOURCE
75 {
76    int __pad[32];
77 };
78 
79 
80 
81 /*
82  * Event structures
83  *
84  * All event types have the following fields in common.
85  *
86  *  type      -- the type of event this is
87  *  timestamp -- when this event was generated
88  *  source    -- which event source generated this event
89  *
90  * For people writing event sources: The common fields must be at the
91  * very start of each event structure, i.e. put _AL_EVENT_HEADER at the
92  * front.
93  */
94 
95 #define _AL_EVENT_HEADER(srctype)                    \
96    ALLEGRO_EVENT_TYPE type;                          \
97    srctype *source;                                  \
98    double timestamp;
99 
100 
101 typedef struct ALLEGRO_ANY_EVENT
102 {
103    _AL_EVENT_HEADER(ALLEGRO_EVENT_SOURCE)
104 } ALLEGRO_ANY_EVENT;
105 
106 
107 typedef struct ALLEGRO_DISPLAY_EVENT
108 {
109    _AL_EVENT_HEADER(struct ALLEGRO_DISPLAY)
110    int x, y;
111    int width, height;
112    int orientation;
113 } ALLEGRO_DISPLAY_EVENT;
114 
115 
116 typedef struct ALLEGRO_JOYSTICK_EVENT
117 {
118    _AL_EVENT_HEADER(struct ALLEGRO_JOYSTICK)
119    struct ALLEGRO_JOYSTICK *id;
120    int stick;
121    int axis;
122    float pos;
123    int button;
124 } ALLEGRO_JOYSTICK_EVENT;
125 
126 
127 
128 typedef struct ALLEGRO_KEYBOARD_EVENT
129 {
130    _AL_EVENT_HEADER(struct ALLEGRO_KEYBOARD)
131    struct ALLEGRO_DISPLAY *display; /* the window the key was pressed in */
132    int keycode;                 /* the physical key pressed */
133    int unichar;                 /* unicode character or negative */
134    unsigned int modifiers;      /* bitfield */
135    bool repeat;                 /* auto-repeated or not */
136 } ALLEGRO_KEYBOARD_EVENT;
137 
138 
139 
140 typedef struct ALLEGRO_MOUSE_EVENT
141 {
142    _AL_EVENT_HEADER(struct ALLEGRO_MOUSE)
143    struct ALLEGRO_DISPLAY *display;
144    /* (display) Window the event originate from
145     * (x, y) Primary mouse position
146     * (z) Mouse wheel position (1D 'wheel'), or,
147     * (w, z) Mouse wheel position (2D 'ball')
148     * (pressure) The pressure applied, for stylus (0 or 1 for normal mouse)
149     */
150    int x,  y,  z, w;
151    int dx, dy, dz, dw;
152    unsigned int button;
153    float pressure;
154 } ALLEGRO_MOUSE_EVENT;
155 
156 
157 
158 typedef struct ALLEGRO_TIMER_EVENT
159 {
160    _AL_EVENT_HEADER(struct ALLEGRO_TIMER)
161    int64_t count;
162    double error;
163 } ALLEGRO_TIMER_EVENT;
164 
165 
166 
167 typedef struct ALLEGRO_TOUCH_EVENT
168 {
169    _AL_EVENT_HEADER(struct ALLEGRO_TOUCH_INPUT)
170    struct ALLEGRO_DISPLAY *display;
171    /* (id) Identifier of the event, always positive number.
172     * (x, y) Touch position on the screen in 1:1 resolution.
173     * (dx, dy) Relative touch position.
174     * (primary) True, if touch is a primary one (usually first one).
175     */
176    int id;
177    float x, y;
178    float dx, dy;
179    bool primary;
180 } ALLEGRO_TOUCH_EVENT;
181 
182 
183 
184 /* Type: ALLEGRO_USER_EVENT
185  */
186 typedef struct ALLEGRO_USER_EVENT ALLEGRO_USER_EVENT;
187 
188 struct ALLEGRO_USER_EVENT
189 {
190    _AL_EVENT_HEADER(struct ALLEGRO_EVENT_SOURCE)
191    struct ALLEGRO_USER_EVENT_DESCRIPTOR *__internal__descr;
192    intptr_t data1;
193    intptr_t data2;
194    intptr_t data3;
195    intptr_t data4;
196 };
197 
198 
199 
200 /* Type: ALLEGRO_EVENT
201  */
202 typedef union ALLEGRO_EVENT ALLEGRO_EVENT;
203 
204 union ALLEGRO_EVENT
205 {
206    /* This must be the same as the first field of _AL_EVENT_HEADER.  */
207    ALLEGRO_EVENT_TYPE type;
208    /* `any' is to allow the user to access the other fields which are
209     * common to all event types, without using some specific type
210     * structure.
211     */
212    ALLEGRO_ANY_EVENT      any;
213    ALLEGRO_DISPLAY_EVENT  display;
214    ALLEGRO_JOYSTICK_EVENT joystick;
215    ALLEGRO_KEYBOARD_EVENT keyboard;
216    ALLEGRO_MOUSE_EVENT    mouse;
217    ALLEGRO_TIMER_EVENT    timer;
218    ALLEGRO_TOUCH_EVENT    touch;
219    ALLEGRO_USER_EVENT     user;
220 };
221 
222 
223 
224 /* Event sources */
225 
226 AL_FUNC(void, al_init_user_event_source, (ALLEGRO_EVENT_SOURCE *));
227 AL_FUNC(void, al_destroy_user_event_source, (ALLEGRO_EVENT_SOURCE *));
228 /* The second argument is ALLEGRO_EVENT instead of ALLEGRO_USER_EVENT
229  * to prevent users passing a pointer to a too-short structure.
230  */
231 AL_FUNC(bool, al_emit_user_event, (ALLEGRO_EVENT_SOURCE *, ALLEGRO_EVENT *,
232                                    void (*dtor)(ALLEGRO_USER_EVENT *)));
233 AL_FUNC(void, al_unref_user_event, (ALLEGRO_USER_EVENT *));
234 AL_FUNC(void, al_set_event_source_data, (ALLEGRO_EVENT_SOURCE*, intptr_t data));
235 AL_FUNC(intptr_t, al_get_event_source_data, (const ALLEGRO_EVENT_SOURCE*));
236 
237 
238 
239 /* Event queues */
240 
241 /* Type: ALLEGRO_EVENT_QUEUE
242  */
243 typedef struct ALLEGRO_EVENT_QUEUE ALLEGRO_EVENT_QUEUE;
244 
245 AL_FUNC(ALLEGRO_EVENT_QUEUE*, al_create_event_queue, (void));
246 AL_FUNC(void, al_destroy_event_queue, (ALLEGRO_EVENT_QUEUE*));
247 AL_FUNC(bool, al_is_event_source_registered, (ALLEGRO_EVENT_QUEUE *,
248          ALLEGRO_EVENT_SOURCE *));
249 AL_FUNC(void, al_register_event_source, (ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT_SOURCE*));
250 AL_FUNC(void, al_unregister_event_source, (ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT_SOURCE*));
251 AL_FUNC(void, al_pause_event_queue, (ALLEGRO_EVENT_QUEUE*, bool));
252 AL_FUNC(bool, al_is_event_queue_paused, (const ALLEGRO_EVENT_QUEUE*));
253 AL_FUNC(bool, al_is_event_queue_empty, (ALLEGRO_EVENT_QUEUE*));
254 AL_FUNC(bool, al_get_next_event, (ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT *ret_event));
255 AL_FUNC(bool, al_peek_next_event, (ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT *ret_event));
256 AL_FUNC(bool, al_drop_next_event, (ALLEGRO_EVENT_QUEUE*));
257 AL_FUNC(void, al_flush_event_queue, (ALLEGRO_EVENT_QUEUE*));
258 AL_FUNC(void, al_wait_for_event, (ALLEGRO_EVENT_QUEUE*,
259                                   ALLEGRO_EVENT *ret_event));
260 AL_FUNC(bool, al_wait_for_event_timed, (ALLEGRO_EVENT_QUEUE*,
261                                         ALLEGRO_EVENT *ret_event,
262                                         float secs));
263 AL_FUNC(bool, al_wait_for_event_until, (ALLEGRO_EVENT_QUEUE *queue,
264                                         ALLEGRO_EVENT *ret_event,
265                                         ALLEGRO_TIMEOUT *timeout));
266 
267 #ifdef __cplusplus
268    }
269 #endif
270 
271 #endif
272 
273 /* vim: set sts=3 sw=3 et: */
274