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