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