From b2760ff420a4f9962c9c0a90162544cfdc0b9867 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 15 Jul 2016 20:58:36 +0200 Subject: [PATCH] Fixed setting wxRegion with rectangle having negative size (MSW). wxRegion uses CreateRectRgn() Win API which requires that its (x1,y1) parameters represent the top-left corner of the rectangle region so if a rectangle with negative values of the width or height is passed to wxRegion's ctor (what means that (x,y) doesn't represent top-left corner) we need to recalculate passed parameters to get rectangle with (x,y) at the top-left corner. --- src/msw/region.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/msw/region.cpp b/src/msw/region.cpp index 425ba91965..8ff88073b3 100644 --- a/src/msw/region.cpp +++ b/src/msw/region.cpp @@ -94,22 +94,40 @@ wxRegion::wxRegion(WXHRGN hRegion) M_REGION = (HRGN) hRegion; } +static HRGN CreateRectRgnMSW(wxCoord x, wxCoord y, wxCoord w, wxCoord h) +{ + // (x,y) has to represent the left-top corner of the region + // so if size values are negative we need to recalculate + // parameters of the region to get (x,y) at this corner. + if ( w < 0 ) + { + w = -w; + x -= (w - 1); + } + if ( h < 0 ) + { + h = -h; + y -= (h - 1); + } + return ::CreateRectRgn(x, y, x + w, y + h); +} + wxRegion::wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) { m_refData = new wxRegionRefData; - M_REGION = ::CreateRectRgn(x, y, x + w, y + h); + M_REGION = CreateRectRgnMSW(x, y, w, h); } wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight) { m_refData = new wxRegionRefData; - M_REGION = ::CreateRectRgn(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); + M_REGION = CreateRectRgnMSW(topLeft.x, topLeft.y, bottomRight.x-topLeft.x, bottomRight.y-topLeft.y); } wxRegion::wxRegion(const wxRect& rect) { m_refData = new wxRegionRefData; - M_REGION = ::CreateRectRgn(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); + M_REGION = CreateRectRgnMSW(rect.x, rect.y, rect.width, rect.height); } wxRegion::wxRegion(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle)