private void OnMouseMoveNotCaptured(MouseEventArgs mouseEvent) { if (Parent != null && Parent.mouseMoveEventHasBeenAcceptedByOther) { mouseMoveEventHasBeenAcceptedByOther = true; } for (int i = Children.Count - 1; i >= 0; i--) { GuiWidget child = Children[i]; double childX = mouseEvent.X; double childY = mouseEvent.Y; child.ParentToChildTransform.inverse_transform(ref childX, ref childY); MouseEventArgs childMouseEvent = new MouseEventArgs(mouseEvent, childX, childY); if (child.Visible && child.Enabled && child.CanSelect) { child.OnMouseMove(childMouseEvent); if (child.PositionWithinLocalBounds(childX, childY)) { mouseMoveEventHasBeenAcceptedByOther = true; } } } if (PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y)) { bool needToCallEnterBounds = underMouseState == UI.UnderMouseState.NotUnderMouse; if (mouseMoveEventHasBeenAcceptedByOther) { if (UnderMouseState == UI.UnderMouseState.FirstUnderMouse) { // set it before we call the function to have the state right to the callee underMouseState = UI.UnderMouseState.UnderMouseNotFirst; OnMouseLeave(mouseEvent); } underMouseState = UI.UnderMouseState.UnderMouseNotFirst; } else { if (!FirstWidgetUnderMouse) { if (mouseMoveEventHasBeenAcceptedByOther) { underMouseState = UI.UnderMouseState.UnderMouseNotFirst; } else { underMouseState = UI.UnderMouseState.FirstUnderMouse; SetToolTipText(mouseEvent); OnMouseEnter(mouseEvent); } } else // we are the first under mouse { if (mouseMoveEventHasBeenAcceptedByOther) { underMouseState = UI.UnderMouseState.UnderMouseNotFirst; OnMouseLeave(mouseEvent); } } } if (needToCallEnterBounds) { OnMouseEnterBounds(mouseEvent); } if (MouseMove != null) { MouseMove(this, mouseEvent); } } else if (UnderMouseState != UI.UnderMouseState.NotUnderMouse) { if (FirstWidgetUnderMouse) { underMouseState = UI.UnderMouseState.NotUnderMouse; OnMouseLeave(mouseEvent); } underMouseState = UI.UnderMouseState.NotUnderMouse; OnMouseLeaveBounds(mouseEvent); } }
public virtual void OnMouseUp(MouseEventArgs mouseEvent) { if (childrenLockedInMouseUpCount != 0) { BreakInDebugger("This should not be locked."); } childrenLockedInMouseUpCount++; if (mouseCapturedState == MouseCapturedState.NotCaptured) { if (PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y)) { bool childHasAcceptedThisEvent = false; for (int i = Children.Count - 1; i >= 0; i--) { GuiWidget child = Children[i]; double childX = mouseEvent.X; double childY = mouseEvent.Y; child.ParentToChildTransform.inverse_transform(ref childX, ref childY); MouseEventArgs childMouseEvent = new MouseEventArgs(mouseEvent, childX, childY); if (child.Visible && child.Enabled && child.CanSelect) { if (child.PositionWithinLocalBounds(childX, childY)) { childHasAcceptedThisEvent = true; child.OnMouseUp(childMouseEvent); i = -1; } else { if (UnderMouseState != UI.UnderMouseState.NotUnderMouse) { if (FirstWidgetUnderMouse) { OnMouseLeave(mouseEvent); } DoMouseMovedOffWidgetRecursive(mouseEvent); underMouseState = UI.UnderMouseState.NotUnderMouse; } } } } if (!childHasAcceptedThisEvent) { if (MouseUp != null) { MouseUp(this, mouseEvent); } } } } else // either this or a child has the mouse captured { if (mouseCapturedState == MouseCapturedState.ChildHasMouseCaptured) { if (childrenLockedInMouseUpCount != 1) { BreakInDebugger("The mouse should always be locked while in mouse up."); } int countOfChildernThatThinkTheyHaveTheMouseCaptured = 0; foreach (GuiWidget child in Children) { if (childrenLockedInMouseUpCount != 1) { BreakInDebugger("The mouse should always be locked while in mouse up."); } double childX = mouseEvent.X; double childY = mouseEvent.Y; child.ParentToChildTransform.inverse_transform(ref childX, ref childY); MouseEventArgs childMouseEvent = new MouseEventArgs(mouseEvent, childX, childY); if (child.mouseCapturedState != MouseCapturedState.NotCaptured) { if (countOfChildernThatThinkTheyHaveTheMouseCaptured > 0) { BreakInDebugger("One and only one child should ever have the mouse captured."); } child.OnMouseUp(childMouseEvent); countOfChildernThatThinkTheyHaveTheMouseCaptured++; } } } else { if (mouseCapturedState != MouseCapturedState.ThisHasMouseCaptured) { BreakInDebugger("You should only ever get here if you have the mouse captured."); } if (MouseUp != null) { MouseUp(this, mouseEvent); } } if (!PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y)) { if (UnderMouseState != UI.UnderMouseState.NotUnderMouse) { if (FirstWidgetUnderMouse) { underMouseState = UI.UnderMouseState.NotUnderMouse; OnMouseLeave(mouseEvent); OnMouseLeaveBounds(mouseEvent); } else { underMouseState = UI.UnderMouseState.NotUnderMouse; OnMouseLeaveBounds(mouseEvent); } DoMouseMovedOffWidgetRecursive(mouseEvent); } } ClearCapturedState(); } childrenLockedInMouseUpCount--; if (childrenLockedInMouseUpCount != 0) { BreakInDebugger("This should not be locked."); } }
private void OnMouseMoveWhenCaptured(MouseEventArgs mouseEvent) { if (mouseCapturedState == MouseCapturedState.ChildHasMouseCaptured) { int countOfChildernThatThinkTheyHaveTheMouseCaptured = 0; foreach (GuiWidget child in Children) { double childX = mouseEvent.X; double childY = mouseEvent.Y; child.ParentToChildTransform.inverse_transform(ref childX, ref childY); MouseEventArgs childMouseEvent = new MouseEventArgs(mouseEvent, childX, childY); if (child.mouseCapturedState != MouseCapturedState.NotCaptured) { child.OnMouseMove(childMouseEvent); countOfChildernThatThinkTheyHaveTheMouseCaptured++; } } if (countOfChildernThatThinkTheyHaveTheMouseCaptured < 1 || countOfChildernThatThinkTheyHaveTheMouseCaptured > 1) { BreakInDebugger("One and only one child should ever have the mouse captured."); } } else { if (mouseCapturedState != MouseCapturedState.ThisHasMouseCaptured) { BreakInDebugger("You should only ever get here if you have the mouse captured."); } if (PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y)) { if (!FirstWidgetUnderMouse) { underMouseState = UI.UnderMouseState.FirstUnderMouse; OnMouseEnter(mouseEvent); OnMouseEnterBounds(mouseEvent); } else if (underMouseState == UI.UnderMouseState.NotUnderMouse) { underMouseState = UI.UnderMouseState.FirstUnderMouse; OnMouseEnterBounds(mouseEvent); } underMouseState = UI.UnderMouseState.FirstUnderMouse; } else { if (FirstWidgetUnderMouse) { underMouseState = UI.UnderMouseState.NotUnderMouse; OnMouseLeave(mouseEvent); OnMouseLeaveBounds(mouseEvent); } else if (underMouseState != UI.UnderMouseState.NotUnderMouse) { underMouseState = UI.UnderMouseState.NotUnderMouse; OnMouseLeaveBounds(mouseEvent); } underMouseState = UI.UnderMouseState.NotUnderMouse; } if (MouseMove != null) { MouseMove(this, mouseEvent); } } }
public virtual void OnMouseDown(MouseEventArgs mouseEvent) { if (PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y)) { bool childHasAcceptedThisEvent = false; bool childHasTakenFocus = false; for (int i = Children.Count - 1; i >= 0; i--) { GuiWidget child = Children[i]; double childX = mouseEvent.X; double childY = mouseEvent.Y; child.ParentToChildTransform.inverse_transform(ref childX, ref childY); MouseEventArgs childMouseEvent = new MouseEventArgs(mouseEvent, childX, childY); // If any previous child has accepted the MouseDown, then we won't continue propogating the event and // will attempt to fire MovedOffWidget logic if (childHasAcceptedThisEvent) { // another child already took the down so no one else can. child.DoMouseMovedOffWidgetRecursive(childMouseEvent); } else { if (child.Visible && child.Enabled && child.CanSelect) { if (child.PositionWithinLocalBounds(childX, childY)) { childHasAcceptedThisEvent = true; child.OnMouseDown(childMouseEvent); if (child.ContainsFocus) { childHasTakenFocus = true; } } else { child.DoMouseMovedOffWidgetRecursive(childMouseEvent); child.Unfocus(); } } } } bool mouseEnteredBounds = underMouseState == UI.UnderMouseState.NotUnderMouse; if (childHasAcceptedThisEvent) { mouseCapturedState = MouseCapturedState.ChildHasMouseCaptured; if (UnderMouseState == UI.UnderMouseState.FirstUnderMouse) { underMouseState = UI.UnderMouseState.NotUnderMouse; OnMouseLeave(mouseEvent); } underMouseState = UI.UnderMouseState.UnderMouseNotFirst; } else { mouseCapturedState = MouseCapturedState.ThisHasMouseCaptured; if (!FirstWidgetUnderMouse) { underMouseState = UI.UnderMouseState.FirstUnderMouse; OnMouseEnter(mouseEvent); } if (MouseDown != null) { MouseDown(this, mouseEvent); } } if (mouseEnteredBounds) { OnMouseEnterBounds(mouseEvent); } if (!childHasTakenFocus) { if (CanFocus) { Focus(); } } if (MouseDownInBounds != null) { MouseDownInBounds(this, mouseEvent); } } else if (UnderMouseState != UI.UnderMouseState.NotUnderMouse) { Unfocus(); mouseCapturedState = MouseCapturedState.NotCaptured; OnMouseLeaveBounds(mouseEvent); if (UnderMouseState == UI.UnderMouseState.FirstUnderMouse) { OnMouseLeave(mouseEvent); } DoMouseMovedOffWidgetRecursive(mouseEvent); } }
private void SetUnderMouseStateRecursive() { foreach (GuiWidget child in Children) { child.SetUnderMouseStateRecursive(); } underMouseState = UI.UnderMouseState.NotUnderMouse; }
private void DoMouseMovedOffWidgetRecursive(MouseEventArgs mouseEvent) { foreach (GuiWidget child in Children) { double childX = mouseEvent.X; double childY = mouseEvent.Y; child.ParentToChildTransform.inverse_transform(ref childX, ref childY); MouseEventArgs childMouseEvent = new MouseEventArgs(mouseEvent, childX, childY); child.DoMouseMovedOffWidgetRecursive(childMouseEvent); } bool needToCallLeaveBounds = underMouseState != UI.UnderMouseState.NotUnderMouse; bool needToCallLeave = UnderMouseState == UI.UnderMouseState.FirstUnderMouse; underMouseState = UI.UnderMouseState.NotUnderMouse; if (needToCallLeave) { OnMouseLeave(mouseEvent); } if (needToCallLeaveBounds) { OnMouseLeaveBounds(mouseEvent); } }
private void ClearMouseOverWidget() { foreach (GuiWidget child in Children) { ClearMouseOverWidget(); } underMouseState = UnderMouseState.NotUnderMouse; }