DrawingChannelGrab.xaml.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using MuchInfo.Chart.Data.EnumTypes;
  2. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Input;
  6. using System.Windows.Media;
  7. namespace MuchInfo.Chart.WPF.Controls.Drawing
  8. {
  9. /// <summary>
  10. /// DrawingChannelGrab.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class DrawingChannelGrab : UserControl
  13. {
  14. private IChannelDrawing _channelDrawing;
  15. private Chart _chart;
  16. private bool _isMouseEnter;
  17. private bool _isMouseDown;
  18. //private bool DrawingChannelGrab_833;
  19. public DrawingChannelGrab()
  20. {
  21. base.MouseMove -= (new MouseEventHandler(this.theBorder_MouseMove));
  22. base.MouseMove += (new MouseEventHandler(this.theBorder_MouseMove));
  23. base.MouseEnter -= (new MouseEventHandler(this.theBorder_MouseEnter));
  24. base.MouseEnter += (new MouseEventHandler(this.theBorder_MouseEnter));
  25. base.MouseLeave -= (new MouseEventHandler(this.theBorder_MouseLeave));
  26. base.MouseLeave += (new MouseEventHandler(this.theBorder_MouseLeave));
  27. base.LostMouseCapture -= (new MouseEventHandler(this.DrawingPointGrab_LostMouseCapture));
  28. base.LostMouseCapture += (new MouseEventHandler(this.DrawingPointGrab_LostMouseCapture));
  29. base.MouseLeftButtonDown -= (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonDown));
  30. base.MouseLeftButtonDown += (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonDown));
  31. base.MouseLeftButtonUp -= (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonUp));
  32. base.MouseLeftButtonUp += (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonUp));
  33. this._isMouseEnter = false;
  34. this._isMouseDown = false;
  35. this.InitializeComponent();
  36. }
  37. public void Setup(IChannelDrawing channelDrawing, Chart chart)
  38. {
  39. this.InitializeComponent();
  40. this.Cursor = Cursors.Hand;
  41. this._channelDrawing = channelDrawing;
  42. this._chart = chart;
  43. this.arrowPath.Visibility = Visibility.Collapsed;
  44. this.dot.Visibility = Visibility.Visible;
  45. this.LayoutRoot.BorderBrush = new SolidColorBrush(Colors.Transparent);
  46. this.LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(50, 120, 120, 120));
  47. this.dot.Stroke = this._chart.IsDarkBackground ? new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)) :
  48. new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
  49. }
  50. internal void DrawingChannelGrab_2829(bool isTop)
  51. {
  52. if (isTop)
  53. {
  54. this.ShowChannelGrab((double)this._channelDrawing.ChanX(), (double)this._channelDrawing.TopY());
  55. }
  56. else
  57. {
  58. this.ShowChannelGrab((double)this._channelDrawing.ChanX(), (double)this._channelDrawing.BotY());
  59. }
  60. }
  61. private DependencyObject GetGreatGrandparent()
  62. {
  63. var parent = this.Parent as FrameworkElement;
  64. if (parent == null) return null;
  65. var grandparent = parent.Parent as FrameworkElement;
  66. return grandparent == null ? null : grandparent.Parent;
  67. }
  68. private void ShowChannelGrab(double aX, double aY)
  69. {
  70. this.SetValue(Canvas.LeftProperty, aX - 7.0);
  71. this.SetValue(Canvas.TopProperty, aY - 7.0);
  72. bool flag = this.GetGreatGrandparent() != null && this.GetGreatGrandparent() is FrameworkElement;
  73. if (flag)
  74. {
  75. var frameworkElement = (FrameworkElement)this.GetGreatGrandparent();
  76. bool flag2 = true;
  77. flag = (aY - 10.0 > frameworkElement.ActualHeight);
  78. if (flag)
  79. {
  80. flag2 = false;
  81. }
  82. else
  83. {
  84. flag = (aY + 10.0 < 0.0);
  85. if (flag)
  86. {
  87. flag2 = false;
  88. }
  89. else
  90. {
  91. flag = (aX - 10.0 > frameworkElement.ActualWidth);
  92. if (flag)
  93. {
  94. flag2 = false;
  95. }
  96. else
  97. {
  98. flag = (aX + 10.0 < 0.0);
  99. if (flag)
  100. {
  101. flag2 = false;
  102. }
  103. }
  104. }
  105. }
  106. flag = flag2;
  107. this.Visibility = flag ? Visibility.Visible : Visibility.Collapsed;
  108. }
  109. }
  110. private void DrawingPointGrab_LostMouseCapture(object sender, MouseEventArgs e)
  111. {
  112. if (this._isMouseDown)
  113. {
  114. this._isMouseDown = false;
  115. this._chart.LockPainting = false;
  116. this._chart.Refresh();
  117. this.DrawingChannelGrab_2835();
  118. }
  119. }
  120. private void theBorder_MouseEnter(object sender, MouseEventArgs e)
  121. {
  122. this._isMouseEnter = true;
  123. this.DrawingChannelGrab_2835();
  124. }
  125. private void theBorder_MouseLeave(object sender, MouseEventArgs e)
  126. {
  127. this._isMouseEnter = false;
  128. this.DrawingChannelGrab_2835();
  129. }
  130. private void DrawingChannelGrab_2835()
  131. {
  132. bool flag = this._isMouseEnter || this._isMouseDown;
  133. if (flag)
  134. {
  135. this.arrowPath.Visibility = Visibility.Visible;
  136. this.dot.Visibility = Visibility.Collapsed;
  137. flag = this._chart.IsDarkBackground;
  138. this.arrowPath.Stroke = flag ? new SolidColorBrush(Colors.Yellow) : new SolidColorBrush(Colors.Blue);
  139. }
  140. else
  141. {
  142. this.arrowPath.Visibility = Visibility.Collapsed;
  143. flag = this._chart.IsDarkBackground;
  144. this.dot.Stroke = flag ? new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)) : new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
  145. this.dot.Visibility = Visibility.Visible;
  146. }
  147. }
  148. private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  149. {
  150. if (this._chart != null && this._chart.PointerType == PointerType.Erase)
  151. {
  152. this._channelDrawing.Delete();
  153. }
  154. else
  155. {
  156. this._chart.LockPainting = true;
  157. this.CaptureMouse();
  158. this.BuildChannelGrab(e);
  159. this._isMouseDown = true;
  160. this.DrawingChannelGrab_2835();
  161. }
  162. }
  163. private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  164. {
  165. bool flag = this._isMouseDown;
  166. if (flag)
  167. {
  168. this.ReleaseMouseCapture();
  169. this.BuildChannelGrab(e);
  170. flag = (this._channelDrawing.OwnerSpec != null);
  171. if (flag)
  172. {
  173. this._channelDrawing.OwnerSpec.ToolChanged(this._channelDrawing);
  174. }
  175. this._isMouseDown = false;
  176. this._chart.LockPainting = false;
  177. this._chart.Refresh();
  178. this.DrawingChannelGrab_2835();
  179. }
  180. }
  181. private void theBorder_MouseMove(object sender, MouseEventArgs e)
  182. {
  183. if (this._chart != null && this._chart.PointerType == PointerType.Erase)
  184. {
  185. this._chart.SetCursorImagePos(true, e);
  186. }
  187. if (this._isMouseDown)
  188. {
  189. this.BuildChannelGrab(e);
  190. }
  191. }
  192. private void BuildChannelGrab(MouseEventArgs e)
  193. {
  194. bool flag = this.GetGreatGrandparent() != null && this.GetGreatGrandparent() is FrameworkElement;
  195. if (flag)
  196. {
  197. Point position = e.GetPosition((UIElement)this.GetGreatGrandparent());
  198. var frameworkElement = (FrameworkElement)this.GetGreatGrandparent();
  199. var num = (float)(frameworkElement.ActualHeight - 6.0);
  200. flag = (num < 0f);
  201. if (flag)
  202. {
  203. num = 0f;
  204. }
  205. var num2 = (float)frameworkElement.ActualWidth;
  206. flag = (num2 < 0f);
  207. if (flag)
  208. {
  209. num2 = 0f;
  210. }
  211. flag = (position.X < 0.0);
  212. if (flag)
  213. {
  214. position.X = (0.0);
  215. }
  216. flag = (position.Y < 0.0);
  217. if (flag)
  218. {
  219. position.Y = (0.0);
  220. }
  221. flag = (position.X > (double)num2);
  222. if (flag)
  223. {
  224. position.X = ((double)num2);
  225. }
  226. flag = (position.Y > (double)num);
  227. if (flag)
  228. {
  229. position.Y = ((double)num);
  230. }
  231. this.ShowChannelGrab(position.X, position.Y);
  232. this._channelDrawing.ChangeWidth((float)position.Y);
  233. }
  234. }
  235. }
  236. }