From bb2b48f2ba699ac6e39091761c0b025c637276af Mon Sep 17 00:00:00 2001 From: Kolya Kosenko Date: Sat, 23 Apr 2016 18:12:56 +0200 Subject: [PATCH] Handle negative width size in GDI+ DrawRectangle() and document it Apparently it's a common convention to allow width and/or height of a rectangle to be negative as both GDI and Cairo handle this natively, so also allow this for GDI+ and document this as the expected behaviour. Closes #17495. --- interface/wx/dc.h | 10 ++++++++-- src/msw/graphics.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/interface/wx/dc.h b/interface/wx/dc.h index cdbf15d161..05fcac33c7 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -523,8 +523,14 @@ public: wxPolygonFillMode fill_style = wxODDEVEN_RULE); /** - Draws a rectangle with the given top left corner, and with the given - size. The current pen is used for the outline and the current brush + Draws a rectangle with the given corner coordinate and size. + + Normally, @a x and @a y specify the top left corner coordinates and + both @a width and @a height are positive, however they are also allowed + to be negative, in which case the corresponding corner coordinate + refers to the right or bottom corner instead. + + The current pen is used for the outline and the current brush for filling the shape. */ void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 2bb9b739cb..b18cd52a73 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -1508,6 +1508,18 @@ void wxGDIPlusContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDoub Brush *brush = m_brush.IsNull() ? NULL : ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush(); Pen *pen = m_pen.IsNull() ? NULL : ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen(); + if ( w < 0 ) + { + x += w; + w = -w; + } + + if ( h < 0 ) + { + y += h; + h = -h; + } + if ( brush ) { // the offset is used to fill only the inside of the rectangle and not paint underneath