sdl/
event.rs

1use std::mem;
2use libc::c_int;
3use std::slice;
4use num::FromPrimitive;
5use std::ffi::CStr;
6use std::str;
7
8pub mod ll {
9    #![allow(non_camel_case_types)]
10
11    use std::mem;
12    use libc::{c_void, c_int, c_uint, c_uchar, uint8_t, uint16_t, int16_t};
13    use libc::types::os::arch::c95::c_schar;
14    pub use keysym::*;
15
16    pub type SDL_EventType = c_uint;
17    pub type SDLMod = c_uint;
18    pub type SDL_SysWMmsg = c_void;
19
20    pub const SDL_NOEVENT: SDL_EventType = 0;
21    pub const SDL_ACTIVEEVENT: SDL_EventType = 1;
22    pub const SDL_KEYDOWN: SDL_EventType = 2;
23    pub const SDL_KEYUP: SDL_EventType = 3;
24    pub const SDL_MOUSEMOTION: SDL_EventType = 4;
25    pub const SDL_MOUSEBUTTONDOWN: SDL_EventType = 5;
26    pub const SDL_MOUSEBUTTONUP: SDL_EventType = 6;
27    pub const SDL_JOYAXISMOTION: SDL_EventType = 7;
28    pub const SDL_JOYBALLMOTION: SDL_EventType = 8;
29    pub const SDL_JOYHATMOTION: SDL_EventType = 9;
30    pub const SDL_JOYBUTTONDOWN: SDL_EventType = 10;
31    pub const SDL_JOYBUTTONUP: SDL_EventType = 11;
32    pub const SDL_QUIT: SDL_EventType = 12;
33    pub const SDL_SYSWMEVENT: SDL_EventType = 13;
34    pub const SDL_VIDEORESIZE: SDL_EventType = 16;
35    pub const SDL_VIDEOEXPOSE: SDL_EventType = 17;
36    pub const SDL_USEREVENT: SDL_EventType = 24;
37
38    pub const SDL_DISABLE: c_int = 0;
39    pub const SDL_ENABLE: c_int = 1;
40    pub const SDL_QUERY: c_int = -1;
41
42    pub const SDL_APPMOUSEFOCUS: c_int = 0x01;
43    pub const SDL_APPINPUTFOCUS: c_int = 0x02;
44    pub const SDL_APPACTIVE: c_int = 0x04;
45
46    #[repr(C)]
47    #[derive(Copy, Clone)]
48    pub struct SDL_keysym {
49        pub scancode: uint8_t,
50        pub sym: SDLKey,
51        pub _mod: SDLMod,
52        pub unicode: uint16_t,
53    }
54
55    #[repr(C)]
56    #[derive(Copy, Clone)]
57    pub struct SDL_Event {
58        pub data: [c_uchar; 24],
59    }
60
61    #[repr(C)]
62    #[derive(Copy, Clone)]
63    pub struct SDL_ActiveEvent {
64        pub _type: uint8_t,
65        pub gain: uint8_t,
66        pub state: uint8_t,
67    }
68
69    #[repr(C)]
70    #[derive(Copy, Clone)]
71    pub struct SDL_KeyboardEvent {
72        pub _type: uint8_t,
73        pub which: uint8_t,
74        pub state: uint8_t,
75        pub keysym: SDL_keysym,
76    }
77
78    #[repr(C)]
79    #[derive(Copy, Clone)]
80    pub struct SDL_MouseMotionEvent {
81        pub _type: uint8_t,
82        pub which: uint8_t,
83        pub state: uint8_t,
84        pub x: uint16_t,
85        pub y: uint16_t,
86        pub xrel: int16_t,
87        pub yrel: int16_t,
88    }
89
90    #[repr(C)]
91    #[derive(Copy, Clone)]
92    pub struct SDL_MouseButtonEvent {
93        pub _type: uint8_t,
94        pub which: uint8_t,
95        pub button: uint8_t,
96        pub state: uint8_t,
97        pub x: uint16_t,
98        pub y: uint16_t,
99    }
100
101    #[repr(C)]
102    #[derive(Copy, Clone)]
103    pub struct SDL_JoyAxisEvent {
104        pub _type: uint8_t,
105        pub which: uint8_t,
106        pub axis: uint8_t,
107        pub value: int16_t,
108    }
109
110    #[repr(C)]
111    #[derive(Copy, Clone)]
112    pub struct SDL_JoyBallEvent {
113        pub _type: uint8_t,
114        pub which: uint8_t,
115        pub ball: uint8_t,
116        pub xrel: int16_t,
117        pub yrel: int16_t,
118    }
119
120    #[repr(C)]
121    #[derive(Copy, Clone)]
122    pub struct SDL_JoyHatEvent {
123        pub _type: uint8_t,
124        pub which: uint8_t,
125        pub hat: uint8_t,
126        pub value: uint8_t,
127    }
128
129    #[repr(C)]
130    #[derive(Copy, Clone)]
131    pub struct SDL_JoyButtonEvent {
132        pub _type: uint8_t,
133        pub which: uint8_t,
134        pub button: uint8_t,
135        pub state: uint8_t,
136    }
137
138    #[repr(C)]
139    #[derive(Copy, Clone)]
140    pub struct SDL_ResizeEvent {
141        pub _type: uint8_t,
142        pub w: c_int,
143        pub h: c_int,
144    }
145
146    #[repr(C)]
147    #[derive(Copy, Clone)]
148    pub struct SDL_ExposeEvent {
149        pub _type: uint8_t,
150    }
151
152    #[repr(C)]
153    #[derive(Copy, Clone)]
154    pub struct SDL_QuitEvent {
155        pub _type: uint8_t,
156    }
157
158    #[repr(C)]
159    #[derive(Copy, Clone)]
160    pub struct SDL_UserEvent {
161        pub _type: uint8_t,
162        pub code: c_int,
163        pub data1: *mut c_void,
164        pub data2: *mut c_void,
165    }
166
167    #[repr(C)]
168    #[derive(Copy, Clone)]
169    pub struct SDL_SysWMEvent {
170        pub _type: uint8_t,
171        pub msg: *mut SDL_SysWMmsg,
172    }
173
174    impl SDL_Event {
175        pub fn _type(&self) -> *const uint8_t {
176            unsafe { mem::transmute_copy(&self) }
177        }
178
179        pub fn active(&self) -> *const SDL_ActiveEvent {
180            unsafe { mem::transmute_copy(&self) }
181        }
182
183        pub fn key(&self) -> *const SDL_KeyboardEvent {
184            unsafe { mem::transmute_copy(&self) }
185        }
186
187        pub fn motion(&self) -> *const SDL_MouseMotionEvent {
188            unsafe { mem::transmute_copy(&self) }
189        }
190
191        pub fn button(&self) -> *const SDL_MouseButtonEvent {
192            unsafe { mem::transmute_copy(&self) }
193        }
194
195        pub fn jaxis(&self) -> *const SDL_JoyAxisEvent {
196            unsafe { mem::transmute_copy(&self) }
197        }
198
199        pub fn jball(&self) -> *const SDL_JoyBallEvent {
200            unsafe { mem::transmute_copy(&self) }
201        }
202
203        pub fn jhat(&self) -> *const SDL_JoyHatEvent {
204            unsafe { mem::transmute_copy(&self) }
205        }
206
207        pub fn jbutton(&self) -> *const SDL_JoyButtonEvent {
208            unsafe { mem::transmute_copy(&self) }
209        }
210
211        pub fn resize(&self) -> *const SDL_ResizeEvent {
212            unsafe { mem::transmute_copy(&self) }
213        }
214
215        pub fn expose(&self) -> *const SDL_ExposeEvent {
216            unsafe { mem::transmute_copy(&self) }
217        }
218
219        pub fn quit(&self) -> *const SDL_QuitEvent {
220            unsafe { mem::transmute_copy(&self) }
221        }
222
223        pub fn user(&self) -> *const SDL_UserEvent {
224            unsafe { mem::transmute_copy(&self) }
225        }
226
227        pub fn syswm(&self) -> *const SDL_SysWMEvent {
228            unsafe { mem::transmute_copy(&self) }
229        }
230    }
231
232    extern "C" {
233        pub fn SDL_PollEvent(event: *mut SDL_Event) -> c_int;
234        pub fn SDL_WaitEvent(event: *mut SDL_Event) -> c_int;
235        pub fn SDL_EventState(_type: uint8_t, state: c_int) -> uint8_t;
236        pub fn SDL_GetKeyState(numkeys: *mut c_int) -> *mut uint8_t;
237        pub fn SDL_GetModState() -> SDLMod;
238        pub fn SDL_GetKeyName(key: SDLKey) -> *mut c_schar;
239        pub fn SDL_JoystickEventState(state: c_int) -> c_int;
240        pub fn SDL_GetAppState() -> uint8_t;
241        pub fn SDL_EnableUNICODE(enable: c_int) -> c_int;
242        pub fn SDL_EnableKeyRepeat(delay: c_int, interval: c_int) -> c_int;
243        pub fn SDL_SetModState(modstate: SDLMod);
244        pub fn SDL_PumpEvents();
245    }
246}
247
248#[derive(PartialEq, Eq, Copy, Clone)]
249pub enum AppState {
250    MouseFocus = ll::SDL_APPMOUSEFOCUS as isize,
251    InputFocus = ll::SDL_APPINPUTFOCUS as isize,
252    Active = ll::SDL_APPACTIVE as isize
253}
254
255fn wrap_app_state(bitflags: u8) -> Vec<AppState> {
256    let flags = [AppState::MouseFocus,
257        AppState::InputFocus,
258        AppState::Active];
259
260    flags.iter().filter_map(|&flag| {
261        if bitflags & (flag as u8) != 0 { Some(flag) }
262        else { None }
263    }).collect()
264}
265
266#[derive(PartialEq, Copy, Clone)]
267pub enum RepeatDelay {
268    Default,
269    Custom(isize)
270}
271
272#[derive(PartialEq, Copy, Clone)]
273pub enum RepeatInterval {
274    Default,
275    Custom(isize)
276}
277
278#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
279pub enum Key {
280    Unknown = ll::SDLK_UNKNOWN as isize,
281    Backspace = ll::SDLK_BACKSPACE as isize,
282    Tab = ll::SDLK_TAB as isize,
283    Clear = ll::SDLK_CLEAR as isize,
284    Return = ll::SDLK_RETURN as isize,
285    Pause = ll::SDLK_PAUSE as isize,
286    Escape = ll::SDLK_ESCAPE as isize,
287    Space = ll::SDLK_SPACE as isize,
288    Exclaim = ll::SDLK_EXCLAIM as isize,
289    Quotedbl = ll::SDLK_QUOTEDBL as isize,
290    Hash = ll::SDLK_HASH as isize,
291    Dollar = ll::SDLK_DOLLAR as isize,
292    Ampersand = ll::SDLK_AMPERSAND as isize,
293    Quote = ll::SDLK_QUOTE as isize,
294    LeftParen = ll::SDLK_LEFTPAREN as isize,
295    RightParen = ll::SDLK_RIGHTPAREN as isize,
296    Asterisk = ll::SDLK_ASTERISK as isize,
297    Plus = ll::SDLK_PLUS as isize,
298    Comma = ll::SDLK_COMMA as isize,
299    Minus = ll::SDLK_MINUS as isize,
300    Period = ll::SDLK_PERIOD as isize,
301    Slash = ll::SDLK_SLASH as isize,
302    Num0 = ll::SDLK_0 as isize,
303    Num1 = ll::SDLK_1 as isize,
304    Num2 = ll::SDLK_2 as isize,
305    Num3 = ll::SDLK_3 as isize,
306    Num4 = ll::SDLK_4 as isize,
307    Num5 = ll::SDLK_5 as isize,
308    Num6 = ll::SDLK_6 as isize,
309    Num7 = ll::SDLK_7 as isize,
310    Num8 = ll::SDLK_8 as isize,
311    Num9 = ll::SDLK_9 as isize,
312    Colon = ll::SDLK_COLON as isize,
313    Semicolon = ll::SDLK_SEMICOLON as isize,
314    Less = ll::SDLK_LESS as isize,
315    Equals = ll::SDLK_EQUALS as isize,
316    Greater = ll::SDLK_GREATER as isize,
317    Question = ll::SDLK_QUESTION as isize,
318    At = ll::SDLK_AT as isize,
319    LeftBracket = ll::SDLK_LEFTBRACKET as isize,
320    Backslash = ll::SDLK_BACKSLASH as isize,
321    RightBracket = ll::SDLK_RIGHTBRACKET as isize,
322    Caret = ll::SDLK_CARET as isize,
323    Underscore = ll::SDLK_UNDERSCORE as isize,
324    Backquote = ll::SDLK_BACKQUOTE as isize,
325    A = ll::SDLK_a as isize,
326    B = ll::SDLK_b as isize,
327    C = ll::SDLK_c as isize,
328    D = ll::SDLK_d as isize,
329    E = ll::SDLK_e as isize,
330    F = ll::SDLK_f as isize,
331    G = ll::SDLK_g as isize,
332    H = ll::SDLK_h as isize,
333    I = ll::SDLK_i as isize,
334    J = ll::SDLK_j as isize,
335    K = ll::SDLK_k as isize,
336    L = ll::SDLK_l as isize,
337    M = ll::SDLK_m as isize,
338    N = ll::SDLK_n as isize,
339    O = ll::SDLK_o as isize,
340    P = ll::SDLK_p as isize,
341    Q = ll::SDLK_q as isize,
342    R = ll::SDLK_r as isize,
343    S = ll::SDLK_s as isize,
344    T = ll::SDLK_t as isize,
345    U = ll::SDLK_u as isize,
346    V = ll::SDLK_v as isize,
347    W = ll::SDLK_w as isize,
348    X = ll::SDLK_x as isize,
349    Y = ll::SDLK_y as isize,
350    Z = ll::SDLK_z as isize,
351    Delete = ll::SDLK_DELETE as isize,
352    World0 = ll::SDLK_WORLD_0 as isize,
353    World1 = ll::SDLK_WORLD_1 as isize,
354    World2 = ll::SDLK_WORLD_2 as isize,
355    World3 = ll::SDLK_WORLD_3 as isize,
356    World4 = ll::SDLK_WORLD_4 as isize,
357    World5 = ll::SDLK_WORLD_5 as isize,
358    World6 = ll::SDLK_WORLD_6 as isize,
359    World7 = ll::SDLK_WORLD_7 as isize,
360    World8 = ll::SDLK_WORLD_8 as isize,
361    World9 = ll::SDLK_WORLD_9 as isize,
362    World10 = ll::SDLK_WORLD_10 as isize,
363    World11 = ll::SDLK_WORLD_11 as isize,
364    World12 = ll::SDLK_WORLD_12 as isize,
365    World13 = ll::SDLK_WORLD_13 as isize,
366    World14 = ll::SDLK_WORLD_14 as isize,
367    World15 = ll::SDLK_WORLD_15 as isize,
368    World16 = ll::SDLK_WORLD_16 as isize,
369    World17 = ll::SDLK_WORLD_17 as isize,
370    World18 = ll::SDLK_WORLD_18 as isize,
371    World19 = ll::SDLK_WORLD_19 as isize,
372    World20 = ll::SDLK_WORLD_20 as isize,
373    World21 = ll::SDLK_WORLD_21 as isize,
374    World22 = ll::SDLK_WORLD_22 as isize,
375    World23 = ll::SDLK_WORLD_23 as isize,
376    World24 = ll::SDLK_WORLD_24 as isize,
377    World25 = ll::SDLK_WORLD_25 as isize,
378    World26 = ll::SDLK_WORLD_26 as isize,
379    World27 = ll::SDLK_WORLD_27 as isize,
380    World28 = ll::SDLK_WORLD_28 as isize,
381    World29 = ll::SDLK_WORLD_29 as isize,
382    World30 = ll::SDLK_WORLD_30 as isize,
383    World31 = ll::SDLK_WORLD_31 as isize,
384    World32 = ll::SDLK_WORLD_32 as isize,
385    World33 = ll::SDLK_WORLD_33 as isize,
386    World34 = ll::SDLK_WORLD_34 as isize,
387    World35 = ll::SDLK_WORLD_35 as isize,
388    World36 = ll::SDLK_WORLD_36 as isize,
389    World37 = ll::SDLK_WORLD_37 as isize,
390    World38 = ll::SDLK_WORLD_38 as isize,
391    World39 = ll::SDLK_WORLD_39 as isize,
392    World40 = ll::SDLK_WORLD_40 as isize,
393    World41 = ll::SDLK_WORLD_41 as isize,
394    World42 = ll::SDLK_WORLD_42 as isize,
395    World43 = ll::SDLK_WORLD_43 as isize,
396    World44 = ll::SDLK_WORLD_44 as isize,
397    World45 = ll::SDLK_WORLD_45 as isize,
398    World46 = ll::SDLK_WORLD_46 as isize,
399    World47 = ll::SDLK_WORLD_47 as isize,
400    World48 = ll::SDLK_WORLD_48 as isize,
401    World49 = ll::SDLK_WORLD_49 as isize,
402    World50 = ll::SDLK_WORLD_50 as isize,
403    World51 = ll::SDLK_WORLD_51 as isize,
404    World52 = ll::SDLK_WORLD_52 as isize,
405    World53 = ll::SDLK_WORLD_53 as isize,
406    World54 = ll::SDLK_WORLD_54 as isize,
407    World55 = ll::SDLK_WORLD_55 as isize,
408    World56 = ll::SDLK_WORLD_56 as isize,
409    World57 = ll::SDLK_WORLD_57 as isize,
410    World58 = ll::SDLK_WORLD_58 as isize,
411    World59 = ll::SDLK_WORLD_59 as isize,
412    World60 = ll::SDLK_WORLD_60 as isize,
413    World61 = ll::SDLK_WORLD_61 as isize,
414    World62 = ll::SDLK_WORLD_62 as isize,
415    World63 = ll::SDLK_WORLD_63 as isize,
416    World64 = ll::SDLK_WORLD_64 as isize,
417    World65 = ll::SDLK_WORLD_65 as isize,
418    World66 = ll::SDLK_WORLD_66 as isize,
419    World67 = ll::SDLK_WORLD_67 as isize,
420    World68 = ll::SDLK_WORLD_68 as isize,
421    World69 = ll::SDLK_WORLD_69 as isize,
422    World70 = ll::SDLK_WORLD_70 as isize,
423    World71 = ll::SDLK_WORLD_71 as isize,
424    World72 = ll::SDLK_WORLD_72 as isize,
425    World73 = ll::SDLK_WORLD_73 as isize,
426    World74 = ll::SDLK_WORLD_74 as isize,
427    World75 = ll::SDLK_WORLD_75 as isize,
428    World76 = ll::SDLK_WORLD_76 as isize,
429    World77 = ll::SDLK_WORLD_77 as isize,
430    World78 = ll::SDLK_WORLD_78 as isize,
431    World79 = ll::SDLK_WORLD_79 as isize,
432    World80 = ll::SDLK_WORLD_80 as isize,
433    World81 = ll::SDLK_WORLD_81 as isize,
434    World82 = ll::SDLK_WORLD_82 as isize,
435    World83 = ll::SDLK_WORLD_83 as isize,
436    World84 = ll::SDLK_WORLD_84 as isize,
437    World85 = ll::SDLK_WORLD_85 as isize,
438    World86 = ll::SDLK_WORLD_86 as isize,
439    World87 = ll::SDLK_WORLD_87 as isize,
440    World88 = ll::SDLK_WORLD_88 as isize,
441    World89 = ll::SDLK_WORLD_89 as isize,
442    World90 = ll::SDLK_WORLD_90 as isize,
443    World91 = ll::SDLK_WORLD_91 as isize,
444    World92 = ll::SDLK_WORLD_92 as isize,
445    World93 = ll::SDLK_WORLD_93 as isize,
446    World94 = ll::SDLK_WORLD_94 as isize,
447    World95 = ll::SDLK_WORLD_95 as isize,
448    Kp0 = ll::SDLK_KP0 as isize,
449    Kp1 = ll::SDLK_KP1 as isize,
450    Kp2 = ll::SDLK_KP2 as isize,
451    Kp3 = ll::SDLK_KP3 as isize,
452    Kp4 = ll::SDLK_KP4 as isize,
453    Kp5 = ll::SDLK_KP5 as isize,
454    Kp6 = ll::SDLK_KP6 as isize,
455    Kp7 = ll::SDLK_KP7 as isize,
456    Kp8 = ll::SDLK_KP8 as isize,
457    Kp9 = ll::SDLK_KP9 as isize,
458    KpPeriod = ll::SDLK_KP_PERIOD as isize,
459    KpDivide = ll::SDLK_KP_DIVIDE as isize,
460    KpMultiply = ll::SDLK_KP_MULTIPLY as isize,
461    KpMinus = ll::SDLK_KP_MINUS as isize,
462    KpPlus = ll::SDLK_KP_PLUS as isize,
463    KpEnter = ll::SDLK_KP_ENTER as isize,
464    KpEquals = ll::SDLK_KP_EQUALS as isize,
465    Up = ll::SDLK_UP as isize,
466    Down = ll::SDLK_DOWN as isize,
467    Right = ll::SDLK_RIGHT as isize,
468    Left = ll::SDLK_LEFT as isize,
469    Insert = ll::SDLK_INSERT as isize,
470    Home = ll::SDLK_HOME as isize,
471    End = ll::SDLK_END as isize,
472    PageUp = ll::SDLK_PAGEUP as isize,
473    PageDown = ll::SDLK_PAGEDOWN as isize,
474    F1 = ll::SDLK_F1 as isize,
475    F2 = ll::SDLK_F2 as isize,
476    F3 = ll::SDLK_F3 as isize,
477    F4 = ll::SDLK_F4 as isize,
478    F5 = ll::SDLK_F5 as isize,
479    F6 = ll::SDLK_F6 as isize,
480    F7 = ll::SDLK_F7 as isize,
481    F8 = ll::SDLK_F8 as isize,
482    F9 = ll::SDLK_F9 as isize,
483    F10 = ll::SDLK_F10 as isize,
484    F11 = ll::SDLK_F11 as isize,
485    F12 = ll::SDLK_F12 as isize,
486    F13 = ll::SDLK_F13 as isize,
487    F14 = ll::SDLK_F14 as isize,
488    F15 = ll::SDLK_F15 as isize,
489    NumLock = ll::SDLK_NUMLOCK as isize,
490    CapsLock = ll::SDLK_CAPSLOCK as isize,
491    ScrolLock = ll::SDLK_SCROLLOCK as isize,
492    RShift = ll::SDLK_RSHIFT as isize,
493    LShift = ll::SDLK_LSHIFT as isize,
494    RCtrl = ll::SDLK_RCTRL as isize,
495    LCtrl = ll::SDLK_LCTRL as isize,
496    RAlt = ll::SDLK_RALT as isize,
497    LAlt = ll::SDLK_LALT as isize,
498    RMeta = ll::SDLK_RMETA as isize,
499    LMeta = ll::SDLK_LMETA as isize,
500    LSuper = ll::SDLK_LSUPER as isize,
501    RSuper = ll::SDLK_RSUPER as isize,
502    Mode = ll::SDLK_MODE as isize,
503    Compose = ll::SDLK_COMPOSE as isize,
504    Help = ll::SDLK_HELP as isize,
505    Print = ll::SDLK_PRINT as isize,
506    SysReq = ll::SDLK_SYSREQ as isize,
507    Break = ll::SDLK_BREAK as isize,
508    Menu = ll::SDLK_MENU as isize,
509    Power = ll::SDLK_POWER as isize,
510    Euro = ll::SDLK_EURO as isize,
511    Undo = ll::SDLK_UNDO as isize,
512    Last,
513}
514
515impl FromPrimitive for Key {
516    fn from_i64(n: i64) -> Option<Key> {
517        use self::Key::*;
518
519        Some(match n as ll::SDLKey {
520            ll::SDLK_UNKNOWN => Unknown,
521            ll::SDLK_BACKSPACE => Backspace,
522            ll::SDLK_TAB => Tab,
523            ll::SDLK_CLEAR => Clear,
524            ll::SDLK_RETURN => Return,
525            ll::SDLK_PAUSE => Pause,
526            ll::SDLK_ESCAPE => Escape,
527            ll::SDLK_SPACE => Space,
528            ll::SDLK_EXCLAIM => Exclaim,
529            ll::SDLK_QUOTEDBL => Quotedbl,
530            ll::SDLK_HASH => Hash,
531            ll::SDLK_DOLLAR => Dollar,
532            ll::SDLK_AMPERSAND => Ampersand,
533            ll::SDLK_QUOTE => Quote,
534            ll::SDLK_LEFTPAREN => LeftParen,
535            ll::SDLK_RIGHTPAREN => RightParen,
536            ll::SDLK_ASTERISK => Asterisk,
537            ll::SDLK_PLUS => Plus,
538            ll::SDLK_COMMA => Comma,
539            ll::SDLK_MINUS => Minus,
540            ll::SDLK_PERIOD => Period,
541            ll::SDLK_SLASH => Slash,
542            ll::SDLK_0 => Num0,
543            ll::SDLK_1 => Num1,
544            ll::SDLK_2 => Num2,
545            ll::SDLK_3 => Num3,
546            ll::SDLK_4 => Num4,
547            ll::SDLK_5 => Num5,
548            ll::SDLK_6 => Num6,
549            ll::SDLK_7 => Num7,
550            ll::SDLK_8 => Num8,
551            ll::SDLK_9 => Num9,
552            ll::SDLK_COLON => Colon,
553            ll::SDLK_SEMICOLON => Semicolon,
554            ll::SDLK_LESS => Less,
555            ll::SDLK_EQUALS => Equals,
556            ll::SDLK_GREATER => Greater,
557            ll::SDLK_QUESTION => Question,
558            ll::SDLK_AT => At,
559            ll::SDLK_LEFTBRACKET => LeftBracket,
560            ll::SDLK_BACKSLASH => Backslash,
561            ll::SDLK_RIGHTBRACKET => RightBracket,
562            ll::SDLK_CARET => Caret,
563            ll::SDLK_UNDERSCORE => Underscore,
564            ll::SDLK_BACKQUOTE => Backquote,
565            ll::SDLK_a => A,
566            ll::SDLK_b => B,
567            ll::SDLK_c => C,
568            ll::SDLK_d => D,
569            ll::SDLK_e => E,
570            ll::SDLK_f => F,
571            ll::SDLK_g => G,
572            ll::SDLK_h => H,
573            ll::SDLK_i => I,
574            ll::SDLK_j => J,
575            ll::SDLK_k => K,
576            ll::SDLK_l => L,
577            ll::SDLK_m => M,
578            ll::SDLK_n => N,
579            ll::SDLK_o => O,
580            ll::SDLK_p => P,
581            ll::SDLK_q => Q,
582            ll::SDLK_r => R,
583            ll::SDLK_s => S,
584            ll::SDLK_t => T,
585            ll::SDLK_u => U,
586            ll::SDLK_v => V,
587            ll::SDLK_w => W,
588            ll::SDLK_x => X,
589            ll::SDLK_y => Y,
590            ll::SDLK_z => Z,
591            ll::SDLK_DELETE => Delete,
592            ll::SDLK_WORLD_0 => World0,
593            ll::SDLK_WORLD_1 => World1,
594            ll::SDLK_WORLD_2 => World2,
595            ll::SDLK_WORLD_3 => World3,
596            ll::SDLK_WORLD_4 => World4,
597            ll::SDLK_WORLD_5 => World5,
598            ll::SDLK_WORLD_6 => World6,
599            ll::SDLK_WORLD_7 => World7,
600            ll::SDLK_WORLD_8 => World8,
601            ll::SDLK_WORLD_9 => World9,
602            ll::SDLK_WORLD_10 => World10,
603            ll::SDLK_WORLD_11 => World11,
604            ll::SDLK_WORLD_12 => World12,
605            ll::SDLK_WORLD_13 => World13,
606            ll::SDLK_WORLD_14 => World14,
607            ll::SDLK_WORLD_15 => World15,
608            ll::SDLK_WORLD_16 => World16,
609            ll::SDLK_WORLD_17 => World17,
610            ll::SDLK_WORLD_18 => World18,
611            ll::SDLK_WORLD_19 => World19,
612            ll::SDLK_WORLD_20 => World20,
613            ll::SDLK_WORLD_21 => World21,
614            ll::SDLK_WORLD_22 => World22,
615            ll::SDLK_WORLD_23 => World23,
616            ll::SDLK_WORLD_24 => World24,
617            ll::SDLK_WORLD_25 => World25,
618            ll::SDLK_WORLD_26 => World26,
619            ll::SDLK_WORLD_27 => World27,
620            ll::SDLK_WORLD_28 => World28,
621            ll::SDLK_WORLD_29 => World29,
622            ll::SDLK_WORLD_30 => World30,
623            ll::SDLK_WORLD_31 => World31,
624            ll::SDLK_WORLD_32 => World32,
625            ll::SDLK_WORLD_33 => World33,
626            ll::SDLK_WORLD_34 => World34,
627            ll::SDLK_WORLD_35 => World35,
628            ll::SDLK_WORLD_36 => World36,
629            ll::SDLK_WORLD_37 => World37,
630            ll::SDLK_WORLD_38 => World38,
631            ll::SDLK_WORLD_39 => World39,
632            ll::SDLK_WORLD_40 => World40,
633            ll::SDLK_WORLD_41 => World41,
634            ll::SDLK_WORLD_42 => World42,
635            ll::SDLK_WORLD_43 => World43,
636            ll::SDLK_WORLD_44 => World44,
637            ll::SDLK_WORLD_45 => World45,
638            ll::SDLK_WORLD_46 => World46,
639            ll::SDLK_WORLD_47 => World47,
640            ll::SDLK_WORLD_48 => World48,
641            ll::SDLK_WORLD_49 => World49,
642            ll::SDLK_WORLD_50 => World50,
643            ll::SDLK_WORLD_51 => World51,
644            ll::SDLK_WORLD_52 => World52,
645            ll::SDLK_WORLD_53 => World53,
646            ll::SDLK_WORLD_54 => World54,
647            ll::SDLK_WORLD_55 => World55,
648            ll::SDLK_WORLD_56 => World56,
649            ll::SDLK_WORLD_57 => World57,
650            ll::SDLK_WORLD_58 => World58,
651            ll::SDLK_WORLD_59 => World59,
652            ll::SDLK_WORLD_60 => World60,
653            ll::SDLK_WORLD_61 => World61,
654            ll::SDLK_WORLD_62 => World62,
655            ll::SDLK_WORLD_63 => World63,
656            ll::SDLK_WORLD_64 => World64,
657            ll::SDLK_WORLD_65 => World65,
658            ll::SDLK_WORLD_66 => World66,
659            ll::SDLK_WORLD_67 => World67,
660            ll::SDLK_WORLD_68 => World68,
661            ll::SDLK_WORLD_69 => World69,
662            ll::SDLK_WORLD_70 => World70,
663            ll::SDLK_WORLD_71 => World71,
664            ll::SDLK_WORLD_72 => World72,
665            ll::SDLK_WORLD_73 => World73,
666            ll::SDLK_WORLD_74 => World74,
667            ll::SDLK_WORLD_75 => World75,
668            ll::SDLK_WORLD_76 => World76,
669            ll::SDLK_WORLD_77 => World77,
670            ll::SDLK_WORLD_78 => World78,
671            ll::SDLK_WORLD_79 => World79,
672            ll::SDLK_WORLD_80 => World80,
673            ll::SDLK_WORLD_81 => World81,
674            ll::SDLK_WORLD_82 => World82,
675            ll::SDLK_WORLD_83 => World83,
676            ll::SDLK_WORLD_84 => World84,
677            ll::SDLK_WORLD_85 => World85,
678            ll::SDLK_WORLD_86 => World86,
679            ll::SDLK_WORLD_87 => World87,
680            ll::SDLK_WORLD_88 => World88,
681            ll::SDLK_WORLD_89 => World89,
682            ll::SDLK_WORLD_90 => World90,
683            ll::SDLK_WORLD_91 => World91,
684            ll::SDLK_WORLD_92 => World92,
685            ll::SDLK_WORLD_93 => World93,
686            ll::SDLK_WORLD_94 => World94,
687            ll::SDLK_WORLD_95 => World95,
688            ll::SDLK_KP0 => Kp0,
689            ll::SDLK_KP1 => Kp1,
690            ll::SDLK_KP2 => Kp2,
691            ll::SDLK_KP3 => Kp3,
692            ll::SDLK_KP4 => Kp4,
693            ll::SDLK_KP5 => Kp5,
694            ll::SDLK_KP6 => Kp6,
695            ll::SDLK_KP7 => Kp7,
696            ll::SDLK_KP8 => Kp8,
697            ll::SDLK_KP9 => Kp9,
698            ll::SDLK_KP_PERIOD => KpPeriod,
699            ll::SDLK_KP_DIVIDE => KpDivide,
700            ll::SDLK_KP_MULTIPLY => KpMultiply,
701            ll::SDLK_KP_MINUS => KpMinus,
702            ll::SDLK_KP_PLUS => KpPlus,
703            ll::SDLK_KP_ENTER => KpEnter,
704            ll::SDLK_KP_EQUALS => KpEquals,
705            ll::SDLK_UP => Up,
706            ll::SDLK_DOWN => Down,
707            ll::SDLK_RIGHT => Right,
708            ll::SDLK_LEFT => Left,
709            ll::SDLK_INSERT => Insert,
710            ll::SDLK_HOME => Home,
711            ll::SDLK_END => End,
712            ll::SDLK_PAGEUP => PageUp,
713            ll::SDLK_PAGEDOWN => PageDown,
714            ll::SDLK_F1 => F1,
715            ll::SDLK_F2 => F2,
716            ll::SDLK_F3 => F3,
717            ll::SDLK_F4 => F4,
718            ll::SDLK_F5 => F5,
719            ll::SDLK_F6 => F6,
720            ll::SDLK_F7 => F7,
721            ll::SDLK_F8 => F8,
722            ll::SDLK_F9 => F9,
723            ll::SDLK_F10 => F10,
724            ll::SDLK_F11 => F11,
725            ll::SDLK_F12 => F12,
726            ll::SDLK_F13 => F13,
727            ll::SDLK_F14 => F14,
728            ll::SDLK_F15 => F15,
729            ll::SDLK_NUMLOCK => NumLock,
730            ll::SDLK_CAPSLOCK => CapsLock,
731            ll::SDLK_SCROLLOCK => ScrolLock,
732            ll::SDLK_RSHIFT => RShift,
733            ll::SDLK_LSHIFT => LShift,
734            ll::SDLK_RCTRL => RCtrl,
735            ll::SDLK_LCTRL => LCtrl,
736            ll::SDLK_RALT => RAlt,
737            ll::SDLK_LALT => LAlt,
738            ll::SDLK_RMETA => RMeta,
739            ll::SDLK_LMETA => LMeta,
740            ll::SDLK_LSUPER => LSuper,
741            ll::SDLK_RSUPER => RSuper,
742            ll::SDLK_MODE => Mode,
743            ll::SDLK_COMPOSE => Compose,
744            ll::SDLK_HELP => Help,
745            ll::SDLK_PRINT => Print,
746            ll::SDLK_SYSREQ => SysReq,
747            ll::SDLK_BREAK => Break,
748            ll::SDLK_MENU => Menu,
749            ll::SDLK_POWER => Power,
750            ll::SDLK_EURO => Euro,
751            ll::SDLK_UNDO => Undo,
752            _ => return None,
753        })
754    }
755
756    fn from_u64(n: u64) -> Option<Key> { FromPrimitive::from_i64(n as i64) }
757}
758
759fn wrap_key(i: ll::SDLKey) -> Option<Key> {
760    FromPrimitive::from_usize(i as usize)
761}
762
763#[derive(PartialEq, Eq, Copy, Clone)]
764pub enum Mod {
765     None = 0x0000,
766     LShift = 0x0001,
767     RShift = 0x0002,
768     LCtrl = 0x0040,
769     RCtrl = 0x0080,
770     LAlt = 0x0100,
771     RAlt = 0x0200,
772     LMeta = 0x0400,
773     RMeta = 0x0800,
774     Num = 0x1000,
775     Caps = 0x2000,
776     Mode = 0x4000,
777     Reserved = 0x8000
778}
779
780fn wrap_mod_state(bitflags: ll::SDLMod) -> Vec<Mod> {
781    let flags = [Mod::None,
782        Mod::LShift,
783        Mod::RShift,
784        Mod::LCtrl,
785        Mod::RCtrl,
786        Mod::LAlt,
787        Mod::RAlt,
788        Mod::LMeta,
789        Mod::RMeta,
790        Mod::Num,
791        Mod::Caps,
792        Mod::Mode,
793        Mod::Reserved];
794
795    flags.iter().filter_map(|&flag| {
796        if bitflags & (flag as ll::SDLMod) != 0 { Some(flag) }
797        else { None }
798    }).collect()
799}
800
801#[derive(PartialEq, Eq, Copy, Clone)]
802pub enum HatState {
803    Centered,
804    Up,
805    Right,
806    Down,
807    Left
808}
809
810fn wrap_hat_state(bitflags: u8) -> Vec<HatState> {
811    let flags = [HatState::Centered,
812        HatState::Up,
813        HatState::Right,
814        HatState::Down,
815        HatState::Left];
816
817    flags.iter().filter_map(|&flag| {
818        if bitflags & (flag as u8) != 0 { Some(flag) }
819        else { None }
820    }).collect()
821}
822
823#[derive(PartialEq, Eq, Copy, Clone)]
824pub enum Mouse {
825    Left = 1,
826    Middle,
827    Right,
828    WheelUp,
829    WheelDown
830}
831
832impl FromPrimitive for Mouse {
833    fn from_i64(n: i64) -> Option<Mouse> {
834        Some(match n {
835            1 => Mouse::Left,
836            2 => Mouse::Middle,
837            3 => Mouse::Right,
838            4 => Mouse::WheelUp,
839            5 => Mouse::WheelDown,
840            _ => return None,
841        })
842    }
843
844    fn from_u64(n: u64) -> Option<Mouse> { FromPrimitive::from_i64(n as i64) }
845}
846
847fn wrap_mouse(bitflags: u8) -> Option<Mouse> {
848    FromPrimitive::from_u8(bitflags)
849}
850
851#[derive(PartialEq, Eq, Copy, Clone)]
852pub enum MouseState {
853    Left = 1,
854    Middle,
855    Right,
856    WheelUp,
857    WheelDown,
858    X1,
859    X2
860}
861
862fn wrap_mouse_state(bitflags: u8) -> Vec<MouseState> {
863    let flags = [MouseState::Left,
864        MouseState::Middle,
865        MouseState::Right,
866        MouseState::WheelUp,
867        MouseState::WheelDown,
868        MouseState::X1,
869        MouseState::X2];
870
871    flags.iter().filter_map(|&flag| {
872        if bitflags & (flag as u8) != 0 { Some(flag) }
873        else { None }
874    }).collect()
875}
876
877#[derive(PartialEq)]
878pub enum Event {
879    // TODO: TextInput, TextEditing
880     None,
881     Active(bool, Vec<AppState>),
882     Key(Key, bool, Vec<Mod>, u16), // RFC: do you need the scancode?
883     MouseMotion(Vec<MouseState>, u16, u16, i16, i16),
884     MouseButton(Mouse, bool, u16, u16),
885     JoyAxis(isize, isize, i16),
886     JoyBall(isize, isize, i16, i16),
887     JoyHat(isize, isize, Vec<HatState>),
888     JoyButton(isize, isize, bool),
889     Quit,
890    // TODO: SysWm
891     Resize(isize, isize),
892     Expose,
893    // TODO: User
894}
895
896fn null_event() -> ll::SDL_Event {
897    ll::SDL_Event { data: [0; 24] }
898}
899
900fn wrap_event(raw: ll::SDL_Event) -> Event {
901    unsafe {
902        let ty = raw._type();
903        let ty = if ty.is_null() { return Event::None; }
904                 else { *ty };
905
906        let ty : EventType = match FromPrimitive::from_usize(ty as usize) {
907            Some(ty) => ty,
908            None => return Event::None
909        };
910
911        match ty {
912            EventType::None => Event::None,
913            EventType::Active => {
914                let active = raw.active();
915                let active = if active.is_null() { return Event::None; }
916                             else { *active };
917
918                Event::Active(active.gain == 1, wrap_app_state(active.state))
919            }
920            EventType::KeyDown | EventType::KeyUp => {
921                let key = raw.key();
922                let (key, okey) = if key.is_null() { return Event::None; }
923                          else { ((*key).keysym, *key) };
924
925                match wrap_key(key.sym) {
926                    Some(sym) => {
927                        Event::Key(sym, okey.state == 1, wrap_mod_state(key._mod),
928                                 key.unicode)
929                    }
930                    None => Event::None
931                }
932            }
933            EventType::MouseMotion => {
934                let motion = raw.motion();
935                let motion = if motion.is_null() { return Event::None; }
936                             else { *motion };
937
938                Event::MouseMotion(wrap_mouse_state(motion.state), motion.x,
939                                 motion.y, motion.xrel, motion.yrel)
940            }
941            EventType::MouseButtonDown | EventType::MouseButtonUp => {
942                let obutton = raw.button();
943                let obutton = if obutton.is_null() { return Event::None; }
944                             else { *obutton };
945
946                match wrap_mouse(obutton.button) {
947                    Some(button) => {
948                        Event::MouseButton(button, obutton.state == 1,
949                                 obutton.x, obutton.y)
950                    }
951                    None => Event::None
952                }
953            }
954            EventType::JoyAxisMotion => {
955                let jaxis = raw.jaxis();
956                let jaxis = if jaxis.is_null() { return Event::None; }
957                            else { *jaxis };
958
959                Event::JoyAxis(jaxis.which as isize, jaxis.axis as isize,
960                             jaxis.value)
961            }
962            EventType::JoyBallMotion => {
963                let jball = raw.jball();
964                let jball = if jball.is_null() { return Event::None; }
965                            else { *jball };
966
967                Event::JoyBall(jball.which as isize, jball.ball as isize,
968                             jball.xrel, jball.yrel)
969            }
970            EventType::JoyHatMotion => {
971                let jhat = raw.jhat();
972                let jhat = if jhat.is_null() { return Event::None; }
973                           else { *jhat };
974
975                Event::JoyHat(jhat.which as isize, jhat.hat as isize,
976                            wrap_hat_state(jhat.value))
977            }
978            EventType::JoyButtonDown | EventType::JoyButtonUp => {
979                let jbutton = raw.jbutton();
980                let jbutton = if jbutton.is_null() { return Event::None; }
981                              else { *jbutton };
982
983                Event::JoyButton(jbutton.which as isize, jbutton.button as isize,
984                               jbutton.state == 1u8)
985            }
986            EventType::Quit => Event::Quit,
987            EventType::Resize => {
988                let resize = raw.resize();
989                let resize = if resize.is_null() { return Event::None; }
990                             else { *resize };
991
992                Event::Resize(resize.w as isize, resize.h as isize)
993            }
994            EventType::Expose => Event::Expose,
995            _ => Event::None
996        }
997    }
998}
999
1000#[derive(PartialEq, Eq, Copy, Clone)]
1001pub enum EventType {
1002    // TODO: TextInput, TextEditing
1003    None = ll::SDL_NOEVENT as isize,
1004    Active = ll::SDL_ACTIVEEVENT as isize,
1005    KeyDown = ll::SDL_KEYDOWN as isize,
1006    KeyUp = ll::SDL_KEYUP as isize,
1007    MouseMotion = ll::SDL_MOUSEMOTION as isize,
1008    MouseButtonDown = ll::SDL_MOUSEBUTTONDOWN as isize,
1009    MouseButtonUp = ll::SDL_MOUSEBUTTONUP as isize,
1010    JoyAxisMotion = ll::SDL_JOYAXISMOTION as isize,
1011    JoyBallMotion = ll::SDL_JOYBALLMOTION as isize,
1012    JoyHatMotion = ll::SDL_JOYHATMOTION as isize,
1013    JoyButtonDown = ll::SDL_JOYBUTTONDOWN as isize,
1014    JoyButtonUp = ll::SDL_JOYBUTTONUP as isize,
1015    Quit = ll::SDL_QUIT as isize,
1016    SysWM = ll::SDL_SYSWMEVENT as isize,
1017    Resize = ll::SDL_VIDEORESIZE as isize,
1018    Expose = ll::SDL_VIDEOEXPOSE as isize,
1019    User = ll::SDL_USEREVENT as isize,
1020}
1021
1022impl EventType {
1023    pub fn get_state(&self) -> bool { get_event_state(*self) }
1024    pub fn set_state(&self, state: bool) { set_event_state(*self, state) }
1025}
1026
1027impl FromPrimitive for EventType {
1028    fn from_i64(n: i64) -> Option<EventType> {
1029        Some(match n as ll::SDL_EventType {
1030            ll::SDL_NOEVENT => EventType::None,
1031            ll::SDL_ACTIVEEVENT => EventType::Active,
1032            ll::SDL_KEYDOWN => EventType::KeyDown,
1033            ll::SDL_KEYUP => EventType::KeyUp,
1034            ll::SDL_MOUSEMOTION => EventType::MouseMotion,
1035            ll::SDL_MOUSEBUTTONDOWN => EventType::MouseButtonDown,
1036            ll::SDL_MOUSEBUTTONUP => EventType::MouseButtonUp,
1037            ll::SDL_JOYAXISMOTION => EventType::JoyAxisMotion,
1038            ll::SDL_JOYBALLMOTION => EventType::JoyBallMotion,
1039            ll::SDL_JOYHATMOTION => EventType::JoyHatMotion,
1040            ll::SDL_JOYBUTTONDOWN => EventType::JoyButtonDown,
1041            ll::SDL_JOYBUTTONUP => EventType::JoyButtonUp,
1042            ll::SDL_QUIT => EventType::Quit,
1043            ll::SDL_SYSWMEVENT => EventType::SysWM,
1044            ll::SDL_VIDEORESIZE => EventType::Resize,
1045            ll::SDL_VIDEOEXPOSE => EventType::Expose,
1046            ll::SDL_USEREVENT => EventType::User,
1047            _ => return None,
1048        })
1049    }
1050
1051    fn from_u64(n: u64) -> Option<EventType> { FromPrimitive::from_i64(n as i64) }
1052}
1053
1054pub fn pump_events() {
1055    unsafe { ll::SDL_PumpEvents(); }
1056}
1057
1058// TODO: peep_events (a tricky one but doable)
1059
1060pub fn wait_event() -> Event {
1061    let mut raw = null_event();
1062    let success = unsafe { ll::SDL_WaitEvent(&mut raw)
1063                            == 1 as c_int };
1064
1065    if success { wrap_event(raw) }
1066    else { Event::None }
1067}
1068
1069pub fn poll_event() -> Event {
1070    pump_events();
1071
1072    let mut raw = null_event();
1073    let have = unsafe { ll::SDL_PollEvent(&mut raw) };
1074
1075    if have != 1 {
1076        return Event::None;
1077    }
1078
1079    wrap_event(raw)
1080}
1081
1082// TODO: set_event_filter, get_event_filter
1083
1084pub fn set_event_state(ty: EventType, state: bool) {
1085    unsafe { ll::SDL_EventState(ty as u8, state as c_int); }
1086}
1087
1088pub fn get_event_state(ty: EventType) -> bool {
1089    unsafe { ll::SDL_EventState(ty as u8, ll::SDL_QUERY as c_int)
1090             == ll::SDL_ENABLE as u8 }
1091}
1092
1093pub fn get_key_state() -> Vec<(Key, bool)> {
1094    let mut num = 0;
1095    let data = unsafe { ll::SDL_GetKeyState(&mut num) };
1096    let mut i = -1isize;
1097
1098    let buf = data as *const u8;
1099    let buf = unsafe { slice::from_raw_parts(buf, num as usize) };
1100    buf.iter().filter_map(|&state| {
1101        i += 1;
1102
1103        match wrap_key(i as ll::SDLKey) {
1104            Some(key) => Some((key, state == 1)),
1105            None => None
1106        }
1107    }).collect()
1108}
1109
1110pub fn get_mod_state() -> Vec<Mod> {
1111    unsafe { wrap_mod_state(ll::SDL_GetModState()) }
1112}
1113
1114pub fn set_mod_state(states: &[Mod]) {
1115    unsafe {
1116        ll::SDL_SetModState(states.iter().fold(0u32, |states, &state| {
1117            states | state as ll::SDLMod
1118        }));
1119    }
1120}
1121
1122pub fn get_key_name(key: Key) -> String {
1123    unsafe {
1124        let cstr = ll::SDL_GetKeyName(key as ll::SDLKey);
1125
1126        str::from_utf8(CStr::from_ptr(mem::transmute_copy(&cstr)).to_bytes()).unwrap().to_string()
1127    }
1128}
1129
1130pub fn set_joystick_event_state(state: bool) {
1131    unsafe {
1132        ll::SDL_JoystickEventState(state as c_int);
1133    }
1134}
1135
1136pub fn get_joystick_event_state() -> bool {
1137    unsafe {
1138        ll::SDL_JoystickEventState(ll::SDL_QUERY as c_int) == ll::SDL_ENABLE as c_int
1139    }
1140}
1141
1142pub fn toggle_joystick_event_state() {
1143    set_joystick_event_state(!get_joystick_event_state());
1144}
1145
1146pub fn get_app_state() -> Vec<AppState> {
1147    let bitflags = unsafe { ll::SDL_GetAppState() };
1148
1149    wrap_app_state(bitflags)
1150}
1151
1152pub fn enable_unicode(enable: bool) {
1153    unsafe { ll::SDL_EnableUNICODE(enable as c_int); }
1154}
1155
1156pub fn is_unicode_enabled() -> bool {
1157    unsafe { ll::SDL_EnableUNICODE(-1 as c_int) == 1 }
1158}
1159
1160pub fn enable_key_repeat(delay: RepeatDelay, interval: RepeatInterval) -> bool {
1161    let delay = match delay {
1162        RepeatDelay::Default => 500,
1163        RepeatDelay::Custom(delay) => delay
1164    };
1165    let interval = match interval {
1166        RepeatInterval::Default => 30,
1167        RepeatInterval::Custom(interval) => interval
1168    };
1169
1170    unsafe {
1171        ll::SDL_EnableKeyRepeat(delay as c_int, interval as c_int) == 0 as c_int
1172    }
1173}
1174
1175// get_mouse_state, get_relative_mouse_state, start_text_input, stop_text_input, set_text_input_rect