TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.UI.ControlManager Class Reference

Control manager to manage various UI controls for a game. More...

Inheritance diagram for TriDevs.TriEngine.UI.ControlManager:
[legend]
Collaboration diagram for TriDevs.TriEngine.UI.ControlManager:
[legend]

Public Member Functions

 ControlManager ()
 Initializes a new instance of this control manager. More...
 
void Enable ()
 Enables this game component. More...
 
void Disable ()
 Disables this game component. More...
 
void Update ()
 Updates the object. More...
 
void Draw ()
 Draw the object to screen. More...
 
IControl AddControl (IControl control)
 Adds a new control to this control manager. More...
 
void RemoveControl (IControl control)
 Removes a control from this control manager. More...
 
void RemoveAllControls (Type type)
 Removes all controls of a specific type from this control manager. More...
 
void RemoveAllControls (Func< IControl, bool > func)
 Removes all controls matching the supplied predicate function. More...
 
bool HasControl (IControl control)
 Returns whether this control manager contains the specified control. More...
 
bool HasControl (Type type)
 Returns whether this control manager contains any control of the specified type. More...
 
bool HasControl (Func< IControl, bool > func)
 Returns whether this control manager contains any control matching the supplied predicate function. More...
 

Properties

bool Enabled [get, set]
 

Detailed Description

Control manager to manage various UI controls for a game.

Constructor & Destructor Documentation

TriDevs.TriEngine.UI.ControlManager.ControlManager ( )

Initializes a new instance of this control manager.

53  {
54  _controls = new List<IControl>();
55  }

Member Function Documentation

IControl TriDevs.TriEngine.UI.ControlManager.AddControl ( IControl  control)

Adds a new control to this control manager.

Parameters
controlThe control to add.
Returns
The control that was added.

Implements TriDevs.TriEngine.UI.IControlManager.

78  {
79  if (HasControl(control))
80  throw new InvalidOperationException("Cannot add a control more than once.");
81  control.Enable();
82  _controls.Add(control);
83  control.Show();
84  return control;
85  }

Here is the call graph for this function:

void TriDevs.TriEngine.UI.ControlManager.Disable ( )

Disables this game component.

Implements TriDevs.TriEngine.Interfaces.IGameComponent.

63  {
64  Enabled = false;
65  }
void TriDevs.TriEngine.UI.ControlManager.Draw ( )

Draw the object to screen.

Implements TriDevs.TriEngine.Interfaces.IDrawable.

73  {
74  _controls.ForEach(c => c.Draw());
75  }
void TriDevs.TriEngine.UI.ControlManager.Enable ( )

Enables this game component.

Implements TriDevs.TriEngine.Interfaces.IGameComponent.

58  {
59  Enabled = true;
60  }
bool TriDevs.TriEngine.UI.ControlManager.HasControl ( IControl  control)

Returns whether this control manager contains the specified control.

Parameters
controlThe control to check.
Returns
True if the specified control exists in this control manager, false otherwise.

Implements TriDevs.TriEngine.UI.IControlManager.

119  {
120  return HasControl(c => c == control);
121  }
bool TriDevs.TriEngine.UI.ControlManager.HasControl ( Type  type)

Returns whether this control manager contains any control of the specified type.

Parameters
typeThe type to check.
Returns
True if this control manager contains a control of the specified type, false otherwise.

Implements TriDevs.TriEngine.UI.IControlManager.

124  {
125  return HasControl(c => c.GetType() == type);
126  }
bool TriDevs.TriEngine.UI.ControlManager.HasControl ( Func< IControl, bool >  func)

Returns whether this control manager contains any control matching the supplied predicate function.

Parameters
funcThe predicate function.
Returns
True if this control manager contains a control matching the specified predicate, false otherwise.

Implements TriDevs.TriEngine.UI.IControlManager.

129  {
130  return _controls.Any(func);
131  }
void TriDevs.TriEngine.UI.ControlManager.RemoveAllControls ( Type  type)

Removes all controls of a specific type from this control manager.

Parameters
typeThe type of control to remove.

Implements TriDevs.TriEngine.UI.IControlManager.

100  {
101  RemoveAllControls(c => c.GetType() == type);
102  }
void TriDevs.TriEngine.UI.ControlManager.RemoveAllControls ( Func< IControl, bool >  func)

Removes all controls matching the supplied predicate function.

Parameters
funcThe predicate function to use.

Implements TriDevs.TriEngine.UI.IControlManager.

105  {
106  var toRemove = _controls.Where(func);
107  var controls = toRemove as IList<IControl> ?? toRemove.ToList();
108  if (controls.Count < 0)
109  return;
110  controls.ToList().ForEach(c =>
111  {
112  c.Hide();
113  c.Disable();
114  });
115  _controls.RemoveAll(c => func(c));
116  }
void TriDevs.TriEngine.UI.ControlManager.RemoveControl ( IControl  control)

Removes a control from this control manager.

Parameters
controlThe control to remove.

Implements TriDevs.TriEngine.UI.IControlManager.

88  {
89  if (!HasControl(control))
90  return;
91  var match = _controls.FirstOrDefault(c => c == control);
92  if (match == null)
93  return;
94  match.Hide();
95  match.Disable();
96  _controls.Remove(match);
97  }

Here is the call graph for this function:

void TriDevs.TriEngine.UI.ControlManager.Update ( )

Updates the object.

Implements TriDevs.TriEngine.Interfaces.IUpdatable.

68  {
69  _controls.ForEach(c => c.Update());
70  }

Property Documentation

bool TriDevs.TriEngine.UI.ControlManager.Enabled
getset

The documentation for this class was generated from the following file: