(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Drawing / System.Drawing / Size.cs
blob1760c92be3bc51893f30722d523b4538437d1ecf
1 //
2 // System.Drawing.Size.cs
3 //
4 // Author:
5 // Mike Kestner (mkestner@speakeasy.net)
6 //
7 // Copyright (C) 2001 Mike Kestner
8 // Copyright (C) 2004 Novell, Inc. http://www.novell.com
9 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System;
35 using System.Runtime.Serialization;
36 using System.Runtime.InteropServices;
37 using System.ComponentModel;
39 namespace System.Drawing
41 [Serializable]
42 [ComVisible (true)]
43 [TypeConverter (typeof (SizeConverter))]
44 public struct Size
47 // Private Height and width fields.
48 private int width, height;
50 // -----------------------
51 // Public Shared Members
52 // -----------------------
54 /// <summary>
55 /// Empty Shared Field
56 /// </summary>
57 ///
58 /// <remarks>
59 /// An uninitialized Size Structure.
60 /// </remarks>
62 public static readonly Size Empty;
64 /// <summary>
65 /// Ceiling Shared Method
66 /// </summary>
67 ///
68 /// <remarks>
69 /// Produces a Size structure from a SizeF structure by
70 /// taking the ceiling of the Width and Height properties.
71 /// </remarks>
73 public static Size Ceiling (SizeF value)
75 int w, h;
76 checked {
77 w = (int) Math.Ceiling (value.Width);
78 h = (int) Math.Ceiling (value.Height);
81 return new Size (w, h);
84 /// <summary>
85 /// Round Shared Method
86 /// </summary>
87 ///
88 /// <remarks>
89 /// Produces a Size structure from a SizeF structure by
90 /// rounding the Width and Height properties.
91 /// </remarks>
93 public static Size Round (SizeF value)
95 int w, h;
96 checked {
97 w = (int) Math.Round (value.Width);
98 h = (int) Math.Round (value.Height);
101 return new Size (w, h);
104 /// <summary>
105 /// Truncate Shared Method
106 /// </summary>
108 /// <remarks>
109 /// Produces a Size structure from a SizeF structure by
110 /// truncating the Width and Height properties.
111 /// </remarks>
113 public static Size Truncate (SizeF value)
115 int w, h;
116 checked {
117 w = (int) value.Width;
118 h = (int) value.Height;
121 return new Size (w, h);
124 /// <summary>
125 /// Addition Operator
126 /// </summary>
128 /// <remarks>
129 /// Addition of two Size structures.
130 /// </remarks>
132 public static Size operator + (Size sz1, Size sz2)
134 return new Size (sz1.Width + sz2.Width,
135 sz1.Height + sz2.Height);
138 /// <summary>
139 /// Equality Operator
140 /// </summary>
142 /// <remarks>
143 /// Compares two Size objects. The return value is
144 /// based on the equivalence of the Width and Height
145 /// properties of the two Sizes.
146 /// </remarks>
148 public static bool operator == (Size sz_a, Size sz_b)
150 return ((sz_a.Width == sz_b.Width) &&
151 (sz_a.Height == sz_b.Height));
154 /// <summary>
155 /// Inequality Operator
156 /// </summary>
158 /// <remarks>
159 /// Compares two Size objects. The return value is
160 /// based on the equivalence of the Width and Height
161 /// properties of the two Sizes.
162 /// </remarks>
164 public static bool operator != (Size sz_a, Size sz_b)
166 return ((sz_a.Width != sz_b.Width) ||
167 (sz_a.Height != sz_b.Height));
170 /// <summary>
171 /// Subtraction Operator
172 /// </summary>
174 /// <remarks>
175 /// Subtracts two Size structures.
176 /// </remarks>
178 public static Size operator - (Size sz1, Size sz2)
180 return new Size (sz1.Width - sz2.Width,
181 sz1.Height - sz2.Height);
184 /// <summary>
185 /// Size to Point Conversion
186 /// </summary>
188 /// <remarks>
189 /// Returns a Point based on the dimensions of a given
190 /// Size. Requires explicit cast.
191 /// </remarks>
193 public static explicit operator Point (Size sz)
195 return new Point (sz.Width, sz.Height);
198 /// <summary>
199 /// Size to SizeF Conversion
200 /// </summary>
202 /// <remarks>
203 /// Creates a SizeF based on the dimensions of a given
204 /// Size. No explicit cast is required.
205 /// </remarks>
207 public static implicit operator SizeF (Size sz)
209 return new SizeF (sz.Width, sz.Height);
213 // -----------------------
214 // Public Constructors
215 // -----------------------
217 /// <summary>
218 /// Size Constructor
219 /// </summary>
221 /// <remarks>
222 /// Creates a Size from a Point value.
223 /// </remarks>
225 public Size (Point pt)
227 width = pt.X;
228 height = pt.Y;
231 /// <summary>
232 /// Size Constructor
233 /// </summary>
235 /// <remarks>
236 /// Creates a Size from specified dimensions.
237 /// </remarks>
239 public Size (int width, int height)
241 this.width = width;
242 this.height = height;
245 // -----------------------
246 // Public Instance Members
247 // -----------------------
249 /// <summary>
250 /// IsEmpty Property
251 /// </summary>
253 /// <remarks>
254 /// Indicates if both Width and Height are zero.
255 /// </remarks>
257 [Browsable (false)]
258 public bool IsEmpty {
259 get {
260 return ((width == 0) && (height == 0));
264 /// <summary>
265 /// Width Property
266 /// </summary>
268 /// <remarks>
269 /// The Width coordinate of the Size.
270 /// </remarks>
272 public int Width {
273 get {
274 return width;
276 set {
277 width = value;
281 /// <summary>
282 /// Height Property
283 /// </summary>
285 /// <remarks>
286 /// The Height coordinate of the Size.
287 /// </remarks>
289 public int Height {
290 get {
291 return height;
293 set {
294 height = value;
298 /// <summary>
299 /// Equals Method
300 /// </summary>
302 /// <remarks>
303 /// Checks equivalence of this Size and another object.
304 /// </remarks>
306 public override bool Equals (object o)
308 if (!(o is Size))
309 return false;
311 return (this == (Size) o);
314 /// <summary>
315 /// GetHashCode Method
316 /// </summary>
318 /// <remarks>
319 /// Calculates a hashing value.
320 /// </remarks>
322 public override int GetHashCode ()
324 return width^height;
327 /// <summary>
328 /// ToString Method
329 /// </summary>
331 /// <remarks>
332 /// Formats the Size as a string in coordinate notation.
333 /// </remarks>
335 public override string ToString ()
337 return String.Format ("{{Width={0}, Height={1}}}", width, height);