public UIObject GetFirstIntersector(Vector2 pos) { if (myChildren.Count > 0) { UIObject intersector = null; for (int i = myChildren.Count - 1; i >= 0; --i) { UIObject child = myChildren[i]; if (child.IsVisible && (intersector = child.GetFirstIntersector(pos - myPaddingTopLeft - child.Position)) != null) { return(intersector); } } } if (CheckPositionWithinBounds(pos)) { return(this); } return(null); }
public void SendMouseButtonEvent(Vector2 mousePos, OpenTK.Input.MouseButtonEventArgs e) { if (e.IsPressed) { if (myChildren.Count > 0) { UIObject intersector = null; for (int i = myChildren.Count - 1; i >= 0; --i) { UIObject child = myChildren[i]; Vector2 relativePos = mousePos - myPaddingTopLeft - child.Position; if (child.IsVisible && (intersector = child.GetFirstIntersector(relativePos)) != null) { if (child.IsEnabled) { if (child.CanBringToFront) { myChildren.Remove(child); myChildren.Add(child); } child.SendMouseButtonEvent(relativePos, e); } if (IsEnabled) { Focus(); if (!child.IsEnabled) { foreach (UIObject ch in myChildren) { if (ch.IsFocused) { ch.UnFocus(); } } myMouseDown = true; OnMouseDown(mousePos, e.Button); if (MouseDown != null) { MouseDown(this, e); } } } return; } } } if (CheckPositionWithinBounds(mousePos)) { if (IsEnabled) { Focus(); foreach (UIObject ch in myChildren) { if (ch.IsFocused) { ch.UnFocus(); } } myMouseDown = true; OnMouseDown(mousePos, e.Button); if (MouseDown != null) { MouseDown(this, e); } } } } else { UIObject intersector = null; if (IsVisible && (intersector = GetFirstIntersector(mousePos)) != null) { OnMouseUp(mousePos, e.Button); if (MouseUp != null) { MouseUp(this, e); } } if (myMouseDown) { myMouseDown = false; if (IsVisible && intersector != null) { OnClick(mousePos, e.Button); if (Click != null) { Click(this, e); } } } else { if (myChildren.Count > 0) { for (int i = myChildren.Count - 1; i >= 0 && i < myChildren.Count; --i) { UIObject child = myChildren[i]; Vector2 relativePos = mousePos - myPaddingTopLeft - child.Position; if (child.IsEnabled) { child.SendMouseButtonEvent(relativePos, e); } } } } } }