using System; using System.Collections.Generic; using Chernobyl.Collections.Generic.Event; using Chernobyl.Event; using Chernobyl.Mathematics; using Chernobyl.Mathematics.Mechanics; using Chernobyl.Mathematics.Movement; using Chernobyl.Mathematics.Vectors; using Chernobyl.Update; using Chernobyl.Values; namespace Chernobyl.Input.Controls.Axis { /// /// A helper class that allows for easy creation of /// classes. /// public class Axis2DControl : MatrixTransform, IAxis2DControl { /// /// Constructor. /// /// The services class that contains the /// dependencies that are to be injected into this object. public Axis2DControl(IEventCollection services) : this(services, new List()) { } /// /// Constructor. /// /// The services class that contains the /// dependencies that are to be injected into this object. /// The list to use to hold the children /// controls. public Axis2DControl(IEventCollection services, ICollection controlChildren) { ControlChildren = controlChildren; UpdateableChildren = new List(); } /// /// The X axis of the 2 dimensions of this control. /// public virtual IAxisControl X { get; protected set; } /// /// The Y axis of the 2 dimensions of this control. /// public virtual IAxisControl Y { get; protected set; } /// /// The (X, Y) position of the IAxis2D. /// public Vector2 Xy { get { return new Vector2(X.CurrentValue, Y.CurrentValue); } } /// /// Invoked when this control moves in either the /// X, Y, or both directions. /// public event EventHandler> OnMove; /// /// Updates this IUpdateable object and it's children /// if the updateable feels it's necessary. /// /// The amount of time that has /// passed since this update was last called. public virtual void Update(TimeSpan deltaTime) { if (X.CurrentValue != X.PreviousValue || Y.CurrentValue != Y.PreviousValue) { IsUpdateNeeded = true; if (OnMove != null) OnMove(this, new EventArgs(this)); } foreach (IUpdateable child in UpdateableChildren) child.Update(deltaTime); } /// /// This method is invoked during the update of the /// right before the /// is actually updated. This /// method keeps the position of this instance up to date. /// /// The value of the . /// It is stored in a so that the calculation can be /// avoided if necessary. Don't call unless /// required. protected override void PreUpdate(Values.LazyValue world) { base.PreUpdate(world); Matrix4 local = LocalMatrix; local.Row3 = new Vector4(Xy.X, Xy.Y, local.Row3.Z, local.Row3.W); SetTransformation(ref local); } /// /// The parent of this control. /// public IControl ControlParent { get; set; } /// /// The children of this control /// public ICollection ControlChildren { get; protected set; } /// /// An event that is raised when this is /// disconnected from the device it was previously connected to and is /// no longer available for use. Actions performed on the /// after it has been disconnected may result /// is an being thrown. /// public event EventHandler Disconnected { add { DisconnectedMethod += value; } remove { DisconnectedMethod -= value; } } /// /// The parent of this IUpdateable or null if this IUpdateable does not /// have a parent. /// public IUpdateable UpdateableParent { get; set; } /// /// Holds a collection of children that should be updated when this /// decides they should be updated. /// public ICollection UpdateableChildren { get; private set; } /// /// The method that acts as the backing property to /// . Use this method if you wish to raise the /// event. /// protected EventHandler DisconnectedMethod { get; private set; } /// /// The X axis of the 2 dimensions of this mechanism. /// IAxis IAxis2D.X { get { return X; } } /// /// The Y axis of the 2 dimensions of this mechanism. /// IAxis IAxis2D.Y { get { return Y; } } } }