RECT.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Diagnostics.CodeAnalysis;
  3. namespace Standard;
  4. internal struct RECT
  5. {
  6. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  7. public void Offset(int dx, int dy)
  8. {
  9. this._left += dx;
  10. this._top += dy;
  11. this._right += dx;
  12. this._bottom += dy;
  13. }
  14. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  15. public int Left
  16. {
  17. get
  18. {
  19. return this._left;
  20. }
  21. set
  22. {
  23. this._left = value;
  24. }
  25. }
  26. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  27. public int Right
  28. {
  29. get
  30. {
  31. return this._right;
  32. }
  33. set
  34. {
  35. this._right = value;
  36. }
  37. }
  38. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  39. public int Top
  40. {
  41. get
  42. {
  43. return this._top;
  44. }
  45. set
  46. {
  47. this._top = value;
  48. }
  49. }
  50. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  51. public int Bottom
  52. {
  53. get
  54. {
  55. return this._bottom;
  56. }
  57. set
  58. {
  59. this._bottom = value;
  60. }
  61. }
  62. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  63. public int Width
  64. {
  65. get
  66. {
  67. return this._right - this._left;
  68. }
  69. }
  70. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  71. public int Height
  72. {
  73. get
  74. {
  75. return this._bottom - this._top;
  76. }
  77. }
  78. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  79. public POINT Position
  80. {
  81. get
  82. {
  83. return new POINT
  84. {
  85. x = this._left,
  86. y = this._top
  87. };
  88. }
  89. }
  90. [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  91. public SIZE Size
  92. {
  93. get
  94. {
  95. return new SIZE
  96. {
  97. cx = this.Width,
  98. cy = this.Height
  99. };
  100. }
  101. }
  102. public static RECT Union(RECT rect1, RECT rect2)
  103. {
  104. return new RECT
  105. {
  106. Left = Math.Min(rect1.Left, rect2.Left),
  107. Top = Math.Min(rect1.Top, rect2.Top),
  108. Right = Math.Max(rect1.Right, rect2.Right),
  109. Bottom = Math.Max(rect1.Bottom, rect2.Bottom)
  110. };
  111. }
  112. public override bool Equals(object obj)
  113. {
  114. bool result;
  115. try
  116. {
  117. RECT rect = (RECT) obj;
  118. result = (rect._bottom == this._bottom && rect._left == this._left && rect._right == this._right && rect._top == this._top);
  119. }
  120. catch (InvalidCastException)
  121. {
  122. result = false;
  123. }
  124. return result;
  125. }
  126. public override int GetHashCode()
  127. {
  128. return (this._left << 16 | Utility.LOWORD(this._right)) ^ (this._top << 16 | Utility.LOWORD(this._bottom));
  129. }
  130. private int _left;
  131. private int _top;
  132. private int _right;
  133. private int _bottom;
  134. }