Added missing attributes to relevent classes and corrected coding style mistakes...
[mono.git] / mcs / class / System.Drawing / System.Drawing / SizeF.cs
1 //
2 // System.Drawing.SizeF.cs
3 //
4 // Author:
5 //   Mike Kestner (mkestner@speakeasy.net)
6 //
7 // (C) 2001 Mike Kestner
8 //
9
10 using System;
11 using System.Runtime.InteropServices;
12
13 namespace System.Drawing {
14
15         [Serializable]
16         [ComVisible (true)]
17         public struct SizeF { 
18                 
19                 // Private height and width fields.
20                 float wd, ht;
21
22                 // -----------------------
23                 // Public Shared Members
24                 // -----------------------
25
26                 /// <summary>
27                 ///     Empty Shared Field
28                 /// </summary>
29                 ///
30                 /// <remarks>
31                 ///     An uninitialized SizeF Structure.
32                 /// </remarks>
33                 
34                 public static readonly SizeF Empty;
35
36                 /// <summary>
37                 ///     Addition Operator
38                 /// </summary>
39                 ///
40                 /// <remarks>
41                 ///     Addition of two SizeF structures.
42                 /// </remarks>
43
44                 public static SizeF operator + (SizeF sz1, SizeF sz2)
45                 {
46                         return new SizeF (sz1.Width + sz2.Width, 
47                                           sz1.Height + sz2.Height);
48                 }
49                 
50                 /// <summary>
51                 ///     Equality Operator
52                 /// </summary>
53                 ///
54                 /// <remarks>
55                 ///     Compares two SizeF objects. The return value is
56                 ///     based on the equivalence of the Width and Height 
57                 ///     properties of the two Sizes.
58                 /// </remarks>
59
60                 public static bool operator == (SizeF sz_a, SizeF sz_b)
61                 {
62                         return ((sz_a.Width == sz_b.Width) && 
63                                 (sz_a.Height == sz_b.Height));
64                 }
65                 
66                 /// <summary>
67                 ///     Inequality Operator
68                 /// </summary>
69                 ///
70                 /// <remarks>
71                 ///     Compares two SizeF objects. The return value is
72                 ///     based on the equivalence of the Width and Height 
73                 ///     properties of the two Sizes.
74                 /// </remarks>
75
76                 public static bool operator != (SizeF sz_a, SizeF sz_b)
77                 {
78                         return ((sz_a.Width != sz_b.Width) || 
79                                 (sz_a.Height != sz_b.Height));
80                 }
81                 
82                 /// <summary>
83                 ///     Subtraction Operator
84                 /// </summary>
85                 ///
86                 /// <remarks>
87                 ///     Subtracts two SizeF structures.
88                 /// </remarks>
89
90                 public static SizeF operator - (SizeF sz1, SizeF sz2)
91                 {
92                         return new SizeF (sz1.Width - sz2.Width, 
93                                           sz1.Height - sz2.Height);
94                 }
95                 
96                 /// <summary>
97                 ///     SizeF to PointF Conversion
98                 /// </summary>
99                 ///
100                 /// <remarks>
101                 ///     Returns a PointF based on the dimensions of a given 
102                 ///     SizeF. Requires explicit cast.
103                 /// </remarks>
104
105                 public static explicit operator PointF (SizeF sz)
106                 {
107                         return new PointF (sz.Width, sz.Height);
108                 }
109
110
111                 // -----------------------
112                 // Public Constructors
113                 // -----------------------
114
115                 /// <summary>
116                 ///     SizeF Constructor
117                 /// </summary>
118                 ///
119                 /// <remarks>
120                 ///     Creates a SizeF from a PointF value.
121                 /// </remarks>
122                 
123                 public SizeF (PointF pt)
124                 {
125                         wd = pt.X;
126                         ht = pt.Y;
127                 }
128
129                 /// <summary>
130                 ///     SizeF Constructor
131                 /// </summary>
132                 ///
133                 /// <remarks>
134                 ///     Creates a SizeF from an existing SizeF value.
135                 /// </remarks>
136                 
137                 public SizeF (SizeF sz)
138                 {
139                         wd = sz.Width;
140                         ht = sz.Height;
141                 }
142
143                 /// <summary>
144                 ///     SizeF Constructor
145                 /// </summary>
146                 ///
147                 /// <remarks>
148                 ///     Creates a SizeF from specified dimensions.
149                 /// </remarks>
150                 
151                 public SizeF (float width, float height)
152                 {
153                         wd = width;
154                         ht = height;
155                 }
156
157                 // -----------------------
158                 // Public Instance Members
159                 // -----------------------
160
161                 /// <summary>
162                 ///     IsEmpty Property
163                 /// </summary>
164                 ///
165                 /// <remarks>
166                 ///     Indicates if both Width and Height are zero.
167                 /// </remarks>
168                 
169                 public bool IsEmpty {
170                         get {
171                                 return ((wd == 0.0) && (ht == 0.0));
172                         }
173                 }
174
175                 /// <summary>
176                 ///     Width Property
177                 /// </summary>
178                 ///
179                 /// <remarks>
180                 ///     The Width coordinate of the SizeF.
181                 /// </remarks>
182                 
183                 public float Width {
184                         get {
185                                 return wd;
186                         }
187                         set {
188                                 wd = value;
189                         }
190                 }
191
192                 /// <summary>
193                 ///     Height Property
194                 /// </summary>
195                 ///
196                 /// <remarks>
197                 ///     The Height coordinate of the SizeF.
198                 /// </remarks>
199                 
200                 public float Height {
201                         get {
202                                 return ht;
203                         }
204                         set {
205                                 ht = value;
206                         }
207                 }
208
209                 /// <summary>
210                 ///     Equals Method
211                 /// </summary>
212                 ///
213                 /// <remarks>
214                 ///     Checks equivalence of this SizeF and another object.
215                 /// </remarks>
216                 
217                 public override bool Equals (object o)
218                 {
219                         if (!(o is SizeF))
220                                 return false;
221
222                         return (this == (SizeF) o);
223                 }
224
225                 /// <summary>
226                 ///     GetHashCode Method
227                 /// </summary>
228                 ///
229                 /// <remarks>
230                 ///     Calculates a hashing value.
231                 /// </remarks>
232                 
233                 public override int GetHashCode ()
234                 {
235                         return (int) wd ^ (int) ht;
236                 }
237
238                 /// <summary>
239                 ///     ToString Method
240                 /// </summary>
241                 ///
242                 /// <remarks>
243                 ///     Formats the SizeF as a string in coordinate notation.
244                 /// </remarks>
245                 
246                 public override string ToString ()
247                 {
248                         return String.Format ("[{0},{1}]", wd, ht);
249                 }
250
251         }
252 }