aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorRobert Knight <robert.knight@mendeley.com>2015-06-12 15:32:11 +0100
committerRobert Knight <robert.knight@mendeley.com>2015-06-13 23:19:31 +0100
commitf0bab95c4dc13c1989979c611a4663eb5d590a0d (patch)
tree62fc80f471dae8fbb99f8f791c8d08fb91d7b4d8 /src/api
parenta0e29d9410181368eee1e0b6db1bbbf11abf45f8 (diff)
downloadglutin-f0bab95c4dc13c1989979c611a4663eb5d590a0d.tar.gz
glutin-f0bab95c4dc13c1989979c611a4663eb5d590a0d.zip
Express scroll deltas as either line or pixel deltas
Depending on the platform and device, scroll deltas may either be represented as pixel deltas specifying the amount in pixels to scroll or they may be expressed in 'lines' or 'chunks' for low resolution devices (eg. a traditional mouse wheel). Pixel deltas are currently available on OS X. X11 currently supports only integer line deltas, though pixel deltas are available via XInput2. Windows supports fractional line deltas.
Diffstat (limited to 'src/api')
-rw-r--r--src/api/cocoa/mod.rs6
-rw-r--r--src/api/win32/callback.rs5
-rw-r--r--src/api/x11/window.rs7
3 files changed, 13 insertions, 5 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 511148b..43628ea 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -275,7 +275,11 @@ impl<'a> Iterator for PollEventsIterator<'a> {
self.window.delegate.state.pending_events.lock().unwrap().extend(events.into_iter());
event
},
- NSScrollWheel => { Some(MouseWheel(event.scrollingDeltaX() as f64, event.scrollingDeltaY() as f64)) },
+ NSScrollWheel => {
+ use events::MouseScrollDelta::PixelDelta;
+ let delta = PixelDelta(event.scrollingDeltaX() as f32, event.scrollingDeltaY() as f32);
+ Some(MouseWheel(delta))
+ },
_ => { None },
};
diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs
index 86d5f1c..6ac56f3 100644
--- a/src/api/win32/callback.rs
+++ b/src/api/win32/callback.rs
@@ -112,12 +112,13 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
winapi::WM_MOUSEWHEEL => {
use events::Event::MouseWheel;
+ use events::MouseScrollDelta::LineDelta;
let value = (wparam >> 16) as i16;
let value = value as i32;
- let value = value as f64 / winapi::WHEEL_DELTA as f64;
+ let value = value as f32 / winapi::WHEEL_DELTA as f32;
- send_event(window, MouseWheel(0.0, value));
+ send_event(window, MouseWheel(LineDelta(0.0, value)));
0
},
diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs
index 8b74e77..55ee007 100644
--- a/src/api/x11/window.rs
+++ b/src/api/x11/window.rs
@@ -219,6 +219,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {
use events::Event::{MouseInput, MouseWheel};
use events::ElementState::{Pressed, Released};
use events::MouseButton::{Left, Right, Middle};
+ use events::MouseScrollDelta::{LineDelta};
let event: &ffi::XButtonEvent = unsafe { mem::transmute(&xev) };
@@ -229,11 +230,13 @@ 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(0.0, 1.0));
+ let delta = LineDelta(0.0, 1.0);
+ self.window.pending_events.lock().unwrap().push_back(MouseWheel(delta));
None
}
ffi::Button5 => {
- self.window.pending_events.lock().unwrap().push_back(MouseWheel(0.0, -1.0));
+ let delta = LineDelta(0.0, -1.0);
+ self.window.pending_events.lock().unwrap().push_back(MouseWheel(delta));
None
}
_ => None