]>
Commit | Line | Data |
---|---|---|
33611ebb RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: erase.cpp | |
3 | // Purpose: Erase wxWindows sample | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robert Roebling | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
4d2c67a9 JS |
21 | #pragma implementation "erase.cpp" |
22 | #pragma interface "erase.cpp" | |
33611ebb RR |
23 | #endif |
24 | ||
25 | // For compilers that support precompilation, includes "wx/wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
29 | #pragma hdrstop | |
30 | #endif | |
31 | ||
32 | // for all others, include the necessary headers (this file is usually all you | |
33 | // need because it includes almost all "standard" wxWindows headers) | |
34 | #ifndef WX_PRECOMP | |
35 | #include "wx/wx.h" | |
36 | #endif | |
37 | ||
38 | // ---------------------------------------------------------------------------- | |
39 | // resources | |
40 | // ---------------------------------------------------------------------------- | |
41 | // the application icon | |
f566b4fe | 42 | #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__) |
33611ebb RR |
43 | #include "mondrian.xpm" |
44 | #endif | |
45 | ||
46 | // ---------------------------------------------------------------------------- | |
47 | // private classes | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | class MyApp : public wxApp | |
51 | { | |
52 | public: | |
53 | virtual bool OnInit(); | |
54 | }; | |
55 | ||
56 | ||
57 | class MyFrame : public wxFrame | |
58 | { | |
59 | public: | |
60 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
61 | ||
62 | void OnQuit(wxCommandEvent& event); | |
63 | void OnAbout(wxCommandEvent& event); | |
64 | ||
65 | private: | |
66 | DECLARE_EVENT_TABLE() | |
67 | }; | |
68 | ||
69 | ||
70 | class MyCanvas : public wxScrolledWindow | |
71 | { | |
72 | public: | |
73 | MyCanvas( MyFrame *parent ); | |
74 | ||
75 | void OnPaint( wxPaintEvent &event ); | |
76 | void OnEraseBackground( wxEraseEvent &event ); | |
77 | ||
78 | private: | |
79 | DECLARE_EVENT_TABLE() | |
80 | }; | |
81 | ||
82 | // ---------------------------------------------------------------------------- | |
83 | // constants | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | enum | |
87 | { | |
88 | // menu items | |
89 | Minimal_Quit = 1, | |
90 | Minimal_About | |
91 | }; | |
92 | ||
93 | ||
94 | // ---------------------------------------------------------------------------- | |
95 | // the application class | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
98 | IMPLEMENT_APP(MyApp) | |
99 | ||
100 | bool MyApp::OnInit() | |
101 | { | |
102 | MyFrame *frame = new MyFrame("Minimal wxWindows App", | |
103 | wxPoint(50, 50), wxSize(450, 340)); | |
104 | ||
105 | frame->Show(TRUE); | |
106 | ||
107 | return TRUE; | |
108 | } | |
109 | ||
110 | // ---------------------------------------------------------------------------- | |
111 | // main frame | |
112 | // ---------------------------------------------------------------------------- | |
113 | ||
114 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
115 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) | |
116 | EVT_MENU(Minimal_About, MyFrame::OnAbout) | |
117 | END_EVENT_TABLE() | |
118 | ||
119 | // frame constructor | |
120 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
121 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
122 | { | |
123 | #ifdef __WXMAC__ | |
124 | wxApp::s_macAboutMenuItemId = Minimal_About; | |
125 | #endif | |
126 | ||
127 | SetIcon(wxICON(mondrian)); | |
128 | ||
129 | wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF); | |
130 | ||
131 | wxMenu *helpMenu = new wxMenu; | |
132 | helpMenu->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); | |
133 | ||
134 | menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program"); | |
135 | ||
136 | wxMenuBar *menuBar = new wxMenuBar(); | |
137 | menuBar->Append(menuFile, "&File"); | |
138 | menuBar->Append(helpMenu, "&Help"); | |
139 | ||
140 | SetMenuBar(menuBar); | |
141 | ||
142 | #if wxUSE_STATUSBAR | |
143 | // create a status bar just for fun (by default with 1 pane only) | |
144 | CreateStatusBar(2); | |
145 | SetStatusText("Welcome to wxWindows!"); | |
146 | #endif // wxUSE_STATUSBAR | |
147 | ||
148 | (void)new MyCanvas( this ); | |
149 | } | |
150 | ||
151 | ||
152 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
153 | { | |
154 | Close(TRUE); | |
155 | } | |
156 | ||
157 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
158 | { | |
159 | wxString msg; | |
83661a13 | 160 | msg.Printf( _T("This is the about dialog of the Erase sample.\n") |
33611ebb RR |
161 | _T("Welcome to %s"), wxVERSION_STRING); |
162 | ||
4d2c67a9 | 163 | wxMessageBox(msg, "About Erase", wxOK | wxICON_INFORMATION, this); |
33611ebb RR |
164 | } |
165 | ||
166 | ||
167 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) | |
168 | EVT_PAINT( MyCanvas::OnPaint) | |
169 | EVT_ERASE_BACKGROUND( MyCanvas::OnEraseBackground) | |
170 | END_EVENT_TABLE() | |
171 | ||
172 | MyCanvas::MyCanvas( MyFrame *parent ) | |
173 | : wxScrolledWindow( parent, -1, wxDefaultPosition, wxDefaultSize, | |
e88be8c9 | 174 | wxScrolledWindowStyle|wxNO_FULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER ) |
33611ebb RR |
175 | { |
176 | SetScrollbars( 10, 10, 40, 100, 0, 0 ); | |
177 | } | |
178 | ||
179 | void MyCanvas::OnPaint( wxPaintEvent &event ) | |
180 | { | |
181 | wxPaintDC dc(this); | |
182 | PrepareDC( dc ); | |
f809133f RR |
183 | |
184 | #if 0 | |
e88be8c9 RR |
185 | wxRegionIterator upd( GetUpdateRegion() ); |
186 | while (upd) | |
187 | { | |
188 | wxLogDebug( "Paint: %d %d %d %d", upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); | |
189 | upd ++; | |
190 | } | |
f809133f RR |
191 | #endif |
192 | ||
193 | #if 0 | |
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 ); | |
197 | #endif | |
2f6c54eb VZ |
198 | |
199 | int i; | |
e88be8c9 | 200 | dc.SetPen( *wxWHITE_PEN ); |
2f6c54eb | 201 | for (i = 0; i < 20; i += 2) |
e88be8c9 | 202 | dc.DrawLine( i,i, i+100,i ); |
33611ebb | 203 | |
f809133f | 204 | dc.SetPen( *wxWHITE_PEN ); |
2f6c54eb | 205 | for (i = 200; i < 220; i += 2) |
f809133f RR |
206 | dc.DrawLine( i-200,i, i-100,i ); |
207 | ||
f566b4fe RR |
208 | wxRegion region( 110, 110, 80, 80 ); |
209 | wxRegion hole( 130, 130, 40, 1 ); | |
210 | region.Intersect( hole ); | |
211 | dc.SetClippingRegion( region ); | |
212 | ||
33611ebb | 213 | dc.SetBrush( *wxRED_BRUSH ); |
f566b4fe | 214 | dc.DrawRectangle( 100, 100, 200, 200 ); |
887dd52f | 215 | |
e88be8c9 | 216 | dc.DestroyClippingRegion(); |
887dd52f RR |
217 | |
218 | dc.SetPen( *wxTRANSPARENT_PEN ); | |
219 | ||
220 | wxRegion strip( 110, 200, 30, 1 ); | |
221 | wxRegionIterator it( strip ); | |
222 | while (it) | |
223 | { | |
224 | dc.DrawRectangle( it.GetX(), it.GetY(), it.GetWidth(), it.GetHeight() ); | |
225 | it ++; | |
226 | } | |
33611ebb RR |
227 | } |
228 | ||
229 | void MyCanvas::OnEraseBackground( wxEraseEvent &event ) | |
230 | { | |
231 | event.Skip( TRUE ); | |
232 | } | |
233 |