use std::intrinsics::TypeId;
use GenericEvent;
use ptr::Ptr;
pub trait MouseCursorEvent {
fn from_xy(x: f64, y: f64) -> Option<Self>;
fn mouse_cursor<U>(&self, f: |f64, f64| -> U) -> Option<U>;
}
impl<T: GenericEvent> MouseCursorEvent for T {
#[inline(always)]
fn from_xy(x: f64, y: f64) -> Option<T> {
let id = TypeId::of::<Box<MouseCursorEvent>>();
Ptr::with_ref::<(f64, f64), Option<T>>(&(x, y), |ptr| {
GenericEvent::from_event(id, ptr)
})
}
#[inline(always)]
fn mouse_cursor<U>(&self, f: |f64, f64| -> U) -> Option<U> {
let id = TypeId::of::<Box<MouseCursorEvent>>();
self.with_event(id, |ptr| {
let &(x, y) = ptr.expect::<(f64, f64)>();
f(x, y)
})
}
}
pub trait MouseRelativeEvent {
fn from_xy(x: f64, y: f64) -> Option<Self>;
fn mouse_relative<U>(&self, f: |f64, f64| -> U) -> Option<U>;
}
impl<T: GenericEvent> MouseRelativeEvent for T {
#[inline(always)]
fn from_xy(x: f64, y: f64) -> Option<T> {
let id = TypeId::of::<Box<MouseRelativeEvent>>();
Ptr::with_ref::<(f64, f64), Option<T>>(&(x, y), |ptr| {
GenericEvent::from_event(id, ptr)
})
}
#[inline(always)]
fn mouse_relative<U>(&self, f: |f64, f64| -> U) -> Option<U> {
let id = TypeId::of::<Box<MouseRelativeEvent>>();
self.with_event(id, |ptr| {
let &(x, y) = ptr.expect::<(f64, f64)>();
f(x, y)
})
}
}
pub trait MouseScrollEvent {
fn from_xy(x: f64, y: f64) -> Option<Self>;
fn mouse_scroll<U>(&self, f: |f64, f64| -> U) -> Option<U>;
}
impl<T: GenericEvent> MouseScrollEvent for T {
#[inline(always)]
fn from_xy(x: f64, y: f64) -> Option<T> {
let id = TypeId::of::<Box<MouseScrollEvent>>();
Ptr::with_ref::<(f64, f64), Option<T>>(&(x, y), |ptr| {
GenericEvent::from_event(id, ptr)
})
}
#[inline(always)]
fn mouse_scroll<U>(&self, f: |f64, f64| -> U) -> Option<U> {
let id = TypeId::of::<Box<MouseScrollEvent>>();
self.with_event(id, |ptr| {
let &(x, y) = ptr.expect::<(f64, f64)>();
f(x, y)
})
}
}