public static Vector2 GetTopLeftPosition(Size shape, Vector2 anchoredPosition, RectAnchors anchor) { switch (anchor) { case RectAnchors.Top: return anchoredPosition - new Vector2(shape.Width / 2, 0); case RectAnchors.TopRight: return anchoredPosition - new Vector2(shape.Width, 0); case RectAnchors.Left: return anchoredPosition - new Vector2(0, shape.Height / 2); case RectAnchors.Center: return anchoredPosition - new Vector2(shape.Width / 2, shape.Height / 2); case RectAnchors.Right: return anchoredPosition - new Vector2(shape.Width, shape.Height / 2); case RectAnchors.BottomLeft: return anchoredPosition - new Vector2(0, shape.Height); case RectAnchors.Bottom: return anchoredPosition - new Vector2(shape.Width / 2, shape.Height); case RectAnchors.BottomRight: return anchoredPosition - new Vector2(shape.Width, shape.Height); default: return anchoredPosition; } }
public void SetViewportPosition(Vector2 position, RectAnchors anchor) { this.viewport.Position = AnchorHelper.GetTopLeftPosition(Size, position, anchor); }
public Vector2 GetViewportPosition(RectAnchors anchor) { return AnchorHelper.GetAnchoredPosition(Size, ViewportPosition, anchor); }