]> git.saurik.com Git - wxWidgets.git/commitdiff
implemented clipping using native regions
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 19 Dec 2001 22:00:14 +0000 (22:00 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 19 Dec 2001 22:00:14 +0000 (22:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13116 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/dc.cpp
src/mac/carbon/dcclient.cpp
src/mac/dc.cpp
src/mac/dcclient.cpp

index f4bf8ea95c72269bdc1947e08f90faed117f3efd..275f5147249ff5ceb6a918c28682fb6ff8beb04c 100644 (file)
@@ -90,10 +90,11 @@ wxDC::wxDC()
        m_macPenInstalled = false ;
        
        m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ;
        m_macPenInstalled = false ;
        
        m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ;
-       m_macClipRect.left = -32000 ;
-       m_macClipRect.top = -32000 ;
-       m_macClipRect.right = 32000 ;
-       m_macClipRect.bottom = 32000 ;
+       m_macBoundaryClipRgn = NewRgn() ;
+       m_macCurrentClipRgn = NewRgn() ;
+
+       SetRectRgn( m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
+       SetRectRgn( m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
 
     m_pen = *wxBLACK_PEN;
     m_font = *wxNORMAL_FONT;
 
     m_pen = *wxBLACK_PEN;
     m_font = *wxNORMAL_FONT;
@@ -113,23 +114,14 @@ wxMacPortSetter::~wxMacPortSetter()
 
 wxDC::~wxDC(void)
 {
 
 wxDC::~wxDC(void)
 {
+  DisposeRgn( m_macBoundaryClipRgn ) ;
+  DisposeRgn( m_macCurrentClipRgn ) ;
 }
 void wxDC::MacSetupPort(AGAPortHelper* help) const
 {
 //     help->Setup( m_macPort ) ;
        ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v);
 }
 void wxDC::MacSetupPort(AGAPortHelper* help) const
 {
 //     help->Setup( m_macPort ) ;
        ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v);
-
-       if ( m_clipping )
-       {
-               Rect clip = { m_clipY1 , m_clipX1 , m_clipY2 , m_clipX2 } ;
-               ::SectRect( &clip , &m_macClipRect , &clip ) ;
-               ::ClipRect( &clip ) ;
-       }
-       else
-       {
-               ::ClipRect(&m_macClipRect);
-       }
-
+       SetClip( m_macCurrentClipRgn);
 
        m_macFontInstalled = false ;
        m_macBrushInstalled = false ;
 
        m_macFontInstalled = false ;
        m_macBrushInstalled = false ;
@@ -251,6 +243,9 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei
     ww = XLOG2DEVREL(width);
     hh = YLOG2DEVREL(height);
 
     ww = XLOG2DEVREL(width);
     hh = YLOG2DEVREL(height);
 
+    SetRectRgn( m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
+    SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+    
     if( m_clipping )
     {
         m_clipX1 = wxMax( m_clipX1 , xx );
     if( m_clipping )
     {
         m_clipX1 = wxMax( m_clipX1 , xx );
@@ -279,14 +274,53 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region  )
         return;
     }
 
         return;
     }
 
+    wxCoord x, y, w, h;
+    region.GetBox( x, y, w, h );
     wxCoord xx, yy, ww, hh;
     wxCoord xx, yy, ww, hh;
-    region.GetBox( xx, yy, ww, hh );
-    wxDC::DoSetClippingRegion( xx, yy, ww, hh );
+
+    xx = XLOG2DEV(x);
+    yy = YLOG2DEV(y);
+    ww = XLOG2DEVREL(w);
+    hh = YLOG2DEVREL(h);
+
+    // if we have a scaling that we cannot map onto native regions
+    // we must use the box
+
+    if ( ww != w || hh != h )
+    {
+        wxDC::DoSetClippingRegion( x, y, w, h );
+    }
+    else
+    {
+        CopyRgn( region.GetWXHRGN() , m_macCurrentClipRgn ) ;
+        if ( xx != x || yy != y )
+        {
+            OffsetRgn( m_macCurrentClipRgn , xx - x , yy - y ) ;
+        }
+        SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+        if( m_clipping )
+        {
+            m_clipX1 = wxMax( m_clipX1 , xx );
+            m_clipY1 = wxMax( m_clipY1 , yy );
+            m_clipX2 = wxMin( m_clipX2, (xx + ww));
+            m_clipY2 = wxMin( m_clipY2, (yy + hh));
+        }
+        else
+        {
+            m_clipping = TRUE;
+            m_clipX1 = xx;
+            m_clipY1 = yy;
+            m_clipX2 = xx + ww;
+            m_clipY2 = yy + hh;
+        }
+    }
+
 }
 
 void wxDC::DestroyClippingRegion()
 {
   wxMacPortSetter helper(this) ;
 }
 
 void wxDC::DestroyClippingRegion()
 {
   wxMacPortSetter helper(this) ;
+  CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
   m_clipping = FALSE;
 }    
 void wxDC::DoGetSize( int* width, int* height ) const
   m_clipping = FALSE;
 }    
 void wxDC::DoGetSize( int* width, int* height ) const
index 74533a7442e23485cf71be7ef8b104fd8eaf0529..7bb6d7a6a867862469ba7dcc9977f8d406017fce 100644 (file)
@@ -51,8 +51,9 @@ wxWindowDC::wxWindowDC(wxWindow *the_canvas)
        wxWindowMac* rootwindow ;
        
        // this time it is really the full window
        wxWindowMac* rootwindow ;
        
        // this time it is really the full window
-       
-       the_canvas->MacGetPortParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow );
+       Rect clipRect ;
+       the_canvas->MacGetPortParams(&m_macLocalOrigin, &clipRect , &windowref , &rootwindow );
+       SetRectRgn( m_macBoundaryClipRgn , clipRect.left , clipRect.top , clipRect.right , clipRect.bottom ) ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = the_canvas->GetSize() ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = the_canvas->GetSize() ;
@@ -80,7 +81,9 @@ wxClientDC::wxClientDC(wxWindow *window)
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
-       window->MacGetPortClientParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow );
+       Rect clipRect ;
+       window->MacGetPortClientParams(&m_macLocalOrigin, &clipRect , &windowref , &rootwindow );
+       SetRectRgn( m_macBoundaryClipRgn , clipRect.left , clipRect.top , clipRect.right , clipRect.bottom ) ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = window->GetSize() ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = window->GetSize() ;
@@ -108,8 +111,9 @@ wxPaintDC::wxPaintDC(wxWindow *window)
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
-       window->MacGetPortClientParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow );
-
+       Rect clipRect ;
+       window->MacGetPortClientParams(&m_macLocalOrigin, &clipRect , &windowref , &rootwindow );
+  CopyRgn( window->GetUpdateRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_ok = TRUE ;
        /*
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_ok = TRUE ;
        /*
index f4bf8ea95c72269bdc1947e08f90faed117f3efd..275f5147249ff5ceb6a918c28682fb6ff8beb04c 100644 (file)
@@ -90,10 +90,11 @@ wxDC::wxDC()
        m_macPenInstalled = false ;
        
        m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ;
        m_macPenInstalled = false ;
        
        m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ;
-       m_macClipRect.left = -32000 ;
-       m_macClipRect.top = -32000 ;
-       m_macClipRect.right = 32000 ;
-       m_macClipRect.bottom = 32000 ;
+       m_macBoundaryClipRgn = NewRgn() ;
+       m_macCurrentClipRgn = NewRgn() ;
+
+       SetRectRgn( m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
+       SetRectRgn( m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
 
     m_pen = *wxBLACK_PEN;
     m_font = *wxNORMAL_FONT;
 
     m_pen = *wxBLACK_PEN;
     m_font = *wxNORMAL_FONT;
@@ -113,23 +114,14 @@ wxMacPortSetter::~wxMacPortSetter()
 
 wxDC::~wxDC(void)
 {
 
 wxDC::~wxDC(void)
 {
+  DisposeRgn( m_macBoundaryClipRgn ) ;
+  DisposeRgn( m_macCurrentClipRgn ) ;
 }
 void wxDC::MacSetupPort(AGAPortHelper* help) const
 {
 //     help->Setup( m_macPort ) ;
        ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v);
 }
 void wxDC::MacSetupPort(AGAPortHelper* help) const
 {
 //     help->Setup( m_macPort ) ;
        ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v);
-
-       if ( m_clipping )
-       {
-               Rect clip = { m_clipY1 , m_clipX1 , m_clipY2 , m_clipX2 } ;
-               ::SectRect( &clip , &m_macClipRect , &clip ) ;
-               ::ClipRect( &clip ) ;
-       }
-       else
-       {
-               ::ClipRect(&m_macClipRect);
-       }
-
+       SetClip( m_macCurrentClipRgn);
 
        m_macFontInstalled = false ;
        m_macBrushInstalled = false ;
 
        m_macFontInstalled = false ;
        m_macBrushInstalled = false ;
@@ -251,6 +243,9 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei
     ww = XLOG2DEVREL(width);
     hh = YLOG2DEVREL(height);
 
     ww = XLOG2DEVREL(width);
     hh = YLOG2DEVREL(height);
 
+    SetRectRgn( m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
+    SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+    
     if( m_clipping )
     {
         m_clipX1 = wxMax( m_clipX1 , xx );
     if( m_clipping )
     {
         m_clipX1 = wxMax( m_clipX1 , xx );
@@ -279,14 +274,53 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region  )
         return;
     }
 
         return;
     }
 
+    wxCoord x, y, w, h;
+    region.GetBox( x, y, w, h );
     wxCoord xx, yy, ww, hh;
     wxCoord xx, yy, ww, hh;
-    region.GetBox( xx, yy, ww, hh );
-    wxDC::DoSetClippingRegion( xx, yy, ww, hh );
+
+    xx = XLOG2DEV(x);
+    yy = YLOG2DEV(y);
+    ww = XLOG2DEVREL(w);
+    hh = YLOG2DEVREL(h);
+
+    // if we have a scaling that we cannot map onto native regions
+    // we must use the box
+
+    if ( ww != w || hh != h )
+    {
+        wxDC::DoSetClippingRegion( x, y, w, h );
+    }
+    else
+    {
+        CopyRgn( region.GetWXHRGN() , m_macCurrentClipRgn ) ;
+        if ( xx != x || yy != y )
+        {
+            OffsetRgn( m_macCurrentClipRgn , xx - x , yy - y ) ;
+        }
+        SectRgn( m_macCurrentClipRgn , m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
+        if( m_clipping )
+        {
+            m_clipX1 = wxMax( m_clipX1 , xx );
+            m_clipY1 = wxMax( m_clipY1 , yy );
+            m_clipX2 = wxMin( m_clipX2, (xx + ww));
+            m_clipY2 = wxMin( m_clipY2, (yy + hh));
+        }
+        else
+        {
+            m_clipping = TRUE;
+            m_clipX1 = xx;
+            m_clipY1 = yy;
+            m_clipX2 = xx + ww;
+            m_clipY2 = yy + hh;
+        }
+    }
+
 }
 
 void wxDC::DestroyClippingRegion()
 {
   wxMacPortSetter helper(this) ;
 }
 
 void wxDC::DestroyClippingRegion()
 {
   wxMacPortSetter helper(this) ;
+  CopyRgn( m_macBoundaryClipRgn , m_macCurrentClipRgn ) ;
   m_clipping = FALSE;
 }    
 void wxDC::DoGetSize( int* width, int* height ) const
   m_clipping = FALSE;
 }    
 void wxDC::DoGetSize( int* width, int* height ) const
index 74533a7442e23485cf71be7ef8b104fd8eaf0529..7bb6d7a6a867862469ba7dcc9977f8d406017fce 100644 (file)
@@ -51,8 +51,9 @@ wxWindowDC::wxWindowDC(wxWindow *the_canvas)
        wxWindowMac* rootwindow ;
        
        // this time it is really the full window
        wxWindowMac* rootwindow ;
        
        // this time it is really the full window
-       
-       the_canvas->MacGetPortParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow );
+       Rect clipRect ;
+       the_canvas->MacGetPortParams(&m_macLocalOrigin, &clipRect , &windowref , &rootwindow );
+       SetRectRgn( m_macBoundaryClipRgn , clipRect.left , clipRect.top , clipRect.right , clipRect.bottom ) ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = the_canvas->GetSize() ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = the_canvas->GetSize() ;
@@ -80,7 +81,9 @@ wxClientDC::wxClientDC(wxWindow *window)
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
-       window->MacGetPortClientParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow );
+       Rect clipRect ;
+       window->MacGetPortClientParams(&m_macLocalOrigin, &clipRect , &windowref , &rootwindow );
+       SetRectRgn( m_macBoundaryClipRgn , clipRect.left , clipRect.top , clipRect.right , clipRect.bottom ) ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = window->GetSize() ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_minY = m_minX =  0;
        wxSize size = window->GetSize() ;
@@ -108,8 +111,9 @@ wxPaintDC::wxPaintDC(wxWindow *window)
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
        WindowRef windowref ;
        wxWindowMac* rootwindow ;
        
-       window->MacGetPortClientParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow );
-
+       Rect clipRect ;
+       window->MacGetPortClientParams(&m_macLocalOrigin, &clipRect , &windowref , &rootwindow );
+  CopyRgn( window->GetUpdateRegion().GetWXHRGN() , m_macBoundaryClipRgn ) ;
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_ok = TRUE ;
        /*
        m_macPort = UMAGetWindowPort( windowref ) ;
        m_ok = TRUE ;
        /*