星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ArrowTool.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. namespace ComeCapture.Controls
  7. {
  8. public class ArrowTool : StackPanel
  9. {
  10. private readonly StreamGeometry geometry = new StreamGeometry();
  11. static ArrowTool()
  12. {
  13. DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowTool), new FrameworkPropertyMetadata(typeof(ArrowTool)));
  14. }
  15. public ArrowTool()
  16. {
  17. _Current = this;
  18. }
  19. public List<Point> CreateArrow(Point start, Point end)
  20. {
  21. double tan = Math.Atan((end.Y - start.Y) / (end.X - start.X));
  22. double Move0 = tan - ArrowAngle;
  23. double Move1 = tan + ArrowAngle;
  24. int convert = end.X > start.X ? -1 : 1;
  25. double X0 = end.X + ((convert * ArrowLength) * Math.Cos(Move0));
  26. double Y0 = end.Y + ((convert * ArrowLength) * Math.Sin(Move0));
  27. double X1 = end.X + ((convert * ArrowLength) * Math.Cos(Move1));
  28. double Y1 = end.Y + ((convert * ArrowLength) * Math.Sin(Move1));
  29. Point point3 = new Point(X0, Y0);
  30. Point point5 = new Point(X1, Y1);
  31. Point point2 = new Point(X0 + 0.25 * (X1 - X0), Y0 + 0.25 * (Y1 - Y0));
  32. Point point4 = new Point(X0 + 0.75 * (X1 - X0), Y0 + 0.75 * (Y1 - Y0));
  33. return new List<Point>()
  34. {
  35. start,
  36. new Point(X0 + 0.25 * (X1 - X0), Y0 + 0.25 * (Y1 - Y0)),
  37. new Point(X0, Y0),
  38. end,
  39. new Point(X1, Y1),
  40. new Point(X0 + 0.75 * (X1 - X0), Y0 + 0.75 * (Y1 - Y0)),
  41. start
  42. };
  43. }
  44. #region 属性 Current
  45. private static ArrowTool _Current = null;
  46. public static ArrowTool Current => _Current;
  47. #endregion 属性 Current
  48. #region LineThickness DependencyProperty
  49. public double LineThickness
  50. {
  51. get => (double)GetValue(LineThicknessProperty);
  52. set => SetValue(LineThicknessProperty, value);
  53. }
  54. public static readonly DependencyProperty LineThicknessProperty =
  55. DependencyProperty.Register("LineThickness", typeof(double), typeof(ArrowTool),
  56. new PropertyMetadata(5.0, new PropertyChangedCallback(ArrowTool.OnLineThicknessPropertyChanged)));
  57. private static void OnLineThicknessPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  58. {
  59. if (obj is ArrowTool)
  60. {
  61. (obj as ArrowTool).OnLineThicknessValueChanged();
  62. }
  63. }
  64. protected void OnLineThicknessValueChanged()
  65. {
  66. ArrowLength = LineThickness * 2 + 7;
  67. }
  68. #endregion LineThickness DependencyProperty
  69. #region LineBrush DependencyProperty
  70. public SolidColorBrush LineBrush
  71. {
  72. get => (SolidColorBrush)GetValue(LineBrushProperty);
  73. set => SetValue(LineBrushProperty, value);
  74. }
  75. public static readonly DependencyProperty LineBrushProperty =
  76. DependencyProperty.Register("LineBrush", typeof(SolidColorBrush), typeof(ArrowTool),
  77. new PropertyMetadata(new SolidColorBrush(Colors.Red), new PropertyChangedCallback(ArrowTool.OnLineBrushPropertyChanged)));
  78. private static void OnLineBrushPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  79. {
  80. if (obj is ArrowTool)
  81. {
  82. (obj as ArrowTool).OnLineBrushValueChanged();
  83. }
  84. }
  85. protected void OnLineBrushValueChanged()
  86. {
  87. }
  88. #endregion LineBrush DependencyProperty
  89. #region ArrowLength DependencyProperty
  90. public double ArrowLength
  91. {
  92. get => (double)GetValue(ArrowLengthProperty);
  93. set => SetValue(ArrowLengthProperty, value);
  94. }
  95. public static readonly DependencyProperty ArrowLengthProperty =
  96. DependencyProperty.Register("ArrowLength", typeof(double), typeof(ArrowTool),
  97. new PropertyMetadata(17.0, new PropertyChangedCallback(ArrowTool.OnArrowLengthPropertyChanged)));
  98. private static void OnArrowLengthPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  99. {
  100. if (obj is ArrowTool)
  101. {
  102. (obj as ArrowTool).OnArrowLengthValueChanged();
  103. }
  104. }
  105. protected void OnArrowLengthValueChanged()
  106. {
  107. }
  108. #endregion ArrowLength DependencyProperty
  109. #region ArrowAngle DependencyProperty
  110. public double ArrowAngle
  111. {
  112. get => (double)GetValue(ArrowAngleProperty);
  113. set => SetValue(ArrowAngleProperty, value);
  114. }
  115. public static readonly DependencyProperty ArrowAngleProperty =
  116. DependencyProperty.Register("ArrowAngle", typeof(double), typeof(ArrowTool),
  117. new PropertyMetadata(0.45, new PropertyChangedCallback(ArrowTool.OnArrowAnglePropertyChanged)));
  118. private static void OnArrowAnglePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  119. {
  120. if (obj is ArrowTool)
  121. {
  122. (obj as ArrowTool).OnArrowAngleValueChanged();
  123. }
  124. }
  125. protected void OnArrowAngleValueChanged()
  126. {
  127. }
  128. #endregion ArrowAngle DependencyProperty
  129. }
  130. }