aboutsummaryrefslogtreecommitdiffstats
path: root/src/osx
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-01-02 09:22:27 +0100
committertomaka <pierre.krieger1708@gmail.com>2015-01-02 09:22:27 +0100
commitebe32bb2d803bc22c4b309acbbd48f3dc2a12127 (patch)
treeb2cc041b67dd54f64c6123981bffbd0201f9620a /src/osx
parentf68bf85a85ceb416f714bc36ff5aa5c6ae65c008 (diff)
parenta698146943bcd6df2a61bbfd56badf3018662709 (diff)
downloadglutin-ebe32bb2d803bc22c4b309acbbd48f3dc2a12127.tar.gz
glutin-ebe32bb2d803bc22c4b309acbbd48f3dc2a12127.zip
Merge pull request #180 from TyOverby/event-change
Change the way that event iterators are represented.
Diffstat (limited to 'src/osx')
-rw-r--r--src/osx/mod.rs33
-rw-r--r--src/osx/monitor.rs5
2 files changed, 20 insertions, 18 deletions
diff --git a/src/osx/mod.rs b/src/osx/mod.rs
index b65f67a..80e08da 100644
--- a/src/osx/mod.rs
+++ b/src/osx/mod.rs
@@ -21,6 +21,7 @@ use std::cell::Cell;
use std::c_str::CString;
use std::mem;
use std::ptr;
+use std::collections::RingBuf;
use events::Event::{MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel};
use events::ElementState::{Pressed, Released};
@@ -337,8 +338,8 @@ impl Window {
WindowProxy
}
- pub fn poll_events(&self) -> Vec<Event> {
- let mut events = Vec::new();
+ pub fn poll_events(&self) -> RingBuf<Event> {
+ let mut events = RingBuf::new();
loop {
unsafe {
@@ -370,53 +371,53 @@ impl Window {
}
match event.get_type() {
- NSLeftMouseDown => { events.push(MouseInput(Pressed, LeftMouseButton)); },
- NSLeftMouseUp => { events.push(MouseInput(Released, LeftMouseButton)); },
- NSRightMouseDown => { events.push(MouseInput(Pressed, RightMouseButton)); },
- NSRightMouseUp => { events.push(MouseInput(Released, RightMouseButton)); },
+ NSLeftMouseDown => { events.push_back(MouseInput(Pressed, LeftMouseButton)); },
+ NSLeftMouseUp => { events.push_back(MouseInput(Released, LeftMouseButton)); },
+ NSRightMouseDown => { events.push_back(MouseInput(Pressed, RightMouseButton)); },
+ NSRightMouseUp => { events.push_back(MouseInput(Released, RightMouseButton)); },
NSMouseMoved => {
let window_point = event.locationInWindow();
let view_point = self.view.convertPoint_fromView_(window_point, nil);
- events.push(MouseMoved((view_point.x as int, view_point.y as int)));
+ events.push_back(MouseMoved((view_point.x as int, view_point.y as int)));
},
NSKeyDown => {
let received_str = CString::new(event.characters().UTF8String(), false);
for received_char in received_str.as_str().unwrap().chars() {
if received_char.is_ascii() {
- events.push(ReceivedCharacter(received_char));
+ events.push_back(ReceivedCharacter(received_char));
}
}
let vkey = event::vkeycode_to_element(event.keycode());
- events.push(KeyboardInput(Pressed, event.keycode() as u8, vkey));
+ events.push_back(KeyboardInput(Pressed, event.keycode() as u8, vkey));
},
NSKeyUp => {
let vkey = event::vkeycode_to_element(event.keycode());
- events.push(KeyboardInput(Released, event.keycode() as u8, vkey));
+ events.push_back(KeyboardInput(Released, event.keycode() as u8, vkey));
},
NSFlagsChanged => {
let shift_modifier = Window::modifier_event(event, appkit::NSShiftKeyMask as u64, events::VirtualKeyCode::LShift, shift_pressed);
if shift_modifier.is_some() {
shift_pressed = !shift_pressed;
- events.push(shift_modifier.unwrap());
+ events.push_back(shift_modifier.unwrap());
}
let ctrl_modifier = Window::modifier_event(event, appkit::NSControlKeyMask as u64, events::VirtualKeyCode::LControl, ctrl_pressed);
if ctrl_modifier.is_some() {
ctrl_pressed = !ctrl_pressed;
- events.push(ctrl_modifier.unwrap());
+ events.push_back(ctrl_modifier.unwrap());
}
let win_modifier = Window::modifier_event(event, appkit::NSCommandKeyMask as u64, events::VirtualKeyCode::LWin, win_pressed);
if win_modifier.is_some() {
win_pressed = !win_pressed;
- events.push(win_modifier.unwrap());
+ events.push_back(win_modifier.unwrap());
}
let alt_modifier = Window::modifier_event(event, appkit::NSAlternateKeyMask as u64, events::VirtualKeyCode::LAlt, alt_pressed);
if alt_modifier.is_some() {
alt_pressed = !alt_pressed;
- events.push(alt_modifier.unwrap());
+ events.push_back(alt_modifier.unwrap());
}
},
- NSScrollWheel => { events.push(MouseWheel(-event.scrollingDeltaY() as i32)); },
+ NSScrollWheel => { events.push_back(MouseWheel(-event.scrollingDeltaY() as i32)); },
NSOtherMouseDown => { },
NSOtherMouseUp => { },
NSOtherMouseDragged => { },
@@ -442,7 +443,7 @@ impl Window {
event.modifierFlags() & modifier != 0
}
- pub fn wait_events(&self) -> Vec<Event> {
+ pub fn wait_events(&self) -> RingBuf<Event> {
unsafe {
let event = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_(
NSAnyEventMask as u64,
diff --git a/src/osx/monitor.rs b/src/osx/monitor.rs
index 383fd32..3fb1d74 100644
--- a/src/osx/monitor.rs
+++ b/src/osx/monitor.rs
@@ -1,9 +1,10 @@
use core_graphics::display;
+use std::collections::RingBuf;
pub struct MonitorID(u32);
pub fn get_available_monitors() -> Vec<MonitorID> {
- let mut monitors = Vec::new();
+ let mut monitors = RingBuf::new();
unsafe {
let max_displays = 10u32;
let mut active_displays = [0u32, ..10];
@@ -12,7 +13,7 @@ pub fn get_available_monitors() -> Vec<MonitorID> {
&mut active_displays[0],
&mut display_count);
for i in range(0u, display_count as uint) {
- monitors.push(MonitorID(active_displays[i]));
+ monitors.push_back(MonitorID(active_displays[i]));
}
}
monitors