using System;
using System.Collections;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing;
#if AdvTree
namespace DevComponents.Tree
#elif DOTNETBAR
namespace DevComponents.DotNetBar
#endif
{
///
/// Represents Collection for the BackgroundColorBlend objects.
///
public class BackgroundColorBlendCollection : CollectionBase
{
#region Private Variables
private ElementStyle m_Parent = null;
#endregion
#region Internal Implementation
/// Creates new instance of the class.
public BackgroundColorBlendCollection() {}
internal ElementStyle Parent
{
get { return m_Parent; }
set { m_Parent = value; }
}
///
/// Adds new object to the collection.
///
/// Object to add.
/// Index of newly added object.
public int Add(BackgroundColorBlend item)
{
return List.Add(item);
}
///
/// Adds array of new objects to the collection.
///
/// Array of object to add.
public void AddRange(BackgroundColorBlend[] items)
{
foreach (BackgroundColorBlend item in items)
this.Add(item);
}
///
/// Returns reference to the object in collection based on it's index.
///
public BackgroundColorBlend this[int index]
{
get {return (BackgroundColorBlend)(List[index]);}
set {List[index] = value;}
}
///
/// Inserts new object into the collection.
///
/// Position of the object.
/// Object to insert.
public void Insert(int index, BackgroundColorBlend value)
{
List.Insert(index, value);
}
///
/// Returns index of the object inside of the collection.
///
/// Reference to the object.
/// Index of the object.
public int IndexOf(BackgroundColorBlend value)
{
return List.IndexOf(value);
}
///
/// Returns whether collection contains specified object.
///
/// Object to look for.
/// true if object is part of the collection, otherwise false.
public bool Contains(BackgroundColorBlend value)
{
return List.Contains(value);
}
///
/// Removes specified object from the collection.
///
///
public void Remove(BackgroundColorBlend value)
{
List.Remove(value);
}
//protected override void OnRemoveComplete(int index,object value)
//{
// base.OnRemoveComplete(index,value);
// BackgroundColorBlend me=value as BackgroundColorBlend;
//}
//protected override void OnInsertComplete(int index,object value)
//{
// base.OnInsertComplete(index,value);
// BackgroundColorBlend me=value as BackgroundColorBlend;
//}
///
/// Copies collection into the specified array.
///
/// Array to copy collection to.
/// Starting index.
public void CopyTo(BackgroundColorBlend[] array, int index)
{
List.CopyTo(array, index);
}
///
/// Copies contained items to the BackgroundColorBlend array.
///
/// Array to copy to.
internal void CopyTo(BackgroundColorBlend[] array)
{
List.CopyTo(array,0);
}
///
/// Creates ColorBlend object based on the members of the collection. ColorBlend object will be valid only if all members of the collection
/// represents relative/percentage based color blends.
///
///
public ColorBlend GetColorBlend()
{
ColorBlend blend = new ColorBlend();
Color[] colors = new Color[this.Count];
float[] positions = new float[this.Count];
for(int i=0; i
/// Adds the BackgroundColorBlend objects from the collection.
///
/// Collection to copy objects from
public void CopyFrom(BackgroundColorBlendCollection col)
{
foreach (BackgroundColorBlend b in col)
this.Add(b);
}
internal eBackgroundColorBlendType GetBlendType()
{
BackgroundColorBlendCollection c = this;
if (c.Count == 1)
return eBackgroundColorBlendType.SolidColor;
if (c.Count <= 1)
return eBackgroundColorBlendType.Invalid;
eBackgroundColorBlendType t = eBackgroundColorBlendType.Invalid;
foreach (BackgroundColorBlend b in c)
{
if (b.Position == 0 || b.Position == 1f)
continue;
if (b.Position <= 1f)
{
if (t == eBackgroundColorBlendType.Invalid)
t = eBackgroundColorBlendType.Relative;
else if (t == eBackgroundColorBlendType.Absolute)
{
t = eBackgroundColorBlendType.Invalid;
break;
}
}
else
{
if (t == eBackgroundColorBlendType.Invalid)
t = eBackgroundColorBlendType.Absolute;
else if (t == eBackgroundColorBlendType.Relative)
{
t = eBackgroundColorBlendType.Invalid;
break;
}
}
}
if (c.Count == 2 && c[0].Position == 0f && c[1].Position == 1f)
return eBackgroundColorBlendType.Relative;
if (t == eBackgroundColorBlendType.Invalid)
return t;
if (t == eBackgroundColorBlendType.Relative && c[0].Position != 0f && c[c.Count - 1].Position != 1f)
return eBackgroundColorBlendType.Invalid;
else if (t == eBackgroundColorBlendType.Absolute && ((c.Count / 2) * 2 != c.Count))
return eBackgroundColorBlendType.Invalid;
return t;
}
///
/// Initializes the collection with the two color blend.
///
/// Collection to initialize.
/// Start color.
/// End color.
public static void InitializeCollection(BackgroundColorBlendCollection collection, int backColor1, int backColor2)
{
InitializeCollection(collection, ColorScheme.GetColor(backColor1), ColorScheme.GetColor(backColor2));
}
///
/// Initializes the collection with the two color blend.
///
/// Collection to initialize.
/// Start color.
/// End color.
public static void InitializeCollection(BackgroundColorBlendCollection collection, Color backColor1, Color backColor2)
{
collection.Clear();
collection.Add(new BackgroundColorBlend(backColor1, 0f));
collection.Add(new BackgroundColorBlend(backColor2, 1f));
}
///
/// Initializes the collection with the two color blend.
///
/// Collection to initialize.
/// Solid Color
public static void InitializeCollection(BackgroundColorBlendCollection collection, Color backColor)
{
collection.Clear();
collection.Add(new BackgroundColorBlend(backColor, 0f));
}
#endregion
}
internal enum eBackgroundColorBlendType
{
Invalid,
Relative,
Absolute,
SolidColor
}
}