Ejemplo n.º 1
0
bool CMouseHandler::AssignMouseCursor(
	const std::string& cmdName,
	const std::string& fileName,
	CMouseCursor::HotSpot hotSpot,
	bool overwrite
) {
	const auto cmdIt = cursorCommandMap.find(cmdName);
	const auto fileIt = cursorFileMap.find(fileName);

	const bool haveCmd = (cmdIt != cursorCommandMap.end());
	const bool haveFile = (fileIt != cursorFileMap.end());

	if (haveCmd && !overwrite)
		return false; // already assigned

	if (haveFile) {
		// cursor is already loaded, reuse it
		cursorCommandMap[cmdName] = fileIt->second;
		return true;
	}

	CMouseCursor newCursor = std::move(CMouseCursor::New(fileName, hotSpot));

	if (!newCursor.IsValid())
		return false;

	const int commandCursorIdx = haveCmd? cmdIt->second: -1;

	// assign the new cursor and remap indices
	loadedCursors.emplace_back();
	loadedCursors.back() = std::move(newCursor);

	cursorFileMap[fileName] = loadedCursors.size() - 1;
	cursorCommandMap[cmdName] = loadedCursors.size() - 1;

	// switch to the null-cursor if our active one is being (re)assigned
	if (activeCursorIdx == commandCursorIdx)
		SetCursor("none", true);

	return true;
}
Ejemplo n.º 2
0
bool CMouseHandler::ReplaceMouseCursor(
	const string& oldName,
	const string& newName,
	CMouseCursor::HotSpot hotSpot
) {
	const auto fileIt = cursorFileMap.find(oldName);

	if (fileIt == cursorFileMap.end())
		return false;

	CMouseCursor newCursor = std::move(CMouseCursor::New(newName, hotSpot));

	if (!newCursor.IsValid())
		return false; // leave the old one

	loadedCursors[fileIt->second] = std::move(newCursor);

	// update current cursor if necessary
	if (activeCursorIdx == fileIt->second)
		SetCursor(cursorText, true);

	return true;
}