logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Struct PreviewQuad

    One HUD element's footprint, projected into the preview frame: a rotated rectangle rather than an axis-aligned one, since an element can carry rotation.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    Namespace: Serenity.Ui.Infrastructure.Editor.Preview
    Assembly: Serenity.UnityUi.Infrastructure.Editor.dll
    Syntax
    public readonly struct PreviewQuad
    Remarks

    Everything drawn or hit-tested against a rotated element goes through this shape instead of RectTransformUtility.CalculateRelativeRectTransformBounds's axis-aligned box, which grows sharply oversized the moment an element turns — a 45° rotation inflates it by roughly 41%.

    Corners are stored in frame space (screen pixels, +Y down, matching IMGUI) so the shape can be hit-tested and drawn directly. LocalMin/LocalMax keep the untransformed footprint, in the element's own local reference units, so a gesture's fixed point can be named in the same space the pure placement solvers expect.

    Constructors

    PreviewQuad(Vector2, Vector2, Vector2, Vector2, Vector2, Vector2, Vector2)

    Creates a quad from its four projected corners and its untransformed local footprint.

    Declaration
    public PreviewQuad(Vector2 topLeft, Vector2 topRight, Vector2 bottomRight, Vector2 bottomLeft, Vector2 localMin, Vector2 localMax, Vector2 pivotFramePoint)
    Parameters
    Type Name Description
    Vector2 topLeft

    Frame-space top-left corner.

    Vector2 topRight

    Frame-space top-right corner.

    Vector2 bottomRight

    Frame-space bottom-right corner.

    Vector2 bottomLeft

    Frame-space bottom-left corner.

    Vector2 localMin

    The untransformed footprint's minimum corner, in local reference units.

    Vector2 localMax

    The untransformed footprint's maximum corner, in local reference units.

    Vector2 pivotFramePoint

    Frame-space position of the element's local origin.

    Fields

    BottomLeft

    Frame-space position of the element's bottom-left corner.

    Declaration
    public readonly Vector2 BottomLeft
    Field Value
    Type Description
    Vector2

    BottomRight

    Frame-space position of the element's bottom-right corner.

    Declaration
    public readonly Vector2 BottomRight
    Field Value
    Type Description
    Vector2

    LocalMax

    The untransformed footprint's maximum corner, in the element's own local reference units.

    Declaration
    public readonly Vector2 LocalMax
    Field Value
    Type Description
    Vector2

    LocalMin

    The untransformed footprint's minimum corner, in the element's own local reference units.

    Declaration
    public readonly Vector2 LocalMin
    Field Value
    Type Description
    Vector2

    PivotFramePoint

    Frame-space position of the element's own local origin — its anchor point.

    Declaration
    public readonly Vector2 PivotFramePoint
    Field Value
    Type Description
    Vector2

    TopLeft

    Frame-space position of the element's top-left corner (its own top-left, before rotation).

    Declaration
    public readonly Vector2 TopLeft
    Field Value
    Type Description
    Vector2

    TopRight

    Frame-space position of the element's top-right corner.

    Declaration
    public readonly Vector2 TopRight
    Field Value
    Type Description
    Vector2

    Properties

    Center

    The quad's centre, in frame space.

    Declaration
    public Vector2 Center { get; }
    Property Value
    Type Description
    Vector2

    Methods

    Contains(Vector2)

    Whether a frame-space point sits inside the quad.

    Declaration
    public bool Contains(Vector2 point)
    Parameters
    Type Name Description
    Vector2 point

    The frame-space point to test.

    Returns
    Type Description
    bool

    True when the point is inside the quad.

    Remarks

    Parameterizes the point against the quad's own two edges from TopLeft rather than testing against an axis-aligned box, so the test stays exact under rotation. No trig and no square root: two dot products place the point in the quad's own (u, v) space, and both must fall in [0, 1] for the point to be inside.

    DeformedAround(Vector2, Vector2, float)

    Predicts where this quad would render after a per-axis stretch and rotation change around a pivot, without a new render.

    Declaration
    public PreviewQuad DeformedAround(Vector2 pivot, Vector2 localRatio, float deltaDegrees)
    Parameters
    Type Name Description
    Vector2 pivot

    The frame-space point the transform turns and stretches around.

    Vector2 localRatio

    How much bigger the element has become along its own local X and Y axes since this quad was captured.

    float deltaDegrees

    How far the element has turned since this quad was captured, in displayed-space CCW degrees.

    Returns
    Type Description
    PreviewQuad

    The predicted quad.

    Remarks

    Decomposes each corner's offset from the pivot onto the quad's own orthonormalized edge axes — so a stretch always applies along the element's own local axes, never the frame's — scales each axis coefficient independently, then re-composes and rotates by deltaDegrees exactly the way TransformedAround(Vector2, float, float) already does. With localRatio's two components equal, this reproduces TransformedAround(Vector2, float, float)'s result.

    Inflated(float)

    Grows the quad outward by a fixed number of pixels on every side, along its own (possibly rotated) axes.

    Declaration
    public PreviewQuad Inflated(float pixels)
    Parameters
    Type Name Description
    float pixels

    How far to grow, in frame-space pixels.

    Returns
    Type Description
    PreviewQuad

    The grown quad.

    Remarks

    Used to pad hit-testing so a small element stays clickable, without the padding itself becoming lopsided under rotation the way inflating an axis-aligned box first would.

    ProjectLocalPoint(Vector2)

    Projects an arbitrary point in the element's own local reference units into frame space, using this quad's four corners as the affine mapping.

    Declaration
    public Vector2 ProjectLocalPoint(Vector2 localPoint)
    Parameters
    Type Name Description
    Vector2 localPoint

    The point to project, in local reference units.

    Returns
    Type Description
    Vector2

    The frame-space position of that point.

    Remarks

    A rotation and uniform scale is an affine map, so bilinear interpolation across the untransformed footprint's corners reconstructs it exactly for any local point — including one outside the footprint, which the mapping still extrapolates correctly.

    TransformedAround(Vector2, float, float)

    Predicts where this quad would render after a scale and rotation change around a pivot, without a new render.

    Declaration
    public PreviewQuad TransformedAround(Vector2 pivot, float scaleRatio, float deltaDegrees)
    Parameters
    Type Name Description
    Vector2 pivot

    The frame-space point the transform turns and scales around.

    float scaleRatio

    How much bigger the element has become since this quad was captured.

    float deltaDegrees

    How far the element has turned since this quad was captured, in displayed-space CCW degrees.

    Returns
    Type Description
    PreviewQuad

    The predicted quad.

    Remarks

    Used to keep the gizmo tracking the mouse at full rate while the canvas texture itself renders on a throttled cadence: scaleRatio and deltaDegrees describe how much further the element has moved since this quad was captured, so the prediction self-corrects the moment the next real render lands.

    The rotation runs in frame space, which is +Y down; a positive deltaDegrees is a counter-clockwise turn in the element's own (+Y up) displayed space, so the frame-space rotation applied here is the negation — the same sign flip HudTransformPlacement.AngleDeltaDegrees uses going the other way.

    Translated(Vector2)

    Shifts every corner and the pivot by a frame-space pixel offset.

    Declaration
    public PreviewQuad Translated(Vector2 pixelDelta)
    Parameters
    Type Name Description
    Vector2 pixelDelta

    The offset to shift by, in frame-space pixels.

    Returns
    Type Description
    PreviewQuad

    The shifted quad.

    In this article
    © 2026 Serenity. All Rights Reserved