Created
February 16, 2015 21:28
-
-
Save Banane9/603fa2aa99b06b00f51d to your computer and use it in GitHub Desktop.
Notifying Point List for glinkis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
namespace Railmaker | |
{ | |
public delegate void ChangedEventHandler(PointList sender, Point item); | |
public class PointList : IList<Point> | |
{ | |
private List<Point> points = new List<Point>(); | |
public event ChangedEventHandler Changed; | |
public event ChangedEventHandler Added; | |
public event ChangedEventHandler Removed; | |
protected void OnChanged(Point item) | |
{ | |
if (Changed != null) | |
Changed(this, item); | |
} | |
protected void OnAdded(Point item) | |
{ | |
if (Added != null) | |
Added(this, item); | |
} | |
protected void OnRemoved(Point item) | |
{ | |
if (Removed != null) | |
Removed(this, item); | |
} | |
public IEnumerator<Point> GetEnumerator() | |
{ | |
return points.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return points.GetEnumerator(); | |
} | |
public void Add(Point item) | |
{ | |
item.Changed += OnChanged; | |
points.Add(item); | |
OnAdded(item); | |
} | |
public void Clear() | |
{ | |
points.Clear(); | |
OnChanged(); //I dunno.... | |
} | |
public bool Contains(Point item) | |
{ | |
return points.Contains(item); | |
} | |
public void CopyTo(Point[] array, int arrayIndex) | |
{ | |
points.CopyTo(array, arrayIndex); | |
} | |
public bool Remove(Point item) | |
{ | |
bool remove = points.Remove(item); | |
item.Changed -= OnChanged; | |
OnRemoved(item); | |
return remove; | |
} | |
public int Count | |
{ | |
get { return points.Count; } | |
} | |
public bool IsReadOnly { get; private set; } | |
public int IndexOf(Point item) | |
{ | |
return points.IndexOf(item); | |
} | |
public void Insert(int index, Point item) | |
{ | |
item.Changed += OnChanged; | |
points.Insert(index, item); | |
OnAdded(item); | |
} | |
public void RemoveAt(int index) | |
{ | |
var item = points[index]; | |
points.RemoveAt(index); | |
OnRemoved(item); | |
} | |
public Point this[int index] | |
{ | |
get { return points[index]; } | |
set | |
{ | |
points[index] = value; | |
OnChanged(value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment