Add wxDisplay::GetScaleFactor()

This is conceptually the same as the ratio of the current DPI to the
standard one, but can be implemented more directly for wxGTK3 and wxOSX
(although the latter doesn't implement it yet).
This commit is contained in:
Vadim Zeitlin
2020-08-07 00:10:22 +02:00
parent e902050002
commit 19fd0fcfd7
3 changed files with 35 additions and 0 deletions

View File

@@ -102,6 +102,9 @@ public:
return wxSize(GetStdPPIValue(), GetStdPPIValue());
}
// get the scaling used by this display
double GetScaleFactor() const;
// name may be empty
wxString GetName() const;

View File

@@ -143,6 +143,19 @@ public:
*/
wxSize GetPPI() const;
/**
Returns scaling factor used by this display.
The scaling factor is the ratio between GetPPI() and GetStdPPI()
(it is implicitly assumed that this ratio is the same for both
horizontal and vertical components).
@see wxWindow::GetContentScaleFactor(), wxWindow::GetDPIScaleFactor()
@since 3.1.5
*/
double GetScaleFactor() const;
/**
Returns default display resolution for the current platform in pixels
per inch.

View File

@@ -149,6 +149,25 @@ wxSize wxDisplay::GetPPI() const
return m_impl->GetPPI();
}
double wxDisplay::GetScaleFactor() const
{
wxCHECK_MSG( IsOk(), 0, wxT("invalid wxDisplay object") );
#ifdef wxHAVE_DPI_INDEPENDENT_PIXELS
// Use wxDisplayImpl::GetScaleFactor() directly, it should be implemented
// correctly for the platforms doing pixel scaling and using it simpler and
// more efficient than using GetPPI().
return m_impl->GetScaleFactor();
#else
// Under the other platforms, we just compute the DPI ratio ourselves.
//
// 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 m_impl->GetPPI().y / (double)GetStdPPIValue();
#endif
}
int wxDisplay::GetDepth() const
{
wxCHECK_MSG( IsOk(), 0, wxT("invalid wxDisplay object") );