310 lines
7.6 KiB
C#

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
namespace DevComponents.DotNetBar.Charts.Style
{
/// <summary>
/// Represents the visual style of a DropShadow
/// </summary>
[ToolboxItem(false), DesignTimeVisible(false)]
[TypeConverter(typeof(DropShadowStyleConvertor))]
public class DropShadowVisualStyle : BaseVisualStyle
{
#region Private variables
private Tbool _Enabled = Tbool.NotSet;
private Color _ShadowColor = Color.Empty;
#endregion
#region Public properties
#region ShadowColor
/// <summary>
/// Gets or sets the DropShadow color
/// </summary>
[Description("Indicates the DropShadow color")]
public Color ShadowColor
{
get { return (_ShadowColor); }
set
{
if (value != _ShadowColor)
{
_ShadowColor = value;
OnPropertyChangedEx("ShadowColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeShadowColor()
{
return (_ShadowColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetShadowColor()
{
_ShadowColor = Color.Empty;
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether drop shadow is displayed.
/// </summary>
[DefaultValue(Tbool.NotSet), Category("Appearance")]
[Description("Indicates whether drop shadow is displayed.")]
public Tbool Enabled
{
get { return (_Enabled); }
set
{
if (value != _Enabled)
{
_Enabled = value;
OnPropertyChangedEx("Enabled", VisualChangeType.Layout);
}
}
}
#endregion
#region IsEmpty
/// <summary>
/// Gets whether the style is logically Empty.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Description("Gets whether the style is logically Empty.")]
public override bool IsEmpty
{
get
{
return ((_ShadowColor.IsEmpty == true) &&
(_Enabled == Tbool.NotSet) &&
(base.IsEmpty == true));
}
}
#endregion
#endregion
#region RenderDropShadow
internal virtual void RenderDropShadow(
Graphics g, Rectangle r, bool drawBot, bool drawRight)
{
Color color = (_ShadowColor.IsEmpty == false) ? _ShadowColor : Color.Black;
Point[] pts = new Point[]
{
new Point(r.X + 3, r.Bottom),
new Point(r.Right, r.Bottom),
new Point(r.Right, r.Y + 3)
};
using (Pen pen1 = new Pen(Color.FromArgb(100, color)))
g.DrawLines(pen1, pts);
IncShadowPts(pts);
using (Pen pen2 = new Pen(Color.FromArgb(64, color)))
g.DrawLines(pen2, pts);
IncShadowPts(pts);
using (Pen pen3 = new Pen(Color.FromArgb(32, color)))
g.DrawLines(pen3, pts);
IncShadowPts(pts);
}
#region IncShadowPts
private void IncShadowPts(Point[] pts)
{
pts[0].X++;
pts[0].Y++;
pts[1].X++;
pts[1].Y++;
pts[2].X++;
pts[2].Y++;
}
#endregion
#endregion
#region ApplyStyle
/// <summary>
/// Applies the style to instance of this style.
/// </summary>
/// <param name="style">Style to apply.</param>
public void ApplyStyle(DropShadowVisualStyle style)
{
if (style != null)
{
base.ApplyStyle(style);
if (style.ShadowColor.IsEmpty == false)
ShadowColor = style.ShadowColor;
if (style.Enabled != Tbool.NotSet)
Enabled = style.Enabled;
}
}
#endregion
#region Copy
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public new DropShadowVisualStyle Copy()
{
DropShadowVisualStyle style = new DropShadowVisualStyle();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public void CopyTo(DropShadowVisualStyle style)
{
base.CopyTo(style);
style.Enabled = _Enabled;
style.ShadowColor = _ShadowColor;
}
#endregion
#region GetSerialData
internal override SerialElementCollection GetSerialData(string serialName)
{
SerialElementCollection sec = new SerialElementCollection();
if (serialName != null)
{
if (serialName.Equals("") == true)
serialName = "DropShadowVisualStyle";
sec.AddStartElement(serialName);
}
sec.AddValue("Enabled", Enabled, Tbool.NotSet);
sec.AddValue("ShadowColor", ShadowColor, Color.Empty);
sec.AddElement(base.GetSerialData(null));
if (serialName != null)
sec.AddEndElement(serialName);
return (sec);
}
#endregion
#region PutSerialData
#region ProcessValue
internal override void ProcessValue(SerialElement se)
{
switch (se.Name)
{
case "Enabled":
Enabled = (Tbool)se.GetValueEnum(typeof(Tbool));
break;
case "ShadowColor":
ShadowColor = se.GetValueColor();
break;
default:
base.ProcessValue(se);
break;
}
}
#endregion
#endregion
#region IDisposable
/// <summary>
/// Dispose
/// </summary>
public override void Dispose()
{
base.Dispose();
}
#endregion
}
#region DropShadowStyleConvertor
public class DropShadowStyleConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
DropShadowVisualStyle dsc = value as DropShadowVisualStyle;
if (dsc != null)
{
ColorConverter cvt = new ColorConverter();
if (dsc.Enabled == Tbool.NotSet)
return (" ");
return ((dsc.Enabled == Tbool.True) ? "Enabled" : "Disabled");
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}