1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: shows and tests wxDC features
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "drawing.cpp"
22 #pragma interface "drawing.cpp"
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers
38 #include "wx/colordlg.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 // the application icon
46 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
47 #include "mondrian.xpm"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 // what do we show on screen (there are too many shapes to put them all on
55 // screen simultaneously)
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 static wxBitmap
*gs_bmpNoMask
= NULL
,
73 *gs_bmpWithColMask
= NULL
,
75 *gs_bmpWithMask
= NULL
,
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 // Define a new application type, each program should derive a class from wxApp
85 class MyApp
: public wxApp
88 // override base class virtuals
89 // ----------------------------
91 // this one is called on application startup and is a good place for the app
92 // initialization (doing it here and not in the ctor allows to have an error
93 // return: if OnInit() returns false, the application terminates)
94 virtual bool OnInit();
96 virtual int OnExit() { DeleteBitmaps(); return 0; }
106 // Define a new frame type: this is going to be our main frame
107 class MyFrame
: public wxFrame
111 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
113 // event handlers (these functions should _not_ be virtual)
114 void OnQuit(wxCommandEvent
& event
);
115 void OnAbout(wxCommandEvent
& event
);
116 void OnShow(wxCommandEvent
&event
);
117 void OnOption(wxCommandEvent
&event
);
119 wxColour
SelectColour();
120 void PrepareDC(wxDC
& dc
);
122 int m_backgroundMode
;
123 int m_textureBackground
;
127 int m_xLogicalOrigin
;
128 int m_yLogicalOrigin
;
129 bool m_xAxisReversed
,
131 wxColour m_colourForeground
, // these are _text_ colours
133 wxBrush m_backgroundBrush
;
137 // any class wishing to process wxWindows events must use this macro
138 DECLARE_EVENT_TABLE()
141 // define a scrollable canvas for drawing onto
142 class MyCanvas
: public wxScrolledWindow
145 MyCanvas( MyFrame
*parent
);
147 void OnPaint(wxPaintEvent
&event
);
148 void OnMouseMove(wxMouseEvent
&event
);
150 void Show(ScreenToShow show
) { m_show
= show
; Refresh(); }
153 void DrawTestPoly( int x
, int y
, wxDC
&dc
,int transparent
);
154 void DrawTestLines( int x
, int y
, int width
, wxDC
&dc
);
155 void DrawText(wxDC
& dc
);
156 void DrawImages(wxDC
& dc
);
157 void DrawWithLogicalOps(wxDC
& dc
);
158 void DrawRegions(wxDC
& dc
);
159 void DrawCircles(wxDC
& dc
);
160 void DrawDefault(wxDC
& dc
);
162 void DrawRegionsHelper(wxDC
& dc
, wxCoord x
);
168 wxBitmap m_smile_bmp
;
171 DECLARE_EVENT_TABLE()
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 // IDs for the controls and the menu commands
186 File_ShowDefault
= MenuShow_First
,
194 MenuShow_Last
= File_ShowCircles
,
198 MapMode_Text
= MenuOption_First
,
204 UserScale_StretchHoriz
,
205 UserScale_ShrinkHoriz
,
206 UserScale_StretchVertic
,
207 UserScale_ShrinkVertic
,
213 LogicalOrigin_MoveDown
,
214 LogicalOrigin_MoveUp
,
215 LogicalOrigin_MoveLeft
,
216 LogicalOrigin_MoveRight
,
218 Colour_TextForeground
,
219 Colour_TextBackground
,
221 Colour_BackgroundMode
,
222 Colour_TextureBackgound
,
224 MenuOption_Last
= Colour_TextureBackgound
227 // ----------------------------------------------------------------------------
228 // event tables and other macros for wxWindows
229 // ----------------------------------------------------------------------------
232 // Create a new application object: this macro will allow wxWindows to create
233 // the application object during program execution (it's better than using a
234 // static object for many reasons) and also declares the accessor function
235 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
239 // ============================================================================
241 // ============================================================================
243 // ----------------------------------------------------------------------------
244 // the application class
245 // ----------------------------------------------------------------------------
247 bool MyApp::LoadImages()
249 gs_bmpNoMask
= new wxBitmap
;
250 gs_bmpWithColMask
= new wxBitmap
;
251 gs_bmpMask
= new wxBitmap
;
252 gs_bmpWithMask
= new wxBitmap
;
253 gs_bmp4
= new wxBitmap
;
254 gs_bmp4_mono
= new wxBitmap
;
255 gs_bmp36
= new wxBitmap
;
261 wxString path
= pathList
.FindValidPath("pat4.bmp");
265 /* 4 colour bitmap */
266 gs_bmp4
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
267 /* turn into mono-bitmap */
268 gs_bmp4_mono
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
269 wxMask
* mask4
= new wxMask(*gs_bmp4_mono
, *wxBLACK
);
270 gs_bmp4_mono
->SetMask(mask4
);
272 path
= pathList
.FindValidPath("pat36.bmp");
275 gs_bmp36
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
276 wxMask
* mask36
= new wxMask(*gs_bmp36
, *wxBLACK
);
277 gs_bmp36
->SetMask(mask36
);
279 path
= pathList
.FindValidPath("image.bmp");
282 gs_bmpNoMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
283 gs_bmpWithMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
284 gs_bmpWithColMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
286 path
= pathList
.FindValidPath("mask.bmp");
289 gs_bmpMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
291 wxMask
*mask
= new wxMask(*gs_bmpMask
, *wxBLACK
);
292 gs_bmpWithMask
->SetMask(mask
);
294 mask
= new wxMask(*gs_bmpWithColMask
, *wxWHITE
);
295 gs_bmpWithColMask
->SetMask(mask
);
300 // `Main program' equivalent: the program execution "starts" here
303 // Create the main application window
304 MyFrame
*frame
= new MyFrame("Drawing sample",
305 wxPoint(50, 50), wxSize(550, 340));
307 // Show it and tell the application that it's our main window
313 wxLogError(wxT("Can't load one of the bitmap files needed ")
314 wxT("for this sample from the current or parent ")
315 wxT("directory, please copy them there."));
327 void MyApp::DeleteBitmaps()
330 delete gs_bmpWithColMask
;
332 delete gs_bmpWithMask
;
338 gs_bmpWithColMask
= NULL
;
340 gs_bmpWithMask
= NULL
;
346 // ----------------------------------------------------------------------------
348 // ----------------------------------------------------------------------------
350 // the event tables connect the wxWindows events with the functions (event
351 // handlers) which process them.
352 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
353 EVT_PAINT (MyCanvas::OnPaint
)
354 EVT_MOTION (MyCanvas::OnMouseMove
)
359 MyCanvas::MyCanvas(MyFrame
*parent
)
360 : wxScrolledWindow(parent
, -1, wxDefaultPosition
, wxDefaultSize
,
361 wxHSCROLL
| wxVSCROLL
| wxNO_FULL_REPAINT_ON_RESIZE
)
364 m_show
= Show_Default
;
365 m_smile_bmp
= wxBitmap(smile_xpm
);
366 m_std_icon
= wxTheApp
->GetStdIcon(wxICON_INFORMATION
);
369 // Draw a polygon and an overlapping rectangle
370 // If transparent is 1, the fill pattern is made transparent.
371 // If transparent is 2, the fill pattern is made transparent but inversed
372 // If is transparent is 0 the text for and background color will be used to represent/map
373 // the colors of the monochrome bitmap pixels to the fillpattern
375 // I abused the the menu items for setting so called back and fore ground color
376 // just to show how the those colors do influence the fillpatterns just play
377 // with those, and with the code variations are endless using other logical
380 void MyCanvas::DrawTestPoly( int x
, int y
,wxDC
&dc
,int transparent
)
382 // wxBrush* brush4 = new wxBrush(*gs_bmp4);
383 wxBrush
* brush4
= new wxBrush(*wxBLACK
,wxFDIAGONAL_HATCH
);
384 wxBrush
* brush4_mono
= new wxBrush(*gs_bmp4_mono
);
385 wxBrush
* brush36
= new wxBrush(*gs_bmp36
);
388 todraw
[0].x
=(long)x
+100;
389 todraw
[0].y
=(long)y
+100;
390 todraw
[1].x
=(long)x
+300;
391 todraw
[1].y
=(long)y
+100;
392 todraw
[2].x
=(long)x
+300;
393 todraw
[2].y
=(long)y
+300;
394 todraw
[3].x
=(long)x
+150;
395 todraw
[3].y
=(long)y
+350;
396 todraw
[4].x
=(long)x
+100;
397 todraw
[4].y
=(long)y
+300;
415 dc
.SetLogicalFunction(wxCOPY
);
417 dc
.SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
418 dc
.SetBrush( *brush4
);
419 dc
.DrawPolygon(5,todraw
,0,0,wxWINDING_RULE
);
421 dc
.SetPen( wxPen( wxT("red"), 4, wxSOLID
) );
422 dc
.SetBrush( *brush36
);
423 dc
.SetTextForeground(*wxCYAN
);
424 dc
.SetTextBackground(m_owner
->m_colourBackground
);
425 dc
.DrawRectangle( x
+10, y
+10, 200, 200 );
427 dc
.SetPen( wxPen( wxT("green"), 4, wxSOLID
) );
428 dc
.SetBrush( *brush4_mono
);
429 dc
.SetTextForeground(*wxCYAN
);
430 dc
.SetTextBackground(m_owner
->m_colourBackground
);
431 dc
.DrawRectangle( x
+50, y
+50, 200, 200 );
433 dc
.DrawCircle( x
+400, y
+50, 130 );
435 dc
.SetBrush(wxNullBrush
);
436 dc
.SetPen(wxNullPen
);
439 case 1: //now with transparent fillpatterns
442 wxBitmap
* bmpBlit
= new wxBitmap(600,400);
443 wxMemoryDC
* memDC
= new wxMemoryDC();
444 // wxBrush _clearbrush(*wxGREEN,wxSOLID);
445 wxBrush
_clearbrush(*wxBLACK
,wxSOLID
);
446 memDC
->SelectObject(*bmpBlit
);
447 memDC
->BeginDrawing();
448 memDC
->SetBackground(_clearbrush
);
450 memDC
->SetBackground(wxNullBrush
);
452 memDC
->SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
453 memDC
->SetBrush( wxNullBrush
);
454 memDC
->SetBrush( *brush4
);
455 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
456 memDC
->SetTextBackground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
457 memDC
->SetLogicalFunction(wxAND_INVERT
);
459 // BLACK OUT the opaque pixels and leave the rest as is
460 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
462 // Set background and foreground colors for fill pattern
463 //the previous blacked out pixels are now merged with the layer color
464 //while the non blacked out pixels stay as they are.
465 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
467 //now define what will be the color of the fillpattern parts that are not transparent
468 // memDC->SetTextBackground(*wxBLUE);
469 memDC
->SetTextBackground(m_owner
->m_colourForeground
);
470 memDC
->SetLogicalFunction(wxOR
);
473 //don't understand how but the outline is also depending on logicalfunction
474 memDC
->SetPen( wxPen( wxT("red"), 4, wxSOLID
) );
475 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
477 memDC
->SetLogicalFunction(wxCOPY
);
479 memDC
->SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
480 memDC
->SetBrush( wxNullBrush
);
481 memDC
->SetBrush( *brush36
);
482 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
483 memDC
->SetTextBackground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
484 memDC
->SetLogicalFunction(wxAND_INVERT
);
486 memDC
->DrawRectangle( 10, 10, 200, 200 );
488 // Set background and foreground colors for fill pattern
489 //the previous blacked out pixels are now merged with the layer color
490 //while the non blacked out pixels stay as they are.
491 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
492 //now define what will be the color of the fillpattern parts that are not transparent
493 // memDC->SetTextBackground(*wxRED);
494 memDC
->SetTextBackground(m_owner
->m_colourBackground
);
495 memDC
->SetLogicalFunction(wxOR
);
497 //don't understand how but the outline is also depending on logicalfunction
498 memDC
->SetPen( wxPen( wxT("yellow"), 4, wxSOLID
) );
499 memDC
->DrawRectangle( 10, 10, 200, 200 );
501 memDC
->SetBrush(wxNullBrush
);
502 memDC
->SetPen(wxNullPen
);
505 dc
.Blit(x
,y
,600,400,memDC
,0,0,wxCOPY
);
510 case 2: //now with transparent inversed fillpatterns
512 wxBitmap
* bmpBlit
= new wxBitmap(600,400);
513 wxMemoryDC
* memDC
= new wxMemoryDC();
514 wxBrush
_clearbrush(*wxWHITE
,wxSOLID
);
515 memDC
->SelectObject(*bmpBlit
);
516 memDC
->BeginDrawing();
517 memDC
->SetBackground(_clearbrush
);
519 memDC
->SetBackground(wxNullBrush
);
521 memDC
->SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
522 memDC
->SetBrush( *brush4
);
523 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
524 memDC
->SetTextForeground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
525 memDC
->SetLogicalFunction(wxAND_INVERT
);
527 // BLACK OUT the opaque pixels and leave the rest as is
528 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
530 // Set background and foreground colors for fill pattern
531 //the previous blacked out pixels are now merged with the layer color
532 //while the non blacked out pixels stay as they are.
533 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
535 //now define what will be the color of the fillpattern parts that are not transparent
536 memDC
->SetTextForeground(m_owner
->m_colourForeground
);
537 memDC
->SetLogicalFunction(wxOR
);
540 //don't understand how but the outline is also depending on logicalfunction
541 memDC
->SetPen( wxPen( wxT("red"), 4, wxSOLID
) );
542 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
544 memDC
->SetLogicalFunction(wxCOPY
);
546 memDC
->SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
547 memDC
->SetBrush( *brush36
);
548 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
549 memDC
->SetTextForeground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
550 memDC
->SetLogicalFunction(wxAND_INVERT
);
552 memDC
->DrawRectangle( 10,10, 200, 200 );
554 // Set background and foreground colors for fill pattern
555 //the previous blacked out pixels are now merged with the layer color
556 //while the non blacked out pixels stay as they are.
557 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
558 //now define what will be the color of the fillpattern parts that are not transparent
559 memDC
->SetTextForeground(m_owner
->m_colourBackground
);
560 memDC
->SetLogicalFunction(wxOR
);
562 //don't understand how but the outline is also depending on logicalfunction
563 memDC
->SetPen( wxPen( wxT("yellow"), 4, wxSOLID
) );
564 memDC
->DrawRectangle( 10, 10, 200, 200 );
566 memDC
->SetBrush(wxNullBrush
);
567 memDC
->SetPen(wxNullPen
);
568 dc
.Blit(x
,y
,600,400,memDC
,0,0,wxCOPY
);
579 void MyCanvas::DrawTestLines( int x
, int y
, int width
, wxDC
&dc
)
581 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
582 dc
.SetBrush( *wxRED_BRUSH
);
583 dc
.DrawText(wxString::Format(wxT("Testing lines of width %d"), width
), x
+ 10, y
- 10);
584 dc
.DrawRectangle( x
+10, y
+10, 100, 190 );
586 dc
.DrawText("Solid/dot/short dash/long dash/dot dash", x
+ 150, y
+ 10);
587 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
588 dc
.DrawLine( x
+20, y
+20, 100, y
+20 );
589 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT
) );
590 dc
.DrawLine( x
+20, y
+30, 100, y
+30 );
591 dc
.SetPen( wxPen( wxT("black"), width
, wxSHORT_DASH
) );
592 dc
.DrawLine( x
+20, y
+40, 100, y
+40 );
593 dc
.SetPen( wxPen( wxT("black"), width
, wxLONG_DASH
) );
594 dc
.DrawLine( x
+20, y
+50, 100, y
+50 );
595 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT_DASH
) );
596 dc
.DrawLine( x
+20, y
+60, 100, y
+60 );
598 dc
.DrawText("Misc hatches", x
+ 150, y
+ 70);
599 dc
.SetPen( wxPen( wxT("black"), width
, wxBDIAGONAL_HATCH
) );
600 dc
.DrawLine( x
+20, y
+70, 100, y
+70 );
601 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSSDIAG_HATCH
) );
602 dc
.DrawLine( x
+20, y
+80, 100, y
+80 );
603 dc
.SetPen( wxPen( wxT("black"), width
, wxFDIAGONAL_HATCH
) );
604 dc
.DrawLine( x
+20, y
+90, 100, y
+90 );
605 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSS_HATCH
) );
606 dc
.DrawLine( x
+20, y
+100, 100, y
+100 );
607 dc
.SetPen( wxPen( wxT("black"), width
, wxHORIZONTAL_HATCH
) );
608 dc
.DrawLine( x
+20, y
+110, 100, y
+110 );
609 dc
.SetPen( wxPen( wxT("black"), width
, wxVERTICAL_HATCH
) );
610 dc
.DrawLine( x
+20, y
+120, 100, y
+120 );
612 dc
.DrawText("User dash", x
+ 150, y
+ 140);
613 wxPen
ud( wxT("black"), width
, wxUSER_DASH
);
616 ud
.SetDashes( 1, dash1
);
617 dc
.DrawLine( x
+20, y
+140, 100, y
+140 );
619 ud
.SetDashes( 1, dash1
);
620 dc
.DrawLine( x
+20, y
+150, 100, y
+150 );
622 ud
.SetDashes( 1, dash1
);
623 dc
.DrawLine( x
+20, y
+160, 100, y
+160 );
625 ud
.SetDashes( 1, dash1
);
626 dc
.DrawLine( x
+20, y
+170, 100, y
+170 );
629 void MyCanvas::DrawDefault(wxDC
& dc
)
632 dc
.DrawCircle(0, 0, 10);
633 #if !(defined __WXGTK__) && !(defined __WXMOTIF__) && !(defined __WXMGL__)
634 // not implemented in wxGTK or wxMOTIF :-(
635 dc
.FloodFill(0, 0, wxColour(255, 0, 0));
638 dc
.DrawCheckMark(5, 80, 15, 15);
639 dc
.DrawCheckMark(25, 80, 30, 30);
640 dc
.DrawCheckMark(60, 80, 60, 60);
642 // this is the test for "blitting bitmap into DC damages selected brush" bug
643 wxCoord rectSize
= m_std_icon
.GetWidth() + 10;
645 dc
.SetPen(*wxTRANSPARENT_PEN
);
646 dc
.SetBrush( *wxGREEN_BRUSH
);
647 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
648 dc
.DrawBitmap(m_std_icon
, x
+ 5, 15, TRUE
);
650 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
651 dc
.DrawIcon(m_std_icon
, x
+ 5, 15);
653 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
655 // test for "transparent" bitmap drawing (it intersects with the last
657 //dc.SetBrush( *wxTRANSPARENT_BRUSH );
659 if (m_smile_bmp
.Ok())
660 dc
.DrawBitmap(m_smile_bmp
, x
+ rectSize
- 20, rectSize
- 10, TRUE
);
662 dc
.SetBrush( *wxBLACK_BRUSH
);
663 dc
.DrawRectangle( 0, 160, 1000, 300 );
666 wxBitmap
bitmap(20,70);
668 memdc
.SelectObject( bitmap
);
669 memdc
.SetBrush( *wxBLACK_BRUSH
);
670 memdc
.SetPen( *wxWHITE_PEN
);
671 memdc
.DrawRectangle(0,0,20,70);
672 memdc
.DrawLine( 10,0,10,70 );
675 wxPen pen
= *wxRED_PEN
;
677 memdc
.DrawLine( 10, 5,10, 5 );
678 memdc
.DrawLine( 10,10,11,10 );
679 memdc
.DrawLine( 10,15,12,15 );
680 memdc
.DrawLine( 10,20,13,20 );
683 memdc.SetPen(*wxRED_PEN);
684 memdc.DrawLine( 12, 5,12, 5 );
685 memdc.DrawLine( 12,10,13,10 );
686 memdc.DrawLine( 12,15,14,15 );
687 memdc.DrawLine( 12,20,15,20 );
691 memdc
.DrawLine( 10,25,10,25 );
692 memdc
.DrawLine( 10,30, 9,30 );
693 memdc
.DrawLine( 10,35, 8,35 );
694 memdc
.DrawLine( 10,40, 7,40 );
697 dc
.SetPen(*wxWHITE_PEN
);
698 memdc
.SetLogicalFunction( wxINVERT
);
699 memdc
.SetPen( *wxWHITE_PEN
);
700 memdc
.DrawLine( 10,50,10,50 );
701 memdc
.DrawLine( 10,55,11,55 );
702 memdc
.DrawLine( 10,60,12,60 );
703 memdc
.DrawLine( 10,65,13,65 );
705 memdc
.DrawLine( 12,50,12,50 );
706 memdc
.DrawLine( 12,55,13,55 );
707 memdc
.DrawLine( 12,60,14,60 );
708 memdc
.DrawLine( 12,65,15,65 );
710 memdc
.SelectObject( wxNullBitmap
);
711 dc
.DrawBitmap( bitmap
, 10, 170 );
712 wxImage
image( bitmap
);
713 image
.Rescale( 60,210 );
714 bitmap
= image
.ConvertToBitmap();
715 dc
.DrawBitmap( bitmap
, 50, 170 );
717 // test the rectangle outline drawing - there should be one pixel between
718 // the rect and the lines
719 dc
.SetPen(*wxWHITE_PEN
);
720 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
721 dc
.DrawRectangle(150, 170, 49, 29);
722 dc
.DrawRectangle(200, 170, 49, 29);
723 dc
.SetPen(*wxWHITE_PEN
);
724 dc
.DrawLine(250, 210, 250, 170);
725 dc
.DrawLine(260, 200, 150, 200);
727 // test the rectangle filled drawing - there should be one pixel between
728 // the rect and the lines
729 dc
.SetPen(*wxTRANSPARENT_PEN
);
730 dc
.SetBrush( *wxWHITE_BRUSH
);
731 dc
.DrawRectangle(300, 170, 49, 29);
732 dc
.DrawRectangle(350, 170, 49, 29);
733 dc
.SetPen(*wxWHITE_PEN
);
734 dc
.DrawLine(400, 170, 400, 210);
735 dc
.DrawLine(300, 200, 410, 200);
737 // a few more tests of this kind
738 dc
.SetPen(*wxRED_PEN
);
739 dc
.SetBrush( *wxWHITE_BRUSH
);
740 dc
.DrawRectangle(300, 220, 1, 1);
741 dc
.DrawRectangle(310, 220, 2, 2);
742 dc
.DrawRectangle(320, 220, 3, 3);
743 dc
.DrawRectangle(330, 220, 4, 4);
745 dc
.SetPen(*wxTRANSPARENT_PEN
);
746 dc
.SetBrush( *wxWHITE_BRUSH
);
747 dc
.DrawRectangle(300, 230, 1, 1);
748 dc
.DrawRectangle(310, 230, 2, 2);
749 dc
.DrawRectangle(320, 230, 3, 3);
750 dc
.DrawRectangle(330, 230, 4, 4);
752 // and now for filled rect with outline
753 dc
.SetPen(*wxRED_PEN
);
754 dc
.SetBrush( *wxWHITE_BRUSH
);
755 dc
.DrawRectangle(500, 170, 49, 29);
756 dc
.DrawRectangle(550, 170, 49, 29);
757 dc
.SetPen(*wxWHITE_PEN
);
758 dc
.DrawLine(600, 170, 600, 210);
759 dc
.DrawLine(500, 200, 610, 200);
761 // test the rectangle outline drawing - there should be one pixel between
762 // the rect and the lines
763 dc
.SetPen(*wxWHITE_PEN
);
764 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
765 dc
.DrawRoundedRectangle(150, 270, 49, 29, 6);
766 dc
.DrawRoundedRectangle(200, 270, 49, 29, 6);
767 dc
.SetPen(*wxWHITE_PEN
);
768 dc
.DrawLine(250, 270, 250, 310);
769 dc
.DrawLine(150, 300, 260, 300);
771 // test the rectangle filled drawing - there should be one pixel between
772 // the rect and the lines
773 dc
.SetPen(*wxTRANSPARENT_PEN
);
774 dc
.SetBrush( *wxWHITE_BRUSH
);
775 dc
.DrawRoundedRectangle(300, 270, 49, 29, 6);
776 dc
.DrawRoundedRectangle(350, 270, 49, 29, 6);
777 dc
.SetPen(*wxWHITE_PEN
);
778 dc
.DrawLine(400, 270, 400, 310);
779 dc
.DrawLine(300, 300, 410, 300);
781 // Added by JACS to demonstrate bizarre behaviour.
782 // With a size of 70, we get a missing red RHS,
783 // and the hight is too small, so we get yellow
784 // showing. With a size of 40, it draws as expected:
785 // it just shows a white rectangle with red outline.
787 int totalHeight
= 70;
788 wxBitmap
bitmap2(totalWidth
, totalHeight
);
791 memdc2
.SelectObject(bitmap2
);
793 wxBrush
yellowBrush(wxColour(255, 255, 0), wxSOLID
);
794 memdc2
.SetBackground(yellowBrush
);
797 wxPen
yellowPen(wxColour(255, 255, 0), 1, wxSOLID
);
799 // Now draw a white rectangle with red outline. It should
800 // entirely eclipse the yellow background.
801 memdc2
.SetPen(*wxRED_PEN
);
802 memdc2
.SetBrush(*wxWHITE_BRUSH
);
804 memdc2
.DrawRectangle(0, 0, totalWidth
, totalHeight
);
806 memdc2
.SetPen(wxNullPen
);
807 memdc2
.SetBrush(wxNullBrush
);
808 memdc2
.SelectObject(wxNullBitmap
);
810 dc
.DrawBitmap(bitmap2
, 500, 270);
812 // Repeat, but draw directly on dc
813 // Draw a yellow rectangle filling the bitmap
815 x
= 600; int y
= 270;
816 dc
.SetPen(yellowPen
);
817 dc
.SetBrush(yellowBrush
);
818 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
820 // Now draw a white rectangle with red outline. It should
821 // entirely eclipse the yellow background.
822 dc
.SetPen(*wxRED_PEN
);
823 dc
.SetBrush(*wxWHITE_BRUSH
);
825 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
828 void MyCanvas::DrawText(wxDC
& dc
)
830 // set underlined font for testing
831 dc
.SetFont( wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, TRUE
) );
832 dc
.DrawText( "This is text", 110, 10 );
833 dc
.DrawRotatedText( "That is text", 20, 10, -45 );
835 // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
836 // under Win9x (it is not TrueType)
837 dc
.SetFont( *wxSWISS_FONT
);
840 dc
.SetBackgroundMode(wxTRANSPARENT
);
842 for ( int n
= -180; n
< 180; n
+= 30 )
844 text
.Printf(wxT(" %d rotated text"), n
);
845 dc
.DrawRotatedText(text
, 400, 400, n
);
848 dc
.SetFont( wxFont( 18, wxSWISS
, wxNORMAL
, wxNORMAL
) );
850 dc
.DrawText( "This is Swiss 18pt text.", 110, 40 );
855 dc
.GetTextExtent( "This is Swiss 18pt text.", &length
, &height
, &descent
);
856 text
.Printf( wxT("Dimensions are length %ld, height %ld, descent %ld"), length
, height
, descent
);
857 dc
.DrawText( text
, 110, 80 );
859 text
.Printf( wxT("CharHeight() returns: %d"), dc
.GetCharHeight() );
860 dc
.DrawText( text
, 110, 120 );
862 dc
.DrawRectangle( 100, 40, 4, height
);
864 // test the logical function effect
866 dc
.SetLogicalFunction(wxINVERT
);
867 dc
.DrawText( "There should be no text below", 110, 150 );
868 dc
.DrawRectangle( 110, y
, 100, height
);
870 // twice drawn inverted should result in invisible
872 dc
.DrawText( "Invisible text", 110, y
);
873 dc
.DrawRectangle( 110, y
, 100, height
);
874 dc
.DrawText( "Invisible text", 110, y
);
875 dc
.DrawRectangle( 110, y
, 100, height
);
876 dc
.SetLogicalFunction(wxCOPY
);
879 dc
.DrawRectangle( 110, y
, 100, height
);
880 dc
.DrawText( "Visible text", 110, y
);
887 } rasterOperations
[] =
889 { wxT("wxAND"), wxAND
},
890 { wxT("wxAND_INVERT"), wxAND_INVERT
},
891 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
892 { wxT("wxCLEAR"), wxCLEAR
},
893 { wxT("wxCOPY"), wxCOPY
},
894 { wxT("wxEQUIV"), wxEQUIV
},
895 { wxT("wxINVERT"), wxINVERT
},
896 { wxT("wxNAND"), wxNAND
},
897 { wxT("wxNO_OP"), wxNO_OP
},
898 { wxT("wxOR"), wxOR
},
899 { wxT("wxOR_INVERT"), wxOR_INVERT
},
900 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
901 { wxT("wxSET"), wxSET
},
902 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
903 { wxT("wxXOR"), wxXOR
},
906 void MyCanvas::DrawImages(wxDC
& dc
)
908 dc
.DrawText("original image", 0, 0);
909 dc
.DrawBitmap(*gs_bmpNoMask
, 0, 20, 0);
910 dc
.DrawText("with colour mask", 0, 100);
911 dc
.DrawBitmap(*gs_bmpWithColMask
, 0, 120, TRUE
);
912 dc
.DrawText("the mask image", 0, 200);
913 dc
.DrawBitmap(*gs_bmpMask
, 0, 220, 0);
914 dc
.DrawText("masked image", 0, 300);
915 dc
.DrawBitmap(*gs_bmpWithMask
, 0, 320, TRUE
);
917 int cx
= gs_bmpWithColMask
->GetWidth(),
918 cy
= gs_bmpWithColMask
->GetHeight();
921 for ( size_t n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
923 wxCoord x
= 120 + 150*(n%4
),
926 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
927 memDC
.SelectObject(*gs_bmpWithColMask
);
928 dc
.Blit(x
, y
, cx
, cy
, &memDC
, 0, 0, rasterOperations
[n
].rop
, TRUE
);
932 void MyCanvas::DrawWithLogicalOps(wxDC
& dc
)
934 static const wxCoord w
= 60;
935 static const wxCoord h
= 60;
937 // reuse the text colour here
938 dc
.SetPen(wxPen(m_owner
->m_colourForeground
, 1, wxSOLID
));
939 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
942 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
944 wxCoord x
= 20 + 150*(n%4
),
947 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
948 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
949 dc
.DrawRectangle(x
, y
, w
, h
);
950 dc
.DrawLine(x
, y
, x
+ w
, y
+ h
);
951 dc
.DrawLine(x
+ w
, y
, x
, y
+ h
);
954 // now some filled rectangles
955 dc
.SetBrush(wxBrush(m_owner
->m_colourForeground
, wxSOLID
));
957 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
959 wxCoord x
= 20 + 150*(n%4
),
962 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
963 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
964 dc
.DrawRectangle(x
, y
, w
, h
);
968 void MyCanvas::DrawCircles(wxDC
& dc
)
974 dc
.DrawText("Some circles", 0, y
);
975 dc
.DrawCircle(x
, y
, r
);
976 dc
.DrawCircle(x
+ 2*r
, y
, r
);
977 dc
.DrawCircle(x
+ 4*r
, y
, r
);
980 dc
.DrawText("And ellipses", 0, y
);
981 dc
.DrawEllipse(x
- r
, y
, 2*r
, r
);
982 dc
.DrawEllipse(x
+ r
, y
, 2*r
, r
);
983 dc
.DrawEllipse(x
+ 3*r
, y
, 2*r
, r
);
986 dc
.DrawText("And arcs", 0, y
);
987 dc
.DrawArc(x
- r
, y
, x
+ r
, y
, x
, y
);
988 dc
.DrawArc(x
+ 4*r
, y
, x
+ 2*r
, y
, x
+ 3*r
, y
);
989 dc
.DrawArc(x
+ 5*r
, y
, x
+ 5*r
, y
, x
+ 6*r
, y
);
992 dc
.DrawEllipticArc(x
- r
, y
, 2*r
, r
, 0, 90);
993 dc
.DrawEllipticArc(x
+ r
, y
, 2*r
, r
, 90, 180);
994 dc
.DrawEllipticArc(x
+ 3*r
, y
, 2*r
, r
, 180, 270);
995 dc
.DrawEllipticArc(x
+ 5*r
, y
, 2*r
, r
, 270, 360);
998 void MyCanvas::DrawRegions(wxDC
& dc
)
1000 dc
.DrawText("You should see a red rect partly covered by a cyan one "
1001 "on the left", 10, 5);
1002 dc
.DrawText("and 5 smileys from which 4 are partially clipped on the "
1003 "right (2 copies should be identical)",
1004 10, 5 + dc
.GetCharHeight());
1006 DrawRegionsHelper(dc
, 10);
1007 DrawRegionsHelper(dc
, 350);
1010 void MyCanvas::DrawRegionsHelper(wxDC
& dc
, wxCoord x
)
1012 dc
.DestroyClippingRegion();
1013 dc
.SetBrush( *wxWHITE_BRUSH
);
1014 dc
.SetPen( *wxTRANSPARENT_PEN
);
1015 dc
.DrawRectangle( x
,50,310,310 );
1017 dc
.SetClippingRegion( x
+10,60,100,270 );
1019 dc
.SetBrush( *wxRED_BRUSH
);
1020 dc
.DrawRectangle( x
,50,310,310 );
1022 dc
.SetClippingRegion( x
+10,60,100,100 );
1024 dc
.SetBrush( *wxCYAN_BRUSH
);
1025 dc
.DrawRectangle( x
,50,310,310 );
1027 // when drawing the left half, destroy the clipping region, when drawing
1028 // the right one - leave it
1030 // normally it shouldn't make any difference as SetClippingRegion()
1031 // replaces the old clipping region
1033 dc
.DestroyClippingRegion();
1034 dc
.SetClippingRegion( x
+110,70,100,270 );
1036 dc
.SetBrush( *wxGREY_BRUSH
);
1037 dc
.DrawRectangle( x
,50,310,310 );
1039 if (m_smile_bmp
.Ok())
1041 dc
.DrawBitmap( m_smile_bmp
, x
+150, 200, TRUE
);
1042 dc
.DrawBitmap( m_smile_bmp
, x
+130, 60, TRUE
);
1043 dc
.DrawBitmap( m_smile_bmp
, x
+130, 330, TRUE
);
1044 dc
.DrawBitmap( m_smile_bmp
, x
+100, 120, TRUE
);
1045 dc
.DrawBitmap( m_smile_bmp
, x
+200, 120, TRUE
);
1049 void MyCanvas::OnPaint(wxPaintEvent
&WXUNUSED(event
))
1054 m_owner
->PrepareDC(dc
);
1056 dc
.SetBackgroundMode( m_owner
->m_backgroundMode
);
1057 if ( m_owner
->m_backgroundBrush
.Ok() )
1058 dc
.SetBackground( m_owner
->m_backgroundBrush
);
1059 if ( m_owner
->m_colourForeground
.Ok() )
1060 dc
.SetTextForeground( m_owner
->m_colourForeground
);
1061 if ( m_owner
->m_colourBackground
.Ok() )
1062 dc
.SetTextBackground( m_owner
->m_colourBackground
);
1064 if ( m_owner
->m_textureBackground
) {
1065 if ( ! m_owner
->m_backgroundBrush
.Ok() ) {
1066 wxBrush
b(wxColour(0,128,0), wxSOLID
);
1067 dc
.SetBackground(b
);
1073 if ( m_owner
->m_textureBackground
) {
1074 dc
.SetPen(*wxMEDIUM_GREY_PEN
);
1075 for (int i
=0; i
<200; i
++)
1076 dc
.DrawLine(0, i
*10, i
*10, 0);
1098 DrawTestLines( 0, 100, 0, dc
);
1099 DrawTestLines( 0, 320, 1, dc
);
1100 DrawTestLines( 0, 540, 2, dc
);
1101 DrawTestLines( 0, 760, 6, dc
);
1105 DrawTestPoly( 0, 100, dc
, 0 );
1107 DrawTestPoly( 33, 500, dc, 1 );
1108 DrawTestPoly( 43, 1000, dc, 2 );
1117 DrawWithLogicalOps(dc
);
1122 dc
.SetPen( *wxBLACK_PEN
);
1123 dc
.DrawLine( 0,0,100,100 );
1129 void MyCanvas::OnMouseMove(wxMouseEvent
&event
)
1131 wxClientDC
dc(this);
1133 m_owner
->PrepareDC(dc
);
1135 wxPoint pos
= event
.GetPosition();
1136 long x
= dc
.DeviceToLogicalX( pos
.x
);
1137 long y
= dc
.DeviceToLogicalY( pos
.y
);
1139 str
.Printf( wxT("Current mouse position: %d,%d"), (int)x
, (int)y
);
1140 m_owner
->SetStatusText( str
);
1143 // ----------------------------------------------------------------------------
1145 // ----------------------------------------------------------------------------
1147 // the event tables connect the wxWindows events with the functions (event
1148 // handlers) which process them. It can be also done at run-time, but for the
1149 // simple menu events like this the static method is much simpler.
1150 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1151 EVT_MENU (File_Quit
, MyFrame::OnQuit
)
1152 EVT_MENU (File_About
, MyFrame::OnAbout
)
1154 EVT_MENU_RANGE(MenuShow_First
, MenuShow_Last
, MyFrame::OnShow
)
1156 EVT_MENU_RANGE(MenuOption_First
, MenuOption_Last
, MyFrame::OnOption
)
1159 // frame constructor
1160 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
1161 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
,
1162 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
1164 // set the frame icon
1165 SetIcon(wxICON(mondrian
));
1167 wxMenu
*menuFile
= new wxMenu
;
1168 menuFile
->Append(File_ShowDefault
, "&Default screen\tF1");
1169 menuFile
->Append(File_ShowText
, "&Text screen\tF2");
1170 menuFile
->Append(File_ShowLines
, "&Lines screen\tF3");
1171 menuFile
->Append(File_ShowPolygons
, "&Polygons screen\tF4");
1172 menuFile
->Append(File_ShowMask
, "wx&Mask screen\tF5");
1173 menuFile
->Append(File_ShowOps
, "&ROP screen\tF6");
1174 menuFile
->Append(File_ShowRegions
, "Re&gions screen\tF7");
1175 menuFile
->Append(File_ShowCircles
, "&Circles screen\tF8");
1176 menuFile
->AppendSeparator();
1177 menuFile
->Append(File_About
, "&About...\tCtrl-A", "Show about dialog");
1178 menuFile
->AppendSeparator();
1179 menuFile
->Append(File_Quit
, "E&xit\tAlt-X", "Quit this program");
1181 wxMenu
*menuMapMode
= new wxMenu
;
1182 menuMapMode
->Append( MapMode_Text
, "&TEXT map mode" );
1183 menuMapMode
->Append( MapMode_Lometric
, "&LOMETRIC map mode" );
1184 menuMapMode
->Append( MapMode_Twips
, "T&WIPS map mode" );
1185 menuMapMode
->Append( MapMode_Points
, "&POINTS map mode" );
1186 menuMapMode
->Append( MapMode_Metric
, "&METRIC map mode" );
1188 wxMenu
*menuUserScale
= new wxMenu
;
1189 menuUserScale
->Append( UserScale_StretchHoriz
, "Stretch horizontally\tCtrl-H" );
1190 menuUserScale
->Append( UserScale_ShrinkHoriz
, "Shrink horizontally\tCtrl-G" );
1191 menuUserScale
->Append( UserScale_StretchVertic
, "Stretch vertically\tCtrl-V" );
1192 menuUserScale
->Append( UserScale_ShrinkVertic
, "Shrink vertically\tCtrl-W" );
1193 menuUserScale
->AppendSeparator();
1194 menuUserScale
->Append( UserScale_Restore
, "Restore to normal\tCtrl-0" );
1196 wxMenu
*menuAxis
= new wxMenu
;
1197 menuAxis
->Append( AxisMirror_Horiz
, "Mirror horizontally\tCtrl-M", "", TRUE
);
1198 menuAxis
->Append( AxisMirror_Vertic
, "Mirror vertically\tCtrl-N", "", TRUE
);
1200 wxMenu
*menuLogical
= new wxMenu
;
1201 menuLogical
->Append( LogicalOrigin_MoveDown
, "Move &down\tCtrl-D" );
1202 menuLogical
->Append( LogicalOrigin_MoveUp
, "Move &up\tCtrl-U" );
1203 menuLogical
->Append( LogicalOrigin_MoveLeft
, "Move &right\tCtrl-L" );
1204 menuLogical
->Append( LogicalOrigin_MoveRight
, "Move &left\tCtrl-R" );
1206 wxMenu
*menuColour
= new wxMenu
;
1207 menuColour
->Append( Colour_TextForeground
, "Text foreground..." );
1208 menuColour
->Append( Colour_TextBackground
, "Text background..." );
1209 menuColour
->Append( Colour_Background
, "Background colour..." );
1210 menuColour
->Append( Colour_BackgroundMode
, "Opaque/transparent\tCtrl-B", "", TRUE
);
1211 menuColour
->Append( Colour_TextureBackgound
, "Draw textured background\tCtrl-T", "", TRUE
);
1213 // now append the freshly created menu to the menu bar...
1214 wxMenuBar
*menuBar
= new wxMenuBar
;
1215 menuBar
->Append(menuFile
, "&File");
1216 menuBar
->Append(menuMapMode
, "&MapMode");
1217 menuBar
->Append(menuUserScale
, "&UserScale");
1218 menuBar
->Append(menuAxis
, "&Axis");
1219 menuBar
->Append(menuLogical
, "&LogicalOrigin");
1220 menuBar
->Append(menuColour
, "&Colours");
1222 // ... and attach this menu bar to the frame
1223 SetMenuBar(menuBar
);
1225 // create a status bar just for fun (by default with 1 pane only)
1227 SetStatusText("Welcome to wxWindows!");
1229 m_mapMode
= wxMM_TEXT
;
1232 m_xLogicalOrigin
= 0;
1233 m_yLogicalOrigin
= 0;
1235 m_yAxisReversed
= FALSE
;
1236 m_backgroundMode
= wxSOLID
;
1237 m_colourForeground
= *wxRED
;
1238 m_colourBackground
= *wxBLUE
;
1239 m_textureBackground
= FALSE
;
1241 m_canvas
= new MyCanvas( this );
1242 m_canvas
->SetScrollbars( 10, 10, 100, 240 );
1247 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
1249 // TRUE is to force the frame to close
1253 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
1256 msg
.Printf( wxT("This is the about dialog of the drawing sample.\n")
1257 wxT("This sample tests various primitive drawing functions\n")
1258 wxT("without any tests to prevent flicker.\n")
1259 wxT("Copyright (c) Robert Roebling 1999")
1262 wxMessageBox(msg
, "About Drawing", wxOK
| wxICON_INFORMATION
, this);
1265 void MyFrame::OnShow(wxCommandEvent
& event
)
1267 m_canvas
->Show((ScreenToShow
)(event
.GetId() - MenuShow_First
));
1270 void MyFrame::OnOption(wxCommandEvent
& event
)
1272 switch (event
.GetId())
1275 m_mapMode
= wxMM_TEXT
;
1277 case MapMode_Lometric
:
1278 m_mapMode
= wxMM_LOMETRIC
;
1281 m_mapMode
= wxMM_TWIPS
;
1283 case MapMode_Points
:
1284 m_mapMode
= wxMM_POINTS
;
1286 case MapMode_Metric
:
1287 m_mapMode
= wxMM_METRIC
;
1290 case LogicalOrigin_MoveDown
:
1291 m_yLogicalOrigin
+= 10;
1293 case LogicalOrigin_MoveUp
:
1294 m_yLogicalOrigin
-= 10;
1296 case LogicalOrigin_MoveLeft
:
1297 m_xLogicalOrigin
+= 10;
1299 case LogicalOrigin_MoveRight
:
1300 m_xLogicalOrigin
-= 10;
1303 case UserScale_StretchHoriz
:
1304 m_xUserScale
*= 1.10;
1306 case UserScale_ShrinkHoriz
:
1307 m_xUserScale
/= 1.10;
1309 case UserScale_StretchVertic
:
1310 m_yUserScale
*= 1.10;
1312 case UserScale_ShrinkVertic
:
1313 m_yUserScale
/= 1.10;
1315 case UserScale_Restore
:
1320 case AxisMirror_Vertic
:
1321 m_yAxisReversed
= !m_yAxisReversed
;
1323 case AxisMirror_Horiz
:
1324 m_xAxisReversed
= !m_xAxisReversed
;
1327 case Colour_TextForeground
:
1328 m_colourForeground
= SelectColour();
1330 case Colour_TextBackground
:
1331 m_colourBackground
= SelectColour();
1333 case Colour_Background
:
1335 wxColour col
= SelectColour();
1338 m_backgroundBrush
.SetColour(col
);
1342 case Colour_BackgroundMode
:
1343 m_backgroundMode
= m_backgroundMode
== wxSOLID
? wxTRANSPARENT
1347 case Colour_TextureBackgound
:
1348 m_textureBackground
= ! m_textureBackground
;
1356 m_canvas
->Refresh();
1359 void MyFrame::PrepareDC(wxDC
& dc
)
1361 dc
.SetMapMode( m_mapMode
);
1362 dc
.SetUserScale( m_xUserScale
, m_yUserScale
);
1363 dc
.SetLogicalOrigin( m_xLogicalOrigin
, m_yLogicalOrigin
);
1364 dc
.SetAxisOrientation( !m_xAxisReversed
, m_yAxisReversed
);
1367 wxColour
MyFrame::SelectColour()
1371 wxColourDialog
dialog(this, &data
);
1373 if ( dialog
.ShowModal() == wxID_OK
)
1375 col
= dialog
.GetColourData().GetColour();