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 {