bool I_SetCursor(FTexture *cursorpic) { HCURSOR cursor; if (cursorpic != NULL && cursorpic->UseType != FTexture::TEX_Null && (screen == NULL || !screen->Is8BitMode())) { // Must be no larger than 32x32. if (cursorpic->GetWidth() > 32 || cursorpic->GetHeight() > 32) { return false; } cursor = CreateAlphaCursor(cursorpic); if (cursor == NULL) { cursor = CreateCompatibleCursor(cursorpic); } if (cursor == NULL) { return false; } // Replace the existing cursor with the new one. DestroyCustomCursor(); CustomCursor = cursor; atterm(DestroyCustomCursor); } else { DestroyCustomCursor(); cursor = LoadCursor(NULL, IDC_ARROW); } SetClassLongPtr(Window, GCLP_HCURSOR, (LONG_PTR)cursor); if (NativeMouse) { POINT pt; RECT client; // If the mouse pointer is within the window's client rect, set it now. if (GetCursorPos(&pt) && GetClientRect(Window, &client) && ClientToScreen(Window, (LPPOINT)&client.left) && ClientToScreen(Window, (LPPOINT)&client.right)) { if (pt.x >= client.left && pt.x < client.right && pt.y >= client.top && pt.y < client.bottom) { SetCursor(cursor); } } } return true; }
Mouse::~Mouse() { DestroyCustomCursor(); }
void Mouse::ReadOptions(ConfigParser& parser, const WCHAR* section) { DestroyCustomCursor(); m_MouseActions[MOUSE_LMB_UP].action = parser.ReadString(section, L"LeftMouseUpAction", L"", false); m_MouseActions[MOUSE_LMB_DOWN].action = parser.ReadString(section, L"LeftMouseDownAction", L"", false); m_MouseActions[MOUSE_LMB_DBLCLK].action = parser.ReadString(section, L"LeftMouseDoubleClickAction", L"", false); m_MouseActions[MOUSE_MMB_UP].action = parser.ReadString(section, L"MiddleMouseUpAction", L"", false); m_MouseActions[MOUSE_MMB_DOWN].action = parser.ReadString(section, L"MiddleMouseDownAction", L"", false); m_MouseActions[MOUSE_MMB_DBLCLK].action = parser.ReadString(section, L"MiddleMouseDoubleClickAction", L"", false); m_MouseActions[MOUSE_RMB_UP].action = parser.ReadString(section, L"RightMouseUpAction", L"", false); m_MouseActions[MOUSE_RMB_DOWN].action = parser.ReadString(section, L"RightMouseDownAction", L"", false); m_MouseActions[MOUSE_RMB_DBLCLK].action = parser.ReadString(section, L"RightMouseDoubleClickAction", L"", false); m_MouseActions[MOUSE_X1MB_UP].action = parser.ReadString(section, L"X1MouseUpAction", L"", false); m_MouseActions[MOUSE_X1MB_DOWN].action = parser.ReadString(section, L"X1MouseDownAction", L"", false); m_MouseActions[MOUSE_X1MB_DBLCLK].action = parser.ReadString(section, L"X1MouseDoubleClickAction", L"", false); m_MouseActions[MOUSE_X2MB_UP].action = parser.ReadString(section, L"X2MouseUpAction", L"", false); m_MouseActions[MOUSE_X2MB_DOWN].action = parser.ReadString(section, L"X2MouseDownAction", L"", false); m_MouseActions[MOUSE_X2MB_DBLCLK].action = parser.ReadString(section, L"X2MouseDoubleClickAction", L"", false); m_MouseActions[MOUSE_MW_UP].action = parser.ReadString(section, L"MouseScrollUpAction", L"", false); m_MouseActions[MOUSE_MW_DOWN].action = parser.ReadString(section, L"MouseScrollDownAction", L"", false); m_MouseActions[MOUSE_MW_LEFT].action = parser.ReadString(section, L"MouseScrollLeftAction", L"", false); m_MouseActions[MOUSE_MW_RIGHT].action = parser.ReadString(section, L"MouseScrollRightAction", L"", false); m_MouseActions[MOUSE_OVER].action = parser.ReadString(section, L"MouseOverAction", L"", false); m_MouseActions[MOUSE_LEAVE].action = parser.ReadString(section, L"MouseLeaveAction", L"", false); if (HasScrollAction()) { m_Skin->SetHasMouseScrollAction(); } const bool defaultState = (section == L"Rainmeter") ? true : m_Skin->GetMouse().GetCursorState(); m_CursorState = parser.ReadBool(section, L"MouseActionCursor", defaultState); const WCHAR* defaultMouseCursor = (section == L"Rainmeter") ? L"HAND" : L""; const WCHAR* mouseCursor = parser.ReadString(section, L"MouseActionCursorName", defaultMouseCursor).c_str(); auto inheritSkinDefault = [&]() { // Inherit from [Rainmeter]. m_CursorType = m_Skin->GetMouse().GetCursorType(); if (m_CursorType == MOUSECURSOR_CUSTOM) { mouseCursor = m_Skin->GetParser().ReadString(L"Rainmeter", L"MouseActionCursorName", L"").c_str(); } }; if (*mouseCursor == L'\0') // meters' default { inheritSkinDefault(); } else if (_wcsicmp(mouseCursor, L"HAND") == 0) // skin's default { m_CursorType = MOUSECURSOR_HAND; } else if (_wcsicmp(mouseCursor, L"TEXT") == 0) { m_CursorType = MOUSECURSOR_TEXT; } else if (_wcsicmp(mouseCursor, L"HELP") == 0) { m_CursorType = MOUSECURSOR_HELP; } else if (_wcsicmp(mouseCursor, L"BUSY") == 0) { m_CursorType = MOUSECURSOR_BUSY; } else if (_wcsicmp(mouseCursor, L"CROSS") == 0) { m_CursorType = MOUSECURSOR_CROSS; } else if (_wcsicmp(mouseCursor, L"PEN") == 0) { m_CursorType = MOUSECURSOR_PEN; } else if (wcschr(mouseCursor, L'.')) { m_CursorType = MOUSECURSOR_CUSTOM; } else { inheritSkinDefault(); } if (m_CursorType == MOUSECURSOR_CUSTOM) { std::wstring cursorPath = m_Skin->GetResourcesPath(); cursorPath += L"Cursors\\"; cursorPath += mouseCursor; m_CustomCursor = LoadCursorFromFile(cursorPath.c_str()); if (!m_CustomCursor) { m_CursorType = MOUSECURSOR_ARROW; LogErrorF(m_Skin, L"Invalid cursor: %s", cursorPath.c_str()); } } }
void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section, CMeterWindow* meterWindow) { DestroyCustomCursor(); m_LeftDownAction = parser.ReadString(section, L"LeftMouseDownAction", L"", false); m_RightDownAction = parser.ReadString(section, L"RightMouseDownAction", L"", false); m_MiddleDownAction = parser.ReadString(section, L"MiddleMouseDownAction", L"", false); m_X1DownAction = parser.ReadString(section, L"X1MouseDownAction", L"", false); m_X2DownAction = parser.ReadString(section, L"X2MouseDownAction", L"", false); m_LeftUpAction = parser.ReadString(section, L"LeftMouseUpAction", L"", false); m_RightUpAction = parser.ReadString(section, L"RightMouseUpAction", L"", false); m_MiddleUpAction = parser.ReadString(section, L"MiddleMouseUpAction", L"", false); m_X1UpAction = parser.ReadString(section, L"X1MouseUpAction", L"", false); m_X2UpAction = parser.ReadString(section, L"X2MouseUpAction", L"", false); m_LeftDoubleClickAction = parser.ReadString(section, L"LeftMouseDoubleClickAction", L"", false); m_RightDoubleClickAction = parser.ReadString(section, L"RightMouseDoubleClickAction", L"", false); m_MiddleDoubleClickAction = parser.ReadString(section, L"MiddleMouseDoubleClickAction", L"", false); m_X1DoubleClickAction = parser.ReadString(section, L"X1MouseDoubleClickAction", L"", false); m_X2DoubleClickAction = parser.ReadString(section, L"X2MouseDoubleClickAction", L"", false); m_OverAction = parser.ReadString(section, L"MouseOverAction", L"", false); m_LeaveAction = parser.ReadString(section, L"MouseLeaveAction", L"", false); m_MouseScrollDownAction = parser.ReadString(section, L"MouseScrollDownAction", L"", false); m_MouseScrollUpAction = parser.ReadString(section, L"MouseScrollUpAction", L"", false); m_MouseScrollLeftAction = parser.ReadString(section, L"MouseScrollLeftAction", L"", false); m_MouseScrollRightAction = parser.ReadString(section, L"MouseScrollRightAction", L"", false); if (!m_MouseScrollDownAction.empty() || !m_MouseScrollUpAction.empty() || !m_MouseScrollLeftAction.empty() || !m_MouseScrollRightAction.empty()) { meterWindow->SetHasMouseScrollAction(); } const bool defaultState = (section == L"Rainmeter") ? true : meterWindow->GetMouse().GetCursorState(); m_CursorState = 0!=parser.ReadInt(section, L"MouseActionCursor", defaultState); const WCHAR* defaultMouseCursor = (section == L"Rainmeter") ? L"HAND" : L""; const WCHAR* mouseCursor = parser.ReadString(section, L"MouseActionCursorName", defaultMouseCursor).c_str(); if (_wcsicmp(mouseCursor, L"HAND") == 0) { m_CursorType = MOUSECURSOR_HAND; } else if (_wcsicmp(mouseCursor, L"TEXT") == 0) { m_CursorType = MOUSECURSOR_TEXT; } else if (_wcsicmp(mouseCursor, L"HELP") == 0) { m_CursorType = MOUSECURSOR_HELP; } else if (_wcsicmp(mouseCursor, L"BUSY") == 0) { m_CursorType = MOUSECURSOR_BUSY; } else if (_wcsicmp(mouseCursor, L"CROSS") == 0) { m_CursorType = MOUSECURSOR_CROSS; } else if (_wcsicmp(mouseCursor, L"PEN") == 0) { m_CursorType = MOUSECURSOR_PEN; } else if (wcschr(mouseCursor, L'.')) { m_CursorType = MOUSECURSOR_CUSTOM; } else { // Inherit from [Rainmeter]. m_CursorType = meterWindow->GetMouse().GetCursorType(); if (m_CursorType == MOUSECURSOR_CUSTOM) { mouseCursor = meterWindow->GetParser().ReadString(L"Rainmeter", L"MouseActionCursorName", L"").c_str(); } } if (m_CursorType == MOUSECURSOR_CUSTOM) { std::wstring cursorPath = meterWindow->GetResourcesPath(); cursorPath += L"Cursors\\"; cursorPath += mouseCursor; m_CustomCursor = LoadCursorFromFile(cursorPath.c_str()); if (!m_CustomCursor) { m_CursorType = MOUSECURSOR_ARROW; LogWithArgs(LOG_ERROR, L"Invalid cursor: %s", cursorPath.c_str()); } } }