Moved all the coordinate system calculation to wxDCBase
and thus removed all the duplicated code in all wxDC classes. Problematic is that wxSVGFileDC and wxPostscriptDC inherit from wxDC and therefore include platform specific code (also before this change) so I chose to override all SetLogicalOrigin() etc. methods in these classes and call their wxDCBase methods thereby circumventing the platform dependent code. I'm afraid the Mac code will require updating, too. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45752 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -42,6 +42,48 @@ IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxBufferedDC, wxMemoryDC)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxBufferedPaintDC, wxBufferedDC)
|
||||
|
||||
wxDCBase::wxDCBase()
|
||||
: m_colour(wxColourDisplay())
|
||||
, m_ok(true)
|
||||
, m_clipping(false)
|
||||
, m_isInteractive(0)
|
||||
, m_isBBoxValid(false)
|
||||
, m_logicalOriginX(0), m_logicalOriginY(0)
|
||||
, m_deviceOriginX(0), m_deviceOriginY(0)
|
||||
, m_deviceLocalOriginX(0), m_deviceLocalOriginY(0)
|
||||
, m_logicalScaleX(1.0), m_logicalScaleY(1.0)
|
||||
, m_userScaleX(1.0), m_userScaleY(1.0)
|
||||
, m_scaleX(1.0), m_scaleY(1.0)
|
||||
, m_signX(1), m_signY(1)
|
||||
, m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
|
||||
, m_clipX1(0), m_clipY1(0), m_clipX2(0), m_clipY2(0)
|
||||
, m_logicalFunction(wxCOPY)
|
||||
, m_backgroundMode(wxTRANSPARENT)
|
||||
, m_mappingMode(wxMM_TEXT)
|
||||
, m_pen()
|
||||
, m_brush()
|
||||
, m_backgroundBrush(*wxTRANSPARENT_BRUSH)
|
||||
, m_textForegroundColour(*wxBLACK)
|
||||
, m_textBackgroundColour(*wxWHITE)
|
||||
, m_font()
|
||||
#if wxUSE_PALETTE
|
||||
, m_palette()
|
||||
, m_hasCustomPalette(false)
|
||||
#endif // wxUSE_PALETTE
|
||||
{
|
||||
m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
|
||||
(double)wxGetDisplaySizeMM().GetWidth();
|
||||
m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
|
||||
(double)wxGetDisplaySizeMM().GetHeight();
|
||||
|
||||
ResetBoundingBox();
|
||||
ResetClipping();
|
||||
}
|
||||
|
||||
wxDCBase::~wxDCBase()
|
||||
{
|
||||
}
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
void wxDCBase::BeginDrawing()
|
||||
{
|
||||
@@ -52,6 +94,125 @@ void wxDCBase::EndDrawing()
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// coordinate conversions and transforms
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
|
||||
{
|
||||
return wxRound((double)(x - m_deviceOriginX - m_deviceLocalOriginX) / m_scaleX) * m_signX + m_logicalOriginX;
|
||||
}
|
||||
|
||||
wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
|
||||
{
|
||||
return wxRound((double)(y - m_deviceOriginY - m_deviceLocalOriginY) / m_scaleY) * m_signY + m_logicalOriginY;
|
||||
}
|
||||
|
||||
wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
|
||||
{
|
||||
return wxRound((double)(x) / m_scaleX);
|
||||
}
|
||||
|
||||
wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
|
||||
{
|
||||
return wxRound((double)(y) / m_scaleY);
|
||||
}
|
||||
|
||||
wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
|
||||
{
|
||||
return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX + m_deviceLocalOriginX;
|
||||
}
|
||||
|
||||
wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
|
||||
{
|
||||
return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY + m_deviceLocalOriginY;
|
||||
}
|
||||
|
||||
wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
|
||||
{
|
||||
return wxRound((double)(x) * m_scaleX);
|
||||
}
|
||||
|
||||
wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
|
||||
{
|
||||
return wxRound((double)(y) * m_scaleY);
|
||||
}
|
||||
|
||||
void wxDCBase::ComputeScaleAndOrigin()
|
||||
{
|
||||
m_scaleX = m_logicalScaleX * m_userScaleX;
|
||||
m_scaleY = m_logicalScaleY * m_userScaleY;
|
||||
}
|
||||
|
||||
void wxDCBase::SetMapMode( int mode )
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case wxMM_TWIPS:
|
||||
SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
|
||||
break;
|
||||
case wxMM_POINTS:
|
||||
SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
|
||||
break;
|
||||
case wxMM_METRIC:
|
||||
SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
|
||||
break;
|
||||
case wxMM_LOMETRIC:
|
||||
SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
|
||||
break;
|
||||
default:
|
||||
case wxMM_TEXT:
|
||||
SetLogicalScale( 1.0, 1.0 );
|
||||
break;
|
||||
}
|
||||
m_mappingMode = mode;
|
||||
}
|
||||
|
||||
void wxDCBase::SetUserScale( double x, double y )
|
||||
{
|
||||
// allow negative ? -> no
|
||||
m_userScaleX = x;
|
||||
m_userScaleY = y;
|
||||
ComputeScaleAndOrigin();
|
||||
}
|
||||
|
||||
void wxDCBase::SetLogicalScale( double x, double y )
|
||||
{
|
||||
// allow negative ?
|
||||
m_logicalScaleX = x;
|
||||
m_logicalScaleY = y;
|
||||
ComputeScaleAndOrigin();
|
||||
}
|
||||
|
||||
void wxDCBase::SetLogicalOrigin( wxCoord x, wxCoord y )
|
||||
{
|
||||
m_logicalOriginX = x * m_signX;
|
||||
m_logicalOriginY = y * m_signY;
|
||||
ComputeScaleAndOrigin();
|
||||
}
|
||||
|
||||
void wxDCBase::SetDeviceOrigin( wxCoord x, wxCoord y )
|
||||
{
|
||||
m_deviceOriginX = x;
|
||||
m_deviceOriginY = y;
|
||||
ComputeScaleAndOrigin();
|
||||
}
|
||||
|
||||
void wxDCBase::SetDeviceLocalOrigin( wxCoord x, wxCoord y )
|
||||
{
|
||||
m_deviceLocalOriginX = x;
|
||||
m_deviceLocalOriginY = y;
|
||||
ComputeScaleAndOrigin();
|
||||
}
|
||||
|
||||
void wxDCBase::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
|
||||
{
|
||||
// only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
|
||||
m_signX = (xLeftRight ? 1 : -1);
|
||||
m_signY = (yBottomUp ? -1 : 1);
|
||||
ComputeScaleAndOrigin();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// special symbols
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user