Add wxWindow::FromDIP() for simpler high DPI support.

This method allows to scale a pixel value by a DPI-dependent factor to the
value used by the underlying toolkit only if necessary, i.e. when not using
GTK+ 3 or OS X which already do this internally.
This commit is contained in:
Vadim Zeitlin
2015-03-20 00:01:57 +01:00
parent bc492a9e6e
commit 00748bbaef
4 changed files with 74 additions and 10 deletions

View File

@@ -27,6 +27,7 @@
#include "wx/string.h"
#include "wx/log.h"
#include "wx/intl.h"
#include "wx/math.h"
#include "wx/frame.h"
#include "wx/window.h"
#include "wx/control.h"
@@ -2860,9 +2861,20 @@ void wxWindowBase::OnInternalIdle()
}
// ----------------------------------------------------------------------------
// dialog units translations
// DPI-independent pixels and dialog units translations
// ----------------------------------------------------------------------------
#ifndef wxHAVE_DPI_INDEPENDENT_PIXELS
wxSize wxWindowBase::FromDIP(const wxSize& sz) const
{
const double scale = GetContentScaleFactor();
return wxSize(wxRound(scale*sz.x), wxRound(scale*sz.y));
}
#endif // !wxHAVE_DPI_INDEPENDENT_PIXELS
// Windows' computes dialog units using average character width over upper-
// and lower-case ASCII alphabet and not using the average character width
// metadata stored in the font; see