SelectedRect.protected.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Media;
  5. namespace ComPDFKit.Tool.DrawTool
  6. {
  7. public partial class SelectedRect
  8. {
  9. #region Properties
  10. /// <summary>
  11. /// Current control point drawing style.
  12. /// </summary>
  13. protected DrawPointType currentDrawPointType { get; set; }
  14. /// <summary>
  15. /// Current drag drawing style.
  16. /// </summary>
  17. protected DrawMoveType currentDrawMoveType { get; set; }
  18. /// <summary>
  19. /// Current click hit control point.
  20. /// </summary>
  21. protected PointControlType hitControlType { get; set; }
  22. /// <summary>
  23. /// Mouse down position information.
  24. /// </summary>
  25. protected Point mouseDownPoint { get; set; }
  26. /// <summary>
  27. /// Whether the mouse is pressed.
  28. /// </summary>
  29. protected bool isMouseDown { get; set; }
  30. /// <summary>
  31. /// Whether proportional scaling is required.
  32. /// </summary>
  33. protected bool isProportionalScaling { get; set; } = false;
  34. /// <summary>
  35. /// Current control point size.
  36. /// </summary>
  37. protected int pointSize { get; set; } = 4;
  38. /// <summary>
  39. /// Rectangular minimum width.
  40. /// </summary>
  41. protected int rectMinWidth { get; set; } = 10;
  42. /// <summary>
  43. /// Rectangular minimum height.
  44. /// </summary>
  45. protected int RectMinHeight { get; set; } = 10;
  46. /// <summary>
  47. /// Current set of ignore points.
  48. /// </summary>
  49. protected List<PointControlType> ignorePoints { get; set; } = new List<PointControlType>();
  50. /// <summary>
  51. /// Current set of drawing rectangles (original data).
  52. /// </summary>
  53. protected Rect SetDrawRect { get; set; } = new Rect(0, 0, 0, 0);
  54. /// <summary>
  55. /// Current drawing rectangle (calculated during operation).
  56. /// </summary>
  57. protected Rect drawRect { get; set; } = new Rect(0, 0, 0, 0);
  58. /// <summary>
  59. /// Maximum range that can be drawn.
  60. /// </summary>
  61. protected Rect maxRect { get; set; } = new Rect(0, 0, 0, 0);
  62. /// <summary>
  63. /// Current center point of the drawing rectangle.
  64. /// </summary>
  65. protected Point drawCenterPoint { get; private set; } = new Point(0, 0);
  66. /// <summary>
  67. /// When the mouse is pressed, the cached rectangle.
  68. /// </summary>
  69. protected Rect cacheRect { get; set; } = new Rect(0, 0, 0, 0);
  70. /// <summary>
  71. /// Current control point coordinates.
  72. /// </summary>
  73. protected List<Point> controlPoints { get; set; } = new List<Point>();
  74. /// <summary>
  75. /// Move offset during movement.
  76. /// </summary>
  77. protected Point moveOffset { get; set; } = new Point(0, 0);
  78. /// <summary>
  79. /// Current actual display width and height of PDFVIewer.
  80. /// </summary>
  81. protected double PDFViewerActualWidth { get; set; } = 0;
  82. protected double PDFViewerActualHeight { get; set; } = 0;
  83. protected double rectPadding = 6;
  84. protected double currentZoom = 1;
  85. protected SelectedAnnotData selectedRectData = new SelectedAnnotData();
  86. protected bool disable = false;
  87. #endregion
  88. #region Functions
  89. /// <summary>
  90. /// Calcuate the control points
  91. /// </summary>
  92. /// <param name="currentRect">
  93. /// Control points in the target rectangle
  94. /// </param>
  95. protected void CalcControlPoint(Rect currentRect)
  96. {
  97. controlPoints.Clear();
  98. int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
  99. int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
  100. controlPoints.Add(new Point(currentRect.Left, currentRect.Top));
  101. controlPoints.Add(new Point(currentRect.Left, centerY));
  102. controlPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
  103. controlPoints.Add(new Point(centerX, currentRect.Bottom));
  104. controlPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
  105. controlPoints.Add(new Point(currentRect.Right, centerY));
  106. controlPoints.Add(new Point(currentRect.Right, currentRect.Top));
  107. controlPoints.Add(new Point(centerX, currentRect.Top));
  108. }
  109. /// <summary>
  110. /// Calcuate the offset of the current rectangle in the maximum rectangle range
  111. /// </summary>
  112. /// <param name="currentRect">
  113. /// The rectangle cached when pressed
  114. /// </param>
  115. /// <param name="offsetPoint">
  116. /// Equivalent to the offset value when pressed
  117. /// </param>
  118. /// <param name="maxRect">
  119. /// The maximum rectangle range.
  120. /// </param>
  121. /// <returns></returns>
  122. protected Point CalcMoveBound(Rect currentRect, Point offsetPoint, Rect maxRect)
  123. {
  124. double cLeft = currentRect.Left;
  125. double cRight = currentRect.Right;
  126. double cUp = currentRect.Top;
  127. double cDown = currentRect.Bottom;
  128. double TmpLeft = cLeft + offsetPoint.X;
  129. double TmpRight = cRight + offsetPoint.X;
  130. double TmpUp = cUp + offsetPoint.Y;
  131. double TmpDown = cDown + offsetPoint.Y;
  132. if (TmpLeft < maxRect.Left)
  133. {
  134. TmpRight = (cRight - cLeft) + maxRect.Left;
  135. TmpLeft = maxRect.Left;
  136. }
  137. if (TmpUp < maxRect.Top)
  138. {
  139. TmpDown = (cDown - cUp) + maxRect.Top;
  140. TmpUp = maxRect.Top;
  141. }
  142. if (TmpRight > maxRect.Right)
  143. {
  144. TmpLeft = maxRect.Right - (cRight - cLeft);
  145. TmpRight = maxRect.Right;
  146. }
  147. if (TmpDown > maxRect.Bottom)
  148. {
  149. TmpUp = maxRect.Bottom - (cDown - cUp);
  150. TmpDown = maxRect.Bottom;
  151. }
  152. offsetPoint = new Point(TmpLeft - cLeft, TmpUp - cUp);
  153. return offsetPoint;
  154. }
  155. /// <summary>
  156. /// Calculate the movement of the hit point
  157. /// </summary>
  158. /// <param name="mousePoint">
  159. /// Current mouse position
  160. /// </param>
  161. /// <returns>
  162. /// Whether the movement is successful
  163. /// </returns>
  164. protected bool CalcHitPointMove(Point mousePoint)
  165. {
  166. if (isMouseDown == false || hitControlType == PointControlType.None)
  167. {
  168. return false;
  169. }
  170. return NormalScaling(mousePoint);
  171. }
  172. private Size GetProportionalScalingSize(double width, double height)
  173. {
  174. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  175. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  176. if (minWidth > width || minHeight > height)
  177. {
  178. if (cacheRect.Width >= cacheRect.Height)
  179. {
  180. width = cacheRect.Width * minHeight / cacheRect.Height;
  181. height = minHeight;
  182. }
  183. else
  184. {
  185. height = cacheRect.Height * minWidth / cacheRect.Width;
  186. width = minWidth;
  187. }
  188. }
  189. return new Size(width, height);
  190. }
  191. /// <summary>
  192. /// Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
  193. /// </summary>
  194. /// <param name="mousePoint">Current mouse position.</param>
  195. /// <returns></returns>
  196. protected bool NormalScaling(Point mousePoint)
  197. {
  198. try
  199. {
  200. double left = 0, right = 0, top = 0, bottom = 0;
  201. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  202. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  203. Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
  204. Point moveVector = (Point)(mousePoint - centerPoint);
  205. moveVector = ProportionalScalingOffsetPos(moveVector);
  206. switch (hitControlType)
  207. {
  208. case PointControlType.LeftTop:
  209. {
  210. left = centerPoint.X + moveVector.X;
  211. right = cacheRect.Right;
  212. top = centerPoint.Y + moveVector.Y;
  213. bottom = cacheRect.Bottom;
  214. if (isProportionalScaling)
  215. {
  216. Size size = GetProportionalScalingSize(right - left, bottom - top);
  217. left = right - size.Width;
  218. top = bottom - size.Height;
  219. if (left < maxRect.Left)
  220. {
  221. double tmpWidth = right - left;
  222. left = maxRect.Left;
  223. double width = right - left;
  224. double height = (bottom - top) * width / tmpWidth;
  225. top = bottom - height;
  226. }
  227. if (top < maxRect.Top)
  228. {
  229. double tmpHeight = bottom - top;
  230. top = maxRect.Top;
  231. double height = bottom - top;
  232. double width = (right - left) * height / tmpHeight;
  233. left = right - width;
  234. }
  235. }
  236. else
  237. {
  238. if (left + minWidth > right)
  239. {
  240. left = right - minWidth;
  241. }
  242. if (top + minHeight > bottom)
  243. {
  244. top = bottom - minHeight;
  245. }
  246. }
  247. }
  248. break;
  249. case PointControlType.LeftMiddle:
  250. {
  251. left = centerPoint.X + moveVector.X;
  252. right = cacheRect.Right;
  253. top = cacheRect.Top;
  254. bottom = cacheRect.Bottom;
  255. if (left + minWidth > right)
  256. {
  257. left = right - minWidth;
  258. }
  259. }
  260. break;
  261. case PointControlType.LeftBottom:
  262. {
  263. left = centerPoint.X + moveVector.X;
  264. right = cacheRect.Right;
  265. top = cacheRect.Top;
  266. bottom = centerPoint.Y + moveVector.Y;
  267. if (isProportionalScaling)
  268. {
  269. Size size = GetProportionalScalingSize(right - left, bottom - top);
  270. left = right - size.Width;
  271. bottom = top + size.Height;
  272. if (left < maxRect.Left)
  273. {
  274. double tmpWidth = right - left;
  275. left = maxRect.Left;
  276. double width = right - left;
  277. double height = (bottom - top) * width / tmpWidth;
  278. bottom = top + height;
  279. }
  280. if (bottom > maxRect.Bottom)
  281. {
  282. double tmpHeight = bottom - top;
  283. bottom = maxRect.Bottom;
  284. double height = bottom - top;
  285. double width = (right - left) * height / tmpHeight;
  286. left = right - width;
  287. }
  288. }
  289. else
  290. {
  291. if (left + minWidth > right)
  292. {
  293. left = right - minWidth;
  294. }
  295. if (top + minHeight > bottom)
  296. {
  297. bottom = top + minHeight;
  298. }
  299. }
  300. }
  301. break;
  302. case PointControlType.MiddlBottom:
  303. {
  304. left = cacheRect.Left;
  305. right = cacheRect.Right;
  306. top = cacheRect.Top;
  307. bottom = centerPoint.Y + moveVector.Y;
  308. if (top + minHeight > bottom)
  309. {
  310. bottom = top + minHeight;
  311. }
  312. }
  313. break;
  314. case PointControlType.RightBottom:
  315. {
  316. left = cacheRect.Left;
  317. right = centerPoint.X + moveVector.X;
  318. top = cacheRect.Top;
  319. bottom = centerPoint.Y + moveVector.Y;
  320. if (isProportionalScaling)
  321. {
  322. Size size = GetProportionalScalingSize(right - left, bottom - top);
  323. right = left + size.Width;
  324. bottom = top + size.Height;
  325. if (right > maxRect.Right)
  326. {
  327. double tmpWidth = right - left;
  328. right = maxRect.Right;
  329. double width = right - left;
  330. double height = (bottom - top) * width / tmpWidth;
  331. bottom = top + height;
  332. }
  333. if (bottom > maxRect.Bottom)
  334. {
  335. double tmpHeight = bottom - top;
  336. bottom = maxRect.Bottom;
  337. double height = bottom - top;
  338. double width = (right - left) * height / tmpHeight;
  339. right = left + width;
  340. }
  341. }
  342. else
  343. {
  344. if (left + minWidth > right)
  345. {
  346. right = left + minWidth;
  347. }
  348. if (top + minHeight > bottom)
  349. {
  350. bottom = top + minHeight;
  351. }
  352. }
  353. }
  354. break;
  355. case PointControlType.RightMiddle:
  356. {
  357. left = cacheRect.Left;
  358. right = centerPoint.X + moveVector.X;
  359. top = cacheRect.Top;
  360. bottom = cacheRect.Bottom;
  361. if (left + minWidth > right)
  362. {
  363. right = left + minWidth;
  364. }
  365. }
  366. break;
  367. case PointControlType.RightTop:
  368. {
  369. left = cacheRect.Left;
  370. right = centerPoint.X + moveVector.X;
  371. top = centerPoint.Y + moveVector.Y;
  372. bottom = cacheRect.Bottom;
  373. if (isProportionalScaling)
  374. {
  375. Size size = GetProportionalScalingSize(right - left, bottom - top);
  376. right = left + size.Width;
  377. top = bottom - size.Height;
  378. if (right > maxRect.Right)
  379. {
  380. double tmpWidth = right - left;
  381. right = maxRect.Right;
  382. double width = right - left;
  383. double height = (bottom - top) * width / tmpWidth;
  384. top = bottom - height;
  385. }
  386. if (top < maxRect.Top)
  387. {
  388. double tmpHeight = bottom - top;
  389. top = maxRect.Top;
  390. double height = bottom - top;
  391. double width = (right - left) * height / tmpHeight;
  392. right = left + width;
  393. }
  394. }
  395. else
  396. {
  397. if (left + minWidth > right)
  398. {
  399. right = left + minWidth;
  400. }
  401. if (top + minHeight > bottom)
  402. {
  403. top = bottom - minHeight;
  404. }
  405. }
  406. }
  407. break;
  408. case PointControlType.MiddleTop:
  409. {
  410. left = cacheRect.Left;
  411. right = cacheRect.Right;
  412. top = centerPoint.Y + moveVector.Y;
  413. bottom = cacheRect.Bottom;
  414. if (top + minHeight > bottom)
  415. {
  416. top = bottom - minHeight;
  417. }
  418. }
  419. break;
  420. case PointControlType.Body:
  421. case PointControlType.Line:
  422. {
  423. Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), maxRect);
  424. left = cacheRect.Left + OffsetPos.X;
  425. right = cacheRect.Right + OffsetPos.X;
  426. top = cacheRect.Top + OffsetPos.Y;
  427. bottom = cacheRect.Bottom + OffsetPos.Y;
  428. }
  429. break;
  430. default:
  431. break;
  432. }
  433. if (left < maxRect.Left)
  434. {
  435. left = maxRect.Left;
  436. }
  437. if (top < maxRect.Top)
  438. {
  439. top = maxRect.Top;
  440. }
  441. if (right > maxRect.Right)
  442. {
  443. right = maxRect.Right;
  444. }
  445. if (bottom > maxRect.Bottom)
  446. {
  447. bottom = maxRect.Bottom;
  448. }
  449. drawRect = new Rect(left, top, right - left, bottom - top);
  450. moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
  451. return true;
  452. }
  453. catch (Exception ex)
  454. {
  455. }
  456. return false;
  457. }
  458. /// <summary>
  459. /// Proportional scaling offset calibration
  460. /// </summary>
  461. /// <param name="movePoint">
  462. /// The current movement point
  463. /// </param>
  464. /// <returns>
  465. /// The offset point after the proportional scaling
  466. /// </returns>
  467. protected Point ProportionalScalingOffsetPos(Point movePoint)
  468. {
  469. if (isProportionalScaling)
  470. {
  471. Point offsetPos = movePoint;
  472. double ratioX = cacheRect.Width > 0 ? cacheRect.Height / cacheRect.Width : 1;
  473. double ratioY = cacheRect.Height > 0 ? cacheRect.Width / cacheRect.Height : 1;
  474. switch (hitControlType)
  475. {
  476. case PointControlType.LeftTop:
  477. case PointControlType.RightBottom:
  478. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  479. break;
  480. case PointControlType.LeftBottom:
  481. case PointControlType.RightTop:
  482. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  483. break;
  484. case PointControlType.LeftMiddle:
  485. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  486. break;
  487. case PointControlType.RightMiddle:
  488. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  489. break;
  490. case PointControlType.MiddlBottom:
  491. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? 1 : -1), movePoint.Y);
  492. break;
  493. case PointControlType.MiddleTop:
  494. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? -1 : 1), movePoint.Y);
  495. break;
  496. default:
  497. break;
  498. }
  499. return offsetPos;
  500. }
  501. else
  502. {
  503. return movePoint;
  504. }
  505. }
  506. /// <summary>
  507. /// Inner drawing circle point
  508. /// </summary>
  509. /// <param name="drawingContext">
  510. /// Drawing context
  511. /// </param>
  512. /// <param name="ignoreList">
  513. /// Collection of positions that need to be drawn
  514. /// </param>
  515. /// <param name="PointSize">
  516. /// Size of the point
  517. /// </param>
  518. /// <param name="PointPen">
  519. /// Brush for drawing points
  520. /// </param>
  521. /// <param name="BorderBrush">
  522. /// Border brush for drawing points
  523. /// </param>
  524. protected void DrawCirclePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  525. {
  526. GeometryGroup controlGroup = new GeometryGroup();
  527. controlGroup.FillRule = FillRule.Nonzero;
  528. List<Point> ignorePointsList = new List<Point>();
  529. // Get specific points
  530. foreach (PointControlType type in ignoreList)
  531. {
  532. if ((int)type < controlPoints.Count)
  533. {
  534. ignorePointsList.Add(controlPoints[(int)type]);
  535. }
  536. }
  537. for (int i = 0; i < controlPoints.Count; i++)
  538. {
  539. Point controlPoint = controlPoints[i];
  540. if (ignorePointsList.Contains(controlPoint))
  541. {
  542. continue;
  543. }
  544. EllipseGeometry circlPoint = new EllipseGeometry(controlPoint, PointSize, PointSize);
  545. controlGroup.Children.Add(circlPoint);
  546. }
  547. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  548. }
  549. /// <summary>
  550. /// Inner drawing square
  551. /// </summary>
  552. /// <param name="drawingContext">
  553. /// Drawing context
  554. /// </param>
  555. /// <param name="ControlPoints">
  556. /// Collection of positions that need to be drawn
  557. /// </param>
  558. /// <param name="PointSize">
  559. /// Size of the point
  560. /// </param>
  561. /// <param name="PointPen">
  562. /// Brush for drawing points
  563. /// </param>
  564. /// <param name="BorderBrush">
  565. /// Border brush for drawing points
  566. /// </param>
  567. protected void DrawSquarePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  568. {
  569. GeometryGroup controlGroup = new GeometryGroup();
  570. controlGroup.FillRule = FillRule.Nonzero;
  571. List<Point> ignorePointsList = new List<Point>();
  572. // Get specific points
  573. foreach (PointControlType type in ignoreList)
  574. {
  575. if ((int)type < controlPoints.Count)
  576. {
  577. ignorePointsList.Add(controlPoints[(int)type]);
  578. }
  579. }
  580. for (int i = 0; i < controlPoints.Count; i++)
  581. {
  582. Point controlPoint = controlPoints[i];
  583. if (ignorePointsList.Contains(controlPoint))
  584. {
  585. continue;
  586. }
  587. RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
  588. PointSize * 2, PointSize * 2), 1, 1);
  589. controlGroup.Children.Add(rectPoint);
  590. }
  591. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  592. }
  593. protected void DrawCropPoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  594. {
  595. GeometryGroup controlGroup = new GeometryGroup();
  596. controlGroup.FillRule = FillRule.Nonzero;
  597. //Left Top Corner
  598. if (!ignoreList.Contains(PointControlType.LeftTop))
  599. {
  600. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[0].X - PointSize, controlPoints[0].Y - PointSize, PointSize, PointSize * 4));
  601. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[0].X - PointSize, controlPoints[0].Y - PointSize, PointSize * 4, PointSize));
  602. }
  603. //Left Center
  604. if (!ignoreList.Contains(PointControlType.LeftMiddle))
  605. {
  606. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[1].X - PointSize, (controlPoints[1].Y + controlPoints[1].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  607. }
  608. //Left Bottom Corner
  609. if (!ignoreList.Contains(PointControlType.LeftBottom))
  610. {
  611. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[2].X - PointSize, controlPoints[2].Y - PointSize * 3, PointSize, PointSize * 4));
  612. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[2].X - PointSize, controlPoints[2].Y, PointSize * 4, PointSize));
  613. }
  614. //Bottom Center
  615. if (!ignoreList.Contains(PointControlType.MiddlBottom))
  616. {
  617. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlPoints[3].X + controlPoints[3].X - PointSize * 5) / 2, controlPoints[3].Y, PointSize * 5, PointSize));
  618. }
  619. //Bottom Right Corner
  620. if (!ignoreList.Contains(PointControlType.RightBottom))
  621. {
  622. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[4].X, controlPoints[4].Y - PointSize * 3, PointSize, PointSize * 4));
  623. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[4].X - PointSize * 3, controlPoints[4].Y, PointSize * 4, PointSize));
  624. }
  625. //Right Center
  626. if (!ignoreList.Contains(PointControlType.RightMiddle))
  627. {
  628. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[5].X, (controlPoints[5].Y + controlPoints[5].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  629. }
  630. //Right Top Corner
  631. if (!ignoreList.Contains(PointControlType.RightTop))
  632. {
  633. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[6].X, controlPoints[6].Y - PointSize, PointSize, PointSize * 4));
  634. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[6].X - PointSize * 4, controlPoints[6].Y - PointSize, PointSize * 4, PointSize));
  635. }
  636. //Top Center
  637. if (!ignoreList.Contains(PointControlType.MiddleTop))
  638. {
  639. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlPoints[7].X + controlPoints[7].X - PointSize * 5) / 2, controlPoints[7].Y - PointSize, PointSize * 5, PointSize));
  640. }
  641. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  642. }
  643. /// <summary>
  644. /// Draw the reference line in the moving state
  645. /// </summary>
  646. /// <param name="drawDc">
  647. /// Draw context handle
  648. /// </param>
  649. /// <param name="controltype">
  650. /// Current selected control point type
  651. /// </param>
  652. /// <param name="activePen">
  653. /// Brush for drawing lines
  654. /// </param>
  655. /// <param name="moveBrush">
  656. /// Brush for drawing rectangles
  657. /// </param>
  658. /// <param name="moveRect">
  659. /// Current rectangle to draw
  660. /// </param>
  661. protected void DrawMoveBounds(DrawingContext drawDc, PointControlType controltype, Pen activePen, Brush moveBrush, Rect moveRect)
  662. {
  663. switch (controltype)
  664. {
  665. case PointControlType.LeftTop:
  666. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  667. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  668. break;
  669. case PointControlType.LeftMiddle:
  670. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  671. break;
  672. case PointControlType.LeftBottom:
  673. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  674. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  675. break;
  676. case PointControlType.MiddlBottom:
  677. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  678. break;
  679. case PointControlType.RightBottom:
  680. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  681. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  682. break;
  683. case PointControlType.RightMiddle:
  684. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  685. break;
  686. case PointControlType.RightTop:
  687. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  688. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  689. break;
  690. case PointControlType.MiddleTop:
  691. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  692. break;
  693. case PointControlType.Rotate:
  694. break;
  695. case PointControlType.Body:
  696. case PointControlType.Line:
  697. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  698. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  699. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  700. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  701. break;
  702. default:
  703. break;
  704. }
  705. drawDc?.DrawRectangle(moveBrush, null, moveRect);
  706. }
  707. /// <summary>
  708. /// Notify the event during/after the drawing data
  709. /// </summary>
  710. /// <param name="isFinish">
  711. /// Identifies whether the data change is complete
  712. /// </param>
  713. protected void InvokeDataChangEvent(bool isFinish)
  714. {
  715. selectedRectData.Square = GetRect();
  716. if (isFinish)
  717. {
  718. DataChanged?.Invoke(this, selectedRectData);
  719. }
  720. else
  721. {
  722. DataChanging?.Invoke(this, selectedRectData);
  723. }
  724. }
  725. /// <summary>
  726. /// Align the rectangle drawing
  727. /// </summary>
  728. /// <param name="RectMovePoint">
  729. /// Move distance required for the aligned algorithm to obtain the rectangle
  730. /// </param>
  731. private void DrawAlignRect(Point RectMovePoint)
  732. {
  733. double TmpLeft, TmpRight, TmpUp, TmpDown;
  734. Point OffsetPos = CalcMoveBound(drawRect, RectMovePoint, maxRect);
  735. TmpLeft = drawRect.Left + OffsetPos.X;
  736. TmpRight = drawRect.Right + OffsetPos.X;
  737. TmpUp = drawRect.Top + OffsetPos.Y;
  738. TmpDown = drawRect.Bottom + OffsetPos.Y;
  739. SetDrawRect = drawRect = new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
  740. Draw();
  741. }
  742. /// <summary>
  743. /// Get the current set of ignore points
  744. /// </summary>
  745. /// <returns>
  746. /// Data set of ignored points
  747. /// </returns>
  748. private List<PointControlType> GetIgnorePoints()
  749. {
  750. List<PointControlType> IgnorePointsList = new List<PointControlType>();
  751. foreach (PointControlType type in ignorePoints)
  752. {
  753. IgnorePointsList.Add(type);
  754. }
  755. return IgnorePointsList;
  756. }
  757. #endregion
  758. }
  759. }