mirror of
https://github.com/turusudiro/SteamEmuUtility.git
synced 2026-02-08 10:01:19 +01:00
227 lines
5.7 KiB
C#
227 lines
5.7 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Playnite.Native
|
|
{
|
|
public static class Windef
|
|
{
|
|
internal static int LOWORD(int i)
|
|
{
|
|
return (short)(i & 0xFFFF);
|
|
}
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct POINTL
|
|
{
|
|
public int x;
|
|
public int y;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct SIZE
|
|
{
|
|
public int cx;
|
|
public int cy;
|
|
}
|
|
|
|
[Serializable]
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct POINT
|
|
{
|
|
private int _x;
|
|
private int _y;
|
|
|
|
public POINT(int x, int y)
|
|
{
|
|
_x = x;
|
|
_y = y;
|
|
}
|
|
|
|
public int X
|
|
{
|
|
get { return _x; }
|
|
set { _x = value; }
|
|
}
|
|
|
|
public int Y
|
|
{
|
|
get { return _y; }
|
|
set { _y = value; }
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj is POINT)
|
|
{
|
|
var point = (POINT)obj;
|
|
|
|
return point._x == _x && point._y == _y;
|
|
}
|
|
return base.Equals(obj);
|
|
}
|
|
public override int GetHashCode()
|
|
{
|
|
return _x.GetHashCode() ^ _y.GetHashCode();
|
|
}
|
|
|
|
public static bool operator ==(POINT a, POINT b)
|
|
{
|
|
return a._x == b._x && a._y == b._y;
|
|
}
|
|
|
|
public static bool operator !=(POINT a, POINT b)
|
|
{
|
|
return !(a == b);
|
|
}
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
|
public struct RECT
|
|
{
|
|
private int _left;
|
|
private int _top;
|
|
private int _right;
|
|
private int _bottom;
|
|
|
|
public static readonly RECT Empty = new RECT();
|
|
|
|
public RECT(int left, int top, int right, int bottom)
|
|
{
|
|
this._left = left;
|
|
this._top = top;
|
|
this._right = right;
|
|
this._bottom = bottom;
|
|
}
|
|
|
|
public RECT(RECT rcSrc)
|
|
{
|
|
_left = rcSrc.Left;
|
|
_top = rcSrc.Top;
|
|
_right = rcSrc.Right;
|
|
_bottom = rcSrc.Bottom;
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public void Offset(int dx, int dy)
|
|
{
|
|
_left += dx;
|
|
_top += dy;
|
|
_right += dx;
|
|
_bottom += dy;
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public int Left
|
|
{
|
|
get { return _left; }
|
|
set { _left = value; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public int Right
|
|
{
|
|
get { return _right; }
|
|
set { _right = value; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public int Top
|
|
{
|
|
get { return _top; }
|
|
set { _top = value; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public int Bottom
|
|
{
|
|
get { return _bottom; }
|
|
set { _bottom = value; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public int Width
|
|
{
|
|
get { return _right - _left; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public int Height
|
|
{
|
|
get { return _bottom - _top; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public POINT Position
|
|
{
|
|
get { return new POINT { X = _left, Y = _top }; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public SIZE Size
|
|
{
|
|
get { return new SIZE { cx = Width, cy = Height }; }
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
public static RECT Union(RECT rect1, RECT rect2)
|
|
{
|
|
return new RECT
|
|
{
|
|
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),
|
|
};
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
try
|
|
{
|
|
var rc = (RECT)obj;
|
|
return rc._bottom == _bottom
|
|
&& rc._left == _left
|
|
&& rc._right == _right
|
|
&& rc._top == _top;
|
|
}
|
|
catch (InvalidCastException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool IsEmpty
|
|
{
|
|
get
|
|
{
|
|
// BUGBUG : On Bidi OS (hebrew arabic) left > right
|
|
return Left >= Right || Top >= Bottom;
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
if (this == Empty)
|
|
return "RECT {Empty}";
|
|
return "RECT { left : " + Left + " / top : " + Top + " / right : " + Right + " / bottom : " + Bottom + " }";
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return (_left << 16 | Windef.LOWORD(_right)) ^ (_top << 16 | Windef.LOWORD(_bottom));
|
|
}
|
|
|
|
public static bool operator ==(RECT rect1, RECT rect2)
|
|
{
|
|
return (rect1.Left == rect2.Left && rect1.Top == rect2.Top && rect1.Right == rect2.Right && rect1.Bottom == rect2.Bottom);
|
|
}
|
|
|
|
public static bool operator !=(RECT rect1, RECT rect2)
|
|
{
|
|
return !(rect1 == rect2);
|
|
}
|
|
}
|
|
}
|