Table of Contents

Class UiSystem

Namespace
MLEM.Ui
Assembly
MLEM.Ui.dll

A ui system is the central location for the updating and rendering of all ui Elements. Each element added to the root of the ui system is assigned a RootElement that has additional data like a transformation matrix. For more information on how ui systems work, check out https://mlem.ellpeck.de/articles/ui.html.

public class UiSystem : GameComponent, IGameComponent, IUpdateable, IDisposable
Inheritance
GameComponent
UiSystem
Implements
IGameComponent
IUpdateable
Inherited Members
GameComponent.Initialize()
GameComponent.Dispose()
GameComponent.Game
GameComponent.Enabled
GameComponent.UpdateOrder
GameComponent.EnabledChanged
GameComponent.UpdateOrderChanged
Extension Methods

Constructors

UiSystem(Game, UiStyle, InputHandler, bool, bool, bool, bool, bool, bool)

Creates a new ui system with the given settings.

public UiSystem(Game game, UiStyle style, InputHandler inputHandler = null, bool automaticViewport = true, bool hasFontModifierFormatting = true, bool hasColorFormatting = true, bool hasAnimationFormatting = true, bool hasMacroFormatting = true, bool hasUiFormatting = true)

Parameters

game Game

The game

style UiStyle

The style settings that this ui should have. Use UntexturedStyle for the default, untextured style.

inputHandler InputHandler

The input handler that this ui's UiControls should use. If none is supplied, a new input handler is created for this ui.

automaticViewport bool

If this value is set to true, the ui system's Viewport will be set automatically based on the Microsoft.Xna.Framework.GameWindow's size. Defaults to true.

hasFontModifierFormatting bool

Whether default font modifier codes should be added to this ui system's TextFormatter, including bold, italic, strikethrough, shadow, subscript, and more.

hasColorFormatting bool

Whether default color codes should be added to this ui system's TextFormatter, including all Microsoft.Xna.Framework.Color values and the ability to use custom colors.

hasAnimationFormatting bool

Whether default animation codes should be added to this ui system's TextFormatter, namely the wobbly animation.

hasMacroFormatting bool

Whether default macros should be added to this ui system's TextFormatter, including TeX's ~ non-breaking space and more.

hasUiFormatting bool

Whether UiSystem-based formatting codes should be added to this ui system's TextFormatter, including Paragraph.Link codes and font switching.

Fields

AutoScaleReferenceSize

If AutoScaleWithScreen is true, this is used as the screen size that uses the default GlobalScale

public Point AutoScaleReferenceSize

Field Value

Point

AutoScaleWithScreen

Set this field to true to cause the ui system and all of its elements to automatically scale up or down with greater and lower resolution, respectively. If this field is true, AutoScaleReferenceSize is used as the size that uses default GlobalScale

public bool AutoScaleWithScreen

Field Value

bool

BlendState

The blend state that this ui system and all of its elements draw with

[Obsolete("Set this through SpriteBatchContext instead")]
public BlendState BlendState

Field Value

BlendState

Controls

The UiControls that this ui system is controlled by. The ui controls are also the place to change bindings for controller and keyboard input.

public UiControls Controls

Field Value

UiControls

DepthStencilState

The depth stencil state that this ui system and all of its elements draw with. The default is Microsoft.Xna.Framework.Graphics.DepthStencilState.None, which is also the default for SpriteBatch.Begin.

[Obsolete("Set this through SpriteBatchContext instead")]
public DepthStencilState DepthStencilState

Field Value

DepthStencilState

DrawAlpha

The transparency (alpha value) that this ui system and all of its elements draw at.

public float DrawAlpha

Field Value

float

Effect

The effect that this ui system and all of its elements draw with. The default is null, which means that no custom effect will be used.

[Obsolete("Set this through SpriteBatchContext instead")]
public Effect Effect

Field Value

Effect

Metrics

The update and rendering statistics to be used for runtime debugging and profiling. The metrics are reset accordingly every frame: ResetUpdates() is called at the start of Update(GameTime), and ResetDraws() is called at the start of Draw(GameTime, SpriteBatch).

public UiMetrics Metrics

Field Value

UiMetrics

SamplerState

The sampler state that this ui system and all of its elements draw with. The default is Microsoft.Xna.Framework.Graphics.SamplerState.PointClamp, as that is the one that works best with pixel graphics.

[Obsolete("Set this through SpriteBatchContext instead")]
public SamplerState SamplerState

Field Value

SamplerState

SpriteBatchContext

The spriteb atch context that this ui system and all of its elements should draw with. The default SamplerState is Microsoft.Xna.Framework.Graphics.SamplerState.PointClamp, as that is the one that works best with pixel graphics.

public SpriteBatchContext SpriteBatchContext

Field Value

SpriteBatchContext

TextFormatter

The TextFormatter that this ui system's Paragraph elements format their text with. To add new formatting codes to the ui system, add them to this formatter.

public TextFormatter TextFormatter

Field Value

TextFormatter

Properties

GlobalScale

The global rendering scale of this ui system and all of its child elements. If AutoScaleWithScreen is true, this scale will be different based on the window size.

public float GlobalScale { get; set; }

Property Value

float

Style

The style options that this ui system and all of its elements use. To set the default, untextured style, use UntexturedStyle.

public UiStyle Style { get; set; }

Property Value

UiStyle

Viewport

The viewport that this ui system is rendering inside of. This is automatically updated during Microsoft.Xna.Framework.GameWindow.ClientSizeChanged by default.

public Rectangle Viewport { get; set; }

Property Value

Rectangle

Methods

Add(string, Element)

Adds a new root element to this ui system and returns the newly created RootElement. Note that, when adding new elements that should be part of the same ui (like buttons on a panel), AddChild<T>(T, int) should be used.

public RootElement Add(string name, Element element)

Parameters

name string

The name of the new root element

element Element

The root element to add

Returns

RootElement

The newly created root element, or null if an element with the specified name already exists.

ApplyToAll(Action<Element>)

Applies the given action to all Element instances in this ui system recursively. Note that, when this method is invoked, all root elements and all of their children receive the Action.

public void ApplyToAll(Action<Element> action)

Parameters

action Action<Element>

The action to execute on each element

Dispose(bool)

Shuts down the component.

protected override void Dispose(bool disposing)

Parameters

disposing bool

Draw(GameTime, SpriteBatch)

Draws any Elements onto the screen.

public void Draw(GameTime time, SpriteBatch batch)

Parameters

time GameTime

The game's time

batch SpriteBatch

The sprite batch to use for drawing

DrawEarly(GameTime, SpriteBatch)

Draws any Panel and other elements that draw onto Microsoft.Xna.Framework.Graphics.RenderTarget2D rather than directly onto the screen. For drawing in this manner to work correctly, this method has to be called before your Microsoft.Xna.Framework.Graphics.GraphicsDevice is cleared, and before everything else in your game is drawn.

[Obsolete("DrawEarly is deprecated. Calling it is not required anymore, and there is no replacement.")]
public void DrawEarly(GameTime time, SpriteBatch batch)

Parameters

time GameTime

The game's time

batch SpriteBatch

The sprite batch to use for drawing

Get(string)

Finds the RootElement with the given name.

public RootElement Get(string name)

Parameters

name string

The root element's name

Returns

RootElement

The root element with the given name, or null if no such element exists

GetRootElements()

Returns an enumerable of all of the RootElement instances that this ui system holds.

public IEnumerable<RootElement> GetRootElements()

Returns

IEnumerable<RootElement>

All of this ui system's root elements

Remove(string)

Removes the RootElement with the specified name, or does nothing if there is no such element.

public void Remove(string name)

Parameters

name string

The name of the root element to remove

Update(GameTime)

Update this ui system, querying the necessary events and updating each element's data.

public override void Update(GameTime time)

Parameters

time GameTime

The game's time

Events

OnElementAreaUpdated

Event that is invoked when an Element's display area changes

public event Element.GenericCallback OnElementAreaUpdated

Event Type

Element.GenericCallback

OnElementDeselected

Event that is invoked when an Element is deselected during the selection of a new element.

public event Element.GenericCallback OnElementDeselected

Event Type

Element.GenericCallback

OnElementDrawn

Event that is invoked after an Element is drawn, but before its children are drawn.

public event Element.DrawCallback OnElementDrawn

Event Type

Element.DrawCallback

OnElementMouseEnter

Event that is invoked when the mouse enters an Element

public event Element.GenericCallback OnElementMouseEnter

Event Type

Element.GenericCallback

OnElementMouseExit

Event that is invoked when the mouse exits an Element

public event Element.GenericCallback OnElementMouseExit

Event Type

Element.GenericCallback

OnElementPressed

Event that is invoked when an Element is pressed with the primary action key

public event Element.GenericCallback OnElementPressed

Event Type

Element.GenericCallback

OnElementSecondaryPressed

Event that is invoked when an Element is pressed with the secondary action key

public event Element.GenericCallback OnElementSecondaryPressed

Event Type

Element.GenericCallback

OnElementSelected

Event that is invoked when an Element is newly selected using automatic navigation, or after it has been pressed with the mouse.

public event Element.GenericCallback OnElementSelected

Event Type

Element.GenericCallback

OnElementStyleInit

Event that is called when an Element's InitStyle(UiStyle) method is called while setting its Style.

public event Element.GenericCallback OnElementStyleInit

Event Type

Element.GenericCallback

OnElementTouchEnter

Event that is invoked when an Element starts being touched

public event Element.GenericCallback OnElementTouchEnter

Event Type

Element.GenericCallback

OnElementTouchExit

Event that is invoked when an Element stops being touched

public event Element.GenericCallback OnElementTouchExit

Event Type

Element.GenericCallback

OnElementUpdated

Event that is invoked when an Element is updated

public event Element.TimeCallback OnElementUpdated

Event Type

Element.TimeCallback

OnMousedElementChanged

Event that is invoked when the Element that the mouse is currently over changes

public event Element.GenericCallback OnMousedElementChanged

Event Type

Element.GenericCallback

OnRootAdded

Event that is invoked when a new RootElement is added to this ui system

public event UiSystem.RootCallback OnRootAdded

Event Type

UiSystem.RootCallback

OnRootRemoved

Event that is invoked when a RootElement is removed from this ui system

public event UiSystem.RootCallback OnRootRemoved

Event Type

UiSystem.RootCallback

OnSelectedElementChanged

Event that is invoked when the selected Element changes, either through automatic navigation, or by pressing on an element with the mouse

public event Element.GenericCallback OnSelectedElementChanged

Event Type

Element.GenericCallback

OnSelectedElementDrawn

Event that is invoked after the SelectedElement for each root element is drawn, but before its children are drawn.

public event Element.DrawCallback OnSelectedElementDrawn

Event Type

Element.DrawCallback

OnTouchedElementChanged

Event that is invoked when the Element that is being touched changes

public event Element.GenericCallback OnTouchedElementChanged

Event Type

Element.GenericCallback