Class HudTransformPlacement
Turns a preview scale, deform or rotate gesture into a new element transform.
Inherited Members
Namespace: Serenity.GameUi.Application.Placement
Assembly: Serenity.GameUi.Application.dll
Syntax
public static class HudTransformPlacement
Remarks
Pure and engine-free, mirroring HudDragPlacement: every gesture is worked out in the element's displayed space and mirrored in and out only at the boundary, so the maths itself never has an opinion about which side of the screen a player is on.
Methods
AngleDeltaDegrees(float, float, float, float)
How far the pointer swept around the fixed point, in counter-clockwise degrees.
Declaration
public static float AngleDeltaDegrees(float startX, float startY, float currentX, float currentY)
Parameters
| Type | Name | Description |
|---|---|---|
| float | startX | Horizontal component of the vector at gesture start. |
| float | startY | Vertical component of the vector at gesture start. |
| float | currentX | Horizontal component of the vector this frame. |
| float | currentY | Vertical component of the vector this frame. |
Returns
| Type | Description |
|---|---|
| float | The angle swept, in degrees; zero when either vector is too short to give a direction. |
Remarks
Screen space runs +Y down, so the raw angle difference between the two vectors reads backwards against the canvas's own counter-clockwise convention; negating it is the one sign flip the whole rotate gesture needs.
AxisRatio(float, float, float, float, float, float)
How much bigger the pointer's motion along one axis has become, as a multiple of where it started.
Declaration
public static float AxisRatio(float startX, float startY, float currentX, float currentY, float axisX, float axisY)
Parameters
| Type | Name | Description |
|---|---|---|
| float | startX | Horizontal component of the vector at gesture start. |
| float | startY | Vertical component of the vector at gesture start. |
| float | currentX | Horizontal component of the vector this frame. |
| float | currentY | Vertical component of the vector this frame. |
| float | axisX | Horizontal component of the axis to project onto. |
| float | axisY | Vertical component of the axis to project onto. |
Returns
| Type | Description |
|---|---|
| float | The axis ratio; 1 when the start projection is too small to give a direction. |
Remarks
Unlike ScaleRatio(float, float, float, float), this projects onto an arbitrary axis rather than the start vector itself, so a deform gesture can grow one of the element's own local axes while ignoring motion along the other entirely. The guard checks the SIGNED projection's magnitude rather than a squared length, since the axis is not required to be normalized and a squared comparison would scale quadratically with however long the caller's axis vector happens to be.
CompensatedOffset(HudOffset, HudElementBasis, HudElementBasis, float, float)
The offset that keeps a fixed point in place while the element's scale, stretch and rotation change around its anchor.
Declaration
public static HudOffset CompensatedOffset(HudOffset displayedOffset, HudElementBasis before, HudElementBasis after, float fixedPointX, float fixedPointY)
Parameters
| Type | Name | Description |
|---|---|---|
| HudOffset | displayedOffset | The offset before this gesture, in displayed space. |
| HudElementBasis | before | The element's basis before this gesture. |
| HudElementBasis | after | The element's basis after this gesture. |
| float | fixedPointX | Horizontal position of the point to hold still, in container-local units. |
| float | fixedPointY | Vertical position of the point to hold still, in container-local units. |
Returns
| Type | Description |
|---|---|
| HudOffset | The compensated offset, in displayed space. |
Remarks
offset' = offset + before.Transform(f) − after.Transform(f) — exact for any affine map, since
the fixed point's position relative to the anchor moved by the old basis and will move by the new
one, so undoing the old displacement and applying the new one to the offset is what holds the point
still on screen.
Deform(IHudPlacedElement, HudTransformGesture, HudDeformGesture)
Applies a deform gesture to an element, stretching it along one or both of its own local axes and compensating its offset around the fixed point.
Declaration
public static HudElementTransform Deform(IHudPlacedElement element, HudTransformGesture gesture, HudDeformGesture deform)
Parameters
| Type | Name | Description |
|---|---|---|
| IHudPlacedElement | element | The element being deformed. |
| HudTransformGesture | gesture | The gesture to apply. |
| HudDeformGesture | deform | Which axes this gesture changes, and their screen-space directions. |
Returns
| Type | Description |
|---|---|
| HudElementTransform | The new scale, stretch, rotation and offset. |
Remarks
Only StretchX/StretchY change;
scale and rotation are echoed back unchanged. Mirrors in and out exactly like Resize(IHudPlacedElement, HudTransformGesture)
and Rotate(IHudPlacedElement, HudTransformGesture) — the offset and rotation cross the mirror boundary, but the stretch itself
never needs to: mirroring is a horizontal flip of an axis-aligned quantity, and F·R(θ)·S·F
equals R(−θ)·S for any stretch, so a mirrored element deforms by the same amount an unmirrored
one would for the same drag.
NormalizeDegrees(float)
Folds an angle into the half-open range (-180, 180] degrees.
Declaration
public static float NormalizeDegrees(float degrees)
Parameters
| Type | Name | Description |
|---|---|---|
| float | degrees | The angle to fold. |
Returns
| Type | Description |
|---|---|
| float | The equivalent angle within (-180, 180]. |
Resize(IHudPlacedElement, HudTransformGesture)
Applies a uniform scale gesture to an element, compensating its offset around the fixed point.
Declaration
public static HudElementTransform Resize(IHudPlacedElement element, HudTransformGesture gesture)
Parameters
| Type | Name | Description |
|---|---|---|
| IHudPlacedElement | element | The element being scaled. |
| HudTransformGesture | gesture | The gesture to apply. |
Returns
| Type | Description |
|---|---|
| HudElementTransform | The new scale, stretch, rotation and offset. |
Remarks
Only Scale changes; the gesture's own stretch is echoed back unchanged.
Rotate(IHudPlacedElement, HudTransformGesture)
Applies a rotate gesture to an element, compensating its offset around the fixed point.
Declaration
public static HudElementTransform Rotate(IHudPlacedElement element, HudTransformGesture gesture)
Parameters
| Type | Name | Description |
|---|---|---|
| IHudPlacedElement | element | The element being rotated. |
| HudTransformGesture | gesture | The gesture to apply. |
Returns
| Type | Description |
|---|---|
| HudElementTransform | The new scale, stretch, rotation and offset. |
Remarks
Only RotationDegrees changes; scale and stretch are echoed back unchanged.
ScaleRatio(float, float, float, float)
How much bigger the pointer's distance from the fixed point has become, as a multiple of where it started.
Declaration
public static float ScaleRatio(float startX, float startY, float currentX, float currentY)
Parameters
| Type | Name | Description |
|---|---|---|
| float | startX | Horizontal component of the vector at gesture start. |
| float | startY | Vertical component of the vector at gesture start. |
| float | currentX | Horizontal component of the vector this frame. |
| float | currentY | Vertical component of the vector this frame. |
Returns
| Type | Description |
|---|---|
| float | The scale ratio; 1 when the start vector is too short to give a direction. |
Remarks
The projection of the current vector onto the start vector, rather than a plain length ratio: a length ratio would report the same growth whichever direction the pointer moved, so dragging perpendicular to the starting handle would still "scale" the element. The projection collapses perpendicular motion towards zero instead, which is also why it needs no square root or trig — it is exact and cheap in both axes at once.
Snap(float, float)
Rounds a value to the nearest multiple of a step.
Declaration
public static float Snap(float value, float step)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to round. |
| float | step | The grid step. Zero or less leaves the value untouched. |
Returns
| Type | Description |
|---|---|
| float | The snapped value. |