X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/914fd3f1e5b3a2be1b1d9a551e462f7ba717af58..a4609ab847819b47c996674420871f4514d50625:/src/common/dcgraph.cpp diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index be08d5b29c..fc1a6a89e7 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -3,7 +3,7 @@ // Purpose: graphics context methods common to all platforms // Author: Stefan Csomor // Modified by: -// Created: +// Created: // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence @@ -27,6 +27,10 @@ #include "wx/region.h" #endif +#ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES + #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0 +#endif + //----------------------------------------------------------------------------- // constants //----------------------------------------------------------------------------- @@ -58,13 +62,18 @@ wxGCDC::wxGCDC() } void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx ) -{ +{ delete m_graphicContext; m_graphicContext = ctx; if ( m_graphicContext ) { 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); } } @@ -72,14 +81,16 @@ wxGCDC::wxGCDC(const wxWindowDC& dc) { 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; @@ -105,7 +116,18 @@ void wxGCDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool WXUNU 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 ) @@ -144,6 +166,7 @@ void wxGCDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) { + // region is in device coordinates wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") ); if (region.Empty()) @@ -152,10 +175,13 @@ void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) 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 ); @@ -294,13 +320,17 @@ void wxGCDC::ComputeScaleAndOrigin() 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 ); - 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) ) @@ -462,7 +492,9 @@ void wxGCDC::DoDrawArc( wxCoord x1, wxCoord y1, 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); @@ -701,7 +733,7 @@ bool wxGCDC::DoBlit( { wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") ); wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") ); - + if ( logical_func == wxNO_OP ) return true; else if ( logical_func != wxCOPY ) @@ -718,9 +750,9 @@ bool wxGCDC::DoBlit( wxRect subrect(source-> LogicalToDeviceX(xsrc),source-> LogicalToDeviceY(ysrc), source-> LogicalToDeviceXRel(width),source-> LogicalToDeviceYRel(height)); - + wxBitmap blit = source->GetAsBitmap( &subrect ); - + if ( blit.Ok() ) { m_graphicContext->DrawBitmap( blit, xdest , ydest , width , height ); @@ -744,7 +776,10 @@ void wxGCDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, if ( m_logicalFunction != wxCOPY ) 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) @@ -756,7 +791,10 @@ void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y) if ( m_logicalFunction != wxCOPY ) 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 @@ -782,13 +820,13 @@ void wxGCDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *heig m_graphicContext->GetTextExtent( str, &w, &h, &d, &e ); if ( height ) - *height = h; + *height = (wxCoord)h; if ( descent ) - *descent = d; + *descent = (wxCoord)d; if ( externalLeading ) - *externalLeading =e; + *externalLeading = (wxCoord)e; if ( width ) - *width = w; + *width = (wxCoord)w; if ( theFont ) { @@ -837,7 +875,7 @@ void wxGCDC::Clear(void) wxPen p = *wxTRANSPARENT_PEN; m_graphicContext->SetPen( p ); DoDrawRectangle( 0, 0, 32000 , 32000 ); - m_graphicContext->SetPen( m_pen ); + m_graphicContext->SetPen( m_pen ); m_graphicContext->SetBrush( m_brush ); }