1 #pragma warning disable 0659, 0661 2 using System; 3 4 namespace OpenBveApi.Textures 5 { 6 /// <summary>Represents a region in a texture to be extracted.</summary> 7 public class TextureClipRegion 8 { 9 // --- members --- 10 /// <summary>The left coordinate.</summary> 11 private readonly int MyLeft; 12 /// <summary>The top coordinate.</summary> 13 private readonly int MyTop; 14 /// <summary>The width.</summary> 15 private readonly int MyWidth; 16 /// <summary>The height.</summary> 17 private readonly int MyHeight; 18 // --- properties --- 19 /// <summary>Gets the left coordinate.</summary> 20 public int Left 21 { 22 get 23 { 24 return this.MyLeft; 25 } 26 } 27 /// <summary>Gets the top coordinate.</summary> 28 public int Top 29 { 30 get 31 { 32 return this.MyTop; 33 } 34 } 35 /// <summary>Gets the width.</summary> 36 public int Width 37 { 38 get 39 { 40 return this.MyWidth; 41 } 42 } 43 /// <summary>Gets the height.</summary> 44 public int Height 45 { 46 get 47 { 48 return this.MyHeight; 49 } 50 } 51 52 // --- constructors --- 53 /// <summary>Creates a new clip region.</summary> 54 /// <param name="left">The left coordinate.</param> 55 /// <param name="top">The top coordinate.</param> 56 /// <param name="width">The width.</param> 57 /// <param name="height">The height.</param> 58 /// <exception cref="System.ArgumentException">Raised when the left or top are negative.</exception> 59 /// <exception cref="System.ArgumentException">Raised when the width or height are non-positive.</exception> TextureClipRegion(int left, int top, int width, int height)60 public TextureClipRegion(int left, int top, int width, int height) 61 { 62 if (left < 0 | top < 0) 63 { 64 throw new ArgumentException("The left or top coordinates are negative."); 65 } 66 else if (width <= 0 | height <= 0) 67 { 68 throw new ArgumentException("The width or height are non-positive."); 69 } 70 else 71 { 72 this.MyLeft = left; 73 this.MyTop = top; 74 this.MyWidth = width; 75 this.MyHeight = height; 76 } 77 } 78 79 // --- operators --- 80 /// <summary>Checks whether two clip regions are equal.</summary> 81 /// <param name="a">The first clip region.</param> 82 /// <param name="b">The second clip region.</param> 83 /// <returns>Whether the two clip regions are equal.</returns> operator ==(TextureClipRegion a, TextureClipRegion b)84 public static bool operator ==(TextureClipRegion a, TextureClipRegion b) 85 { 86 if (object.ReferenceEquals(a, b)) return true; 87 if (object.ReferenceEquals(a, null)) return false; 88 if (object.ReferenceEquals(b, null)) return false; 89 if (a.MyLeft != b.MyLeft) return false; 90 if (a.MyTop != b.MyTop) return false; 91 if (a.MyWidth != b.MyWidth) return false; 92 if (a.MyHeight != b.MyHeight) return false; 93 return true; 94 } 95 96 /// <summary>Checks whether two clip regions are unequal.</summary> 97 /// <param name="a">The first clip region.</param> 98 /// <param name="b">The second clip region.</param> 99 /// <returns>Whether the two clip regions are unequal.</returns> operator !=(TextureClipRegion a, TextureClipRegion b)100 public static bool operator !=(TextureClipRegion a, TextureClipRegion b) 101 { 102 if (object.ReferenceEquals(a, b)) return false; 103 if (object.ReferenceEquals(a, null)) return true; 104 if (object.ReferenceEquals(b, null)) return true; 105 if (a.MyLeft != b.MyLeft) return true; 106 if (a.MyTop != b.MyTop) return true; 107 if (a.MyWidth != b.MyWidth) return true; 108 if (a.MyHeight != b.MyHeight) return true; 109 return false; 110 } 111 112 /// <summary>Checks whether this instance is equal to the specified object.</summary> 113 /// <param name="obj">The object.</param> 114 /// <returns>Whether this instance is equal to the specified object.</returns> Equals(object obj)115 public override bool Equals(object obj) 116 { 117 if (object.ReferenceEquals(this, obj)) return true; 118 if (object.ReferenceEquals(this, null)) return false; 119 if (object.ReferenceEquals(obj, null)) return false; 120 if (!(obj is TextureClipRegion)) return false; 121 TextureClipRegion x = (TextureClipRegion) obj; 122 if (this.MyLeft != x.MyLeft) return false; 123 if (this.MyTop != x.MyTop) return false; 124 if (this.MyWidth != x.MyWidth) return false; 125 if (this.MyHeight != x.MyHeight) return false; 126 return true; 127 } 128 } 129 } 130