From bbb6dbea1b6d6a0de7cb74b6d0c9a9f750df43c5 Mon Sep 17 00:00:00 2001 From: Steve Browne Date: Tue, 24 Nov 2015 12:47:31 -0500 Subject: [PATCH] Added wxWindow::ToDIP functionality. --- include/wx/window.h | 15 +++++++++++++++ src/common/wincmn.cpp | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/wx/window.h b/include/wx/window.h index 51f6163d4b..02f5d6e71d 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -979,6 +979,21 @@ public: wxPoint FromDIP(const wxPoint& pt) const { return FromDIP(pt, this); } int FromDIP(int d) const { return FromDIP(d, this); } + static wxSize ToDIP(const wxSize& sz, const wxWindowBase* w); + static wxPoint ToDIP(const wxPoint& pt, const wxWindowBase* w) + { + const wxSize sz = ToDIP(wxSize(pt.x, pt.y), w); + return wxPoint(sz.x, sz.y); + } + static int ToDIP(int d, const wxWindowBase* w) + { + return ToDIP(wxSize(d, 0), w).x; + } + + wxSize ToDIP(const wxSize& sz) const { return ToDIP(sz, this); } + wxPoint ToDIP(const wxPoint& pt) const { return ToDIP(pt, this); } + int ToDIP(int d) const { return ToDIP(d, this); } + // Dialog units are based on the size of the current font. diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index eaba02285e..71e9723041 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2878,6 +2878,18 @@ wxWindowBase::FromDIP(const wxSize& sz, const wxWindowBase* WXUNUSED(w)) sz.y == -1 ? -1 : wxMulDivInt32(sz.y, dpi.y, BASELINE_DPI)); } +/* static */ +wxSize +wxWindowBase::ToDIP(const wxSize& sz, const wxWindowBase* WXUNUSED(w)) +{ + const wxSize dpi = wxScreenDC().GetPPI(); + + // Take care to not scale -1 because it has a special meaning of + // "unspecified" which should be preserved. + return wxSize(sz.x == -1 ? -1 : wxMulDivInt32(sz.x, BASELINE_DPI, dpi.x), + sz.y == -1 ? -1 : wxMulDivInt32(sz.y, BASELINE_DPI, dpi.y)); +} + #endif // !wxHAVE_DPI_INDEPENDENT_PIXELS // Windows' computes dialog units using average character width over upper-