X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/773ccc318e21e2ce170789aaaaaa18b8b0f1878e..4aae00c69cf6e44c52e1a9e39f60c5d6a3498b02:/src/common/dcgraph.cpp diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index fc1a6a89e7..420e9039bb 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -27,10 +27,6 @@ #include "wx/region.h" #endif -#ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES - #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0 -#endif - //----------------------------------------------------------------------------- // constants //----------------------------------------------------------------------------- @@ -103,6 +99,7 @@ void wxGCDC::Init() m_brush = *wxWHITE_BRUSH; m_graphicContext = NULL; + m_logicalFunctionSupported = true; } @@ -203,6 +200,12 @@ void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) void wxGCDC::DestroyClippingRegion() { m_graphicContext->ResetClip(); + // currently the clip eg of a window extends to the area between the scrollbars + // so we must explicitely make sure it only covers the area we want it to draw + int width, height ; + GetSize( &width , &height ) ; + m_graphicContext->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , width, height ); + m_graphicContext->SetPen( m_pen ); m_graphicContext->SetBrush( m_brush ); @@ -378,7 +381,7 @@ void wxGCDC::SetBrush( const wxBrush &brush ) m_graphicContext->SetBrush( m_brush ); } } - + void wxGCDC::SetBackground( const wxBrush &brush ) { if (m_backgroundBrush == brush) @@ -395,17 +398,10 @@ void wxGCDC::SetLogicalFunction( int function ) return; m_logicalFunction = function; -#if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES - - CGContextRef cgContext = ((wxCairoContext*)(m_graphicContext))->GetNativeContext(); - if ( m_logicalFunction == wxCOPY ) - CGContextSetBlendMode( cgContext, kCGBlendModeNormal ); - else if ( m_logicalFunction == wxINVERT ) - CGContextSetBlendMode( cgContext, kCGBlendModeExclusion ); + if ( m_graphicContext->SetLogicalFunction( function ) ) + m_logicalFunctionSupported=true; else - CGContextSetBlendMode( cgContext, kCGBlendModeNormal ); -#endif - + m_logicalFunctionSupported=false; } bool wxGCDC::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), @@ -424,11 +420,8 @@ void wxGCDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") ); -#if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES - - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; -#endif m_graphicContext->StrokeLine(x1,y1,x2,y2); @@ -440,7 +433,7 @@ void wxGCDC::DoCrossHair( wxCoord x, wxCoord y ) { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") ); - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; int w = 0, h = 0; @@ -460,7 +453,7 @@ void wxGCDC::DoDrawArc( wxCoord x1, wxCoord y1, { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") ); - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; double dx = x1 - xc; @@ -505,23 +498,18 @@ void wxGCDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") ); - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; - bool fill = m_brush.GetStyle() != wxTRANSPARENT; - wxGraphicsPath path = m_graphicContext->CreatePath(); m_graphicContext->PushState(); - m_graphicContext->Translate(x+w/2,y+h/2); + m_graphicContext->Translate(x+w/2.0,y+h/2.0); wxDouble factor = ((wxDouble) w) / h; m_graphicContext->Scale( factor , 1.0); - if ( fill && (sa!=ea) ) - path.MoveToPoint(0,0); + // since these angles (ea,sa) are measured counter-clockwise, we invert them to // get clockwise angles - path.AddArc( 0, 0, h/2 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); - if ( fill && (sa!=ea) ) - path.AddLineToPoint(0,0); + path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); m_graphicContext->DrawPath( path ); m_graphicContext->PopState(); } @@ -538,11 +526,8 @@ void wxGCDC::DoDrawLines(int n, wxPoint points[], { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") ); -#if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES - - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; -#endif wxPoint2DDouble* pointsD = new wxPoint2DDouble[n]; for( int i = 0; i < n; ++i) @@ -560,7 +545,7 @@ void wxGCDC::DoDrawSpline(wxList *points) { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") ); - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; wxGraphicsPath path = m_graphicContext->CreatePath(); @@ -622,7 +607,7 @@ void wxGCDC::DoDrawPolygon( int n, wxPoint points[], if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) return; - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; bool closeIt = false; @@ -675,7 +660,7 @@ void wxGCDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") ); - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; // CMB: draw nothing if transformed w or h is 0 @@ -698,7 +683,7 @@ void wxGCDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") ); - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; if (radius < 0.0) @@ -708,6 +693,13 @@ void wxGCDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, if (w == 0 || h == 0) return; + if ( m_graphicContext->ShouldOffset() ) + { + // if we are offsetting the entire rectangle is moved 0.5, so the + // border line gets off by 1 + w -= 1; + h -= 1; + } m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius); } @@ -715,9 +707,16 @@ void wxGCDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") ); - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; + if ( m_graphicContext->ShouldOffset() ) + { + // if we are offsetting the entire rectangle is moved 0.5, so the + // border line gets off by 1 + w -= 1; + h -= 1; + } m_graphicContext->DrawEllipse(x,y,w,h); } @@ -728,11 +727,22 @@ bool wxGCDC::CanDrawBitmap() const bool wxGCDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, - wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool WXUNUSED(useMask), + wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask, + wxCoord xsrcMask, wxCoord ysrcMask ) +{ + return DoStretchBlit( xdest, ydest, width, height, + source, xsrc, ysrc, width, height, logical_func, useMask, + xsrcMask,ysrcMask ); +} + +bool wxGCDC::DoStretchBlit( + wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight, + wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight, + int logical_func , bool WXUNUSED(useMask), wxCoord xsrcMask, wxCoord ysrcMask ) { - wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") ); - wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") ); + wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") ); + wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") ); if ( logical_func == wxNO_OP ) return true; @@ -748,14 +758,27 @@ bool wxGCDC::DoBlit( ysrcMask = ysrc; } - wxRect subrect(source-> LogicalToDeviceX(xsrc),source-> LogicalToDeviceY(ysrc), - source-> LogicalToDeviceXRel(width),source-> LogicalToDeviceYRel(height)); + wxRect subrect(source->LogicalToDeviceX(xsrc), + source->LogicalToDeviceY(ysrc), + source->LogicalToDeviceXRel(srcWidth), + source->LogicalToDeviceYRel(srcHeight)); + + // if needed clip the subrect down to the size of the source DC + wxCoord sw, sh; + source->GetSize(&sw, &sh); + sw = source->LogicalToDeviceXRel(sw); + sh = source->LogicalToDeviceYRel(sh); + if (subrect.x + subrect.width > sw) + subrect.width = sw - subrect.x; + if (subrect.y + subrect.height > sh) + subrect.height = sh - subrect.y; wxBitmap blit = source->GetAsBitmap( &subrect ); if ( blit.Ok() ) { - m_graphicContext->DrawBitmap( blit, xdest , ydest , width , height ); + m_graphicContext->DrawBitmap( blit, xdest, ydest, + dstWidth, dstHeight); } else { @@ -773,7 +796,7 @@ void wxGCDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, if ( str.length() == 0 ) return; - if ( m_logicalFunction != wxCOPY ) + if ( !m_logicalFunctionSupported ) return; if ( m_backgroundMode == wxTRANSPARENT ) @@ -788,7 +811,8 @@ void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y) if ( str.length() == 0 ) return; - if ( m_logicalFunction != wxCOPY ) + + if ( !m_logicalFunctionSupported ) return; if ( m_backgroundMode == wxTRANSPARENT ) @@ -806,7 +830,7 @@ bool wxGCDC::CanGetTextExtent() const void wxGCDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height, wxCoord *descent, wxCoord *externalLeading , - wxFont *theFont ) const + const wxFont *theFont ) const { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );