diff options
author | B. Stack <bgstack15@gmail.com> | 2022-06-26 11:59:57 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2022-06-26 11:59:57 -0400 |
commit | 03efe856012a55165542a3ac5c9055c25723f5e8 (patch) | |
tree | f820b53379f3d14e103e2663e8b0ecd38d1b2105 /wx+/dc.h | |
parent | Merge branch 'b11.21' into 'master' (diff) | |
download | FreeFileSync-03efe856012a55165542a3ac5c9055c25723f5e8.tar.gz FreeFileSync-03efe856012a55165542a3ac5c9055c25723f5e8.tar.bz2 FreeFileSync-03efe856012a55165542a3ac5c9055c25723f5e8.zip |
add upstream 11.22
Diffstat (limited to 'wx+/dc.h')
-rw-r--r-- | wx+/dc.h | 34 |
1 files changed, 28 insertions, 6 deletions
@@ -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() @@ -104,6 +104,13 @@ int getDPI() inline +double getDisplayScaleFactor() +{ + return static_cast<double>(getDPI()) / defaultDpi; +} + + +inline int fastFromDIP(int d) //like wxWindow::FromDIP (but tied to primary monitor and buffered) { return numeric::intDivRound(d * getDPI() - 10 /*round values like 1.5 down => 1 pixel on 150% scale*/, defaultDpi); @@ -123,11 +130,23 @@ wxBitmapBundle toBitmapBundle(const wxImage& img /*expected to be DPI-scaled!*/) { //return wxBitmap(img, -1 /*depth*/, static_cast<double>(getDPI()) / defaultDpi); implementation just ignores scale parameter! WTF! wxBitmap bmpScaled(img); - bmpScaled.SetScaleFactor(static_cast<double>(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<wxDcSurgeon*>(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); // } |