diff options
author | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-04-29 14:06:11 +0200 |
---|---|---|
committer | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-04-29 14:35:09 +0200 |
commit | d9f0d92584af1d76779cb8cb4a70762c889970f5 (patch) | |
tree | 68ed4378c8aa816b5f7c7593a0bee91a5522f992 | |
parent | c752142e045156c6869a43183032030dd1d0439d (diff) | |
download | glutin-d9f0d92584af1d76779cb8cb4a70762c889970f5.tar.gz glutin-d9f0d92584af1d76779cb8cb4a70762c889970f5.zip |
Rework MouseWheel event and fix the values on win32
-rw-r--r-- | src/api/cocoa/mod.rs | 2 | ||||
-rw-r--r-- | src/api/win32/callback.rs | 3 | ||||
-rw-r--r-- | src/api/x11/mod.rs | 4 | ||||
-rw-r--r-- | src/events.rs | 6 |
4 files changed, 9 insertions, 6 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index a6bdfa3..3254ee6 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -275,7 +275,7 @@ impl<'a> Iterator for PollEventsIterator<'a> { self.window.delegate.state.pending_events.lock().unwrap().extend(events.into_iter()); event }, - NSScrollWheel => { Some(MouseWheel(event.scrollingDeltaY() as i32)) }, + NSScrollWheel => { Some(MouseWheel(event.scrollingDeltaX() as f64, event.scrollingDeltaY() as f64)) }, _ => { None }, }; diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index e852eeb..1ea95a5 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -114,8 +114,9 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, let value = (wparam >> 16) as i16; let value = value as i32; + let value = value as f64 / winapi::WHEEL_DELTA as f64; - send_event(window, MouseWheel(value)); + send_event(window, MouseWheel(0.0, value)); 0 }, diff --git a/src/api/x11/mod.rs b/src/api/x11/mod.rs index 3dd90d3..252b22e 100644 --- a/src/api/x11/mod.rs +++ b/src/api/x11/mod.rs @@ -240,11 +240,11 @@ impl<'a> Iterator for PollEventsIterator<'a> { ffi::Button2 => Some(Middle), ffi::Button3 => Some(Right), ffi::Button4 => { - self.window.pending_events.lock().unwrap().push_back(MouseWheel(1)); + self.window.pending_events.lock().unwrap().push_back(MouseWheel(0.0, 1.0)); None } ffi::Button5 => { - self.window.pending_events.lock().unwrap().push_back(MouseWheel(-1)); + self.window.pending_events.lock().unwrap().push_back(MouseWheel(0.0, -1.0)); None } _ => None diff --git a/src/events.rs b/src/events.rs index 957e0c3..7962706 100644 --- a/src/events.rs +++ b/src/events.rs @@ -25,9 +25,11 @@ pub enum Event { /// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window. MouseMoved((i32, i32)), + /// Returns the horizontal and vertical mouse scrolling. + /// /// A positive value indicates that the wheel was rotated forward, away from the user; - /// a negative value indicates that the wheel was rotated backward, toward the user. - MouseWheel(i32), + /// a negative value indicates that the wheel was rotated backward, toward the user. + MouseWheel(f64, f64), /// An event from the mouse has been received. MouseInput(ElementState, MouseButton), |