+class MyCanvas : public wxScrolledWindow
+{
+public:
+ MyCanvas(wxFrame *parent);
+
+ void UseBuffer(bool useBuffer) { m_useBuffer = useBuffer; Refresh(); }
+ bool UsesBuffer() const { return m_useBuffer; }
+
+ void UseBgBitmap(bool useBgBmp)
+ {
+ m_useBgBmp = useBgBmp;
+ SetBackgroundBitmap(m_useBgBmp ? GetBgBitmap() : wxBitmap());
+
+ Refresh();
+ }
+
+ void EraseBgInPaint(bool erase) { m_eraseBgInPaint = erase; Refresh(); }
+
+private:
+ void OnPaint( wxPaintEvent &event );
+ void OnEraseBackground( wxEraseEvent &event );
+
+ void DoPaint(wxDC& dc);
+
+ // Create an easily recognizable background bitmap.
+ static wxBitmap GetBgBitmap()
+ {
+ static const int BMP_SIZE = 40;
+
+ wxBitmap bmp(BMP_SIZE, BMP_SIZE);
+ wxMemoryDC dc(bmp);
+ dc.SetBackground(*wxCYAN);
+ dc.Clear();
+
+ dc.SetPen(*wxBLUE_PEN);
+ dc.DrawLine(0, BMP_SIZE/2, BMP_SIZE/2, 0);
+ dc.DrawLine(BMP_SIZE/2, 0, BMP_SIZE, BMP_SIZE/2);
+ dc.DrawLine(BMP_SIZE, BMP_SIZE/2, BMP_SIZE/2, BMP_SIZE);
+ dc.DrawLine(BMP_SIZE/2, BMP_SIZE, 0, BMP_SIZE/2);
+
+ return bmp;
+ }
+
+ wxBitmap m_bitmap;
+
+ // use wxMemoryDC in OnPaint()?
+ bool m_useBuffer;
+
+ // use background bitmap?
+ bool m_useBgBmp;
+
+ // erase background in OnPaint()?
+ bool m_eraseBgInPaint;
+
+
+ DECLARE_EVENT_TABLE()
+};
+