Merge branch 'display-ppi-from-scaling-factor'

Determine display DPI from scaling factor instead of trying to compute
it from the physical display dimensions.

See https://github.com/wxWidgets/wxWidgets/pull/2015

Closes #18855.
This commit is contained in:
Vadim Zeitlin
2020-08-24 00:14:27 +02:00
20 changed files with 232 additions and 215 deletions

View File

@@ -87,6 +87,24 @@ public:
// get the resolution of this monitor in pixels per inch
wxSize GetPPI() const;
// get the default resolution for displays on this platform
static int GetStdPPIValue()
{
#ifdef __WXOSX__
return 72;
#else
return 96;
#endif
}
static wxSize GetStdPPI()
{
return wxSize(GetStdPPIValue(), GetStdPPIValue());
}
// get the scaling used by this display
double GetScaleFactor() const;
// name may be empty
wxString GetName() const;

View File

@@ -97,6 +97,7 @@ public:
virtual int GetCharHeight() const wxOVERRIDE;
virtual int GetCharWidth() const wxOVERRIDE;
virtual double GetContentScaleFactor() const wxOVERRIDE;
virtual double GetDPIScaleFactor() const wxOVERRIDE;
virtual void SetScrollbar( int orient, int pos, int thumbVisible,
int range, bool refresh = true ) wxOVERRIDE;

View File

@@ -100,6 +100,8 @@ public:
virtual bool Reparent(wxWindowBase *newParent) wxOVERRIDE;
virtual wxSize GetDPI() const wxOVERRIDE;
virtual double GetDPIScaleFactor() const wxOVERRIDE;
virtual void WarpPointer(int x, int y) wxOVERRIDE;
virtual bool EnableTouchEvents(int eventsMask) wxOVERRIDE;

View File

@@ -121,6 +121,7 @@ public:
#endif // wxUSE_HOTKEY
virtual wxSize GetDPI() const wxOVERRIDE;
virtual double GetDPIScaleFactor() const wxOVERRIDE;
#if wxUSE_DRAG_AND_DROP
virtual void SetDropTarget( wxDropTarget *dropTarget ) wxOVERRIDE;

View File

@@ -115,14 +115,9 @@ public:
// return the scale factor used to convert logical pixels to physical ones
virtual double GetScaleFactor() const { return 1.0; }
// return the resolution of the display, uses GetSize(), GetScaleFactor()
// and GetSizeMM() by default but can be also overridden directly
virtual wxSize GetPPI() const;
// return the physical size of the display or (0, 0) if unknown: this is
// only used by GetPPI() implementation in the base class, so if GetPPI()
// is overridden, this one doesn't have to be implemented
virtual wxSize GetSizeMM() const { return wxSize(0, 0); }
// return the resolution of the display, by default uses GetScaleFactor(),
// but can be also overridden directly, as is done in wxMSW
virtual wxSize GetPPI() const { return wxDisplay::GetStdPPI()*GetScaleFactor(); }
// return the name (may be empty)
virtual wxString GetName() const { return wxString(); }
@@ -149,11 +144,6 @@ protected:
// create the object providing access to the display with the given index
wxDisplayImpl(unsigned n) : m_index(n) { }
// Compute PPI from the sizes in pixels and mm.
//
// Return (0, 0) if physical size (in mm) is not known, i.e. 0.
static wxSize ComputePPI(int pxX, int pxY, int mmX, int mmY);
// the index of this display (0 is always the primary one)
const unsigned m_index;

View File

@@ -537,7 +537,7 @@ public:
// 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;
virtual double GetDPIScaleFactor() const;
// return the size of the left/right and top/bottom borders in x and y
// components of the result respectively