DrawingRectangle.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using Microsoft.VisualBasic;
  2. using Microsoft.VisualBasic.CompilerServices;
  3. using MuchInfo.Chart.Data;
  4. using MuchInfo.Chart.Data.EnumTypes;
  5. using MuchInfo.Chart.Infrastructure.Helpers;
  6. using MuchInfo.Chart.Infrastructure.Utilities;
  7. using MuchInfo.Chart.WPF.Controls.Drawing;
  8. using MuchInfo.Chart.WPF.Controls.Editors;
  9. using MuchInfo.Chart.WPF.Helpers;
  10. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Runtime.CompilerServices;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Media;
  17. using System.Windows.Shapes;
  18. using System.Xml.Linq;
  19. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  20. {
  21. public class DrawingRectangle : Drawing2PointBase
  22. {
  23. #region Fields
  24. private bool _doFill;
  25. private ExtendableLine _extendableLine;
  26. private Color _fillColor;
  27. private double _fillOpacity;
  28. private Rectangle _rectangle;
  29. #endregion Fields
  30. #region Constructors
  31. public DrawingRectangle()
  32. {
  33. this._doFill = true;
  34. this._fillOpacity = 0.3;
  35. this._fillColor = Colors.Gray;
  36. }
  37. #endregion Constructors
  38. #region Properties
  39. #region Public Properties
  40. public Color FillColor
  41. {
  42. get
  43. {
  44. return this._fillColor;
  45. }
  46. set
  47. {
  48. if (_fillColor.Equals(value))
  49. {
  50. this._fillColor = value;
  51. this.ColorChanged();
  52. this.PropertyChanged();
  53. }
  54. }
  55. }
  56. public bool DoFill
  57. {
  58. get
  59. {
  60. return this._doFill;
  61. }
  62. set
  63. {
  64. bool flag = this._doFill != value;
  65. if (flag)
  66. {
  67. this._doFill = value;
  68. this.ColorChanged();
  69. this.PropertyChanged();
  70. }
  71. }
  72. }
  73. public double FillOpacity
  74. {
  75. get
  76. {
  77. return this._fillOpacity;
  78. }
  79. set
  80. {
  81. bool flag = this._fillOpacity.Equals(value);
  82. if (flag)
  83. {
  84. this._fillOpacity = value;
  85. this.ColorChanged();
  86. this.PropertyChanged();
  87. }
  88. }
  89. }
  90. public override string RootName
  91. {
  92. get { return "DrawRectangle"; }
  93. }
  94. #endregion Public Properties
  95. #endregion Properties
  96. #region Methods
  97. #region Public Methods
  98. public override string Abbreviation()
  99. {
  100. return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_Rectangle);
  101. }
  102. public override List<ControlPair> AdditionalEditors()
  103. {
  104. var list = new List<ControlPair>()
  105. {
  106. new ControlPair()
  107. {
  108. ControlLeft = new TextBlock {Text = LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_Fill)},
  109. ControlRight = new ColorOpacityEditor(this, "FillColor", "FillOpacity", "DoFill")
  110. }
  111. };
  112. return list;
  113. }
  114. public override IDrawingTool Clone()
  115. {
  116. return new DrawingRectangle
  117. {
  118. mColor = Colors.White
  119. };
  120. }
  121. public override string Description()
  122. {
  123. return this.MenuDescription();
  124. }
  125. public override ImageSource Icon()
  126. {
  127. ImageSource result;
  128. try
  129. {
  130. result = ImageHelper.GetImage("Rectangle.png");
  131. }
  132. catch (Exception expr_3A)
  133. {
  134. ProjectData.SetProjectError(expr_3A);
  135. result = null;
  136. ProjectData.ClearProjectError();
  137. }
  138. return result;
  139. }
  140. public override string MenuDescription()
  141. {
  142. return LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_Description_Rectangle);
  143. }
  144. public override DrawingToolType ToolType()
  145. {
  146. return DrawingToolType.Rectangle;
  147. }
  148. #endregion Public Methods
  149. #region Protected Methods
  150. protected override void AddFromInfo(DrawingToolInfo info)
  151. {
  152. base.AddFromInfo(info);
  153. }
  154. protected override void AddFromXml(XElement xml)
  155. {
  156. }
  157. protected override void AddToInfo(DrawingToolInfo info)
  158. {
  159. base.AddToInfo(info);
  160. }
  161. protected override void AddToXml(XElement xml, List<object> args)
  162. {
  163. }
  164. protected override bool CanExtendLeft()
  165. {
  166. return false;
  167. }
  168. protected override bool CanExtendRight()
  169. {
  170. return false;
  171. }
  172. protected override void ColorChanged()
  173. {
  174. bool flag = this._rectangle != null;
  175. checked
  176. {
  177. if (flag)
  178. {
  179. this._rectangle.Stroke = (new SolidColorBrush(this.mColor));
  180. flag = !this._doFill;
  181. if (flag)
  182. {
  183. this._rectangle.Fill = null;
  184. }
  185. else
  186. {
  187. var num = (int)Math.Round(unchecked(2.55 * this._fillOpacity) * 100);
  188. flag = (num < 0);
  189. if (flag)
  190. {
  191. num = 0;
  192. }
  193. flag = (num > 255);
  194. if (flag)
  195. {
  196. num = 255;
  197. }
  198. this._rectangle.Fill = (new SolidColorBrush(Color.FromArgb((byte)num, this._fillColor.R, this._fillColor.G, this._fillColor.B)));
  199. }
  200. }
  201. }
  202. }
  203. protected override List<FrameworkElement> GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect)
  204. {
  205. var list = new List<FrameworkElement>();
  206. bool flag = this._extendableLine == null;
  207. if (flag)
  208. {
  209. this._extendableLine = new ExtendableLine(this, owner);
  210. this._extendableLine.Stroke = new SolidColorBrush(Colors.Transparent);
  211. }
  212. this._rectangle = new Rectangle { StrokeThickness = (1.4), IsHitTestVisible = (false) };
  213. this.MoveDrawingToNewLocations(aRect);
  214. this.ColorChanged();
  215. list.Add(this._rectangle);
  216. list.Add(this._extendableLine);
  217. return list;
  218. }
  219. protected override void MoveDrawingToNewLocations(Rect aRect)
  220. {
  221. if (this._extendableLine != null)
  222. {
  223. this._extendableLine.SetPosition(this.mDrawP1, this.mDrawP2, false, false, aRect);
  224. //this._extendableLine.SetPosition(this.mDrawP1, this.mDrawP2, this.ExtendLeft, this.ExtendRight, aRect);
  225. }
  226. if (this._rectangle != null)
  227. {
  228. ////ÏÞÖÆp1,p2λÖÃ
  229. //var p1X = this.mDrawP1.X < 0 ? 0 : (this.mDrawP1.X > aRect.Width ? aRect.Width : this.mDrawP1.X);
  230. //var p1Y = this.mDrawP1.Y < 0 ? 0 : (this.mDrawP1.Y > aRect.Height ? aRect.Height : this.mDrawP1.Y);
  231. //var p2X = this.mDrawP2.X < 0 ? 0 : (this.mDrawP2.X > aRect.Width ? aRect.Width : this.mDrawP2.X);
  232. //var p2Y = this.mDrawP2.Y < 0 ? 0 : (this.mDrawP2.Y > aRect.Height ? aRect.Height : this.mDrawP2.Y);
  233. var p1X = this.mDrawP1.X;
  234. var p1Y = this.mDrawP1.Y;
  235. var p2X = this.mDrawP2.X;
  236. var p2Y = this.mDrawP2.Y;
  237. if (p1X < p2X)
  238. {
  239. this._rectangle.SetValue(Canvas.LeftProperty, p1X);
  240. this._rectangle.Width = (p2X - p1X);
  241. }
  242. else
  243. {
  244. this._rectangle.SetValue(Canvas.LeftProperty, p2X);
  245. this._rectangle.Width = (p1X - p2X);
  246. }
  247. if (p1Y < p2Y)
  248. {
  249. this._rectangle.SetValue(Canvas.TopProperty, p1Y);
  250. this._rectangle.Height = (p2Y - p1Y);
  251. }
  252. else
  253. {
  254. this._rectangle.SetValue(Canvas.TopProperty, p2Y);
  255. this._rectangle.Height = (p1Y - p2Y);
  256. }
  257. }
  258. }
  259. #endregion Protected Methods
  260. #endregion Methods
  261. }
  262. }