Use wxDisplay::GetScaleFactor() in wxWindow::GetDPIScaleFactor()

This can be more direct and efficient than computing the ratio of DPIs
in wxWindow.
This commit is contained in:
Vadim Zeitlin
2020-08-07 00:15:26 +02:00
parent 19fd0fcfd7
commit f572797965

View File

@@ -786,25 +786,6 @@ wxSize wxWindowBase::DoGetBestSize() const
return best;
}
namespace
{
static wxSize GetDPIHelper(const wxWindowBase* w)
{
wxSize dpi;
if ( w )
dpi = w->GetDPI();
if ( !dpi.x || !dpi.y )
dpi = wxScreenDC().GetPPI();
if ( !dpi.x || !dpi.y )
dpi = wxDisplay::GetStdPPI();
return dpi;
}
}
double wxWindowBase::GetContentScaleFactor() const
{
// By default, we assume that there is no mapping between logical and
@@ -817,12 +798,7 @@ double wxWindowBase::GetContentScaleFactor() const
double wxWindowBase::GetDPIScaleFactor() const
{
const wxSize dpi = GetDPIHelper(this);
// We 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.
return dpi.y / (double)wxDisplay::GetStdPPIValue();
return wxDisplay(static_cast<const wxWindow*>(this)).GetScaleFactor();
}
// helper of GetWindowBorderSize(): as many ports don't implement support for
@@ -2887,6 +2863,25 @@ wxSize wxWindowBase::GetDPI() const
#ifndef wxHAVE_DPI_INDEPENDENT_PIXELS
namespace
{
static wxSize GetDPIHelper(const wxWindowBase* w)
{
wxSize dpi;
if ( w )
dpi = w->GetDPI();
if ( !dpi.x || !dpi.y )
dpi = wxScreenDC().GetPPI();
if ( !dpi.x || !dpi.y )
dpi = wxDisplay::GetStdPPI();
return dpi;
}
}
/* static */
wxSize
wxWindowBase::FromDIP(const wxSize& sz, const wxWindowBase* w)