Пример #1
0
/// If false, will use current stack top to get hover element. If using mouse you should pass true as argument.
UIElement * UserInterface::GetHoverElement(bool fromRoot /* = false */)
{
	if (fromRoot)
		return root->GetElementByState(UIState::HOVER);
	UIElement * stackTop = GetStackTop();
	if (stackTop)
		return stackTop->GetElementByState(UIState::HOVER);
	return NULL;
}
Пример #2
0
/** Mouse interactions with the UI, in x and y from 0.0 to 1.0, with 0.0 being in the Upper Left corner. Returns the element currently hovered over.
	If allUi is specified the current stack order will be ignored to a certain extent, meaning that ui below the current stack top will be made available too.
	Search is conducted starting at the highest stack element and going down until an element is found that we can hover over.
*/
UIElement * UserInterface::Hover(int x, int y, bool allUi)
{
	UIElement * stackTop = GetStackTop();
	if (!stackTop)
		return NULL;
	UIElement * previousHoverElement = NULL;
	if (!previousHoverElement)
	{			
		previousHoverElement = stackTop->GetElementByState(UIState::HOVER);
//		std::cout<<"\nPrevious hover element: "<<previousHoverElement;
//		if (previousHoverElement)
//			std::cout<<previousHoverElement->name;
	}
	UIElement * result = NULL;
	/// Search taking into consideration the stack but searching until an element is found.
	if(allUi)
	{
		for (int i = stack.Size()-1; i >= 0; --i)
		{
			UIElement * stackElement = stack[i];
			/// Remove the hover flag before re-hovering.
			stackElement->RemoveFlags(UIState::HOVER);
			result = stackElement->Hover(x,y);
			if (result)
				break;
		}
		/// If still no result, try the root.
		if (!result)
		{
			root->RemoveFlags(UIState::HOVER);
			result = root->Hover(x,y);
		}
		/// Demand hover will have to be investigated how it could work in this mode, if at all.
		hoverElement = result;	
	}
	/// Old search using only the stack-top.
	else {
		UIElement * previous = stackTop->GetElementByState(UIState::HOVER);
		/// Remove the hover flag before re-hovering.
		stackTop->RemoveFlags(UIState::HOVER);
		result = stackTop->Hover(x,y);
		hoverElement = result;
		/// If we always want a hovered element (for whatever reason).
		if (!hoverElement && demandHovered && previous){
			hoverElement = stackTop->Hover(previous->posX, previous->posY);
		}
	}

	if (inputState->demandHoverElement && result == NULL)
	{
		/// Try reverting to previous element?
		if (previousHoverElement)
		{
			result = previousHoverElement;
			result->state |= UIState::HOVER;
		}
		if (result == NULL)
		{
//			std::cout<<"\nProblema.";
		}
	}
	return result;
}