PolygonObject.cs 2.8 KB

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