diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index ea27b75a01..f4d2a25c51 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -642,13 +642,29 @@ void wxMSWDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h h = -h; y -= (h - 1); } - HRGN hrgn = ::CreateRectRgn(LogicalToDeviceX(x), - LogicalToDeviceY(y), - LogicalToDeviceX(x + w), - LogicalToDeviceY(y + h)); + // Because world transform can be applied to HDC and its coordiante + // system may be e.g. rotated we shouldn't assume that axis-aligned + // clipping box in local coordinates will remain axis-aligned box in + // device coordinates. Therefore we need to take into account all + // 4 corners of the rectangle to create a polygonal clipping region + // in device coordinates. + POINT rect[4]; + wxPoint p = LogicalToDevice(x, y); + rect[0].x = p.x; + rect[0].y = p.y; + p = LogicalToDevice(x + w, y); + rect[1].x = p.x; + rect[1].y = p.y; + p = LogicalToDevice(x + w, y + h); + rect[2].x = p.x; + rect[2].y = p.y; + p = LogicalToDevice(x, y + h); + rect[3].x = p.x; + rect[3].y = p.y; + HRGN hrgn = ::CreatePolygonRgn(rect, WXSIZEOF(rect), WINDING); if ( !hrgn ) { - wxLogLastError(wxT("CreateRectRgn")); + wxLogLastError(wxT("CreatePolygonRgn")); } else {