Implement platform-specific coordinate conversion functions

Generic wxDC::DeviceToLogicalRel{X|Y}() and wxDC::LogicalToDeviceRel{X|Y}()
functions don't take into account scaling applied with
wxDC::SetTransformMatrix().
We need to implement in wxDCImpl and its platform-specific derivates
new conversion functions that take all applied transformations into account.

See #18923.
This commit is contained in:
Artur Wieczorek 2020-09-27 10:38:08 +02:00
parent 6fac6c0b35
commit 2c3c841719
6 changed files with 54 additions and 0 deletions

View File

@ -325,6 +325,8 @@ public:
// coordinates conversions and transforms
virtual wxPoint DeviceToLogical(wxCoord x, wxCoord y) const;
virtual wxPoint LogicalToDevice(wxCoord x, wxCoord y) const;
virtual wxSize DeviceToLogicalRel(int x, int y) const;
virtual wxSize LogicalToDeviceRel(int x, int y) const;
// bounding box

View File

@ -124,6 +124,8 @@ public:
// coordinates conversions and transforms
virtual wxPoint DeviceToLogical(wxCoord x, wxCoord y) const wxOVERRIDE;
virtual wxPoint LogicalToDevice(wxCoord x, wxCoord y) const wxOVERRIDE;
virtual wxSize DeviceToLogicalRel(int x, int y) const wxOVERRIDE;
virtual wxSize LogicalToDeviceRel(int x, int y) const wxOVERRIDE;
// the true implementations
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,

View File

@ -88,6 +88,8 @@ public:
virtual wxPoint DeviceToLogical(wxCoord x, wxCoord y) const wxOVERRIDE;
virtual wxPoint LogicalToDevice(wxCoord x, wxCoord y) const wxOVERRIDE;
virtual wxSize DeviceToLogicalRel(int x, int y) const wxOVERRIDE;
virtual wxSize LogicalToDeviceRel(int x, int y) const wxOVERRIDE;
#if wxUSE_DC_TRANSFORM_MATRIX
virtual bool CanUseTransformMatrix() const wxOVERRIDE;

View File

@ -512,6 +512,16 @@ wxPoint wxDCImpl::LogicalToDevice(wxCoord x, wxCoord y) const
return wxPoint(LogicalToDeviceX(x), LogicalToDeviceY(y));
}
wxSize wxDCImpl::DeviceToLogicalRel(int x, int y) const
{
return wxSize(DeviceToLogicalXRel(x), DeviceToLogicalYRel(y));
}
wxSize wxDCImpl::LogicalToDeviceRel(int x, int y) const
{
return wxSize(LogicalToDeviceXRel(x), LogicalToDeviceYRel(y));
}
void wxDCImpl::ComputeScaleAndOrigin()
{
m_scaleX = m_logicalScaleX * m_userScaleX;

View File

@ -613,6 +613,22 @@ wxPoint wxGCDCImpl::LogicalToDevice(wxCoord x, wxCoord y) const
return wxPoint(wxRound(px), wxRound(py));
}
wxSize wxGCDCImpl::DeviceToLogicalRel(int x, int y) const
{
wxDouble dx = x;
wxDouble dy = y;
m_matrixCurrentInv.TransformDistance(&dx, &dy);
return wxSize(wxRound(dx), wxRound(dy));
}
wxSize wxGCDCImpl::LogicalToDeviceRel(int x, int y) const
{
wxDouble dx = x;
wxDouble dy = y;
m_matrixCurrent.TransformDistance(&dx, &dy);
return wxSize(wxRound(dx), wxRound(dy));
}
bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
const wxColour& WXUNUSED(col),
wxFloodFillStyle WXUNUSED(style))

View File

@ -2118,6 +2118,28 @@ wxPoint wxMSWDCImpl::LogicalToDevice(wxCoord x, wxCoord y) const
return wxPoint(p[0].x, p[0].y);
}
wxSize wxMSWDCImpl::DeviceToLogicalRel(int x, int y) const
{
POINT p[2];
p[0].x = 0;
p[0].y = 0;
p[1].x = x;
p[1].y = y;
::DPtoLP(GetHdc(), p, WXSIZEOF(p));
return wxSize(p[1].x-p[0].x, p[1].y-p[0].y);
}
wxSize wxMSWDCImpl::LogicalToDeviceRel(int x, int y) const
{
POINT p[2];
p[0].x = 0;
p[0].y = 0;
p[1].x = x;
p[1].y = y;
::LPtoDP(GetHdc(), p, WXSIZEOF(p));
return wxSize(p[1].x-p[0].x, p[1].y-p[0].y);
}
// ----------------------------------------------------------------------------
// Transform matrix
// ----------------------------------------------------------------------------