| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- namespace IndexFormula.Finance
- {
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Drawing.Drawing2D;
- using System.Xml.Serialization;
- [Serializable, Editor(typeof(PenMapperEditor), typeof(UITypeEditor)), TypeConverter(typeof(ExpandableObjectConverter))]
- public class PenMapper
- {
- private byte alpha;
- private System.Drawing.Color color;
- private System.Drawing.Drawing2D.DashCap dashCap;
- private float[] dashPattern;
- private System.Drawing.Drawing2D.DashStyle dashStyle;
- private static PenMapper defaultPen = new PenMapper();
- private ArrowCap endCap;
- private ArrowCap startCap;
- private int width;
- public PenMapper()
- {
- this.color = System.Drawing.Color.Black;
- this.alpha = 0xff;
- this.width = 1;
- }
- public PenMapper(System.Drawing.Color color) : this()
- {
- this.color = color;
- }
- public PenMapper(System.Drawing.Color color, int width) : this(color)
- {
- this.width = width;
- }
- public PenMapper(System.Drawing.Color color, int width, byte alpha) : this(color, width)
- {
- this.alpha = alpha;
- }
- public PenMapper Clone()
- {
- PenMapper mapper = new PenMapper();
- mapper.color = this.color;
- mapper.alpha = this.alpha;
- mapper.dashStyle = this.dashStyle;
- mapper.startCap = this.startCap;
- mapper.endCap = this.endCap;
- mapper.width = this.width;
- mapper.dashPattern = this.dashPattern;
- return mapper;
- }
- public Pen GetPen()
- {
- Pen pen = new Pen(System.Drawing.Color.FromArgb(this.alpha, this.color), (float) this.width);
- pen.DashCap = this.DashCap;
- if (this.dashPattern != null)
- {
- pen.DashPattern = this.dashPattern;
- }
- else
- {
- pen.DashStyle = this.dashStyle;
- }
- if (((this.startCap != null) && (this.startCap.Width != 0)) && (this.startCap.Height != 0))
- {
- pen.CustomStartCap = new AdjustableArrowCap((float) this.startCap.Width, (float) this.startCap.Height, this.startCap.Filled);
- }
- if (((this.endCap != null) && (this.endCap.Width != 0)) && (this.endCap.Height != 0))
- {
- pen.CustomEndCap = new AdjustableArrowCap((float) this.endCap.Width, (float) this.endCap.Height, this.endCap.Filled);
- }
- return pen;
- }
- public static bool NotDefault(PenMapper op)
- {
- return (((((defaultPen.Alpha != op.Alpha) || (defaultPen.Color != op.Color)) || ((defaultPen.DashCap != op.DashCap) || (defaultPen.DashStyle != op.DashStyle))) || (((defaultPen.EndCap != op.EndCap) || (defaultPen.StartCap != op.StartCap)) || (defaultPen.Width != op.Width))) || (op.dashPattern != null));
- }
- public override string ToString()
- {
- return (this.color.Name + "," + this.width);
- }
- [RefreshProperties(RefreshProperties.All), XmlAttribute, DefaultValue(0xff)]
- public byte Alpha
- {
- get
- {
- return this.alpha;
- }
- set
- {
- this.alpha = value;
- }
- }
- [XmlIgnore]
- public System.Drawing.Color Color
- {
- get
- {
- return this.color;
- }
- set
- {
- this.color = value;
- }
- }
- [XmlAttribute, DefaultValue(0), RefreshProperties(RefreshProperties.All)]
- public System.Drawing.Drawing2D.DashCap DashCap
- {
- get
- {
- return this.dashCap;
- }
- set
- {
- this.dashCap = value;
- }
- }
- [TypeConverter(typeof(FloatArrayConverter)), Editor(typeof(FloatArrayEditor), typeof(UITypeEditor))]
- public float[] DashPattern
- {
- get
- {
- return this.dashPattern;
- }
- set
- {
- this.dashPattern = value;
- if (value != null)
- {
- for (int i = 0; i < value.Length; i++)
- {
- if (value[i] <= 0f)
- {
- value[i] = 1f;
- }
- }
- }
- }
- }
- [DefaultValue(0), XmlAttribute, RefreshProperties(RefreshProperties.All)]
- public System.Drawing.Drawing2D.DashStyle DashStyle
- {
- get
- {
- return this.dashStyle;
- }
- set
- {
- this.dashStyle = value;
- }
- }
- public ArrowCap EndCap
- {
- get
- {
- return this.endCap;
- }
- set
- {
- this.endCap = value;
- }
- }
- public ArrowCap StartCap
- {
- get
- {
- return this.startCap;
- }
- set
- {
- this.startCap = value;
- }
- }
- [XmlAttribute, RefreshProperties(RefreshProperties.All), DefaultValue(1)]
- public int Width
- {
- get
- {
- return this.width;
- }
- set
- {
- this.width = 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);
- }
- }
- }
- }
|