]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/dc.cpp
corrected graying out, only to be executed when background is gray or white
[wxWidgets.git] / src / mac / carbon / dc.cpp
index 8e930cd837837a1dcd3f09938017fae94ba107fa..59472ddfa54b71968894b93fe310e60db8f562ec 100644 (file)
@@ -778,54 +778,40 @@ void  wxDC::DoDrawPolygon(int n, wxPoint points[],
        
        wxCoord x1, x2 , y1 , y2 ;
   
+    if ( m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT )
+        return ;
+        
+       PolyHandle polygon = OpenPoly();
+       
+       x1 = XLOG2DEVMAC(points[0].x + xoffset);
+       y1 = YLOG2DEVMAC(points[0].y + yoffset);   
+       ::MoveTo(x1,y1);
+
+       for (int i = 0; i < n-1; i++)
+       {
+               x2 = XLOG2DEVMAC(points[i+1].x + xoffset);
+               y2 = YLOG2DEVMAC(points[i+1].y + yoffset);
+               ::LineTo(x2, y2);
+       }
+
+       ClosePoly();
+
        if (m_brush.GetStyle() != wxTRANSPARENT)
        {
-               PolyHandle polygon = OpenPoly();
-               
-               x1 = XLOG2DEVMAC(points[0].x + xoffset);
-               y1 = YLOG2DEVMAC(points[0].y + yoffset);   
-               ::MoveTo(x1,y1);
-  
-               for (int i = 0; i < n-1; i++)
-               {
-               x2 = XLOG2DEVMAC(points[i+1].x + xoffset);
-               y2 = YLOG2DEVMAC(points[i+1].y + yoffset);
-               ::LineTo(x2, y2);
-               }
-
-               ClosePoly();
 
                MacInstallBrush();
                ::PaintPoly( polygon );
                
-               KillPoly( polygon );
        }
        
        if (m_pen.GetStyle() != wxTRANSPARENT) 
        {
-               PolyHandle polygon = OpenPoly();
-               
-               x1 = XLOG2DEVMAC(points[0].x + xoffset);
-               y1 = YLOG2DEVMAC(points[0].y + yoffset);   
-               ::MoveTo(x1,y1);
-  
-               for (int i = 0; i < n-1; i++)
-               {
-               x2 = XLOG2DEVMAC(points[i+1].x + xoffset);
-               y2 = YLOG2DEVMAC(points[i+1].y + yoffset);
-               ::LineTo(x2, y2);
-               }
-               
-               // return to origin to close path
-               ::LineTo(x1,y1);
-
-               ClosePoly();
        
                MacInstallPen() ;
                ::FramePoly( polygon ) ;
                
-               KillPoly( polygon );
        }
+       KillPoly( polygon );
 }
 
 void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
@@ -1445,27 +1431,28 @@ void wxDC::MacInstallFont() const
 
 static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern)
 {
-       int thePatListID = sysPatListID;
+    // we have our own pattern list now
+       int thePatListID = 128;
        int theIndex;
        switch(hatchStyle)
        {
                case wxBDIAGONAL_HATCH:
-                       theIndex = 34; // WCH: this is not good
+                       theIndex = 2; 
                        break;
                case wxFDIAGONAL_HATCH:
-                       theIndex = 26;
+                       theIndex = 3;
                        break;
                case wxCROSS_HATCH:
-                       theIndex = 5;
+                       theIndex = 4;
                        break;
                case wxHORIZONTAL_HATCH:
-                       theIndex = 25;
+                       theIndex = 5;
                        break;
                case wxVERTICAL_HATCH:
                        theIndex = 6;
                        break;
                case wxCROSSDIAG_HATCH:
-                       theIndex = 4; // WCH: this is not good
+                       theIndex = 7; 
                        break;
                default:
                        theIndex = 1; // solid pattern
@@ -1510,7 +1497,46 @@ void wxDC::MacInstallPen() const
        }
        else
        {
-               ::PenPat(GetQDGlobalsBlack(&blackColor));
+           Pattern pat = *GetQDGlobalsBlack(&blackColor) ;
+           switch( penStyle )
+           {
+               case wxDOT :
+                for ( int i = 0 ; i < 8 ; ++i )
+                {
+                    pat.pat[i] = 0xCC ;
+                }
+                   break ;
+               case wxLONG_DASH :
+                for ( int i = 0 ; i < 8 ; ++i )
+                {
+                    pat.pat[i] = 0xFE ;
+                }
+                   break ;
+               case wxSHORT_DASH :
+                for ( int i = 0 ; i < 8 ; ++i )
+                {
+                    pat.pat[i] = 0xEE ;
+                }
+                   break ;
+               case wxDOT_DASH :
+                for ( int i = 0 ; i < 8 ; ++i )
+                {
+                    pat.pat[i] = 0x6F ;
+                }
+                   break ;
+               case wxUSER_DASH :
+                   {
+                       wxDash* dash ;
+                       int number = m_pen.GetDashes(&dash) ;
+                       // right now we don't allocate larger pixmaps
+                       for ( int i = 0 ; i < 8 ; ++i )
+                       {
+                           pat.pat[i] = dash[0] ;
+                       }
+                   }
+                   break ;
+           }
+               ::PenPat(&pat);
        }
 
        short mode = patCopy ;
@@ -1519,11 +1545,11 @@ void wxDC::MacInstallPen() const
        
        switch( m_logicalFunction )
        {
-               case wxCOPY:       // src
-                       mode = patCopy ;
+               case wxCOPY:       // only foreground color, leave background (thus not patCopy)
+                       mode = patOr ;
                        break ;
                case wxINVERT:     // NOT dst
-                       ::PenPat(GetQDGlobalsBlack(&blackColor));
+//                     ::PenPat(GetQDGlobalsBlack(&blackColor));
                        mode = patXor ;
                        break ;
                case wxXOR:        // src XOR dst
@@ -1618,9 +1644,46 @@ void wxDC::MacInstallBrush() const
                wxMacGetHatchPattern(brushStyle, &pat);
                ::PenPat(&pat);
        }
-       else
+       else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
        {
-               ::PenPat(GetQDGlobalsBlack(&blackColor));
+           // for these the text fore (and back for MASK_OPAQUE) colors are used
+           wxBitmap* bitmap = m_brush.GetStipple() ;
+           int width = bitmap->GetWidth() ;
+           int height = bitmap->GetHeight() ;
+           int depth = bitmap->GetDepth() ;
+           if ( m_brush.GetStyle() == wxSTIPPLE )
+           {
+               GWorldPtr gw = bitmap->GetHBITMAP() ;
+               if ( width == 8 && height == 8 && depth == 1)
+               {
+                   Pattern pat ;
+                LockPixels( GetGWorldPixMap( gw ) ) ;
+                BitMap* gwbitmap = (BitMap*) *GetGWorldPixMap( gw ) ; // since the color depth is 1 it is a BitMap
+                   int alignment = gwbitmap->rowBytes & 0x7FFF ;
+                UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
+                for ( int i = 0 ; i < 8 ; ++i )
+                {
+                    pat.pat[i] = gwbits[i*alignment+0] ;
+                }
+                UnlockPixels( GetGWorldPixMap( gw ) ) ;
+                   
+                   ::PenPat( &pat ) ;
+               }
+               else
+               {
+                       ::PenPat(GetQDGlobalsBlack(&blackColor));
+                   }
+           }
+           else if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
+           {
+               ::RGBForeColor( &m_textForegroundColour.GetPixel() );
+               ::RGBForeColor( &m_textBackgroundColour.GetPixel() );
+                   ::PenPat(GetQDGlobalsBlack(&blackColor));
+           }
+       }
+    else
+    {
+           ::PenPat(GetQDGlobalsBlack(&blackColor));
        }