Add touch API

This commit is contained in:
Travis Watkins
2013-09-16 11:39:08 -05:00
parent a5e9804803
commit 5fd0af58f2
+43 -14
View File
@@ -1,19 +1,48 @@
use std::ptr;
pub type TouchDevice = ll::SDL_TouchID;
#[deriving(Eq)]
pub struct Finger {
id: TouchDevice,
x: f32,
y: f32,
pressure: f32,
}
pub mod ll {
use std::libc::{c_float, c_int, int64_t};
use std::libc::{c_int, int64_t};
use touch::Finger;
pub type SDL_TouchID = int64_t;
pub type SDL_FingerID = int64_t;
pub type SDL_TouchID = int64_t;
pub type SDL_FingerID = int64_t;
pub type SDL_Finger = Finger;
pub struct SDL_Finger {
id: SDL_FingerID,
x: c_float,
y: c_float,
pressure: c_float,
}
externfn!(fn SDL_GetNumTouchDevices() -> c_int)
externfn!(fn SDL_GetTouchDevice(index: c_int) -> SDL_TouchID)
externfn!(fn SDL_GetNumTouchFingers(touchID: SDL_TouchID) -> c_int)
externfn!(fn SDL_GetTouchFinger(touchID: SDL_TouchID, index: c_int))
externfn!(fn SDL_GetNumTouchDevices() -> c_int)
externfn!(fn SDL_GetTouchDevice(index: c_int) -> SDL_TouchID)
externfn!(fn SDL_GetNumTouchFingers(touchID: SDL_TouchID) -> c_int)
externfn!(fn SDL_GetTouchFinger(touchID: SDL_TouchID, index: c_int) ->
*SDL_Finger)
}
pub fn get_num_touch_devices() -> int {
unsafe { ll::SDL_GetNumTouchDevices() as int }
}
pub fn get_touch_device(index: int) -> TouchDevice {
unsafe { ll::SDL_GetTouchDevice(index as i32) }
}
pub fn get_num_touch_fingers(touch: TouchDevice) -> int {
unsafe { ll::SDL_GetNumTouchFingers(touch) as int }
}
pub fn get_touch_finger(touch: TouchDevice, index: int) -> Option<Finger> {
let raw = unsafe { ll::SDL_GetTouchFinger(touch, index as i32) };
if raw == ptr::null() {
None
} else {
unsafe { Some(*raw) }
}
}