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