BrushMapper.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. namespace IndexFormula.Finance
  2. {
  3. using System;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Design;
  7. using System.Drawing.Drawing2D;
  8. using System.Xml.Serialization;
  9. //[Editor(typeof(ObjectBrushEditor), typeof(UITypeEditor)), TypeConverter(typeof(ExpandableObjectConverter))]
  10. public class BrushMapper
  11. {
  12. private byte alpha;
  13. private byte alpha2;
  14. private int angle;
  15. private BrushMapperStyle brushStyle;
  16. private System.Drawing.Color color;
  17. private System.Drawing.Color color2;
  18. private static BrushMapper defaultBrush = new BrushMapper();
  19. private System.Drawing.Drawing2D.HatchStyle hatchStyle;
  20. public BrushMapper()
  21. {
  22. this.color = System.Drawing.Color.Black;
  23. this.alpha = 0xff;
  24. this.alpha2 = 0;
  25. this.brushStyle = BrushMapperStyle.Solid;
  26. }
  27. public BrushMapper(BrushMapperStyle style) : this()
  28. {
  29. this.BrushStyle = style;
  30. }
  31. public BrushMapper(System.Drawing.Color color) : this()
  32. {
  33. this.color = color;
  34. }
  35. public BrushMapper Clone()
  36. {
  37. BrushMapper mapper = new BrushMapper();
  38. mapper.Color = this.Color;
  39. mapper.Color2 = this.Color2;
  40. mapper.BrushStyle = this.BrushStyle;
  41. mapper.Alpha = this.Alpha;
  42. mapper.Alpha2 = this.Alpha2;
  43. mapper.HatchStyle = this.HatchStyle;
  44. mapper.Angle = this.Angle;
  45. return mapper;
  46. }
  47. public Brush GetBrush()
  48. {
  49. return this.GetBrush(new RectangleF(0f, 0f, 640f, 480f));
  50. }
  51. public Brush GetBrush(RectangleF R)
  52. {
  53. switch (this.BrushStyle)
  54. {
  55. case BrushMapperStyle.Hatch:
  56. return new HatchBrush(this.hatchStyle, System.Drawing.Color.FromArgb(this.alpha, this.color), System.Drawing.Color.FromArgb(this.alpha2, this.color2));
  57. case BrushMapperStyle.Linear:
  58. return new LinearGradientBrush(R, System.Drawing.Color.FromArgb(this.alpha, this.color), System.Drawing.Color.FromArgb(this.alpha2, this.color2), (float) this.angle, false);
  59. case BrushMapperStyle.Empty:
  60. return new SolidBrush(System.Drawing.Color.Empty);
  61. }
  62. return new SolidBrush(System.Drawing.Color.FromArgb(this.alpha, this.color));
  63. }
  64. public static bool NotDefault(BrushMapper ob)
  65. {
  66. 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));
  67. }
  68. public override string ToString()
  69. {
  70. return this.BrushStyle.ToString();
  71. }
  72. [XmlAttribute, RefreshProperties(RefreshProperties.All), DefaultValue(0xff)]
  73. public byte Alpha
  74. {
  75. get
  76. {
  77. return this.alpha;
  78. }
  79. set
  80. {
  81. this.alpha = value;
  82. }
  83. }
  84. [DefaultValue(0), RefreshProperties(RefreshProperties.All), XmlAttribute]
  85. public byte Alpha2
  86. {
  87. get
  88. {
  89. return this.alpha2;
  90. }
  91. set
  92. {
  93. this.alpha2 = value;
  94. }
  95. }
  96. [DefaultValue(0), RefreshProperties(RefreshProperties.All), XmlAttribute]
  97. public int Angle
  98. {
  99. get
  100. {
  101. return this.angle;
  102. }
  103. set
  104. {
  105. this.angle = value;
  106. }
  107. }
  108. [RefreshProperties(RefreshProperties.All), DefaultValue(0), XmlAttribute]
  109. public BrushMapperStyle BrushStyle
  110. {
  111. get
  112. {
  113. return this.brushStyle;
  114. }
  115. set
  116. {
  117. this.brushStyle = value;
  118. }
  119. }
  120. [XmlIgnore]
  121. public System.Drawing.Color Color
  122. {
  123. get
  124. {
  125. return this.color;
  126. }
  127. set
  128. {
  129. this.color = value;
  130. }
  131. }
  132. [XmlIgnore]
  133. public System.Drawing.Color Color2
  134. {
  135. get
  136. {
  137. return this.color2;
  138. }
  139. set
  140. {
  141. this.color2 = value;
  142. }
  143. }
  144. public static BrushMapper Empty
  145. {
  146. get
  147. {
  148. return new BrushMapper(BrushMapperStyle.Empty);
  149. }
  150. }
  151. [RefreshProperties(RefreshProperties.All), DefaultValue(0), XmlAttribute]
  152. public System.Drawing.Drawing2D.HatchStyle HatchStyle
  153. {
  154. get
  155. {
  156. return this.hatchStyle;
  157. }
  158. set
  159. {
  160. this.hatchStyle = value;
  161. }
  162. }
  163. [DefaultValue("Black"), XmlAttribute(AttributeName="Color"), Browsable(false)]
  164. public string XmlColor
  165. {
  166. get
  167. {
  168. return TypeDescriptor.GetConverter(typeof(System.Drawing.Color)).ConvertToString(null, FormulaHelper.enUS, this.Color);
  169. }
  170. set
  171. {
  172. TypeConverter converter = TypeDescriptor.GetConverter(typeof(System.Drawing.Color));
  173. this.color = (System.Drawing.Color) converter.ConvertFromString(null, FormulaHelper.enUS, value);
  174. }
  175. }
  176. [DefaultValue(""), XmlAttribute(AttributeName="Color2"), Browsable(false)]
  177. public string XmlColor2
  178. {
  179. get
  180. {
  181. return TypeDescriptor.GetConverter(typeof(System.Drawing.Color)).ConvertToString(null, FormulaHelper.enUS, this.Color2);
  182. }
  183. set
  184. {
  185. TypeConverter converter = TypeDescriptor.GetConverter(typeof(System.Drawing.Color));
  186. this.color2 = (System.Drawing.Color) converter.ConvertFromString(null, FormulaHelper.enUS, value);
  187. }
  188. }
  189. }
  190. }