/* This Source Code is partially based on reverse engineering of the Windows Operating System, and is intended for use on Windows systems only. This Source Code is partially based on the source code provided by the .NET Foundation. */ using System.Runtime.InteropServices; namespace WPFluent.Interop.WinDef; // ReSharper disable InconsistentNaming /// /// The RECTL structure defines a rectangle by the coordinates of its upper-left and lower-right corners. /// [StructLayout(LayoutKind.Sequential)] public struct RECTL { private long _left; private long _top; private long _right; private long _bottom; public static bool operator !=(RECTL left, RECTL right) { return !(left == right); } public static bool operator ==(RECTL left, RECTL right) { return left.Equals(right); } /// public override readonly bool Equals(object? obj) { if(obj is not RECTL) { return false; } try { var rc = (RECTL)obj; return rc._bottom == _bottom && rc._left == _left && rc._right == _right && rc._top == _top; } catch(InvalidCastException) { return false; } } /// public override readonly int GetHashCode() { return _top.GetHashCode() ^ _bottom.GetHashCode() ^ _left.GetHashCode() ^ _right.GetHashCode(); } /// /// Sets offset of the rectangle. /// public void Offset(int dx, int dy) { _left += dx; _top += dy; _right += dx; _bottom += dy; } /// /// Combines two RECTLs /// public static RECTL Union(RECTL rect1, RECTL rect2) { return new RECTL { Left = Math.Min(rect1.Left, rect2.Left), Top = Math.Min(rect1.Top, rect2.Top), Right = Math.Max(rect1.Right, rect2.Right), Bottom = Math.Max(rect1.Bottom, rect2.Bottom), }; } /// /// Gets or sets the y-coordinate of the lower-right corner of the rectangle. /// public long Bottom { readonly get { return _bottom; } set { _bottom = value; } } /// /// Gets the height of the rectangle. /// public readonly long Height { get { return _bottom - _top; } } /// /// Gets or sets the x-coordinate of the upper-left corner of the rectangle. /// public long Left { readonly get { return _left; } set { _left = value; } } /// /// Gets the position of the rectangle. /// public POINTL Position { get { return new POINTL { x = _left, y = _top }; } } /// /// Gets or sets the x-coordinate of the lower-right corner of the rectangle. /// public long Right { readonly get { return _right; } set { _right = value; } } /// /// Gets the size of the rectangle. /// public SIZE Size { get { return new SIZE { cx = Width, cy = Height }; } } /// /// Gets or sets the y-coordinate of the upper-left corner of the rectangle. /// public long Top { readonly get { return _top; } set { _top = value; } } /// /// Gets the width of the rectangle. /// public readonly long Width { get { return _right - _left; } } }