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