1 // Size.cs
2 //
3 // Author:  Mike Kestner (mkestner@speakeasy.net)
4 //
5 // Copyright (c) 2001 Mike Kestner
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of version 2 of the Lesser GNU General
9 // Public License as published by the Free Software Foundation.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this program; if not, write to the
18 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA.
20 
21 
22 using System;
23 
24 namespace Gdk {
25 
26 	public struct Size : IEquatable<Size> {
27 
28 		int width, height;
29 
30 		public static readonly Size Empty;
31 
operator +Gdk.Size32 		public static Size operator + (Size sz1, Size sz2)
33 		{
34 			return new Size (sz1.Width + sz2.Width,
35 					 sz1.Height + sz2.Height);
36 		}
37 
operator ==Gdk.Size38 		public static bool operator == (Size sz_a, Size sz_b)
39 		{
40 			return ((sz_a.Width == sz_b.Width) &&
41 				(sz_a.Height == sz_b.Height));
42 		}
43 
operator !=Gdk.Size44 		public static bool operator != (Size sz_a, Size sz_b)
45 		{
46 			return ((sz_a.Width != sz_b.Width) ||
47 				(sz_a.Height != sz_b.Height));
48 		}
49 
operator -Gdk.Size50 		public static Size operator - (Size sz1, Size sz2)
51 		{
52 			return new Size (sz1.Width - sz2.Width,
53 					 sz1.Height - sz2.Height);
54 		}
55 
operator PointGdk.Size56 		public static explicit operator Point (Size sz)
57 		{
58 			return new Point (sz.Width, sz.Height);
59 		}
60 
SizeGdk.Size61 		public Size (Point pt)
62 		{
63 			width = pt.X;
64 			height = pt.Y;
65 		}
66 
SizeGdk.Size67 		public Size (int width, int height)
68 		{
69 			this.width = width;
70 			this.height = height;
71 		}
72 
73 		public bool IsEmpty {
74 			get {
75 				return ((width == 0) && (height == 0));
76 			}
77 		}
78 
79 		public int Width {
80 			get {
81 				return width;
82 			}
83 			set {
84 				width = value;
85 			}
86 		}
87 
88 		public int Height {
89 			get {
90 				return height;
91 			}
92 			set {
93 				height = value;
94 			}
95 		}
96 
EqualsGdk.Size97 		public override bool Equals (object o)
98 		{
99 			if (!(o is Size))
100 				return false;
101 
102 			return (this == (Size) o);
103 		}
104 
EqualsGdk.Size105 		public bool Equals (Size other)
106 		{
107 			return this == other;
108 		}
109 
GetHashCodeGdk.Size110 		public override int GetHashCode ()
111 		{
112 			return width^height;
113 		}
114 
ToStringGdk.Size115 		public override string ToString ()
116 		{
117 			return String.Format ("{{Width={0}, Height={1}}}", width, height);
118 		}
119 	}
120 }
121