From ae65b423ddf2be0bb7981eba81366a93c686724f Mon Sep 17 00:00:00 2001 From: Tomaka17 Date: Wed, 13 Aug 2014 17:04:57 +0200 Subject: Implement new events system --- src/win32/event.rs | 6 +++--- src/win32/ffi.rs | 1 + src/win32/init.rs | 61 +++++++++++++++++++++++++++++++----------------------- 3 files changed, 39 insertions(+), 29 deletions(-) (limited to 'src/win32') diff --git a/src/win32/event.rs b/src/win32/event.rs index 83d775d..03eebfc 100644 --- a/src/win32/event.rs +++ b/src/win32/event.rs @@ -1,7 +1,7 @@ use events; use super::ffi; -pub fn vkeycode_to_element(code: ffi::WPARAM) -> Option { +pub fn vkeycode_to_element(code: ffi::WPARAM) -> Option { Some(match code { //ffi::VK_LBUTTON => events::Lbutton, //ffi::VK_RBUTTON => events::Rbutton, @@ -31,8 +31,8 @@ pub fn vkeycode_to_element(code: ffi::WPARAM) -> Option { //ffi::VK_ACCEPT => events::Accept, //ffi::VK_MODECHANGE => events::Modechange, ffi::VK_SPACE => events::Space, - ffi::VK_PRIOR => events::Prior, - ffi::VK_NEXT => events::Next, + ffi::VK_PRIOR => events::PageUp, + ffi::VK_NEXT => events::PageDown, ffi::VK_END => events::End, ffi::VK_HOME => events::Home, ffi::VK_LEFT => events::Left, diff --git a/src/win32/ffi.rs b/src/win32/ffi.rs index 4480155..7f06064 100644 --- a/src/win32/ffi.rs +++ b/src/win32/ffi.rs @@ -409,6 +409,7 @@ pub static WM_KILLFOCUS: UINT = 0x0008; pub static WM_MBUTTONDOWN: UINT = 0x0207; pub static WM_MBUTTONUP: UINT = 0x0208; pub static WM_MOUSEMOVE: UINT = 0x0200; +pub static WM_MOUSEWHEEL: UINT = 0x020A; pub static WM_MOVE: UINT = 0x0003; pub static WM_PAINT: UINT = 0x000F; pub static WM_RBUTTONDOWN: UINT = 0x0204; diff --git a/src/win32/init.rs b/src/win32/init.rs index 77a864e..14c61a4 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -431,67 +431,76 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, }, ffi::WM_MOUSEMOVE => { - use CursorPositionChanged; + use MouseMoved; - let x = ffi::GET_X_LPARAM(lparam) as uint; - let y = ffi::GET_Y_LPARAM(lparam) as uint; + let x = ffi::GET_X_LPARAM(lparam) as int; + let y = ffi::GET_Y_LPARAM(lparam) as int; - send_event(window, CursorPositionChanged(x, y)); + send_event(window, MouseMoved((x, y))); + + 0 + }, + + ffi::WM_MOUSEWHEEL => { + use events::MouseWheel; + + let value = (wparam >> 16) as i16; + let value = value as i32; + + send_event(window, MouseWheel(value)); 0 }, ffi::WM_KEYDOWN => { - use events::Pressed; - let element = event::vkeycode_to_element(wparam); - if element.is_some() { - send_event(window, Pressed(element.unwrap())); - } + use events::{KeyboardInput, KeyModifiers, Pressed}; + let scancode = ((lparam >> 16) & 0xff) as u8; + let vkey = event::vkeycode_to_element(wparam); + send_event(window, KeyboardInput(Pressed, scancode, vkey, KeyModifiers::empty())); 0 }, ffi::WM_KEYUP => { - use events::Released; - let element = event::vkeycode_to_element(wparam); - if element.is_some() { - send_event(window, Released(element.unwrap())); - } + use events::{KeyboardInput, KeyModifiers, Released}; + let scancode = ((lparam >> 16) & 0xff) as u8; + let vkey = event::vkeycode_to_element(wparam); + send_event(window, KeyboardInput(Released, scancode, vkey, KeyModifiers::empty())); 0 }, ffi::WM_LBUTTONDOWN => { - use events::{Pressed, Button0}; - send_event(window, Pressed(Button0)); + use events::{Pressed, MouseInput, LeftMouseButton}; + send_event(window, MouseInput(Pressed, LeftMouseButton)); 0 }, ffi::WM_LBUTTONUP => { - use events::{Released, Button0}; - send_event(window, Released(Button0)); + use events::{Released, MouseInput, LeftMouseButton}; + send_event(window, MouseInput(Released, LeftMouseButton)); 0 }, ffi::WM_RBUTTONDOWN => { - use events::{Pressed, Button1}; - send_event(window, Pressed(Button1)); + use events::{Pressed, MouseInput, RightMouseButton}; + send_event(window, MouseInput(Pressed, RightMouseButton)); 0 }, ffi::WM_RBUTTONUP => { - use events::{Released, Button1}; - send_event(window, Released(Button1)); + use events::{Released, MouseInput, RightMouseButton}; + send_event(window, MouseInput(Released, RightMouseButton)); 0 }, ffi::WM_MBUTTONDOWN => { - use events::{Pressed, Button2}; - send_event(window, Pressed(Button2)); + use events::{Pressed, MouseInput, MiddleMouseButton}; + send_event(window, MouseInput(Pressed, MiddleMouseButton)); 0 }, ffi::WM_MBUTTONUP => { - use events::{Released, Button2}; - send_event(window, Released(Button2)); + use events::{Released, MouseInput, MiddleMouseButton}; + send_event(window, MouseInput(Released, MiddleMouseButton)); 0 }, -- cgit v1.2.3