anx.framework/ANX.Framework/GameComponentCollection.cs

81 lines
2.3 KiB
C#
Raw Normal View History

#region Using Statements
2011-10-31 05:36:24 +00:00
using System;
using System.Collections.ObjectModel;
using ANX.Framework.NonXNA.Development;
2011-10-31 05:36:24 +00:00
#endregion // Using Statements
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
2011-10-31 05:36:24 +00:00
namespace ANX.Framework
{
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
[Developer("Glatzemann")]
2011-10-31 05:36:24 +00:00
public sealed class GameComponentCollection : Collection<IGameComponent>
{
#region Events
2011-10-31 05:36:24 +00:00
public event EventHandler<GameComponentCollectionEventArgs> ComponentAdded;
public event EventHandler<GameComponentCollectionEventArgs> ComponentRemoved;
#endregion
2011-10-31 05:36:24 +00:00
public GameComponentCollection()
{
// nothing to do here
2011-10-31 05:36:24 +00:00
}
protected override void ClearItems()
{
for (int i = 0; i < base.Count; i++)
{
OnComponentRemoved(base[i]);
}
base.Clear();
2011-10-31 05:36:24 +00:00
}
protected override void InsertItem(int index, IGameComponent item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
base.Insert(index, item);
OnComponentAdded(item);
2011-10-31 05:36:24 +00:00
}
protected override void RemoveItem(int index)
2011-10-31 05:36:24 +00:00
{
IGameComponent component = base[index];
base.Remove(component);
OnComponentRemoved(component);
2011-10-31 05:36:24 +00:00
}
protected override void SetItem(int index, IGameComponent item)
2011-10-31 05:36:24 +00:00
{
base[index] = item;
OnComponentAdded(item);
2011-10-31 05:36:24 +00:00
}
private void OnComponentAdded(IGameComponent component)
2011-10-31 05:36:24 +00:00
{
if (ComponentAdded != null)
{
ComponentAdded(this, new GameComponentCollectionEventArgs(component));
}
2011-10-31 05:36:24 +00:00
}
private void OnComponentRemoved(IGameComponent component)
2011-10-31 05:36:24 +00:00
{
if (ComponentRemoved != null)
{
ComponentRemoved(this, new GameComponentCollectionEventArgs(component));
}
2011-10-31 05:36:24 +00:00
}
}
}