| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- 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);
- }
- }
- }
- }
|