Color legend plain property dependency property method
A class. The quick start guide shows it in context.
Names are colored by what they are: a property, a method or an event; values and fields keep the plain color.
Properties
DisplayScaleFactor 馃爢
float 路 What the display scale is multiplied with while following: a UI size setting of the game. 1 by default, a positive number. Set while following, it applies at once.
DrawTransform 馃爢
Matrix 路 Read-only. The matrix the UI draws with. Draw code that begins its own sprite batch inside the UI passes it to draw in logical units.
ElementUnderMouse 馃爢
BaseElement 路 Read-only. ElementAt where the mouse is, as the elements read it (MousePosition). See finding the element at a point.
ExceptionHandler 馃爢
Action<Exception> 路 Gets the exceptions thrown inside Update, Draw and the handling of text input. Without a handler they are rethrown.
FocusedElement 馃爢
BaseElement 路 Read-only. The element that has the keyboard, null when none has it. See keyboard and focus.
FollowsBackBuffer 馃爢
bool 路 Whether the UI takes the back buffer鈥檚 size by itself, at the start of every Update. On by default. Turn it off for a UI drawn into a render target of its own size. Turned on again, it takes the back buffer鈥檚 size at the next update.
FollowsDisplayScale 馃爢
bool 路 Whether Scale follows the display scale of the window鈥檚 monitor, times DisplayScaleFactor. Turned on, it sets the scale at once and then follows the window to other monitors. A scale set by hand stays until the DPI changes. Off by default. Needs the window constructor, otherwise turning it on throws.
HasKeyboard 馃爢
bool 路 Read-only. Whether an element has the keyboard (see FocusedElement). A game leaves the keys to the UI while it is true, so typing in a text box doesn鈥檛 also move the player.
HasMouse 馃爢
bool 路 Read-only. Whether the UI has the mouse: it is over an element that takes the mouse (the root doesn鈥檛 count), the buttons pressed on an element are still held, or a modal window is shown. Buttons pressed where no element takes the mouse are the game鈥檚 until they are released, also while the mouse passes over elements, so a camera dragged across a panel goes on turning. A game acts on the mouse itself only while it is false, so a click on a button doesn鈥檛 also pick what is behind it. Worked out from the last update鈥檚 layout, so read it after Update. See sharing the mouse and keys.
MouseCursorHandler 馃爢
Action<MouseCursor> 路 Shows the cursors the elements ask for; it never gets null. By default MonoGame鈥檚 Mouse.SetCursor, which shows them through the game window and throws without one, so a UI hosted outside a game window gives its own way, or null to show no cursors. Disposing the UI puts MonoGame鈥檚 way back. See showing the cursors.
MousePosition 馃爢
Point 路 Read-only. Where the mouse is, in logical units (see Scale) and read through ShownAt: the position the elements read, for a tool that works over the UI with the mouse. Outside of the screen while the mouse is outside of it. See drawing into a render target.
RootElement 馃爢
RootElement 路 Read-only. The element at the top of the tree, the size of the screen. See the root element.
Scale 馃爢
float 路 How large one logical unit is on screen, see display scaling. Between MinScale (0.25) and MaxScale (8).
ShownAt 馃爢
Rectangle? 路 Where the UI鈥檚 screen is shown, in device pixels of the window the mouse is read in, when it is not shown where it is drawn: drawn into a render target of its own size (see FollowsBackBuffer) and that target shown scaled or moved, as a tool previewing a game鈥檚 UI at the game鈥檚 resolution inside its own window does. The mouse is read through it: a position in the rectangle is mapped onto the UI鈥檚 screen, one outside of it is outside of the screen, over no element. Changing it has the UI work out again what the mouse is over, though the mouse didn鈥檛 move. null, the default, shows the screen as it is drawn and reads the mouse as it is; a rectangle without a size counts as null. Disposing the UI puts it back to null. See drawing into a render target.
Fields
MaxScale
float
MinScale
float
Methods
BorrowedTorchUI() 馃爢
BorrowedTorchUI(GraphicsDevice graphicsDevice, ContentManager contentManager, SpriteBatch spriteBatch, GameWindow window) 路 Creates the UI over the back buffer鈥檚 size, with the text and keys of the window. The sprite batch is the one the UI draws with; the content manager loads the textures named by TexturesPath. Disposing the UI unsubscribes from the window.
| Parameter | Type | Description |
|---|---|---|
graphicsDevice |
GraphicsDevice |
The game鈥檚 graphics device, which the UI draws with. |
contentManager |
ContentManager |
The content manager the UI loads pictures with: the TexturesPath textures and SourceData paths. |
spriteBatch |
SpriteBatch |
The sprite batch the UI draws with. |
window |
GameWindow |
The game window: the UI takes typed text and keys from it, and reads the display scale of its monitor for FollowsDisplayScale. |
BorrowedTorchUI(GraphicsDevice graphicsDevice, ContentManager contentManager, SpriteBatch spriteBatch, ITextInputEvents textInputEvents) 路 The same, with the text and keys of a source of your own, for a UI hosted outside a game window. The UI doesn鈥檛 dispose the source.
| Parameter | Type | Description |
|---|---|---|
graphicsDevice |
GraphicsDevice |
The game鈥檚 graphics device, which the UI draws with. |
contentManager |
ContentManager |
The content manager the UI loads pictures with: the TexturesPath textures and SourceData paths. |
spriteBatch |
SpriteBatch |
The sprite batch the UI draws with. |
textInputEvents |
ITextInputEvents |
The source of typed text and keys, such as a GameWindowTextInputEvents. The UI doesn鈥檛 dispose it. |
AddAnimation() 馃爢
AddAnimation(BaseAnimation animation) 路 Starts updating an animation, which plays once it is started. Animation.Start adds the animation as well, so this is needed only for one you start later. Adding it again while it is updated, or adding null, does nothing. See animations.
| Parameter | Type | Description |
|---|---|---|
animation |
BaseAnimation |
The animation to update with the UI; it plays once it is started. |
AddElementToRoot() 馃爢
AddElementToRoot(BaseElement element) 路 Adds an element to the root.
| Parameter | Type | Description |
|---|---|---|
element |
BaseElement |
The element to add to the root. |
ApplyGameWindowSize() 馃爢
ApplyGameWindowSize(int width, int height) 路 Lays the UI out over a screen size in device pixels. A size of 0, such as a minimized window鈥檚, is ignored. With FollowsBackBuffer on, the size stays until the back buffer changes.
| Parameter | Type | Description |
|---|---|---|
width |
int |
The screen width, in device pixels. |
height |
int |
The screen height, in device pixels. |
Dispose() 馃爢
Dispose() 路 Disposes the root and forgets the shared state, so a new UI can be created.
Draw() 馃爢
Draw() 路 Draws the whole tree with the sprite batch, beginning and ending it itself.
ElementAt() 馃爢
ElementAt(Point position) 路 The element the mouse would be over at the position, by the rules the UI hovers by: the open context menu and drop-down first, then the tree from the top down (windows above their siblings, children by ZIndex); only visible elements that take the mouse and aren鈥檛 cropped away; while a modal window is shown, only its elements and the root around it. The root where nothing else takes the mouse, null outside of the screen. Nothing is hovered by it. It can be a control鈥檚 part, such as a list鈥檚 row or a slider鈥檚 thumb: walk up the Parents to the element you want. See finding the element at a point.
| Parameter | Type | Description |
|---|---|---|
position |
Point |
The position, in logical units (see Scale). |
GetElementByName() 馃爢
GetElementByName(string name) 路 Finds an element anywhere in the tree by the name given to its constructor, null if there is none.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The Name to look for. |
GetElementByName<T>(string name) 路 The same, null also when the element is not a T.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The Name to look for. |
RemoveAnimation() 馃爢
RemoveAnimation(BaseAnimation animation) 路 Stops updating an animation. It keeps its state, and adding it again continues it. Animation.Stop takes an animation out as well, and puts it back at its start.
| Parameter | Type | Description |
|---|---|---|
animation |
BaseAnimation |
The animation to stop updating. |
SetDefaultMouseCursorsSet() 馃爢
SetDefaultMouseCursorsSet(MouseCursorsSet mouseCursorsSet) 路 Sets the cursors every element uses unless it has its own, see mouse cursors.
| Parameter | Type | Description |
|---|---|---|
mouseCursorsSet |
MouseCursorsSet |
The cursors every element uses unless it has its own. |
Update() 馃爢
Update(GameTime gameTime) 路 Runs timers and animations, lays out what changed, and handles the mouse. Poll the input before it.
| Parameter | Type | Description |
|---|---|---|
gameTime |
GameTime |
The game鈥檚 time, from Game.Update. |