From 277f9c58a17b8ef486f721d7d2b3cb47120433b9 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 16 Sep 2016 22:04:53 +0200 Subject: [PATCH] Fix retrieving bounding box coordinates Bounding box coordinates have to be calculated and stored internally in device units to be independent on changes of logical coordinates between calls to wxDC::CalcBoundingBox. These stored coordinates are converted to the logical units on demand when they are retrieved with call to wxDC::MinX, MinY, MaxX or MaxY. Closes #17667. --- docs/changes.txt | 1 + include/wx/dc.h | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b6eb8f14fa..04d9ce5629 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -105,6 +105,7 @@ All (GUI): - Add wxGraphicsContext::Flush() for Cairo renderer. - Add wxStyledTextEvent::GetListCompletionMethod() (NewPagodi). - Add wxEVT_STC_AUTOCOMP_COMPLETED event (NewPagodi). +- Fix retrieving bounding box for wxDC with transformed coordinates. wxGTK: diff --git a/include/wx/dc.h b/include/wx/dc.h index c61498724f..7cfe17fb14 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -325,6 +325,9 @@ public: virtual void CalcBoundingBox(wxCoord x, wxCoord y) { + // Bounding box is internally stored in device units. + x = LogicalToDeviceX(x); + y = LogicalToDeviceY(y); if ( m_isBBoxValid ) { if ( x < m_minX ) m_minX = x; @@ -349,10 +352,11 @@ public: m_minX = m_maxX = m_minY = m_maxY = 0; } - wxCoord MinX() const { return m_minX; } - wxCoord MaxX() const { return m_maxX; } - wxCoord MinY() const { return m_minY; } - wxCoord MaxY() const { return m_maxY; } + // Get bounding box in logical units. + wxCoord MinX() const { return m_isBBoxValid ? DeviceToLogicalX(m_minX) : 0; } + wxCoord MaxX() const { return m_isBBoxValid ? DeviceToLogicalX(m_maxX) : 0; } + wxCoord MinY() const { return m_isBBoxValid ? DeviceToLogicalY(m_minY) : 0; } + wxCoord MaxY() const { return m_isBBoxValid ? DeviceToLogicalY(m_maxY) : 0; } // setters and getters @@ -712,8 +716,8 @@ protected: m_mm_to_pix_y; // bounding and clipping boxes - wxCoord m_minX, m_minY, m_maxX, m_maxY; - wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2; + 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. wxRasterOperationMode m_logicalFunction; int m_backgroundMode;