DrawingFibTimeZones.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using MuchInfo.Chart.Data.EnumTypes;
  2. using MuchInfo.Chart.Infrastructure.Helpers;
  3. using MuchInfo.Chart.WPF.Controls.Drawing;
  4. using MuchInfo.Chart.WPF.Helpers;
  5. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Media;
  11. using System.Windows.Shapes;
  12. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  13. {
  14. public class DrawingFibTimeZones : Drawing2PointBase
  15. {
  16. #region Fields
  17. private Canvas _canvas;
  18. private ExtendableLine _extendableLine;
  19. #endregion Fields
  20. #region Constructors
  21. public DrawingFibTimeZones()
  22. {
  23. }
  24. #endregion Constructors
  25. #region Properties
  26. #region Public Properties
  27. public override string RootName
  28. {
  29. get { return "DrawFibTimeZone"; }
  30. }
  31. #endregion Public Properties
  32. #endregion Properties
  33. #region Methods
  34. #region Public Methods
  35. public override string Abbreviation()
  36. {
  37. return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_FibTimeZones);
  38. }
  39. public override IDrawingTool Clone()
  40. {
  41. return new DrawingFibTimeZones
  42. {
  43. mColor = Colors.White
  44. };
  45. }
  46. public override string Description()
  47. {
  48. return this.MenuDescription();
  49. }
  50. public override ImageSource Icon()
  51. {
  52. return ImageHelper.GetImage("FibTime.png");
  53. }
  54. public override string MenuDescription()
  55. {
  56. return LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_Description_FibTimeZones);
  57. }
  58. public override DrawingToolType ToolType()
  59. {
  60. return DrawingToolType.FibTime;
  61. }
  62. #endregion Public Methods
  63. #region Protected Methods
  64. protected override bool CanExtendLeft()
  65. {
  66. return true;
  67. }
  68. protected override bool CanExtendRight()
  69. {
  70. return true;
  71. }
  72. protected override void ColorChanged()
  73. {
  74. bool flag = this._extendableLine != null;
  75. if (flag)
  76. {
  77. this._extendableLine.Stroke = new SolidColorBrush(this.mColor);
  78. this._extendableLine.ExtensionStroke = new SolidColorBrush(this.mExtensionColor);
  79. }
  80. }
  81. protected override List<FrameworkElement> GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect)
  82. {
  83. var list = new List<FrameworkElement>();
  84. this._canvas = new Canvas();
  85. bool flag = this._extendableLine == null;
  86. if (flag)
  87. {
  88. this._extendableLine = new ExtendableLine(this, owner)
  89. {
  90. Stroke = new SolidColorBrush(this.mColor),
  91. ExtensionStroke = new SolidColorBrush(this.mExtensionColor),
  92. StrokeThickness = 1.4
  93. };
  94. }
  95. this.MoveDrawingToNewLocations(aRect);
  96. list.Add(this._canvas);
  97. list.Add(this._extendableLine);
  98. return list;
  99. }
  100. protected override void MoveDrawingToNewLocations(Rect aRect)
  101. {
  102. this._canvas.Children.Clear();
  103. if (this._extendableLine != null)
  104. {
  105. this._extendableLine.SetPosition(this.mDrawP1, this.mDrawP2, this.ExtendLeft, this.ExtendRight, aRect);
  106. }
  107. checked
  108. {
  109. var point = new Point((double)((int)Math.Round(this.mDrawP1.X)), (double)((int)Math.Round(this.mDrawP1.Y)));
  110. var point2 = new Point((double)((int)Math.Round(this.mDrawP2.X)), (double)((int)Math.Round(this.mDrawP2.Y)));
  111. var point3 = new Point((double)((int)Math.Round(unchecked(this.mDrawP2.X / 2.0 + this.mDrawP1.X / 2.0))),
  112. (double)((int)Math.Round(unchecked(this.mDrawP2.Y / 2.0 + this.mDrawP1.Y / 2.0))));
  113. this._canvas.Children.Add(this.CreateLine(point.X, aRect.Top, point.X, aRect.Bottom));
  114. this._canvas.Children.Add(this.CreateTextBlock("0", point.X, aRect.Top));
  115. this._canvas.Children.Add(this.CreateLine(point2.X, aRect.Top, point2.X, aRect.Bottom));
  116. this._canvas.Children.Add(this.CreateTextBlock("1", point2.X, aRect.Top));
  117. var num = (int)Math.Round(unchecked(point2.X - point.X));
  118. var num2 = 1;
  119. var num3 = 2;
  120. var num4 = 0;
  121. var num5 = 0f;
  122. while (num > 0 && num4 < 1000 && num5 <= 1f)
  123. {
  124. var num6 = (int)Math.Round(unchecked(point.X + (double)checked(num3 * num)));
  125. var flag = ((double)num6 >= aRect.Right);
  126. if (flag)
  127. {
  128. break;
  129. }
  130. this._canvas.Children.Add(this.CreateLine((double)num6, aRect.Top, (double)num6, aRect.Bottom));
  131. this._canvas.Children.Add(this.CreateTextBlock(num3.ToString(), (double)num6, aRect.Top));
  132. int num7 = num3;
  133. num3 += num2;
  134. num2 = num7;
  135. }
  136. }
  137. }
  138. #endregion Protected Methods
  139. #region Private Methods
  140. private Line CreateLine(double x1, double y1, double x2, double y2)
  141. {
  142. return this.CreateLine(new Point(x1, y1), new Point(x2, y2));
  143. }
  144. private Line CreateLine(Point p1, Point p2)
  145. {
  146. var line = new Line
  147. {
  148. X1 = p1.X,
  149. Y1 = p1.Y,
  150. X2 = p2.X,
  151. Y2 = p2.Y,
  152. Stroke = new SolidColorBrush(this.mColor),
  153. StrokeThickness = 1.0,
  154. StrokeDashArray = new DoubleCollection { 6.0, 4.0 },
  155. IsHitTestVisible = false
  156. };
  157. return line;
  158. }
  159. private TextBlock CreateTextBlock(string txt, double aX, double aY)
  160. {
  161. var textBlock = new TextBlock
  162. {
  163. Text = txt,
  164. Foreground = new SolidColorBrush(this.mColor),
  165. Margin = new Thickness(2.0, 2.0, 0.0, 0.0),
  166. IsHitTestVisible = false
  167. };
  168. textBlock.SetValue(Canvas.LeftProperty, aX);
  169. textBlock.SetValue(Canvas.TopProperty, aY);
  170. return textBlock;
  171. }
  172. #endregion Private Methods
  173. #endregion Methods
  174. }
  175. }