From fc9a3aef051957a334e1e83bfa0408abdcf5ec73 Mon Sep 17 00:00:00 2001 From: Xian55 <367101+Xian55@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:25:33 +0100 Subject: [PATCH] Fix: Core: WoWScreenDXGI: an issue when the game window is placed on a non primary monitor. --- Core/WoWScreen/WowScreenDXGI.cs | 35 ++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/Core/WoWScreen/WowScreenDXGI.cs b/Core/WoWScreen/WowScreenDXGI.cs index 7b1fecdf..3cb3265b 100644 --- a/Core/WoWScreen/WowScreenDXGI.cs +++ b/Core/WoWScreen/WowScreenDXGI.cs @@ -40,6 +40,8 @@ public sealed class WowScreenDXGI : IWowScreen, IAddonDataProvider public Rectangle ScreenRect => screenRect; private Rectangle screenRect; + private readonly Vortice.RawRect monitorRect; + public Image ScreenImage { get; init; } private readonly SixLabors.ImageSharp.Configuration ContiguousJpegConfiguration @@ -88,8 +90,6 @@ public WowScreenDXGI(ILogger logger, Bgra32Size = Unsafe.SizeOf(); GetRectangle(out screenRect); - windowedMode = IsWindowedMode(screenRect.Location); - ScreenImage = new(ContiguousJpegConfiguration, screenRect.Width, screenRect.Height); MiniMapRect = new(0, 0, MiniMapSize, MiniMapSize); @@ -112,8 +112,22 @@ public WowScreenDXGI(ILogger logger, if (result == Result.Ok && output.Description.Monitor == hMonitor) { + monitorRect = output.Description.DesktopCoordinates; + if ((monitorRect.Right - monitorRect.Left) != screenRect.Width || + (monitorRect.Bottom - monitorRect.Top) != screenRect.Height) + { + windowedMode = true; + } + else + { + windowedMode = false; + } + + NormalizeScreenRect(); + break; } + srcIdx++; } while (result != Result.Fail); output1 = output.QueryInterface(); @@ -159,7 +173,9 @@ public WowScreenDXGI(ILogger logger, this.logger.LogInformation($"{screenRect} - " + $"Windowed Mode: {windowedMode} - " + - $"Scale: {DPI2PPI(GetDpi()):F2}"); + $"Scale: {DPI2PPI(GetDpi()):F2} - " + + $"Monitor Rect: {monitorRect} - " + + $"Monitor Index: {srcIdx}"); } public void Dispose() @@ -219,6 +235,7 @@ public void Update() if (windowedMode) { GetRectangle(out screenRect); + NormalizeScreenRect(); // TODO: bounds check if (screenRect.X < 0 || @@ -382,4 +399,16 @@ public void GetRectangle(out Rectangle rect) { NativeMethods.GetWindowRect(process.MainWindowHandle, out rect); } + + private void NormalizeScreenRect() + { + screenRect.X -= monitorRect.Left; + screenRect.Y -= monitorRect.Top; + + if (screenRect.X < 0) + screenRect.X = 0; + + if (screenRect.Y < 0) + screenRect.Y = 0; + } } \ No newline at end of file