// (c) 2003-2005 Datron, Inc. All rights reserved. http://www.blix.net
using System;
using System.Runtime.Serialization;
using System.Drawing;
using UITestingFramework;
namespace freeBlix
{
[Serializable]
public class DragColorSample: ISerializable, IColorCollection
{
#region Fields
private ColorCollection _Colors;
#endregion
#region DragColorSample(aControl, aOffscreen)
public DragColorSample(Control aControl, Bitmap aOffscreen)
{
#region Precondition
if (!(((IBounds) aControl).Bounds is Rectangle))
throw new Exception(GetType().FullName + String.Format(".RectangleColorSample(): {0}.Bounds is not a {1}", aControl.GetType().Name, typeof(Rectangle).Name));
#endregion
_Colors = new ColorCollection();
Rectangle bounds = (Rectangle)((IBounds)aControl).Bounds;
if ((bounds.Left >= 0) && (bounds.Top >= 0) && (bounds.Width >= 3) && (bounds.Height >= 3))
{
int left = bounds.Left;
int top = bounds.Top;
int right = bounds.Right - 1;
int bottom = bounds.Bottom - 1;
int height = bounds.Height - 1;
int width = bounds.Width - 1;
Color lColor = aOffscreen.GetPixel(left, top);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(right, top);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(right, bottom);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left, bottom);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left + 1, top + 1);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(right - 1, top + 1);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(right - 1, bottom - 1);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left + 1, bottom - 1);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left + 2, top + 2);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(right - 2, top + 2);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(right - 2, bottom - 2);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left + 2, bottom - 2);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left + width / 2, top);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left, top + height / 2);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(left + width / 2, bottom);
_Colors.Add(lColor);
lColor = aOffscreen.GetPixel(right, top + height / 2);
_Colors.Add(lColor);
}
}
#endregion
#region Colors
public ColorCollection Colors
{
get
{
return _Colors;
}
}
#endregion
#region IColorCollection
ColorCollection IColorCollection.Colors
{
get
{
return _Colors;
}
}
#endregion
#region ISerializable
protected DragColorSample(SerializationInfo aInfo, StreamingContext aContext)
{
_Colors = (ColorCollection) aInfo.GetValue("_Colors", typeof(ColorCollection));
}
public void GetObjectData(SerializationInfo aInfo, StreamingContext aContext)
{
aInfo.AddValue("_Colors", _Colors);
}
#endregion
}
}