public void ProcessMouse(bool handledClick, bool handledMouseOver, out bool outHandledClick, out bool outHandledMouseOver) { // Apply mouse click and mouse over events for (int i = hierarchy.AllSorted.Count - 1; i >= 0; i--) { GUIElement element = hierarchy.AllSorted[i]; GUIElementMouseState ms = element.MouseState; bool mouseOver = element.CapturesMouseClicks && element.CanDraw() && element.CalculatedRectangle.Contains(Input.CursorPosition); element.IsMouseOver = !handledMouseOver && mouseOver; // Handle mouse enter/leave if (!handledMouseOver && mouseOver) { handledMouseOver = true; if (!ms.MouseWasOver) { element.MouseEnter(); ms.MouseWasOver = true; } } else if (ms.MouseWasOver) { element.MouseLeave(); ms.MouseWasOver = false; } // Handle mouse down/up for (int m = 0; m < MouseState.AllButtons.Length; m++) { MouseButton mbtn = MouseState.AllButtons[m]; if (mouseOver && !element.Disabled && !handledClick && Input.GetMouseButtonDown(mbtn)) { ms.ButtonsDown.Add(mbtn); element.MouseButtonDown(mbtn); handledClick = true; } else if (!Input.GetMouseButton(mbtn) && ms.ButtonsDown.Contains(mbtn)) { ms.ButtonsDown.Remove(mbtn); element.MouseButtonUp(mbtn); handledClick = true; } } } outHandledClick = handledClick || elementUsedKeyboard; outHandledMouseOver = handledMouseOver; elementUsedKeyboard = false; }
public GUIElement() { Children = new List <GUIElement>(); DeltaState = new GUIElementDeltaState(this); MouseState = new GUIElementMouseState(this); }