From 6bfcfbb74dfd8f4f528c3f0bb32bf41c260c3e32 Mon Sep 17 00:00:00 2001 From: DGriffin91 Date: Sat, 9 Oct 2021 16:52:56 -0700 Subject: [PATCH] add scrollwheel support for windows --- src/win/window.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/win/window.rs b/src/win/window.rs index f1fc687..82cd463 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -9,8 +9,8 @@ use winapi::um::winuser::{ DestroyWindow, SetProcessDpiAwarenessContext, SetWindowPos, GetDpiForWindow, CS_OWNDC, GWLP_USERDATA, IDC_ARROW, - MSG, WM_CLOSE, WM_CREATE, WM_MOUSEMOVE, WM_SHOWWINDOW, WM_TIMER, WM_NCDESTROY, - WNDCLASSW, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, + MSG, WM_CLOSE, WM_CREATE, WM_MOUSEMOVE, WM_MOUSEWHEEL, WHEEL_DELTA, WM_SHOWWINDOW, WM_TIMER, + WM_NCDESTROY, WNDCLASSW, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW, WS_SIZEBOX, WS_VISIBLE, WM_DPICHANGED, WM_CHAR, WM_SYSCHAR, WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP, WM_INPUTLANGCHANGE, WM_SIZE, GET_XBUTTON_WPARAM, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, @@ -30,7 +30,7 @@ use raw_window_handle::{ }; use crate::{ - Event, MouseButton, MouseEvent, WindowEvent, + Event, MouseButton, MouseEvent, ScrollDelta, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, PhyPoint, PhySize }; @@ -89,6 +89,22 @@ unsafe extern "system" fn wnd_proc( ); return 0; } + WM_MOUSEWHEEL => { + let value = (wparam >> 16) as i16; + let value = value as i32; + let value = value as f32 / WHEEL_DELTA as f32; + + let mut window_state = (&*window_state_ptr).borrow_mut(); + + window_state.handler.on_event( + &mut window, + Event::Mouse(MouseEvent::WheelScrolled(ScrollDelta::Lines { + x: 0.0, + y: value, + })), + ); + return 0; + } WM_LBUTTONDOWN | WM_LBUTTONUP | WM_MBUTTONDOWN | WM_MBUTTONUP | WM_RBUTTONDOWN | WM_RBUTTONUP | WM_XBUTTONDOWN | WM_XBUTTONUP => {