Class UiSystem
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
-
GameComponentUiSystem
- Implements
-
IGameComponentIUpdateable
- Inherited Members
-
GameComponent.Initialize()GameComponent.Dispose()GameComponent.GameGameComponent.EnabledGameComponent.UpdateOrderGameComponent.EnabledChangedGameComponent.UpdateOrderChanged
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
GameThe game
style
UiStyleThe style settings that this ui should have. Use UntexturedStyle for the default, untextured style.
inputHandler
InputHandlerThe input handler that this ui's UiControls should use. If none is supplied, a new input handler is created for this ui.
automaticViewport
boolIf 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
boolWhether default font modifier codes should be added to this ui system's TextFormatter, including bold, italic, strikethrough, shadow, subscript, and more.
hasColorFormatting
boolWhether 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
boolWhether default animation codes should be added to this ui system's TextFormatter, namely the wobbly animation.
hasMacroFormatting
boolWhether default macros should be added to this ui system's TextFormatter, including TeX's ~ non-breaking space and more.
hasUiFormatting
boolWhether 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
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
DrawAlpha
The transparency (alpha value) that this ui system and all of its elements draw at.
public float DrawAlpha
Field Value
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
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
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
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
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
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
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
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
GameTimeThe game's time
batch
SpriteBatchThe sprite batch to use for drawing
Get(string)
Finds the RootElement with the given name.
public RootElement Get(string name)
Parameters
name
stringThe 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
stringThe 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
GameTimeThe game's time
Events
OnElementAreaUpdated
Event that is invoked when an Element's display area changes
public event Element.GenericCallback OnElementAreaUpdated
Event Type
OnElementDeselected
Event that is invoked when an Element is deselected during the selection of a new element.
public event Element.GenericCallback OnElementDeselected
Event Type
OnElementDrawn
Event that is invoked after an Element is drawn, but before its children are drawn.
public event Element.DrawCallback OnElementDrawn
Event Type
OnElementMouseEnter
Event that is invoked when the mouse enters an Element
public event Element.GenericCallback OnElementMouseEnter
Event Type
OnElementMouseExit
Event that is invoked when the mouse exits an Element
public event Element.GenericCallback OnElementMouseExit
Event Type
OnElementPressed
Event that is invoked when an Element is pressed with the primary action key
public event Element.GenericCallback OnElementPressed
Event Type
OnElementSecondaryPressed
Event that is invoked when an Element is pressed with the secondary action key
public event Element.GenericCallback OnElementSecondaryPressed
Event Type
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
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
OnElementTouchEnter
Event that is invoked when an Element starts being touched
public event Element.GenericCallback OnElementTouchEnter
Event Type
OnElementTouchExit
Event that is invoked when an Element stops being touched
public event Element.GenericCallback OnElementTouchExit
Event Type
OnElementUpdated
Event that is invoked when an Element is updated
public event Element.TimeCallback OnElementUpdated
Event Type
OnMousedElementChanged
Event that is invoked when the Element that the mouse is currently over changes
public event Element.GenericCallback OnMousedElementChanged
Event Type
OnRootAdded
Event that is invoked when a new RootElement is added to this ui system
public event UiSystem.RootCallback OnRootAdded
Event Type
OnRootRemoved
Event that is invoked when a RootElement is removed from this ui system
public event UiSystem.RootCallback OnRootRemoved
Event Type
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
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
OnTouchedElementChanged
Event that is invoked when the Element that is being touched changes
public event Element.GenericCallback OnTouchedElementChanged