Skip to content

Commit

Permalink
Adjust snipping rectangles if they are located on non-primary displays
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Jul 20, 2024
1 parent 49a36a9 commit 2e79a64
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/utility/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,25 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags)
void
SKIV_Image_CaptureRegion (ImRect capture_area)
{
// Fixes snipping rectangles on non-primary (origin != 0,0) displays
auto _AdjustCaptureAreaRelativeToDisplayOrigin = [&](void)
{
HMONITOR hMonCaptured =
MonitorFromPoint ({ static_cast <long> (capture_area.Min.x),
static_cast <long> (capture_area.Min.y) }, MONITOR_DEFAULTTONEAREST);

MONITORINFO minfo = { .cbSize = sizeof (MONITORINFO) };
GetMonitorInfo (hMonCaptured, &minfo);

capture_area.Min.x -= minfo.rcMonitor.left;
capture_area.Max.x -= minfo.rcMonitor.left;

capture_area.Min.y -= minfo.rcMonitor.top;
capture_area.Max.y -= minfo.rcMonitor.top;
};

_AdjustCaptureAreaRelativeToDisplayOrigin ();

const size_t
x = static_cast <size_t> (std::max (0.0f, capture_area.Min.x)),
y = static_cast <size_t> (std::max (0.0f, capture_area.Min.y)),
Expand Down Expand Up @@ -1861,8 +1880,8 @@ SKIV_Image_CaptureRegion (ImRect capture_area)
{
PLOG_VERBOSE << "subrect.Initialize2D ( ): SUCCEEDED";

if (SUCCEEDED (DirectX::CopyRectangle (*captured_img.GetImages (), src_rect,
*subrect.GetImages (), DirectX::TEX_FILTER_DEFAULT, 0, 0)))
if (SUCCEEDED (DirectX::CopyRectangle (*captured_img.GetImages (), src_rect,
*subrect.GetImages (), DirectX::TEX_FILTER_DEFAULT, 0, 0)))
{
PLOG_VERBOSE << "DirectX::CopyRectangle ( ): SUCCEEDED";

Expand Down

0 comments on commit 2e79a64

Please sign in to comment.