namespace IndexFormula.Finance { using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Design; using System.Drawing.Drawing2D; using System.Xml.Serialization; //[Editor(typeof(ObjectBrushEditor), typeof(UITypeEditor)), TypeConverter(typeof(ExpandableObjectConverter))] public class BrushMapper { private byte alpha; private byte alpha2; private int angle; private BrushMapperStyle brushStyle; private System.Drawing.Color color; private System.Drawing.Color color2; private static BrushMapper defaultBrush = new BrushMapper(); private System.Drawing.Drawing2D.HatchStyle hatchStyle; public BrushMapper() { this.color = System.Drawing.Color.Black; this.alpha = 0xff; this.alpha2 = 0; this.brushStyle = BrushMapperStyle.Solid; } public BrushMapper(BrushMapperStyle style) : this() { this.BrushStyle = style; } public BrushMapper(System.Drawing.Color color) : this() { this.color = color; } public BrushMapper Clone() { BrushMapper mapper = new BrushMapper(); mapper.Color = this.Color; mapper.Color2 = this.Color2; mapper.BrushStyle = this.BrushStyle; mapper.Alpha = this.Alpha; mapper.Alpha2 = this.Alpha2; mapper.HatchStyle = this.HatchStyle; mapper.Angle = this.Angle; return mapper; } public Brush GetBrush() { return this.GetBrush(new RectangleF(0f, 0f, 640f, 480f)); } public Brush GetBrush(RectangleF R) { switch (this.BrushStyle) { case BrushMapperStyle.Hatch: return new HatchBrush(this.hatchStyle, System.Drawing.Color.FromArgb(this.alpha, this.color), System.Drawing.Color.FromArgb(this.alpha2, this.color2)); case BrushMapperStyle.Linear: return new LinearGradientBrush(R, System.Drawing.Color.FromArgb(this.alpha, this.color), System.Drawing.Color.FromArgb(this.alpha2, this.color2), (float) this.angle, false); case BrushMapperStyle.Empty: return new SolidBrush(System.Drawing.Color.Empty); } return new SolidBrush(System.Drawing.Color.FromArgb(this.alpha, this.color)); } public static bool NotDefault(BrushMapper ob) { return (((((ob.Color != defaultBrush.Color) || (ob.Color2 != defaultBrush.Color2)) || ((ob.Alpha != defaultBrush.Alpha) || (ob.Alpha2 != defaultBrush.Alpha2))) || ((ob.Angle != defaultBrush.Angle) || (ob.HatchStyle != defaultBrush.HatchStyle))) || (ob.BrushStyle != defaultBrush.BrushStyle)); } public override string ToString() { return this.BrushStyle.ToString(); } [XmlAttribute, RefreshProperties(RefreshProperties.All), DefaultValue(0xff)] public byte Alpha { get { return this.alpha; } set { this.alpha = value; } } [DefaultValue(0), RefreshProperties(RefreshProperties.All), XmlAttribute] public byte Alpha2 { get { return this.alpha2; } set { this.alpha2 = value; } } [DefaultValue(0), RefreshProperties(RefreshProperties.All), XmlAttribute] public int Angle { get { return this.angle; } set { this.angle = value; } } [RefreshProperties(RefreshProperties.All), DefaultValue(0), XmlAttribute] public BrushMapperStyle BrushStyle { get { return this.brushStyle; } set { this.brushStyle = value; } } [XmlIgnore] public System.Drawing.Color Color { get { return this.color; } set { this.color = value; } } [XmlIgnore] public System.Drawing.Color Color2 { get { return this.color2; } set { this.color2 = value; } } public static BrushMapper Empty { get { return new BrushMapper(BrushMapperStyle.Empty); } } [RefreshProperties(RefreshProperties.All), DefaultValue(0), XmlAttribute] public System.Drawing.Drawing2D.HatchStyle HatchStyle { get { return this.hatchStyle; } set { this.hatchStyle = value; } } [DefaultValue("Black"), XmlAttribute(AttributeName="Color"), Browsable(false)] public string XmlColor { get { return TypeDescriptor.GetConverter(typeof(System.Drawing.Color)).ConvertToString(null, FormulaHelper.enUS, this.Color); } set { TypeConverter converter = TypeDescriptor.GetConverter(typeof(System.Drawing.Color)); this.color = (System.Drawing.Color) converter.ConvertFromString(null, FormulaHelper.enUS, value); } } [DefaultValue(""), XmlAttribute(AttributeName="Color2"), Browsable(false)] public string XmlColor2 { get { return TypeDescriptor.GetConverter(typeof(System.Drawing.Color)).ConvertToString(null, FormulaHelper.enUS, this.Color2); } set { TypeConverter converter = TypeDescriptor.GetConverter(typeof(System.Drawing.Color)); this.color2 = (System.Drawing.Color) converter.ConvertFromString(null, FormulaHelper.enUS, value); } } } }