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.
This commit is contained in:
Paul Cornett
2022-03-31 07:46:28 -07:00
parent 5536f0196f
commit d51f274e1c

View File

@@ -29,6 +29,7 @@
#endif //WX_PRECOMP #endif //WX_PRECOMP
#include "wx/caret.h" #include "wx/caret.h"
#include "wx/graphics.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// global variables for this module // global variables for this module
@@ -290,8 +291,21 @@ void wxCaret::DoDraw(wxDC *dc, wxWindow* win)
} }
else else
{ {
pen.SetJoin(wxJOIN_MITER);
dc->SetPen(pen); dc->SetPen(pen);
dc->SetBrush(*wxTRANSPARENT_BRUSH); 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 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is