]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/erase/erase.cpp
Large image-loading speedup and small attribute-loading speedup
[wxWidgets.git] / samples / erase / erase.cpp
index cc6ca65d4fe51acd5cf9b4552bdc408f5cef0265..d603a93cefca80e56db8a84ff4d2a4756e36a5f3 100644 (file)
 // ----------------------------------------------------------------------------
 // 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
 
 // ----------------------------------------------------------------------------
@@ -59,6 +60,8 @@ public:
     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 );
@@ -73,6 +76,9 @@ private:
     // use wxMemoryDC in OnPaint()?
     bool m_useBuffer;
 
+    // erase background in OnPaint()?
+    bool m_eraseBgInPaint;
+
 
     DECLARE_EVENT_TABLE()
 };
@@ -84,6 +90,7 @@ public:
 
 private:
     void OnUseBuffer(wxCommandEvent& event);
+    void OnEraseBgInPaint(wxCommandEvent& event);
     void OnChangeBgStyle(wxCommandEvent& event);
     void OnQuit(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
@@ -113,6 +120,7 @@ enum
 {
     // menu items
     Erase_Menu_UseBuffer = 100,
+    Erase_Menu_EraseBgInPaint,
     Erase_Menu_BgStyleErase,
     Erase_Menu_BgStyleSystem,
     Erase_Menu_BgStylePaint,
@@ -144,7 +152,8 @@ bool MyApp::OnInit()
 // ----------------------------------------------------------------------------
 
 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)
 
@@ -161,10 +170,12 @@ MyFrame::MyFrame()
        : 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");
@@ -194,6 +205,11 @@ void MyFrame::OnUseBuffer(wxCommandEvent& event)
     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;
@@ -233,10 +249,11 @@ MyCanvas::MyCanvas(wxFrame *parent)
         : 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) );
 
@@ -269,6 +286,20 @@ void MyCanvas::OnChar( wxKeyEvent &event )
 
 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 );