using Modding; using UnityEngine; namespace MagicUI.Core { /// /// Class containing various UI utilities and constants /// public static class UI { /// /// A rectangle representing the screen /// public static readonly Rect Screen = new(Vector2.zero, new Vector2(1920, 1080)); /// /// The Trajan Normal font /// public static Font TrajanNormal { get => CanvasUtil.TrajanNormal; } /// /// The Trajan Bold font /// public static Font TrajanBold { get => CanvasUtil.TrajanBold; } /// /// The Perpetua font /// public static Font Perpetua { get => CanvasUtil.GetFont("Perpetua"); } /// /// Converts a position in reference screen space to a unity position /// /// The position in screen space /// The size of the element /// /// Reference screen space is the coordinate system with (0, 0) in the top-left and /// (1920, 1080) in the bottom-right. /// public static Vector2 UnityScreenPosition(Vector2 pos, Vector2 elementSize) { return UnityParentRelativePosition(pos, elementSize, Screen.size); } /// /// Converts a position in parent space to a unity position /// /// The position in parent space /// The size of the element /// The size of the element's parent /// /// Parent space is the coordinate system with (0, 0) in the top-left and /// (W, H) in the bottom-right, where W is the width of the parent and H is the height /// of the parent /// public static Vector2 UnityParentRelativePosition(Vector2 pos, Vector2 elementSize, Vector2 parentSize) { return new((pos.x + elementSize.x / 2f) / parentSize.x, (parentSize.y - (pos.y + elementSize.y / 2f)) / parentSize.y); } } }