From aa053ad269ec7741b1f121e21cc62d19d52ff104 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Fri, 18 May 2018 23:56:36 +0800 Subject: [PATCH] =?UTF-8?q?Input=E5=87=BD=E6=95=B0=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Base/Input.cpp | 12 ++++++------ core/Node/Button.cpp | 6 +++--- core/e2dbase.h | 29 +++++++++++++++-------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp index a3d25bb6..99bb875c 100644 --- a/core/Base/Input.cpp +++ b/core/Base/Input.cpp @@ -142,14 +142,14 @@ void Input::__updateDeviceState() ScreenToClient(Window::getHWnd(), &s_MousePosition); } -bool Input::isKeyDown(KeyCode key) +bool Input::isDown(Key key) { if (s_KeyBuffer[static_cast(key)] & 0x80) return true; return false; } -bool Input::isKeyPress(KeyCode key) +bool Input::isPress(Key key) { if ((s_KeyBuffer[static_cast(key)] & 0x80) && !(s_KeyRecordBuffer[static_cast(key)] & 0x80)) @@ -157,7 +157,7 @@ bool Input::isKeyPress(KeyCode key) return false; } -bool Input::isKeyRelease(KeyCode key) +bool Input::isRelease(Key key) { if (!(s_KeyBuffer[static_cast(key)] & 0x80) && (s_KeyRecordBuffer[static_cast(key)] & 0x80)) @@ -165,14 +165,14 @@ bool Input::isKeyRelease(KeyCode key) return false; } -bool e2d::Input::isMouseDown(MouseCode code) +bool e2d::Input::isDown(Mouse code) { if (s_MouseState.rgbButtons[static_cast(code)] & 0x80) return true; return false; } -bool e2d::Input::isMousePress(MouseCode code) +bool e2d::Input::isPress(Mouse code) { if ((s_MouseState.rgbButtons[static_cast(code)] & 0x80) && !(s_MouseRecordState.rgbButtons[static_cast(code)] & 0x80)) @@ -180,7 +180,7 @@ bool e2d::Input::isMousePress(MouseCode code) return false; } -bool e2d::Input::isMouseRelease(MouseCode code) +bool e2d::Input::isRelease(Mouse code) { if (!(s_MouseState.rgbButtons[static_cast(code)] & 0x80) && (s_MouseRecordState.rgbButtons[static_cast(code)] & 0x80)) diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index e4083ed6..0b0631a2 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -209,7 +209,7 @@ void e2d::Button::onFixedUpdate() if (_enable && _visiable && _normal) { - if (Input::isMouseRelease(Input::MouseCode::LEFT)) + if (Input::isRelease(Input::Mouse::LEFT)) { // 鼠标左键抬起时,判断鼠标坐标是否在按钮内部 if (_isSelected && @@ -221,7 +221,7 @@ void e2d::Button::onFixedUpdate() _isSelected = false; } - if (Input::isMousePress(Input::MouseCode::LEFT)) + if (Input::isPress(Input::Mouse::LEFT)) { if (_normal->isPointIn(Input::getMousePos())) { @@ -231,7 +231,7 @@ void e2d::Button::onFixedUpdate() } } - if (_isSelected && Input::isMouseDown(Input::MouseCode::LEFT)) + if (_isSelected && Input::isDown(Input::Mouse::LEFT)) { if (_normal->isPointIn(Input::getMousePos())) { diff --git a/core/e2dbase.h b/core/e2dbase.h index b7e6263e..3a2d40f7 100644 --- a/core/e2dbase.h +++ b/core/e2dbase.h @@ -188,15 +188,16 @@ class Input public: // 鼠标键值 - enum class MouseCode : int + enum class Mouse : int { LEFT, /* 鼠标左键 */ RIGHT, /* 鼠标右键 */ MIDDLE /* 鼠标中键 */ }; + // 键盘键值 - enum class KeyCode : int + enum class Key : int { UP = 0xC8, LEFT = 0xCB, @@ -258,33 +259,33 @@ public: public: // 检测键盘某按键是否正被按下 - static bool isKeyDown( - KeyCode key + static bool isDown( + Key key ); // 检测键盘某按键是否被点击 - static bool isKeyPress( - KeyCode key + static bool isPress( + Key key ); // 检测键盘某按键是否正在松开 - static bool isKeyRelease( - KeyCode key + static bool isRelease( + Key key ); // 检测鼠标按键是否正被按下 - static bool isMouseDown( - MouseCode code + static bool isDown( + Mouse code ); // 检测鼠标按键是否被点击 - static bool isMousePress( - MouseCode code + static bool isPress( + Mouse code ); // 检测鼠标按键是否正在松开 - static bool isMouseRelease( - MouseCode code + static bool isRelease( + Mouse code ); // 获得鼠标X轴坐标值