Make wxWindow::GetContentScaleFactor() useful for non-OSX platforms.

Return the ration of the current DPI to the standard one to allow using this
function to scale pixel values for the current screen resolution.
This commit is contained in:
Vadim Zeitlin
2015-03-18 15:07:02 +01:00
parent 6448fa074a
commit bc492a9e6e
3 changed files with 27 additions and 5 deletions

View File

@@ -791,6 +791,21 @@ wxSize wxWindowBase::DoGetBestSize() const
return best;
}
double wxWindowBase::GetContentScaleFactor() const
{
// Currently we don't support per-monitor DPI, so it's useless to construct
// a DC associated with this window, just use the global value.
//
// We also use just the vertical component of the DPI because it's the one
// that counts most and, in practice, it's equal to the horizontal one
// anyhow.
//
// Finally, we consider 96 DPI to be the standard value, this is correct
// at least for MSW, but could conceivably need adjustment for the other
// platforms.
return wxScreenDC().GetPPI().y / 96.;
}
// helper of GetWindowBorderSize(): as many ports don't implement support for
// wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
// fallbacks in this case