Add GetDPIScaleFactor to wxDC and wxGraphicsContext

It can be used to scale coordinates and sizes to make them DPI aware.

In the common headers, use wxDisplay::GetStdPPIValue() as default DPI value,
so the correct values are used on Windows (96) and macOS (72).

In wxMemoryDC use m_contentScaleFactor as the DPIScaleFactor, see e4c2298e5e
(Use window scale factor for all MSW wxDCs associated with windows, 2022-04-04).
This commit is contained in:
Maarten Bent
2022-04-16 00:31:10 +02:00
parent d72a3f7cec
commit ee2b02614e
9 changed files with 39 additions and 6 deletions

View File

@@ -34,6 +34,7 @@
#endif
#include "wx/private/graphics.h"
#include "wx/display.h"
//-----------------------------------------------------------------------------
@@ -612,6 +613,13 @@ void wxGraphicsContext::SetContentScaleFactor(double contentScaleFactor)
m_contentScaleFactor = contentScaleFactor;
}
double wxGraphicsContext::GetDPIScaleFactor() const
{
wxDouble x, y;
GetDPI(&x, &y);
return x / (double)wxDisplay::GetStdPPIValue();
}
#if 0
void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) )
{
@@ -635,8 +643,8 @@ void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY) const
{
// Use some standard DPI value, it doesn't make much sense for the
// contexts not using any pixels anyhow.
*dpiX = 72.0;
*dpiY = 72.0;
*dpiX = wxDisplay::GetStdPPIValue();
*dpiY = wxDisplay::GetStdPPIValue();
}
}
@@ -908,8 +916,8 @@ wxGraphicsContext::CreateLinearGradientBrush(
return GetRenderer()->CreateLinearGradientBrush
(
x1, y1,
x2, y2,
gradientStops,
x2, y2,
gradientStops,
matrix
);
}