1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Windows: Add helper to find client rect in screen coordinates

This commit is contained in:
reuk 2024-08-13 12:09:01 +01:00
parent d344c2bf71
commit 4a76872f54
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -1680,13 +1680,7 @@ public:
return snapped; return snapped;
} }
RECT rect{}; const auto logicalClient = convertPhysicalScreenRectangleToLogical (getClientRectInScreen(), hwnd);
GetClientRect (hwnd, &rect);
auto points = readUnaligned<std::array<POINT, 2>> (&rect);
MapWindowPoints (hwnd, nullptr, points.data(), (UINT) points.size());
const auto mappedRect = readUnaligned<RECT> (points.data());
const auto logicalClient = convertPhysicalScreenRectangleToLogical (D2DUtilities::toRectangle (mappedRect), hwnd);
return logicalClient; return logicalClient;
} }
@ -1798,6 +1792,19 @@ public:
return wp.showCmd == SW_SHOWMAXIMIZED; return wp.showCmd == SW_SHOWMAXIMIZED;
} }
Rectangle<int> getClientRectInScreen() const
{
ScopedThreadDPIAwarenessSetter setter { hwnd };
RECT rect{};
GetClientRect (hwnd, &rect);
auto points = readUnaligned<std::array<POINT, 2>> (&rect);
MapWindowPoints (hwnd, nullptr, points.data(), (UINT) points.size());
const auto result = readUnaligned<RECT> (&points);
return D2DUtilities::toRectangle (result);
}
bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
{ {
auto r = convertPhysicalScreenRectangleToLogical (D2DUtilities::toRectangle (getWindowScreenRect (hwnd)), hwnd); auto r = convertPhysicalScreenRectangleToLogical (D2DUtilities::toRectangle (getWindowScreenRect (hwnd)), hwnd);
@ -1808,17 +1815,7 @@ public:
const auto screenPos = convertLogicalScreenPointToPhysical (localPos + getScreenPosition(), hwnd); const auto screenPos = convertLogicalScreenPointToPhysical (localPos + getScreenPosition(), hwnd);
if (trueIfInAChildWindow) if (trueIfInAChildWindow)
{ return getClientRectInScreen().contains (screenPos);
// Quick check to see whether the point is inside the client bounds
RECT rect;
GetClientRect (hwnd, &rect);
POINT points[2];
memcpy (points, &rect, sizeof (points));
MapWindowPoints (hwnd, nullptr, points, (UINT) std::size (points));
memcpy (&rect, points, sizeof (points));
return PtInRect (&rect, D2DUtilities::toPOINT (screenPos));
}
auto w = WindowFromPoint (D2DUtilities::toPOINT (screenPos)); auto w = WindowFromPoint (D2DUtilities::toPOINT (screenPos));