|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Runtime.Serialization;
using System.Collections;
using BizDraw.Core;
namespace BizDraw.Objects
{
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable()]
public class GraphicsList : List<DrawObject>
{
public GraphicsList()
{
}
#region Collection Methods
public new void Add(DrawObject item)
{
PrepareObject(item);
base.Insert (0, item);
}
internal void PrepareObject(DrawObject item)
{
item.Parent = this;
item.SelectChanged += new EventHandler(item_SelectChanged);
}
void item_SelectChanged(object sender, EventArgs e)
{
OnSelectedObjectChanged(sender, e);
}
public new void Insert(int index, DrawObject item)
{
PrepareObject(item);
base.Insert(index, item);
}
#endregion
#region Non Collection Properties
[NonSerialized()]
internal Document parentDocument;
/// <summary>
/// SelectedCount and GetSelectedObject allow to read
/// selected objects in the loop
/// </summary>
public int SelectionCount
{
get
{
int n = 0;
foreach (DrawObject o in this)
{
if (o.Selected)
n++;
}
return n;
}
}
#endregion
#region Non Collection Methods
public void Draw(Graphics g)
{
int n = this.Count;
DrawObject o;
// Enumerate list in reverse order
// to get first object on the top
for (int i = n - 1; i >= 0; i--)
{
o = this[i];
o.Draw(g);
if (o.Selected == true)
{
o.DrawTracker(g);
}
}
}
public DrawObject GetSelectedObject(int index)
{
int n = -1;
foreach (DrawObject o in this)
{
if (o.Selected)
{
n++;
if (n == index)
return o;
}
}
return null;
}
public void SelectInRectangle(Rectangle rectangle)
{
UnselectAll();
foreach (DrawObject o in this)
{
if (o.IntersectsWith(rectangle))
o.SetSelectedState(true);
}
}
public void UnselectAll()
{
foreach (DrawObject o in this)
{
o.SetSelectedState(false);
}
}
public void SelectAll()
{
foreach (DrawObject o in this)
{
o.SetSelectedState(true);
}
}
internal void SetDirty()
{
}
#endregion
#region events
public event EventHandler SelectedObjectChanged;
protected void OnSelectedObjectChanged(object sender, EventArgs e)
{
if (SelectedObjectChanged != null)
SelectedObjectChanged(sender, e);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here