diff options
| author | HampusM <hampus@hampusmat.com> | 2026-07-13 16:20:03 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-07-13 16:20:03 +0200 |
| commit | 7cccebbe314170696c0af9f0f81be013cc0e5fac (patch) | |
| tree | ea0488a0ce86f49370f6420d34c63293651be42d /engine/src | |
| parent | d683ad12636f4069cc73c4d69cdbdf85cc9b4099 (diff) | |
fix(engine): make mouse scroll not inverted
Apparently, mouse scroll deltas from DeviceEvent::MouseWheel are
inverted so this commit replaces it's usage with WindowEvent::MouseWheel
Diffstat (limited to 'engine/src')
| -rw-r--r-- | engine/src/windowing.rs | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/engine/src/windowing.rs b/engine/src/windowing.rs index 36941cf..adc5132 100644 --- a/engine/src/windowing.rs +++ b/engine/src/windowing.rs @@ -957,6 +957,36 @@ impl ApplicationHandler for App ); }; } + WindowEvent::MouseWheel { device_id: _, delta, phase: _ } => { + let (hor_lines, vert_lines) = match delta { + winit::event::MouseScrollDelta::LineDelta(hor_lines, vert_lines) => { + (hor_lines, vert_lines) + } + winit::event::MouseScrollDelta::PixelDelta(pos_delta) => { + let hor_lines = match pos_delta.x.partial_cmp(&0.0) { + Some(std::cmp::Ordering::Greater) => 1.0, + Some(std::cmp::Ordering::Less) => -1.0, + _ => 0.0, + }; + + let vert_lines = match pos_delta.y.partial_cmp(&0.0) { + Some(std::cmp::Ordering::Greater) => 1.0, + Some(std::cmp::Ordering::Less) => -1.0, + _ => 0.0, + }; + + (hor_lines, vert_lines) + } + }; + + let Some(mut input) = self.lock_input() else { + tracing::error!("Locking input mutex timed out after 100ms"); + return; + }; + + input.mouse_scroll_delta.hor_lines += hor_lines; + input.mouse_scroll_delta.vert_lines += vert_lines; + } WindowEvent::MouseInput { device_id: _, state, button } => { self.send_message(MessageFromApp::MouseButtonStateChanged( button.into(), @@ -990,36 +1020,6 @@ impl ApplicationHandler for App input.relative_mouse_pos_delta += Vec2::from(delta); } - DeviceEvent::MouseWheel { delta } => { - let (hor_lines, vert_lines) = match delta { - winit::event::MouseScrollDelta::LineDelta(hor_lines, vert_lines) => { - (hor_lines, vert_lines) - } - winit::event::MouseScrollDelta::PixelDelta(pos_delta) => { - let hor_lines = match pos_delta.x.partial_cmp(&0.0) { - Some(std::cmp::Ordering::Greater) => 1.0, - Some(std::cmp::Ordering::Less) => -1.0, - _ => 0.0, - }; - - let vert_lines = match pos_delta.y.partial_cmp(&0.0) { - Some(std::cmp::Ordering::Greater) => 1.0, - Some(std::cmp::Ordering::Less) => -1.0, - _ => 0.0, - }; - - (hor_lines, vert_lines) - } - }; - - let Some(mut input) = self.lock_input() else { - tracing::error!("Locking input mutex timed out after 100ms"); - return; - }; - - input.mouse_scroll_delta.hor_lines += hor_lines; - input.mouse_scroll_delta.vert_lines += vert_lines; - } _ => {} } } |
