From 3a587cee195a0e745c10786a86746c0a4984df17 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 10 Jul 2021 22:57:18 +0100 Subject: [PATCH] Use DPI-independent positions and sizes in render sample Don't hardcode physical pixel values, use GetCharWidth() or FromDIP() to make the sample appear correctly in high DPI too. --- samples/render/render.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/samples/render/render.cpp b/samples/render/render.cpp index a8cd136125..f6589271f6 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -219,9 +219,9 @@ private: wxRendererNative& renderer = m_useGeneric ? wxRendererNative::GetGeneric() : wxRendererNative::Get(); - int x1 = 10, // text offset - x2 = 300, // drawing offset - y = 10; + int x1 = FromDIP(10), // text offset + x2 = FromDIP(300), // drawing offset + y = FromDIP(10); const int lineHeight = dc.GetCharHeight(); dc.DrawText("Demonstration of various wxRenderer functions:", x1, y); @@ -247,7 +247,7 @@ private: y += lineHeight*3; const wxCoord heightHdr = renderer.GetHeaderButtonHeight(this); - const wxCoord width = 120; + const wxCoord width = 15*GetCharWidth(); const wxHeaderSortIconType hdrSortIcon = m_useIcon ? wxHDR_SORT_ICON_UP @@ -307,7 +307,7 @@ private: #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP dc.DrawText("DrawTitleBarBitmap()", x1, y); - wxRect rBtn(x2, y, 21, 21); + wxRect rBtn(x2, y, FromDIP(21), FromDIP(21)); renderer.DrawTitleBarBitmap(this, dc, rBtn, wxTITLEBAR_BUTTON_HELP, m_flags); rBtn.x += 2*rBtn.width; @@ -327,21 +327,21 @@ private: #endif // wxHAS_DRAW_TITLE_BAR_BITMAP // The meanings of those are reversed for the vertical gauge below. - const wxCoord heightGauge = 24; - const wxCoord widthGauge = 180; + const wxCoord heightGauge = FromDIP(24); + const wxCoord widthGauge = 30*GetCharWidth(); dc.DrawText("DrawGauge()", x1, y); renderer.DrawGauge(this, dc, wxRect(x2, y, widthGauge, heightGauge), 25, 100, m_flags); renderer.DrawGauge(this, dc, - wxRect(x2 + widthGauge + 30, y + heightGauge - widthGauge, + wxRect(x2 + widthGauge + FromDIP(30), y + heightGauge - widthGauge, heightGauge, widthGauge), 25, 100, m_flags | wxCONTROL_SPECIAL); y += lineHeight + heightGauge; - const wxCoord heightListItem = 48; - const wxCoord widthListItem = 260; + const wxCoord heightListItem = FromDIP(48); + const wxCoord widthListItem = 30*GetCharWidth(); dc.DrawText("DrawItemSelectionRect()", x1, y); renderer.DrawItemSelectionRect(this, dc, @@ -356,8 +356,6 @@ private: dc.DrawText("DrawChoice()", x1, y); renderer.DrawChoice(this, dc, wxRect(x2, y, width, 1.5*GetCharHeight()), m_flags); - y += 50; - } int m_flags;