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
);
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
95 // the application class
96 // ----------------------------------------------------------------------------
102 MyFrame
*frame
= new MyFrame("Minimal wxWindows App",
103 wxPoint(50, 50), wxSize(450, 340));
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
115 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
116 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
120 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
121 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
124 wxApp::s_macAboutMenuItemId
= Minimal_About
;
127 SetIcon(wxICON(mondrian
));
129 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
131 wxMenu
*helpMenu
= new wxMenu
;
132 helpMenu
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
134 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
136 wxMenuBar
*menuBar
= new wxMenuBar();
137 menuBar
->Append(menuFile
, "&File");
138 menuBar
->Append(helpMenu
, "&Help");
143 // create a status bar just for fun (by default with 1 pane only)
145 SetStatusText("Welcome to wxWindows!");
146 #endif // wxUSE_STATUSBAR
148 (void)new MyCanvas( this );
152 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
157 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
160 msg
.Printf( _T("This is the about dialog of the Erase sample.\n")
161 _T("Welcome to %s"), wxVERSION_STRING
);
163 wxMessageBox(msg
, "About Erase", wxOK
| wxICON_INFORMATION
, this);
167 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
168 EVT_PAINT( MyCanvas::OnPaint
)
169 EVT_ERASE_BACKGROUND( MyCanvas::OnEraseBackground
)
172 MyCanvas::MyCanvas( MyFrame
*parent
)
173 : wxScrolledWindow( parent
, -1, wxDefaultPosition
, wxDefaultSize
,
174 wxScrolledWindowStyle
|wxNO_FULL_REPAINT_ON_RESIZE
|wxSUNKEN_BORDER
)
176 SetScrollbars( 10, 10, 40, 100, 0, 0 );
179 void MyCanvas::OnPaint( wxPaintEvent
&event
)
185 wxRegionIterator
upd( GetUpdateRegion() );
188 wxLogDebug( "Paint: %d %d %d %d", upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
194 wxSize size
= GetSize();
195 wxSize client_size
= GetClientSize();
196 wxLogDebug( "size %d %d client_size %d %d", size
.x
, size
.y
, client_size
.x
, client_size
.y
);
200 dc
.SetPen( *wxWHITE_PEN
);
201 for (i
= 0; i
< 20; i
+= 2)
202 dc
.DrawLine( i
,i
, i
+100,i
);
204 dc
.SetPen( *wxWHITE_PEN
);
205 for (i
= 200; i
< 220; i
+= 2)
206 dc
.DrawLine( i
-200,i
, i
-100,i
);
208 wxRegion
region( 110, 110, 80, 80 );
209 wxRegion
hole( 130, 130, 40, 1 );
210 region
.Intersect( hole
);
211 dc
.SetClippingRegion( region
);
213 dc
.SetBrush( *wxRED_BRUSH
);
214 dc
.DrawRectangle( 100, 100, 200, 200 );
216 dc
.DestroyClippingRegion();
218 dc
.SetPen( *wxTRANSPARENT_PEN
);
220 wxRegion
strip( 110, 200, 30, 1 );
221 wxRegionIterator
it( strip
);
224 dc
.DrawRectangle( it
.GetX(), it
.GetY(), it
.GetWidth(), it
.GetHeight() );
229 void MyCanvas::OnEraseBackground( wxEraseEvent
&event
)