From e8cf1f989bacaceec96ce664e3eb9665e80698c4 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 21 Apr 2022 21:37:53 +0200 Subject: [PATCH] Add ToDIP to wxDC and wxGraphicsContext --- include/wx/dc.h | 16 ++++++++++++++++ include/wx/dcsvg.h | 5 +++++ include/wx/generic/dcpsg.h | 5 +++++ include/wx/graphics.h | 11 +++++++++++ include/wx/msw/dcprint.h | 5 +++++ src/common/dcbase.cpp | 11 +++++++++++ src/common/graphcmn.cpp | 12 ++++++++++++ src/msw/enhmeta.cpp | 5 +++++ 8 files changed, 70 insertions(+) diff --git a/include/wx/dc.h b/include/wx/dc.h index c1f978f2c4..6ca1742f1d 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -541,6 +541,8 @@ public: virtual wxSize FromDIP(const wxSize& sz) const; + virtual wxSize ToDIP(const wxSize& sz) const; + #ifdef __WXMSW__ // Native Windows functions using the underlying HDC don't honour GDI+ // transformations which may be applied to it. Using this function we can @@ -839,6 +841,20 @@ public: int FromDIP(int d) const { return FromDIP(wxSize(d, 0)).x; } + wxSize ToDIP(const wxSize & sz) const + { + return m_pimpl->ToDIP(sz); + } + wxPoint ToDIP(const wxPoint & pt) const + { + const wxSize sz = ToDIP(wxSize(pt.x, pt.y)); + return wxPoint(sz.x, sz.y); + } + int ToDIP(int d) const + { + return ToDIP(wxSize(d, 0)).x; + } + // Right-To-Left (RTL) modes void SetLayoutDirection(wxLayoutDirection dir) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 91e04c4449..778e247446 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -253,6 +253,11 @@ private: return sz; } + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE + { + return sz; + } + void Init(const wxString& filename, int width, int height, double dpi, const wxString& title); diff --git a/include/wx/generic/dcpsg.h b/include/wx/generic/dcpsg.h index 45628064ba..17b58c6285 100644 --- a/include/wx/generic/dcpsg.h +++ b/include/wx/generic/dcpsg.h @@ -81,6 +81,11 @@ public: return sz; } + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE + { + return sz; + } + virtual void ComputeScaleAndOrigin() wxOVERRIDE; void SetBackgroundMode(int WXUNUSED(mode)) wxOVERRIDE { } diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 935f06ac53..e6b3b02196 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -750,6 +750,17 @@ public: return FromDIP(wxSize(d, 0)).x; } + wxSize ToDIP(const wxSize& sz) const; + wxPoint ToDIP(const wxPoint& pt) const + { + const wxSize sz = ToDIP(wxSize(pt.x, pt.y)); + return wxPoint(sz.x, sz.y); + } + int ToDIP(int d) const + { + return ToDIP(wxSize(d, 0)).x; + } + #if 0 // sets the current alpha on this context virtual void SetAlpha( wxDouble alpha ); diff --git a/include/wx/msw/dcprint.h b/include/wx/msw/dcprint.h index 0b9a9af7fa..fac813719d 100644 --- a/include/wx/msw/dcprint.h +++ b/include/wx/msw/dcprint.h @@ -41,6 +41,11 @@ public: return sz; } + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE + { + return sz; + } + void SetFont(const wxFont& font) wxOVERRIDE; protected: diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index f718a1163a..be5c069e63 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -617,6 +617,17 @@ wxSize wxDCImpl::FromDIP(const wxSize& sz) const #endif // wxHAS_DPI_INDEPENDENT_PIXELS } +wxSize wxDCImpl::ToDIP(const wxSize& sz) const +{ +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + return sz; +#else + const wxSize dpi = GetPPI(); + const wxSize baseline = wxDisplay::GetStdPPI(); + return wxRescaleCoord(sz).From(dpi).To(baseline); +#endif // wxHAS_DPI_INDEPENDENT_PIXELS +} + bool wxDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const { wxTextMeasure tm(GetOwner(), &m_font); diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 1143fe4a7b..f03d1f7dec 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -647,6 +647,18 @@ wxSize wxGraphicsContext::FromDIP(const wxSize& sz) const #endif // wxHAS_DPI_INDEPENDENT_PIXELS } +wxSize wxGraphicsContext::ToDIP(const wxSize& sz) const +{ +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + return sz; +#else + wxRealPoint dpi; + GetDPI(&dpi.x, &dpi.y); + const wxSize baseline = wxDisplay::GetStdPPI(); + return wxRescaleCoord(sz).From(wxSize((int)dpi.x, (int)dpi.y)).To(baseline); +#endif // wxHAS_DPI_INDEPENDENT_PIXELS +} + // sets the pen void wxGraphicsContext::SetPen( const wxGraphicsPen& pen ) { diff --git a/src/msw/enhmeta.cpp b/src/msw/enhmeta.cpp index 62e9105e35..c1f2e2f7ef 100644 --- a/src/msw/enhmeta.cpp +++ b/src/msw/enhmeta.cpp @@ -229,6 +229,11 @@ public: return sz; } + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE + { + return sz; + } + void SetFont(const wxFont& font) wxOVERRIDE { wxFont scaledFont = font;