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