PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/GammaJul.LgLcd/LcdGdiPolygon.cs

#
C# | 108 lines | 53 code | 12 blank | 43 comment | 11 complexity | 2a04fc10b1254a4369d4e0ad7525ae63 MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. namespace GammaJul.LgLcd {
  5. /// <summary>
  6. /// Represents a polygon on a <see cref="LcdGdiPage"/>.
  7. /// </summary>
  8. public class LcdGdiPolygon : LcdGdiAbsObject {
  9. private FillMode _fillMode;
  10. /// <summary>
  11. /// Gets or sets a member of the <see cref="FillMode"/> enumeration that determines how the polygon is filled.
  12. /// </summary>
  13. public FillMode FillMode {
  14. get { return _fillMode; }
  15. set {
  16. if (_fillMode != value) {
  17. _fillMode = value;
  18. HasChanged = true;
  19. }
  20. }
  21. }
  22. /// <summary>
  23. /// Changes the points of the polygon.
  24. /// </summary>
  25. /// <param name="points">Points delimiting the polygon.</param>
  26. /// <param name="keepAbsolute">Whether the given points are left untouched.
  27. /// <see cref="LcdGdiAbsObject.KeepAbsolute"/> for details.</param>
  28. public void SetPoints(PointF[] points, bool keepAbsolute) {
  29. if (points == null)
  30. throw new ArgumentNullException("points");
  31. if (points.Length < 3)
  32. throw new ArgumentOutOfRangeException("points", "There must be at least 3 points to make a polygon.");
  33. CalcAndSetPoints(points, keepAbsolute);
  34. }
  35. /// <summary>
  36. /// Draws the polygon.
  37. /// </summary>
  38. /// <param name="page">Page where this object will be drawn.</param>
  39. /// <param name="graphics"><see cref="Graphics"/> to use for drawing.</param>
  40. protected internal override void Draw(LcdGdiPage page, Graphics graphics) {
  41. PointF[] points = GetPoints();
  42. for (int i = 0; i < points.Length; ++i) {
  43. PointF point = points[i];
  44. point.X += AbsolutePosition.X;
  45. point.Y += AbsolutePosition.Y;
  46. points[i] = point;
  47. }
  48. if (Brush != null)
  49. graphics.FillPolygon(Brush, points, _fillMode);
  50. if (Pen != null)
  51. graphics.DrawPolygon(Pen, points);
  52. }
  53. /// <summary>
  54. /// Creates a new <see cref="LcdGdiPolygon"/>.
  55. /// </summary>
  56. public LcdGdiPolygon()
  57. : base(new PointF[3], false) {
  58. }
  59. /// <summary>
  60. /// Creates a new <see cref="LcdGdiPolygon"/> with the specified pen for the edge and points.
  61. /// </summary>
  62. /// <param name="pen">Pen used to draw the edge of the polygon.</param>
  63. /// <param name="points">Points delimiting the polygon.</param>
  64. /// <param name="keepAbsolute">Whether the given points are left untouched.
  65. /// <see cref="LcdGdiAbsObject.KeepAbsolute"/> for details.</param>
  66. public LcdGdiPolygon(Pen pen, PointF[] points, bool keepAbsolute)
  67. : this(pen, null, points, keepAbsolute) {
  68. }
  69. /// <summary>
  70. /// Creates a new <see cref="LcdGdiPolygon"/> with the specified brush for the fill and points.
  71. /// </summary>
  72. /// <param name="brush">Brush used to fill the polygon.</param>
  73. /// <param name="points">Points delimiting the polygon.</param>
  74. /// <param name="keepAbsolute">Whether the given points are left untouched.
  75. /// <see cref="LcdGdiAbsObject.KeepAbsolute"/> for details.</param>
  76. public LcdGdiPolygon(Brush brush, PointF[] points, bool keepAbsolute)
  77. : this(null, brush, points, keepAbsolute) {
  78. }
  79. /// <summary>
  80. /// Creates a new <see cref="LcdGdiPolygon"/> with the specified pen for the edge,
  81. /// brush for the fill and points.
  82. /// </summary>
  83. /// <param name="pen">Pen used to draw the edge of the polygon.</param>
  84. /// <param name="brush">Brush used to fill the polygon.</param>
  85. /// <param name="points">Points delimiting the polygon.</param>
  86. /// <param name="keepAbsolute">Whether the given points are left untouched.
  87. /// <see cref="LcdGdiAbsObject.KeepAbsolute"/> for details.</param>
  88. public LcdGdiPolygon(Pen pen, Brush brush, PointF[] points, bool keepAbsolute)
  89. : base(points, keepAbsolute) {
  90. if (points.Length < 3)
  91. throw new ArgumentOutOfRangeException("points", "There must be at least 3 points to make a curve.");
  92. Pen = pen;
  93. Brush = brush;
  94. }
  95. }
  96. }