SelectedRect.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.Tool.SettingParam;
  3. using ComPDFKit.Viewer.Layer;
  4. using ComPDFKitViewer;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Controls.Primitives;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Media3D;
  19. using System.Xml.Linq;
  20. using static System.Net.Mime.MediaTypeNames;
  21. namespace ComPDFKit.Tool.DrawTool
  22. {
  23. public enum PointControlType
  24. {
  25. None = -1,
  26. LeftTop,
  27. LeftMiddle,
  28. LeftBottom,
  29. MiddlBottom,
  30. RightBottom,
  31. RightMiddle,
  32. RightTop,
  33. MiddleTop,
  34. Rotate,
  35. Body,
  36. Line
  37. }
  38. public enum SelectedType
  39. {
  40. None = -1,
  41. Annot,
  42. PDFEdit
  43. }
  44. public enum DrawPointType
  45. {
  46. Circle,
  47. Square,
  48. Crop
  49. }
  50. public enum DrawMoveType
  51. {
  52. kDefault,
  53. kReferenceLine,
  54. }
  55. public class SelectedAnnotData
  56. {
  57. /// <summary>
  58. /// Current size of the rectangle
  59. /// </summary>
  60. public Rect Square { get; set; }
  61. /// <summary>
  62. /// Current points of the rectangle
  63. /// </summary>
  64. public PointCollection Points { get; set; }
  65. public AnnotData annotData { get; set; }
  66. }
  67. public partial class SelectedRect : DrawingVisual
  68. {
  69. /// <summary>
  70. /// Re-layout child elements
  71. /// </summary>
  72. public void Arrange()
  73. {
  74. foreach (Visual child in Children)
  75. {
  76. if (!(child is UIElement))
  77. {
  78. continue;
  79. }
  80. UIElement checkChild = child as UIElement;
  81. try
  82. {
  83. double left = Canvas.GetLeft(checkChild);
  84. double top = Canvas.GetTop(checkChild);
  85. double width = (double)checkChild.GetValue(FrameworkElement.WidthProperty);
  86. double height = (double)checkChild.GetValue(FrameworkElement.HeightProperty);
  87. checkChild.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  88. checkChild.Arrange(new Rect(
  89. double.IsNaN(left) ? 0 : left,
  90. double.IsNaN(top) ? 0 : top,
  91. double.IsNaN(width) ? checkChild.DesiredSize.Width : width,
  92. double.IsNaN(height) ? checkChild.DesiredSize.Height : height));
  93. }
  94. catch (Exception ex)
  95. {
  96. }
  97. }
  98. }
  99. protected DefaultDrawParam DrawParam = new DefaultDrawParam();
  100. protected DrawingContext drawDC { get; set; }
  101. /// <summary>
  102. /// Data changing event
  103. /// </summary>
  104. public event EventHandler<SelectedAnnotData> DataChanging;
  105. /// <summary>
  106. /// Data changed event
  107. /// </summary>
  108. public event EventHandler<SelectedAnnotData> DataChanged;
  109. protected bool isHover = false;
  110. protected bool isSelected = false;
  111. protected SelectedType selectedType = SelectedType.None;
  112. public SelectedType GetSelectedType()
  113. {
  114. return selectedType;
  115. }
  116. public void SetIsHover(bool hover)
  117. {
  118. isHover = hover;
  119. }
  120. public bool GetIsHover()
  121. {
  122. return isHover;
  123. }
  124. public void SetIsSelected(bool selected)
  125. {
  126. isSelected = selected;
  127. }
  128. public bool GetIsSelected()
  129. {
  130. return isSelected;
  131. }
  132. public void SetCurrentDrawPointType(DrawPointType type)
  133. {
  134. currentDrawPointType = type;
  135. }
  136. public DrawPointType GetCurrentDrawPointType()
  137. {
  138. return currentDrawPointType;
  139. }
  140. public virtual void OnMouseLeftButtonDown(Point downPoint)
  141. {
  142. isMouseDown = true;
  143. hitControlType = PointControlType.None;
  144. mouseDownPoint = downPoint;
  145. moveOffset = new Point(0, 0);
  146. HitTestResult hitResult = VisualTreeHelper.HitTest(this, downPoint);
  147. if (hitResult != null && hitResult.VisualHit is DrawingVisual)
  148. {
  149. hitControlType = GetHitControlIndex(downPoint);
  150. if (hitControlType != PointControlType.None)
  151. {
  152. cacheRect = drawRect;
  153. }
  154. }
  155. }
  156. public virtual void OnMouseLeftButtonUp(Point upPoint)
  157. {
  158. if (isMouseDown && hitControlType != PointControlType.None)
  159. {
  160. isMouseDown = false;
  161. cacheRect = SetDrawRect = drawRect;
  162. Draw();
  163. if ((int)upPoint.X != (int)mouseDownPoint.X || (int)upPoint.Y != (int)mouseDownPoint.Y)
  164. {
  165. InvokeDataChangEvent(true);
  166. }
  167. }
  168. moveOffset = new Point(0, 0);
  169. }
  170. public virtual void OnMouseMove(Point mousePoint, out bool Tag, double width, double height)
  171. {
  172. PDFViewerActualWidth = width;
  173. PDFViewerActualHeight = height;
  174. Tag = false;
  175. if (isMouseDown && hitControlType != PointControlType.None)
  176. {
  177. Tag = isMouseDown;
  178. if (CalcHitPointMove(mousePoint))
  179. {
  180. Draw();
  181. if ((int)mousePoint.X != (int)mouseDownPoint.X || (int)mousePoint.Y != (int)mouseDownPoint.Y)
  182. {
  183. InvokeDataChangEvent(false);
  184. }
  185. }
  186. }
  187. }
  188. public Cursor GetCursor(Point downPoint, Cursor cursor)
  189. {
  190. if (isMouseDown)
  191. {
  192. return cursor;
  193. }
  194. hitControlType = GetHitControlIndex(downPoint);
  195. switch (hitControlType)
  196. {
  197. case PointControlType.LeftTop:
  198. case PointControlType.RightBottom:
  199. return Cursors.SizeNWSE;
  200. case PointControlType.LeftMiddle:
  201. case PointControlType.RightMiddle:
  202. return Cursors.SizeWE;
  203. case PointControlType.LeftBottom:
  204. case PointControlType.RightTop:
  205. return Cursors.SizeNESW;
  206. case PointControlType.MiddlBottom:
  207. case PointControlType.MiddleTop:
  208. return Cursors.SizeNS;
  209. case PointControlType.Body:
  210. return Cursors.Arrow;
  211. case PointControlType.Line:
  212. return Cursors.SizeAll;
  213. default:
  214. return Cursors.Arrow;
  215. }
  216. }
  217. public SelectedRect(DefaultDrawParam defaultDrawParam, SelectedType type) : base()
  218. {
  219. DrawParam = defaultDrawParam;
  220. currentDrawPointType = DrawPointType.Square;
  221. selectedType = type;
  222. }
  223. public void Draw()
  224. {
  225. Dispatcher.Invoke(() =>
  226. {
  227. Rect currentRect = SetDrawRect;
  228. drawDC = RenderOpen();
  229. switch (currentDrawMoveType)
  230. {
  231. case DrawMoveType.kDefault:
  232. currentRect = drawRect;
  233. CalcControlPoint(currentRect);
  234. break;
  235. case DrawMoveType.kReferenceLine:
  236. CalcControlPoint(currentRect);
  237. if (isMouseDown == true)
  238. {
  239. SolidColorBrush moveBrush = DrawParam.AnnotMoveBrush;
  240. Pen movepen = DrawParam.AnnotMovePen;
  241. GetMoveBrushAndPen(ref moveBrush, ref movepen);
  242. DrawMoveBounds(drawDC, hitControlType, movepen, moveBrush, drawRect);
  243. }
  244. break;
  245. default:
  246. break;
  247. }
  248. SolidColorBrush solidColorBrush = DrawParam.AnnotRectFillBrush;
  249. Pen pen = DrawParam.AnnotRectLinePen;
  250. GetBrushAndPen(ref solidColorBrush, ref pen);
  251. drawDC?.DrawRectangle(solidColorBrush, pen, currentRect);
  252. SolidColorBrush PointBrush = DrawParam.AnnotPointBorderBrush;
  253. Pen PointPen = DrawParam.AnnotPointPen;
  254. GetPointBrushAndPen(ref PointBrush, ref PointPen);
  255. switch (currentDrawPointType)
  256. {
  257. case DrawPointType.Circle:
  258. DrawCirclePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
  259. break;
  260. case DrawPointType.Square:
  261. DrawSquarePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
  262. break;
  263. case DrawPointType.Crop:
  264. DrawCropPoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
  265. break;
  266. }
  267. drawDC?.Close();
  268. drawDC = null;
  269. });
  270. }
  271. private void GetMoveBrushAndPen(ref SolidColorBrush colorBrush, ref Pen pen)
  272. {
  273. switch (selectedType)
  274. {
  275. case SelectedType.None:
  276. break;
  277. case SelectedType.Annot:
  278. colorBrush = DrawParam.AnnotMoveBrush;
  279. pen = DrawParam.AnnotMovePen;
  280. break;
  281. case SelectedType.PDFEdit:
  282. colorBrush = DrawParam.PDFEditMoveBrush;
  283. pen = DrawParam.PDFEditMovePen;
  284. break;
  285. default:
  286. break;
  287. }
  288. }
  289. private void GetPointBrushAndPen(ref SolidColorBrush colorBrush, ref Pen pen)
  290. {
  291. switch (selectedType)
  292. {
  293. case SelectedType.None:
  294. break;
  295. case SelectedType.Annot:
  296. colorBrush = DrawParam.AnnotPointBorderBrush;
  297. pen = DrawParam.AnnotPointPen;
  298. break;
  299. case SelectedType.PDFEdit:
  300. if (isHover)
  301. {
  302. colorBrush = DrawParam.PDFEditRectFillHoverBrush;
  303. pen = DrawParam.PDFEditPointHoverPen;
  304. }
  305. else if (currentDrawPointType == DrawPointType.Crop)
  306. {
  307. colorBrush = DrawParam.SPDFEditCropBorderBrush;//new SolidColorBrush((DrawParam.SPDFEditPointPen.Brush as SolidColorBrush).Color);
  308. pen = DrawParam.SPDFEditPointPen.Clone();
  309. pen.DashStyle = DashStyles.Solid;
  310. }
  311. else
  312. {
  313. if (isSelected)
  314. {
  315. colorBrush = DrawParam.SPDFEditPointBorderBrush;
  316. pen = DrawParam.SPDFEditPointPen;
  317. }
  318. else
  319. {
  320. colorBrush = DrawParam.PDFEditPointBorderBrush;
  321. pen = DrawParam.PDFEditPointPen;
  322. }
  323. }
  324. break;
  325. default:
  326. break;
  327. }
  328. }
  329. private void GetBrushAndPen(ref SolidColorBrush colorBrush, ref Pen pen)
  330. {
  331. switch (selectedType)
  332. {
  333. case SelectedType.None:
  334. break;
  335. case SelectedType.Annot:
  336. if (isHover)
  337. {
  338. colorBrush = DrawParam.AnnotRectFillBrush;
  339. pen = DrawParam.AnnotRectHoverPen;
  340. }
  341. else
  342. {
  343. colorBrush = DrawParam.AnnotRectFillBrush;
  344. pen = DrawParam.AnnotRectLinePen;
  345. }
  346. break;
  347. case SelectedType.PDFEdit:
  348. if (isHover)
  349. {
  350. colorBrush = DrawParam.PDFEditRectFillHoverBrush;
  351. pen = DrawParam.PDFEditRectLineHoverPen;
  352. }
  353. else
  354. {
  355. if (isSelected)
  356. {
  357. colorBrush = DrawParam.SPDFEditRectFillBrush;
  358. pen = DrawParam.SPDFEditRectLinePen;
  359. }
  360. else
  361. {
  362. colorBrush = DrawParam.PDFEditRectFillBrush;
  363. pen = DrawParam.PDFEditRectLinePen;
  364. }
  365. }
  366. break;
  367. default:
  368. break;
  369. }
  370. }
  371. public virtual void ClearDraw()
  372. {
  373. SetDrawRect = drawRect = new Rect();
  374. drawDC = RenderOpen();
  375. drawDC?.Close();
  376. drawDC = null;
  377. }
  378. /// <summary>
  379. /// Hide the drawing
  380. /// </summary>
  381. public virtual void HideDraw()
  382. {
  383. drawDC = RenderOpen();
  384. drawDC?.Close();
  385. }
  386. public void SetRect(Rect newRect,double zoom)
  387. {
  388. if(newRect == Rect.Empty || newRect == null)
  389. {
  390. return;
  391. }
  392. newRect = new Rect((int)(newRect.X - rectPadding* zoom), (int)(newRect.Y - rectPadding* zoom),(int)( newRect.Width + 2 * rectPadding* zoom), (int)(newRect.Height + 2 * rectPadding* zoom));
  393. currentZoom = zoom;
  394. SetDrawRect = drawRect = newRect;
  395. drawCenterPoint = new Point(drawRect.Left + drawRect.Width / 2, drawRect.Top + drawRect.Height / 2);
  396. }
  397. /// <summary>
  398. /// Get the original set Rect, not the calculated fill
  399. /// </summary>
  400. /// <param name="newRect">
  401. /// The new rect to set
  402. /// </param>
  403. public Rect GetRect()
  404. {
  405. Rect rect = new Rect(drawRect.X + rectPadding * currentZoom, drawRect.Y + rectPadding * currentZoom, Math.Max(rectMinWidth, drawRect.Width - 2 * rectPadding * currentZoom), Math.Max(RectMinHeight, drawRect.Height - 2 * rectPadding * currentZoom));
  406. return rect;
  407. }
  408. public void SetRectPadding(double rectPadding)
  409. {
  410. this.rectPadding = rectPadding;
  411. }
  412. public double GetRectPadding()
  413. {
  414. return rectPadding;
  415. }
  416. public Rect GetDrawRect()
  417. {
  418. return drawRect;
  419. }
  420. public void SetMaxRect(Rect rect)
  421. {
  422. maxRect = rect;
  423. }
  424. public Rect GetMaxRect()
  425. {
  426. return maxRect;
  427. }
  428. public void SetAnnotData(AnnotData annotData)
  429. {
  430. SetIgnorePoints(new List<PointControlType>());
  431. SetIsProportionalScaling(false);
  432. isProportionalScaling = false;
  433. switch (annotData.AnnotType)
  434. {
  435. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  436. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  437. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  438. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  439. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  440. case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
  441. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  442. DisableAll();
  443. break;
  444. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  445. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  446. SetIgnorePointsAll();
  447. break;
  448. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  449. SetIsProportionalScaling(true);
  450. break;
  451. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  452. SetIgnorePointsAll();
  453. break;
  454. default:
  455. break;
  456. }
  457. SetMaxRect(annotData.PaintOffset);
  458. SetRect(annotData.PaintRect, annotData.CurrentZoom);
  459. selectedRectData = new SelectedAnnotData();
  460. selectedRectData.annotData = annotData;
  461. }
  462. public void SetIsProportionalScaling(bool isProportionalScaling)
  463. {
  464. this.isProportionalScaling = isProportionalScaling;
  465. ignorePoints.Clear();
  466. if (isProportionalScaling)
  467. {
  468. ignorePoints.Add(PointControlType.LeftMiddle);
  469. ignorePoints.Add(PointControlType.MiddlBottom);
  470. ignorePoints.Add(PointControlType.RightMiddle);
  471. ignorePoints.Add(PointControlType.MiddleTop);
  472. ignorePoints.Add(PointControlType.Rotate);
  473. }
  474. }
  475. public void SetDrawType(DrawPointType drawType)
  476. {
  477. currentDrawPointType = drawType;
  478. }
  479. public void SetDrawMoveType(DrawMoveType drawType)
  480. {
  481. currentDrawMoveType = drawType;
  482. }
  483. /// <summary>
  484. /// Set the types that need to be ignored
  485. /// </summary>
  486. /// <param name="types">
  487. /// The collection of point types that need to be ignored
  488. /// </param>
  489. public void SetIgnorePoints(List<PointControlType> types)
  490. {
  491. ignorePoints.Clear();
  492. foreach (PointControlType type in types)
  493. {
  494. ignorePoints.Add(type);
  495. }
  496. }
  497. /// <summary>
  498. /// Ignore all points
  499. /// </summary>
  500. public void SetIgnorePointsAll()
  501. {
  502. ignorePoints.Clear();
  503. ignorePoints.Add(PointControlType.LeftTop);
  504. ignorePoints.Add(PointControlType.LeftMiddle);
  505. ignorePoints.Add(PointControlType.LeftBottom);
  506. ignorePoints.Add(PointControlType.MiddlBottom);
  507. ignorePoints.Add(PointControlType.RightBottom);
  508. ignorePoints.Add(PointControlType.RightMiddle);
  509. ignorePoints.Add(PointControlType.RightTop);
  510. ignorePoints.Add(PointControlType.MiddleTop);
  511. }
  512. /// <summary>
  513. /// Disable all functions
  514. /// </summary>
  515. public void DisableAll()
  516. {
  517. ignorePoints.Clear();
  518. ignorePoints.Add(PointControlType.LeftTop);
  519. ignorePoints.Add(PointControlType.LeftMiddle);
  520. ignorePoints.Add(PointControlType.LeftBottom);
  521. ignorePoints.Add(PointControlType.MiddlBottom);
  522. ignorePoints.Add(PointControlType.RightBottom);
  523. ignorePoints.Add(PointControlType.RightMiddle);
  524. ignorePoints.Add(PointControlType.RightTop);
  525. ignorePoints.Add(PointControlType.MiddleTop);
  526. ignorePoints.Add(PointControlType.Rotate);
  527. ignorePoints.Add(PointControlType.Body);
  528. ignorePoints.Add(PointControlType.Line);
  529. }
  530. /// <summary>
  531. /// Set the left alignment in the set maximum rectangle
  532. /// </summary>
  533. public virtual void SetAlignLeftForMaxRect()
  534. {
  535. DrawAlignRect(AlignmentsHelp.SetAlignLeft(drawRect, maxRect));
  536. }
  537. /// <summary>
  538. /// Set horizontal center alignment in the set maximum rectangle
  539. /// </summary>
  540. public virtual void SetAlignHorizonCenterForMaxRect()
  541. {
  542. DrawAlignRect(AlignmentsHelp.SetAlignHorizonCenter(drawRect, maxRect));
  543. }
  544. /// <summary>
  545. /// Set horizontal right alignment in the set maximum rectangle
  546. /// </summary>
  547. public virtual void SetAlignRightForMaxRect()
  548. {
  549. DrawAlignRect(AlignmentsHelp.SetAlignRight(drawRect, maxRect));
  550. }
  551. /// <summary>
  552. /// Set the top alignment in the set maximum rectangle
  553. /// </summary>
  554. public virtual void SetAlignTopForMaxRect()
  555. {
  556. DrawAlignRect(AlignmentsHelp.SetAlignTop(drawRect, maxRect));
  557. }
  558. /// <summary>
  559. /// Set vertical center alignment in the set maximum rectangle
  560. /// </summary>
  561. public virtual void SetAlignVerticalCenterForMaxRect()
  562. {
  563. DrawAlignRect(AlignmentsHelp.SetAlignVerticalCenter(drawRect, maxRect));
  564. }
  565. /// <summary>
  566. /// Set vertical center alignment in the set maximum rectangle
  567. /// </summary>
  568. public virtual void SetAlignHorizonVerticalCenterForMaxRect()
  569. {
  570. DrawAlignRect(AlignmentsHelp.SetAlignHorizonVerticalCenter(drawRect, maxRect));
  571. }
  572. /// <summary>
  573. /// Set the bottom alignment in the set maximum rectangle
  574. /// </summary>
  575. public virtual void SetAlignBottomForMaxRect()
  576. {
  577. DrawAlignRect(AlignmentsHelp.SetAlignBottom(drawRect, maxRect));
  578. }
  579. /// <summary>
  580. /// Get which control point the coordinate is on
  581. /// </summary>
  582. /// <param name="clickPoint">
  583. /// The point to check
  584. /// </param>
  585. /// <returns>
  586. /// The control point type
  587. /// </returns>
  588. public PointControlType GetHitControlIndex(Point point, bool isIgnore=true)
  589. {
  590. HitTestResult hitResult = VisualTreeHelper.HitTest(this, point);
  591. if (hitResult != null && hitResult.VisualHit is DrawingVisual)
  592. {
  593. List<PointControlType> ignoreList = GetIgnorePoints();
  594. List<Point> IgnorePointsList = new List<Point>();
  595. foreach (PointControlType type in ignoreList)
  596. {
  597. if ((int)type < controlPoints.Count)
  598. {
  599. IgnorePointsList.Add(controlPoints[(int)type]);
  600. }
  601. }
  602. for (int i = 0; i < controlPoints.Count; i++)
  603. {
  604. Point checkPoint = controlPoints[i];
  605. if (isIgnore&&IgnorePointsList.Contains(checkPoint))
  606. {
  607. continue;
  608. }
  609. switch (currentDrawPointType)
  610. {
  611. case DrawPointType.Circle:
  612. Vector checkVector = checkPoint - point;
  613. if (checkVector.Length < pointSize)
  614. {
  615. return (PointControlType)i;
  616. }
  617. break;
  618. case DrawPointType.Square:
  619. Rect checkRect = new Rect(Math.Max(checkPoint.X - pointSize,0), Math.Max(checkPoint.Y - pointSize,0), pointSize * 2, pointSize * 2);
  620. if (checkRect.Contains(point))
  621. {
  622. return (PointControlType)i;
  623. }
  624. break;
  625. case DrawPointType.Crop:
  626. Rect cropRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
  627. if (cropRect.Contains(point))
  628. {
  629. return (PointControlType)i;
  630. }
  631. break;
  632. default:
  633. break;
  634. }
  635. }
  636. if (drawRect.Contains(point))
  637. {
  638. double rectWidth = (drawRect.Width - 2 * rectPadding > 0)? drawRect.Width - 2 * rectPadding: 0;
  639. double rectHeight = (drawRect.Height - 2 * rectPadding > 0)? drawRect.Height - 2 * rectPadding: 0;
  640. Rect rect = new Rect(Math.Max(drawRect.X + rectPadding,0),Math.Max( drawRect.Y + rectPadding,0), rectWidth, rectHeight);
  641. if (rect.Contains(point))
  642. {
  643. if (!ignoreList.Contains(PointControlType.Body))
  644. {
  645. return PointControlType.Body;
  646. }
  647. }
  648. if (!ignoreList.Contains(PointControlType.Body))
  649. {
  650. return PointControlType.Line;
  651. }
  652. }
  653. }
  654. return PointControlType.None;
  655. }
  656. }
  657. }