123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- //
- // System.Drawing.Size.cs
- //
- // Author:
- // Mike Kestner ([email protected])
- //
- // Copyright (C) 2001 Mike Kestner
- // Copyright (C) 2004 Novell, Inc. http://www.novell.com
- //
- using System;
- namespace Terminal {
- /// <summary>
- /// Stores an ordered pair of integers, which specify a Height and Width.
- /// </summary>
- public struct Size
- {
- private int width, height;
- /// <summary>
- /// Gets a Size structure that has a Height and Width value of 0.
- /// </summary>
- public static readonly Size Empty;
- /// <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 sz1, Size sz2)
- {
- return ((sz1.Width == sz2.Width) &&
- (sz1.Height == sz2.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 sz1, Size sz2)
- {
- return ((sz1.Width != sz2.Width) ||
- (sz1.Height != sz2.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 size)
- {
- return new Point (size.Width, size.Height);
- }
- /// <summary>
- /// Size Constructor
- /// </summary>
- ///
- /// <remarks>
- /// Creates a Size from a Point value.
- /// </remarks>
-
- public Size (Point pt)
- {
- width = pt.X;
- height = pt.Y;
- }
- /// <summary>
- /// Size Constructor
- /// </summary>
- ///
- /// <remarks>
- /// Creates a Size from specified dimensions.
- /// </remarks>
-
- public Size (int width, int height)
- {
- this.width = width;
- this.height = height;
- }
- /// <summary>
- /// IsEmpty Property
- /// </summary>
- ///
- /// <remarks>
- /// Indicates if both Width and Height are zero.
- /// </remarks>
-
- public bool IsEmpty {
- get {
- return ((width == 0) && (height == 0));
- }
- }
- /// <summary>
- /// Width Property
- /// </summary>
- ///
- /// <remarks>
- /// The Width coordinate of the Size.
- /// </remarks>
-
- public int Width {
- get {
- return width;
- }
- set {
- width = value;
- }
- }
- /// <summary>
- /// Height Property
- /// </summary>
- ///
- /// <remarks>
- /// The Height coordinate of the Size.
- /// </remarks>
-
- public int Height {
- get {
- return height;
- }
- set {
- height = value;
- }
- }
- /// <summary>
- /// Equals Method
- /// </summary>
- ///
- /// <remarks>
- /// Checks equivalence of this Size and another object.
- /// </remarks>
-
- public override bool Equals (object obj)
- {
- if (!(obj is Size))
- return false;
- return (this == (Size) obj);
- }
- /// <summary>
- /// GetHashCode Method
- /// </summary>
- ///
- /// <remarks>
- /// Calculates a hashing value.
- /// </remarks>
-
- public override int GetHashCode ()
- {
- return width^height;
- }
- /// <summary>
- /// ToString Method
- /// </summary>
- ///
- /// <remarks>
- /// Formats the Size as a string in coordinate notation.
- /// </remarks>
-
- public override string ToString ()
- {
- return String.Format ("{{Width={0}, Height={1}}}", width, height);
- }
- /// <summary>
- /// Adds the width and height of one Size structure to the width and height of another Size structure.
- /// </summary>
- /// <returns>The add.</returns>
- /// <param name="sz1">The first Size structure to add.</param>
- /// <param name="sz2">The second Size structure to add.</param>
- 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);
- }
- }
- }
|