diff --git a/include/wx/display.h b/include/wx/display.h index d6f501cd7e..a5e8271e9b 100644 --- a/include/wx/display.h +++ b/include/wx/display.h @@ -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; diff --git a/interface/wx/display.h b/interface/wx/display.h index b71cbb0d72..e9a51cc4c0 100644 --- a/interface/wx/display.h +++ b/interface/wx/display.h @@ -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. diff --git a/src/common/dpycmn.cpp b/src/common/dpycmn.cpp index 4f0d537ef1..c968f9c960 100644 --- a/src/common/dpycmn.cpp +++ b/src/common/dpycmn.cpp @@ -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") );