From 7153eaf6ec028051e268d6b1178528c88d246bd6 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 27 Sep 2020 11:16:26 +0200 Subject: [PATCH] Implement new coordinates conversion functions in wxDC Current DeviceToLogical{X|Y}(), LogicalToDevice{X|Y}(), DeviceToLogicalRel{X|Y}(), LogicalToDeviceRel{X|Y}() functions don't take into account transformations applied with SetTransformMatrix() so conversion results are invalid if coordinate system is e.g. rotated. We need to implement new conversion functions that take into account all applied transformations and also convert x,y coordinates in one call because in general case x,y coordinates are coupled and cannot be converted independently on each other. Closes #18923. --- include/wx/dc.h | 16 +++++++++++ interface/wx/dc.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/include/wx/dc.h b/include/wx/dc.h index 41f6d8212e..6dcf24c1c3 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -1014,6 +1014,14 @@ public: { return m_pimpl->DeviceToLogicalXRel(x); } wxCoord DeviceToLogicalYRel(wxCoord y) const { return m_pimpl->DeviceToLogicalYRel(y); } + wxPoint DeviceToLogical(const wxPoint& pt) const + { return m_pimpl->DeviceToLogical(pt.x, pt.y); } + wxPoint DeviceToLogical(wxCoord x, wxCoord y) const + { return m_pimpl->DeviceToLogical(x, y); } + wxSize DeviceToLogicalRel(const wxSize& dim) const + { return m_pimpl->DeviceToLogicalRel(dim.x, dim.y); } + wxSize DeviceToLogicalRel(int x, int y) const + { return m_pimpl->DeviceToLogicalRel(x, y); } wxCoord LogicalToDeviceX(wxCoord x) const { return m_pimpl->LogicalToDeviceX(x); } wxCoord LogicalToDeviceY(wxCoord y) const @@ -1022,6 +1030,14 @@ public: { return m_pimpl->LogicalToDeviceXRel(x); } wxCoord LogicalToDeviceYRel(wxCoord y) const { return m_pimpl->LogicalToDeviceYRel(y); } + wxPoint LogicalToDevice(const wxPoint& pt) const + { return m_pimpl->LogicalToDevice(pt.x, pt.y); } + wxPoint LogicalToDevice(wxCoord x, wxCoord y) const + { return m_pimpl->LogicalToDevice(x, y); } + wxSize LogicalToDeviceRel(const wxSize& dim) const + { return m_pimpl->LogicalToDeviceRel(dim.x, dim.y); } + wxSize LogicalToDeviceRel(int x, int y) const + { return m_pimpl->LogicalToDeviceRel(x, y); } void SetMapMode(wxMappingMode mode) { m_pimpl->SetMapMode(mode); } diff --git a/interface/wx/dc.h b/interface/wx/dc.h index 10a0392df5..fc1505ec21 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -283,6 +283,74 @@ public: */ wxCoord LogicalToDeviceYRel(wxCoord y) const; + /** + Converts device (@a x, @a y) coordinates to logical coordinates + taking into account all apllied transformations like the current + mapping mode, scale factors, device origin, axes orientation, + affine transformation. + + @since 3.1.5 + */ + wxPoint DeviceToLogical(wxCoord x, wxCoord y) const; + + /** + @overload + + @since 3.1.5 + */ + wxPoint DeviceToLogical(const wxPoint& pt) const; + + /** + Converts device @a x, @a y coordinates to relative logical coordinates + taking into account all apllied transformations like the current + mapping mode, scale factors, affine transformation. + Use this for converting distances like e.g. width and height. + + @since 3.1.5 + */ + wxSize DeviceToLogicalRel(int x, int y) const; + + /** + @overload + + @since 3.1.5 + */ + wxSize DeviceToLogicalRel(const wxSize& dim) const; + + /** + Converts logical (@a x, @a y) coordinates to device coordinates + taking into account all apllied transformations like the current + mapping mode, scale factors, device origin, axes orientation, + affine transformation. + + @since 3.1.5 + */ + wxPoint LogicalToDevice(wxCoord x, wxCoord y) const; + + /** + @overload + + @since 3.1.5 + */ + wxPoint LogicalToDevice(const wxPoint& pt) const; + + /** + Converts logical @a x, @a y coordinates to relative device coordinates + taking into account all apllied transformations like the current + mapping mode, scale factors, affine transformation. + Use this for converting distances like e.g. width and height. + + @since 3.1.5 + */ + wxSize LogicalToDeviceRel(int x, int y) const; + + /** + @overload + + @since 3.1.5 + */ + wxSize LogicalToDeviceRel(const wxSize& dim) const; + //@}