Fix drawing rectangle with width 1 pen using wxGCDC and HiDPI
To match raster-based wxDC implementations, the line should be drawn along the inside edge of the solid rectangle, regardless of the scale. See #23485
This commit is contained in:
parent
b4a29beecd
commit
d43b2862c3
1 changed files with 33 additions and 10 deletions
|
|
@ -71,6 +71,27 @@ static wxCompositionMode TranslateRasterOp(wxRasterOperationMode function)
|
|||
return wxCOMPOSITION_INVALID;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class OffsetDisabler
|
||||
{
|
||||
wxGraphicsContext* const m_gc;
|
||||
const bool m_enable;
|
||||
public:
|
||||
explicit OffsetDisabler(wxGraphicsContext* gc)
|
||||
: m_gc(gc)
|
||||
, m_enable(gc->OffsetEnabled())
|
||||
{
|
||||
gc->EnableOffset(false);
|
||||
}
|
||||
~OffsetDisabler()
|
||||
{
|
||||
m_gc->EnableOffset(m_enable);
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDC bridge class
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -980,13 +1001,15 @@ void wxGCDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
|
|||
|
||||
CalcBoundingBox(wxPoint(x, y), wxSize(w, h));
|
||||
|
||||
if (m_pen.IsOk() && m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT && m_pen.GetWidth() > 0)
|
||||
if (m_pen.IsNonTransparent() && m_pen.GetWidth() == 1)
|
||||
{
|
||||
// outline is one pixel larger than what raster-based wxDC implementations draw
|
||||
w -= 1;
|
||||
h -= 1;
|
||||
// Match raster-based wxDC implementations, which draw the line
|
||||
// along the inside edge of the solid rectangle
|
||||
OffsetDisabler offsetDisabler(m_graphicContext);
|
||||
m_graphicContext->DrawRectangle(x + 0.5, y + 0.5, w - 1, h - 1);
|
||||
}
|
||||
m_graphicContext->DrawRectangle(x,y,w,h);
|
||||
else
|
||||
m_graphicContext->DrawRectangle(x, y, w, h);
|
||||
}
|
||||
|
||||
void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
|
||||
|
|
@ -1007,13 +1030,13 @@ void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
|
|||
|
||||
CalcBoundingBox(wxPoint(x, y), wxSize(w, h));
|
||||
|
||||
if (m_pen.IsOk() && m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT && m_pen.GetWidth() > 0)
|
||||
if (m_pen.IsNonTransparent() && m_pen.GetWidth() == 1)
|
||||
{
|
||||
// outline is one pixel larger than what raster-based wxDC implementations draw
|
||||
w -= 1;
|
||||
h -= 1;
|
||||
OffsetDisabler offsetDisabler(m_graphicContext);
|
||||
m_graphicContext->DrawRoundedRectangle(x + 0.5, y + 0.5, w - 1, h - 1, radius);
|
||||
}
|
||||
m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius);
|
||||
else
|
||||
m_graphicContext->DrawRoundedRectangle(x, y, w, h, radius);
|
||||
}
|
||||
|
||||
void wxGCDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue