X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8c6b0819ecb3f8c7a4b84869ee273dff82358159..538f284a44001ff8285eaafebcc384bf638b5d66:/samples/drawing/drawing.cpp diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index edb821c26b..bf1a09c7ed 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -149,7 +149,7 @@ public: #if wxUSE_GRAPHICS_CONTEXT void UseGraphicContext(bool use) { m_useContext = use; Refresh(); } #endif - template void Draw(T& dc); + void Draw(wxDC& dc); protected: enum DrawMode @@ -1487,26 +1487,47 @@ void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime) } } -#if TEST_CAIRO_EVERYWHERE -extern wxGraphicsRenderer* gCairoRenderer; -#endif - void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) { wxPaintDC pdc(this); Draw(pdc); } -template -void MyCanvas::Draw(T& pdc) +void MyCanvas::Draw(wxDC& pdc) { #if wxUSE_GRAPHICS_CONTEXT -#if TEST_CAIRO_EVERYWHERE wxGCDC gdc; - gdc.SetGraphicsContext( gCairoRenderer->CreateContext( pdc ) ); + wxGraphicsRenderer* const renderer = wxGraphicsRenderer:: +#if TEST_CAIRO_EVERYWHERE + GetCairoRenderer() #else - wxGCDC gdc( pdc ) ; + GetDefaultRenderer() #endif + ; + + wxGraphicsContext* context; + if ( wxPaintDC *paintdc = wxDynamicCast(&pdc, wxPaintDC) ) + { + context = renderer->CreateContext(*paintdc); + } + else if ( wxMemoryDC *memdc = wxDynamicCast(&pdc, wxMemoryDC) ) + { + context = renderer->CreateContext(*memdc); + } +#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH) + else if ( wxMetafileDC *metadc = wxDynamicCast(&pdc, wxMetafileDC) ) + { + context = renderer->CreateContext(*metadc); + } +#endif + else + { + wxFAIL_MSG( "Unknown wxDC kind" ); + return; + } + + gdc.SetGraphicsContext(context); + wxDC &dc = m_useContext ? (wxDC&) gdc : (wxDC&) pdc ; #else wxDC &dc = pdc ;