Skip to content

Class Transform

Definition

Namespace: StardewUI.Graphics
Assembly: StardewUI.dll

Global transform applied to an ISpriteBatch.

[StardewUI.DuckType]
public record Transform : IEquatable<StardewUI.Graphics.Transform>

Inheritance
Object ⇦ Transform

Implements
IEquatable<Transform>

Remarks

The order of the different translation parameters reflects the actual order in which the transformations will be applied in a GlobalTransform. Scaling before rotation prevents unexpected skewing, and rotating before translation keeps the coordinate system intact.

To deliberately apply the individual operations in a different order, use separate Transform instances applied in sequence, or simply compute the Matrix directly.

Members

Constructors

Name Description
Transform(Vector2, Single, Vector2) Global transform applied to an ISpriteBatch.
Transform(Vector2?, Single, Vector2) Initializes a new Transform instance.

Fields

Name Description
Default Default instance with no transformations applied.

Properties

Name Description
EqualityContract
HasNonUniformScale Whether the current instance has a non-uniform Scale.
HasRotation Whether the current instance has a non-zero Rotation.
HasScale Whether the current instance has non-unity Scale, regardless of uniformity.
HasTranslation Whether the current instance has a non-zero Translation.
IsOriginRelative Whether the current transform is affected by transform origin.
Rotation 2D rotation (always along Z axis) to apply, in radians.
Scale The scale at which to draw. One is unity scale (i.e. no scaling).
Translation Translation offset for drawn content.

Methods

Name Description
CanMergeLocally(Transform) Checks if a subsequent transform can be merged into this one while preserving the result as a simple local transform, i.e. not requiring the use of a transformation matrix.
CanMergeLocally(Vector2, Single, Vector2) Checks if a subsequent transform, represented by its individual components, can be merged into this one while preserving the result as a simple local transform, i.e. not requiring the use of a transformation matrix.
FromRotation(Single) Creates a new Transform that applies a specific 2D rotation.
FromScale(Vector2) Creates a Transform using a specified scale.
FromTranslation(Vector2) Creates a Transform using a specified translation offset.
IsRectangular() Checks if this transform represents a single rectangular area of the parent, i.e. not rotated or skewed.
ToMatrix() Creates a transformation matrix from the properties of this transform.

Details

Constructors

Transform(Vector2, float, Vector2)

Global transform applied to an ISpriteBatch.

public Transform(Microsoft.Xna.Framework.Vector2 Scale, float Rotation, Microsoft.Xna.Framework.Vector2 Translation);
Parameters

Scale   Vector2
The scale at which to draw. One is unity scale (i.e. no scaling).

Rotation   Single
2D rotation (always along Z axis) to apply, in radians.

Translation   Vector2
Translation offset for drawn content.

Remarks

The order of the different translation parameters reflects the actual order in which the transformations will be applied in a GlobalTransform. Scaling before rotation prevents unexpected skewing, and rotating before translation keeps the coordinate system intact.

To deliberately apply the individual operations in a different order, use separate Transform instances applied in sequence, or simply compute the Matrix directly.


Transform(Vector2?, float, Vector2)

Initializes a new Transform instance.

public Transform(Microsoft.Xna.Framework.Vector2? Scale, float Rotation, Microsoft.Xna.Framework.Vector2 Translation);
Parameters

Scale   Nullable<Vector2>
The scale at which to draw. One is unity scale (i.e. no scaling).

Rotation   Single
2D rotation (always along Z axis) to apply, in radians.

Translation   Vector2
Translation offset for drawn content.

Remarks

This overload supports optional parameters, particularly for use in duck typing.


Fields

Default

Default instance with no transformations applied.

public static readonly StardewUI.Graphics.Transform Default;
Field Value

Transform


Properties

EqualityContract

protected System.Type EqualityContract { get; }
Property Value

Type


HasNonUniformScale

Whether the current instance has a non-uniform Scale.

public bool HasNonUniformScale { get; }
Property Value

Boolean

Remarks

Non-uniform scale sometimes needs to be treated differently from uniform scale because the former is not commutative with rotation.


HasRotation

Whether the current instance has a non-zero Rotation.

public bool HasRotation { get; }
Property Value

Boolean


HasScale

Whether the current instance has non-unity Scale, regardless of uniformity.

public bool HasScale { get; }
Property Value

Boolean


HasTranslation

Whether the current instance has a non-zero Translation.

public bool HasTranslation { get; }
Property Value

Boolean


IsOriginRelative

Whether the current transform is affected by transform origin.

public bool IsOriginRelative { get; }
Property Value

Boolean

Remarks

Some types of transformations, specifically translation, have outcomes independent of the transformation origin and should therefore not attempt to use it or pass it on to global transforms.


Rotation

2D rotation (always along Z axis) to apply, in radians.

public float Rotation { get; set; }
Property Value

Single


Scale

The scale at which to draw. One is unity scale (i.e. no scaling).

public Microsoft.Xna.Framework.Vector2 Scale { get; set; }
Property Value

Vector2


Translation

Translation offset for drawn content.

public Microsoft.Xna.Framework.Vector2 Translation { get; set; }
Property Value

Vector2


Methods

CanMergeLocally(Transform)

Checks if a subsequent transform can be merged into this one while preserving the result as a simple local transform, i.e. not requiring the use of a transformation matrix.

public bool CanMergeLocally(StardewUI.Graphics.Transform next);
Parameters

next   Transform
The local transformation to apply after the current instance.

Returns

Boolean

true if the cumulative sequence of transformations can continue to be represented as a simple local Transform; false if the combination requires converting ToMatrix() and subsequent inclusion into a new GlobalTransform.

Remarks

Local transforms can be merged if they are either:


CanMergeLocally(Vector2, float, Vector2)

Checks if a subsequent transform, represented by its individual components, can be merged into this one while preserving the result as a simple local transform, i.e. not requiring the use of a transformation matrix.

public bool CanMergeLocally(Microsoft.Xna.Framework.Vector2 scale, float rotation, Microsoft.Xna.Framework.Vector2 translation);
Parameters

scale   Vector2
The Scale component of the next transform.

rotation   Single
The Rotation component of the next transform.

translation   Vector2
The Translation component of the next transform.

Returns

Boolean


FromRotation(float)

Creates a new Transform that applies a specific 2D rotation.

public static StardewUI.Graphics.Transform FromRotation(float angle);
Parameters

angle   Single
The rotation angle, in radians.

Returns

Transform

A Transform whose Rotation is equal to the specified angle.


FromScale(Vector2)

Creates a Transform using a specified scale.

public static StardewUI.Graphics.Transform FromScale(Microsoft.Xna.Framework.Vector2 scale);
Parameters

scale   Vector2
The scale to apply.

Returns

Transform

A Transform whose Scale is equal to the specified scale.


FromTranslation(Vector2)

Creates a Transform using a specified translation offset.

public static StardewUI.Graphics.Transform FromTranslation(Microsoft.Xna.Framework.Vector2 translation);
Parameters

translation   Vector2
The translation offset.

Returns

Transform

A Transform whose Translation is equal to the specified translation.


IsRectangular()

Checks if this transform represents a single rectangular area of the parent, i.e. not rotated or skewed.

public bool IsRectangular();
Returns

Boolean


ToMatrix()

Creates a transformation matrix from the properties of this transform.

public Microsoft.Xna.Framework.Matrix ToMatrix();
Returns

Matrix

A transformation matrix equivalent to this transform.

Remarks

The created matrix, when used with Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?), will have the same effect as if the current Scale, Rotation and Translation were to be provided directly as arguments to the sprite or text drawing method(s).