Factor out wxDisplayImpl::ComputePPI() helper

No real changes, this is a pure refactoring.
This commit is contained in:
Vadim Zeitlin 2018-10-29 18:31:42 +01:00
parent 68a7cbd08d
commit 9f8684c789
2 changed files with 17 additions and 5 deletions

View File

@ -118,6 +118,11 @@ protected:
// create the object providing access to the display with the given index
wxDisplayImpl(unsigned n) : m_index(n) { }
// Compute PPI from the sizes in pixels and mm.
//
// Return (0, 0) if physical size (in mm) is not known, i.e. 0.
static wxSize ComputePPI(int pxX, int pxY, int mmX, int mmY);
// the index of this display (0 is always the primary one)
const unsigned m_index;

View File

@ -193,22 +193,29 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
// wxDisplayImpl implementation
// ============================================================================
wxSize wxDisplayImpl::GetPPI() const
/* static */
wxSize wxDisplayImpl::ComputePPI(int pxX, int pxY, int mmX, int mmY)
{
const wxSize mm = GetSizeMM();
if ( !mm.x || !mm.y )
if ( !mmX || !mmY )
{
// Physical size is unknown, return a special value indicating that we
// can't compute the resolution -- what else can we do?
return wxSize(0, 0);
}
return wxSize(wxRound((pxX * inches2mm) / mmX),
wxRound((pxY * inches2mm) / mmY));
}
wxSize wxDisplayImpl::GetPPI() const
{
const wxSize mm = GetSizeMM();
// 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));
return ComputePPI(pixels.x, pixels.y, mm.x, mm.y);
}
// ============================================================================