summaryrefslogtreecommitdiff
path: root/wx+/dc.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-06-26 16:00:37 +0000
committerB. Stack <bgstack15@gmail.com>2022-06-26 16:00:37 +0000
commit2a026bc7d76875b88700bebc7c5a801fef881bfd (patch)
treef820b53379f3d14e103e2663e8b0ecd38d1b2105 /wx+/dc.h
parentMerge branch 'b11.21' into 'master' (diff)
parentadd upstream 11.22 (diff)
downloadFreeFileSync-2a026bc7d76875b88700bebc7c5a801fef881bfd.tar.gz
FreeFileSync-2a026bc7d76875b88700bebc7c5a801fef881bfd.tar.bz2
FreeFileSync-2a026bc7d76875b88700bebc7c5a801fef881bfd.zip
Merge branch '11.22' into 'master'11.22
add upstream 11.22 See merge request opensource-tracking/FreeFileSync!45
Diffstat (limited to 'wx+/dc.h')
-rw-r--r--wx+/dc.h34
1 files changed, 28 insertions, 6 deletions
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()
@@ -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); //
}
bgstack15