SelectedRect.protected.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  1. using ComPDFKit.Import;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Windows;
  6. using System.Windows.Media;
  7. using static ComPDFKit.Tool.Help.ImportWin32;
  8. namespace ComPDFKit.Tool.DrawTool
  9. {
  10. public partial class SelectedRect
  11. {
  12. #region Properties
  13. /// <summary>
  14. /// Current control point drawing style.
  15. /// </summary>
  16. protected DrawPointType currentDrawPointType
  17. {
  18. get;
  19. set;
  20. }
  21. /// <summary>
  22. /// Current drag drawing style.
  23. /// </summary>
  24. protected DrawMoveType currentDrawMoveType { get; set; }
  25. /// <summary>
  26. /// Current click hit control point.
  27. /// </summary>
  28. protected PointControlType hitControlType { get; set; }
  29. /// <summary>
  30. /// Mouse down position information.
  31. /// </summary>
  32. protected Point mouseDownPoint { get; set; }
  33. /// <summary>
  34. /// Whether the mouse is pressed.
  35. /// </summary>
  36. protected bool isMouseDown { get; set; }
  37. /// <summary>
  38. /// Whether proportional scaling is required.
  39. /// </summary>
  40. protected bool isProportionalScaling { get; set; } = false;
  41. /// <summary>
  42. /// Current control point size.
  43. /// </summary>
  44. protected int pointSize { get; set; } = 4;
  45. /// <summary>
  46. /// Rectangular minimum width.
  47. /// </summary>
  48. protected int rectMinWidth { get; set; } = 10;
  49. /// <summary>
  50. /// Rectangular minimum height.
  51. /// </summary>
  52. protected int RectMinHeight { get; set; } = 10;
  53. /// <summary>
  54. /// Current set of ignore points.
  55. /// </summary>
  56. protected List<PointControlType> ignorePoints { get; set; } = new List<PointControlType>();
  57. /// <summary>
  58. /// Current set of drawing rectangles (original data).
  59. /// </summary>
  60. protected Rect SetDrawRect { get; set; } = new Rect(0, 0, 0, 0);
  61. /// <summary>
  62. /// Current drawing rectangle (calculated during operation).
  63. /// </summary>
  64. protected Rect drawRect { get; set; } = new Rect(0, 0, 0, 0);
  65. /// <summary>
  66. /// Maximum range that can be drawn.
  67. /// </summary>
  68. protected Rect maxRect { get; set; } = new Rect(0, 0, 0, 0);
  69. /// <summary>
  70. /// Current center point of the drawing rectangle.
  71. /// </summary>
  72. protected Point drawCenterPoint { get; private set; } = new Point(0, 0);
  73. /// <summary>
  74. /// When the mouse is pressed, the cached rectangle.
  75. /// </summary>
  76. protected Rect cacheRect { get; set; } = new Rect(0, 0, 0, 0);
  77. /// <summary>
  78. /// Current control point coordinates.
  79. /// </summary>
  80. protected List<Point> controlPoints { get; set; } = new List<Point>();
  81. /// <summary>
  82. /// Move offset during movement.
  83. /// </summary>
  84. protected Point moveOffset { get; set; } = new Point(0, 0);
  85. /// <summary>
  86. /// Current drawing rectangle (calculated during operation).
  87. /// </summary>
  88. protected Thickness clipThickness = new Thickness(0, 0, 0, 0);
  89. private Pen editPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
  90. private Pen editHoverPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
  91. private bool showCreatTextRect = false;
  92. protected bool isOutSideScaling = false;
  93. /// <summary>
  94. /// Current actual display width and height of PDFVIewer.
  95. /// </summary>
  96. protected double PDFViewerActualWidth { get; set; } = 0;
  97. protected double PDFViewerActualHeight { get; set; } = 0;
  98. protected double rectPadding = 6;
  99. protected double currentZoom = 1;
  100. protected SelectedAnnotData selectedRectData = new SelectedAnnotData();
  101. protected bool disable = false;
  102. private double RotateSize { get; set; } = 5;
  103. #endregion
  104. #region Functions
  105. /// <summary>
  106. /// Calcuate the control points
  107. /// </summary>
  108. /// <param name="currentRect">
  109. /// Control points in the target rectangle
  110. /// </param>
  111. protected void CalcControlPoint(Rect currentRect)
  112. {
  113. controlPoints.Clear();
  114. double centerX = (currentRect.Left + currentRect.Right) / 2;
  115. double centerY = (currentRect.Top + currentRect.Bottom) / 2;
  116. controlPoints.Add(new Point(currentRect.Left, currentRect.Top));
  117. controlPoints.Add(new Point(currentRect.Left, centerY));
  118. controlPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
  119. controlPoints.Add(new Point(centerX, currentRect.Bottom));
  120. controlPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
  121. controlPoints.Add(new Point(currentRect.Right, centerY));
  122. controlPoints.Add(new Point(currentRect.Right, currentRect.Top));
  123. controlPoints.Add(new Point(centerX, currentRect.Top));
  124. }
  125. protected List<Point> GetControlPoint(Rect currentRect)
  126. {
  127. List<Point> controlCurrentPoints = new List<Point>();
  128. controlCurrentPoints.Clear();
  129. int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
  130. int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
  131. controlCurrentPoints.Add(new Point(currentRect.Left, currentRect.Top));
  132. controlCurrentPoints.Add(new Point(currentRect.Left, centerY));
  133. controlCurrentPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
  134. controlCurrentPoints.Add(new Point(centerX, currentRect.Bottom));
  135. controlCurrentPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
  136. controlCurrentPoints.Add(new Point(currentRect.Right, centerY));
  137. controlCurrentPoints.Add(new Point(currentRect.Right, currentRect.Top));
  138. controlCurrentPoints.Add(new Point(centerX, currentRect.Top));
  139. return controlCurrentPoints;
  140. }
  141. /// <summary>
  142. /// Calcuate the offset of the current rectangle in the maximum rectangle range
  143. /// </summary>
  144. /// <param name="currentRect">
  145. /// The rectangle cached when pressed
  146. /// </param>
  147. /// <param name="offsetPoint">
  148. /// Equivalent to the offset value when pressed
  149. /// </param>
  150. /// <param name="maxRect">
  151. /// The maximum rectangle range.
  152. /// </param>
  153. /// <returns></returns>
  154. protected Point CalcMoveBound(Rect currentRect, Point offsetPoint, Rect maxRect)
  155. {
  156. double cLeft = currentRect.Left;
  157. double cRight = currentRect.Right;
  158. double cUp = currentRect.Top;
  159. double cDown = currentRect.Bottom;
  160. double TmpLeft = cLeft + offsetPoint.X;
  161. double TmpRight = cRight + offsetPoint.X;
  162. double TmpUp = cUp + offsetPoint.Y;
  163. double TmpDown = cDown + offsetPoint.Y;
  164. if (TmpLeft < maxRect.Left)
  165. {
  166. TmpRight = (cRight - cLeft) + maxRect.Left;
  167. TmpLeft = maxRect.Left;
  168. }
  169. if (TmpUp < maxRect.Top)
  170. {
  171. TmpDown = (cDown - cUp) + maxRect.Top;
  172. TmpUp = maxRect.Top;
  173. }
  174. if (TmpRight > maxRect.Right)
  175. {
  176. TmpLeft = maxRect.Right - (cRight - cLeft);
  177. TmpRight = maxRect.Right;
  178. }
  179. if (TmpDown > maxRect.Bottom)
  180. {
  181. TmpUp = maxRect.Bottom - (cDown - cUp);
  182. TmpDown = maxRect.Bottom;
  183. }
  184. offsetPoint = new Point(TmpLeft - cLeft, TmpUp - cUp);
  185. return offsetPoint;
  186. }
  187. /// <summary>
  188. /// Calculate the movement of the hit point
  189. /// </summary>
  190. /// <param name="mousePoint">
  191. /// Current mouse position
  192. /// </param>
  193. /// <returns>
  194. /// Whether the movement is successful
  195. /// </returns>
  196. protected bool CalcHitPointMove(Point mousePoint)
  197. {
  198. if (isMouseDown == false || hitControlType == PointControlType.None)
  199. {
  200. return false;
  201. }
  202. if (!isOutSideScaling)
  203. {
  204. return NormalScaling(mousePoint);
  205. }
  206. else
  207. {
  208. return OutSideScaling(mousePoint);
  209. }
  210. }
  211. public void SetOutSideScaling(bool IsOutSideScaling)
  212. {
  213. isOutSideScaling = IsOutSideScaling;
  214. }
  215. private Size GetProportionalScalingSize(double width, double height)
  216. {
  217. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  218. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  219. if (minWidth > width || minHeight > height)
  220. {
  221. if (cacheRect.Width >= cacheRect.Height)
  222. {
  223. width = cacheRect.Width * minHeight / cacheRect.Height;
  224. height = minHeight;
  225. }
  226. else
  227. {
  228. height = cacheRect.Height * minWidth / cacheRect.Width;
  229. width = minWidth;
  230. }
  231. }
  232. return new Size(width, height);
  233. }
  234. /// <summary>
  235. /// Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
  236. /// </summary>
  237. /// <param name="mousePoint">Current mouse position.</param>
  238. /// <returns></returns>
  239. protected bool NormalScaling(Point mousePoint)
  240. {
  241. if (CanRotate)
  242. {
  243. return RotateScaling(mousePoint);
  244. }
  245. return GenerallyScaling(mousePoint);
  246. }
  247. private bool GenerallyScaling(Point mousePoint)
  248. {
  249. try
  250. {
  251. double left = 0, right = 0, top = 0, bottom = 0;
  252. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  253. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  254. Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
  255. Point moveVector = (Point)(mousePoint - centerPoint);
  256. moveVector = ProportionalScalingOffsetPos(moveVector);
  257. switch (hitControlType)
  258. {
  259. case PointControlType.LeftTop:
  260. {
  261. left = centerPoint.X + moveVector.X;
  262. right = cacheRect.Right;
  263. top = centerPoint.Y + moveVector.Y;
  264. bottom = cacheRect.Bottom;
  265. if (isProportionalScaling)
  266. {
  267. Size size = GetProportionalScalingSize(right - left, bottom - top);
  268. left = right - size.Width;
  269. top = bottom - size.Height;
  270. if (left < maxRect.Left)
  271. {
  272. double tmpWidth = right - left;
  273. left = maxRect.Left;
  274. double width = right - left;
  275. double height = (bottom - top) * width / tmpWidth;
  276. top = bottom - height;
  277. }
  278. if (top < maxRect.Top)
  279. {
  280. double tmpHeight = bottom - top;
  281. top = maxRect.Top;
  282. double height = bottom - top;
  283. double width = (right - left) * height / tmpHeight;
  284. left = right - width;
  285. }
  286. }
  287. else
  288. {
  289. if (left + minWidth > right)
  290. {
  291. left = right - minWidth;
  292. }
  293. if (top + minHeight > bottom)
  294. {
  295. top = bottom - minHeight;
  296. }
  297. }
  298. }
  299. break;
  300. case PointControlType.LeftMiddle:
  301. {
  302. left = centerPoint.X + moveVector.X;
  303. right = cacheRect.Right;
  304. top = cacheRect.Top;
  305. bottom = cacheRect.Bottom;
  306. if (left + minWidth > right)
  307. {
  308. left = right - minWidth;
  309. }
  310. }
  311. break;
  312. case PointControlType.LeftBottom:
  313. {
  314. left = centerPoint.X + moveVector.X;
  315. right = cacheRect.Right;
  316. top = cacheRect.Top;
  317. bottom = centerPoint.Y + moveVector.Y;
  318. if (isProportionalScaling)
  319. {
  320. Size size = GetProportionalScalingSize(right - left, bottom - top);
  321. left = right - size.Width;
  322. bottom = top + size.Height;
  323. if (left < maxRect.Left)
  324. {
  325. double tmpWidth = right - left;
  326. left = maxRect.Left;
  327. double width = right - left;
  328. double height = (bottom - top) * width / tmpWidth;
  329. bottom = top + height;
  330. }
  331. if (bottom > maxRect.Bottom)
  332. {
  333. double tmpHeight = bottom - top;
  334. bottom = maxRect.Bottom;
  335. double height = bottom - top;
  336. double width = (right - left) * height / tmpHeight;
  337. left = right - width;
  338. }
  339. }
  340. else
  341. {
  342. if (left + minWidth > right)
  343. {
  344. left = right - minWidth;
  345. }
  346. if (top + minHeight > bottom)
  347. {
  348. bottom = top + minHeight;
  349. }
  350. }
  351. }
  352. break;
  353. case PointControlType.MiddlBottom:
  354. {
  355. left = cacheRect.Left;
  356. right = cacheRect.Right;
  357. top = cacheRect.Top;
  358. bottom = centerPoint.Y + moveVector.Y;
  359. if (top + minHeight > bottom)
  360. {
  361. bottom = top + minHeight;
  362. }
  363. }
  364. break;
  365. case PointControlType.RightBottom:
  366. {
  367. left = cacheRect.Left;
  368. right = centerPoint.X + moveVector.X;
  369. top = cacheRect.Top;
  370. bottom = centerPoint.Y + moveVector.Y;
  371. if (isProportionalScaling)
  372. {
  373. Size size = GetProportionalScalingSize(right - left, bottom - top);
  374. right = left + size.Width;
  375. bottom = top + size.Height;
  376. if (right > maxRect.Right)
  377. {
  378. double tmpWidth = right - left;
  379. right = maxRect.Right;
  380. double width = right - left;
  381. double height = (bottom - top) * width / tmpWidth;
  382. bottom = top + height;
  383. }
  384. if (bottom > maxRect.Bottom)
  385. {
  386. double tmpHeight = bottom - top;
  387. bottom = maxRect.Bottom;
  388. double height = bottom - top;
  389. double width = (right - left) * height / tmpHeight;
  390. right = left + width;
  391. }
  392. }
  393. else
  394. {
  395. if (left + minWidth > right)
  396. {
  397. right = left + minWidth;
  398. }
  399. if (top + minHeight > bottom)
  400. {
  401. bottom = top + minHeight;
  402. }
  403. }
  404. }
  405. break;
  406. case PointControlType.RightMiddle:
  407. {
  408. left = cacheRect.Left;
  409. right = centerPoint.X + moveVector.X;
  410. top = cacheRect.Top;
  411. bottom = cacheRect.Bottom;
  412. if (left + minWidth > right)
  413. {
  414. right = left + minWidth;
  415. }
  416. }
  417. break;
  418. case PointControlType.RightTop:
  419. {
  420. left = cacheRect.Left;
  421. right = centerPoint.X + moveVector.X;
  422. top = centerPoint.Y + moveVector.Y;
  423. bottom = cacheRect.Bottom;
  424. if (isProportionalScaling)
  425. {
  426. Size size = GetProportionalScalingSize(right - left, bottom - top);
  427. right = left + size.Width;
  428. top = bottom - size.Height;
  429. if (right > maxRect.Right)
  430. {
  431. double tmpWidth = right - left;
  432. right = maxRect.Right;
  433. double width = right - left;
  434. double height = (bottom - top) * width / tmpWidth;
  435. top = bottom - height;
  436. }
  437. if (top < maxRect.Top)
  438. {
  439. double tmpHeight = bottom - top;
  440. top = maxRect.Top;
  441. double height = bottom - top;
  442. double width = (right - left) * height / tmpHeight;
  443. right = left + width;
  444. }
  445. }
  446. else
  447. {
  448. if (left + minWidth > right)
  449. {
  450. right = left + minWidth;
  451. }
  452. if (top + minHeight > bottom)
  453. {
  454. top = bottom - minHeight;
  455. }
  456. }
  457. }
  458. break;
  459. case PointControlType.MiddleTop:
  460. {
  461. left = cacheRect.Left;
  462. right = cacheRect.Right;
  463. top = centerPoint.Y + moveVector.Y;
  464. bottom = cacheRect.Bottom;
  465. if (top + minHeight > bottom)
  466. {
  467. top = bottom - minHeight;
  468. }
  469. }
  470. break;
  471. case PointControlType.Body:
  472. case PointControlType.Line:
  473. {
  474. Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), maxRect);
  475. left = cacheRect.Left + OffsetPos.X;
  476. right = cacheRect.Right + OffsetPos.X;
  477. top = cacheRect.Top + OffsetPos.Y;
  478. bottom = cacheRect.Bottom + OffsetPos.Y;
  479. }
  480. break;
  481. case PointControlType.Rotate:
  482. {
  483. Point rotatPoint = new Point(centerPoint.X, centerPoint.Y - cacheRect.Height / 2 - rotateline);
  484. Vector startVector = rotatPoint - centerPoint;
  485. Vector currentVector = mousePoint - centerPoint;
  486. angle = Vector.AngleBetween(startVector, currentVector);
  487. }
  488. break;
  489. default:
  490. break;
  491. }
  492. if (left < maxRect.Left)
  493. {
  494. left = maxRect.Left;
  495. }
  496. if (top < maxRect.Top)
  497. {
  498. top = maxRect.Top;
  499. }
  500. if (right > maxRect.Right)
  501. {
  502. right = maxRect.Right;
  503. }
  504. if (bottom > maxRect.Bottom)
  505. {
  506. bottom = maxRect.Bottom;
  507. }
  508. drawRect = new Rect(left, top, right - left, bottom - top);
  509. moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
  510. return true;
  511. }
  512. catch (Exception ex)
  513. {
  514. }
  515. return false;
  516. }
  517. private Point CalcRotateRawPoint(Point calcPoint)
  518. {
  519. if(CanRotate==false || angle==0)
  520. {
  521. return calcPoint;
  522. }
  523. //旋转回去
  524. Vector currentVector = calcPoint - rotateCenter;
  525. Matrix matrix = new Matrix();
  526. matrix.Rotate(-angle);
  527. Vector transVector = matrix.Transform(currentVector);
  528. Point checkPos = new Point(rotateCenter.X + transVector.X, rotateCenter.Y + transVector.Y);
  529. return checkPos;
  530. }
  531. private bool RotateScaling(Point uiPoint)
  532. {
  533. try
  534. {
  535. //旋转回去
  536. Point mousePoint = CalcRotateRawPoint(uiPoint);
  537. double left = 0, right = 0, top = 0, bottom = 0;
  538. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  539. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  540. Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
  541. Point moveVector = (Point)(mousePoint - centerPoint);
  542. moveVector = ProportionalScalingOffsetPos(moveVector);
  543. switch (hitControlType)
  544. {
  545. case PointControlType.LeftTop:
  546. {
  547. left = centerPoint.X + moveVector.X;
  548. right = cacheRect.Right;
  549. top = centerPoint.Y + moveVector.Y;
  550. bottom = cacheRect.Bottom;
  551. if (isProportionalScaling)
  552. {
  553. Size size = GetProportionalScalingSize(right - left, bottom - top);
  554. left = right - size.Width;
  555. top = bottom - size.Height;
  556. if (left < maxRect.Left)
  557. {
  558. double tmpWidth = right - left;
  559. left = maxRect.Left;
  560. double width = right - left;
  561. double height = (bottom - top) * width / tmpWidth;
  562. top = bottom - height;
  563. }
  564. if (top < maxRect.Top)
  565. {
  566. double tmpHeight = bottom - top;
  567. top = maxRect.Top;
  568. double height = bottom - top;
  569. double width = (right - left) * height / tmpHeight;
  570. left = right - width;
  571. }
  572. }
  573. else
  574. {
  575. if (left + minWidth > right)
  576. {
  577. left = right - minWidth;
  578. }
  579. if (top + minHeight > bottom)
  580. {
  581. top = bottom - minHeight;
  582. }
  583. }
  584. }
  585. break;
  586. case PointControlType.LeftMiddle:
  587. {
  588. left = centerPoint.X + moveVector.X;
  589. right = cacheRect.Right;
  590. top = cacheRect.Top;
  591. bottom = cacheRect.Bottom;
  592. if (left + minWidth > right)
  593. {
  594. left = right - minWidth;
  595. }
  596. }
  597. break;
  598. case PointControlType.LeftBottom:
  599. {
  600. left = centerPoint.X + moveVector.X;
  601. right = cacheRect.Right;
  602. top = cacheRect.Top;
  603. bottom = centerPoint.Y + moveVector.Y;
  604. if (isProportionalScaling)
  605. {
  606. Size size = GetProportionalScalingSize(right - left, bottom - top);
  607. left = right - size.Width;
  608. bottom = top + size.Height;
  609. if (left < maxRect.Left)
  610. {
  611. double tmpWidth = right - left;
  612. left = maxRect.Left;
  613. double width = right - left;
  614. double height = (bottom - top) * width / tmpWidth;
  615. bottom = top + height;
  616. }
  617. if (bottom > maxRect.Bottom)
  618. {
  619. double tmpHeight = bottom - top;
  620. bottom = maxRect.Bottom;
  621. double height = bottom - top;
  622. double width = (right - left) * height / tmpHeight;
  623. left = right - width;
  624. }
  625. }
  626. else
  627. {
  628. if (left + minWidth > right)
  629. {
  630. left = right - minWidth;
  631. }
  632. if (top + minHeight > bottom)
  633. {
  634. bottom = top + minHeight;
  635. }
  636. }
  637. }
  638. break;
  639. case PointControlType.MiddlBottom:
  640. {
  641. left = cacheRect.Left;
  642. right = cacheRect.Right;
  643. top = cacheRect.Top;
  644. bottom = centerPoint.Y + moveVector.Y;
  645. if (top + minHeight > bottom)
  646. {
  647. bottom = top + minHeight;
  648. }
  649. }
  650. break;
  651. case PointControlType.RightBottom:
  652. {
  653. left = cacheRect.Left;
  654. right = centerPoint.X + moveVector.X;
  655. top = cacheRect.Top;
  656. bottom = centerPoint.Y + moveVector.Y;
  657. if (isProportionalScaling)
  658. {
  659. Size size = GetProportionalScalingSize(right - left, bottom - top);
  660. right = left + size.Width;
  661. bottom = top + size.Height;
  662. if (right > maxRect.Right)
  663. {
  664. double tmpWidth = right - left;
  665. right = maxRect.Right;
  666. double width = right - left;
  667. double height = (bottom - top) * width / tmpWidth;
  668. bottom = top + height;
  669. }
  670. if (bottom > maxRect.Bottom)
  671. {
  672. double tmpHeight = bottom - top;
  673. bottom = maxRect.Bottom;
  674. double height = bottom - top;
  675. double width = (right - left) * height / tmpHeight;
  676. right = left + width;
  677. }
  678. }
  679. else
  680. {
  681. if (left + minWidth > right)
  682. {
  683. right = left + minWidth;
  684. }
  685. if (top + minHeight > bottom)
  686. {
  687. bottom = top + minHeight;
  688. }
  689. }
  690. }
  691. break;
  692. case PointControlType.RightMiddle:
  693. {
  694. left = cacheRect.Left;
  695. right = centerPoint.X + moveVector.X;
  696. top = cacheRect.Top;
  697. bottom = cacheRect.Bottom;
  698. if (left + minWidth > right)
  699. {
  700. right = left + minWidth;
  701. }
  702. }
  703. break;
  704. case PointControlType.RightTop:
  705. {
  706. left = cacheRect.Left;
  707. right = centerPoint.X + moveVector.X;
  708. top = centerPoint.Y + moveVector.Y;
  709. bottom = cacheRect.Bottom;
  710. if (isProportionalScaling)
  711. {
  712. Size size = GetProportionalScalingSize(right - left, bottom - top);
  713. right = left + size.Width;
  714. top = bottom - size.Height;
  715. if (right > maxRect.Right)
  716. {
  717. double tmpWidth = right - left;
  718. right = maxRect.Right;
  719. double width = right - left;
  720. double height = (bottom - top) * width / tmpWidth;
  721. top = bottom - height;
  722. }
  723. if (top < maxRect.Top)
  724. {
  725. double tmpHeight = bottom - top;
  726. top = maxRect.Top;
  727. double height = bottom - top;
  728. double width = (right - left) * height / tmpHeight;
  729. right = left + width;
  730. }
  731. }
  732. else
  733. {
  734. if (left + minWidth > right)
  735. {
  736. right = left + minWidth;
  737. }
  738. if (top + minHeight > bottom)
  739. {
  740. top = bottom - minHeight;
  741. }
  742. }
  743. }
  744. break;
  745. case PointControlType.MiddleTop:
  746. {
  747. left = cacheRect.Left;
  748. right = cacheRect.Right;
  749. top = centerPoint.Y + moveVector.Y;
  750. bottom = cacheRect.Bottom;
  751. if (top + minHeight > bottom)
  752. {
  753. top = bottom - minHeight;
  754. }
  755. }
  756. break;
  757. case PointControlType.Body:
  758. case PointControlType.Line:
  759. {
  760. Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(uiPoint -mouseDownPoint)), maxRect);
  761. left = cacheRect.Left + OffsetPos.X;
  762. right = cacheRect.Right + OffsetPos.X;
  763. top = cacheRect.Top + OffsetPos.Y;
  764. bottom = cacheRect.Bottom + OffsetPos.Y;
  765. }
  766. break;
  767. case PointControlType.Rotate:
  768. {
  769. Point rotatPoint = new Point(rotateCenter.X, rotateCenter.Y - cacheRect.Height / 2 - rotateline);
  770. Vector startVector = rotatPoint - rotateCenter;
  771. Vector endVector = uiPoint - rotateCenter;
  772. angle = Vector.AngleBetween(startVector, endVector);
  773. }
  774. break;
  775. default:
  776. break;
  777. }
  778. if (left < maxRect.Left)
  779. {
  780. left = maxRect.Left;
  781. }
  782. if (top < maxRect.Top)
  783. {
  784. top = maxRect.Top;
  785. }
  786. if (right > maxRect.Right)
  787. {
  788. right = maxRect.Right;
  789. }
  790. if (bottom > maxRect.Bottom)
  791. {
  792. bottom = maxRect.Bottom;
  793. }
  794. drawRect = new Rect(left, top, right - left, bottom - top);
  795. moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
  796. return true;
  797. }
  798. catch (Exception ex)
  799. {
  800. }
  801. return false;
  802. }
  803. /// <summary>
  804. /// Provisional logic, to be further improved, not yet used: Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
  805. /// </summary>
  806. /// <param name="mousePoint">Current mouse position.</param>
  807. /// <returns></returns>
  808. protected bool OutSideScaling(Point mousePoint)
  809. {
  810. try
  811. {
  812. double left = 0, right = 0, top = 0, bottom = 0;
  813. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  814. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  815. Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
  816. Point moveVector = (Point)(mousePoint - centerPoint);
  817. moveVector = ProportionalScalingOffsetPos(moveVector);
  818. switch (hitControlType)
  819. {
  820. case PointControlType.LeftTop:
  821. {
  822. left = centerPoint.X + moveVector.X;
  823. right = cacheRect.Right;
  824. top = centerPoint.Y + moveVector.Y;
  825. bottom = cacheRect.Bottom;
  826. if (isProportionalScaling)
  827. {
  828. Size size = GetProportionalScalingSize(right - left, bottom - top);
  829. left = right - size.Width;
  830. top = bottom - size.Height;
  831. if (left < maxRect.Left)
  832. {
  833. double tmpWidth = right - left;
  834. left = maxRect.Left;
  835. double width = right - left;
  836. double height = (bottom - top) * width / tmpWidth;
  837. top = bottom - height;
  838. }
  839. if (top < maxRect.Top)
  840. {
  841. double tmpHeight = bottom - top;
  842. top = maxRect.Top;
  843. double height = bottom - top;
  844. double width = (right - left) * height / tmpHeight;
  845. left = right - width;
  846. }
  847. }
  848. else
  849. {
  850. if (left + minWidth > right)
  851. {
  852. left = right - minWidth;
  853. }
  854. if (top + minHeight > bottom)
  855. {
  856. top = bottom - minHeight;
  857. }
  858. }
  859. }
  860. break;
  861. case PointControlType.LeftMiddle:
  862. {
  863. left = centerPoint.X + moveVector.X;
  864. right = cacheRect.Right;
  865. top = cacheRect.Top;
  866. bottom = cacheRect.Bottom;
  867. if (left + minWidth > right)
  868. {
  869. left = right - minWidth;
  870. }
  871. }
  872. break;
  873. case PointControlType.LeftBottom:
  874. {
  875. left = centerPoint.X + moveVector.X;
  876. right = cacheRect.Right;
  877. top = cacheRect.Top;
  878. bottom = centerPoint.Y + moveVector.Y;
  879. if (isProportionalScaling)
  880. {
  881. Size size = GetProportionalScalingSize(right - left, bottom - top);
  882. left = right - size.Width;
  883. bottom = top + size.Height;
  884. if (left < maxRect.Left)
  885. {
  886. double tmpWidth = right - left;
  887. left = maxRect.Left;
  888. double width = right - left;
  889. double height = (bottom - top) * width / tmpWidth;
  890. bottom = top + height;
  891. }
  892. if (bottom > maxRect.Bottom)
  893. {
  894. double tmpHeight = bottom - top;
  895. bottom = maxRect.Bottom;
  896. double height = bottom - top;
  897. double width = (right - left) * height / tmpHeight;
  898. left = right - width;
  899. }
  900. }
  901. else
  902. {
  903. if (left + minWidth > right)
  904. {
  905. left = right - minWidth;
  906. }
  907. if (top + minHeight > bottom)
  908. {
  909. bottom = top + minHeight;
  910. }
  911. }
  912. }
  913. break;
  914. case PointControlType.MiddlBottom:
  915. {
  916. left = cacheRect.Left;
  917. right = cacheRect.Right;
  918. top = cacheRect.Top;
  919. bottom = centerPoint.Y + moveVector.Y;
  920. if (top + minHeight > bottom)
  921. {
  922. bottom = top + minHeight;
  923. }
  924. }
  925. break;
  926. case PointControlType.RightBottom:
  927. {
  928. left = cacheRect.Left;
  929. right = centerPoint.X + moveVector.X;
  930. top = cacheRect.Top;
  931. bottom = centerPoint.Y + moveVector.Y;
  932. if (isProportionalScaling)
  933. {
  934. Size size = GetProportionalScalingSize(right - left, bottom - top);
  935. right = left + size.Width;
  936. bottom = top + size.Height;
  937. if (right > maxRect.Right)
  938. {
  939. double tmpWidth = right - left;
  940. right = maxRect.Right;
  941. double width = right - left;
  942. double height = (bottom - top) * width / tmpWidth;
  943. bottom = top + height;
  944. }
  945. if (bottom > maxRect.Bottom)
  946. {
  947. double tmpHeight = bottom - top;
  948. bottom = maxRect.Bottom;
  949. double height = bottom - top;
  950. double width = (right - left) * height / tmpHeight;
  951. right = left + width;
  952. }
  953. }
  954. else
  955. {
  956. if (left + minWidth > right)
  957. {
  958. right = left + minWidth;
  959. }
  960. if (top + minHeight > bottom)
  961. {
  962. bottom = top + minHeight;
  963. }
  964. }
  965. }
  966. break;
  967. case PointControlType.RightMiddle:
  968. {
  969. left = cacheRect.Left;
  970. right = centerPoint.X + moveVector.X;
  971. top = cacheRect.Top;
  972. bottom = cacheRect.Bottom;
  973. if (left + minWidth > right)
  974. {
  975. right = left + minWidth;
  976. }
  977. }
  978. break;
  979. case PointControlType.RightTop:
  980. {
  981. left = cacheRect.Left;
  982. right = centerPoint.X + moveVector.X;
  983. top = centerPoint.Y + moveVector.Y;
  984. bottom = cacheRect.Bottom;
  985. if (isProportionalScaling)
  986. {
  987. Size size = GetProportionalScalingSize(right - left, bottom - top);
  988. right = left + size.Width;
  989. top = bottom - size.Height;
  990. if (right > maxRect.Right)
  991. {
  992. double tmpWidth = right - left;
  993. right = maxRect.Right;
  994. double width = right - left;
  995. double height = (bottom - top) * width / tmpWidth;
  996. top = bottom - height;
  997. }
  998. if (top < maxRect.Top)
  999. {
  1000. double tmpHeight = bottom - top;
  1001. top = maxRect.Top;
  1002. double height = bottom - top;
  1003. double width = (right - left) * height / tmpHeight;
  1004. right = left + width;
  1005. }
  1006. }
  1007. else
  1008. {
  1009. if (left + minWidth > right)
  1010. {
  1011. right = left + minWidth;
  1012. }
  1013. if (top + minHeight > bottom)
  1014. {
  1015. top = bottom - minHeight;
  1016. }
  1017. }
  1018. }
  1019. break;
  1020. case PointControlType.MiddleTop:
  1021. {
  1022. left = cacheRect.Left;
  1023. right = cacheRect.Right;
  1024. top = centerPoint.Y + moveVector.Y;
  1025. bottom = cacheRect.Bottom;
  1026. if (top + minHeight > bottom)
  1027. {
  1028. top = bottom - minHeight;
  1029. }
  1030. }
  1031. break;
  1032. case PointControlType.Body:
  1033. case PointControlType.Line:
  1034. {
  1035. double newleft = maxRect.Left - SetDrawRect.Width + 10;
  1036. double newright = maxRect.Right + SetDrawRect.Width - 10;
  1037. double newtop = maxRect.Top - SetDrawRect.Height + 10;
  1038. double newbottom = maxRect.Bottom + SetDrawRect.Height - 10;
  1039. if (newleft < 0)
  1040. {
  1041. newleft = 0;
  1042. }
  1043. Rect newMaxRect = new Rect(newleft, newtop, newright - newleft, newbottom - newtop);
  1044. Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), newMaxRect);
  1045. left = cacheRect.Left + OffsetPos.X;
  1046. right = cacheRect.Right + OffsetPos.X;
  1047. top = cacheRect.Top + OffsetPos.Y;
  1048. bottom = cacheRect.Bottom + OffsetPos.Y;
  1049. }
  1050. break;
  1051. default:
  1052. break;
  1053. }
  1054. //if (left < maxRect.Left)
  1055. //{
  1056. // left = maxRect.Left;
  1057. //}
  1058. //if (top < maxRect.Top)
  1059. //{
  1060. // top = maxRect.Top;
  1061. //}
  1062. if (right > maxRect.Right + SetDrawRect.Width - 10)
  1063. {
  1064. if (left > maxRect.Right - 10)
  1065. {
  1066. left = maxRect.Right - 10;
  1067. }
  1068. right = maxRect.Right + SetDrawRect.Width - 10;
  1069. }
  1070. if (bottom > maxRect.Bottom + SetDrawRect.Height - 10)
  1071. {
  1072. if (top > maxRect.Bottom - 10)
  1073. {
  1074. top = maxRect.Bottom - 10;
  1075. }
  1076. bottom = maxRect.Bottom + SetDrawRect.Height - 10;
  1077. }
  1078. drawRect = new Rect(left, top, right - left, bottom - top);
  1079. moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
  1080. return true;
  1081. }
  1082. catch (Exception ex)
  1083. {
  1084. }
  1085. return false;
  1086. }
  1087. /// <summary>
  1088. /// Proportional scaling offset calibration
  1089. /// </summary>
  1090. /// <param name="movePoint">
  1091. /// The current movement point
  1092. /// </param>
  1093. /// <returns>
  1094. /// The offset point after the proportional scaling
  1095. /// </returns>
  1096. protected Point ProportionalScalingOffsetPos(Point movePoint)
  1097. {
  1098. if (isProportionalScaling)
  1099. {
  1100. Point offsetPos = movePoint;
  1101. double ratioX = cacheRect.Width > 0 ? cacheRect.Height / cacheRect.Width : 1;
  1102. double ratioY = cacheRect.Height > 0 ? cacheRect.Width / cacheRect.Height : 1;
  1103. switch (hitControlType)
  1104. {
  1105. case PointControlType.LeftTop:
  1106. case PointControlType.RightBottom:
  1107. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  1108. break;
  1109. case PointControlType.LeftBottom:
  1110. case PointControlType.RightTop:
  1111. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  1112. break;
  1113. case PointControlType.LeftMiddle:
  1114. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  1115. break;
  1116. case PointControlType.RightMiddle:
  1117. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  1118. break;
  1119. case PointControlType.MiddlBottom:
  1120. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? 1 : -1), movePoint.Y);
  1121. break;
  1122. case PointControlType.MiddleTop:
  1123. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? -1 : 1), movePoint.Y);
  1124. break;
  1125. default:
  1126. break;
  1127. }
  1128. return offsetPos;
  1129. }
  1130. else
  1131. {
  1132. return movePoint;
  1133. }
  1134. }
  1135. /// <summary>
  1136. /// Inner drawing circle point
  1137. /// </summary>
  1138. /// <param name="drawingContext">
  1139. /// Drawing context
  1140. /// </param>
  1141. /// <param name="ignoreList">
  1142. /// Collection of positions that need to be drawn
  1143. /// </param>
  1144. /// <param name="PointSize">
  1145. /// Size of the point
  1146. /// </param>
  1147. /// <param name="PointPen">
  1148. /// Brush for drawing points
  1149. /// </param>
  1150. /// <param name="BorderBrush">
  1151. /// Border brush for drawing points
  1152. /// </param>
  1153. protected void DrawCirclePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  1154. {
  1155. GeometryGroup controlGroup = new GeometryGroup();
  1156. controlGroup.FillRule = FillRule.Nonzero;
  1157. List<Point> ignorePointsList = new List<Point>();
  1158. // Get specific points
  1159. foreach (PointControlType type in ignoreList)
  1160. {
  1161. if ((int)type < controlPoints.Count)
  1162. {
  1163. ignorePointsList.Add(controlPoints[(int)type]);
  1164. }
  1165. }
  1166. for (int i = 0; i < controlPoints.Count; i++)
  1167. {
  1168. Point controlPoint = controlPoints[i];
  1169. if (ignorePointsList.Contains(controlPoint))
  1170. {
  1171. continue;
  1172. }
  1173. EllipseGeometry circlPoint = new EllipseGeometry(controlPoint, PointSize, PointSize);
  1174. controlGroup.Children.Add(circlPoint);
  1175. }
  1176. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  1177. }
  1178. /// <summary>
  1179. /// Inner drawing square
  1180. /// </summary>
  1181. /// <param name="drawingContext">
  1182. /// Drawing context
  1183. /// </param>
  1184. /// <param name="ControlPoints">
  1185. /// Collection of positions that need to be drawn
  1186. /// </param>
  1187. /// <param name="PointSize">
  1188. /// Size of the point
  1189. /// </param>
  1190. /// <param name="PointPen">
  1191. /// Brush for drawing points
  1192. /// </param>
  1193. /// <param name="BorderBrush">
  1194. /// Border brush for drawing points
  1195. /// </param>
  1196. protected void DrawSquarePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  1197. {
  1198. GeometryGroup controlGroup = new GeometryGroup();
  1199. controlGroup.FillRule = FillRule.Nonzero;
  1200. List<Point> ignorePointsList = new List<Point>();
  1201. // Get specific points
  1202. foreach (PointControlType type in ignoreList)
  1203. {
  1204. if ((int)type < controlPoints.Count)
  1205. {
  1206. ignorePointsList.Add(controlPoints[(int)type]);
  1207. }
  1208. }
  1209. for (int i = 0; i < controlPoints.Count; i++)
  1210. {
  1211. Point controlPoint = controlPoints[i];
  1212. if (ignorePointsList.Contains(controlPoint))
  1213. {
  1214. continue;
  1215. }
  1216. RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
  1217. PointSize * 2, PointSize * 2));
  1218. controlGroup.Children.Add(rectPoint);
  1219. }
  1220. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  1221. }
  1222. protected void DrawCropPoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  1223. {
  1224. //GeometryGroup controlGroup = new GeometryGroup();
  1225. //controlGroup.FillRule = FillRule.Nonzero;
  1226. clipThickness.Left = (SetDrawRect.Left - drawRect.Left)/currentZoom;
  1227. clipThickness.Top = (SetDrawRect.Top - drawRect.Top) / currentZoom;
  1228. clipThickness.Right = (SetDrawRect.Right - drawRect.Right) / currentZoom;
  1229. clipThickness.Bottom = (SetDrawRect.Bottom - drawRect.Bottom) / currentZoom;
  1230. List<Point> controlCurrentPoints = GetControlPoint(drawRect);
  1231. CombinedGeometry controlGroup = new CombinedGeometry();
  1232. RectangleGeometry paintGeometry = new RectangleGeometry();
  1233. paintGeometry.Rect = SetDrawRect;
  1234. controlGroup.Geometry1 = paintGeometry;
  1235. RectangleGeometry moveGeometry = new RectangleGeometry();
  1236. Rect clippedBorder = drawRect;
  1237. if (clippedBorder.IsEmpty == false)
  1238. {
  1239. moveGeometry.Rect = drawRect;
  1240. }
  1241. controlGroup.Geometry2 = moveGeometry;
  1242. controlGroup.GeometryCombineMode = GeometryCombineMode.Exclude;
  1243. //Left Top Corner
  1244. if (!ignoreList.Contains(PointControlType.LeftTop))
  1245. {
  1246. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[0].X - PointSize, controlCurrentPoints[0].Y - PointSize, PointSize, PointSize * 4));
  1247. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[0].X - PointSize, controlCurrentPoints[0].Y - PointSize, PointSize * 4, PointSize));
  1248. }
  1249. //Left Center
  1250. if (!ignoreList.Contains(PointControlType.LeftMiddle))
  1251. {
  1252. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[1].X - PointSize, (controlCurrentPoints[1].Y + controlCurrentPoints[1].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  1253. }
  1254. //Left Bottom Corner
  1255. if (!ignoreList.Contains(PointControlType.LeftBottom))
  1256. {
  1257. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[2].X - PointSize, controlCurrentPoints[2].Y - PointSize * 3, PointSize, PointSize * 4));
  1258. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[2].X - PointSize, controlCurrentPoints[2].Y, PointSize * 4, PointSize));
  1259. }
  1260. //Bottom Center
  1261. if (!ignoreList.Contains(PointControlType.MiddlBottom))
  1262. {
  1263. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlCurrentPoints[3].X + controlCurrentPoints[3].X - PointSize * 5) / 2, controlCurrentPoints[3].Y, PointSize * 5, PointSize));
  1264. }
  1265. //Bottom Right Corner
  1266. if (!ignoreList.Contains(PointControlType.RightBottom))
  1267. {
  1268. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[4].X, controlCurrentPoints[4].Y - PointSize * 3, PointSize, PointSize * 4));
  1269. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[4].X - PointSize * 3, controlCurrentPoints[4].Y, PointSize * 4, PointSize));
  1270. }
  1271. //Right Center
  1272. if (!ignoreList.Contains(PointControlType.RightMiddle))
  1273. {
  1274. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[5].X, (controlCurrentPoints[5].Y + controlCurrentPoints[5].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  1275. }
  1276. //Right Top Corner
  1277. if (!ignoreList.Contains(PointControlType.RightTop))
  1278. {
  1279. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[6].X, controlCurrentPoints[6].Y - PointSize, PointSize, PointSize * 4));
  1280. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[6].X - PointSize * 4, controlCurrentPoints[6].Y - PointSize, PointSize * 4, PointSize));
  1281. }
  1282. //Top Center
  1283. if (!ignoreList.Contains(PointControlType.MiddleTop))
  1284. {
  1285. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlCurrentPoints[7].X + controlCurrentPoints[7].X - PointSize * 5) / 2, controlCurrentPoints[7].Y - PointSize, PointSize * 5, PointSize));
  1286. }
  1287. BorderBrush = new SolidColorBrush(Color.FromArgb(0x3F, 0x00, 0x00, 0x00));
  1288. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  1289. }
  1290. /// <summary>
  1291. /// Draw the reference line in the moving state
  1292. /// </summary>
  1293. /// <param name="drawDc">
  1294. /// Draw context handle
  1295. /// </param>
  1296. /// <param name="controltype">
  1297. /// Current selected control point type
  1298. /// </param>
  1299. /// <param name="activePen">
  1300. /// Brush for drawing lines
  1301. /// </param>
  1302. /// <param name="moveBrush">
  1303. /// Brush for drawing rectangles
  1304. /// </param>
  1305. /// <param name="moveRect">
  1306. /// Current rectangle to draw
  1307. /// </param>
  1308. protected void DrawMoveBounds(DrawingContext drawDc, PointControlType controltype, Pen activePen, Brush moveBrush, Rect moveRect, Pen RectPen = null)
  1309. {
  1310. switch (controltype)
  1311. {
  1312. case PointControlType.LeftTop:
  1313. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1314. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  1315. break;
  1316. case PointControlType.LeftMiddle:
  1317. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  1318. break;
  1319. case PointControlType.LeftBottom:
  1320. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1321. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  1322. break;
  1323. case PointControlType.MiddlBottom:
  1324. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1325. break;
  1326. case PointControlType.RightBottom:
  1327. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1328. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  1329. break;
  1330. case PointControlType.RightMiddle:
  1331. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  1332. break;
  1333. case PointControlType.RightTop:
  1334. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1335. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  1336. break;
  1337. case PointControlType.MiddleTop:
  1338. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1339. break;
  1340. case PointControlType.Rotate:
  1341. break;
  1342. case PointControlType.Body:
  1343. case PointControlType.Line:
  1344. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(moveRect.Left, moveRect.Top));
  1345. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1346. drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Top), new Point(moveRect.Left, 0));
  1347. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(moveRect.Right, 0));
  1348. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(moveRect.Left, moveRect.Bottom));
  1349. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1350. drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Bottom), new Point(moveRect.Left, PDFViewerActualHeight));
  1351. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(moveRect.Right, PDFViewerActualHeight));
  1352. break;
  1353. default:
  1354. break;
  1355. }
  1356. drawDc?.DrawRectangle(moveBrush, RectPen, moveRect);
  1357. }
  1358. /// <summary>
  1359. /// Notify the event during/after the drawing data
  1360. /// </summary>
  1361. /// <param name="isFinish">
  1362. /// Identifies whether the data change is complete
  1363. /// </param>
  1364. protected void InvokeDataChangEvent(bool isFinish)
  1365. {
  1366. selectedRectData.Square = GetRect();
  1367. if (isFinish)
  1368. {
  1369. selectedRectData.Angle=angle;
  1370. DataChanged?.Invoke(this, selectedRectData);
  1371. }
  1372. else
  1373. {
  1374. DataChanging?.Invoke(this, selectedRectData);
  1375. }
  1376. }
  1377. /// <summary>
  1378. /// Align the rectangle drawing
  1379. /// </summary>
  1380. /// <param name="RectMovePoint">
  1381. /// Move distance required for the aligned algorithm to obtain the rectangle
  1382. /// </param>
  1383. private void DrawAlignRect(Point RectMovePoint)
  1384. {
  1385. double TmpLeft, TmpRight, TmpUp, TmpDown;
  1386. Point OffsetPos = CalcMoveBound(drawRect, RectMovePoint, maxRect);
  1387. TmpLeft = drawRect.Left + OffsetPos.X;
  1388. TmpRight = drawRect.Right + OffsetPos.X;
  1389. TmpUp = drawRect.Top + OffsetPos.Y;
  1390. TmpDown = drawRect.Bottom + OffsetPos.Y;
  1391. SetDrawRect = drawRect = new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
  1392. Draw();
  1393. }
  1394. /// <summary>
  1395. /// Get the current set of ignore points
  1396. /// </summary>
  1397. /// <returns>
  1398. /// Data set of ignored points
  1399. /// </returns>
  1400. private List<PointControlType> GetIgnorePoints()
  1401. {
  1402. List<PointControlType> IgnorePointsList = new List<PointControlType>();
  1403. foreach (PointControlType type in ignorePoints)
  1404. {
  1405. IgnorePointsList.Add(type);
  1406. }
  1407. return IgnorePointsList;
  1408. }
  1409. #endregion
  1410. }
  1411. }