Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region License
2
//
3
// The Open Toolkit Library License
4
//
5
// Copyright (c) 2006 - 2009 the Open Toolkit library.
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a copy
8
// of this software and associated documentation files (the "Software"), to deal
9
// in the Software without restriction, including without limitation the rights to
10
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
// the Software, and to permit persons to whom the Software is furnished to do
12
// so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included in all
15
// copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
// OTHER DEALINGS IN THE SOFTWARE.
25
//
26
#endregion
27
 
28
using System;
29
using System.Collections.Generic;
30
using System.Text;
31
 
32
namespace OpenTK
33
{
34
#if NO_SYSDRAWING
35
    /// <summary>
36
    /// Stores the width and height of a rectangle.
37
    /// </summary>
38
    public struct Size : IEquatable<Size>
39
    {
40
        #region Fields
41
 
42
        int width, height;
43
 
44
        #endregion
45
 
46
        #region Constructors
47
 
48
        /// <summary>
49
        /// Constructs a new Size instance.
50
        /// </summary>
51
        /// <param name="width">The width of this instance.</param>
52
        /// <param name="height">The height of this instance.</param>
53
        public Size(int width, int height)
54
            : this()
55
        {
56
            Width = width;
57
            Height = height;
58
        }
59
 
60
        #endregion
61
 
62
        #region Public Members
63
 
64
        /// <summary>
65
        /// Gets or sets the width of this instance.
66
        /// </summary>
67
        public int Width
68
        {
69
            get { return width; }
70
            set
71
            {
72
                if (width < 0)
73
                    throw new ArgumentOutOfRangeException();
74
                width = value;
75
            }
76
        }
77
 
78
        /// <summary>
79
        /// Gets or sets the height of this instance.
80
        /// </summary>
81
        public int Height
82
        {
83
            get { return height; }
84
            set
85
            {
86
                if (height < 0)
87
                    throw new ArgumentOutOfRangeException();
88
                height = value;
89
            }
90
        }
91
 
92
        /// <summary>
93
        /// Gets a <see cref="System.Boolean"/> that indicates whether this instance is empty or zero.
94
        /// </summary>
95
        public bool IsEmpty
96
        {
97
            get { return Width == 0 && Height == 0; }
98
        }
99
 
100
        /// <summary>
101
        /// Returns a Size instance equal to (0, 0).
102
        /// </summary>
103
        public static readonly Size Empty = new Size();
104
 
105
        /// <summary>
106
        /// Returns a Size instance equal to (0, 0).
107
        /// </summary>
108
        public static readonly Size Zero = new Size();
109
 
110
        /// <summary>
111
        /// Compares two instances for equality.
112
        /// </summary>
113
        /// <param name="left">The first instance.</param>
114
        /// <param name="right">The second instance.</param>
115
        /// <returns>True, if left is equal to right; false otherwise.</returns>
116
        public static bool operator ==(Size left, Size right)
117
        {
118
            return left.Equals(right);
119
        }
120
 
121
        /// <summary>
122
        /// Compares two instances for inequality.
123
        /// </summary>
124
        /// <param name="left">The first instance.</param>
125
        /// <param name="right">The second instance.</param>
126
        /// <returns>True, if left is not equal to right; false otherwise.</returns>
127
        public static bool operator !=(Size left, Size right)
128
        {
129
            return !left.Equals(right);
130
        }
131
 
132
        /// <summary>
133
        /// Converts an OpenTK.Size instance to a System.Drawing.Size.
134
        /// </summary>
135
        /// <param name="size">
136
        /// The <see cref="Size"/> instance to convert.
137
        /// </param>
138
        /// <returns>
139
        /// A <see cref="System.Drawing.Size"/> instance equivalent to size.
140
        /// </returns>
141
        public static implicit operator System.Drawing.Size(Size size)
142
{
143
            return new System.Drawing.Size(size.Width, size.Height);
144
        }
145
 
146
        /// <summary>
147
        /// Converts a System.Drawing.Size instance to an OpenTK.Size.
148
        /// </summary>
149
        /// <param name="size">
150
        /// The <see cref="System.Drawing.Size"/> instance to convert.
151
        /// </param>
152
        /// <returns>
153
        /// A <see cref="Size"/> instance equivalent to size.
154
        /// </returns>
155
        public static implicit operator Size(System.Drawing.Size size)
156
        {
157
            return new Size(size.Width, size.Height);
158
        }
159
 
160
        /// <summary>
161
        /// Converts an OpenTK.Point instance to a System.Drawing.SizeF.
162
        /// </summary>
163
        /// <param name="size">
164
        /// The <see cref="Size"/> instance to convert.
165
        /// </param>
166
        /// <returns>
167
        /// A <see cref="System.Drawing.SizeF"/> instance equivalent to size.
168
        /// </returns>
169
        public static implicit operator System.Drawing.SizeF(Size size)
170
        {
171
            return new System.Drawing.SizeF(size.Width, size.Height);
172
         }
173
 
174
        /// <summary>
175
        /// Indicates whether this instance is equal to the specified object.
176
        /// </summary>
177
        /// <param name="obj">The object instance to compare to.</param>
178
        /// <returns>True, if both instances are equal; false otherwise.</returns>
179
        public override bool Equals(object obj)
180
        {
181
            if (obj is Size)
182
                return Equals((Size)obj);
183
 
184
            return false;
185
        }
186
 
187
        /// <summary>
188
        /// Returns the hash code for this instance.
189
        /// </summary>
190
        /// <returns>A <see cref="System.Int32"/> that represents the hash code for this instance./></returns>
191
        public override int GetHashCode()
192
        {
193
            return Width.GetHashCode() ^ Height.GetHashCode();
194
        }
195
 
196
        /// <summary>
197
        /// Returns a <see cref="System.String"/> that describes this instance.
198
        /// </summary>
199
        /// <returns>A <see cref="System.String"/> that describes this instance.</returns>
200
        public override string ToString()
201
        {
202
            return String.Format("{{{0}, {1}}}", Width, Height);
203
        }
204
 
205
        #endregion
206
 
207
        #region IEquatable<Size> Members
208
 
209
        /// <summary>
210
        /// Indicates whether this instance is equal to the specified Size.
211
        /// </summary>
212
        /// <param name="other">The instance to compare to.</param>
213
        /// <returns>True, if both instances are equal; false otherwise.</returns>
214
        public bool Equals(Size other)
215
        {
216
            return Width == other.Width && Height == other.Height;
217
        }
218
 
219
        #endregion
220
    }
221
#endif
222
}