From 53230aaf4d3347d6b4893e0f71eb0c1a35df0af4 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 9 Jul 2016 22:50:27 +0200 Subject: [PATCH] Fixed retrieving clipping box for transformed wxDC Because wxDC can be the subject of geometric transformations (like translation, scaling) so we cannot assume in the calculations of the clipping box that DC origin is always at (0,0) and its logical size is the same as physical size. To get correct result we have to use logical coordinates of wxDC area in all clipping box calculations. --- include/wx/dc.h | 8 ++++---- src/common/dcbase.cpp | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/wx/dc.h b/include/wx/dc.h index ac0f97d6ea..c61498724f 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -449,13 +449,13 @@ public: DoGetSize(&dcWidth, &dcHeight); if ( x ) - *x = m_clipping ? m_clipX1 : 0; + *x = m_clipping ? m_clipX1 : DeviceToLogicalX(0); if ( y ) - *y = m_clipping ? m_clipY1 : 0; + *y = m_clipping ? m_clipY1 : DeviceToLogicalY(0); if ( w ) - *w = m_clipping ? m_clipX2 - m_clipX1 : dcWidth; + *w = m_clipping ? m_clipX2 - m_clipX1 : DeviceToLogicalXRel(dcWidth); if ( h ) - *h = m_clipping ? m_clipY2 - m_clipY1 : dcHeight; + *h = m_clipping ? m_clipY2 - m_clipY1 : DeviceToLogicalYRel(dcHeight); } virtual void DestroyClippingRegion() { ResetClipping(); } diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index d298ad300c..427955aca2 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -387,7 +387,8 @@ void wxDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) // of required clipping box and DC surface. int dcWidth, dcHeight; DoGetSize(&dcWidth, &dcHeight); - wxRect dcRect(wxSize(dcWidth, dcHeight)); + wxRect dcRect(DeviceToLogicalX(0), DeviceToLogicalY(0), + DeviceToLogicalXRel(dcWidth), DeviceToLogicalYRel(dcHeight)); clipRegion = dcRect.Intersect(newRegion); m_clipping = true;