#include "wx/region.h"
#endif
-#ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
- #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
-#endif
-
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
{
m_matrixOriginal = m_graphicContext->GetTransform();
m_ok = true;
+ // apply the stored transformations to the passed in context
+ ComputeScaleAndOrigin();
+ m_graphicContext->SetFont( m_font , m_textForegroundColour );
+ m_graphicContext->SetPen( m_pen );
+ m_graphicContext->SetBrush( m_brush);
}
}
{
Init();
SetGraphicsContext( wxGraphicsContext::Create(dc) );
- if ( dc.GetFont().Ok())
- m_graphicContext->SetFont( m_graphicContext->CreateFont(dc.GetFont(),dc.GetTextForeground()));
- if ( dc.GetPen().Ok())
- m_graphicContext->SetPen( m_graphicContext->CreatePen(dc.GetPen()));
- if ( dc.GetBrush().Ok())
- m_graphicContext->SetBrush( m_graphicContext->CreateBrush(dc.GetBrush()));
}
+#ifdef __WXMSW__
+wxGCDC::wxGCDC(const wxMemoryDC& dc)
+{
+ Init();
+ SetGraphicsContext( wxGraphicsContext::Create(dc) );
+}
+#endif
+
void wxGCDC::Init()
{
m_ok = false;
m_brush = *wxWHITE_BRUSH;
m_graphicContext = NULL;
+ m_logicalFunctionSupported = true;
}
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
wxCHECK_RET( bmp.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
- m_graphicContext->DrawBitmap( bmp, x , y , bmp.GetWidth() , bmp.GetHeight() );
+ if ( bmp.GetDepth() == 1 )
+ {
+ m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
+ m_graphicContext->SetBrush( wxBrush( m_textBackgroundColour , wxSOLID ) );
+ m_graphicContext->DrawRectangle( x , y , bmp.GetWidth() , bmp.GetHeight() );
+ m_graphicContext->SetBrush( wxBrush( m_textForegroundColour , wxSOLID ) );
+ m_graphicContext->DrawBitmap( bmp, x , y , bmp.GetWidth() , bmp.GetHeight() );
+ m_graphicContext->SetBrush( m_graphicContext->CreateBrush(m_brush));
+ m_graphicContext->SetPen( m_graphicContext->CreatePen(m_pen));
+ }
+ else
+ m_graphicContext->DrawBitmap( bmp, x , y , bmp.GetWidth() , bmp.GetHeight() );
}
void wxGCDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion ®ion )
{
+ // region is in device coordinates
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
if (region.Empty())
return;
}
+ wxRegion logRegion( region );
wxCoord x, y, w, h;
- region.GetBox( x, y, w, h );
- m_graphicContext->Clip( region );
+ logRegion.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
+ logRegion.GetBox( x, y, w, h );
+
+ m_graphicContext->Clip( logRegion );
if ( m_clipping )
{
m_clipX1 = wxMax( m_clipX1, x );
m_scaleX = m_logicalScaleX * m_userScaleX;
m_scaleY = m_logicalScaleY * m_userScaleY;
- m_matrixCurrent = m_graphicContext->CreateMatrix();
- m_matrixCurrent.Translate( m_deviceOriginX, m_deviceOriginY );
- m_matrixCurrent.Scale( m_scaleX, m_scaleY );
- // the logical origin sets the origin to have new coordinates
- m_matrixCurrent.Translate( -m_logicalOriginX, -m_logicalOriginY );
-
- m_graphicContext->SetTransform( m_matrixOriginal );
- m_graphicContext->ConcatTransform( m_matrixCurrent );
+ if ( m_graphicContext )
+ {
+ m_matrixCurrent = m_graphicContext->CreateMatrix();
+ m_matrixCurrent.Translate( m_deviceOriginX, m_deviceOriginY );
+ m_matrixCurrent.Scale( m_scaleX, m_scaleY );
+ // the logical origin sets the origin to have new coordinates
+ m_matrixCurrent.Translate( -m_logicalOriginX, -m_logicalOriginY );
+
+ m_graphicContext->SetTransform( m_matrixOriginal );
+ m_graphicContext->ConcatTransform( m_matrixCurrent );
+ }
}
void wxGCDC::SetPalette( const wxPalette& WXUNUSED(palette) )
m_graphicContext->SetBrush( m_brush );
}
}
-
+
void wxGCDC::SetBackground( const wxBrush &brush )
{
if (m_backgroundBrush == brush)
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),
{
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);
{
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
int w = 0, h = 0;
{
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
double dx = x1 - xc;
wxGraphicsPath path = m_graphicContext->CreatePath();
if ( fill && ((x1!=x2)||(y1!=y2)) )
path.MoveToPoint( xc, yc );
- path.AddArc( xc, yc , rad , DegToRad(sa) , DegToRad(ea), false );
+ // since these angles (ea,sa) are measured counter-clockwise, we invert them to
+ // get clockwise angles
+ path.AddArc( xc, yc , rad , DegToRad(-sa) , DegToRad(-ea), false );
if ( fill && ((x1!=x2)||(y1!=y2)) )
path.AddLineToPoint( xc, yc );
m_graphicContext->DrawPath(path);
{
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
bool fill = m_brush.GetStyle() != wxTRANSPARENT;
{
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)
{
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
wxGraphicsPath path = m_graphicContext->CreatePath();
if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) )
return;
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
bool closeIt = false;
{
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
{
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
if (radius < 0.0)
{
wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
m_graphicContext->DrawEllipse(x,y,w,h);
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(width),
+ source->LogicalToDeviceYRel(height));
+
+ // 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,
+ wxMin(width, blit.GetWidth()),
+ wxMin(height, blit.GetHeight()));
}
else
{
if ( str.length() == 0 )
return;
- if ( m_logicalFunction != wxCOPY )
+ if ( !m_logicalFunctionSupported )
return;
- m_graphicContext->DrawText( str, x ,y , DegToRad(angle ));
+ if ( m_backgroundMode == wxTRANSPARENT )
+ m_graphicContext->DrawText( str, x ,y , DegToRad(angle ));
+ else
+ m_graphicContext->DrawText( str, x ,y , DegToRad(angle ), m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
}
void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y)
if ( str.length() == 0 )
return;
- if ( m_logicalFunction != wxCOPY )
+
+ if ( !m_logicalFunctionSupported )
return;
- m_graphicContext->DrawText( str, x ,y);
+ if ( m_backgroundMode == wxTRANSPARENT )
+ m_graphicContext->DrawText( str, x ,y);
+ else
+ m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
}
bool wxGCDC::CanGetTextExtent() const