00001 #region License
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #endregion
00027
00028 using System;
00029 using System.Collections.Generic;
00030 using System.Text;
00031
00032 namespace OpenTK
00033 {
00034 #if NO_SYSDRAWING
00038 public struct Rectangle : IEquatable<Rectangle>
00039 {
00040 #region Fields
00041
00042 Point location;
00043 Size size;
00044
00045 #endregion
00046
00047 #region Constructors
00048
00054 public Rectangle(Point location, Size size)
00055 : this()
00056 {
00057 Location = location;
00058 Size = size;
00059 }
00060
00068 public Rectangle(int x, int y, int width, int height)
00069 : this(new Point(x, y), new Size(width, height))
00070 { }
00071
00072 #endregion
00073
00074 #region Public Members
00075
00079 public int X
00080 {
00081 get { return Location.X; }
00082 set { Location = new Point (value, Y); }
00083 }
00084
00088 public int Y
00089 {
00090 get { return Location.Y; }
00091 set { Location = new Point (X, value); }
00092 }
00093
00097 public int Width
00098 {
00099 get { return Size.Width; }
00100 set { Size = new Size (value, Height); }
00101 }
00102
00106 public int Height
00107 {
00108 get { return Size.Height; }
00109 set { Size = new Size(Width, value); }
00110 }
00111
00116 public Point Location
00117 {
00118 get { return location; }
00119 set { location = value; }
00120 }
00121
00126 public Size Size
00127 {
00128 get { return size; }
00129 set { size = value; }
00130 }
00131
00135 public int Top { get { return Y; } }
00136
00140 public int Right { get { return X + Width; } }
00141
00145 public int Bottom { get { return Y + Height; } }
00146
00150 public int Left { get { return X; } }
00151
00156 public bool IsEmpty
00157 {
00158 get { return Location.IsEmpty && Size.IsEmpty; }
00159 }
00160
00164 public static readonly Rectangle Zero = new Rectangle();
00165
00169 public static readonly Rectangle Empty = new Rectangle();
00170
00179 public static Rectangle FromLTRB(int left, int top, int right, int bottom)
00180 {
00181 return new Rectangle(new Point(left, top), new Size(right - left, bottom - top));
00182 }
00183
00191 public bool Contains(Point point)
00192 {
00193 return point.X >= Left && point.X < Right &&
00194 point.Y >= Top && point.Y < Bottom;
00195 }
00196
00204 public bool Contains(Rectangle rect)
00205 {
00206 return Contains(rect.Location) && Contains(rect.Location + rect.Size);
00207 }
00208
00215 public static bool operator ==(Rectangle left, Rectangle right)
00216 {
00217 return left.Equals(right);
00218 }
00219
00226 public static bool operator !=(Rectangle left, Rectangle right)
00227 {
00228 return !left.Equals(right);
00229 }
00230
00240 public static implicit operator System.Drawing.Rectangle(Rectangle rect)
00241 {
00242 return new System.Drawing.Rectangle(rect.Location, rect.Size);
00243 }
00244
00254 public static implicit operator Rectangle(System.Drawing.Rectangle rect)
00255 {
00256 return new Rectangle(rect.Location, rect.Size);
00257 }
00258
00268 public static implicit operator System.Drawing.RectangleF(Rectangle rect)
00269 {
00270 return new System.Drawing.RectangleF(rect.Location, rect.Size);
00271 }
00272
00278 public override bool Equals(object obj)
00279 {
00280 if (obj is Rectangle)
00281 return Equals((Rectangle)obj);
00282
00283 return false;
00284 }
00285
00290 public override int GetHashCode()
00291 {
00292 return Location.GetHashCode() & Size.GetHashCode();
00293 }
00294
00299 public override string ToString()
00300 {
00301 return String.Format("{{{0}-{1}}}", Location, Location + Size);
00302 }
00303
00304
00305 #endregion
00306
00307 #region IEquatable<Rectangle> Members
00308
00314 public bool Equals(Rectangle other)
00315 {
00316 return Location.Equals(other.Location) &&
00317 Size.Equals(other.Size);
00318 }
00319
00320 #endregion
00321 }
00322 #endif
00323 }