1 module allegro5.events; 2 3 import allegro5.altime; 4 import allegro5.base; 5 import allegro5.display; 6 import allegro5.joystick; 7 import allegro5.mouse; 8 import allegro5.keyboard; 9 import allegro5.timer; 10 import allegro5.touch_input; 11 12 version (Tango) { 13 import tango.stdc.stdint; 14 } 15 else { 16 import std.stdint; 17 } 18 19 extern (C) 20 { 21 alias uint ALLEGRO_EVENT_TYPE; 22 23 enum 24 { 25 ALLEGRO_EVENT_JOYSTICK_AXIS = 1, 26 ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN = 2, 27 ALLEGRO_EVENT_JOYSTICK_BUTTON_UP = 3, 28 ALLEGRO_EVENT_JOYSTICK_CONFIGURATION = 4, 29 30 ALLEGRO_EVENT_KEY_DOWN = 10, 31 ALLEGRO_EVENT_KEY_CHAR = 11, 32 ALLEGRO_EVENT_KEY_UP = 12, 33 34 ALLEGRO_EVENT_MOUSE_AXES = 20, 35 ALLEGRO_EVENT_MOUSE_BUTTON_DOWN = 21, 36 ALLEGRO_EVENT_MOUSE_BUTTON_UP = 22, 37 ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY = 23, 38 ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY = 24, 39 ALLEGRO_EVENT_MOUSE_WARPED = 25, 40 41 ALLEGRO_EVENT_TIMER = 30, 42 43 ALLEGRO_EVENT_DISPLAY_EXPOSE = 40, 44 ALLEGRO_EVENT_DISPLAY_RESIZE = 41, 45 ALLEGRO_EVENT_DISPLAY_CLOSE = 42, 46 ALLEGRO_EVENT_DISPLAY_LOST = 43, 47 ALLEGRO_EVENT_DISPLAY_FOUND = 44, 48 ALLEGRO_EVENT_DISPLAY_SWITCH_IN = 45, 49 ALLEGRO_EVENT_DISPLAY_SWITCH_OUT = 46, 50 ALLEGRO_EVENT_DISPLAY_ORIENTATION = 47, 51 ALLEGRO_EVENT_DISPLAY_HALT_DRAWING = 48, 52 ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING = 49, 53 54 ALLEGRO_EVENT_TOUCH_BEGIN = 50, 55 ALLEGRO_EVENT_TOUCH_END = 51, 56 ALLEGRO_EVENT_TOUCH_MOVE = 52, 57 ALLEGRO_EVENT_TOUCH_CANCEL = 53, 58 59 ALLEGRO_EVENT_DISPLAY_CONNECTED = 60, 60 ALLEGRO_EVENT_DISPLAY_DISCONNECTED = 61 61 } 62 } 63 64 bool ALLEGRO_EVENT_TYPE_IS_USER(ALLEGRO_EVENT_TYPE t) 65 { 66 return t >= 512; 67 } 68 69 ALLEGRO_EVENT_TYPE ALLEGRO_GET_EVENT_TYPE(char a, char b, char c, char d) 70 { 71 return AL_ID(a, b, c, d); 72 } 73 74 package char[] _AL_EVENT_HEADER(in char[] src_type) 75 { 76 return "ALLEGRO_EVENT_TYPE type;" ~ src_type ~ "* source; double timestamp;"; 77 } 78 79 extern (C) 80 { 81 struct ALLEGRO_EVENT_SOURCE 82 { 83 int[32] __pad = void; 84 } 85 86 struct ALLEGRO_ANY_EVENT 87 { 88 mixin(_AL_EVENT_HEADER("ALLEGRO_EVENT_SOURCE")); 89 } 90 91 struct ALLEGRO_DISPLAY_EVENT 92 { 93 mixin(_AL_EVENT_HEADER("ALLEGRO_DISPLAY")); 94 int x, y; 95 int width, height; 96 int orientation; 97 } 98 99 struct ALLEGRO_JOYSTICK_EVENT 100 { 101 mixin(_AL_EVENT_HEADER("ALLEGRO_JOYSTICK")); 102 ALLEGRO_JOYSTICK* id; 103 int stick; 104 int axis; 105 float pos; 106 int button; 107 } 108 109 struct ALLEGRO_KEYBOARD_EVENT 110 { 111 mixin(_AL_EVENT_HEADER("ALLEGRO_KEYBOARD")); 112 ALLEGRO_DISPLAY* display; /* the window the key was pressed in */ 113 int keycode; /* the physical key pressed */ 114 int unichar; /* unicode character or negative */ 115 uint modifiers; /* bitfield */ 116 bool repeat; /* auto-repeated or not */ 117 } 118 119 struct ALLEGRO_MOUSE_EVENT 120 { 121 mixin(_AL_EVENT_HEADER("ALLEGRO_MOUSE")); 122 ALLEGRO_DISPLAY* display; 123 /* (display) Window the event originate from */ 124 /* (x, y) Primary mouse position */ 125 /* (z) Mouse wheel position (1D 'wheel'), or, */ 126 /* (w, z) Mouse wheel position (2D 'ball') */ 127 int x, y, z, w; 128 int dx, dy, dz, dw; 129 uint button; 130 float pressure; 131 } 132 133 struct ALLEGRO_TIMER_EVENT 134 { 135 mixin(_AL_EVENT_HEADER("ALLEGRO_TIMER")); 136 long count; 137 double error; 138 } 139 140 struct ALLEGRO_TOUCH_EVENT 141 { 142 mixin(_AL_EVENT_HEADER("ALLEGRO_TOUCH_INPUT")); 143 ALLEGRO_DISPLAY* display; 144 /* (id) Identifier of the event, always positive number. 145 * (x, y) Touch position on the screen in 1:1 resolution. 146 * (dx, dy) Relative touch position. 147 * (primary) True, if touch is a primary one (usually first one). 148 */ 149 int id; 150 float x, y; 151 float dx, dy; 152 bool primary; 153 } 154 155 struct ALLEGRO_USER_EVENT_DESCRIPTOR; 156 157 struct ALLEGRO_USER_EVENT 158 { 159 mixin(_AL_EVENT_HEADER("ALLEGRO_EVENT_SOURCE")); 160 ALLEGRO_USER_EVENT_DESCRIPTOR* __internal__descr; 161 intptr_t data1; 162 intptr_t data2; 163 intptr_t data3; 164 intptr_t data4; 165 } 166 167 union ALLEGRO_EVENT 168 { 169 /* This must be the same as the first field of _AL_EVENT_HEADER. */ 170 ALLEGRO_EVENT_TYPE type; 171 172 ALLEGRO_ANY_EVENT any; 173 ALLEGRO_DISPLAY_EVENT display; 174 ALLEGRO_JOYSTICK_EVENT joystick; 175 ALLEGRO_KEYBOARD_EVENT keyboard; 176 ALLEGRO_MOUSE_EVENT mouse; 177 ALLEGRO_TIMER_EVENT timer; 178 ALLEGRO_TOUCH_EVENT touch; 179 ALLEGRO_USER_EVENT user; 180 } 181 182 /* Event sources */ 183 void al_init_user_event_source(ALLEGRO_EVENT_SOURCE* src); 184 void al_destroy_user_event_source(ALLEGRO_EVENT_SOURCE* src); 185 /* The second argument is ALLEGRO_EVENT instead of ALLEGRO_USER_EVENT 186 * to prevent users passing a pointer to a too-short structure. 187 */ 188 bool al_emit_user_event(ALLEGRO_EVENT_SOURCE *, ALLEGRO_EVENT *, void function(ALLEGRO_USER_EVENT *) dtor); 189 void al_unref_user_event(ALLEGRO_USER_EVENT *); 190 void al_set_event_source_data(ALLEGRO_EVENT_SOURCE*, intptr_t data); 191 intptr_t al_get_event_source_data(in ALLEGRO_EVENT_SOURCE*); 192 193 /* Event queues */ 194 195 struct ALLEGRO_EVENT_QUEUE; 196 197 ALLEGRO_EVENT_QUEUE* al_create_event_queue(); 198 void al_destroy_event_queue(ALLEGRO_EVENT_QUEUE*); 199 bool al_is_event_source_registered(ALLEGRO_EVENT_QUEUE *, ALLEGRO_EVENT_SOURCE *); 200 void al_register_event_source(ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT_SOURCE*); 201 void al_unregister_event_source(ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT_SOURCE*); 202 void al_pause_event_queue(ALLEGRO_EVENT_QUEUE*, bool); 203 bool al_is_event_queue_paused(in ALLEGRO_EVENT_QUEUE*); 204 bool al_is_event_queue_empty(ALLEGRO_EVENT_QUEUE*); 205 bool al_get_next_event(ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT* ret_event); 206 bool al_peek_next_event(ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT* ret_event); 207 bool al_drop_next_event(ALLEGRO_EVENT_QUEUE*); 208 void al_flush_event_queue(ALLEGRO_EVENT_QUEUE*); 209 void al_wait_for_event(ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT* ret_event); 210 bool al_wait_for_event_timed(ALLEGRO_EVENT_QUEUE*, ALLEGRO_EVENT* ret_event, float secs); 211 bool al_wait_for_event_until(ALLEGRO_EVENT_QUEUE* queue, ALLEGRO_EVENT* ret_event, ALLEGRO_TIMEOUT* timeout); 212 }