From a3141b5d0c1e84b67de0a222adbfd8e1f5a8c813 Mon Sep 17 00:00:00 2001 From: Jimmy Quach Date: Fri, 17 Jan 2025 10:06:52 -0800 Subject: [PATCH] refactor: WindowSize.Rect struct --- Classes/Services/DetectionService.cs | 2 +- Classes/Services/WindowService.cs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Classes/Services/DetectionService.cs b/Classes/Services/DetectionService.cs index 13e1180c..287afd74 100644 --- a/Classes/Services/DetectionService.cs +++ b/Classes/Services/DetectionService.cs @@ -212,7 +212,7 @@ public static bool AutoDetectGame(int processId, string executablePath, nint win var aspectRatio = GetAspectRatio(windowSize.GetWidth(), windowSize.GetHeight()); bool isValidAspectRatio = IsValidAspectRatio(windowSize.GetWidth(), windowSize.GetHeight()); bool isWhitelistedClass = classWhitelist.Where(c => className.ToLower().Contains(c)).Any() || classWhitelist.Where(c => className.ToLower().Replace(" ", "").Contains(c)).Any(); - detailedWindowStr += $"[{windowSize.GetWidth()}x{windowSize.GetHeight()}, {aspectRatio}]"; + detailedWindowStr += $"[{windowSize}, {aspectRatio}]"; // if there is no matched game, lets try to make assumptions from the process given the following information: // 1. window size & aspect ratio diff --git a/Classes/Services/WindowService.cs b/Classes/Services/WindowService.cs index c538a457..1fc4a37e 100644 --- a/Classes/Services/WindowService.cs +++ b/Classes/Services/WindowService.cs @@ -210,7 +210,7 @@ public static IntPtr GetWindowHandleByProcessId(int processId, bool lazy = false } [StructLayout(LayoutKind.Sequential)] - public struct Rect(int left, int top, int right, int bottom) { + public struct Rect(int left = 0, int top = 0, int right = 0, int bottom = 0) { public int Left = left, Top = top, Right = right, Bottom = bottom; public int GetWidth() { @@ -221,8 +221,18 @@ public int GetHeight() { return Bottom - Top; } - public string GetSizeStr() { - return GetWidth() + "x" + GetHeight(); + public override string ToString() { + return $"{GetWidth()}x{GetHeight()}"; + } + + public static bool operator ==(Rect left, Rect right) => left.Equals(right); + public static bool operator !=(Rect left, Rect right) => !left.Equals(right); + + public override bool Equals(object obj) { + if (obj is Rect rect) { + return GetWidth() == rect.GetWidth() && GetHeight() == rect.GetHeight(); + } + return false; } }