SelectionDrawModeInfo.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using PaintDotNet.Measurement.Enum;
  2. using System;
  3. using System.Runtime.Serialization;
  4. namespace PaintDotNet.Measurement.ObjInfo
  5. {
  6. [Serializable]
  7. public sealed class SelectionDrawModeInfo
  8. : ICloneable<SelectionDrawModeInfo>,
  9. IDeserializationCallback
  10. {
  11. private SelectionDrawMode drawMode;
  12. private double width;
  13. private double height;
  14. private MeasurementUnit units;
  15. public SelectionDrawMode DrawMode
  16. {
  17. get
  18. {
  19. return this.drawMode;
  20. }
  21. }
  22. public double Width
  23. {
  24. get
  25. {
  26. return this.width;
  27. }
  28. }
  29. public double Height
  30. {
  31. get
  32. {
  33. return this.height;
  34. }
  35. }
  36. public MeasurementUnit Units
  37. {
  38. get
  39. {
  40. return this.units;
  41. }
  42. }
  43. public override bool Equals(object obj)
  44. {
  45. SelectionDrawModeInfo asSDMI = obj as SelectionDrawModeInfo;
  46. if (asSDMI == null)
  47. {
  48. return false;
  49. }
  50. return (asSDMI.drawMode == this.drawMode) && (asSDMI.width == this.width) && (asSDMI.height == this.height) && (asSDMI.units == this.units);
  51. }
  52. public override int GetHashCode()
  53. {
  54. return unchecked(this.drawMode.GetHashCode() ^ this.width.GetHashCode() ^ this.height.GetHashCode() & this.units.GetHashCode());
  55. }
  56. public SelectionDrawModeInfo(SelectionDrawMode drawMode, double width, double height, MeasurementUnit units)
  57. {
  58. this.drawMode = drawMode;
  59. this.width = width;
  60. this.height = height;
  61. this.units = units;
  62. }
  63. public static SelectionDrawModeInfo CreateDefault()
  64. {
  65. return new SelectionDrawModeInfo(SelectionDrawMode.Normal, 4.0, 3.0, MeasurementUnit.Inch);
  66. }
  67. public SelectionDrawModeInfo CloneWithNewDrawMode(SelectionDrawMode newDrawMode)
  68. {
  69. return new SelectionDrawModeInfo(newDrawMode, this.width, this.height, this.units);
  70. }
  71. public SelectionDrawModeInfo CloneWithNewWidth(double newWidth)
  72. {
  73. return new SelectionDrawModeInfo(this.drawMode, newWidth, this.height, this.units);
  74. }
  75. public SelectionDrawModeInfo CloneWithNewHeight(double newHeight)
  76. {
  77. return new SelectionDrawModeInfo(this.drawMode, this.width, newHeight, this.units);
  78. }
  79. public SelectionDrawModeInfo CloneWithNewWidthAndHeight(double newWidth, double newHeight)
  80. {
  81. return new SelectionDrawModeInfo(this.drawMode, newWidth, newHeight, this.units);
  82. }
  83. public SelectionDrawModeInfo Clone()
  84. {
  85. return new SelectionDrawModeInfo(this.drawMode, this.width, this.height, this.units);
  86. }
  87. public SelectionDrawModeInfo CloneWithNewUnits(MeasurementUnit newUnits)
  88. {
  89. return new SelectionDrawModeInfo(this.drawMode, this.width, this.height, newUnits);
  90. }
  91. object ICloneable.Clone()
  92. {
  93. return Clone();
  94. }
  95. void IDeserializationCallback.OnDeserialization(object sender)
  96. {
  97. switch (this.units)
  98. {
  99. case MeasurementUnit.Centimeter:
  100. case MeasurementUnit.Inch:
  101. case MeasurementUnit.Pixel:
  102. break;
  103. default:
  104. this.units = MeasurementUnit.Pixel;
  105. break;
  106. }
  107. }
  108. }
  109. }