Beispiel #1
0
// --------------------------------------------------------------------------------------------------------------------
bool CViewPointer::drawCustom(CCtrlBase* pCB)
{
	string texName;
	uint8 rot;
	NLMISC::CRGBA col;
	if (pCB->getMouseOverShape(texName, rot, col))
	{
		if (texName[0] == '@')
		{
			const string &tooltipInfos = texName.substr(1);
			string tooltip;
			vector<string> tooltipInfosList;
			splitString(tooltipInfos, "@", tooltipInfosList);
			texName = tooltipInfosList[0];
			tooltip = tooltipInfosList[1];
			nlinfo(tooltip.c_str());
			setString(ucstring(tooltip));
			CInterfaceManager *pIM = CInterfaceManager::getInstance();
			CViewRenderer &rVR = pIM->getViewRenderer();
			sint32 texId = rVR.getTextureIdFromName (texName);

			CInterfaceGroup *stringCursor = IsMouseCursorHardware() ? _StringCursorHardware : _StringCursor;
			if (stringCursor)
			{
				stringCursor->setX(_PointerX);
				stringCursor->setY(_PointerY);
				stringCursor->updateCoords();
				stringCursor->draw();
				// if in hardware mode, force to draw the default cursor no matter what..
				if (IsMouseCursorHardware())
					drawCursor(texId, col, 0);
			}
			else
			{
				drawCursor(texId, col, 0);
			}
			return true;
		}
		else
		{
			CInterfaceManager *pIM = CInterfaceManager::getInstance();
			CViewRenderer &rVR = pIM->getViewRenderer();
			sint32 texId = rVR.getTextureIdFromName (texName);
			drawCursor(texId, col, 0);
			return true;
		}
	}
	return false;
}
Beispiel #2
0
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::draw ()
{
	// Do not display the pointer if not visible.
	if(!_PointerVisible)
		return;

	CInterfaceManager *pIM = CInterfaceManager::getInstance();
	CViewRenderer &rVR = pIM->getViewRenderer();

	if (pIM->isInGame())
	if (!_StringCursor)
	{
		// Create the string cursor instance
		std::vector<std::pair<std::string,std::string> > templateParams;
		templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor"));

		_StringCursor = pIM->createGroupInstance("string_cursor", "", templateParams);
		if (_StringCursor)
			_StringCursor->setParentPos(pIM->getElementFromId("ui:interface"));

		templateParams.clear();
		templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor_hardware"));
		_StringCursorHardware = pIM->createGroupInstance("string_cursor_hardware", "", templateParams);
		if (_StringCursorHardware)
			_StringCursorHardware->setParentPos(pIM->getElementFromId("ui:interface"));
	}

	CRGBA col;
	if(getModulateGlobalColor())
		col.modulateFromColor (_Color, pIM->getGlobalColor());
	else
		col= _Color;

	//col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColor().A+1))>>8);
	col.A = _Color.A;

	if (_LastHightLight != NULL)
	{
		_LastHightLight->setHighLighted(false,0);
		_LastHightLight = NULL;
	}

	if (pIM->getCapturePointerLeft() != NULL && pIM->isMouseHandlingEnabled())
	{
		CCtrlMover *pCM = dynamic_cast<CCtrlMover*>(pIM->getCapturePointerLeft());
		if ((pCM != NULL) && (pCM->canMove() == true))
		{
			CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent());
			if (pGC != NULL && !pGC->isLocked())
			{
				pGC->setHighLighted(true, 255);
				_LastHightLight = pGC;
			}
		}
	}

	if (_TxIdDefault == -2)
	{
		_TxIdDefault	= rVR.getTextureIdFromName (_TxDefault);
		_TxIdMoveWindow = rVR.getTextureIdFromName (_TxMoveWindow);
		_TxIdResizeBRTL = rVR.getTextureIdFromName (_TxResizeBRTL);
		_TxIdResizeBLTR = rVR.getTextureIdFromName (_TxResizeBLTR);
		_TxIdResizeTB	= rVR.getTextureIdFromName (_TxResizeTB);
		_TxIdResizeLR	= rVR.getTextureIdFromName (_TxResizeLR);
		_TxIdRotate		= rVR.getTextureIdFromName (_TxRotate);
		_TxIdScale		= rVR.getTextureIdFromName (_TxScale);
		_TxIdColPick	= rVR.getTextureIdFromName (_TxColPick);
		_TxIdPan		= rVR.getTextureIdFromName (_TxPan);
		_TxIdCanPan		= rVR.getTextureIdFromName (_TxCanPan);
		if (ClientCfg.R2EDEnabled)
		{
			_TxIdPanR2		= rVR.getTextureIdFromName (_TxPanR2);
			_TxIdCanPanR2	= rVR.getTextureIdFromName (_TxCanPanR2);
		}
	}

	const vector<CCtrlBase *> &rICL = pIM->getCtrlsUnderPointer ();


	// Draw the captured cursor
	CCtrlBase *pCB = pIM->getCapturePointerLeft();
	if (pCB != NULL)
	{
		if (drawResizer(pCB,col)) return;
		//if (drawMover(pCB,col)) return;
		if (drawColorPicker(pCB,col)) return;
		if (drawRotate(pCB,col)) return;
		if (drawPan(pCB,col)) return;
		if (drawCustom(pCB)) return;
		drawCursor(_TxIdDefault, col, 0);
		return;
	}

	const vector<CViewBase *> &vUP = pIM->getViewsUnderPointer ();

	for(uint i=0;i<vUP.size();i++)
	{
		CViewLink *vLink = dynamic_cast<CViewLink*>(vUP[i]);
		if (vLink != NULL)
		{
			string tooltip;
			uint8 rot;

			if (vLink->getMouseOverShape(tooltip, rot, col))
			{
				setString(ucstring(tooltip));
				sint32 texId = rVR.getTextureIdFromName ("curs_pick.tga");

				CInterfaceGroup *stringCursor = IsMouseCursorHardware() ? _StringCursorHardware : _StringCursor;
				if (stringCursor)
				{
					stringCursor->setX(_PointerX);
					stringCursor->setY(_PointerY);
					stringCursor->updateCoords();
					stringCursor->draw();
					// if in hardware mode, force to draw the default cursor no matter what..
					if (IsMouseCursorHardware())
						drawCursor(texId, col, 0);
				}
				else
				{
					drawCursor(texId, col, 0);
				}
				return;
			}
		}
	}

	// Draw if capture right
	pCB = pIM->getCapturePointerRight();
	if (pCB != NULL)
	{
		// Is it a 3d scene ?
		if (drawScale(pCB,col)) return;
		drawCursor(_TxIdDefault, col, 0);
		return;
	}

	bool overModalWindow = false;


	// is the cursor currently over a modal window ?
	CInterfaceGroup *currModal = pIM->getModalWindow();
	if (currModal)
	{
		sint32 xPos = _XReal + _OffsetX;
		sint32 yPos = _YReal + _OffsetY;
		overModalWindow = currModal->isIn(xPos, yPos, _WReal, _HReal);
	}

	// Draw the cursor type that are under the pointer
	if (pIM->isMouseHandlingEnabled())
	{
		// Sorts the controls according to their depth, to approximate as best the CapturePointerLeft algo.
		// Especially important so that Resizers controls get the precedence over the move control (else could randomly bug like in chat group)
		static vector<CCtrlDepthEntry>		sortedControls;
		sortedControls.clear();
		for(uint i=0;i<rICL.size();i++)
		{
			CCtrlDepthEntry		cde;
			cde.Ctrl= rICL[i];
			// NB: not the exact CInterfaceManager getDepth test here, but should work fine
			cde.Depth= cde.Ctrl->getParentDepth() + cde.Ctrl->getDeltaDepth();
			sortedControls.push_back(cde);
		}
		std::sort(sortedControls.begin(), sortedControls.end());

		// Then draw the correct cursor
		for (uint32 i = 0; i < sortedControls.size(); ++i)
		{
			CCtrlBase *pCB = sortedControls[i].Ctrl;

			if (overModalWindow)
			{
				if (!pCB->isSonOf(currModal)) continue;
			}

			if (drawBrowse(pCB, col)) return;
			if (drawResizer(pCB,col)) return;
			if (drawColorPicker(pCB,col)) return;
			if (drawLink (pCB, col)) return;
			if (drawCustom(pCB)) return;

			// test for move highlight
			if (_LastHightLight == NULL)
			{
				CCtrlMover *pCM = dynamic_cast<CCtrlMover*>(pCB);
				if ( (pCM != NULL) && (pCM->canMove() == true) )
				{
					CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent());
					if (pGC != NULL && !pGC->isLocked())
					{
						if (pIM->getCapturePointerLeft() != pCM)
							pGC->setHighLighted(true, 128);
						else
							pGC->setHighLighted(true, 255);
						_LastHightLight = pGC;
						break;
					}
				}
			}

			//if (drawMover(pCB,col)) return;
		}
	}

	if (pIM->isMouseHandlingEnabled())
	{
		if (rICL.empty())
		{
			const vector<CInterfaceGroup *> &rIGL = pIM->getGroupsUnderPointer ();
			for (uint32 i = 0; i < rIGL.size(); ++i)
			{
				CInterfaceGroup *pG = rIGL[i];
				if (overModalWindow)
				{
					if (!pG->isSonOf(currModal)) continue;
				}
				if (drawPan (pG, col)) return;
				if (drawBrowse(pG, col)) return;
			}
		}
	}

	if (_StringMode && pIM->isMouseHandlingEnabled())
	{
		CInterfaceGroup *stringCursor = IsMouseCursorHardware() ? _StringCursorHardware : _StringCursor;
		if (stringCursor)
		{
			stringCursor->setX(_PointerX);
			stringCursor->setY(_PointerY);
			stringCursor->updateCoords();
			stringCursor->draw();
			// if in hardware mode, force to draw the default cursor no matter what..
			if (IsMouseCursorHardware())
			{
				drawCursor(_TxIdDefault, col, 0);
			}
		}
	}
	else
	{
		// Draw the default cursor
		drawCursor(_TxIdDefault, col, 0);
	}
}