DotNet 4.8.1 build of DotNetBar
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DevComponents.Instrumentation.Primitives
|
||||
{
|
||||
public class ColorFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts hex string to Color type.
|
||||
/// </summary>
|
||||
/// <param name="rgbHex">Hexadecimal color representation.</param>
|
||||
/// <returns>Reference to Color object.</returns>
|
||||
public static Color GetColor(string rgbHex)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rgbHex) == false)
|
||||
{
|
||||
if (rgbHex.Length == 8)
|
||||
{
|
||||
return (Color.FromArgb(Convert.ToInt32(rgbHex.Substring(0, 2), 16),
|
||||
Convert.ToInt32(rgbHex.Substring(2, 2), 16),
|
||||
Convert.ToInt32(rgbHex.Substring(4, 2), 16),
|
||||
Convert.ToInt32(rgbHex.Substring(6, 2), 16)));
|
||||
}
|
||||
|
||||
return (Color.FromArgb(Convert.ToInt32(rgbHex.Substring(0, 2), 16),
|
||||
Convert.ToInt32(rgbHex.Substring(2, 2), 16),
|
||||
Convert.ToInt32(rgbHex.Substring(4, 2), 16)));
|
||||
}
|
||||
|
||||
return Color.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts hex string to Color type.
|
||||
/// </summary>
|
||||
/// <param name="rgb">Color representation as 32-bit RGB value.</param>
|
||||
/// <returns>Reference to Color object.</returns>
|
||||
public static Color GetColor(int rgb)
|
||||
{
|
||||
return ((rgb == -1) ? Color.Empty :
|
||||
Color.FromArgb((rgb & 0xFF0000) >> 16, (rgb & 0xFF00) >> 8, rgb & 0xFF));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts hex string to Color type.
|
||||
/// </summary>
|
||||
/// <param name="alpha"></param>
|
||||
/// <param name="rgb">Color representation as 32-bit RGB value.</param>
|
||||
/// <returns>Reference to Color object.</returns>
|
||||
public static Color GetColor(int alpha, int rgb)
|
||||
{
|
||||
return ((rgb == -1) ? Color.Empty :
|
||||
Color.FromArgb(alpha, (rgb & 0xFF0000) >> 16, (rgb & 0xFF00) >> 8, rgb & 0xFF));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace DevComponents.Instrumentation.Primitives
|
||||
{
|
||||
public class BaseCollection<T> : Collection<T> where T : class, ICloneable, new()
|
||||
{
|
||||
#region Events
|
||||
|
||||
public event EventHandler<EventArgs> CollectionChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private variables
|
||||
|
||||
private bool _IsRangeSet;
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddRange
|
||||
|
||||
/// <summary>
|
||||
/// Adds a range of items to the collection
|
||||
/// </summary>
|
||||
/// <param name="items">Array of items to add</param>
|
||||
public void AddRange(T[] items)
|
||||
{
|
||||
try
|
||||
{
|
||||
_IsRangeSet = true;
|
||||
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
Add(items[i]);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_IsRangeSet = false;
|
||||
|
||||
OnCollectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RemoveItem
|
||||
|
||||
/// <summary>
|
||||
/// Processes list RemoveItem calls
|
||||
/// </summary>
|
||||
/// <param name="index">Index to remove</param>
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
base.RemoveItem(index);
|
||||
|
||||
OnCollectionChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region InsertItem
|
||||
|
||||
/// <summary>
|
||||
/// Processes list InsertItem calls
|
||||
/// </summary>
|
||||
/// <param name="index">Index to add</param>
|
||||
/// <param name="item">Text to add</param>
|
||||
protected override void InsertItem(int index, T item)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
base.InsertItem(index, item);
|
||||
|
||||
OnCollectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SetItem
|
||||
|
||||
/// <summary>
|
||||
/// Processes list SetItem calls (e.g. replace)
|
||||
/// </summary>
|
||||
/// <param name="index">Index to replace</param>
|
||||
/// <param name="newItem">Text to replace</param>
|
||||
protected override void SetItem(int index, T newItem)
|
||||
{
|
||||
base.SetItem(index, newItem);
|
||||
|
||||
OnCollectionChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ClearItems
|
||||
|
||||
/// <summary>
|
||||
/// Processes list Clear calls (e.g. remove all)
|
||||
/// </summary>
|
||||
protected override void ClearItems()
|
||||
{
|
||||
if (Count > 0)
|
||||
base.ClearItems();
|
||||
|
||||
OnCollectionChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnCollectionChanged
|
||||
|
||||
private void OnCollectionChanged()
|
||||
{
|
||||
if (CollectionChanged != null)
|
||||
{
|
||||
if (_IsRangeSet == false)
|
||||
CollectionChanged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICloneable Members
|
||||
|
||||
public virtual object Clone()
|
||||
{
|
||||
BaseCollection<T> copy = new BaseCollection<T>();
|
||||
|
||||
CopyToItem(copy);
|
||||
|
||||
return (copy);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CopyToItem
|
||||
|
||||
internal void CopyToItem(BaseCollection<T> copy)
|
||||
{
|
||||
foreach (T item in this)
|
||||
copy.Add((T)item.Clone());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class GenericCollection<T> : BaseCollection<T> where T : GaugeItem, new()
|
||||
{
|
||||
#region Name indexer
|
||||
|
||||
public T this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (T item in Items)
|
||||
{
|
||||
if (item.Name != null && item.Name.Equals(name))
|
||||
return (item);
|
||||
}
|
||||
|
||||
return (null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,288 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DevComponents.Instrumentation.Primitives
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the color table of linear gradient.
|
||||
/// </summary>
|
||||
[TypeConverter(typeof(LinearGradientColorTableConvertor))]
|
||||
public class LinearGradientColorTable
|
||||
{
|
||||
public static readonly LinearGradientColorTable Empty = new LinearGradientColorTable();
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<EventArgs> ColorTableChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private variables
|
||||
|
||||
private Color _Start = Color.Empty;
|
||||
private Color _End = Color.Empty;
|
||||
private int _GradientAngle = 90;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance of the object.
|
||||
/// </summary>
|
||||
public LinearGradientColorTable() { }
|
||||
/// <summary>
|
||||
/// Creates new instance of the object.
|
||||
/// </summary>
|
||||
/// <param name="start">Start color.</param>
|
||||
public LinearGradientColorTable(Color start)
|
||||
{
|
||||
this.Start = start;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance of the object.
|
||||
/// </summary>
|
||||
/// <param name="start">Start color.</param>
|
||||
/// <param name="end">End color.</param>
|
||||
public LinearGradientColorTable(Color start, Color end)
|
||||
{
|
||||
this.Start = start;
|
||||
this.End = end;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance of the object.
|
||||
/// </summary>
|
||||
/// <param name="start">Start color in hexadecimal representation like FFFFFF.</param>
|
||||
/// <param name="end">End color in hexadecimal representation like FFFFFF.</param>
|
||||
public LinearGradientColorTable(string start, string end)
|
||||
{
|
||||
this.Start = ColorFactory.GetColor(start);
|
||||
this.End = ColorFactory.GetColor(end);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance of the object.
|
||||
/// </summary>
|
||||
/// <param name="start">Start color in 32-bit RGB representation.</param>
|
||||
/// <param name="end">End color in 32-bit RGB representation.</param>
|
||||
public LinearGradientColorTable(int start, int end)
|
||||
{
|
||||
this.Start = ColorFactory.GetColor(start);
|
||||
this.End = ColorFactory.GetColor(end);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance of the object.
|
||||
/// </summary>
|
||||
/// <param name="start">Start color in 32-bit RGB representation.</param>
|
||||
/// <param name="end">End color in 32-bit RGB representation.</param>
|
||||
/// <param name="gradientAngle">Gradient angle.</param>
|
||||
public LinearGradientColorTable(int start, int end, int gradientAngle)
|
||||
{
|
||||
this.Start = ColorFactory.GetColor(start);
|
||||
this.End = ColorFactory.GetColor(end);
|
||||
this.GradientAngle = gradientAngle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new instance of the object.
|
||||
/// </summary>
|
||||
/// <param name="start">Start color.</param>
|
||||
/// <param name="end">End color.</param>
|
||||
/// <param name="gradientAngle">Gradient angle.</param>
|
||||
public LinearGradientColorTable(Color start, Color end, int gradientAngle)
|
||||
{
|
||||
this.Start = start;
|
||||
this.End = end;
|
||||
this.GradientAngle = gradientAngle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public properties
|
||||
|
||||
#region Start
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the start color.
|
||||
/// </summary>
|
||||
[Browsable(true)]
|
||||
[NotifyParentProperty(true)]
|
||||
[Description("Indicates the Starting Gradient Color.")]
|
||||
public Color Start
|
||||
{
|
||||
get { return (_Start); }
|
||||
|
||||
set
|
||||
{
|
||||
if (_Start != value)
|
||||
{
|
||||
_Start = value;
|
||||
|
||||
OnColorTableChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal virtual bool ShouldSerializeStart()
|
||||
{
|
||||
return (_Start.IsEmpty == false);
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal virtual void ResetStart()
|
||||
{
|
||||
Start = Color.Empty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region End
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the end color.
|
||||
/// </summary>
|
||||
[Browsable(true)]
|
||||
[NotifyParentProperty(true)]
|
||||
[Description("Indicates the Ending Gradient Color.")]
|
||||
public Color End
|
||||
{
|
||||
get { return (_End); }
|
||||
|
||||
set
|
||||
{
|
||||
if (_End != value)
|
||||
{
|
||||
_End = value;
|
||||
|
||||
OnColorTableChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal virtual bool ShouldSerializeEnd()
|
||||
{
|
||||
return (_End.IsEmpty == false);
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal virtual void ResetEnd()
|
||||
{
|
||||
End = Color.Empty;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GradientAngle
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the gradient angle. Default value is 90.
|
||||
/// </summary>
|
||||
[Browsable(true), DefaultValue(90)]
|
||||
[NotifyParentProperty(true)]
|
||||
[Description("Indicates the Gradient Angle. Default is 90")]
|
||||
public int GradientAngle
|
||||
{
|
||||
get { return (_GradientAngle); }
|
||||
|
||||
set
|
||||
{
|
||||
if (_GradientAngle != value)
|
||||
{
|
||||
_GradientAngle = value;
|
||||
|
||||
OnColorTableChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsEmpty
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether both colors assigned are empty.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public virtual bool IsEmpty
|
||||
{
|
||||
get { return (Start.IsEmpty && End.IsEmpty && GradientAngle == 90); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnColorTableChanged
|
||||
|
||||
protected void OnColorTableChanged()
|
||||
{
|
||||
if (ColorTableChanged != null)
|
||||
ColorTableChanged(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetBrush
|
||||
|
||||
public Brush GetBrush(Rectangle r)
|
||||
{
|
||||
return (GetBrush(r, _GradientAngle));
|
||||
}
|
||||
|
||||
public Brush GetBrush(Rectangle r, int angle)
|
||||
{
|
||||
if (_End.IsEmpty == true)
|
||||
return (new SolidBrush(_Start));
|
||||
|
||||
LinearGradientBrush lbr =
|
||||
new LinearGradientBrush(r, _Start, _End, angle);
|
||||
|
||||
return (lbr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region LinearGradientColorTableConvertor
|
||||
|
||||
public class LinearGradientColorTableConvertor : ExpandableObjectConverter
|
||||
{
|
||||
public override object ConvertTo(
|
||||
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
{
|
||||
LinearGradientColorTable lct = value as LinearGradientColorTable;
|
||||
|
||||
if (lct != null)
|
||||
{
|
||||
ColorConverter cvt = new ColorConverter();
|
||||
|
||||
if (lct.Start != Color.Empty)
|
||||
return (cvt.ConvertToString(lct.Start));
|
||||
|
||||
if (lct.End != Color.Empty)
|
||||
return (cvt.ConvertToString(lct.End));
|
||||
|
||||
if (lct.GradientAngle != 90)
|
||||
return (lct.GradientAngle.ToString());
|
||||
|
||||
return (String.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
return (base.ConvertTo(context, culture, value, destinationType));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user