PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/GammaJul.LgLcd/LcdGdiRectangle.cs

#
C# | 64 lines | 26 code | 8 blank | 30 comment | 4 complexity | d9fd0011be3f54aa9b960b4e336b46cb MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Drawing;
  3. namespace GammaJul.LgLcd {
  4. /// <summary>
  5. /// Represents a simple rectangle on a <see cref="LcdGdiPage"/>.
  6. /// </summary>
  7. public class LcdGdiRectangle : LcdGdiObject {
  8. /// <summary>
  9. /// Draws the rectangle.
  10. /// </summary>
  11. /// <param name="page">Page where this object will be drawn.</param>
  12. /// <param name="graphics"><see cref="Graphics"/> to use for drawing.</param>
  13. protected internal override void Draw(LcdGdiPage page, Graphics graphics) {
  14. if (Brush != null)
  15. graphics.FillRectangle(Brush, AbsolutePosition.X, AbsolutePosition.Y, FinalSize.Width - 1.0f, FinalSize.Height - 1.0f);
  16. if (Pen != null)
  17. graphics.DrawRectangle(Pen, AbsolutePosition.X, AbsolutePosition.Y, FinalSize.Width - 1.0f, FinalSize.Height - 1.0f);
  18. }
  19. /// <summary>
  20. /// Creates a new <see cref="LcdGdiRectangle"/>.
  21. /// </summary>
  22. public LcdGdiRectangle() {
  23. }
  24. /// <summary>
  25. /// Creates a new <see cref="LcdGdiRectangle"/> with no edge,
  26. /// and specified brush for the fill and rectangle dimensions.
  27. /// </summary>
  28. /// <param name="brush">Brush to use to draw the fill of this object.</param>
  29. /// <param name="rectangle">Rectangle dimensions.</param>
  30. public LcdGdiRectangle(Brush brush, RectangleF rectangle)
  31. : this(null, brush, rectangle) {
  32. }
  33. /// <summary>
  34. /// Creates a new <see cref="LcdGdiRectangle"/> with the specified pen for the edge,
  35. /// no fill brush and specified rectangle dimensions.
  36. /// </summary>
  37. /// <param name="pen">Pen to use to draw the edge of this object.</param>
  38. /// <param name="rectangle">Rectangle dimensions.</param>
  39. public LcdGdiRectangle(Pen pen, RectangleF rectangle)
  40. : this(pen, null, rectangle) {
  41. }
  42. /// <summary>
  43. /// Creates a new <see cref="LcdGdiRectangle"/> with the specified pen for the edge,
  44. /// brush for the fill and rectangle dimensions.
  45. /// </summary>
  46. /// <param name="pen">Pen to use to draw the edge of this object.</param>
  47. /// <param name="brush">Brush to use to draw the fill of this object.</param>
  48. /// <param name="rectangle">Rectangle dimensions.</param>
  49. public LcdGdiRectangle(Pen pen, Brush brush, RectangleF rectangle) {
  50. Pen = pen;
  51. Brush = brush;
  52. Margin = new MarginF(rectangle.Location.X, rectangle.Location.Y, 0.0f, 0.0f);
  53. Size = rectangle.Size;
  54. }
  55. }
  56. }