C# Class FSO.Client.UI.Framework.UIElement

Base class for all UIElements. This class has all the common stuff that user interface components have. This includes: X,Y, ScaleX, ScaleY, Visible, Parent etc. The UIElement has its own coordinate space. You can imagine that when you draw a texture inside a UIElement you are drawing it at 0,0 within the UIElement. This is then translated by the engine to screen coordinates.
Inheritance: IDepthProvider
Mostra file Open project: RHY3756547/FreeSO Class Usage Examples

Public Properties

Property Type Description
MASK_COLORS uint[]
Visible bool

Protected Properties

Property Type Description
_BlendColor Color
_HasOpacity bool
_Mtx float[]
_MtxDirty bool
_Opacity float
_OpacityDirty bool
_Parent UIContainer
_Scale Vector2
_ScaleParent Vector2
_ScaleX float
_ScaleY float
_Tooltip string
_X float
_Y float
m_StringID string

Private Properties

Property Type Description

Public Methods

Method Description
AddUpdateHook ( UpdateHookDelegate hook ) : void

Adds a callback that will be executed every update loop.

Async ( AsyncHandler handler ) : void

Little utility to make it easier to do work outside of the UI thread

Draw ( FSO.Client.UI.Framework.UISpriteBatch batch ) : void

Basic draw method. Your component should implement this and add any drawing behavior it needs.

DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style ) : void

This utility will draw a line of text onto the UIElement.

DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align ) : void

This utility will draw a line of text onto the UIElement.

DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin ) : void

This utility will draw a line of text onto the UIElement.

DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state ) : void

This utility will draw a line of text onto the UIElement.

DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Nullable from, Vector2 to, Vector2 scale ) : void

Draws a texture to the UIElement. This method will deal with the matrix calculations

DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Nullable from, Vector2 to, Vector2 scale, Color blend ) : void

Draws a texture to the UIElement. This method will deal with the matrix calculations

DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Rectangle from, Vector2 to ) : void

Draws a texture to the UIElement. This method will deal with the matrix calculations

DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Vector2 to ) : void

Draws a texture to the UIElement. This method will deal with the matrix calculations

DrawTiledTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Rectangle dest, Color blend ) : void
FlooredLocalPoint ( Vector2 point ) : Vector2
GetBounds ( ) : Rectangle

Gets the bounding box for the component

GetMousePosition ( Microsoft.Xna.Framework.Input.MouseState mouse ) : Vector2

Gets the local mouse coordinates for the given mouse state

GetTexture ( ContentID id ) : Microsoft.Xna.Framework.Graphics.Texture2D
GetTexture ( ulong id ) : Microsoft.Xna.Framework.Graphics.Texture2D
GlobalPoint ( Vector2 globalPoint ) : Vector2

Converts a point relative to the screen into a point relative to this component

HitTestArea ( UpdateState state, Rectangle area, bool cache ) : bool

Returns true if the mouse is over the given area

InvalidateMatrix ( ) : void

Utility to force the component to recalculate its matrix

InvalidateOpacity ( ) : void

Utility to force the component to recalculate its blend colour

ListenForMouse ( Rectangle region, UIMouseEvent callback ) : UIMouseEventRef
LocalPoint ( Vector2 point ) : Vector2

Converts a point relative to this UIElement into a point relative to the screen

LocalPoint ( float x, float y ) : Vector2

Converts a point relative to this UIElement into a point relative to the screen

LocalRect ( float x, float y, float w, float h ) : Rectangle

Converts a rectangle relative to this UIElement into a rectangle relative to the screen.

LocalRect ( float x, float y, float w, float h, float mtx ) : Rectangle

Converts a rectangle relative to this UIElement into a rectangle relative to the screen.

PreDraw ( FSO.Client.UI.Framework.UISpriteBatch batch ) : void

May be removed - Called before the draw method.

RemoveMouseListener ( UIMouseEventRef item ) : void
RemoveUpdateHook ( UpdateHookDelegate hook ) : void

Removes a previously added update hook.

StoreTexture ( ulong id, ContentResource assetData ) : Microsoft.Xna.Framework.Graphics.Texture2D
StoreTexture ( ulong id, ContentResource assetData, bool mask, bool cacheOnDisk ) : Microsoft.Xna.Framework.Graphics.Texture2D
ToString ( ) : string
Update ( UpdateState state ) : void

Standard UIElement update method. All sub-classes should call this super method. The argument is an UpdateState object, this object contains everything you may need during update including GameTime, MouseState, KeyboardState etc. This is useful because it means we dont ask for Mouse & Keyboard state in every UIElement which would be wasteful

WillDraw ( ) : bool

Scans through parents to determine if this element will be drawn.

Protected Methods

Method Description
CalculateMatrix ( ) : void

Calculate a matrix which represents this objects position in screen space

CalculateOpacity ( ) : void

When the opacity changes this method is used to calculate the blend colour.

ManualTextureMask ( Microsoft.Xna.Framework.Graphics.Texture2D &Texture, Color ColorFrom ) : void

Manually replaces a specified color in a texture with transparent black, thereby masking it.

Method Details

AddUpdateHook() public method

Adds a callback that will be executed every update loop.
public AddUpdateHook ( UpdateHookDelegate hook ) : void
hook UpdateHookDelegate
return void

Async() public method

Little utility to make it easier to do work outside of the UI thread
public Async ( AsyncHandler handler ) : void
handler AsyncHandler
return void

CalculateMatrix() protected method

Calculate a matrix which represents this objects position in screen space
protected CalculateMatrix ( ) : void
return void

CalculateOpacity() protected method

When the opacity changes this method is used to calculate the blend colour.
protected CalculateOpacity ( ) : void
return void

Draw() public abstract method

Basic draw method. Your component should implement this and add any drawing behavior it needs.
public abstract Draw ( FSO.Client.UI.Framework.UISpriteBatch batch ) : void
batch FSO.Client.UI.Framework.UISpriteBatch
return void

DrawLocalString() public method

This utility will draw a line of text onto the UIElement.
public DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch The SpriteBatch to draw the text onto
text string The content of the text
to Vector2 The position of the text. Relative to this UIElement.
style TextStyle The text style
return void

DrawLocalString() public method

This utility will draw a line of text onto the UIElement.
public DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch The SpriteBatch to draw the text onto
text string The content of the text
to Vector2 The position of the text. Relative to this UIElement.
style TextStyle The text style
bounds Microsoft.Xna.Framework.Rectangle Rectangle relative to this UIElement which the text should be positioned within
align TextAlignment Alignment of the text within the bounds box.
return void

DrawLocalString() public method

This utility will draw a line of text onto the UIElement.
public DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch The SpriteBatch to draw the text onto
text string The content of the text
to Vector2 The position of the text. Relative to this UIElement.
style TextStyle The text style
bounds Microsoft.Xna.Framework.Rectangle Rectangle relative to this UIElement which the text should be positioned within
align TextAlignment Alignment of the text within the bounds box.
margin Microsoft.Xna.Framework.Rectangle Margin offset from the bounding box.
return void

DrawLocalString() public method

This utility will draw a line of text onto the UIElement.
public DrawLocalString ( SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch The SpriteBatch to draw the text onto
text string The content of the text
to Vector2 The position of the text. Relative to this UIElement.
style TextStyle The text style
bounds Microsoft.Xna.Framework.Rectangle Rectangle relative to this UIElement which the text should be positioned within
align TextAlignment Alignment of the text within the bounds box.
margin Microsoft.Xna.Framework.Rectangle Margin offset from the bounding box.
state UIElementState State of the text, e.g. hover, down, normal
return void

DrawLocalTexture() public method

Draws a texture to the UIElement. This method will deal with the matrix calculations
public DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Nullable from, Vector2 to, Vector2 scale ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch
texture Microsoft.Xna.Framework.Graphics.Texture2D
from Nullable
to Vector2
scale Vector2
return void

DrawLocalTexture() public method

Draws a texture to the UIElement. This method will deal with the matrix calculations
public DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Nullable from, Vector2 to, Vector2 scale, Color blend ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch
texture Microsoft.Xna.Framework.Graphics.Texture2D
from Nullable
to Vector2
scale Vector2
blend Color
return void

DrawLocalTexture() public method

Draws a texture to the UIElement. This method will deal with the matrix calculations
public DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Rectangle from, Vector2 to ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch
texture Microsoft.Xna.Framework.Graphics.Texture2D
from Microsoft.Xna.Framework.Rectangle
to Vector2
return void

DrawLocalTexture() public method

Draws a texture to the UIElement. This method will deal with the matrix calculations
public DrawLocalTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Vector2 to ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch
texture Microsoft.Xna.Framework.Graphics.Texture2D
to Vector2
return void

DrawTiledTexture() public method

public DrawTiledTexture ( SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Rectangle dest, Color blend ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch
texture Microsoft.Xna.Framework.Graphics.Texture2D
dest Microsoft.Xna.Framework.Rectangle
blend Color
return void

FlooredLocalPoint() public method

public FlooredLocalPoint ( Vector2 point ) : Vector2
point Vector2
return Vector2

GetBounds() public method

Gets the bounding box for the component
public GetBounds ( ) : Rectangle
return Microsoft.Xna.Framework.Rectangle

GetMousePosition() public method

Gets the local mouse coordinates for the given mouse state
public GetMousePosition ( Microsoft.Xna.Framework.Input.MouseState mouse ) : Vector2
mouse Microsoft.Xna.Framework.Input.MouseState
return Vector2

GetTexture() public static method

public static GetTexture ( ContentID id ) : Microsoft.Xna.Framework.Graphics.Texture2D
id FSO.Common.Content.ContentID
return Microsoft.Xna.Framework.Graphics.Texture2D

GetTexture() public static method

public static GetTexture ( ulong id ) : Microsoft.Xna.Framework.Graphics.Texture2D
id ulong
return Microsoft.Xna.Framework.Graphics.Texture2D

GlobalPoint() public method

Converts a point relative to the screen into a point relative to this component
public GlobalPoint ( Vector2 globalPoint ) : Vector2
globalPoint Vector2
return Vector2

HitTestArea() public method

Returns true if the mouse is over the given area
public HitTestArea ( UpdateState state, Rectangle area, bool cache ) : bool
state FSO.Common.Rendering.Framework.Model.UpdateState
area Microsoft.Xna.Framework.Rectangle
cache bool
return bool

InvalidateMatrix() public method

Utility to force the component to recalculate its matrix
public InvalidateMatrix ( ) : void
return void

InvalidateOpacity() public method

Utility to force the component to recalculate its blend colour
public InvalidateOpacity ( ) : void
return void

ListenForMouse() public method

public ListenForMouse ( Rectangle region, UIMouseEvent callback ) : UIMouseEventRef
region Microsoft.Xna.Framework.Rectangle
callback UIMouseEvent
return FSO.Common.Rendering.Framework.IO.UIMouseEventRef

LocalPoint() public method

Converts a point relative to this UIElement into a point relative to the screen
public LocalPoint ( Vector2 point ) : Vector2
point Vector2
return Vector2

LocalPoint() public method

Converts a point relative to this UIElement into a point relative to the screen
public LocalPoint ( float x, float y ) : Vector2
x float
y float
return Vector2

LocalRect() public method

Converts a rectangle relative to this UIElement into a rectangle relative to the screen.
public LocalRect ( float x, float y, float w, float h ) : Rectangle
x float
y float
w float
h float
return Microsoft.Xna.Framework.Rectangle

LocalRect() public method

Converts a rectangle relative to this UIElement into a rectangle relative to the screen.
public LocalRect ( float x, float y, float w, float h, float mtx ) : Rectangle
x float
y float
w float
h float
mtx float
return Microsoft.Xna.Framework.Rectangle

ManualTextureMask() protected method

Manually replaces a specified color in a texture with transparent black, thereby masking it.
protected ManualTextureMask ( Microsoft.Xna.Framework.Graphics.Texture2D &Texture, Color ColorFrom ) : void
Texture Microsoft.Xna.Framework.Graphics.Texture2D The texture on which to apply the mask.
ColorFrom Color The color to mask away.
return void

PreDraw() public method

May be removed - Called before the draw method.
public PreDraw ( FSO.Client.UI.Framework.UISpriteBatch batch ) : void
batch FSO.Client.UI.Framework.UISpriteBatch
return void

RemoveMouseListener() public method

public RemoveMouseListener ( UIMouseEventRef item ) : void
item FSO.Common.Rendering.Framework.IO.UIMouseEventRef
return void

RemoveUpdateHook() public method

Removes a previously added update hook.
public RemoveUpdateHook ( UpdateHookDelegate hook ) : void
hook UpdateHookDelegate
return void

StoreTexture() public static method

public static StoreTexture ( ulong id, ContentResource assetData ) : Microsoft.Xna.Framework.Graphics.Texture2D
id ulong
assetData FSO.Client.GameContent.ContentResource
return Microsoft.Xna.Framework.Graphics.Texture2D

StoreTexture() public static method

public static StoreTexture ( ulong id, ContentResource assetData, bool mask, bool cacheOnDisk ) : Microsoft.Xna.Framework.Graphics.Texture2D
id ulong
assetData FSO.Client.GameContent.ContentResource
mask bool
cacheOnDisk bool
return Microsoft.Xna.Framework.Graphics.Texture2D

ToString() public method

public ToString ( ) : string
return string

Update() public method

Standard UIElement update method. All sub-classes should call this super method. The argument is an UpdateState object, this object contains everything you may need during update including GameTime, MouseState, KeyboardState etc. This is useful because it means we dont ask for Mouse & Keyboard state in every UIElement which would be wasteful
public Update ( UpdateState state ) : void
state FSO.Common.Rendering.Framework.Model.UpdateState
return void

WillDraw() public method

Scans through parents to determine if this element will be drawn.
public WillDraw ( ) : bool
return bool

Property Details

MASK_COLORS public_oe static_oe property

public static uint[] MASK_COLORS
return uint[]

Visible public_oe property

Indicates if the component is visible or not. If false the UIElement should not draw. This must be implemented in the super class. UIElement does nothing with this variable.
public bool Visible
return bool

_BlendColor protected_oe property

When the opacity changes this color will be changed into a representation of the opacity that can be used when calling the draw texture methods.
protected Color _BlendColor
return Color

_HasOpacity protected_oe property

Boolean which indicates if the opacity is not 1.0. This is here as a utility because its faster to compare a boolean than to compare a float (_Opacity != 1.0f)
protected bool _HasOpacity
return bool

_Mtx protected_oe property

Matrix object which represents the position & scale of this UIElement. Whenever X, Y, ScaleX, ScaleY, Parent (or any of these values on my parent) change We recalculate this matrix. It is used to convert local coordinates into absolute screen coordinates for drawing.
protected float[] _Mtx
return float[]

_MtxDirty protected_oe property

Indicates if something has changed to make the Matrix invalid, e.g. X,Y has changed or the component is now inside a different parent object. Also called when the parent decides its dirty.
protected bool _MtxDirty
return bool

_Opacity protected_oe property

Transparency value for this UIElement. Can be between 0.0 and 1.0
protected float _Opacity
return float

_OpacityDirty protected_oe property

Indicates if the opacity has changed and we have not recauclated the blend colour
protected bool _OpacityDirty
return bool

_Parent protected_oe property

The container which this element is a child of. Can be null if top level UI object. UIContainer sets this in its Add method. Helps describe the UI Tree.
protected UIContainer,FSO.Client.UI.Framework _Parent
return UIContainer

_Scale protected_oe property

This is the absolute scale of this UIElement, Aka it is all the parent scales multiplied together finally multiplied by this UIElement's scale. Essentially, this is the scale value you would pass into a texture draw method. It is relative to the screen
protected Vector2 _Scale
return Vector2

_ScaleParent protected_oe property

This is the absolute scale of this UIElement, Aka it is all the parent scales multiplied together. This is used for some specific calculations.
protected Vector2 _ScaleParent
return Vector2

_ScaleX protected_oe property

Scale Factor of the X Axis.
protected float _ScaleX
return float

_ScaleY protected_oe property

Scale Factor of the Y Axis.
protected float _ScaleY
return float

_Tooltip protected_oe property

Tooltip of this UIComponent. This is displayed when the mouse is moved over the control.
protected string _Tooltip
return string

_X protected_oe property

X position of this UIComponent. This coordinate is relative to this UIElement's parent component.
protected float _X
return float

_Y protected_oe property

Y position of this UIComponent. This coordinate is relative to this UIElement's parent component.
protected float _Y
return float

m_StringID protected_oe property

ID of the element, this is not used by any functional code. It is only used in the debug UI Inspector to help you identify which component you are looking at.
protected string m_StringID
return string