Skip to content

ControlBase.cs

Charles Humphrey edited this page Nov 16, 2017 · 3 revisions

RandomchaosMGUIBase.UIBaseClasses.ControlBase

This class is derived from DrawableGameComponent and implements the IHasTransform interface. It is the base classed used for all the UI elements.

Events

MouseOver OnMouseOverEvent

Caleed when the mouse pointer is over the control.

MouseEnter OnMouseEnterEvent

Fired when the mouse leaves the control.

MouseLeave OnMouseLeaveEvent

Is called when the mouse pointer leaves the bounds of the control.

MouseButtonDown OnMouseButtonDownEvent

Fired when over control and mouse button is down.

MouseClick OnMouseClickEvent

Is called when the mouse pointer is over the control, and the mouse is clicked.

GotFocus OnGotFocusEvent

Is called when the control has focus.

LostFocus OnLostFocusEvent

Is called when the control loses focus.

Public Properties

string BackgroundAsset

Used to load the texture to be used for the background.

Rectangle RenderSize

The size of the control eb be rendered.

Rectangle BoundsRectangle

This has be be the screen position of the control as it is used when detecting mouse intersects.

Rectangle ScissorRectangle

Scissor rectangle to stop control overflow.

Transform Transform

Transform used for position, scale and rotation..

Color BoundsColor

Color to render the bounds in when required..

Color BackgroundColor

Color to render the background in.

bool RenderBoundsRectnagle

Used to state if we want to render the bounds rectangle or not.

Vector2 BorderThickness

The thickness of the border we want to render, defaults to 1,1

Color BorderColor

Color of the border to be rendered.

bool HasFocus

Indicates if this control has focus...

bool IsMouseOver

Indicates if the mouse is over the current control.

Public Fields

List Children

List of the children to be rendered (if any).

Public Static Fields

ControlBase FocusControl

Public Methods

ControlBase(Game game, Rectangle sizeRect, string backgroundAsset = null)

This is the class constructor, when called various defaults are initialized.

void Initialize()

Initializes it's self and calls Initialize on any children it has.

void LoadContent()

Sets up it's internal SpriteBatch and default textures.

void Update(GameTime gameTime)

Update method manages event detection, and iterates through children calling their updates.

void Draw(GameTime gameTime)

Draws it's own back ground, then iterates through children calling their draw calls.

void SetFocus(object sender)

Sets the control as having focus.

void BringToFront()

Brings the control to to end of the draw order, so drawing it on top of all other elements.

void StartDraw(GameTime gameTime)

Used to set up the SpriteBatch draw call, setting scissor rectangles as needed.

void EndDraw(GameTime gameTime)

Ends draw call and puts the scissor rectangle back as it was in the graphics device.

void DrawBoundsRectangle()

Used for testing where the bounds rectangle is located.

void AddChild(ControlBase control)

Method to add a child control. If this HasInitialized it true, then children are initialized as added.

void RemoveChild(ControlBase control)

Removes child from Child list.

Clone this wiki locally