Beispiel #1
0
//! called if an event happened.
bool CGUIContextMenu::OnEvent(const SEvent& event)
{
	if (!IsEnabled)
		return Parent ? Parent->OnEvent(event) : false;

	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
				setEventParent(Parent);
				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 Parent ? Parent->OnEvent(event) : false;
}
//! 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);
}