void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos)
{
	IGUIElement* lastHovered = Hovered;

	Hovered = getElementFromPoint(mousePos);

	if (Hovered)
	{
		Hovered->grab();

		if (Hovered != lastHovered)
		{
			SEvent event;
			event.EventType = EET_GUI_EVENT;

			if (lastHovered)
			{
				event.GUIEvent.Caller = lastHovered;
				event.GUIEvent.EventType = EGET_ELEMENT_LEFT;
				lastHovered->OnEvent(event);
			}

			event.GUIEvent.Caller = Hovered;
			event.GUIEvent.EventType = EGET_ELEMENT_HOVERED;
			Hovered->OnEvent(event);
		}
	}

	if (lastHovered)
		lastHovered->drop();
}
Example #2
0
void KGUIWin32Wnd::UpdateHoveredElement(const KDS_EVENT& event)
{
	KPoint point(event.MouseEvent.X, event.MouseEvent.Y);

	if (GetChildCount() <= 0)
		return ;

	// Window element has only one child.
	IGUIElement * pGUIOver = this->GetChild(0)->HitTest(point);
	if (m_pGUIHover != pGUIOver)
	{
		if (m_pGUIHover != NULL)
		{
			KDS_EVENT msg;
			memset(&msg, 0, sizeof(msg));
			msg.EventType = KET_MOUSE;
			msg.MouseEvent = event.MouseEvent;
			msg.MouseEvent.Event = KME_MOUSE_LEAVE;			// Mouse leave message
			m_pGUIHover->OnEvent(msg);
		}
		if (pGUIOver != NULL)
		{
			KDS_EVENT msg;
			memset(&msg, 0, sizeof(msg));
			msg.EventType = KET_MOUSE;
			msg.MouseEvent = event.MouseEvent;
			msg.MouseEvent.Event	= KME_MOUSE_ENTER;		// Mouse enter message
			pGUIOver->OnEvent(msg);
		}
	}

	m_pGUIHover = pGUIOver;
}
Example #3
0
//! called if an event happened.
bool CGUIContextMenu::OnEvent(const SEvent& event)
{
	if (isEnabled())
	{

		switch(event.EventType)
		{
		case EET_GUI_EVENT:
			switch(event.GUIEvent.EventType)
			{
			case EGET_ELEMENT_FOCUS_LOST:
				if (event.GUIEvent.Caller == this && !isMyChild(event.GUIEvent.Element) && AllowFocus)
				{
					// set event parent of submenus
					IGUIElement * p =  EventParent ? EventParent : Parent;
					setEventParent(p);

					SEvent event;
					event.EventType = EET_GUI_EVENT;
					event.GUIEvent.Caller = this;
					event.GUIEvent.Element = 0;
					event.GUIEvent.EventType = EGET_ELEMENT_CLOSED;
					if ( !p->OnEvent(event) )
					{
						if ( CloseHandling & ECMC_HIDE )
						{
							setVisible(false);
						}
						if ( CloseHandling & ECMC_REMOVE )
						{
							remove();
						}
					}

					return false;
				}
				break;
			case EGET_ELEMENT_FOCUSED:
				if (event.GUIEvent.Caller == this && !AllowFocus)
				{
					return true;
				}
				break;
			default:
				break;
			}
			break;
		case EET_MOUSE_INPUT_EVENT:
			switch(event.MouseInput.Event)
			{
			case EMIE_LMOUSE_LEFT_UP:
				{
					// menu might be removed if it loses focus in sendClick, so grab a reference
					grab();
					const u32 t = sendClick(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
					if ((t==0 || t==1) && Environment->hasFocus(this))
						Environment->removeFocus(this);
					drop();
				}
				return true;
			case EMIE_LMOUSE_PRESSED_DOWN:
				return true;
			case EMIE_MOUSE_MOVED:
				if (Environment->hasFocus(this))
					highlight(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y), true);
				return true;
			default:
				break;
			}
			break;
		default:
			break;
		}
	}

	return IGUIElement::OnEvent(event);
}