]>
Commit | Line | Data |
---|---|---|
aba99005 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: drawing.cpp | |
0f0c61d0 | 3 | // Purpose: shows and tests wxDC features |
aba99005 RR |
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 | // ---------------------------------------------------------------------------- | |
568708e2 | 19 | |
aba99005 | 20 | #ifdef __GNUG__ |
0f0c61d0 VZ |
21 | #pragma implementation "drawing.cpp" |
22 | #pragma interface "drawing.cpp" | |
aba99005 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 | ||
0f0c61d0 | 38 | #include "wx/colordlg.h" |
107a1787 | 39 | #include "wx/image.h" |
0f0c61d0 | 40 | |
aba99005 RR |
41 | // ---------------------------------------------------------------------------- |
42 | // ressources | |
43 | // ---------------------------------------------------------------------------- | |
568708e2 | 44 | |
aba99005 RR |
45 | // the application icon |
46 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
47 | #include "mondrian.xpm" | |
48 | #endif | |
49 | ||
568708e2 VZ |
50 | // ---------------------------------------------------------------------------- |
51 | // constants | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | // what do we show on screen (there are too many shapes to put them all on | |
55 | // screen simultaneously) | |
56 | enum ScreenToShow | |
57 | { | |
58 | Show_Default, | |
59 | Show_Text, | |
60 | Show_Lines, | |
61 | Show_Polygons, | |
81278df2 VZ |
62 | Show_Mask, |
63 | Show_Ops | |
568708e2 VZ |
64 | }; |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // global variables | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | static wxBitmap gs_bmpNoMask, | |
71 | gs_bmpWithColMask, | |
72 | gs_bmpMask, | |
73 | gs_bmpWithMask, | |
74 | gs_bmp4, | |
75 | gs_bmp36; | |
76 | ||
aba99005 RR |
77 | // ---------------------------------------------------------------------------- |
78 | // private classes | |
79 | // ---------------------------------------------------------------------------- | |
80 | ||
81 | // Define a new application type, each program should derive a class from wxApp | |
82 | class MyApp : public wxApp | |
83 | { | |
84 | public: | |
85 | // override base class virtuals | |
86 | // ---------------------------- | |
87 | ||
88 | // this one is called on application startup and is a good place for the app | |
89 | // initialization (doing it here and not in the ctor allows to have an error | |
90 | // return: if OnInit() returns false, the application terminates) | |
91 | virtual bool OnInit(); | |
568708e2 VZ |
92 | |
93 | protected: | |
94 | bool LoadImages(); | |
aba99005 RR |
95 | }; |
96 | ||
b62c3631 RR |
97 | class MyCanvas; |
98 | ||
aba99005 RR |
99 | // Define a new frame type: this is going to be our main frame |
100 | class MyFrame : public wxFrame | |
101 | { | |
102 | public: | |
103 | // ctor(s) | |
104 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
105 | ||
106 | // event handlers (these functions should _not_ be virtual) | |
107 | void OnQuit(wxCommandEvent& event); | |
108 | void OnAbout(wxCommandEvent& event); | |
568708e2 | 109 | void OnShow(wxCommandEvent &event); |
aba99005 | 110 | void OnOption(wxCommandEvent &event); |
aba99005 | 111 | |
220af862 VZ |
112 | wxColour SelectColour(); |
113 | void PrepareDC(wxDC& dc); | |
0f0c61d0 | 114 | |
b62c3631 | 115 | int m_backgroundMode; |
1edc9f45 | 116 | int m_textureBackground; |
b62c3631 RR |
117 | int m_mapMode; |
118 | double m_xUserScale; | |
119 | double m_yUserScale; | |
120 | int m_xLogicalOrigin; | |
121 | int m_yLogicalOrigin; | |
122 | bool m_xAxisReversed, | |
123 | m_yAxisReversed; | |
124 | wxColour m_colourForeground, // these are _text_ colours | |
125 | m_colourBackground; | |
126 | wxBrush m_backgroundBrush; | |
127 | MyCanvas *m_canvas; | |
aba99005 RR |
128 | |
129 | private: | |
130 | // any class wishing to process wxWindows events must use this macro | |
131 | DECLARE_EVENT_TABLE() | |
132 | }; | |
133 | ||
b62c3631 RR |
134 | // define a scrollable canvas for drawing onto |
135 | class MyCanvas: public wxScrolledWindow | |
136 | { | |
137 | public: | |
138 | MyCanvas( MyFrame *parent ); | |
1e7fd311 | 139 | |
b62c3631 | 140 | void OnPaint(wxPaintEvent &event); |
bf0c00c6 | 141 | void OnMouseMove(wxMouseEvent &event); |
4786aabd | 142 | |
568708e2 VZ |
143 | void Show(ScreenToShow show) { m_show = show; Refresh(); } |
144 | ||
b62c3631 | 145 | protected: |
568708e2 VZ |
146 | void DrawTestPoly( int x, int y, wxDC &dc ,int transparent ); |
147 | void DrawTestLines( int x, int y, int width, wxDC &dc ); | |
148 | void DrawText(wxDC& dc); | |
149 | void DrawImages(wxDC& dc); | |
81278df2 | 150 | void DrawWithLogicalOps(wxDC& dc); |
568708e2 | 151 | void DrawDefault(wxDC& dc); |
4786aabd | 152 | |
b62c3631 | 153 | private: |
568708e2 VZ |
154 | MyFrame *m_owner; |
155 | ||
156 | ScreenToShow m_show; | |
0e09f76e RR |
157 | wxBitmap m_smile_bmp; |
158 | wxIcon m_std_icon; | |
568708e2 | 159 | |
b62c3631 RR |
160 | DECLARE_EVENT_TABLE() |
161 | }; | |
162 | ||
aba99005 RR |
163 | // ---------------------------------------------------------------------------- |
164 | // constants | |
165 | // ---------------------------------------------------------------------------- | |
166 | ||
167 | // IDs for the controls and the menu commands | |
168 | enum | |
169 | { | |
170 | // menu items | |
568708e2 VZ |
171 | File_Quit = 1, |
172 | File_About, | |
173 | ||
174 | MenuShow_First, | |
175 | File_ShowDefault = MenuShow_First, | |
176 | File_ShowText, | |
177 | File_ShowLines, | |
178 | File_ShowPolygons, | |
179 | File_ShowMask, | |
81278df2 VZ |
180 | File_ShowOps, |
181 | MenuShow_Last = File_ShowOps, | |
0f0c61d0 VZ |
182 | |
183 | MenuOption_First, | |
184 | ||
185 | MapMode_Text = MenuOption_First, | |
aba99005 RR |
186 | MapMode_Lometric, |
187 | MapMode_Twips, | |
188 | MapMode_Points, | |
189 | MapMode_Metric, | |
0f0c61d0 | 190 | |
aba99005 RR |
191 | UserScale_StretchHoriz, |
192 | UserScale_ShrinkHoriz, | |
193 | UserScale_StretchVertic, | |
194 | UserScale_ShrinkVertic, | |
0f0c61d0 VZ |
195 | UserScale_Restore, |
196 | ||
aba99005 RR |
197 | AxisMirror_Horiz, |
198 | AxisMirror_Vertic, | |
0f0c61d0 | 199 | |
aba99005 RR |
200 | LogicalOrigin_MoveDown, |
201 | LogicalOrigin_MoveUp, | |
202 | LogicalOrigin_MoveLeft, | |
203 | LogicalOrigin_MoveRight, | |
0f0c61d0 VZ |
204 | |
205 | Colour_TextForeground, | |
206 | Colour_TextBackground, | |
207 | Colour_Background, | |
208 | Colour_BackgroundMode, | |
1edc9f45 | 209 | Colour_TextureBackgound, |
0f0c61d0 | 210 | |
1edc9f45 | 211 | MenuOption_Last = Colour_TextureBackgound |
aba99005 RR |
212 | }; |
213 | ||
214 | // ---------------------------------------------------------------------------- | |
215 | // event tables and other macros for wxWindows | |
216 | // ---------------------------------------------------------------------------- | |
217 | ||
aba99005 RR |
218 | |
219 | // Create a new application object: this macro will allow wxWindows to create | |
220 | // the application object during program execution (it's better than using a | |
221 | // static object for many reasons) and also declares the accessor function | |
222 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
223 | // not wxApp) | |
224 | IMPLEMENT_APP(MyApp) | |
225 | ||
226 | // ============================================================================ | |
227 | // implementation | |
228 | // ============================================================================ | |
229 | ||
230 | // ---------------------------------------------------------------------------- | |
231 | // the application class | |
232 | // ---------------------------------------------------------------------------- | |
233 | ||
568708e2 VZ |
234 | bool MyApp::LoadImages() |
235 | { | |
236 | wxPathList pathList; | |
237 | pathList.Add("."); | |
238 | pathList.Add(".."); | |
239 | ||
240 | wxString path = pathList.FindValidPath("pat4.bmp"); | |
241 | if ( !path ) | |
242 | return FALSE; | |
243 | gs_bmp4.LoadFile(path, wxBITMAP_TYPE_BMP); | |
244 | wxMask* mask4 = new wxMask(gs_bmp4, *wxBLACK); | |
245 | gs_bmp4.SetMask(mask4); | |
246 | ||
247 | path = pathList.FindValidPath("pat36.bmp"); | |
248 | if ( !path ) | |
249 | return FALSE; | |
250 | gs_bmp36.LoadFile(path, wxBITMAP_TYPE_BMP); | |
251 | wxMask* mask36 = new wxMask(gs_bmp36, *wxBLACK); | |
252 | gs_bmp36.SetMask(mask36); | |
253 | ||
254 | path = pathList.FindValidPath("image.bmp"); | |
255 | if ( !path ) | |
256 | return FALSE; | |
257 | gs_bmpNoMask.LoadFile(path, wxBITMAP_TYPE_BMP); | |
258 | gs_bmpWithMask.LoadFile(path, wxBITMAP_TYPE_BMP); | |
259 | gs_bmpWithColMask.LoadFile(path, wxBITMAP_TYPE_BMP); | |
260 | ||
261 | path = pathList.FindValidPath("mask.bmp"); | |
262 | if ( !path ) | |
263 | return FALSE; | |
264 | gs_bmpMask.LoadFile(path, wxBITMAP_TYPE_BMP); | |
b9de1315 | 265 | |
ff7c6c9c RR |
266 | // This is so wrong, it hurts. |
267 | // gs_bmpMask.SetDepth(1); | |
268 | // wxMask *mask = new wxMask(gs_bmpMask); | |
568708e2 | 269 | |
ff7c6c9c | 270 | wxMask *mask = new wxMask(gs_bmpMask, *wxBLACK); |
568708e2 VZ |
271 | gs_bmpWithMask.SetMask(mask); |
272 | ||
273 | mask = new wxMask(gs_bmpWithColMask, *wxWHITE); | |
274 | gs_bmpWithColMask.SetMask(mask); | |
275 | ||
276 | return TRUE; | |
277 | } | |
278 | ||
aba99005 RR |
279 | // `Main program' equivalent: the program execution "starts" here |
280 | bool MyApp::OnInit() | |
281 | { | |
282 | // Create the main application window | |
ed43910d | 283 | MyFrame *frame = new MyFrame("Drawing sample", |
b62c3631 | 284 | wxPoint(50, 50), wxSize(550, 340)); |
aba99005 RR |
285 | |
286 | // Show it and tell the application that it's our main window | |
aba99005 RR |
287 | frame->Show(TRUE); |
288 | SetTopWindow(frame); | |
289 | ||
568708e2 VZ |
290 | if ( !LoadImages() ) |
291 | { | |
292 | wxLogError("Can't load one of the bitmap files needed for this sample " | |
293 | "from the current or parent directory, please copy them " | |
294 | "there."); | |
295 | ||
296 | // stop here | |
297 | return FALSE; | |
298 | } | |
299 | ||
300 | // ok, continue | |
aba99005 RR |
301 | return TRUE; |
302 | } | |
303 | ||
304 | // ---------------------------------------------------------------------------- | |
b62c3631 | 305 | // MyCanvas |
aba99005 RR |
306 | // ---------------------------------------------------------------------------- |
307 | ||
b62c3631 RR |
308 | // the event tables connect the wxWindows events with the functions (event |
309 | // handlers) which process them. | |
310 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) | |
311 | EVT_PAINT (MyCanvas::OnPaint) | |
bf0c00c6 | 312 | EVT_MOTION (MyCanvas::OnMouseMove) |
b62c3631 RR |
313 | END_EVENT_TABLE() |
314 | ||
0e09f76e RR |
315 | #include "../image/smile.xpm" |
316 | ||
b97fa7cf | 317 | MyCanvas::MyCanvas( MyFrame *parent ) : wxScrolledWindow( parent ) |
b62c3631 | 318 | { |
b97fa7cf | 319 | m_owner = parent; |
568708e2 | 320 | m_show = Show_Default; |
0e09f76e RR |
321 | m_smile_bmp = wxBitmap(smile_xpm); |
322 | m_std_icon = wxTheApp->GetStdIcon(wxICON_INFORMATION); | |
b97fa7cf VZ |
323 | } |
324 | ||
325 | //draw a polygon and an overlapping rectangle | |
326 | //is transparent is 1, the fill pattern are made transparent | |
327 | //is transparent is 2, the fill pattern are made transparent but inversed | |
328 | //is transparent is 0 the text for and background color will be used to represent/map | |
329 | //the colors of the monochrome bitmap pixels to the fillpattern | |
330 | // | |
331 | //i miss_used the the menu items for setting so called back and fore ground color | |
332 | //just to show how the those colors do influence the fillpatterns | |
333 | //just play with those, | |
334 | //and with the code | |
335 | //variations are endless using other logical functions | |
336 | void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent ) | |
337 | { | |
568708e2 VZ |
338 | wxBrush* brush4 = new wxBrush(gs_bmp4); |
339 | wxBrush* brush36 = new wxBrush(gs_bmp36); | |
b97fa7cf VZ |
340 | |
341 | wxPoint todraw[5]; | |
342 | todraw[0].x=(long)x+100; | |
343 | todraw[0].y=(long)y+100; | |
344 | todraw[1].x=(long)x+300; | |
345 | todraw[1].y=(long)y+100; | |
346 | todraw[2].x=(long)x+300; | |
347 | todraw[2].y=(long)y+300; | |
348 | todraw[3].x=(long)x+150; | |
349 | todraw[3].y=(long)y+350; | |
350 | todraw[4].x=(long)x+100; | |
351 | todraw[4].y=(long)y+300; | |
352 | ||
353 | wxPoint todraw2[5]; | |
354 | todraw2[0].x=100; | |
355 | todraw2[0].y=100; | |
356 | todraw2[1].x=300; | |
357 | todraw2[1].y=100; | |
358 | todraw2[2].x=300; | |
359 | todraw2[2].y=300; | |
360 | todraw2[3].x=150; | |
361 | todraw2[3].y=350; | |
362 | todraw2[4].x=100; | |
363 | todraw2[4].y=300; | |
364 | ||
365 | switch (transparent) | |
366 | { | |
367 | case 0: | |
368 | { | |
369 | dc.SetPen( wxPen( "black", 4, wxSOLID) ); | |
568708e2 | 370 | dc.SetBrush( *brush4 ); |
b97fa7cf | 371 | dc.SetTextForeground(*wxGREEN); |
b97fa7cf VZ |
372 | dc.SetTextBackground(m_owner->m_colourForeground); |
373 | dc.SetLogicalFunction(wxCOPY); | |
374 | dc.DrawPolygon(5,todraw,0,0,wxWINDING_RULE); | |
375 | ||
376 | //don't understand hwo but the outline is also depending on logicalfunction | |
377 | dc.SetPen( wxPen( "red", 4, wxSOLID) ); | |
568708e2 | 378 | dc.SetBrush( *brush36 ); |
b97fa7cf | 379 | dc.SetTextForeground(*wxCYAN); |
b97fa7cf VZ |
380 | dc.SetTextBackground(m_owner->m_colourBackground); |
381 | dc.SetLogicalFunction(wxCOPY); | |
382 | dc.DrawRectangle( x+10, y+10, 200, 200 ); | |
383 | dc.SetBrush(wxNullBrush); | |
384 | dc.SetPen(wxNullPen); | |
385 | break; | |
386 | } | |
387 | case 1: //now with transparent fillpatterns | |
388 | { | |
389 | ||
568708e2 VZ |
390 | wxBitmap* bmpBlit = new wxBitmap(600,400); |
391 | wxMemoryDC* memDC= new wxMemoryDC(); | |
b97fa7cf VZ |
392 | // wxBrush _clearbrush(*wxGREEN,wxSOLID); |
393 | wxBrush _clearbrush(*wxBLACK,wxSOLID); | |
568708e2 VZ |
394 | memDC->SelectObject(*bmpBlit); |
395 | memDC->BeginDrawing(); | |
396 | memDC->SetBackground(_clearbrush); | |
397 | memDC->Clear(); | |
398 | memDC->SetBackground(wxNullBrush); | |
399 | ||
400 | memDC->SetPen( wxPen( "black", 4, wxSOLID) ); | |
401 | memDC->SetBrush( wxNullBrush); | |
402 | memDC->SetBrush( *brush4 ); | |
403 | memDC->SetTextForeground(*wxBLACK); // 0s --> 0x000000 (black) | |
404 | memDC->SetTextBackground(*wxWHITE); // 1s --> 0xFFFFFF (white) | |
405 | memDC->SetLogicalFunction(wxAND_INVERT); | |
b97fa7cf VZ |
406 | |
407 | // BLACK OUT the opaque pixels and leave the rest as is | |
568708e2 | 408 | memDC->DrawPolygon(5,todraw2,0,0,wxWINDING_RULE); |
b97fa7cf VZ |
409 | |
410 | // Set background and foreground colors for fill pattern | |
411 | //the previous blacked out pixels are now merged with the layer color | |
412 | //while the non blacked out pixels stay as they are. | |
568708e2 | 413 | memDC->SetTextForeground(*wxBLACK); // 0s --> 0x000000 (black) |
b97fa7cf VZ |
414 | |
415 | //now define what will be the color of the fillpattern parts that are not transparent | |
568708e2 VZ |
416 | // memDC->SetTextBackground(*wxBLUE); |
417 | memDC->SetTextBackground(m_owner->m_colourForeground); | |
418 | memDC->SetLogicalFunction(wxOR); | |
b97fa7cf VZ |
419 | |
420 | ||
421 | //don't understand how but the outline is also depending on logicalfunction | |
568708e2 VZ |
422 | memDC->SetPen( wxPen( "red", 4, wxSOLID) ); |
423 | memDC->DrawPolygon(5,todraw2,0,0,wxWINDING_RULE); | |
b97fa7cf | 424 | |
568708e2 | 425 | memDC->SetLogicalFunction(wxCOPY); |
b97fa7cf | 426 | |
568708e2 VZ |
427 | memDC->SetPen( wxPen( "black", 4, wxSOLID) ); |
428 | memDC->SetBrush( wxNullBrush); | |
429 | memDC->SetBrush( *brush36 ); | |
430 | memDC->SetTextForeground(*wxBLACK); // 0s --> 0x000000 (black) | |
431 | memDC->SetTextBackground(*wxWHITE); // 1s --> 0xFFFFFF (white) | |
432 | memDC->SetLogicalFunction(wxAND_INVERT); | |
b97fa7cf | 433 | |
568708e2 | 434 | memDC->DrawRectangle( 10, 10, 200, 200 ); |
b97fa7cf VZ |
435 | |
436 | // Set background and foreground colors for fill pattern | |
437 | //the previous blacked out pixels are now merged with the layer color | |
438 | //while the non blacked out pixels stay as they are. | |
568708e2 | 439 | memDC->SetTextForeground(*wxBLACK); // 0s --> 0x000000 (black) |
b97fa7cf | 440 | //now define what will be the color of the fillpattern parts that are not transparent |
568708e2 VZ |
441 | // memDC->SetTextBackground(*wxRED); |
442 | memDC->SetTextBackground(m_owner->m_colourBackground); | |
443 | memDC->SetLogicalFunction(wxOR); | |
b97fa7cf VZ |
444 | |
445 | //don't understand how but the outline is also depending on logicalfunction | |
568708e2 VZ |
446 | memDC->SetPen( wxPen( "yellow", 4, wxSOLID) ); |
447 | memDC->DrawRectangle( 10, 10, 200, 200 ); | |
b97fa7cf | 448 | |
568708e2 VZ |
449 | memDC->SetBrush(wxNullBrush); |
450 | memDC->SetPen(wxNullPen); | |
b97fa7cf | 451 | |
568708e2 VZ |
452 | memDC->EndDrawing(); |
453 | dc.Blit(x,y,600,400,memDC,0,0,wxCOPY); | |
454 | delete bmpBlit; | |
455 | delete memDC; | |
b97fa7cf VZ |
456 | break; |
457 | } | |
458 | case 2: //now with transparent inversed fillpatterns | |
459 | { | |
568708e2 VZ |
460 | wxBitmap* bmpBlit = new wxBitmap(600,400); |
461 | wxMemoryDC* memDC= new wxMemoryDC(); | |
b97fa7cf | 462 | wxBrush _clearbrush(*wxWHITE,wxSOLID); |
568708e2 VZ |
463 | memDC->SelectObject(*bmpBlit); |
464 | memDC->BeginDrawing(); | |
465 | memDC->SetBackground(_clearbrush); | |
466 | memDC->Clear(); | |
467 | memDC->SetBackground(wxNullBrush); | |
468 | ||
469 | memDC->SetPen( wxPen( "black", 4, wxSOLID) ); | |
470 | memDC->SetBrush( *brush4 ); | |
471 | memDC->SetTextBackground(*wxBLACK); // 0s --> 0x000000 (black) | |
472 | memDC->SetTextForeground(*wxWHITE); // 1s --> 0xFFFFFF (white) | |
473 | memDC->SetLogicalFunction(wxAND_INVERT); | |
b97fa7cf VZ |
474 | |
475 | // BLACK OUT the opaque pixels and leave the rest as is | |
568708e2 | 476 | memDC->DrawPolygon(5,todraw2,0,0,wxWINDING_RULE); |
b97fa7cf VZ |
477 | |
478 | // Set background and foreground colors for fill pattern | |
479 | //the previous blacked out pixels are now merged with the layer color | |
480 | //while the non blacked out pixels stay as they are. | |
568708e2 | 481 | memDC->SetTextBackground(*wxBLACK); // 0s --> 0x000000 (black) |
b97fa7cf VZ |
482 | |
483 | //now define what will be the color of the fillpattern parts that are not transparent | |
568708e2 VZ |
484 | memDC->SetTextForeground(m_owner->m_colourForeground); |
485 | memDC->SetLogicalFunction(wxOR); | |
b97fa7cf VZ |
486 | |
487 | ||
488 | //don't understand how but the outline is also depending on logicalfunction | |
568708e2 VZ |
489 | memDC->SetPen( wxPen( "red", 4, wxSOLID) ); |
490 | memDC->DrawPolygon(5,todraw2,0,0,wxWINDING_RULE); | |
b97fa7cf | 491 | |
568708e2 | 492 | memDC->SetLogicalFunction(wxCOPY); |
b97fa7cf | 493 | |
568708e2 VZ |
494 | memDC->SetPen( wxPen( "black", 4, wxSOLID) ); |
495 | memDC->SetBrush( *brush36 ); | |
496 | memDC->SetTextBackground(*wxBLACK); // 0s --> 0x000000 (black) | |
497 | memDC->SetTextForeground(*wxWHITE); // 1s --> 0xFFFFFF (white) | |
498 | memDC->SetLogicalFunction(wxAND_INVERT); | |
b97fa7cf | 499 | |
568708e2 | 500 | memDC->DrawRectangle( 10,10, 200, 200 ); |
b97fa7cf VZ |
501 | |
502 | // Set background and foreground colors for fill pattern | |
503 | //the previous blacked out pixels are now merged with the layer color | |
504 | //while the non blacked out pixels stay as they are. | |
568708e2 | 505 | memDC->SetTextBackground(*wxBLACK); // 0s --> 0x000000 (black) |
b97fa7cf | 506 | //now define what will be the color of the fillpattern parts that are not transparent |
568708e2 VZ |
507 | memDC->SetTextForeground(m_owner->m_colourBackground); |
508 | memDC->SetLogicalFunction(wxOR); | |
b97fa7cf VZ |
509 | |
510 | //don't understand how but the outline is also depending on logicalfunction | |
568708e2 VZ |
511 | memDC->SetPen( wxPen( "yellow", 4, wxSOLID) ); |
512 | memDC->DrawRectangle( 10, 10, 200, 200 ); | |
513 | ||
514 | memDC->SetBrush(wxNullBrush); | |
515 | memDC->SetPen(wxNullPen); | |
516 | dc.Blit(x,y,600,400,memDC,0,0,wxCOPY); | |
517 | delete bmpBlit; | |
518 | delete memDC; | |
b97fa7cf VZ |
519 | } |
520 | } | |
521 | ||
568708e2 VZ |
522 | delete brush4; |
523 | delete brush36; | |
b62c3631 RR |
524 | } |
525 | ||
1e7fd311 | 526 | void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc ) |
b62c3631 | 527 | { |
1e7fd311 RR |
528 | dc.SetPen( wxPen( "black", width, wxSOLID) ); |
529 | dc.SetBrush( *wxRED_BRUSH ); | |
9a8c7620 | 530 | dc.DrawRectangle( x+10, y+10, 100, 190 ); |
4786aabd | 531 | |
1e7fd311 | 532 | dc.SetPen( wxPen( "black", width, wxSOLID) ); |
696e1ea0 | 533 | dc.DrawLine( x+20, y+20, 100, y+20 ); |
1e7fd311 | 534 | dc.SetPen( wxPen( "black", width, wxDOT) ); |
696e1ea0 | 535 | dc.DrawLine( x+20, y+30, 100, y+30 ); |
1e7fd311 | 536 | dc.SetPen( wxPen( "black", width, wxSHORT_DASH) ); |
696e1ea0 | 537 | dc.DrawLine( x+20, y+40, 100, y+40 ); |
1e7fd311 | 538 | dc.SetPen( wxPen( "black", width, wxLONG_DASH) ); |
696e1ea0 | 539 | dc.DrawLine( x+20, y+50, 100, y+50 ); |
1e7fd311 | 540 | dc.SetPen( wxPen( "black", width, wxDOT_DASH) ); |
696e1ea0 | 541 | dc.DrawLine( x+20, y+60, 100, y+60 ); |
1e7fd311 RR |
542 | |
543 | dc.SetPen( wxPen( "black", width, wxBDIAGONAL_HATCH) ); | |
696e1ea0 | 544 | dc.DrawLine( x+20, y+70, 100, y+70 ); |
1e7fd311 | 545 | dc.SetPen( wxPen( "black", width, wxCROSSDIAG_HATCH) ); |
696e1ea0 | 546 | dc.DrawLine( x+20, y+80, 100, y+80 ); |
1e7fd311 | 547 | dc.SetPen( wxPen( "black", width, wxFDIAGONAL_HATCH) ); |
696e1ea0 | 548 | dc.DrawLine( x+20, y+90, 100, y+90 ); |
1e7fd311 | 549 | dc.SetPen( wxPen( "black", width, wxCROSS_HATCH) ); |
696e1ea0 | 550 | dc.DrawLine( x+20, y+100, 100, y+100 ); |
1e7fd311 | 551 | dc.SetPen( wxPen( "black", width, wxHORIZONTAL_HATCH) ); |
696e1ea0 | 552 | dc.DrawLine( x+20, y+110, 100, y+110 ); |
1e7fd311 | 553 | dc.SetPen( wxPen( "black", width, wxVERTICAL_HATCH) ); |
696e1ea0 | 554 | dc.DrawLine( x+20, y+120, 100, y+120 ); |
1e7fd311 RR |
555 | |
556 | wxPen ud( "black", width, wxUSER_DASH ); | |
557 | wxDash dash1[1]; | |
558 | dash1[0] = 0; | |
559 | ud.SetDashes( 1, dash1 ); | |
696e1ea0 | 560 | dc.DrawLine( x+20, y+140, 100, y+140 ); |
1e7fd311 RR |
561 | dash1[0] = 1; |
562 | ud.SetDashes( 1, dash1 ); | |
696e1ea0 | 563 | dc.DrawLine( x+20, y+150, 100, y+150 ); |
1e7fd311 RR |
564 | dash1[0] = 2; |
565 | ud.SetDashes( 1, dash1 ); | |
696e1ea0 | 566 | dc.DrawLine( x+20, y+160, 100, y+160 ); |
1e7fd311 RR |
567 | dash1[0] = 0xFF; |
568 | ud.SetDashes( 1, dash1 ); | |
696e1ea0 | 569 | dc.DrawLine( x+20, y+170, 100, y+170 ); |
b62c3631 RR |
570 | } |
571 | ||
568708e2 | 572 | void MyCanvas::DrawDefault(wxDC& dc) |
b62c3631 | 573 | { |
b62c3631 RR |
574 | // mark the origin |
575 | dc.DrawCircle(0, 0, 10); | |
70bdacfc MB |
576 | #if !(defined __WXGTK__) && !(defined __WXMOTIF__) |
577 | // not implemented in wxGTK or wxMOTIF :-( | |
b62c3631 | 578 | dc.FloodFill(0, 0, wxColour(255, 0, 0)); |
70bdacfc | 579 | #endif // |
b62c3631 | 580 | |
11f26ea0 | 581 | dc.DrawIcon( wxICON(mondrian), 40, 40 ); |
568708e2 | 582 | |
cd9da200 VZ |
583 | dc.DrawCheckMark(5, 80, 15, 15); |
584 | dc.DrawCheckMark(25, 80, 30, 30); | |
585 | dc.DrawCheckMark(60, 80, 60, 60); | |
586 | ||
0e09f76e RR |
587 | // this is the test for "blitting bitmap into DC damages selected brush" bug |
588 | wxIcon m_std_icon = wxTheApp->GetStdIcon(wxICON_INFORMATION); | |
589 | wxCoord rectSize = m_std_icon.GetWidth() + 10; | |
cd9da200 | 590 | wxCoord x = 100; |
11f26ea0 VZ |
591 | dc.SetPen(*wxTRANSPARENT_PEN); |
592 | dc.SetBrush( *wxGREEN_BRUSH ); | |
cd9da200 | 593 | dc.DrawRectangle(x, 10, rectSize, rectSize); |
0e09f76e | 594 | dc.DrawBitmap(m_std_icon, x + 5, 15, TRUE); |
cd9da200 VZ |
595 | x += rectSize + 10; |
596 | dc.DrawRectangle(x, 10, rectSize, rectSize); | |
0e09f76e | 597 | dc.DrawIcon(m_std_icon, x + 5, 15); |
cd9da200 VZ |
598 | x += rectSize + 10; |
599 | dc.DrawRectangle(x, 10, rectSize, rectSize); | |
11f26ea0 VZ |
600 | |
601 | // test for "transparent" bitmap drawing (it intersects with the last | |
602 | // rectangle above) | |
603 | //dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
d6f0a4b3 | 604 | |
0e09f76e RR |
605 | if (m_smile_bmp.Ok()) |
606 | dc.DrawBitmap(m_smile_bmp, x + rectSize - 20, rectSize - 10, TRUE); | |
107a1787 | 607 | |
ff7c6c9c | 608 | dc.SetBrush( *wxBLACK_BRUSH ); |
107a1787 RR |
609 | dc.DrawRectangle( 0, 160, 1000, 300 ); |
610 | ||
611 | // draw lines | |
612 | wxBitmap bitmap(20,70); | |
613 | wxMemoryDC memdc; | |
614 | memdc.SelectObject( bitmap ); | |
615 | memdc.SetBrush( *wxBLACK_BRUSH ); | |
616 | memdc.SetPen( *wxWHITE_PEN ); | |
617 | memdc.DrawRectangle(0,0,20,70); | |
618 | memdc.DrawLine( 10,0,10,70 ); | |
81278df2 | 619 | |
d4aa3a4b | 620 | // to the right |
4c45f240 | 621 | wxPen pen = *wxRED_PEN; |
4c45f240 | 622 | memdc.SetPen(pen); |
107a1787 RR |
623 | memdc.DrawLine( 10, 5,10, 5 ); |
624 | memdc.DrawLine( 10,10,11,10 ); | |
625 | memdc.DrawLine( 10,15,12,15 ); | |
626 | memdc.DrawLine( 10,20,13,20 ); | |
81278df2 | 627 | |
d4aa3a4b RR |
628 | /* |
629 | memdc.SetPen(*wxRED_PEN); | |
107a1787 RR |
630 | memdc.DrawLine( 12, 5,12, 5 ); |
631 | memdc.DrawLine( 12,10,13,10 ); | |
632 | memdc.DrawLine( 12,15,14,15 ); | |
633 | memdc.DrawLine( 12,20,15,20 ); | |
d4aa3a4b | 634 | */ |
81278df2 | 635 | |
107a1787 RR |
636 | // same to the left |
637 | memdc.DrawLine( 10,25,10,25 ); | |
638 | memdc.DrawLine( 10,30, 9,30 ); | |
639 | memdc.DrawLine( 10,35, 8,35 ); | |
640 | memdc.DrawLine( 10,40, 7,40 ); | |
641 | ||
642 | // XOR draw lines | |
d4aa3a4b | 643 | dc.SetPen(*wxWHITE_PEN); |
107a1787 RR |
644 | memdc.SetLogicalFunction( wxINVERT ); |
645 | memdc.SetPen( *wxWHITE_PEN ); | |
646 | memdc.DrawLine( 10,50,10,50 ); | |
647 | memdc.DrawLine( 10,55,11,55 ); | |
648 | memdc.DrawLine( 10,60,12,60 ); | |
649 | memdc.DrawLine( 10,65,13,65 ); | |
81278df2 | 650 | |
107a1787 RR |
651 | memdc.DrawLine( 12,50,12,50 ); |
652 | memdc.DrawLine( 12,55,13,55 ); | |
653 | memdc.DrawLine( 12,60,14,60 ); | |
654 | memdc.DrawLine( 12,65,15,65 ); | |
81278df2 | 655 | |
107a1787 RR |
656 | memdc.SelectObject( wxNullBitmap ); |
657 | dc.DrawBitmap( bitmap, 10, 170 ); | |
658 | wxImage image( bitmap ); | |
659 | image.Rescale( 60,210 ); | |
660 | bitmap = image.ConvertToBitmap(); | |
661 | dc.DrawBitmap( bitmap, 50, 170 ); | |
81278df2 | 662 | |
b9de1315 | 663 | // test the rectangle outline drawing - there should be one pixel between |
ff7c6c9c RR |
664 | // the rect and the lines |
665 | dc.SetPen(*wxWHITE_PEN); | |
666 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
ff7c6c9c | 667 | dc.DrawRectangle(150, 170, 49, 29); |
107a1787 | 668 | dc.DrawRectangle(200, 170, 49, 29); |
ff7c6c9c | 669 | dc.SetPen(*wxWHITE_PEN); |
107a1787 RR |
670 | dc.DrawLine(250, 210, 250, 170); |
671 | dc.DrawLine(260, 200, 150, 200); | |
b9de1315 VZ |
672 | |
673 | // test the rectangle filled drawing - there should be one pixel between | |
ff7c6c9c RR |
674 | // the rect and the lines |
675 | dc.SetPen(*wxTRANSPARENT_PEN); | |
676 | dc.SetBrush( *wxWHITE_BRUSH ); | |
677 | dc.DrawRectangle(300, 170, 49, 29); | |
568708e2 | 678 | dc.DrawRectangle(350, 170, 49, 29); |
ff7c6c9c | 679 | dc.SetPen(*wxWHITE_PEN); |
b9de1315 VZ |
680 | dc.DrawLine(400, 170, 400, 210); |
681 | dc.DrawLine(300, 200, 410, 200); | |
682 | ||
3d2d8da1 RR |
683 | // a few more tests of this kind |
684 | dc.SetPen(*wxRED_PEN); | |
685 | dc.SetBrush( *wxWHITE_BRUSH ); | |
686 | dc.DrawRectangle(300, 220, 1, 1); | |
687 | dc.DrawRectangle(310, 220, 2, 2); | |
688 | dc.DrawRectangle(320, 220, 3, 3); | |
689 | dc.DrawRectangle(330, 220, 4, 4); | |
690 | ||
691 | dc.SetPen(*wxTRANSPARENT_PEN); | |
692 | dc.SetBrush( *wxWHITE_BRUSH ); | |
693 | dc.DrawRectangle(300, 230, 1, 1); | |
694 | dc.DrawRectangle(310, 230, 2, 2); | |
695 | dc.DrawRectangle(320, 230, 3, 3); | |
696 | dc.DrawRectangle(330, 230, 4, 4); | |
697 | ||
b9de1315 VZ |
698 | // and now for filled rect with outline |
699 | dc.SetPen(*wxRED_PEN); | |
700 | dc.SetBrush( *wxWHITE_BRUSH ); | |
701 | dc.DrawRectangle(500, 170, 49, 29); | |
702 | dc.DrawRectangle(550, 170, 49, 29); | |
703 | dc.SetPen(*wxWHITE_PEN); | |
704 | dc.DrawLine(600, 170, 600, 210); | |
705 | dc.DrawLine(500, 200, 610, 200); | |
706 | ||
707 | // test the rectangle outline drawing - there should be one pixel between | |
ff7c6c9c RR |
708 | // the rect and the lines |
709 | dc.SetPen(*wxWHITE_PEN); | |
710 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
ff7c6c9c | 711 | dc.DrawRoundedRectangle(150, 270, 49, 29, 6); |
107a1787 | 712 | dc.DrawRoundedRectangle(200, 270, 49, 29, 6); |
ff7c6c9c | 713 | dc.SetPen(*wxWHITE_PEN); |
107a1787 RR |
714 | dc.DrawLine(250, 270, 250, 310); |
715 | dc.DrawLine(150, 300, 260, 300); | |
b9de1315 VZ |
716 | |
717 | // test the rectangle filled drawing - there should be one pixel between | |
ff7c6c9c RR |
718 | // the rect and the lines |
719 | dc.SetPen(*wxTRANSPARENT_PEN); | |
720 | dc.SetBrush( *wxWHITE_BRUSH ); | |
721 | dc.DrawRoundedRectangle(300, 270, 49, 29, 6); | |
722 | dc.DrawRoundedRectangle(350, 270, 49, 29, 6); | |
723 | dc.SetPen(*wxWHITE_PEN); | |
b9de1315 VZ |
724 | dc.DrawLine(400, 270, 400, 310); |
725 | dc.DrawLine(300, 300, 410, 300); | |
ff7c6c9c | 726 | |
b14c14ff JS |
727 | // Added by JACS to demonstrate bizarre behaviour. |
728 | // With a size of 70, we get a missing red RHS, | |
729 | // and the hight is too small, so we get yellow | |
730 | // showing. With a size of 40, it draws as expected: | |
731 | // it just shows a white rectangle with red outline. | |
732 | int totalWidth = 70; | |
733 | int totalHeight = 70; | |
734 | wxBitmap bitmap2(totalWidth, totalHeight); | |
735 | ||
736 | wxMemoryDC memdc2; | |
737 | memdc2.SelectObject(bitmap2); | |
738 | ||
d6f0a4b3 JS |
739 | wxBrush yellowBrush(wxColour(255, 255, 0), wxSOLID); |
740 | memdc2.SetBackground(yellowBrush); | |
741 | memdc2.Clear(); | |
b14c14ff | 742 | |
d6f0a4b3 | 743 | wxPen yellowPen(wxColour(255, 255, 0), 1, wxSOLID); |
b14c14ff JS |
744 | |
745 | // Now draw a white rectangle with red outline. It should | |
746 | // entirely eclipse the yellow background. | |
747 | memdc2.SetPen(*wxRED_PEN); | |
748 | memdc2.SetBrush(*wxWHITE_BRUSH); | |
749 | ||
750 | memdc2.DrawRectangle(0, 0, totalWidth, totalHeight); | |
751 | ||
b14c14ff JS |
752 | memdc2.SetPen(wxNullPen); |
753 | memdc2.SetBrush(wxNullBrush); | |
cd9da200 | 754 | memdc2.SelectObject(wxNullBitmap); |
b14c14ff JS |
755 | |
756 | dc.DrawBitmap(bitmap2, 500, 270); | |
d6f0a4b3 JS |
757 | |
758 | // Repeat, but draw directly on dc | |
759 | // Draw a yellow rectangle filling the bitmap | |
760 | ||
761 | x = 600; int y = 270; | |
762 | dc.SetPen(yellowPen); | |
763 | dc.SetBrush(yellowBrush); | |
764 | dc.DrawRectangle(x, y, totalWidth, totalHeight); | |
765 | ||
766 | // Now draw a white rectangle with red outline. It should | |
767 | // entirely eclipse the yellow background. | |
768 | dc.SetPen(*wxRED_PEN); | |
769 | dc.SetBrush(*wxWHITE_BRUSH); | |
770 | ||
771 | dc.DrawRectangle(x, y, totalWidth, totalHeight); | |
568708e2 VZ |
772 | } |
773 | ||
774 | void MyCanvas::DrawText(wxDC& dc) | |
775 | { | |
9a8c7620 VZ |
776 | // set underlined font for testing |
777 | dc.SetFont( wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, TRUE) ); | |
b62c3631 | 778 | dc.DrawText( "This is text", 110, 10 ); |
4786aabd | 779 | dc.DrawRotatedText( "That is text", 20, 10, -45 ); |
9a8c7620 VZ |
780 | |
781 | dc.SetFont( *wxNORMAL_FONT ); | |
b62c3631 | 782 | |
696e1ea0 | 783 | wxString text; |
9a8c7620 | 784 | dc. SetBackgroundMode(wxTRANSPARENT); |
696e1ea0 VZ |
785 | |
786 | for ( int n = -180; n < 180; n += 30 ) | |
787 | { | |
788 | text.Printf(" %d rotated text", n); | |
789 | dc.DrawRotatedText(text , 400, 400, n); | |
790 | } | |
95724b1a | 791 | |
196c87f4 | 792 | dc.SetFont( wxFont( 18, wxSWISS, wxNORMAL, wxNORMAL ) ); |
c45a644e RR |
793 | |
794 | dc.DrawText( "This is Swiss 18pt text.", 110, 40 ); | |
795 | ||
796 | long length; | |
797 | long height; | |
798 | long descent; | |
799 | dc.GetTextExtent( "This is Swiss 18pt text.", &length, &height, &descent ); | |
c45a644e RR |
800 | text.Printf( "Dimensions are length %ld, height %ld, descent %ld", length, height, descent ); |
801 | dc.DrawText( text, 110, 80 ); | |
802 | ||
c45a644e RR |
803 | text.Printf( "CharHeight() returns: %d", dc.GetCharHeight() ); |
804 | dc.DrawText( text, 110, 120 ); | |
805 | ||
568708e2 VZ |
806 | dc.DrawRectangle( 100, 40, 4, height ); |
807 | } | |
808 | ||
81278df2 | 809 | static const struct |
568708e2 | 810 | { |
81278df2 VZ |
811 | const wxChar *name; |
812 | int rop; | |
813 | } rasterOperations[] = | |
814 | { | |
815 | { "wxAND", wxAND }, | |
816 | { "wxAND_INVERT", wxAND_INVERT }, | |
817 | { "wxAND_REVERSE", wxAND_REVERSE }, | |
818 | { "wxCLEAR", wxCLEAR }, | |
819 | { "wxCOPY", wxCOPY }, | |
820 | { "wxEQUIV", wxEQUIV }, | |
821 | { "wxINVERT", wxINVERT }, | |
822 | { "wxNAND", wxNAND }, | |
823 | { "wxNO_OP", wxNO_OP }, | |
824 | { "wxOR", wxOR }, | |
825 | { "wxOR_INVERT", wxOR_INVERT }, | |
826 | { "wxOR_REVERSE", wxOR_REVERSE }, | |
827 | { "wxSET", wxSET }, | |
828 | { "wxSRC_INVERT", wxSRC_INVERT }, | |
829 | { "wxXOR", wxXOR }, | |
830 | }; | |
568708e2 | 831 | |
81278df2 VZ |
832 | void MyCanvas::DrawImages(wxDC& dc) |
833 | { | |
568708e2 VZ |
834 | dc.DrawText("original image", 0, 0); |
835 | dc.DrawBitmap(gs_bmpNoMask, 0, 20, 0); | |
836 | dc.DrawText("with colour mask", 0, 100); | |
837 | dc.DrawBitmap(gs_bmpWithColMask, 0, 120, TRUE); | |
838 | dc.DrawText("the mask image", 0, 200); | |
839 | dc.DrawBitmap(gs_bmpMask, 0, 220, 0); | |
840 | dc.DrawText("masked image", 0, 300); | |
841 | dc.DrawBitmap(gs_bmpWithMask, 0, 320, TRUE); | |
842 | ||
843 | int cx = gs_bmpWithColMask.GetWidth(), | |
844 | cy = gs_bmpWithColMask.GetHeight(); | |
845 | ||
846 | wxMemoryDC memDC; | |
847 | for ( size_t n = 0; n < WXSIZEOF(rasterOperations); n++ ) | |
848 | { | |
849 | wxCoord x = 120 + 150*(n%4), | |
850 | y = 20 + 100*(n/4); | |
4786aabd | 851 | |
568708e2 VZ |
852 | dc.DrawText(rasterOperations[n].name, x, y - 20); |
853 | memDC.SelectObject(gs_bmpWithColMask); | |
854 | dc.Blit(x, y, cx, cy, &memDC, 0, 0, rasterOperations[n].rop, TRUE); | |
855 | } | |
856 | } | |
857 | ||
81278df2 VZ |
858 | void MyCanvas::DrawWithLogicalOps(wxDC& dc) |
859 | { | |
860 | static const wxCoord w = 60; | |
861 | static const wxCoord h = 60; | |
862 | ||
863 | // reuse the text colour here | |
864 | dc.SetPen(wxPen(m_owner->m_colourForeground, 1, wxSOLID)); | |
11f26ea0 | 865 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
81278df2 | 866 | |
5888ef1e VZ |
867 | size_t n; |
868 | for ( n = 0; n < WXSIZEOF(rasterOperations); n++ ) | |
81278df2 VZ |
869 | { |
870 | wxCoord x = 20 + 150*(n%4), | |
871 | y = 20 + 100*(n/4); | |
872 | ||
873 | dc.DrawText(rasterOperations[n].name, x, y - 20); | |
874 | dc.SetLogicalFunction(rasterOperations[n].rop); | |
11f26ea0 | 875 | dc.DrawRectangle(x, y, w, h); |
81278df2 VZ |
876 | dc.DrawLine(x, y, x + w, y + h); |
877 | dc.DrawLine(x + w, y, x, y + h); | |
878 | } | |
c1d139da GRG |
879 | |
880 | // now some filled rectangles | |
881 | dc.SetBrush(wxBrush(m_owner->m_colourForeground, wxSOLID)); | |
882 | ||
5888ef1e | 883 | for ( n = 0; n < WXSIZEOF(rasterOperations); n++ ) |
c1d139da GRG |
884 | { |
885 | wxCoord x = 20 + 150*(n%4), | |
886 | y = 500 + 100*(n/4); | |
887 | ||
888 | dc.DrawText(rasterOperations[n].name, x, y - 20); | |
889 | dc.SetLogicalFunction(rasterOperations[n].rop); | |
890 | dc.DrawRectangle(x, y, w, h); | |
891 | } | |
81278df2 VZ |
892 | } |
893 | ||
568708e2 VZ |
894 | void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) |
895 | { | |
896 | wxPaintDC dc(this); | |
897 | PrepareDC(dc); | |
898 | m_owner->PrepareDC(dc); | |
899 | ||
900 | dc.SetBackgroundMode( m_owner->m_backgroundMode ); | |
901 | if ( m_owner->m_backgroundBrush.Ok() ) | |
902 | dc.SetBackground( m_owner->m_backgroundBrush ); | |
903 | if ( m_owner->m_colourForeground.Ok() ) | |
904 | dc.SetTextForeground( m_owner->m_colourForeground ); | |
905 | if ( m_owner->m_colourBackground.Ok() ) | |
906 | dc.SetTextBackground( m_owner->m_colourBackground ); | |
4786aabd | 907 | |
1edc9f45 | 908 | if ( m_owner->m_textureBackground) { |
047473c9 | 909 | if ( ! m_owner->m_backgroundBrush.Ok() ) { |
1edc9f45 RD |
910 | wxBrush b(wxColour(0,128,0), wxSOLID); |
911 | dc.SetBackground(b); | |
912 | } | |
047473c9 RD |
913 | } |
914 | ||
915 | dc.Clear(); | |
1edc9f45 | 916 | |
047473c9 | 917 | if ( m_owner->m_textureBackground) { |
1edc9f45 RD |
918 | dc.SetPen(*wxMEDIUM_GREY_PEN); |
919 | for (int i=0; i<200; i++) | |
920 | dc.DrawLine(0, i*10, i*10, 0); | |
921 | } | |
922 | ||
568708e2 VZ |
923 | switch ( m_show ) |
924 | { | |
925 | case Show_Default: | |
926 | DrawDefault(dc); | |
927 | break; | |
1e7fd311 | 928 | |
568708e2 VZ |
929 | case Show_Text: |
930 | DrawText(dc); | |
931 | break; | |
1e7fd311 | 932 | |
568708e2 VZ |
933 | case Show_Lines: |
934 | DrawTestLines( 0, 100, 0, dc ); | |
935 | DrawTestLines( 0, 300, 1, dc ); | |
936 | DrawTestLines( 0, 500, 2, dc ); | |
937 | DrawTestLines( 0, 700, 6, dc ); | |
938 | break; | |
1e7fd311 | 939 | |
568708e2 VZ |
940 | case Show_Polygons: |
941 | DrawTestPoly( 0, 100, dc, 0 ); | |
942 | DrawTestPoly( 33, 500, dc, 1 ); | |
943 | DrawTestPoly( 43, 1000, dc, 2 ); | |
944 | break; | |
1e7fd311 | 945 | |
568708e2 VZ |
946 | case Show_Mask: |
947 | DrawImages(dc); | |
948 | break; | |
81278df2 VZ |
949 | |
950 | case Show_Ops: | |
951 | DrawWithLogicalOps(dc); | |
952 | break; | |
568708e2 | 953 | } |
b62c3631 RR |
954 | } |
955 | ||
bf0c00c6 RR |
956 | void MyCanvas::OnMouseMove(wxMouseEvent &event) |
957 | { | |
958 | wxClientDC dc(this); | |
959 | PrepareDC(dc); | |
960 | m_owner->PrepareDC(dc); | |
961 | ||
962 | wxPoint pos = event.GetPosition(); | |
963 | long x = dc.DeviceToLogicalX( pos.x ); | |
964 | long y = dc.DeviceToLogicalY( pos.y ); | |
965 | wxString str; | |
966 | str.Printf( "Current mouse position: %d,%d", (int)x, (int)y ); | |
967 | m_owner->SetStatusText( str ); | |
968 | } | |
969 | ||
b62c3631 RR |
970 | // ---------------------------------------------------------------------------- |
971 | // MyFrame | |
972 | // ---------------------------------------------------------------------------- | |
973 | ||
974 | // the event tables connect the wxWindows events with the functions (event | |
975 | // handlers) which process them. It can be also done at run-time, but for the | |
976 | // simple menu events like this the static method is much simpler. | |
977 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
568708e2 VZ |
978 | EVT_MENU (File_Quit, MyFrame::OnQuit) |
979 | EVT_MENU (File_About, MyFrame::OnAbout) | |
980 | ||
981 | EVT_MENU_RANGE(MenuShow_First, MenuShow_Last, MyFrame::OnShow) | |
982 | ||
b62c3631 RR |
983 | EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption) |
984 | END_EVENT_TABLE() | |
985 | ||
aba99005 RR |
986 | // frame constructor |
987 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
988 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
989 | { | |
990 | // set the frame icon | |
991 | SetIcon(wxICON(mondrian)); | |
992 | ||
993 | wxMenu *menuFile = new wxMenu; | |
568708e2 VZ |
994 | menuFile->Append(File_ShowDefault, "&Default screen\tF1"); |
995 | menuFile->Append(File_ShowText, "&Text screen\tF2"); | |
996 | menuFile->Append(File_ShowLines, "&Lines screen\tF3"); | |
997 | menuFile->Append(File_ShowPolygons, "&Polygons screen\tF4"); | |
998 | menuFile->Append(File_ShowMask, "wx&Mask screen\tF5"); | |
81278df2 | 999 | menuFile->Append(File_ShowOps, "&ROP screen\tF6"); |
568708e2 VZ |
1000 | menuFile->AppendSeparator(); |
1001 | menuFile->Append(File_About, "&About...\tCtrl-A", "Show about dialog"); | |
aba99005 | 1002 | menuFile->AppendSeparator(); |
568708e2 | 1003 | menuFile->Append(File_Quit, "E&xit\tAlt-X", "Quit this program"); |
0f0c61d0 | 1004 | |
aba99005 RR |
1005 | wxMenu *menuMapMode = new wxMenu; |
1006 | menuMapMode->Append( MapMode_Text, "&TEXT map mode" ); | |
1007 | menuMapMode->Append( MapMode_Lometric, "&LOMETRIC map mode" ); | |
1008 | menuMapMode->Append( MapMode_Twips, "T&WIPS map mode" ); | |
1009 | menuMapMode->Append( MapMode_Points, "&POINTS map mode" ); | |
1010 | menuMapMode->Append( MapMode_Metric, "&METRIC map mode" ); | |
0f0c61d0 | 1011 | |
aba99005 | 1012 | wxMenu *menuUserScale = new wxMenu; |
ed43910d RR |
1013 | menuUserScale->Append( UserScale_StretchHoriz, "Stretch horizontally\tCtrl-H" ); |
1014 | menuUserScale->Append( UserScale_ShrinkHoriz, "Shrink horizontally\tCtrl-G" ); | |
1015 | menuUserScale->Append( UserScale_StretchVertic, "Stretch vertically\tCtrl-V" ); | |
1016 | menuUserScale->Append( UserScale_ShrinkVertic, "Shrink vertically\tCtrl-W" ); | |
0f0c61d0 VZ |
1017 | menuUserScale->AppendSeparator(); |
1018 | menuUserScale->Append( UserScale_Restore, "Restore to normal\tCtrl-0" ); | |
1019 | ||
aba99005 | 1020 | wxMenu *menuAxis = new wxMenu; |
220af862 VZ |
1021 | menuAxis->Append( AxisMirror_Horiz, "Mirror horizontally\tCtrl-M", "", TRUE ); |
1022 | menuAxis->Append( AxisMirror_Vertic, "Mirror vertically\tCtrl-N", "", TRUE ); | |
0f0c61d0 | 1023 | |
aba99005 RR |
1024 | wxMenu *menuLogical = new wxMenu; |
1025 | menuLogical->Append( LogicalOrigin_MoveDown, "Move &down\tCtrl-D" ); | |
1026 | menuLogical->Append( LogicalOrigin_MoveUp, "Move &up\tCtrl-U" ); | |
1027 | menuLogical->Append( LogicalOrigin_MoveLeft, "Move &right\tCtrl-L" ); | |
1028 | menuLogical->Append( LogicalOrigin_MoveRight, "Move &left\tCtrl-R" ); | |
1029 | ||
0f0c61d0 VZ |
1030 | wxMenu *menuColour = new wxMenu; |
1031 | menuColour->Append( Colour_TextForeground, "Text foreground..." ); | |
1032 | menuColour->Append( Colour_TextBackground, "Text background..." ); | |
1033 | menuColour->Append( Colour_Background, "Background colour..." ); | |
1034 | menuColour->Append( Colour_BackgroundMode, "Opaque/transparent\tCtrl-B", "", TRUE ); | |
1edc9f45 | 1035 | menuColour->Append( Colour_TextureBackgound, "Draw textured background\tCtrl-T", "", TRUE); |
0f0c61d0 | 1036 | |
aba99005 RR |
1037 | // now append the freshly created menu to the menu bar... |
1038 | wxMenuBar *menuBar = new wxMenuBar; | |
1039 | menuBar->Append(menuFile, "&File"); | |
1040 | menuBar->Append(menuMapMode, "&MapMode"); | |
1041 | menuBar->Append(menuUserScale, "&UserScale"); | |
1042 | menuBar->Append(menuAxis, "&Axis"); | |
1043 | menuBar->Append(menuLogical, "&LogicalOrigin"); | |
0f0c61d0 | 1044 | menuBar->Append(menuColour, "&Colours"); |
aba99005 RR |
1045 | |
1046 | // ... and attach this menu bar to the frame | |
1047 | SetMenuBar(menuBar); | |
1048 | ||
1049 | // create a status bar just for fun (by default with 1 pane only) | |
1050 | CreateStatusBar(2); | |
1051 | SetStatusText("Welcome to wxWindows!"); | |
0f0c61d0 | 1052 | |
aba99005 RR |
1053 | m_mapMode = wxMM_TEXT; |
1054 | m_xUserScale = 1.0; | |
1055 | m_yUserScale = 1.0; | |
1056 | m_xLogicalOrigin = 0; | |
1057 | m_yLogicalOrigin = 0; | |
0f0c61d0 VZ |
1058 | m_xAxisReversed = |
1059 | m_yAxisReversed = FALSE; | |
1060 | m_backgroundMode = wxSOLID; | |
b97fa7cf VZ |
1061 | m_colourForeground = *wxRED; |
1062 | m_colourBackground = *wxBLUE; | |
1edc9f45 | 1063 | m_textureBackground = FALSE; |
aba99005 | 1064 | |
b62c3631 | 1065 | m_canvas = new MyCanvas( this ); |
b97fa7cf | 1066 | m_canvas->SetScrollbars( 10, 10, 100, 240 ); |
b62c3631 | 1067 | } |
aba99005 RR |
1068 | |
1069 | // event handlers | |
1070 | ||
1071 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
1072 | { | |
1073 | // TRUE is to force the frame to close | |
1074 | Close(TRUE); | |
1075 | } | |
1076 | ||
1077 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
1078 | { | |
1079 | wxString msg; | |
c916e13b RR |
1080 | msg.Printf( wxT("This is the about dialog of the drawing sample.\n") |
1081 | wxT("This sample tests various primitive drawing functions\n") | |
1082 | wxT("without any tests to prevent flicker.\n") | |
1083 | wxT("Copyright (c) Robert Roebling 1999") | |
aba99005 RR |
1084 | ); |
1085 | ||
1086 | wxMessageBox(msg, "About Drawing", wxOK | wxICON_INFORMATION, this); | |
1087 | } | |
1088 | ||
568708e2 VZ |
1089 | void MyFrame::OnShow(wxCommandEvent& event) |
1090 | { | |
1091 | m_canvas->Show((ScreenToShow)(event.GetInt() - MenuShow_First)); | |
1092 | } | |
1093 | ||
1094 | void MyFrame::OnOption(wxCommandEvent& event) | |
aba99005 RR |
1095 | { |
1096 | switch (event.GetInt()) | |
1097 | { | |
1098 | case MapMode_Text: | |
b9857632 | 1099 | m_mapMode = wxMM_TEXT; |
0f0c61d0 | 1100 | break; |
aba99005 RR |
1101 | case MapMode_Lometric: |
1102 | m_mapMode = wxMM_LOMETRIC; | |
0f0c61d0 VZ |
1103 | break; |
1104 | case MapMode_Twips: | |
aba99005 | 1105 | m_mapMode = wxMM_TWIPS; |
0f0c61d0 VZ |
1106 | break; |
1107 | case MapMode_Points: | |
aba99005 | 1108 | m_mapMode = wxMM_POINTS; |
0f0c61d0 VZ |
1109 | break; |
1110 | case MapMode_Metric: | |
aba99005 | 1111 | m_mapMode = wxMM_METRIC; |
0f0c61d0 VZ |
1112 | break; |
1113 | ||
1114 | case LogicalOrigin_MoveDown: | |
1115 | m_yLogicalOrigin += 10; | |
1116 | break; | |
1117 | case LogicalOrigin_MoveUp: | |
1118 | m_yLogicalOrigin -= 10; | |
1119 | break; | |
1120 | case LogicalOrigin_MoveLeft: | |
1121 | m_xLogicalOrigin += 10; | |
1122 | break; | |
1123 | case LogicalOrigin_MoveRight: | |
1124 | m_xLogicalOrigin -= 10; | |
1125 | break; | |
1126 | ||
1127 | case UserScale_StretchHoriz: | |
1128 | m_xUserScale *= 1.10; | |
1129 | break; | |
1130 | case UserScale_ShrinkHoriz: | |
1131 | m_xUserScale /= 1.10; | |
1132 | break; | |
1133 | case UserScale_StretchVertic: | |
1134 | m_yUserScale *= 1.10; | |
1135 | break; | |
1136 | case UserScale_ShrinkVertic: | |
1137 | m_yUserScale /= 1.10; | |
1138 | break; | |
1139 | case UserScale_Restore: | |
1140 | m_xUserScale = | |
1141 | m_yUserScale = 1.0; | |
1142 | break; | |
1143 | ||
1144 | case AxisMirror_Vertic: | |
1145 | m_yAxisReversed = !m_yAxisReversed; | |
1146 | break; | |
1147 | case AxisMirror_Horiz: | |
1148 | m_xAxisReversed = !m_xAxisReversed; | |
1149 | break; | |
1150 | ||
1151 | case Colour_TextForeground: | |
1152 | m_colourForeground = SelectColour(); | |
1153 | break; | |
1154 | case Colour_TextBackground: | |
1155 | m_colourBackground = SelectColour(); | |
1156 | break; | |
1157 | case Colour_Background: | |
1158 | { | |
1159 | wxColour col = SelectColour(); | |
1160 | if ( col.Ok() ) | |
1161 | { | |
1162 | m_backgroundBrush.SetColour(col); | |
1163 | } | |
1164 | } | |
1165 | break; | |
1166 | case Colour_BackgroundMode: | |
1167 | m_backgroundMode = m_backgroundMode == wxSOLID ? wxTRANSPARENT | |
1168 | : wxSOLID; | |
1169 | break; | |
1170 | ||
1edc9f45 RD |
1171 | case Colour_TextureBackgound: |
1172 | m_textureBackground = ! m_textureBackground; | |
1173 | break; | |
1174 | ||
0f0c61d0 VZ |
1175 | default: |
1176 | // skip Refresh() | |
1177 | return; | |
aba99005 | 1178 | } |
0f0c61d0 | 1179 | |
1e7fd311 | 1180 | m_canvas->Refresh(); |
aba99005 RR |
1181 | } |
1182 | ||
220af862 | 1183 | void MyFrame::PrepareDC(wxDC& dc) |
aba99005 | 1184 | { |
0f0c61d0 VZ |
1185 | dc.SetMapMode( m_mapMode ); |
1186 | dc.SetUserScale( m_xUserScale, m_yUserScale ); | |
1187 | dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin ); | |
428db2ea | 1188 | dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed ); |
220af862 VZ |
1189 | } |
1190 | ||
220af862 | 1191 | wxColour MyFrame::SelectColour() |
0f0c61d0 VZ |
1192 | { |
1193 | wxColour col; | |
1194 | wxColourData data; | |
1195 | wxColourDialog dialog(this, &data); | |
1196 | ||
1197 | if ( dialog.ShowModal() == wxID_OK ) | |
1198 | { | |
428db2ea | 1199 | col = dialog.GetColourData().GetColour(); |
0f0c61d0 VZ |
1200 | } |
1201 | ||
1202 | return col; | |
aba99005 | 1203 | } |