mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Gamma Init
This commit is contained in:
104
app/WindowsDisplayAPI/Native/Structures/LUID.cs
Normal file
104
app/WindowsDisplayAPI/Native/Structures/LUID.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.Structures
|
||||
{
|
||||
/// <summary>
|
||||
/// Locally unique identifier is a 64-bit value guaranteed to be unique only on the system on which it was generated.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct LUID : IEquatable<LUID>
|
||||
{
|
||||
/// <summary>
|
||||
/// 32Bit unsigned integer, low
|
||||
/// </summary>
|
||||
public readonly uint LowPart;
|
||||
|
||||
/// <summary>
|
||||
/// 32Bit signed integer, high
|
||||
/// </summary>
|
||||
public readonly int HighPart;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new LUID
|
||||
/// </summary>
|
||||
/// <param name="lowPart">32Bit unsigned integer, low</param>
|
||||
/// <param name="highPart">32Bit signed integer, high</param>
|
||||
public LUID(uint lowPart, int highPart)
|
||||
{
|
||||
LowPart = lowPart;
|
||||
HighPart = highPart;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ {LowPart:X} - {HighPart:X} }}";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(LUID other)
|
||||
{
|
||||
return LowPart == other.LowPart && HighPart == other.HighPart;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is LUID luid && Equals(luid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for equality between two objects of same type
|
||||
/// </summary>
|
||||
/// <param name="left">The first object</param>
|
||||
/// <param name="right">The second object</param>
|
||||
/// <returns>true, if both objects are equal, otherwise false</returns>
|
||||
public static bool operator ==(LUID left, LUID right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for inequality between two objects of same type
|
||||
/// </summary>
|
||||
/// <param name="left">The first object</param>
|
||||
/// <param name="right">The second object</param>
|
||||
/// <returns>true, if both objects are not equal, otherwise false</returns>
|
||||
public static bool operator !=(LUID left, LUID right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((int) LowPart * 397) ^ HighPart;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this type is empty and holds no real data
|
||||
/// </summary>
|
||||
/// <returns>true if empty, otherwise false</returns>
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return LowPart == 0 && HighPart == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an empty instance of this type
|
||||
/// </summary>
|
||||
public static LUID Empty
|
||||
{
|
||||
get => default;
|
||||
}
|
||||
}
|
||||
}
|
||||
74
app/WindowsDisplayAPI/Native/Structures/PointL.cs
Normal file
74
app/WindowsDisplayAPI/Native/Structures/PointL.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/dd162807(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct PointL : IEquatable<PointL>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.I4)] public readonly int X;
|
||||
[MarshalAs(UnmanagedType.I4)] public readonly int Y;
|
||||
|
||||
[Pure]
|
||||
public Point ToPoint()
|
||||
{
|
||||
return new Point(X, Y);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public Size ToSize()
|
||||
{
|
||||
return new Size(X, Y);
|
||||
}
|
||||
|
||||
public PointL(Point point) : this(point.X, point.Y)
|
||||
{
|
||||
}
|
||||
|
||||
public PointL(Size size) : this(size.Width, size.Height)
|
||||
{
|
||||
}
|
||||
|
||||
public PointL(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public bool Equals(PointL other)
|
||||
{
|
||||
return X == other.X && Y == other.Y;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is PointL point && Equals(point);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (X * 397) ^ Y;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(PointL left, PointL right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(PointL left, PointL right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
app/WindowsDisplayAPI/Native/Structures/RectangleL.cs
Normal file
73
app/WindowsDisplayAPI/Native/Structures/RectangleL.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WindowsDisplayAPI.Native.Structures
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/vs/alm/dd162907(v=vs.85).aspx
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct RectangleL : IEquatable<RectangleL>
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Left;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Top;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Right;
|
||||
[MarshalAs(UnmanagedType.U4)] public readonly int Bottom;
|
||||
|
||||
[Pure]
|
||||
public Rectangle ToRectangle()
|
||||
{
|
||||
return new Rectangle(Left, Top, Right - Left, Bottom - Top);
|
||||
}
|
||||
|
||||
public RectangleL(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
public RectangleL(Rectangle rectangle) : this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Equals(RectangleL other)
|
||||
{
|
||||
return Left == other.Left && Top == other.Top && Right == other.Right && Bottom == other.Bottom;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj is RectangleL rectangle && Equals(rectangle);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = Left;
|
||||
hashCode = (hashCode * 397) ^ Top;
|
||||
hashCode = (hashCode * 397) ^ Right;
|
||||
hashCode = (hashCode * 397) ^ Bottom;
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(RectangleL left, RectangleL right)
|
||||
{
|
||||
return Equals(left, right) || left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(RectangleL left, RectangleL right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user