diff --git a/include/wx/window.h b/include/wx/window.h index e574fe9df2..a6977b368b 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -533,6 +533,10 @@ public: // e.g. 2.0 for a window on a retina screen virtual double GetContentScaleFactor() const; + // Return the ratio of the DPI used by this window to the standard DPI, + // e.g. 1 for standard DPI screens and 2 for "200% scaling". + double GetDPIScaleFactor() const; + // return the size of the left/right and top/bottom borders in x and y // components of the result respectively virtual wxSize GetWindowBorderSize() const; @@ -957,7 +961,7 @@ public: // DPI-independent pixels, or DIPs, are pixel values for the standard // 96 DPI display, they are scaled to take the current resolution into // account (i.e. multiplied by the same factor as returned by - // GetContentScaleFactor()) if necessary for the current platform. + // GetDPIScaleFactor()) if necessary for the current platform. // // To support monitor-specific resolutions, prefer using the non-static // member functions or use a valid (non-null) window pointer. diff --git a/interface/wx/window.h b/interface/wx/window.h index 5898beef6a..db1e9c55ff 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -1034,7 +1034,7 @@ public: A DPI-independent pixel is just a pixel at the standard 96 DPI resolution. To keep the same physical size at higher resolution, the - physical pixel value must be scaled by GetContentScaleFactor() but this + physical pixel value must be scaled by GetDPIScaleFactor() but this scaling may be already done by the underlying toolkit (GTK+, Cocoa, ...) automatically. This method performs the conversion only if it is not already done by the lower level toolkit and so by using it with @@ -1110,7 +1110,7 @@ public: A DPI-independent pixel is just a pixel at the standard 96 DPI resolution. To keep the same physical size at higher resolution, the - physical pixel value must be scaled by GetContentScaleFactor() but this + physical pixel value must be scaled by GetDPIScaleFactor() but this scaling may be already done by the underlying toolkit (GTK+, Cocoa, ...) automatically. This method performs the conversion only if it is not already done by the lower level toolkit, For example, you may @@ -1379,8 +1379,20 @@ public: Returns the magnification of the backing store of this window, eg 2.0 for a window on a retina screen. - This factor should be used to determine the size of bitmaps and similar - "content-containing" windows appropriate for the current resolution. + @since 2.9.5 + */ + double GetContentScaleFactor() const; + + /** + Returns the ratio of the DPI used by this window to the standard DPI. + + The returned value is 1 for standard DPI screens or 2 for "200% + scaling". + + This factor should be used to increase the size of icons and similar + windows whose best size is not based on text metrics when using DPI + scaling. + E.g. the program may load a 32px bitmap if the content scale factor is 1.0 or 64px version of the same bitmap if it is 2.0 or bigger. @@ -1388,9 +1400,9 @@ public: are already scaled by this factor by the underlying toolkit under some platforms. Use FromDIP() for anything window-related instead. - @since 2.9.5 - */ - double GetContentScaleFactor() const; + @since 3.1.4 + */ + double GetDPIScaleFactor() const; /** Returns the size of the left/right and top/bottom borders of this window in x diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 6bdc060c84..05c01e5616 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -802,7 +802,7 @@ void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc, break; } - wxAuiScaleBitmap(bmp, window->GetContentScaleFactor()); + wxAuiScaleBitmap(bmp, window->GetDPIScaleFactor()); wxRect rect = _rect; diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index b378d72b05..432a207610 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -578,7 +578,7 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc, bmp = m_activeCloseBmp; } - wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); + wxAuiScaleBitmap(bmp, wnd->GetDPIScaleFactor()); int offsetY = tab_y-1; if (m_flags & wxAUI_NB_BOTTOM) @@ -755,7 +755,7 @@ void wxAuiGenericTabArt::DrawButton(wxDC& dc, if (!bmp.IsOk()) return; - wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); + wxAuiScaleBitmap(bmp, wnd->GetDPIScaleFactor()); rect = in_rect; @@ -1125,7 +1125,7 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc, else bmp = m_disabledCloseBmp; - wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); + wxAuiScaleBitmap(bmp, wnd->GetDPIScaleFactor()); wxRect rect(tab_x + tab_width - bmp.GetScaledWidth() - 1, tab_y + (tab_height/2) - (bmp.GetScaledHeight()/2) + 1, @@ -1273,7 +1273,7 @@ void wxAuiSimpleTabArt::DrawButton(wxDC& dc, if (!bmp.IsOk()) return; - wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); + wxAuiScaleBitmap(bmp, wnd->GetDPIScaleFactor()); rect = in_rect; diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index a0b1768ea1..a84567d467 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -111,7 +111,7 @@ float wxSizerFlags::DoGetDefaultBorderInPx() if ( s_defaultBorderInPx.HasChanged(win) ) { s_defaultBorderInPx.SetAtNewDPI( - (float)(5 * (win ? win->GetContentScaleFactor() : 1))); + (float)(5 * (win ? win->GetDPIScaleFactor() : 1.0))); } return s_defaultBorderInPx.Get(); } diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 0319a96e45..630aa05916 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -101,9 +101,12 @@ bool IsInCaptureStack(wxWindowBase* win); } // wxMouseCapture -// We consider 96 DPI to be the standard value, this is correct at least for -// MSW, but could conceivably need adjustment for the other platforms. +// Most platforms use 96 DPI by default, but Mac traditionally uses 72. +#ifdef __WXOSX__ +static const int BASELINE_DPI = 72; +#else static const int BASELINE_DPI = 96; +#endif // ---------------------------------------------------------------------------- // static data @@ -808,6 +811,11 @@ static wxSize GetDPIHelper(const wxWindowBase* w) } double wxWindowBase::GetContentScaleFactor() const +{ + return GetDPIScaleFactor(); +} + +double wxWindowBase::GetDPIScaleFactor() const { const wxSize dpi = GetDPIHelper(this); diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp index 8fdbe56cf6..6662d1cd77 100644 --- a/src/html/htmlwin.cpp +++ b/src/html/htmlwin.cpp @@ -493,7 +493,7 @@ bool wxHtmlWindow::DoSetPage(const wxString& source) double pixelScale = 1.0; #ifndef wxHAVE_DPI_INDEPENDENT_PIXELS - pixelScale = GetContentScaleFactor(); + pixelScale = GetDPIScaleFactor(); #endif m_Parser->SetDC(&dc, pixelScale, 1.0); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index cfd7f3d926..03921a9ce9 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -4610,7 +4610,7 @@ void wxPropertyGrid::OnResize( wxSizeEvent& event ) if ( !HasExtraStyle(wxPG_EX_NATIVE_DOUBLE_BUFFERING) ) { - double scaleFactor = GetContentScaleFactor(); + double scaleFactor = GetDPIScaleFactor(); int dblh = (m_lineHeight*2); if ( !m_doubleBuffer ) {