Skip to content

Instantly share code, notes, and snippets.

@Skrylar
Created January 2, 2014 11:21
Show Gist options
  • Save Skrylar/8217841 to your computer and use it in GitHub Desktop.
Save Skrylar/8217841 to your computer and use it in GitHub Desktop.
Finally getting a zero-copy event dispatch working with SDL.
extern mod sdl;
use std::rc::Rc;
struct Foof;
impl sdl::MouseDelegate for Foof {
fn mouse_did_move(_info: &sdl::MouseMotionEventInfo) {
println!("Mouse position: {}x{}", _info.x(), _info.y())
}
fn mouse_did_click(_info: &sdl::MouseButtonEventInfo) {
}
fn mouse_did_scroll(_info: &sdl::MouseWheelEventInfo) {
}
}
fn main() {
do sdl::start(sdl::init::Video) {
let win = sdl::Window::create("Foof wob", 32, 32, 800, 600, 0).ok().unwrap();
let mut ep = sdl::EventPump::new();
let delegate = Rc::from_send(~Foof as ~sdl::MouseDelegate);
let mut x = win.borrow_mut();
x.get().set_mouse_delegate(&delegate);
'core : loop {
ep.do_all();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment