using System;
using System.Collections.Generic;
using Chernobyl.Collections.Generic.Event;
using Chernobyl.Event;
namespace Chernobyl.Interface.Input
{
///
/// An that represents multiple
/// instances (through the use of the composite design pattern).
///
public class PointerControlCollection : DecoratingEventCollection, IPointerControl, IEventCollection
{
///
/// Initializes a new instance of the class.
///
public PointerControlCollection()
: base(new List())
{
ItemsAdded += ControlsAdded;
ItemsRemoved += ControlsRemoved;
}
///
/// An event that is raised each time the control mechanism is pressed
/// down. This mechanism can only be once per
/// mechanism's pointer. The mechanism must raise
/// for a pointer prior to that pointer raising
/// again. For example, a mouse can only raise
/// once and then it must raise
/// to allow to be raised. A touch screen on
/// the other hand can invoke for each finger
/// that touches the screen but must invoke for each
/// finger.
///
public event EventHandler PressedDown;
///
/// An event that is raised each time the control mechanism is let up.
/// See for more information on this topic.
///
public event EventHandler LetUp;
///
/// An event handler that is invoked when
/// instances are removed from this.
///
/// The instance that generated the event.
/// The
/// instance containing the event data.
void ControlsAdded(object sender, ItemsEventArgs e)
{
foreach (IPointerControl control in e.Items)
{
control.PressedDown += ControlPressedDown;
control.LetUp += ControlLetUp;
}
}
///
/// An event handler that is invoked when
/// instances are removed from this.
///
/// The instance that generated the event.
/// The
/// instance containing the event data.
void ControlsRemoved(object sender, ItemsEventArgs e)
{
foreach (IPointerControl control in e.Items)
{
control.PressedDown -= ControlPressedDown;
control.LetUp -= ControlLetUp;
}
}
///
/// An event handler that is invoked when one of the
/// instances contained within this
/// instance raises its . This method
/// will raise the event of this
/// instance.
///
/// The instance that generated the event.
/// The instance
/// containing the event data.
void ControlLetUp(object sender, PointerEventArgs e)
{
if (LetUp != null)
LetUp(this, e);
}
///
/// An event handler that is invoked when one of the
/// instances contained within this
/// instance raises its . This
/// method will raise the event
/// of this instance.
///
/// The instance that generated the event.
/// The instance
/// containing the event data.
void ControlPressedDown(object sender, PointerEventArgs e)
{
if (PressedDown != null)
PressedDown(this, e);
}
}
}