Created
January 2, 2014 12:07
-
-
Save Skrylar/8218341 to your computer and use it in GitHub Desktop.
Heinous hackery to transmit zero-copy events in Rust.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[inline] | |
unsafe fn with_window_event_db(_in: &CommonEventInfo, block: |&mut DelegateBoard|) { | |
let event : &MouseMotionEventInfo = cast::transmute(_in); | |
EventPump::with_window_db(event.window_id(), block) | |
} | |
unsafe fn with_window_db(id: u32, block: |&mut DelegateBoard|) { | |
let win = ffi::SDL_GetWindowFromID(id); | |
if win.is_not_null() { | |
let dbp = ffi::SDL_GetWindowData(win, bytes!("rust_cb", 0).as_ptr() as *i8); | |
if dbp.is_not_null() { | |
let db : &mut DelegateBoard = cast::transmute(dbp); | |
block(db) | |
} | |
} | |
} | |
pub fn do_all(&mut self) { | |
unsafe { | |
while (ffi::SDL_PollEvent(&mut self.data as *mut EventInfo) == 1) { | |
let event : &CommonEventInfo = cast::transmute(&self.data); | |
match event.etype { | |
event::MouseMotion => EventPump::with_window_event_db(event, |db| { | |
db.mouse.borrow().with_mut(|this| { | |
this.mouse_did_move(cast::transmute(event)) | |
}) | |
}), | |
event::MouseButtonDown => {}, | |
event::MouseButtonUp => {}, | |
event::MouseWheel => {}, | |
_ => {} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment