public void OnEvent(DeftEvent theEvent, params object[] args) { Gadget focus = DeftUI.focus; if (focus == null) { return; } if (DeftUI.focusState == UIFocusState.Dragging) { Drag(focus); } else if (DeftUI.focusState == UIFocusState.Resizing) { Resize(focus, DeftUI.focusResizeAnchor); } }
private void Resize(Gadget g, AnchorPoint anchor) { Vector2 delta = Input.DeltaMousePos; float dx = delta.X; float dy = delta.Y; if (anchor == AnchorPoint.Left) { g.MoveByX(dx); g.Resize(new Vector2(-dx, 0)); } else if (anchor == AnchorPoint.Top) { g.MoveByY(dy); g.Resize(new Vector2(0, -dy)); } else if (anchor == AnchorPoint.Right) { g.Resize(new Vector2(dx, 0)); } else if (anchor == AnchorPoint.Bot) { g.Resize(new Vector2(0, dy)); } else if (anchor == AnchorPoint.TopLeft) { g.MoveBy(delta); g.Resize(-delta); } else if (anchor == AnchorPoint.TopRight) { g.MoveByY(dy); g.Resize(new Vector2(dx, -dy)); } else if (anchor == AnchorPoint.BotLeft) { g.MoveByX(dx); g.Resize(new Vector2(-dx, dy)); } else if (anchor == AnchorPoint.BotRight) { g.Resize(delta); } }
public void OnEvent(DeftEvent theEvent, params object[] args) { Gadget focus = DeftUI.focus; if (focus == null) { SelectNewFocusGadget(); } else { // Already have an active gadget, only make a new selection IF: // If within borders, we're not within the borders of a higher layer element // If not within borders, // If resizable, mouse not within resize boxes if (focus.Bounds.Contains(Input.MousePos)) { if (!IsHighestLayerGadgetAtPos(focus.Layer, Input.MousePos)) { SelectNewFocusGadget(); } } else // Mouse not within focus borders { if (!focus.isResizable) { SelectNewFocusGadget(); } else if (focus.Bounds.GetBoxAnchorPointAtPos(Input.MousePos, 7) == AnchorPoint.None) { SelectNewFocusGadget(); } } } // After focus gadget has been determined, fire its OnClick event. if (DeftUI.focus != null) { DeftUI.focus.OnClick(); } }
private void Drag(Gadget g) { g.MoveBy(Input.DeltaMousePos); }