using System; using System.Runtime.InteropServices; namespace NvAPIWrapper.Native.Display.Structures { /// /// Holds a [Width, Height] pair as the resolution of a display device, as well as a color format /// [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct Resolution : IEquatable { internal readonly uint _Width; internal readonly uint _Height; internal readonly uint _ColorDepth; /// /// Creates a new Resolution /// /// Display resolution width /// Display resolution height /// Display color depth public Resolution(int width, int height, int colorDepth) { _Width = (uint) width; _Height = (uint) height; _ColorDepth = (uint) colorDepth; } /// public bool Equals(Resolution other) { return _Width == other._Width && _Height == other._Height && _ColorDepth == other._ColorDepth; } /// public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } return obj is Resolution resolution && Equals(resolution); } /// public override int GetHashCode() { unchecked { var hashCode = (int) _Width; hashCode = (hashCode * 397) ^ (int) _Height; hashCode = (hashCode * 397) ^ (int) _ColorDepth; return hashCode; } } /// /// Checks for equality between two objects of same type /// /// The first object /// The second object /// true, if both objects are equal, otherwise false public static bool operator ==(Resolution left, Resolution right) { return left.Equals(right); } /// /// Checks for inequality between two objects of same type /// /// The first object /// The second object /// true, if both objects are not equal, otherwise false public static bool operator !=(Resolution left, Resolution right) { return !left.Equals(right); } /// public override string ToString() { return $"({Width}, {Height}) @ {ColorDepth}bpp"; } /// /// Display resolution width /// public int Width { get => (int) _Width; } /// /// Display resolution height /// public int Height { get => (int) _Height; } /// /// Display color depth /// public int ColorDepth { get => (int) _ColorDepth; } } }