From fe9d155779ed411a6b33c07ae68bc88f9dc56a17 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Mon, 7 May 2018 17:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Window::setCursor=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BF=AE=E6=94=B9=E9=BC=A0=E6=A0=87=E6=8C=87=E9=92=88?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=EF=BC=9B=E9=BC=A0=E6=A0=87=E7=A7=BB=E5=85=A5?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=97=B6=E8=87=AA=E5=8A=A8=E5=8F=98=E6=8D=A2?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Base/Window.cpp | 39 ++++++++++++++++++++++++++++++++++++--- core/Node/Button.cpp | 7 +++++++ core/e2dbase.h | 5 +++++ core/e2dcommon.h | 11 +++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp index 813d1d40..9d3abc98 100644 --- a/core/Base/Window.cpp +++ b/core/Base/Window.cpp @@ -12,6 +12,8 @@ bool e2d::Window::__init() // 注册窗口类 WNDCLASSEX wcex = { 0 }; wcex.cbSize = sizeof(WNDCLASSEX); + wcex.lpszClassName = L"Easy2DApp"; + wcex.hIcon = NULL; wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = Window::WndProc; wcex.cbClsExtra = 0; @@ -19,9 +21,7 @@ bool e2d::Window::__init() wcex.hInstance = HINST_THISCOMPONENT; wcex.hbrBackground = NULL; wcex.lpszMenuName = NULL; - wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); - wcex.lpszClassName = L"Easy2DApp"; - wcex.hIcon = NULL; + wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW); RegisterClassEx(&wcex); @@ -189,6 +189,39 @@ void e2d::Window::setIcon(int iconID) ::SendMessage(s_HWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } +void e2d::Window::setCursor(Cursor cursor) +{ + LPCWSTR pCursorName = NULL; + switch (cursor) + { + case Cursor::NORMAL: + pCursorName = IDC_ARROW; + break; + + case Cursor::HAND: + pCursorName = IDC_HAND; + break; + + case Cursor::NO: + pCursorName = IDC_NO; + break; + + case Cursor::WAIT: + pCursorName = IDC_WAIT; + break; + + case Cursor::ARROW_WAIT: + pCursorName = IDC_APPSTARTING; + break; + + default: + break; + } + + HCURSOR hCursor = ::LoadCursor(NULL, pCursorName); + ::SetCursor(hCursor); +} + e2d::String e2d::Window::getTitle() { wchar_t wszTitle[MAX_PATH] = { 0 }; diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index abc2afb4..36738bfa 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -211,17 +211,24 @@ void e2d::Button::onFixedUpdate() if (m_pNormal->isPointIn(Input::getMousePos())) { _setState(ButtonState::SELECTED); + Window::setCursor(Cursor::HAND); return; } } else if (m_pNormal->isPointIn(Input::getMousePos())) { _setState(ButtonState::MOUSEOVER); + Window::setCursor(Cursor::HAND); return; } _setState(ButtonState::NORMAL); } + + if (m_bVisiable && !m_bEnable && m_pNormal && m_pNormal->isPointIn(Input::getMousePos())) + { + Window::setCursor(Cursor::NO); + } } void e2d::Button::_setState(ButtonState state) diff --git a/core/e2dbase.h b/core/e2dbase.h index 465144f4..864af551 100644 --- a/core/e2dbase.h +++ b/core/e2dbase.h @@ -70,6 +70,11 @@ public: int iconID ); + // 设置鼠标指针样式 + static void setCursor( + Cursor cursor + ); + // 获取窗口标题 static String getTitle(); diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 8940e0c9..6cf0c909 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -426,6 +426,17 @@ enum class KeyCode : int }; +// 鼠标指针样式 +enum class Cursor : int +{ + NORMAL, /* 默认指针样式 */ + HAND, /* 手状指针 */ + NO, /* 禁止指针 */ + WAIT, /* 沙漏指针 */ + ARROW_WAIT /* 默认指针和小沙漏 */ +}; + + // 方向 enum class Direct : int {