using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Design; using System.Globalization; namespace DevComponents.DotNetBar.Charts.Style { /// /// Represents the visual style of a DropShadow /// [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 /// /// Gets or sets the DropShadow color /// [Description("Indicates the DropShadow color")] public Color ShadowColor { get { return (_ShadowColor); } set { if (value != _ShadowColor) { _ShadowColor = value; OnPropertyChangedEx("ShadowColor", VisualChangeType.Render); } } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] private bool ShouldSerializeShadowColor() { return (_ShadowColor.IsEmpty == false); } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] private void ResetShadowColor() { _ShadowColor = Color.Empty; } #endregion #region Enabled /// /// Gets or sets whether drop shadow is displayed. /// [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 /// /// Gets whether the style is logically Empty. /// [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 /// /// Applies the style to instance of this style. /// /// Style to apply. 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 /// /// Returns the copy of the style. /// /// Copy of the style. public new DropShadowVisualStyle Copy() { DropShadowVisualStyle style = new DropShadowVisualStyle(); CopyTo(style); return (style); } #endregion #region CopyTo /// /// Returns the copy of the style. /// /// Copy of the style. 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 /// /// Dispose /// 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 }