Make wxWindow::GetContentScaleFactor() useful for non-OSX platforms.
Return the ration of the current DPI to the standard one to allow using this function to scale pixel values for the current screen resolution.
This commit is contained in:
parent
6448fa074a
commit
bc492a9e6e
@ -533,9 +533,8 @@ public:
|
||||
|
||||
// returns the magnification of the content of this window
|
||||
// eg 2.0 for a window on a retina screen
|
||||
virtual double GetContentScaleFactor() const
|
||||
{ return 1.0; }
|
||||
|
||||
virtual double GetContentScaleFactor() 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;
|
||||
|
@ -1126,10 +1126,18 @@ public:
|
||||
Returns the magnification of the backing store of this window, eg 2.0
|
||||
for a window on a retina screen.
|
||||
|
||||
This method can be used to adjust hard coded pixel values to the values
|
||||
appropriate for the current screen resolution. E.g. instead of using
|
||||
32px icons, which would look tiny on the high resolution (also known as
|
||||
HiDPI or retina) displays, you should use
|
||||
@code
|
||||
wxRound(32*GetContentScaleFactor())
|
||||
@endcode instead.
|
||||
|
||||
@since 2.9.5
|
||||
*/
|
||||
virtual double GetContentScaleFactor() const;
|
||||
|
||||
double GetContentScaleFactor() const;
|
||||
|
||||
/**
|
||||
Returns the size of the left/right and top/bottom borders of this window in x
|
||||
and y components of the result respectively.
|
||||
|
@ -791,6 +791,21 @@ wxSize wxWindowBase::DoGetBestSize() const
|
||||
return best;
|
||||
}
|
||||
|
||||
double wxWindowBase::GetContentScaleFactor() const
|
||||
{
|
||||
// Currently we don't support per-monitor DPI, so it's useless to construct
|
||||
// a DC associated with this window, just use the global value.
|
||||
//
|
||||
// We also 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.
|
||||
//
|
||||
// Finally, 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.
|
||||
return wxScreenDC().GetPPI().y / 96.;
|
||||
}
|
||||
|
||||
// helper of GetWindowBorderSize(): as many ports don't implement support for
|
||||
// wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
|
||||
// fallbacks in this case
|
||||
|
Loading…
Reference in New Issue
Block a user