2009-11-02 07:20:59 +00:00
|
|
|
#region License
|
2009-11-01 12:44:38 +00:00
|
|
|
//
|
|
|
|
// The Open Toolkit Library License
|
|
|
|
//
|
|
|
|
// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights to
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
// so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
#endregion
|
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
using System;
|
2009-11-01 12:44:38 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace OpenTK
|
|
|
|
{
|
|
|
|
#if EXPERIMENTAL
|
|
|
|
|
|
|
|
public struct Rectangle : IEquatable<Rectangle>
|
|
|
|
{
|
|
|
|
#region Fields
|
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
Point location;
|
2009-11-01 12:44:38 +00:00
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
Size size;
|
2009-11-01 12:44:38 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
public Rectangle(Point location, Size size)
|
|
|
|
: this()
|
|
|
|
{
|
|
|
|
Location = location;
|
|
|
|
Size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Rectangle(int x, int y, int width, int height)
|
|
|
|
: this(new Point(x, y), new Size(width, height))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public Members
|
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
public int X
|
|
|
|
{
|
|
|
|
get { return Location.X; }
|
|
|
|
set { Location = new Point (value, Y); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Y
|
|
|
|
{
|
|
|
|
get { return Location.Y; }
|
|
|
|
set { Location = new Point (X, value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
{
|
|
|
|
get { return Size.Width; }
|
|
|
|
set { Size = new Size (value, Height); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get { return Size.Height; }
|
|
|
|
set { Size = new Size(Width, value); }
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Point Location
|
|
|
|
{
|
2009-11-02 07:20:59 +00:00
|
|
|
get { return location; }
|
|
|
|
set { location = value; }
|
2009-11-01 12:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Size Size
|
|
|
|
{
|
2009-11-02 07:20:59 +00:00
|
|
|
get { return size; }
|
|
|
|
set { size = value; }
|
2009-11-01 12:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Top { get { return Y; } }
|
|
|
|
public int Right { get { return X + Width; } }
|
|
|
|
public int Bottom { get { return Y + Height; } }
|
|
|
|
public int Left { get { return X; } }
|
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
public bool IsEmpty
|
|
|
|
{
|
|
|
|
get { return Location.IsEmpty && Size.IsEmpty; }
|
2009-11-01 12:44:38 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
public static readonly Rectangle Zero = new Rectangle();
|
|
|
|
public static readonly Rectangle Empty = new Rectangle();
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
|
|
|
|
{
|
|
|
|
return new Rectangle(new Point(left, top), new Size(right - left, bottom - top));
|
|
|
|
}
|
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
public bool Contains(Point point)
|
|
|
|
{
|
|
|
|
return point.X >= Left && point.X < Right &&
|
|
|
|
point.Y >= Top && point.Y < Bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Contains(Rectangle rect)
|
|
|
|
{
|
|
|
|
return Contains(rect.Location) && Contains(rect.Location + rect.Size);
|
2009-11-01 12:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool operator ==(Rectangle left, Rectangle right)
|
|
|
|
{
|
|
|
|
return left.Equals(right);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool operator !=(Rectangle left, Rectangle right)
|
|
|
|
{
|
|
|
|
return !left.Equals(right);
|
|
|
|
}
|
|
|
|
|
2009-11-02 07:20:59 +00:00
|
|
|
public static implicit operator System.Drawing.Rectangle(Rectangle rect)
|
|
|
|
{
|
|
|
|
return new System.Drawing.Rectangle(rect.Location, rect.Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static implicit operator Rectangle(System.Drawing.Rectangle rect)
|
|
|
|
{
|
|
|
|
return new Rectangle(rect.Location, rect.Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static implicit operator System.Drawing.RectangleF(Rectangle rect)
|
|
|
|
{
|
|
|
|
return new System.Drawing.RectangleF(rect.Location, rect.Size);
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IEquatable<Rectangle> Members
|
|
|
|
|
|
|
|
public bool Equals(Rectangle other)
|
|
|
|
{
|
|
|
|
return Location.Equals(other.Location) &&
|
|
|
|
Size.Equals(other.Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|