// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
+
// the application icon
-#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
- #include "mondrian.xpm"
+#if !defined(__WXMSW__) && !defined(__WXPM__)
+ #include "../sample.xpm"
#endif
// ----------------------------------------------------------------------------
void UseBuffer(bool useBuffer) { m_useBuffer = useBuffer; Refresh(); }
bool UsesBuffer() const { return m_useBuffer; }
+ void EraseBgInPaint(bool erase) { m_eraseBgInPaint = erase; Refresh(); }
+
private:
void OnPaint( wxPaintEvent &event );
void OnChar( wxKeyEvent &event );
// use wxMemoryDC in OnPaint()?
bool m_useBuffer;
+ // erase background in OnPaint()?
+ bool m_eraseBgInPaint;
+
DECLARE_EVENT_TABLE()
};
private:
void OnUseBuffer(wxCommandEvent& event);
+ void OnEraseBgInPaint(wxCommandEvent& event);
void OnChangeBgStyle(wxCommandEvent& event);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
{
// menu items
Erase_Menu_UseBuffer = 100,
+ Erase_Menu_EraseBgInPaint,
Erase_Menu_BgStyleErase,
Erase_Menu_BgStyleSystem,
Erase_Menu_BgStylePaint,
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
- EVT_MENU(Erase_Menu_UseBuffer, MyFrame::OnUseBuffer)
+ EVT_MENU(Erase_Menu_UseBuffer, MyFrame::OnUseBuffer)
+ EVT_MENU(Erase_Menu_EraseBgInPaint, MyFrame::OnEraseBgInPaint)
EVT_MENU_RANGE(Erase_Menu_BgStyleErase, Erase_Menu_BgStylePaint,
MyFrame::OnChangeBgStyle)
: wxFrame(NULL, wxID_ANY, "Erase sample",
wxPoint(50, 50), wxSize(450, 340))
{
- SetIcon(wxICON(mondrian));
+ SetIcon(wxICON(sample));
wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
menuFile->AppendCheckItem(Erase_Menu_UseBuffer, "&Use memory DC\tCtrl-M");
+ menuFile->AppendCheckItem(Erase_Menu_EraseBgInPaint,
+ "&Erase background in EVT_PAINT\tCtrl-R");
menuFile->AppendSeparator();
menuFile->AppendRadioItem(Erase_Menu_BgStyleErase,
"Use wxBG_STYLE_&ERASE\tCtrl-E");
m_canvas->UseBuffer(event.IsChecked());
}
+void MyFrame::OnEraseBgInPaint(wxCommandEvent& event)
+{
+ m_canvas->EraseBgInPaint(event.IsChecked());
+}
+
void MyFrame::OnChangeBgStyle(wxCommandEvent& event)
{
int style = wxBG_STYLE_ERASE + event.GetId() - Erase_Menu_BgStyleErase;
: wxScrolledWindow(parent, wxID_ANY)
{
m_useBuffer = false;
+ m_eraseBgInPaint = false;
SetScrollbars( 10, 10, 40, 100, 0, 0 );
- m_bitmap = wxBitmap( wxICON(mondrian) );
+ m_bitmap = wxBitmap( wxICON(sample) );
new wxStaticBitmap( this, wxID_ANY, m_bitmap, wxPoint(80,20) );
void MyCanvas::DoPaint(wxDC& dc)
{
+ if ( m_eraseBgInPaint )
+ {
+ dc.SetBackground(*wxLIGHT_GREY);
+ dc.Clear();
+
+ dc.DrawText("Background erased in OnPaint", 65, 110);
+ }
+ else if ( GetBackgroundStyle() == wxBG_STYLE_PAINT )
+ {
+ dc.SetTextForeground(*wxRED);
+ dc.DrawText("You must enable erasing background in OnPaint to avoid "
+ "display corruption", 65, 110);
+ }
+
dc.SetBrush( *wxBLACK_BRUSH );
dc.DrawRectangle( 10,10,60,50 );