BrushInfo.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using PaintDotNet.Measurement.Enum;
  2. using System;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. namespace PaintDotNet.Measurement.ObjInfo
  6. {
  7. /// <summary>
  8. /// Carries information about the subset of Brush configuration details that we support.
  9. /// Does not carry color information.
  10. /// </summary>
  11. [Serializable]
  12. public class BrushInfo : ICloneable
  13. {
  14. private BrushType brushType;
  15. private HatchStyle hatchStyle;
  16. public BrushType BrushType
  17. {
  18. get
  19. {
  20. return brushType;
  21. }
  22. set
  23. {
  24. brushType = value;
  25. }
  26. }
  27. /// <summary>
  28. /// If BrushType is equal to BrushType.Hatch, then this info is pertinent.
  29. /// </summary>
  30. public HatchStyle HatchStyle
  31. {
  32. get
  33. {
  34. return hatchStyle;
  35. }
  36. set
  37. {
  38. hatchStyle = value;
  39. }
  40. }
  41. public Brush CreateBrush(Color foreColor, Color backColor)
  42. {
  43. if (brushType == BrushType.Solid)
  44. {
  45. return new SolidBrush(foreColor);
  46. }
  47. else if (brushType == BrushType.Hatch)
  48. {
  49. return new HatchBrush(hatchStyle, foreColor, backColor);
  50. }
  51. throw new InvalidOperationException("BrushType is invalid");
  52. }
  53. public BrushInfo(BrushType brushType, HatchStyle hatchStyle)
  54. {
  55. this.brushType = brushType;
  56. this.hatchStyle = hatchStyle;
  57. }
  58. public BrushInfo Clone()
  59. {
  60. return new BrushInfo(this.brushType, this.hatchStyle);
  61. }
  62. object ICloneable.Clone()
  63. {
  64. return Clone();
  65. }
  66. }
  67. }