mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Merge pull request #483 from robertknight/rob-precise_scroll_deltas
Specify scroll deltas as either line or pixel-based
This commit is contained in:
commit
5e8271dad0
|
@ -17,7 +17,7 @@ fn main() { println!("This example requires glutin to be compiled with the `wind
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let mut window = glutin::Window::new().unwrap();
|
let window = glutin::Window::new().unwrap();
|
||||||
window.set_title("A fantastic window!");
|
window.set_title("A fantastic window!");
|
||||||
unsafe { window.make_current() };
|
unsafe { window.make_current() };
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,15 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
self.window.delegate.state.pending_events.lock().unwrap().extend(events.into_iter());
|
self.window.delegate.state.pending_events.lock().unwrap().extend(events.into_iter());
|
||||||
event
|
event
|
||||||
},
|
},
|
||||||
NSScrollWheel => { Some(MouseWheel(event.scrollingDeltaX() as f64, event.scrollingDeltaY() as f64)) },
|
NSScrollWheel => {
|
||||||
|
use events::MouseScrollDelta::{LineDelta, PixelDelta};
|
||||||
|
let delta = if event.hasPreciseScrollingDeltas() == YES {
|
||||||
|
PixelDelta(event.scrollingDeltaX() as f32, event.scrollingDeltaY() as f32)
|
||||||
|
} else {
|
||||||
|
LineDelta(event.scrollingDeltaX() as f32, event.scrollingDeltaY() as f32)
|
||||||
|
};
|
||||||
|
Some(MouseWheel(delta))
|
||||||
|
},
|
||||||
_ => { None },
|
_ => { None },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -112,12 +112,13 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
|
|
||||||
winapi::WM_MOUSEWHEEL => {
|
winapi::WM_MOUSEWHEEL => {
|
||||||
use events::Event::MouseWheel;
|
use events::Event::MouseWheel;
|
||||||
|
use events::MouseScrollDelta::LineDelta;
|
||||||
|
|
||||||
let value = (wparam >> 16) as i16;
|
let value = (wparam >> 16) as i16;
|
||||||
let value = value as i32;
|
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
|
0
|
||||||
},
|
},
|
||||||
|
|
|
@ -219,6 +219,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
use events::Event::{MouseInput, MouseWheel};
|
use events::Event::{MouseInput, MouseWheel};
|
||||||
use events::ElementState::{Pressed, Released};
|
use events::ElementState::{Pressed, Released};
|
||||||
use events::MouseButton::{Left, Right, Middle};
|
use events::MouseButton::{Left, Right, Middle};
|
||||||
|
use events::MouseScrollDelta::{LineDelta};
|
||||||
|
|
||||||
let event: &ffi::XButtonEvent = unsafe { mem::transmute(&xev) };
|
let event: &ffi::XButtonEvent = unsafe { mem::transmute(&xev) };
|
||||||
|
|
||||||
|
@ -229,11 +230,13 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
ffi::Button2 => Some(Middle),
|
ffi::Button2 => Some(Middle),
|
||||||
ffi::Button3 => Some(Right),
|
ffi::Button3 => Some(Right),
|
||||||
ffi::Button4 => {
|
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
|
None
|
||||||
}
|
}
|
||||||
ffi::Button5 => {
|
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
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
|
|
|
@ -25,11 +25,8 @@ pub enum Event {
|
||||||
/// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window.
|
/// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window.
|
||||||
MouseMoved((i32, i32)),
|
MouseMoved((i32, i32)),
|
||||||
|
|
||||||
/// Returns the horizontal and vertical mouse scrolling.
|
/// A mouse wheel movement or touchpad scroll occurred.
|
||||||
///
|
MouseWheel(MouseScrollDelta),
|
||||||
/// 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(f64, f64),
|
|
||||||
|
|
||||||
/// An event from the mouse has been received.
|
/// An event from the mouse has been received.
|
||||||
MouseInput(ElementState, MouseButton),
|
MouseInput(ElementState, MouseButton),
|
||||||
|
@ -57,6 +54,23 @@ pub enum MouseButton {
|
||||||
Other(u8),
|
Other(u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum MouseScrollDelta {
|
||||||
|
/// Amount in lines or rows to scroll in the horizontal
|
||||||
|
/// and vertical directions.
|
||||||
|
///
|
||||||
|
/// Positive values indicate movement forward
|
||||||
|
/// (away from the user) or rightwards.
|
||||||
|
LineDelta(f32, f32),
|
||||||
|
/// Amount in pixels to scroll in the horizontal and
|
||||||
|
/// vertical direction.
|
||||||
|
///
|
||||||
|
/// Scroll events are expressed as a PixelDelta if
|
||||||
|
/// supported by the device (eg. a touchpad) and
|
||||||
|
/// platform.
|
||||||
|
PixelDelta(f32, f32)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum VirtualKeyCode {
|
pub enum VirtualKeyCode {
|
||||||
/// The '1' key over the letters.
|
/// The '1' key over the letters.
|
||||||
|
|
Loading…
Reference in a new issue