1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Erase wxWindows sample
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "erase.cpp"
22 #pragma interface "erase.cpp"
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers)
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
41 // the application icon
42 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
43 #include "mondrian.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 class MyApp
: public wxApp
53 virtual bool OnInit();
57 class MyFrame
: public wxFrame
60 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
62 void OnQuit(wxCommandEvent
& event
);
63 void OnAbout(wxCommandEvent
& event
);
70 class MyCanvas
: public wxScrolledWindow
73 MyCanvas( MyFrame
*parent
);
75 void OnPaint( wxPaintEvent
&event
);
76 void OnEraseBackground( wxEraseEvent
&event
);
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
97 // the application class
98 // ----------------------------------------------------------------------------
104 MyFrame
*frame
= new MyFrame("Minimal wxWindows App",
105 wxPoint(50, 50), wxSize(450, 340));
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
117 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
118 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
122 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
123 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
126 wxApp::s_macAboutMenuItemId
= Minimal_About
;
129 SetIcon(wxICON(mondrian
));
131 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
133 wxMenu
*helpMenu
= new wxMenu
;
134 helpMenu
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
136 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
138 wxMenuBar
*menuBar
= new wxMenuBar();
139 menuBar
->Append(menuFile
, "&File");
140 menuBar
->Append(helpMenu
, "&Help");
145 // create a status bar just for fun (by default with 1 pane only)
147 SetStatusText("Welcome to wxWindows!");
148 #endif // wxUSE_STATUSBAR
150 (void)new MyCanvas( this );
154 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
159 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
162 msg
.Printf( _T("This is the about dialog of the Erase sample.\n")
163 _T("Welcome to %s"), wxVERSION_STRING
);
165 wxMessageBox(msg
, "About Erase", wxOK
| wxICON_INFORMATION
, this);
169 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
170 EVT_PAINT( MyCanvas::OnPaint
)
171 EVT_ERASE_BACKGROUND( MyCanvas::OnEraseBackground
)
174 MyCanvas::MyCanvas( MyFrame
*parent
)
175 : wxScrolledWindow( parent
, -1, wxDefaultPosition
, wxDefaultSize
,
176 wxScrolledWindowStyle
|wxNO_FULL_REPAINT_ON_RESIZE
|wxSUNKEN_BORDER
)
178 SetScrollbars( 10, 10, 40, 100, 0, 0 );
180 m_bitmap
= wxBitmap( mondrian_xpm
);
182 new wxStaticBitmap( this, -1, m_bitmap
, wxPoint(80,20) );
185 void MyCanvas::OnPaint( wxPaintEvent
&event
)
190 dc
.SetBrush( *wxBLACK_BRUSH
);
191 dc
.DrawRectangle( 0,0,200,50 );
193 dc
.DrawBitmap( m_bitmap
, 10, 20, TRUE
);
196 wxRegionIterator
upd( GetUpdateRegion() );
199 wxLogDebug( "Paint: %d %d %d %d", upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
205 wxSize size
= GetSize();
206 wxSize client_size
= GetClientSize();
207 wxLogDebug( "size %d %d client_size %d %d", size
.x
, size
.y
, client_size
.x
, client_size
.y
);
211 dc
.SetPen( *wxWHITE_PEN
);
212 for (i
= 0; i
< 20; i
+= 2)
213 dc
.DrawLine( i
,i
, i
+100,i
);
215 dc
.SetPen( *wxWHITE_PEN
);
216 for (i
= 200; i
< 220; i
+= 2)
217 dc
.DrawLine( i
-200,i
, i
-100,i
);
219 wxRegion
region( 110, 110, 80, 80 );
220 wxRegion
hole( 130, 130, 40, 1 );
221 region
.Intersect( hole
);
222 dc
.SetClippingRegion( region
);
224 dc
.SetBrush( *wxRED_BRUSH
);
225 dc
.DrawRectangle( 100, 100, 200, 200 );
227 dc
.DestroyClippingRegion();
229 dc
.SetPen( *wxTRANSPARENT_PEN
);
231 wxRegion
strip( 110, 200, 30, 1 );
232 wxRegionIterator
it( strip
);
235 dc
.DrawRectangle( it
.GetX(), it
.GetY(), it
.GetWidth(), it
.GetHeight() );
240 void MyCanvas::OnEraseBackground( wxEraseEvent
&event
)