增加Window::setCursor函数修改鼠标指针样式;鼠标移入按钮时自动变换样式
This commit is contained in:
parent
6336c979c9
commit
fe9d155779
|
|
@ -12,6 +12,8 @@ bool e2d::Window::__init()
|
||||||
// ×¢²á´°¿ÚÀà
|
// ×¢²á´°¿ÚÀà
|
||||||
WNDCLASSEX wcex = { 0 };
|
WNDCLASSEX wcex = { 0 };
|
||||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||||
|
wcex.lpszClassName = L"Easy2DApp";
|
||||||
|
wcex.hIcon = NULL;
|
||||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
wcex.lpfnWndProc = Window::WndProc;
|
wcex.lpfnWndProc = Window::WndProc;
|
||||||
wcex.cbClsExtra = 0;
|
wcex.cbClsExtra = 0;
|
||||||
|
|
@ -19,9 +21,7 @@ bool e2d::Window::__init()
|
||||||
wcex.hInstance = HINST_THISCOMPONENT;
|
wcex.hInstance = HINST_THISCOMPONENT;
|
||||||
wcex.hbrBackground = NULL;
|
wcex.hbrBackground = NULL;
|
||||||
wcex.lpszMenuName = NULL;
|
wcex.lpszMenuName = NULL;
|
||||||
wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION);
|
wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
|
||||||
wcex.lpszClassName = L"Easy2DApp";
|
|
||||||
wcex.hIcon = NULL;
|
|
||||||
|
|
||||||
RegisterClassEx(&wcex);
|
RegisterClassEx(&wcex);
|
||||||
|
|
||||||
|
|
@ -189,6 +189,39 @@ void e2d::Window::setIcon(int iconID)
|
||||||
::SendMessage(s_HWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
|
::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()
|
e2d::String e2d::Window::getTitle()
|
||||||
{
|
{
|
||||||
wchar_t wszTitle[MAX_PATH] = { 0 };
|
wchar_t wszTitle[MAX_PATH] = { 0 };
|
||||||
|
|
|
||||||
|
|
@ -211,17 +211,24 @@ void e2d::Button::onFixedUpdate()
|
||||||
if (m_pNormal->isPointIn(Input::getMousePos()))
|
if (m_pNormal->isPointIn(Input::getMousePos()))
|
||||||
{
|
{
|
||||||
_setState(ButtonState::SELECTED);
|
_setState(ButtonState::SELECTED);
|
||||||
|
Window::setCursor(Cursor::HAND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_pNormal->isPointIn(Input::getMousePos()))
|
else if (m_pNormal->isPointIn(Input::getMousePos()))
|
||||||
{
|
{
|
||||||
_setState(ButtonState::MOUSEOVER);
|
_setState(ButtonState::MOUSEOVER);
|
||||||
|
Window::setCursor(Cursor::HAND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setState(ButtonState::NORMAL);
|
_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)
|
void e2d::Button::_setState(ButtonState state)
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,11 @@ public:
|
||||||
int iconID
|
int iconID
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 譜崔報炎峺寞劔塀
|
||||||
|
static void setCursor(
|
||||||
|
Cursor cursor
|
||||||
|
);
|
||||||
|
|
||||||
// »ñÈ¡´°¿Ú±êÌâ
|
// »ñÈ¡´°¿Ú±êÌâ
|
||||||
static String getTitle();
|
static String getTitle();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -426,6 +426,17 @@ enum class KeyCode : int
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 鼠标指针样式
|
||||||
|
enum class Cursor : int
|
||||||
|
{
|
||||||
|
NORMAL, /* 默认指针样式 */
|
||||||
|
HAND, /* 手状指针 */
|
||||||
|
NO, /* 禁止指针 */
|
||||||
|
WAIT, /* 沙漏指针 */
|
||||||
|
ARROW_WAIT /* 默认指针和小沙漏 */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// 方向
|
// 方向
|
||||||
enum class Direct : int
|
enum class Direct : int
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue