LineObject.DesignExt.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Windows.Forms;
  6. using FastReport.Utils;
  7. namespace FastReport
  8. {
  9. partial class LineObject
  10. {
  11. #region Properties
  12. /// <summary>
  13. /// This property is not relevant to this class.
  14. /// </summary>
  15. [Browsable(false)]
  16. public override FillBase Fill
  17. {
  18. get { return base.Fill; }
  19. set { base.Fill = value; }
  20. }
  21. #endregion
  22. #region Private Methods
  23. private bool ShouldSerializeStartCap()
  24. {
  25. return !StartCap.Equals(new CapSettings());
  26. }
  27. private bool ShouldSerializeEndCap()
  28. {
  29. return !EndCap.Equals(new CapSettings());
  30. }
  31. #endregion
  32. #region Protected Methods
  33. /// <inheritdoc/>
  34. protected override SelectionPoint[] GetSelectionPoints()
  35. {
  36. return new SelectionPoint[] {
  37. new SelectionPoint(AbsLeft, AbsTop, SizingPoint.LeftTop),
  38. new SelectionPoint(AbsLeft + Width, AbsTop + Height, SizingPoint.RightBottom) };
  39. }
  40. #endregion
  41. #region Public Methods
  42. /// <inheritdoc/>
  43. public override bool PointInObject(PointF point)
  44. {
  45. using (Pen pen = new Pen(Color.Black, 10 / Report?.Designer?.ZoomDpi ?? 1))
  46. using (GraphicsPath path = new GraphicsPath())
  47. {
  48. path.AddLine(AbsLeft, AbsTop, AbsRight, AbsBottom);
  49. return path.IsOutlineVisible(point, pen);
  50. }
  51. }
  52. /// <inheritdoc/>
  53. public override void CheckNegativeSize(FRMouseEventArgs e)
  54. {
  55. // do nothing
  56. }
  57. /// <inheritdoc/>
  58. public override SizeF GetPreferredSize()
  59. {
  60. return new SizeF(0, 0);
  61. }
  62. /// <inheritdoc/>
  63. public override void HandleMouseMove(FRMouseEventArgs e)
  64. {
  65. base.HandleMouseMove(e);
  66. if (e.handled)
  67. e.cursor = Cursors.Cross;
  68. }
  69. /// <inheritdoc/>
  70. public override void HandleMouseUp(FRMouseEventArgs e)
  71. {
  72. base.HandleMouseUp(e);
  73. if (e.mode == WorkspaceMode2.SelectionRect)
  74. {
  75. GraphicsPath path = new GraphicsPath();
  76. Pen pen = null;
  77. if (Width != 0 && Height != 0)
  78. {
  79. path.AddLine(AbsLeft, AbsTop, AbsRight, AbsBottom);
  80. pen = new Pen(Color.Black, 10 / Report.Designer.ZoomDpi);
  81. path.Widen(pen);
  82. }
  83. else
  84. {
  85. float d = 5 / Report.Designer.ZoomDpi;
  86. if (Width == 0)
  87. {
  88. path.AddLine(AbsLeft - d, AbsTop, AbsRight - d, AbsBottom);
  89. path.AddLine(AbsRight - d, AbsBottom, AbsRight + d, AbsBottom);
  90. path.AddLine(AbsRight + d, AbsBottom, AbsRight + d, AbsTop);
  91. }
  92. else
  93. {
  94. path.AddLine(AbsLeft, AbsTop - d, AbsRight, AbsBottom - d);
  95. path.AddLine(AbsRight, AbsBottom - d, AbsRight, AbsBottom + d);
  96. path.AddLine(AbsRight, AbsBottom + d, AbsLeft, AbsTop + d);
  97. }
  98. path.CloseFigure();
  99. }
  100. Region region = new Region(path);
  101. e.handled = region.IsVisible(e.selectionRect);
  102. path.Dispose();
  103. region.Dispose();
  104. if (pen != null)
  105. pen.Dispose();
  106. }
  107. else if (e.mode == WorkspaceMode2.Size)
  108. {
  109. if (!Diagonal)
  110. {
  111. if (Math.Abs(Width) > Math.Abs(Height))
  112. Height = 0;
  113. else
  114. Width = 0;
  115. }
  116. }
  117. }
  118. /// <inheritdoc/>
  119. public override void OnBeforeInsert(int flags)
  120. {
  121. diagonal = flags != 0;
  122. if (flags == 3 || flags == 4)
  123. StartCap.Style = CapStyle.Arrow;
  124. if (flags == 2 || flags == 4)
  125. EndCap.Style = CapStyle.Arrow;
  126. }
  127. #endregion
  128. }
  129. }