]> git.saurik.com Git - wxWidgets.git/commitdiff
Refactor the code that decides if the 0.5 offset chousl be applied
authorRobin Dunn <robin@alldunn.com>
Wed, 25 Oct 2006 06:55:17 +0000 (06:55 +0000)
committerRobin Dunn <robin@alldunn.com>
Wed, 25 Oct 2006 06:55:17 +0000 (06:55 +0000)
into its own method

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42388 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/graphics.h
src/mac/carbon/graphics.cpp

index e47ba09df8b84390bf8070bdaf0ccdc4fb39c736..6de106cdfcf75a56d77a9ebf4e70e878ebc27f3d 100755 (executable)
@@ -263,8 +263,12 @@ public:
     // draws a rounded rectangle
     virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
 
-     // wrappers using wxPoint2DDouble TODO
+    // 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)
 };
index 6aec43bfc27f71f15a462d08dbcae4b89b49c2bb..83e149970170c3e4dcf155e740f6ce4a5ccd5efc 100755 (executable)
@@ -290,6 +290,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)
@@ -446,15 +458,9 @@ void wxMacCoreGraphicsContext::ResetClip()
 
 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 ; 
+    EnsureIsValid();
+       
+    bool offset = ShouldOffset();
 
     if ( offset )
         CGContextTranslateCTM( m_cgContext, 0.5, 0.5 );
@@ -479,14 +485,8 @@ void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath *path , int fillSt
         else if ( mode == kCGPathFillStroke )
             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 );