增加Window::setCursor函数修改鼠标指针样式;鼠标移入按钮时自动变换样式

This commit is contained in:
Nomango 2018-05-07 17:03:59 +08:00
parent 6336c979c9
commit fe9d155779
4 changed files with 59 additions and 3 deletions

View File

@ -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 };

View File

@ -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)

View File

@ -70,6 +70,11 @@ public:
int iconID
);
// 譜崔報炎峺寞劔塀
static void setCursor(
Cursor cursor
);
// »ñÈ¡´°¿Ú±êÌâ
static String getTitle();

View File

@ -426,6 +426,17 @@ enum class KeyCode : int
};
// 鼠标指针样式
enum class Cursor : int
{
NORMAL, /* 默认指针样式 */
HAND, /* 手状指针 */
NO, /* 禁止指针 */
WAIT, /* 沙漏指针 */
ARROW_WAIT /* 默认指针和小沙漏 */
};
// 方向
enum class Direct : int
{