PolygonObject.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. using System.Linq;
  4. using FastReport.Utils;
  5. namespace FastReport
  6. {
  7. /// <summary>
  8. /// Represents a polygon object.
  9. /// </summary>
  10. /// <remarks>
  11. /// Use the <b>Border.Width</b>, <b>Border.Style</b> and <b>Border.Color</b> properties to set
  12. /// the line width, style and color.
  13. ///
  14. /// </remarks>
  15. public partial class PolygonObject : PolyLineObject
  16. {
  17. #region Protected Methods
  18. /// <summary>
  19. /// Calculate GraphicsPath for draw to page
  20. /// </summary>
  21. /// <param name="pen">Pen for lines</param>
  22. /// <param name="scaleX">scale by width</param>
  23. /// <param name="scaleY">scale by height</param>
  24. /// <returns>Always returns a non-empty path</returns>
  25. protected GraphicsPath getPolygonPath(Pen pen, float scaleX, float scaleY)
  26. {
  27. GraphicsPath gp = base.GetPath(pen, AbsLeft, AbsTop, AbsRight, AbsBottom, scaleX, scaleY);
  28. gp.CloseAllFigures();
  29. return gp;
  30. }
  31. /// <summary>
  32. /// Draw polyline path to graphics
  33. /// </summary>
  34. /// <param name="e">Event arguments</param>
  35. protected override void drawPoly(FRPaintEventArgs e)
  36. {
  37. float x = (AbsLeft + Border.Width / 2) * e.ScaleX;
  38. float y = (AbsTop + Border.Width / 2) * e.ScaleY;
  39. float dx = (Width - Border.Width) * e.ScaleX - 1;
  40. float dy = (Height - Border.Width) * e.ScaleY - 1;
  41. Pen pen;
  42. if (polygonSelectionMode == PolygonSelectionMode.MoveAndScale)
  43. {
  44. pen = e.Cache.GetPen(Border.Color, Border.Width * e.ScaleX, Border.DashStyle);
  45. }
  46. else pen = e.Cache.GetPen(Border.Color, 1, DashStyle.Solid);
  47. Brush brush = null;
  48. if (Fill is SolidFill)
  49. brush = e.Cache.GetBrush((Fill as SolidFill).Color);
  50. else
  51. brush = Fill.CreateBrush(new RectangleF(x, y, dx, dy), e.ScaleX, e.ScaleY);
  52. DrawUtils.SetPenDashPatternOrStyle(DashPattern, pen, Border);
  53. using (GraphicsPath path = getPolygonPath(pen, e.ScaleX, e.ScaleY))
  54. {
  55. if (polygonSelectionMode == PolygonSelectionMode.MoveAndScale)
  56. e.Graphics.FillAndDrawPath(pen, brush, path);
  57. else
  58. e.Graphics.DrawPath(pen, path);
  59. }
  60. }
  61. #endregion
  62. #region Public Methods
  63. /// <inheritdoc/>
  64. public override void Serialize(FRWriter writer)
  65. {
  66. Border.SimpleBorder = true;
  67. base.Serialize(writer);
  68. PolygonObject c = writer.DiffObject as PolygonObject;
  69. }
  70. #endregion
  71. /// <summary>
  72. /// Initializes a new instance of the <see cref="LineObject"/> class with default settings.
  73. /// </summary>
  74. public PolygonObject() : base()
  75. {
  76. FlagSimpleBorder = true;
  77. FlagUseFill = true;
  78. }
  79. }
  80. }