Răsfoiți Sursa

Added the PointF, Size, and SizeF structures to System.Drawing.

svn path=/trunk/mcs/; revision=490
Mike Kestner 24 ani în urmă
părinte
comite
bd02735dae

+ 4 - 0
mcs/class/System.Drawing/System.Drawing/ChangeLog

@@ -1,3 +1,7 @@
+2001-08-17  Mike Kestner <[email protected]>
+
+	* PointF.cs, Size.cs, SizeF.cs : New struct implementations.
+
 2001-08-16  Mike Kestner <[email protected]>
 
 	* Point.cs : New. Implementation of System.Drawing.Point struct.

+ 204 - 0
mcs/class/System.Drawing/System.Drawing/PointF.cs

@@ -0,0 +1,204 @@
+//
+// System.Drawing.PointF.cs
+//
+// Author:
+//   Mike Kestner ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System;
+
+namespace System.Drawing {
+	
+	public struct PointF { 
+		
+		// Private x and y coordinate fields.
+		float cx, cy;
+
+		// -----------------------
+		// Public Shared Members
+		// -----------------------
+
+		/// <summary>
+		///	Empty Shared Field
+		/// </summary>
+		///
+		/// <remarks>
+		///	An uninitialized PointF Structure.
+		/// </remarks>
+		
+		public static readonly PointF Empty;
+
+		/// <summary>
+		///	Addition Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Translates a PointF using the Width and Height
+		///	properties of the given Size.
+		/// </remarks>
+
+		public static PointF operator + (PointF pt, Size sz)
+		{
+			return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
+		}
+		
+		/// <summary>
+		///	Equality Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Compares two PointF objects. The return value is
+		///	based on the equivalence of the X and Y properties 
+		///	of the two points.
+		/// </remarks>
+
+		public static bool operator == (PointF pt_a, PointF pt_b)
+		{
+			return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y));
+		}
+		
+		/// <summary>
+		///	Inequality Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Compares two PointF objects. The return value is
+		///	based on the equivalence of the X and Y properties 
+		///	of the two points.
+		/// </remarks>
+
+		public static bool operator != (PointF pt_a, PointF pt_b)
+		{
+			return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y));
+		}
+		
+		/// <summary>
+		///	Subtraction Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Translates a PointF using the negation of the Width 
+		///	and Height properties of the given Size.
+		/// </remarks>
+
+		public static PointF operator - (PointF pt, Size sz)
+		{
+			return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
+		}
+		
+		// -----------------------
+		// Public Constructor
+		// -----------------------
+
+		/// <summary>
+		///	PointF Constructor
+		/// </summary>
+		///
+		/// <remarks>
+		///	Creates a PointF from a specified x,y coordinate pair.
+		/// </remarks>
+		
+		public PointF (float x, float y)
+		{
+			cx = x;
+			cy = y;
+		}
+
+		// -----------------------
+		// Public Instance Members
+		// -----------------------
+
+		/// <summary>
+		///	IsEmpty Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	Indicates if both X and Y are zero.
+		/// </remarks>
+		
+		public bool IsEmpty {
+			get {
+				return ((cx == 0.0) && (cy == 0.0));
+			}
+		}
+
+		/// <summary>
+		///	X Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	The X coordinate of the PointF.
+		/// </remarks>
+		
+		public float X {
+			get {
+				return cx;
+			}
+			set {
+				cx = value;
+			}
+		}
+
+		/// <summary>
+		///	Y Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	The Y coordinate of the PointF.
+		/// </remarks>
+		
+		public float Y {
+			get {
+				return cy;
+			}
+			set {
+				cy = value;
+			}
+		}
+
+		/// <summary>
+		///	Equals Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Checks equivalence of this PointF and another object.
+		/// </remarks>
+		
+		public override bool Equals (object o)
+		{
+			if (!(o is PointF))
+				return false;
+
+			return (this == (PointF) o);
+		}
+
+		/// <summary>
+		///	GetHashCode Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Calculates a hashing value.
+		/// </remarks>
+		
+		public override int GetHashCode ()
+		{
+			return (int) cx ^ (int) cy;
+		}
+
+		/// <summary>
+		///	ToString Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Formats the PointF as a string in coordinate notation.
+		/// </remarks>
+		
+		public override string ToString ()
+		{
+			return String.Format ("[{0},{1}]", cx, cy);
+		}
+
+	}
+}

+ 309 - 0
mcs/class/System.Drawing/System.Drawing/Size.cs

@@ -0,0 +1,309 @@
+//
+// System.Drawing.Size.cs
+//
+// Author:
+//   Mike Kestner ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System;
+
+namespace System.Drawing {
+	
+	public struct Size { 
+		
+		// Private height and width fields.
+		int wd, ht;
+
+		// -----------------------
+		// Public Shared Members
+		// -----------------------
+
+		/// <summary>
+		///	Empty Shared Field
+		/// </summary>
+		///
+		/// <remarks>
+		///	An uninitialized Size Structure.
+		/// </remarks>
+		
+		public static readonly Size Empty;
+
+		/// <summary>
+		///	Ceiling Shared Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Produces a Size structure from a SizeF structure by
+		///	taking the ceiling of the Width and Height properties.
+		/// </remarks>
+		
+		public static Size Ceiling (SizeF value)
+		{
+			int w, h;
+			checked {
+				w = (int) Math.Ceiling (value.Width);
+				h = (int) Math.Ceiling (value.Height);
+			}
+
+			return new Size (w, h);
+		}
+
+		/// <summary>
+		///	Round Shared Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Produces a Size structure from a SizeF structure by
+		///	rounding the Width and Height properties.
+		/// </remarks>
+		
+		public static Size Round (SizeF value)
+		{
+			int w, h;
+			checked {
+				w = (int) Math.Round (value.Width);
+				h = (int) Math.Round (value.Height);
+			}
+
+			return new Size (w, h);
+		}
+
+		/// <summary>
+		///	Truncate Shared Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Produces a Size structure from a SizeF structure by
+		///	truncating the Width and Height properties.
+		/// </remarks>
+		
+		public static Size Truncate (SizeF value)
+		{
+			int w, h;
+			checked {
+				w = (int) value.Width;
+				h = (int) value.Height;
+			}
+
+			return new Size (w, h);
+		}
+
+		/// <summary>
+		///	Addition Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Addition of two Size structures.
+		/// </remarks>
+
+		public static Size operator + (Size sz1, Size sz2)
+		{
+			return new Size (sz1.Width + sz2.Width, 
+					 sz1.Height + sz2.Height);
+		}
+		
+		/// <summary>
+		///	Equality Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Compares two Size objects. The return value is
+		///	based on the equivalence of the Width and Height 
+		///	properties of the two Sizes.
+		/// </remarks>
+
+		public static bool operator == (Size sz_a, Size sz_b)
+		{
+			return ((sz_a.Width == sz_b.Width) && 
+				(sz_a.Height == sz_b.Height));
+		}
+		
+		/// <summary>
+		///	Inequality Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Compares two Size objects. The return value is
+		///	based on the equivalence of the Width and Height 
+		///	properties of the two Sizes.
+		/// </remarks>
+
+		public static bool operator != (Size sz_a, Size sz_b)
+		{
+			return ((sz_a.Width != sz_b.Width) || 
+				(sz_a.Height != sz_b.Height));
+		}
+		
+		/// <summary>
+		///	Subtraction Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Subtracts two Size structures.
+		/// </remarks>
+
+		public static Size operator - (Size sz1, Size sz2)
+		{
+			return new Size (sz1.Width - sz2.Width, 
+					 sz1.Height - sz2.Height);
+		}
+		
+		/// <summary>
+		///	Size to Point Conversion
+		/// </summary>
+		///
+		/// <remarks>
+		///	Returns a Point based on the dimensions of a given 
+		///	Size. Requires explicit cast.
+		/// </remarks>
+
+		public static explicit operator Point (Size sz)
+		{
+			return new Point (sz.Width, sz.Height);
+		}
+
+		/// <summary>
+		///	Size to SizeF Conversion
+		/// </summary>
+		///
+		/// <remarks>
+		///	Creates a SizeF based on the dimensions of a given 
+		///	Size. No explicit cast is required.
+		/// </remarks>
+
+		public static implicit operator SizeF (Size sz)
+		{
+			return new SizeF (sz.Width, sz.Height);
+		}
+
+
+		// -----------------------
+		// Public Constructors
+		// -----------------------
+
+		/// <summary>
+		///	Size Constructor
+		/// </summary>
+		///
+		/// <remarks>
+		///	Creates a Size from a Point value.
+		/// </remarks>
+		
+		public Size (Point pt)
+		{
+			wd = pt.X;
+			ht = pt.Y;
+		}
+
+		/// <summary>
+		///	Size Constructor
+		/// </summary>
+		///
+		/// <remarks>
+		///	Creates a Size from specified dimensions.
+		/// </remarks>
+		
+		public Size (int width, int height)
+		{
+			wd = width;
+			ht = height;
+		}
+
+		// -----------------------
+		// Public Instance Members
+		// -----------------------
+
+		/// <summary>
+		///	IsEmpty Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	Indicates if both Width and Height are zero.
+		/// </remarks>
+		
+		public bool IsEmpty {
+			get {
+				return ((wd == 0) && (ht == 0));
+			}
+		}
+
+		/// <summary>
+		///	Width Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	The Width coordinate of the Size.
+		/// </remarks>
+		
+		public int Width {
+			get {
+				return wd;
+			}
+			set {
+				wd = value;
+			}
+		}
+
+		/// <summary>
+		///	Height Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	The Height coordinate of the Size.
+		/// </remarks>
+		
+		public int Height {
+			get {
+				return ht;
+			}
+			set {
+				ht = value;
+			}
+		}
+
+		/// <summary>
+		///	Equals Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Checks equivalence of this Size and another object.
+		/// </remarks>
+		
+		public override bool Equals (object o)
+		{
+			if (!(o is Size))
+				return false;
+
+			return (this == (Size) o);
+		}
+
+		/// <summary>
+		///	GetHashCode Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Calculates a hashing value.
+		/// </remarks>
+		
+		public override int GetHashCode ()
+		{
+			return wd^ht;
+		}
+
+		/// <summary>
+		///	ToString Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Formats the Size as a string in coordinate notation.
+		/// </remarks>
+		
+		public override string ToString ()
+		{
+			return String.Format ("[{0},{1}]", wd, ht);
+		}
+
+	}
+}

+ 249 - 0
mcs/class/System.Drawing/System.Drawing/SizeF.cs

@@ -0,0 +1,249 @@
+//
+// System.Drawing.SizeF.cs
+//
+// Author:
+//   Mike Kestner ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System;
+
+namespace System.Drawing {
+	
+	public struct SizeF { 
+		
+		// Private height and width fields.
+		float wd, ht;
+
+		// -----------------------
+		// Public Shared Members
+		// -----------------------
+
+		/// <summary>
+		///	Empty Shared Field
+		/// </summary>
+		///
+		/// <remarks>
+		///	An uninitialized SizeF Structure.
+		/// </remarks>
+		
+		public static readonly SizeF Empty;
+
+		/// <summary>
+		///	Addition Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Addition of two SizeF structures.
+		/// </remarks>
+
+		public static SizeF operator + (SizeF sz1, SizeF sz2)
+		{
+			return new SizeF (sz1.Width + sz2.Width, 
+					  sz1.Height + sz2.Height);
+		}
+		
+		/// <summary>
+		///	Equality Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Compares two SizeF objects. The return value is
+		///	based on the equivalence of the Width and Height 
+		///	properties of the two Sizes.
+		/// </remarks>
+
+		public static bool operator == (SizeF sz_a, SizeF sz_b)
+		{
+			return ((sz_a.Width == sz_b.Width) && 
+				(sz_a.Height == sz_b.Height));
+		}
+		
+		/// <summary>
+		///	Inequality Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Compares two SizeF objects. The return value is
+		///	based on the equivalence of the Width and Height 
+		///	properties of the two Sizes.
+		/// </remarks>
+
+		public static bool operator != (SizeF sz_a, SizeF sz_b)
+		{
+			return ((sz_a.Width != sz_b.Width) || 
+				(sz_a.Height != sz_b.Height));
+		}
+		
+		/// <summary>
+		///	Subtraction Operator
+		/// </summary>
+		///
+		/// <remarks>
+		///	Subtracts two SizeF structures.
+		/// </remarks>
+
+		public static SizeF operator - (SizeF sz1, SizeF sz2)
+		{
+			return new SizeF (sz1.Width - sz2.Width, 
+					  sz1.Height - sz2.Height);
+		}
+		
+		/// <summary>
+		///	SizeF to PointF Conversion
+		/// </summary>
+		///
+		/// <remarks>
+		///	Returns a PointF based on the dimensions of a given 
+		///	SizeF. Requires explicit cast.
+		/// </remarks>
+
+		public static explicit operator PointF (SizeF sz)
+		{
+			return new PointF (sz.Width, sz.Height);
+		}
+
+
+		// -----------------------
+		// Public Constructors
+		// -----------------------
+
+		/// <summary>
+		///	SizeF Constructor
+		/// </summary>
+		///
+		/// <remarks>
+		///	Creates a SizeF from a PointF value.
+		/// </remarks>
+		
+		public SizeF (PointF pt)
+		{
+			wd = pt.X;
+			ht = pt.Y;
+		}
+
+		/// <summary>
+		///	SizeF Constructor
+		/// </summary>
+		///
+		/// <remarks>
+		///	Creates a SizeF from an existing SizeF value.
+		/// </remarks>
+		
+		public SizeF (SizeF sz)
+		{
+			wd = sz.Width;
+			ht = sz.Height;
+		}
+
+		/// <summary>
+		///	SizeF Constructor
+		/// </summary>
+		///
+		/// <remarks>
+		///	Creates a SizeF from specified dimensions.
+		/// </remarks>
+		
+		public SizeF (float width, float height)
+		{
+			wd = width;
+			ht = height;
+		}
+
+		// -----------------------
+		// Public Instance Members
+		// -----------------------
+
+		/// <summary>
+		///	IsEmpty Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	Indicates if both Width and Height are zero.
+		/// </remarks>
+		
+		public bool IsEmpty {
+			get {
+				return ((wd == 0.0) && (ht == 0.0));
+			}
+		}
+
+		/// <summary>
+		///	Width Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	The Width coordinate of the SizeF.
+		/// </remarks>
+		
+		public float Width {
+			get {
+				return wd;
+			}
+			set {
+				wd = value;
+			}
+		}
+
+		/// <summary>
+		///	Height Property
+		/// </summary>
+		///
+		/// <remarks>
+		///	The Height coordinate of the SizeF.
+		/// </remarks>
+		
+		public float Height {
+			get {
+				return ht;
+			}
+			set {
+				ht = value;
+			}
+		}
+
+		/// <summary>
+		///	Equals Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Checks equivalence of this SizeF and another object.
+		/// </remarks>
+		
+		public override bool Equals (object o)
+		{
+			if (!(o is SizeF))
+				return false;
+
+			return (this == (SizeF) o);
+		}
+
+		/// <summary>
+		///	GetHashCode Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Calculates a hashing value.
+		/// </remarks>
+		
+		public override int GetHashCode ()
+		{
+			return (int) wd ^ (int) ht;
+		}
+
+		/// <summary>
+		///	ToString Method
+		/// </summary>
+		///
+		/// <remarks>
+		///	Formats the SizeF as a string in coordinate notation.
+		/// </remarks>
+		
+		public override string ToString ()
+		{
+			return String.Format ("[{0},{1}]", wd, ht);
+		}
+
+	}
+}