Add wxWindow::GetDPIScaleFactor()
This function replaces some uses of GetContentScaleFactor(), where a factor greater than 1 must be used even under the platforms not doing any logical/physical pixel mapping, such as MSW. For now GetContentScaleFactor() is still unchanged, but it will return 1 for such platforms in the future and adding GetDPIScaleFactor() allows to avoid changing the behaviour of the code which relied on its current behaviour.
This commit is contained in:
@@ -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.
|
||||
|
@@ -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
|
||||
@since 3.1.4
|
||||
*/
|
||||
double GetContentScaleFactor() const;
|
||||
double GetDPIScaleFactor() const;
|
||||
|
||||
/**
|
||||
Returns the size of the left/right and top/bottom borders of this window in x
|
||||
|
@@ -802,7 +802,7 @@ void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc,
|
||||
break;
|
||||
}
|
||||
|
||||
wxAuiScaleBitmap(bmp, window->GetContentScaleFactor());
|
||||
wxAuiScaleBitmap(bmp, window->GetDPIScaleFactor());
|
||||
|
||||
wxRect rect = _rect;
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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 )
|
||||
{
|
||||
|
Reference in New Issue
Block a user