// // System.Drawing.Size.cs // // Author: // Mike Kestner (mkestner@speakeasy.net) // // Copyright (C) 2001 Mike Kestner // Copyright (C) 2004 Novell, Inc. http://www.novell.com // using System; namespace Terminal { /// /// Stores an ordered pair of integers, which specify a Height and Width. /// public struct Size { private int width, height; /// /// Gets a Size structure that has a Height and Width value of 0. /// public static readonly Size Empty; /// /// Addition Operator /// /// /// /// Addition of two Size structures. /// public static Size operator + (Size sz1, Size sz2) { return new Size (sz1.Width + sz2.Width, sz1.Height + sz2.Height); } /// /// Equality Operator /// /// /// /// Compares two Size objects. The return value is /// based on the equivalence of the Width and Height /// properties of the two Sizes. /// public static bool operator == (Size sz1, Size sz2) { return ((sz1.Width == sz2.Width) && (sz1.Height == sz2.Height)); } /// /// Inequality Operator /// /// /// /// Compares two Size objects. The return value is /// based on the equivalence of the Width and Height /// properties of the two Sizes. /// public static bool operator != (Size sz1, Size sz2) { return ((sz1.Width != sz2.Width) || (sz1.Height != sz2.Height)); } /// /// Subtraction Operator /// /// /// /// Subtracts two Size structures. /// public static Size operator - (Size sz1, Size sz2) { return new Size (sz1.Width - sz2.Width, sz1.Height - sz2.Height); } /// /// Size to Point Conversion /// /// /// /// Returns a Point based on the dimensions of a given /// Size. Requires explicit cast. /// public static explicit operator Point (Size size) { return new Point (size.Width, size.Height); } /// /// Size Constructor /// /// /// /// Creates a Size from a Point value. /// public Size (Point pt) { width = pt.X; height = pt.Y; } /// /// Size Constructor /// /// /// /// Creates a Size from specified dimensions. /// public Size (int width, int height) { this.width = width; this.height = height; } /// /// IsEmpty Property /// /// /// /// Indicates if both Width and Height are zero. /// public bool IsEmpty { get { return ((width == 0) && (height == 0)); } } /// /// Width Property /// /// /// /// The Width coordinate of the Size. /// public int Width { get { return width; } set { width = value; } } /// /// Height Property /// /// /// /// The Height coordinate of the Size. /// public int Height { get { return height; } set { height = value; } } /// /// Equals Method /// /// /// /// Checks equivalence of this Size and another object. /// public override bool Equals (object obj) { if (!(obj is Size)) return false; return (this == (Size) obj); } /// /// GetHashCode Method /// /// /// /// Calculates a hashing value. /// public override int GetHashCode () { return width^height; } /// /// ToString Method /// /// /// /// Formats the Size as a string in coordinate notation. /// public override string ToString () { return String.Format ("{{Width={0}, Height={1}}}", width, height); } /// /// Adds the width and height of one Size structure to the width and height of another Size structure. /// /// The add. /// The first Size structure to add. /// The second Size structure to add. public static Size Add (Size sz1, Size sz2) { return new Size (sz1.Width + sz2.Width, sz1.Height + sz2.Height); } public static Size Subtract (Size sz1, Size sz2) { return new Size (sz1.Width - sz2.Width, sz1.Height - sz2.Height); } } }