Add wxDisplayImpl::GetScaleFactor() and implement it for wxGTK

We need to account for the scale factor under GTK+ (and, presumably,
under macOS) to compute the correct PPI value as it must use the number
of physical and not logical pixels.
This commit is contained in:
Vadim Zeitlin
2018-10-29 17:41:37 +01:00
parent 43d2b1db0e
commit f09b9dbfa2
3 changed files with 28 additions and 4 deletions

View File

@@ -195,9 +195,7 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
wxSize wxDisplayImpl::GetPPI() const
{
const wxSize pixels = GetGeometry().GetSize();
const wxSize mm = GetSizeMM();
if ( !mm.x || !mm.y )
{
// Physical size is unknown, return a special value indicating that we
@@ -205,6 +203,10 @@ wxSize wxDisplayImpl::GetPPI() const
return wxSize(0, 0);
}
// We need physical pixels here, not logical ones returned by
// GetGeometry(), to compute the real DPI.
const wxSize pixels = GetGeometry().GetSize()*GetScaleFactor();
return wxSize(wxRound((pixels.x * inches2mm) / mm.x),
wxRound((pixels.y * inches2mm) / mm.y));
}