From d51f274e1c2ec16b84e10c529b1701faa6728126 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 31 Mar 2022 07:46:28 -0700 Subject: [PATCH] Avoid drawing generic wxCaret outside of its bounds Outline caret rectangle needs to be inset so that its outer edge is the same as the solid caret when window is scaled. --- src/generic/caret.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/generic/caret.cpp b/src/generic/caret.cpp index 093ce01094..f9add3875d 100644 --- a/src/generic/caret.cpp +++ b/src/generic/caret.cpp @@ -29,6 +29,7 @@ #endif //WX_PRECOMP #include "wx/caret.h" +#include "wx/graphics.h" // ---------------------------------------------------------------------------- // global variables for this module @@ -290,8 +291,21 @@ void wxCaret::DoDraw(wxDC *dc, wxWindow* win) } else { + pen.SetJoin(wxJOIN_MITER); dc->SetPen(pen); dc->SetBrush(*wxTRANSPARENT_BRUSH); +#if wxUSE_GRAPHICS_CONTEXT + wxGraphicsContext* gc = dc->GetGraphicsContext(); + if (gc) + { + // Draw outline rect so that its outside edges correspond with + // those of the solid rect. This is necessary to avoid drawing + // outside the solid rect bounds when window content is scaled. + gc->EnableOffset(false); + gc->DrawRectangle(m_x + 0.5, m_y + 0.5, m_width - 1, m_height - 1); + return; + } +#endif } // VZ: unfortunately, the rectangle comes out a pixel smaller when this is