From 03efe856012a55165542a3ac5c9055c25723f5e8 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Sun, 26 Jun 2022 11:59:57 -0400 Subject: add upstream 11.22 --- wx+/dc.h | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'wx+/dc.h') diff --git a/wx+/dc.h b/wx+/dc.h index 3728aeb4..c93715c2 100644 --- a/wx+/dc.h +++ b/wx+/dc.h @@ -87,7 +87,7 @@ void drawInsetRectangle(wxDC& dc, const wxRect& rect, int borderWidth, const wxC /* Standard DPI: Windows/Ubuntu: 96 x 96 macOS: wxWidgets uses DIP (note: wxScreenDC().GetPPI() returns 72 x 72 which is a lie; looks like 96 x 96) */ -constexpr int defaultDpi = 96; +constexpr int defaultDpi = 96; //on Windows same as wxDisplay::GetStdPPIValue() (however returns 72 on macOS!) inline int getDPI() @@ -103,6 +103,13 @@ int getDPI() } +inline +double getDisplayScaleFactor() +{ + return static_cast(getDPI()) / defaultDpi; +} + + inline int fastFromDIP(int d) //like wxWindow::FromDIP (but tied to primary monitor and buffered) { @@ -123,11 +130,23 @@ wxBitmapBundle toBitmapBundle(const wxImage& img /*expected to be DPI-scaled!*/) { //return wxBitmap(img, -1 /*depth*/, static_cast(getDPI()) / defaultDpi); implementation just ignores scale parameter! WTF! wxBitmap bmpScaled(img); - bmpScaled.SetScaleFactor(static_cast(getDPI()) / defaultDpi); + bmpScaled.SetScaleFactor(getDisplayScaleFactor()); return bmpScaled; } +//all this shit just because wxDC::SetScaleFactor() is missing: +inline +void setScaleFactor(wxDC& dc, double scale) +{ + struct wxDcSurgeon : public wxDCImpl + { + void setScaleFactor(double scale) { m_contentScaleFactor = scale; } + }; + static_cast(dc.GetImpl())->setScaleFactor(scale); +} + + //---------------------- implementation ------------------------ class RecursiveDcClipper { @@ -195,10 +214,13 @@ public: const wxSize clientSize = wnd.GetClientSize(); if (clientSize.GetWidth() > 0 && clientSize.GetHeight() > 0) //wxBitmap asserts this!! width may be 0; test case "Grid::CornerWin": compare both sides, then change config { - if (!buffer_ || clientSize != wxSize(buffer->GetWidth(), buffer->GetHeight())) - buffer = wxBitmap(clientSize.GetWidth(), clientSize.GetHeight()); + if (!buffer_ || buffer->GetSize() != clientSize) + buffer.emplace(clientSize); + + if (buffer->GetScaleFactor() != wnd.GetDPIScaleFactor()) + buffer->SetScaleFactor(wnd.GetDPIScaleFactor()); - SelectObject(*buffer); + SelectObject(*buffer); //copies scale factor from wxBitmap if (paintDc_.IsOk() && paintDc_.GetLayoutDirection() == wxLayout_RightToLeft) SetLayoutDirection(wxLayout_RightToLeft); @@ -213,7 +235,7 @@ public: { if (GetLayoutDirection() == wxLayout_RightToLeft) { - paintDc_.SetLayoutDirection(wxLayout_LeftToRight); //workaround bug in wxDC::Blit() + paintDc_.SetLayoutDirection(wxLayout_LeftToRight); //work around bug in wxDC::Blit() SetLayoutDirection(wxLayout_LeftToRight); // } -- cgit