Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #191 from 3vi1/monogame-sdl2
Browse files Browse the repository at this point in the history
FNA Cleanup: GameComponent - GraphicsDeviceManager
  • Loading branch information
flibitijibibo committed Apr 6, 2014
2 parents c0f2742 + 6a6cc67 commit 37ba458
Show file tree
Hide file tree
Showing 9 changed files with 1,153 additions and 1,001 deletions.
2 changes: 1 addition & 1 deletion MonoGame.Framework/GameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#endregion

namespace Microsoft.Xna.Framework
{
{
public class GameComponent : IGameComponent, IUpdateable, IComparable<GameComponent>, IDisposable
{
#region Public Properties
Expand Down
144 changes: 73 additions & 71 deletions MonoGame.Framework/GameComponentCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,76 +14,78 @@

namespace Microsoft.Xna.Framework
{
public sealed class GameComponentCollection : Collection<IGameComponent>
{
#region Events

public event EventHandler<GameComponentCollectionEventArgs> ComponentAdded;

public event EventHandler<GameComponentCollectionEventArgs> ComponentRemoved;

#endregion

#region Protected Methods

protected override void ClearItems()
{
for (int i = 0; i < base.Count; i++)
{
this.OnComponentRemoved(new GameComponentCollectionEventArgs(base[i]));
}
base.ClearItems();
}

protected override void InsertItem(int index, IGameComponent item)
{
if (base.IndexOf(item) != -1)
{
throw new ArgumentException("Cannot Add Same Component Multiple Times");
}
base.InsertItem(index, item);
if (item != null)
{
this.OnComponentAdded(new GameComponentCollectionEventArgs(item));
}
}

protected override void RemoveItem(int index)
{
IGameComponent gameComponent = base[index];
base.RemoveItem(index);
if (gameComponent != null)
{
this.OnComponentRemoved(new GameComponentCollectionEventArgs(gameComponent));
}
}

protected override void SetItem(int index, IGameComponent item)
{
throw new NotSupportedException();
}

#endregion

#region Private Methods

private void OnComponentAdded(GameComponentCollectionEventArgs eventArgs)
{
if (this.ComponentAdded != null)
{
this.ComponentAdded(this, eventArgs);
}
}

private void OnComponentRemoved(GameComponentCollectionEventArgs eventArgs)
{
if (this.ComponentRemoved != null)
{
this.ComponentRemoved(this, eventArgs);
}
}

#endregion
}
public sealed class GameComponentCollection : Collection<IGameComponent>
{
#region Events

public event EventHandler<GameComponentCollectionEventArgs> ComponentAdded;

public event EventHandler<GameComponentCollectionEventArgs> ComponentRemoved;

#endregion

#region Protected Methods

protected override void ClearItems()
{
for (int i = 0; i < base.Count; i += 1)
{
this.OnComponentRemoved(new GameComponentCollectionEventArgs(base[i]));
}
base.ClearItems();
}

protected override void InsertItem(int index, IGameComponent item)
{
if (base.IndexOf(item) != -1)
{
throw new ArgumentException("Cannot Add Same Component Multiple Times");
}
base.InsertItem(index, item);
if (item != null)
{
this.OnComponentAdded(new GameComponentCollectionEventArgs(item));
}
}

protected override void RemoveItem(int index)
{
IGameComponent gameComponent = base[index];
base.RemoveItem(index);
if (gameComponent != null)
{
this.OnComponentRemoved(
new GameComponentCollectionEventArgs(gameComponent)
);
}
}

protected override void SetItem(int index, IGameComponent item)
{
throw new NotSupportedException();
}

#endregion

#region Private Methods

private void OnComponentAdded(GameComponentCollectionEventArgs eventArgs)
{
if (this.ComponentAdded != null)
{
this.ComponentAdded(this, eventArgs);
}
}

private void OnComponentRemoved(GameComponentCollectionEventArgs eventArgs)
{
if (this.ComponentRemoved != null)
{
this.ComponentRemoved(this, eventArgs);
}
}

#endregion
}
}

42 changes: 21 additions & 21 deletions MonoGame.Framework/GameComponentCollectionEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@

namespace Microsoft.Xna.Framework
{
public class GameComponentCollectionEventArgs : EventArgs
{
#region Public Properties
public class GameComponentCollectionEventArgs : EventArgs
{
#region Public Properties

public IGameComponent GameComponent
{
get
{
return _gameComponent;
}
}
public IGameComponent GameComponent
{
get
{
return _gameComponent;
}
}

#endregion
#endregion

#region Private Variables
#region Private Variables

private IGameComponent _gameComponent;
private IGameComponent _gameComponent;

#endregion
#endregion

#region Public Constructors
#region Public Constructors

public GameComponentCollectionEventArgs(IGameComponent gameComponent)
{
_gameComponent = gameComponent;
}
public GameComponentCollectionEventArgs(IGameComponent gameComponent)
{
_gameComponent = gameComponent;
}

#endregion
}
#endregion
}
}

Loading

0 comments on commit 37ba458

Please sign in to comment.