Allow selecting wxGraphicsRenderer to use in the drawing sample.
In particular, allow switching between GDI+ and Direct2D under Windows, which is very convenient for comparing the rendering results. This can also be useful when using Cairo. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77692 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -84,51 +84,7 @@ protected:
|
|||||||
bool LoadImages();
|
bool LoadImages();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyCanvas;
|
class MyFrame;
|
||||||
|
|
||||||
// Define a new frame type: this is going to be our main frame
|
|
||||||
class MyFrame : public wxFrame
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// ctor(s)
|
|
||||||
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
|
||||||
|
|
||||||
// event handlers (these functions should _not_ be virtual)
|
|
||||||
void OnQuit(wxCommandEvent& event);
|
|
||||||
void OnAbout(wxCommandEvent& event);
|
|
||||||
void OnClip(wxCommandEvent& event);
|
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
|
||||||
void OnGraphicContext(wxCommandEvent& event);
|
|
||||||
#endif
|
|
||||||
void OnBuffer(wxCommandEvent& event);
|
|
||||||
void OnCopy(wxCommandEvent& event);
|
|
||||||
void OnSave(wxCommandEvent& event);
|
|
||||||
void OnShow(wxCommandEvent &event);
|
|
||||||
void OnOption(wxCommandEvent &event);
|
|
||||||
|
|
||||||
#if wxUSE_COLOURDLG
|
|
||||||
wxColour SelectColour();
|
|
||||||
#endif // wxUSE_COLOURDLG
|
|
||||||
void PrepareDC(wxDC& dc) wxOVERRIDE;
|
|
||||||
|
|
||||||
int m_backgroundMode;
|
|
||||||
int m_textureBackground;
|
|
||||||
wxMappingMode m_mapMode;
|
|
||||||
double m_xUserScale;
|
|
||||||
double m_yUserScale;
|
|
||||||
int m_xLogicalOrigin;
|
|
||||||
int m_yLogicalOrigin;
|
|
||||||
bool m_xAxisReversed,
|
|
||||||
m_yAxisReversed;
|
|
||||||
wxColour m_colourForeground, // these are _text_ colours
|
|
||||||
m_colourBackground;
|
|
||||||
wxBrush m_backgroundBrush;
|
|
||||||
MyCanvas *m_canvas;
|
|
||||||
|
|
||||||
private:
|
|
||||||
// any class wishing to process wxWidgets events must use this macro
|
|
||||||
wxDECLARE_EVENT_TABLE();
|
|
||||||
};
|
|
||||||
|
|
||||||
// define a scrollable canvas for drawing onto
|
// define a scrollable canvas for drawing onto
|
||||||
class MyCanvas: public wxScrolledWindow
|
class MyCanvas: public wxScrolledWindow
|
||||||
@@ -146,7 +102,8 @@ public:
|
|||||||
// set or remove the clipping region
|
// set or remove the clipping region
|
||||||
void Clip(bool clip) { m_clip = clip; Refresh(); }
|
void Clip(bool clip) { m_clip = clip; Refresh(); }
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
void UseGraphicContext(bool use) { m_useContext = use; Refresh(); }
|
void UseGraphicRenderer(wxGraphicsRenderer* renderer)
|
||||||
|
{ m_renderer = renderer; Refresh(); }
|
||||||
#endif
|
#endif
|
||||||
void UseBuffer(bool use) { m_useBuffer = use; Refresh(); }
|
void UseBuffer(bool use) { m_useBuffer = use; Refresh(); }
|
||||||
|
|
||||||
@@ -189,13 +146,88 @@ private:
|
|||||||
wxPoint m_anchorpoint;
|
wxPoint m_anchorpoint;
|
||||||
wxPoint m_currentpoint;
|
wxPoint m_currentpoint;
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
bool m_useContext ;
|
wxGraphicsRenderer* m_renderer;
|
||||||
#endif
|
#endif
|
||||||
bool m_useBuffer;
|
bool m_useBuffer;
|
||||||
|
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Define a new frame type: this is going to be our main frame
|
||||||
|
class MyFrame : public wxFrame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// ctor(s)
|
||||||
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||||
|
|
||||||
|
// event handlers (these functions should _not_ be virtual)
|
||||||
|
void OnQuit(wxCommandEvent& event);
|
||||||
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
void OnClip(wxCommandEvent& event);
|
||||||
|
|
||||||
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
|
void OnGraphicContextNone(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_canvas->UseGraphicRenderer(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnGraphicContextDefault(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetDefaultRenderer());
|
||||||
|
}
|
||||||
|
#if wxUSE_CAIRO
|
||||||
|
void OnGraphicContextCairo(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetCairoRenderer());
|
||||||
|
}
|
||||||
|
#endif // wxUSE_CAIRO
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
#if wxUSE_GRAPHICS_GDIPLUS
|
||||||
|
void OnGraphicContextGDIPlus(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetGDIPlusRenderer());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if wxUSE_GRAPHICS_DIRECT2D
|
||||||
|
void OnGraphicContextDirect2D(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetDirect2DRenderer());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // __WXMSW__
|
||||||
|
#endif // wxUSE_GRAPHICS_CONTEXT
|
||||||
|
|
||||||
|
void OnBuffer(wxCommandEvent& event);
|
||||||
|
void OnCopy(wxCommandEvent& event);
|
||||||
|
void OnSave(wxCommandEvent& event);
|
||||||
|
void OnShow(wxCommandEvent &event);
|
||||||
|
void OnOption(wxCommandEvent &event);
|
||||||
|
|
||||||
|
#if wxUSE_COLOURDLG
|
||||||
|
wxColour SelectColour();
|
||||||
|
#endif // wxUSE_COLOURDLG
|
||||||
|
void PrepareDC(wxDC& dc) wxOVERRIDE;
|
||||||
|
|
||||||
|
int m_backgroundMode;
|
||||||
|
int m_textureBackground;
|
||||||
|
wxMappingMode m_mapMode;
|
||||||
|
double m_xUserScale;
|
||||||
|
double m_yUserScale;
|
||||||
|
int m_xLogicalOrigin;
|
||||||
|
int m_yLogicalOrigin;
|
||||||
|
bool m_xAxisReversed,
|
||||||
|
m_yAxisReversed;
|
||||||
|
wxColour m_colourForeground, // these are _text_ colours
|
||||||
|
m_colourBackground;
|
||||||
|
wxBrush m_backgroundBrush;
|
||||||
|
MyCanvas *m_canvas;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// any class wishing to process wxWidgets events must use this macro
|
||||||
|
wxDECLARE_EVENT_TABLE();
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -226,10 +258,22 @@ enum
|
|||||||
File_ShowGradients,
|
File_ShowGradients,
|
||||||
MenuShow_Last = File_ShowGradients,
|
MenuShow_Last = File_ShowGradients,
|
||||||
|
|
||||||
File_Clip,
|
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
File_GraphicContext,
|
File_DC,
|
||||||
|
File_GC_Default,
|
||||||
|
#if wxUSE_CAIRO
|
||||||
|
File_GC_Cairo,
|
||||||
|
#endif // wxUSE_CAIRO
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
#if wxUSE_GRAPHICS_GDIPLUS
|
||||||
|
File_GC_GDIPlus,
|
||||||
#endif
|
#endif
|
||||||
|
#if wxUSE_GRAPHICS_DIRECT2D
|
||||||
|
File_GC_Direct2D,
|
||||||
|
#endif
|
||||||
|
#endif // __WXMSW__
|
||||||
|
#endif // wxUSE_GRAPHICS_CONTEXT
|
||||||
|
File_Clip,
|
||||||
File_Buffer,
|
File_Buffer,
|
||||||
File_Copy,
|
File_Copy,
|
||||||
File_Save,
|
File_Save,
|
||||||
@@ -412,7 +456,7 @@ MyCanvas::MyCanvas(MyFrame *parent)
|
|||||||
m_clip = false;
|
m_clip = false;
|
||||||
m_rubberBand = false;
|
m_rubberBand = false;
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
m_useContext = false;
|
m_renderer = NULL;
|
||||||
#endif
|
#endif
|
||||||
m_useBuffer = false;
|
m_useBuffer = false;
|
||||||
}
|
}
|
||||||
@@ -1323,7 +1367,7 @@ void MyCanvas::DrawGradients(wxDC& dc)
|
|||||||
dc.GradientFillLinear(r4, *wxBLACK, *wxGREEN, wxWEST);
|
dc.GradientFillLinear(r4, *wxBLACK, *wxGREEN, wxWEST);
|
||||||
|
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
if (m_useContext)
|
if (m_renderer)
|
||||||
{
|
{
|
||||||
wxGCDC &gdc = (wxGCDC&)dc;
|
wxGCDC &gdc = (wxGCDC&)dc;
|
||||||
wxGraphicsContext *gc = gdc.GetGraphicsContext();
|
wxGraphicsContext *gc = gdc.GetGraphicsContext();
|
||||||
@@ -1540,29 +1584,22 @@ void MyCanvas::Draw(wxDC& pdc)
|
|||||||
{
|
{
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
wxGCDC gdc;
|
wxGCDC gdc;
|
||||||
wxGraphicsRenderer* const renderer = wxGraphicsRenderer::
|
|
||||||
#if TEST_CAIRO_EVERYWHERE
|
|
||||||
GetCairoRenderer()
|
|
||||||
#else
|
|
||||||
GetDefaultRenderer()
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
|
|
||||||
if ( m_useContext )
|
if ( m_renderer )
|
||||||
{
|
{
|
||||||
wxGraphicsContext* context;
|
wxGraphicsContext* context;
|
||||||
if ( wxPaintDC *paintdc = wxDynamicCast(&pdc, wxPaintDC) )
|
if ( wxPaintDC *paintdc = wxDynamicCast(&pdc, wxPaintDC) )
|
||||||
{
|
{
|
||||||
context = renderer->CreateContext(*paintdc);
|
context = m_renderer->CreateContext(*paintdc);
|
||||||
}
|
}
|
||||||
else if ( wxMemoryDC *memdc = wxDynamicCast(&pdc, wxMemoryDC) )
|
else if ( wxMemoryDC *memdc = wxDynamicCast(&pdc, wxMemoryDC) )
|
||||||
{
|
{
|
||||||
context = renderer->CreateContext(*memdc);
|
context = m_renderer->CreateContext(*memdc);
|
||||||
}
|
}
|
||||||
#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
|
#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
|
||||||
else if ( wxMetafileDC *metadc = wxDynamicCast(&pdc, wxMetafileDC) )
|
else if ( wxMetafileDC *metadc = wxDynamicCast(&pdc, wxMetafileDC) )
|
||||||
{
|
{
|
||||||
context = renderer->CreateContext(*metadc);
|
context = m_renderer->CreateContext(*metadc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
@@ -1574,7 +1611,7 @@ void MyCanvas::Draw(wxDC& pdc)
|
|||||||
gdc.SetGraphicsContext(context);
|
gdc.SetGraphicsContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDC &dc = m_useContext ? (wxDC&) gdc : (wxDC&) pdc ;
|
wxDC &dc = m_renderer ? (wxDC&) gdc : (wxDC&) pdc ;
|
||||||
#else
|
#else
|
||||||
wxDC &dc = pdc ;
|
wxDC &dc = pdc ;
|
||||||
#endif
|
#endif
|
||||||
@@ -1767,9 +1804,23 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU (File_Quit, MyFrame::OnQuit)
|
EVT_MENU (File_Quit, MyFrame::OnQuit)
|
||||||
EVT_MENU (File_About, MyFrame::OnAbout)
|
EVT_MENU (File_About, MyFrame::OnAbout)
|
||||||
EVT_MENU (File_Clip, MyFrame::OnClip)
|
EVT_MENU (File_Clip, MyFrame::OnClip)
|
||||||
|
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
EVT_MENU (File_GraphicContext, MyFrame::OnGraphicContext)
|
EVT_MENU (File_DC, MyFrame::OnGraphicContextNone)
|
||||||
|
EVT_MENU (File_GC_Default, MyFrame::OnGraphicContextDefault)
|
||||||
|
#if wxUSE_CAIRO
|
||||||
|
EVT_MENU (File_GC_Cairo, MyFrame::OnGraphicContextCairo)
|
||||||
|
#endif // wxUSE_CAIRO
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
#if wxUSE_GRAPHICS_GDIPLUS
|
||||||
|
EVT_MENU (File_GC_GDIPlus, MyFrame::OnGraphicContextGDIPlus)
|
||||||
#endif
|
#endif
|
||||||
|
#if wxUSE_GRAPHICS_DIRECT2D
|
||||||
|
EVT_MENU (File_GC_Direct2D, MyFrame::OnGraphicContextDirect2D)
|
||||||
|
#endif
|
||||||
|
#endif // __WXMSW__
|
||||||
|
#endif // wxUSE_GRAPHICS_CONTEXT
|
||||||
|
|
||||||
EVT_MENU (File_Buffer, MyFrame::OnBuffer)
|
EVT_MENU (File_Buffer, MyFrame::OnBuffer)
|
||||||
EVT_MENU (File_Copy, MyFrame::OnCopy)
|
EVT_MENU (File_Copy, MyFrame::OnCopy)
|
||||||
EVT_MENU (File_Save, MyFrame::OnSave)
|
EVT_MENU (File_Save, MyFrame::OnSave)
|
||||||
@@ -1808,10 +1859,23 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuFile = new wxMenu;
|
||||||
menuFile->AppendCheckItem(File_Clip, wxT("&Clip\tCtrl-C"), wxT("Clip/unclip drawing"));
|
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
#if wxUSE_GRAPHICS_CONTEXT
|
||||||
menuFile->AppendCheckItem(File_GraphicContext, wxT("&Use GraphicContext\tCtrl-Y"), wxT("Use GraphicContext"));
|
menuFile->AppendRadioItem(File_DC, "Use wx&DC\tShift-Ctrl-Y");
|
||||||
|
menuFile->AppendRadioItem(File_GC_Default, "Use default wx&GraphicContext\tCtrl-Y");
|
||||||
|
#if wxUSE_CAIRO
|
||||||
|
menuFile->AppendRadioItem(File_GC_Cairo, "Use &Cairo\tCtrl-O");
|
||||||
|
#endif // wxUSE_CAIRO
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
#if wxUSE_GRAPHICS_GDIPLUS
|
||||||
|
menuFile->AppendRadioItem(File_GC_GDIPlus, "Use &GDI+\tCtrl-+");
|
||||||
#endif
|
#endif
|
||||||
|
#if wxUSE_GRAPHICS_DIRECT2D
|
||||||
|
menuFile->AppendRadioItem(File_GC_Direct2D, "Use &Direct2D\tCtrl-2");
|
||||||
|
#endif
|
||||||
|
#endif // __WXMSW__
|
||||||
|
#endif // wxUSE_GRAPHICS_CONTEXT
|
||||||
|
menuFile->AppendSeparator();
|
||||||
|
menuFile->AppendCheckItem(File_Clip, wxT("&Clip\tCtrl-C"), wxT("Clip/unclip drawing"));
|
||||||
menuFile->AppendCheckItem(File_Buffer, wxT("&Use wx&BufferedPaintDC\tCtrl-Z"), wxT("Buffer painting"));
|
menuFile->AppendCheckItem(File_Buffer, wxT("&Use wx&BufferedPaintDC\tCtrl-Z"), wxT("Buffer painting"));
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
|
#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
|
||||||
@@ -1919,13 +1983,6 @@ void MyFrame::OnClip(wxCommandEvent& event)
|
|||||||
m_canvas->Clip(event.IsChecked());
|
m_canvas->Clip(event.IsChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_GRAPHICS_CONTEXT
|
|
||||||
void MyFrame::OnGraphicContext(wxCommandEvent& event)
|
|
||||||
{
|
|
||||||
m_canvas->UseGraphicContext(event.IsChecked());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void MyFrame::OnBuffer(wxCommandEvent& event)
|
void MyFrame::OnBuffer(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
m_canvas->UseBuffer(event.IsChecked());
|
m_canvas->UseBuffer(event.IsChecked());
|
||||||
|
Reference in New Issue
Block a user