Table of Contents

Class Image

Namespace
MLEM.Ui.Elements
Assembly
MLEM.Ui.dll

An image element to be used inside of a UiSystem. An image is simply an element that displays a supplied TextureRegion and optionally allows for the texture region to remain at its original aspect ratio, regardless of the element's size.

public class Image : Element, IGenericDataHolder, IDisposable
Inheritance
Image
Implements
Derived
Inherited Members
Extension Methods

Constructors

Image(Anchor, Vector2, TextureRegion, bool)

Creates a new image with the given settings

public Image(Anchor anchor, Vector2 size, TextureRegion texture, bool scaleToImage = false)

Parameters

anchor Anchor

The image's anchor

size Vector2

The image's size

texture TextureRegion

The texture the image should render

scaleToImage bool

Whether this image's size should be based on the texture's size

Image(Anchor, Vector2, TextureCallback, bool)

Creates a new image with the given settings

public Image(Anchor anchor, Vector2 size, Image.TextureCallback getTextureCallback, bool scaleToImage = false)

Parameters

anchor Anchor

The image's anchor

size Vector2

The image's size

getTextureCallback Image.TextureCallback
scaleToImage bool

Whether this image's size should be based on the texture's size

Fields

Color

The color to render the image at

public StyleProp<Color> Color

Field Value

StyleProp<Color>

GetTextureCallback

A callback to retrieve the TextureRegion that this image should render. This can be used if the image changes frequently.

public Image.TextureCallback GetTextureCallback

Field Value

Image.TextureCallback

ImageEffects

The Microsoft.Xna.Framework.Graphics.SpriteEffects that the texture should be rendered with

public SpriteEffects ImageEffects

Field Value

SpriteEffects

ImageRotation

The rotation that the image should be rendered with. Note that increased rotation does not increase this component's size, even if the rotated texture would go out of bounds of this component.

public float ImageRotation

Field Value

float

ImageScale

The scale that the image should be rendered with

public Vector2 ImageScale

Field Value

Vector2

MaintainImageAspect

Whether to cause the TextureRegion to be rendered at its proper aspect ratio. If this is false, the image will be stretched according to this component's size.

public bool MaintainImageAspect

Field Value

bool

SamplerState

The sampler state that this image's Texture should be drawn with. If this is null, the current SpriteBatchContext's SamplerState will be used, which will likely be the same as SpriteBatchContext.

public SamplerState SamplerState

Field Value

SamplerState

Properties

IsHidden

Set this property to true to cause this element to be hidden. Hidden elements don't receive input events, aren't rendered and don't factor into auto-anchoring.

public override bool IsHidden { get; }

Property Value

bool

ScaleToImage

Whether this image element's Size should be based on the size of the TextureRegion given. Note that, when scaling to the image's size, the Scale is also taken into account.

public bool ScaleToImage { get; set; }

Property Value

bool

SetHeightBasedOnAspect

Whether this image's height should automatically be calculated based on this image's calculated width in relation to its Texture's aspect ratio. This behavior is useful if an image should take up a certain width, but the aspect ratio of its texture can vary and the image should not take up more height than is necessary. Note that, if this is true, the AutoSizeAddedAbsolute value will still be applied to this image's height.

public bool SetHeightBasedOnAspect { get; set; }

Property Value

bool

SetWidthBasedOnAspect

Whether this image's width should automatically be calculated based on this image's calculated height in relation to its Texture's aspect ratio. Note that, if this is true, the AutoSizeAddedAbsolute value will still be applied to this image's width.

public bool SetWidthBasedOnAspect { get; set; }

Property Value

bool

Texture

The texture that this TextureRegion should render

public TextureRegion Texture { get; set; }

Property Value

TextureRegion

Methods

CalcActualSize(RectangleF)

Calculates the actual size that this element should take up, based on the area that its parent encompasses. By default, this is based on the information specified in Size's documentation.

protected override Vector2 CalcActualSize(RectangleF parentArea)

Parameters

parentArea RectangleF

This parent's area, or the ui system's viewport if it has no parent

Returns

Vector2

The actual size of this element, taking Scale into account

Draw(GameTime, SpriteBatch, float, SpriteBatchContext)

Draws this element and all of its children. Override this method to draw the content of custom elements. Note that, when this is called, SpriteBatch.Begin has already been called with custom Transform etc. applied.

public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context)

Parameters

time GameTime

The game's time

batch SpriteBatch

The sprite batch to use for drawing

alpha float

The alpha to draw this element and its children with

context SpriteBatchContext

The sprite batch context to use for drawing

Update(GameTime)

Updates this element and all of its SortedChildren

public override void Update(GameTime time)

Parameters

time GameTime

The game's time