Commit 12c926ff authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Convert most things to using .events()

parent 58fee4b9
......@@ -193,7 +193,27 @@ impl Window {
/// Return a iterator over events
pub fn events(&mut self) -> EventIter {
EventIter::new(self)
let mut iter = EventIter {
events: [Event::new(); 128],
i: 0,
count: 0,
};
'blocking: loop {
//Should it be cleared? iter.events = [Event::new(); 128];
match self.file.read(unsafe {
slice::from_raw_parts_mut(iter.events.as_mut_ptr() as *mut u8, iter.events.len() * mem::size_of::<Event>())
}){
Ok(0) => thread::yield_now(),
Ok(count) => {
iter.count = count/mem::size_of::<Event>();
break 'blocking;
},
Err(_) => break 'blocking,
}
}
iter
}
/// Poll for an event
......@@ -225,32 +245,6 @@ pub struct EventIter {
count: usize,
}
impl EventIter {
pub fn new(window: &mut Window) -> EventIter {
let mut iter = EventIter {
events: [Event::new(); 128],
i: 0,
count: 0,
};
'blocking: loop {
//Should it be cleared? iter.events = [Event::new(); 128];
match window.file.read(unsafe {
slice::from_raw_parts_mut(iter.events.as_mut_ptr() as *mut u8, iter.events.len() * mem::size_of::<Event>())
}){
Ok(0) => thread::yield_now(),
Ok(count) => {
iter.count = count/mem::size_of::<Event>();
break 'blocking;
},
Err(_) => break 'blocking,
}
}
iter
}
}
impl Iterator for EventIter {
type Item = Event;
fn next(&mut self) -> Option<Event> {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment