diff options
| -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; - } _ => {} } } |
