From c1a42765331c8c6161e12805f19877e53003cb07 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 15 Sep 2021 19:15:08 +0800 Subject: [PATCH] KeyboardButton/JoystickButton use enum class instead of enum --- inc/hgl/platform/InputDevice.h | 303 +++++++++++++++++---------------- inc/hgl/platform/Window.h | 2 +- src/Win/WinMessage.cpp | 212 +++++++++++------------ src/Window.cpp | 6 +- 4 files changed, 265 insertions(+), 258 deletions(-) diff --git a/inc/hgl/platform/InputDevice.h b/inc/hgl/platform/InputDevice.h index 382d256..ce05b66 100644 --- a/inc/hgl/platform/InputDevice.h +++ b/inc/hgl/platform/InputDevice.h @@ -1,6 +1,7 @@ #ifndef HGL_INPUT_DEVICE_INCLUDE #define HGL_INPUT_DEVICE_INCLUDE +#include namespace hgl { /** @@ -24,184 +25,190 @@ namespace hgl /** * 按键枚举定义 */ - enum KeyboardButton + enum class KeyboardButton { - kbBeginRange=0, + NONE=0, + //主键盘区 + Esc, ///=256)return(kbBeginRange); - if(KeyConvert[key]==0)return(kbBeginRange); + if(key>=256)return(KeyboardButton::NONE); + if(KeyConvert[key]==KeyboardButton::NONE)return(KeyboardButton::NONE); if(key==VK_SHIFT) { if((GetAsyncKeyState(VK_LSHIFT)>>15)&1) - return kbLeftShift; + return KeyboardButton::LeftShift; else - return kbRightShift; + return KeyboardButton::RightShift; } else if(key==VK_CONTROL) { if((GetAsyncKeyState(VK_LCONTROL)>>15)&1) - return kbLeftCtrl; + return KeyboardButton::LeftCtrl; else - return kbRightCtrl; + return KeyboardButton::RightCtrl; } if(key==VK_MENU) { if((GetAsyncKeyState(VK_LMENU)>>15)&1) - return kbLeftAlt; + return KeyboardButton::LeftAlt; else - return kbRightAlt; + return KeyboardButton::RightAlt; } #ifdef _DEBUG - if(KeyConvert[key]==0) + if(KeyConvert[key]==KeyboardButton::NONE) { wchar_t name[64]; @@ -226,16 +226,16 @@ namespace hgl #define WMEF2(name) void name(WinWindow *win,uint32 wParam,uint32 lParam) WMEF2(WMProcMouseWheel) { - int zDelta=GET_WHEEL_DELTA_WPARAM(wParam); - uint key=ConvertOSKey(GET_KEYSTATE_WPARAM(wParam)); + const int zDelta=GET_WHEEL_DELTA_WPARAM(wParam); + const uint key=(uint)ConvertOSKey(GET_KEYSTATE_WPARAM(wParam)); win->ProcMouseWheel(zDelta,0,key); } WMEF2(WMProcMouseHWheel) { - int zDelta=GET_WHEEL_DELTA_WPARAM(wParam); - uint key=ConvertOSKey(GET_KEYSTATE_WPARAM(wParam)); + const int zDelta=GET_WHEEL_DELTA_WPARAM(wParam); + const uint key=(uint)ConvertOSKey(GET_KEYSTATE_WPARAM(wParam)); win->ProcMouseWheel(0,zDelta,key); } diff --git a/src/Window.cpp b/src/Window.cpp index fe17ff6..7a746f0 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -4,17 +4,17 @@ namespace hgl { void Window::ProcKeyPressed(KeyboardButton kb) { - if(key_push[kb]) + if(key_push[size_t(kb)]) ProcKeyRepeat(kb); else - key_push[kb]=true; + key_push[size_t(kb)]=true; SafeCallEvent(OnKeyPressed,(kb)); } void Window::ProcKeyReleased(KeyboardButton kb) { - key_push[kb]=false; + key_push[size_t(kb)]=false; SafeCallEvent(OnKeyReleased,(kb)); }