From c445cbb6af954b8ac45c4bbf313ab5048340f764 Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 15 Apr 2024 22:06:27 +0200 Subject: [PATCH] Equality overrides --- OBSBlur/Window/{POINT.cs => Point.cs} | 15 +++++++++++++++ OBSBlur/Window/WindowInfo.cs | 18 ++++++++++++++++++ .../{WINDOWPLACEMENT.cs => WindowPlacement.cs} | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+) rename OBSBlur/Window/{POINT.cs => Point.cs} (67%) rename OBSBlur/Window/{WINDOWPLACEMENT.cs => WindowPlacement.cs} (77%) diff --git a/OBSBlur/Window/POINT.cs b/OBSBlur/Window/Point.cs similarity index 67% rename from OBSBlur/Window/POINT.cs rename to OBSBlur/Window/Point.cs index 1aefb23..9dffb09 100644 --- a/OBSBlur/Window/POINT.cs +++ b/OBSBlur/Window/Point.cs @@ -28,4 +28,19 @@ public struct Point { return $"{{X={X,-7:####0}, Y={Y,-7:####0}}}"; } + + public override bool Equals(object? obj) + { + return obj is Point other && Equals(other); + } + + public bool Equals(Point other) + { + return X == other.X && Y == other.Y; + } + + public override int GetHashCode() + { + return HashCode.Combine(X, Y); + } } \ No newline at end of file diff --git a/OBSBlur/Window/WindowInfo.cs b/OBSBlur/Window/WindowInfo.cs index 94d4e5e..c3bd450 100644 --- a/OBSBlur/Window/WindowInfo.cs +++ b/OBSBlur/Window/WindowInfo.cs @@ -17,6 +17,24 @@ public struct WindowInfo this.WindowTitle = windowTitle; } + public override bool Equals(object? obj) + { + return obj is WindowInfo other && Equals(other); + } + + public bool Equals(WindowInfo other) + { + return WindowHandle == other.WindowHandle && + WindowPlacement.Equals(other.WindowPlacement) && + WindowTitle == other.WindowTitle && + ProcessInfo.Equals(other.ProcessInfo); + } + + public override int GetHashCode() + { + return HashCode.Combine(WindowHandle, WindowPlacement, WindowTitle, ProcessInfo); + } + public override string ToString() { const int cutoffStr = 17; diff --git a/OBSBlur/Window/WINDOWPLACEMENT.cs b/OBSBlur/Window/WindowPlacement.cs similarity index 77% rename from OBSBlur/Window/WINDOWPLACEMENT.cs rename to OBSBlur/Window/WindowPlacement.cs index ccc83a1..5360133 100644 --- a/OBSBlur/Window/WINDOWPLACEMENT.cs +++ b/OBSBlur/Window/WindowPlacement.cs @@ -59,4 +59,22 @@ public struct WINDOWPLACEMENT { return $"CMD: {ShowCmd,13} Min: {MinPosition} Max: {MaxPosition} Normal: {NormalPosition}"; } + + public override bool Equals(object? obj) + { + return obj is WindowPlacement other && Equals(other); + } + + public bool Equals(WindowPlacement other) + { + return ShowCmd == other.ShowCmd && + MinPosition.Equals(other.MinPosition) && + MaxPosition.Equals(other.MaxPosition) && + NormalPosition.Equals(other.NormalPosition); + } + + public override int GetHashCode() + { + return HashCode.Combine((int)ShowCmd, MinPosition, MaxPosition, NormalPosition); + } } \ No newline at end of file