Refactor the code that decides if the 0.5 offset chousl be applied

into its own method


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42388 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2006-10-25 06:55:17 +00:00
parent eb3e358db8
commit de3cb39f85
2 changed files with 22 additions and 18 deletions

View File

@@ -265,6 +265,10 @@ public:
// wrappers using wxPoint2DDouble TODO
// helper to determine if a 0.5 offset should be applied for the drawing operation
virtual bool ShouldOffset() const { return false; }
DECLARE_NO_COPY_CLASS(wxGraphicsContext)
DECLARE_ABSTRACT_CLASS(wxGraphicsContext)
};

View File

@@ -291,6 +291,18 @@ public:
void SetNativeContext( CGContextRef cg );
CGPathDrawingMode GetDrawingMode() const { return m_mode; }
virtual bool ShouldOffset() const
{
int penwidth = m_pen.GetWidth();
if ( penwidth == 0 )
penwidth = 1;
if ( m_pen.GetStyle() == wxTRANSPARENT )
penwidth = 0;
return ( penwidth % 2 ) == 1;
}
DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext)
DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext)
@@ -448,13 +460,7 @@ void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath *path )
{
EnsureIsValid();
int width = m_pen.GetWidth();
if ( width == 0 )
width = 1 ;
if ( m_pen.GetStyle() == wxTRANSPARENT )
width = 0 ;
bool offset = ( width % 2 ) == 1 ;
bool offset = ShouldOffset();
if ( offset )
CGContextTranslateCTM( m_cgContext, 0.5, 0.5 );
@@ -480,13 +486,7 @@ void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath *path , int fillSt
mode = kCGPathEOFillStroke;
}
int width = m_pen.GetWidth();
if ( width == 0 )
width = 1 ;
if ( m_pen.GetStyle() == wxTRANSPARENT )
width = 0 ;
bool offset = ( width % 2 ) == 1 ;
bool offset = ShouldOffset();
if ( offset )
CGContextTranslateCTM( m_cgContext, 0.5, 0.5 );