From 2bcc9382a76aa3fd8e792c7842456349b54f4293 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 26 Jul 2021 21:04:21 +0200 Subject: [PATCH] Store clipping box coordinates in device units for generic wxDC Clipping box coordinates should be stored internally in device units to be independent on changes of logical coordinates made between calls to wxDCImpl::DoSetClippingRegion(). These stored coordinates should be converted on demand to the current logical units on call to wxDCImpl::DoGetClippingRect(). --- include/wx/dc.h | 3 ++- src/common/dcbase.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/wx/dc.h b/include/wx/dc.h index 2131ca91a1..85c55342f9 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -742,7 +742,8 @@ protected: // bounding and clipping boxes wxCoord m_minX, m_minY, m_maxX, m_maxY; // Bounding box is stored in device units. - wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2; // Clipping box is stored in logical units. + wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2; // Clipping box is stored in device units. + // Derived classes may store it in logical units. wxRasterOperationMode m_logicalFunction; int m_backgroundMode; diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index a788a3aac3..0784915fbc 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -362,7 +362,7 @@ void wxDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxASSERT_MSG( w >= 0 && h >= 0, wxS("Clipping box size values cannot be negative") ); - wxRect clipRegion(x, y, w, h); + wxRect clipRegion(LogicalToDevice(x, y), LogicalToDeviceRel(w, h)); if ( m_clipping ) { @@ -377,7 +377,7 @@ 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(DeviceToLogical(0, 0), DeviceToLogicalRel(dcWidth, dcHeight)); + wxRect dcRect(0, 0, dcWidth, dcHeight); clipRegion.Intersect(dcRect); m_clipping = true; @@ -420,10 +420,10 @@ bool wxDCImpl::DoGetClippingRect(wxRect& rect) const if ( m_clipping ) { - rect = wxRect(m_clipX1, - m_clipY1, - m_clipX2 - m_clipX1, - m_clipY2 - m_clipY1); + if ( m_clipX1 == m_clipX2 || m_clipY1 == m_clipY2 ) + rect = wxRect(); // empty clip region + else + rect = wxRect(DeviceToLogical(m_clipX1, m_clipY1), DeviceToLogicalRel(m_clipX2 - m_clipX1, m_clipY2 - m_clipY1)); return true; }