1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/drawing/drawing.cpp
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 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers
33 #include "wx/colordlg.h"
35 #include "wx/artprov.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // the application icon
42 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
43 #include "mondrian.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // what do we show on screen (there are too many shapes to put them all on
51 // 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 OnClip(wxCommandEvent
& event
);
117 void OnShow(wxCommandEvent
&event
);
118 void OnOption(wxCommandEvent
&event
);
121 wxColour
SelectColour();
122 #endif // wxUSE_COLOURDLG
123 void PrepareDC(wxDC
& dc
);
125 int m_backgroundMode
;
126 int m_textureBackground
;
130 int m_xLogicalOrigin
;
131 int m_yLogicalOrigin
;
132 bool m_xAxisReversed
,
134 wxColour m_colourForeground
, // these are _text_ colours
136 wxBrush m_backgroundBrush
;
140 // any class wishing to process wxWidgets events must use this macro
141 DECLARE_EVENT_TABLE()
144 // define a scrollable canvas for drawing onto
145 class MyCanvas
: public wxScrolledWindow
148 MyCanvas( MyFrame
*parent
);
150 void OnPaint(wxPaintEvent
&event
);
151 void OnMouseMove(wxMouseEvent
&event
);
153 void ToShow(ScreenToShow show
) { m_show
= show
; Refresh(); }
155 // set or remove the clipping region
156 void Clip(bool clip
) { m_clip
= clip
; Refresh(); }
159 void DrawTestLines( int x
, int y
, int width
, wxDC
&dc
);
160 void DrawTestPoly(wxDC
& dc
);
161 void DrawTestBrushes(wxDC
& dc
);
162 void DrawText(wxDC
& dc
);
163 void DrawImages(wxDC
& dc
);
164 void DrawWithLogicalOps(wxDC
& dc
);
165 void DrawRegions(wxDC
& dc
);
166 void DrawCircles(wxDC
& dc
);
167 void DrawSplines(wxDC
& dc
);
168 void DrawDefault(wxDC
& dc
);
169 void DrawGradients(wxDC
& dc
);
171 void DrawRegionsHelper(wxDC
& dc
, wxCoord x
, bool firstTime
);
177 wxBitmap m_smile_bmp
;
181 DECLARE_EVENT_TABLE()
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 // IDs for the controls and the menu commands
192 File_Quit
= wxID_EXIT
,
193 File_About
= wxID_ABOUT
,
195 MenuShow_First
= wxID_HIGHEST
,
196 File_ShowDefault
= MenuShow_First
,
207 MenuShow_Last
= File_ShowGradients
,
213 MapMode_Text
= MenuOption_First
,
219 UserScale_StretchHoriz
,
220 UserScale_ShrinkHoriz
,
221 UserScale_StretchVertic
,
222 UserScale_ShrinkVertic
,
228 LogicalOrigin_MoveDown
,
229 LogicalOrigin_MoveUp
,
230 LogicalOrigin_MoveLeft
,
231 LogicalOrigin_MoveRight
,
233 LogicalOrigin_Restore
,
236 Colour_TextForeground
,
237 Colour_TextBackground
,
239 #endif // wxUSE_COLOURDLG
240 Colour_BackgroundMode
,
241 Colour_TextureBackgound
,
243 MenuOption_Last
= Colour_TextureBackgound
246 // ----------------------------------------------------------------------------
247 // event tables and other macros for wxWidgets
248 // ----------------------------------------------------------------------------
251 // Create a new application object: this macro will allow wxWidgets to create
252 // the application object during program execution (it's better than using a
253 // static object for many reasons) and also declares the accessor function
254 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
258 // ============================================================================
260 // ============================================================================
262 // ----------------------------------------------------------------------------
263 // the application class
264 // ----------------------------------------------------------------------------
266 bool MyApp::LoadImages()
268 gs_bmpNoMask
= new wxBitmap
;
269 gs_bmpWithColMask
= new wxBitmap
;
270 gs_bmpMask
= new wxBitmap
;
271 gs_bmpWithMask
= new wxBitmap
;
272 gs_bmp4
= new wxBitmap
;
273 gs_bmp4_mono
= new wxBitmap
;
274 gs_bmp36
= new wxBitmap
;
277 pathList
.Add(_T("."));
278 pathList
.Add(_T(".."));
280 wxString path
= pathList
.FindValidPath(_T("pat4.bmp"));
284 /* 4 colour bitmap */
285 gs_bmp4
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
286 /* turn into mono-bitmap */
287 gs_bmp4_mono
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
288 wxMask
* mask4
= new wxMask(*gs_bmp4_mono
, *wxBLACK
);
289 gs_bmp4_mono
->SetMask(mask4
);
291 path
= pathList
.FindValidPath(_T("pat36.bmp"));
294 gs_bmp36
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
295 wxMask
* mask36
= new wxMask(*gs_bmp36
, *wxBLACK
);
296 gs_bmp36
->SetMask(mask36
);
298 path
= pathList
.FindValidPath(_T("image.bmp"));
301 gs_bmpNoMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
302 gs_bmpWithMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
303 gs_bmpWithColMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
305 path
= pathList
.FindValidPath(_T("mask.bmp"));
308 gs_bmpMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
310 wxMask
*mask
= new wxMask(*gs_bmpMask
, *wxBLACK
);
311 gs_bmpWithMask
->SetMask(mask
);
313 mask
= new wxMask(*gs_bmpWithColMask
, *wxWHITE
);
314 gs_bmpWithColMask
->SetMask(mask
);
319 // `Main program' equivalent: the program execution "starts" here
322 // Create the main application window
323 MyFrame
*frame
= new MyFrame(_T("Drawing sample"),
324 wxPoint(50, 50), wxSize(550, 340));
326 // Show it and tell the application that it's our main window
332 wxLogError(wxT("Can't load one of the bitmap files needed ")
333 wxT("for this sample from the current or parent ")
334 wxT("directory, please copy them there."));
346 void MyApp::DeleteBitmaps()
349 delete gs_bmpWithColMask
;
351 delete gs_bmpWithMask
;
357 gs_bmpWithColMask
= NULL
;
359 gs_bmpWithMask
= NULL
;
365 // ----------------------------------------------------------------------------
367 // ----------------------------------------------------------------------------
369 // the event tables connect the wxWidgets events with the functions (event
370 // handlers) which process them.
371 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
372 EVT_PAINT (MyCanvas::OnPaint
)
373 EVT_MOTION (MyCanvas::OnMouseMove
)
378 MyCanvas::MyCanvas(MyFrame
*parent
)
379 : wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
380 wxHSCROLL
| wxVSCROLL
| wxNO_FULL_REPAINT_ON_RESIZE
)
383 m_show
= Show_Default
;
384 m_smile_bmp
= wxBitmap(smile_xpm
);
385 m_std_icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
389 void MyCanvas::DrawTestBrushes(wxDC
& dc
)
391 static const wxCoord WIDTH
= 200;
392 static const wxCoord HEIGHT
= 80;
397 dc
.SetBrush(wxBrush(*wxGREEN
, wxSOLID
));
398 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
399 dc
.DrawText(_T("Solid green"), x
+ 10, y
+ 10);
402 dc
.SetBrush(wxBrush(*wxRED
, wxCROSSDIAG_HATCH
));
403 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
404 dc
.DrawText(_T("Hatched red"), x
+ 10, y
+ 10);
407 dc
.SetBrush(wxBrush(*gs_bmpMask
));
408 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
409 dc
.DrawText(_T("Stipple mono"), x
+ 10, y
+ 10);
412 dc
.SetBrush(wxBrush(*gs_bmpNoMask
));
413 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
414 dc
.DrawText(_T("Stipple colour"), x
+ 10, y
+ 10);
417 void MyCanvas::DrawTestPoly(wxDC
& dc
)
419 wxBrush
brushHatch(*wxRED
, wxFDIAGONAL_HATCH
);
420 dc
.SetBrush(brushHatch
);
423 star
[0] = wxPoint(100, 60);
424 star
[1] = wxPoint(60, 150);
425 star
[2] = wxPoint(160, 100);
426 star
[3] = wxPoint(40, 100);
427 star
[4] = wxPoint(140, 150);
429 dc
.DrawText(_T("You should see two (irregular) stars below, the left one ")
430 _T("hatched"), 10, 10);
431 dc
.DrawText(_T("except for the central region and the right ")
432 _T("one entirely hatched"), 10, 30);
433 dc
.DrawText(_T("The third star only has a hatched outline"), 10, 50);
435 dc
.DrawPolygon(WXSIZEOF(star
), star
, 0, 30);
436 dc
.DrawPolygon(WXSIZEOF(star
), star
, 160, 30, wxWINDING_RULE
);
439 star2
[0] = wxPoint(0, 100);
440 star2
[1] = wxPoint(-59, -81);
441 star2
[2] = wxPoint(95, 31);
442 star2
[3] = wxPoint(-95, 31);
443 star2
[4] = wxPoint(59, -81);
444 star2
[5] = wxPoint(0, 80);
445 star2
[6] = wxPoint(-47, -64);
446 star2
[7] = wxPoint(76, 24);
447 star2
[8] = wxPoint(-76, 24);
448 star2
[9] = wxPoint(47, -64);
449 int count
[2] = {5, 5};
451 dc
.DrawPolyPolygon(WXSIZEOF(count
), count
, star2
, 450, 150);
454 void MyCanvas::DrawTestLines( int x
, int y
, int width
, wxDC
&dc
)
456 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
457 dc
.SetBrush( *wxRED_BRUSH
);
458 dc
.DrawText(wxString::Format(wxT("Testing lines of width %d"), width
), x
+ 10, y
- 10);
459 dc
.DrawRectangle( x
+10, y
+10, 100, 190 );
461 dc
.DrawText(_T("Solid/dot/short dash/long dash/dot dash"), x
+ 150, y
+ 10);
462 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
463 dc
.DrawLine( x
+20, y
+20, 100, y
+20 );
464 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT
) );
465 dc
.DrawLine( x
+20, y
+30, 100, y
+30 );
466 dc
.SetPen( wxPen( wxT("black"), width
, wxSHORT_DASH
) );
467 dc
.DrawLine( x
+20, y
+40, 100, y
+40 );
468 dc
.SetPen( wxPen( wxT("black"), width
, wxLONG_DASH
) );
469 dc
.DrawLine( x
+20, y
+50, 100, y
+50 );
470 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT_DASH
) );
471 dc
.DrawLine( x
+20, y
+60, 100, y
+60 );
473 dc
.DrawText(_T("Misc hatches"), x
+ 150, y
+ 70);
474 dc
.SetPen( wxPen( wxT("black"), width
, wxBDIAGONAL_HATCH
) );
475 dc
.DrawLine( x
+20, y
+70, 100, y
+70 );
476 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSSDIAG_HATCH
) );
477 dc
.DrawLine( x
+20, y
+80, 100, y
+80 );
478 dc
.SetPen( wxPen( wxT("black"), width
, wxFDIAGONAL_HATCH
) );
479 dc
.DrawLine( x
+20, y
+90, 100, y
+90 );
480 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSS_HATCH
) );
481 dc
.DrawLine( x
+20, y
+100, 100, y
+100 );
482 dc
.SetPen( wxPen( wxT("black"), width
, wxHORIZONTAL_HATCH
) );
483 dc
.DrawLine( x
+20, y
+110, 100, y
+110 );
484 dc
.SetPen( wxPen( wxT("black"), width
, wxVERTICAL_HATCH
) );
485 dc
.DrawLine( x
+20, y
+120, 100, y
+120 );
487 dc
.DrawText(_T("User dash"), x
+ 150, y
+ 140);
488 wxPen
ud( wxT("black"), width
, wxUSER_DASH
);
490 dash1
[0] = 8; // Long dash <---------+
491 dash1
[1] = 2; // Short gap |
492 dash1
[2] = 3; // Short dash |
493 dash1
[3] = 2; // Short gap |
494 dash1
[4] = 3; // Short dash |
495 dash1
[5] = 2; // Short gap and repeat +
496 ud
.SetDashes( 6, dash1
);
498 dc
.DrawLine( x
+20, y
+140, 100, y
+140 );
499 dash1
[0] = 5; // Make first dash shorter
500 ud
.SetDashes( 6, dash1
);
502 dc
.DrawLine( x
+20, y
+150, 100, y
+150 );
503 dash1
[2] = 5; // Make second dash longer
504 ud
.SetDashes( 6, dash1
);
506 dc
.DrawLine( x
+20, y
+160, 100, y
+160 );
507 dash1
[4] = 5; // Make third dash longer
508 ud
.SetDashes( 6, dash1
);
510 dc
.DrawLine( x
+20, y
+170, 100, y
+170 );
513 void MyCanvas::DrawDefault(wxDC
& dc
)
516 dc
.DrawCircle(0, 0, 10);
518 #if !defined(wxMAC_USE_CORE_GRAPHICS) || !wxMAC_USE_CORE_GRAPHICS
519 // GetPixel and FloodFill not supported by Mac OS X CoreGraphics
520 // (FloodFill uses Blit from a non-wxMemoryDC)
521 //flood fill using brush, starting at 1,1 and replacing whatever colour we find there
522 dc
.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID
));
525 dc
.GetPixel(1,1, &tmpColour
);
526 dc
.FloodFill(1,1, tmpColour
, wxFLOOD_SURFACE
);
529 dc
.DrawCheckMark(5, 80, 15, 15);
530 dc
.DrawCheckMark(25, 80, 30, 30);
531 dc
.DrawCheckMark(60, 80, 60, 60);
533 // this is the test for "blitting bitmap into DC damages selected brush" bug
534 wxCoord rectSize
= m_std_icon
.GetWidth() + 10;
536 dc
.SetPen(*wxTRANSPARENT_PEN
);
537 dc
.SetBrush( *wxGREEN_BRUSH
);
538 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
539 dc
.DrawBitmap(m_std_icon
, x
+ 5, 15, true);
541 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
542 dc
.DrawIcon(m_std_icon
, x
+ 5, 15);
544 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
546 // test for "transparent" bitmap drawing (it intersects with the last
548 //dc.SetBrush( *wxTRANSPARENT_BRUSH );
550 if (m_smile_bmp
.Ok())
551 dc
.DrawBitmap(m_smile_bmp
, x
+ rectSize
- 20, rectSize
- 10, true);
553 dc
.SetBrush( *wxBLACK_BRUSH
);
554 dc
.DrawRectangle( 0, 160, 1000, 300 );
557 wxBitmap
bitmap(20,70);
559 memdc
.SelectObject( bitmap
);
560 memdc
.SetBrush( *wxBLACK_BRUSH
);
561 memdc
.SetPen( *wxWHITE_PEN
);
562 memdc
.DrawRectangle(0,0,20,70);
563 memdc
.DrawLine( 10,0,10,70 );
566 wxPen pen
= *wxRED_PEN
;
568 memdc
.DrawLine( 10, 5,10, 5 );
569 memdc
.DrawLine( 10,10,11,10 );
570 memdc
.DrawLine( 10,15,12,15 );
571 memdc
.DrawLine( 10,20,13,20 );
574 memdc.SetPen(*wxRED_PEN);
575 memdc.DrawLine( 12, 5,12, 5 );
576 memdc.DrawLine( 12,10,13,10 );
577 memdc.DrawLine( 12,15,14,15 );
578 memdc.DrawLine( 12,20,15,20 );
582 memdc
.DrawLine( 10,25,10,25 );
583 memdc
.DrawLine( 10,30, 9,30 );
584 memdc
.DrawLine( 10,35, 8,35 );
585 memdc
.DrawLine( 10,40, 7,40 );
588 dc
.SetPen(*wxWHITE_PEN
);
589 memdc
.SetLogicalFunction( wxINVERT
);
590 memdc
.SetPen( *wxWHITE_PEN
);
591 memdc
.DrawLine( 10,50,10,50 );
592 memdc
.DrawLine( 10,55,11,55 );
593 memdc
.DrawLine( 10,60,12,60 );
594 memdc
.DrawLine( 10,65,13,65 );
596 memdc
.DrawLine( 12,50,12,50 );
597 memdc
.DrawLine( 12,55,13,55 );
598 memdc
.DrawLine( 12,60,14,60 );
599 memdc
.DrawLine( 12,65,15,65 );
601 memdc
.SelectObject( wxNullBitmap
);
602 dc
.DrawBitmap( bitmap
, 10, 170 );
603 wxImage image
= bitmap
.ConvertToImage();
604 image
.Rescale( 60,210 );
605 bitmap
= wxBitmap(image
);
606 dc
.DrawBitmap( bitmap
, 50, 170 );
608 // test the rectangle outline drawing - there should be one pixel between
609 // the rect and the lines
610 dc
.SetPen(*wxWHITE_PEN
);
611 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
612 dc
.DrawRectangle(150, 170, 49, 29);
613 dc
.DrawRectangle(200, 170, 49, 29);
614 dc
.SetPen(*wxWHITE_PEN
);
615 dc
.DrawLine(250, 210, 250, 170);
616 dc
.DrawLine(260, 200, 150, 200);
618 // test the rectangle filled drawing - there should be one pixel between
619 // the rect and the lines
620 dc
.SetPen(*wxTRANSPARENT_PEN
);
621 dc
.SetBrush( *wxWHITE_BRUSH
);
622 dc
.DrawRectangle(300, 170, 49, 29);
623 dc
.DrawRectangle(350, 170, 49, 29);
624 dc
.SetPen(*wxWHITE_PEN
);
625 dc
.DrawLine(400, 170, 400, 210);
626 dc
.DrawLine(300, 200, 410, 200);
628 // a few more tests of this kind
629 dc
.SetPen(*wxRED_PEN
);
630 dc
.SetBrush( *wxWHITE_BRUSH
);
631 dc
.DrawRectangle(300, 220, 1, 1);
632 dc
.DrawRectangle(310, 220, 2, 2);
633 dc
.DrawRectangle(320, 220, 3, 3);
634 dc
.DrawRectangle(330, 220, 4, 4);
636 dc
.SetPen(*wxTRANSPARENT_PEN
);
637 dc
.SetBrush( *wxWHITE_BRUSH
);
638 dc
.DrawRectangle(300, 230, 1, 1);
639 dc
.DrawRectangle(310, 230, 2, 2);
640 dc
.DrawRectangle(320, 230, 3, 3);
641 dc
.DrawRectangle(330, 230, 4, 4);
643 // and now for filled rect with outline
644 dc
.SetPen(*wxRED_PEN
);
645 dc
.SetBrush( *wxWHITE_BRUSH
);
646 dc
.DrawRectangle(500, 170, 49, 29);
647 dc
.DrawRectangle(550, 170, 49, 29);
648 dc
.SetPen(*wxWHITE_PEN
);
649 dc
.DrawLine(600, 170, 600, 210);
650 dc
.DrawLine(500, 200, 610, 200);
652 // test the rectangle outline drawing - there should be one pixel between
653 // the rect and the lines
654 dc
.SetPen(*wxWHITE_PEN
);
655 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
656 dc
.DrawRoundedRectangle(150, 270, 49, 29, 6);
657 dc
.DrawRoundedRectangle(200, 270, 49, 29, 6);
658 dc
.SetPen(*wxWHITE_PEN
);
659 dc
.DrawLine(250, 270, 250, 310);
660 dc
.DrawLine(150, 300, 260, 300);
662 // test the rectangle filled drawing - there should be one pixel between
663 // the rect and the lines
664 dc
.SetPen(*wxTRANSPARENT_PEN
);
665 dc
.SetBrush( *wxWHITE_BRUSH
);
666 dc
.DrawRoundedRectangle(300, 270, 49, 29, 6);
667 dc
.DrawRoundedRectangle(350, 270, 49, 29, 6);
668 dc
.SetPen(*wxWHITE_PEN
);
669 dc
.DrawLine(400, 270, 400, 310);
670 dc
.DrawLine(300, 300, 410, 300);
672 // Added by JACS to demonstrate bizarre behaviour.
673 // With a size of 70, we get a missing red RHS,
674 // and the height is too small, so we get yellow
675 // showing. With a size of 40, it draws as expected:
676 // it just shows a white rectangle with red outline.
678 int totalHeight
= 70;
679 wxBitmap
bitmap2(totalWidth
, totalHeight
);
682 memdc2
.SelectObject(bitmap2
);
684 wxColour
clr(255, 255, 0);
685 wxBrush
yellowBrush(clr
, wxSOLID
);
686 memdc2
.SetBackground(yellowBrush
);
689 wxPen
yellowPen(clr
, 1, wxSOLID
);
691 // Now draw a white rectangle with red outline. It should
692 // entirely eclipse the yellow background.
693 memdc2
.SetPen(*wxRED_PEN
);
694 memdc2
.SetBrush(*wxWHITE_BRUSH
);
696 memdc2
.DrawRectangle(0, 0, totalWidth
, totalHeight
);
698 memdc2
.SetPen(wxNullPen
);
699 memdc2
.SetBrush(wxNullBrush
);
700 memdc2
.SelectObject(wxNullBitmap
);
702 dc
.DrawBitmap(bitmap2
, 500, 270);
704 // Repeat, but draw directly on dc
705 // Draw a yellow rectangle filling the bitmap
707 x
= 600; int y
= 270;
708 dc
.SetPen(yellowPen
);
709 dc
.SetBrush(yellowBrush
);
710 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
712 // Now draw a white rectangle with red outline. It should
713 // entirely eclipse the yellow background.
714 dc
.SetPen(*wxRED_PEN
);
715 dc
.SetBrush(*wxWHITE_BRUSH
);
717 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
720 void MyCanvas::DrawText(wxDC
& dc
)
722 // set underlined font for testing
723 dc
.SetFont( wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, true) );
724 dc
.DrawText( _T("This is text"), 110, 10 );
725 dc
.DrawRotatedText( _T("That is text"), 20, 10, -45 );
727 // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
728 // under Win9x (it is not TrueType)
729 dc
.SetFont( *wxSWISS_FONT
);
732 dc
.SetBackgroundMode(wxTRANSPARENT
);
734 for ( int n
= -180; n
< 180; n
+= 30 )
736 text
.Printf(wxT(" %d rotated text"), n
);
737 dc
.DrawRotatedText(text
, 400, 400, n
);
740 dc
.SetFont( wxFont( 18, wxSWISS
, wxNORMAL
, wxNORMAL
) );
742 dc
.DrawText( _T("This is Swiss 18pt text."), 110, 40 );
747 dc
.GetTextExtent( _T("This is Swiss 18pt text."), &length
, &height
, &descent
);
748 text
.Printf( wxT("Dimensions are length %ld, height %ld, descent %ld"), length
, height
, descent
);
749 dc
.DrawText( text
, 110, 80 );
751 text
.Printf( wxT("CharHeight() returns: %d"), dc
.GetCharHeight() );
752 dc
.DrawText( text
, 110, 120 );
754 dc
.DrawRectangle( 100, 40, 4, height
);
756 // test the logical function effect
758 dc
.SetLogicalFunction(wxINVERT
);
759 dc
.DrawText( _T("There should be no text below"), 110, 150 );
760 dc
.DrawRectangle( 110, y
, 100, height
);
762 // twice drawn inverted should result in invisible
764 dc
.DrawText( _T("Invisible text"), 110, y
);
765 dc
.DrawRectangle( 110, y
, 100, height
);
766 dc
.DrawText( _T("Invisible text"), 110, y
);
767 dc
.DrawRectangle( 110, y
, 100, height
);
768 dc
.SetLogicalFunction(wxCOPY
);
771 dc
.DrawRectangle( 110, y
, 100, height
);
772 dc
.DrawText( _T("Visible text"), 110, y
);
779 } rasterOperations
[] =
781 { wxT("wxAND"), wxAND
},
782 { wxT("wxAND_INVERT"), wxAND_INVERT
},
783 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
784 { wxT("wxCLEAR"), wxCLEAR
},
785 { wxT("wxCOPY"), wxCOPY
},
786 { wxT("wxEQUIV"), wxEQUIV
},
787 { wxT("wxINVERT"), wxINVERT
},
788 { wxT("wxNAND"), wxNAND
},
789 { wxT("wxNO_OP"), wxNO_OP
},
790 { wxT("wxOR"), wxOR
},
791 { wxT("wxOR_INVERT"), wxOR_INVERT
},
792 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
793 { wxT("wxSET"), wxSET
},
794 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
795 { wxT("wxXOR"), wxXOR
},
798 void MyCanvas::DrawImages(wxDC
& dc
)
800 dc
.DrawText(_T("original image"), 0, 0);
801 dc
.DrawBitmap(*gs_bmpNoMask
, 0, 20, 0);
802 dc
.DrawText(_T("with colour mask"), 0, 100);
803 dc
.DrawBitmap(*gs_bmpWithColMask
, 0, 120, true);
804 dc
.DrawText(_T("the mask image"), 0, 200);
805 dc
.DrawBitmap(*gs_bmpMask
, 0, 220, 0);
806 dc
.DrawText(_T("masked image"), 0, 300);
807 dc
.DrawBitmap(*gs_bmpWithMask
, 0, 320, true);
809 int cx
= gs_bmpWithColMask
->GetWidth(),
810 cy
= gs_bmpWithColMask
->GetHeight();
813 for ( size_t n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
815 wxCoord x
= 120 + 150*(n%4
),
818 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
819 memDC
.SelectObject(*gs_bmpWithColMask
);
820 dc
.Blit(x
, y
, cx
, cy
, &memDC
, 0, 0, rasterOperations
[n
].rop
, true);
824 void MyCanvas::DrawWithLogicalOps(wxDC
& dc
)
826 static const wxCoord w
= 60;
827 static const wxCoord h
= 60;
829 // reuse the text colour here
830 dc
.SetPen(wxPen(m_owner
->m_colourForeground
, 1, wxSOLID
));
831 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
834 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
836 wxCoord x
= 20 + 150*(n%4
),
839 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
840 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
841 dc
.DrawRectangle(x
, y
, w
, h
);
842 dc
.DrawLine(x
, y
, x
+ w
, y
+ h
);
843 dc
.DrawLine(x
+ w
, y
, x
, y
+ h
);
846 // now some filled rectangles
847 dc
.SetBrush(wxBrush(m_owner
->m_colourForeground
, wxSOLID
));
849 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
851 wxCoord x
= 20 + 150*(n%4
),
854 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
855 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
856 dc
.DrawRectangle(x
, y
, w
, h
);
860 void MyCanvas::DrawCircles(wxDC
& dc
)
866 dc
.DrawText(_T("Some circles"), 0, y
);
867 dc
.DrawCircle(x
, y
, r
);
868 dc
.DrawCircle(x
+ 2*r
, y
, r
);
869 dc
.DrawCircle(x
+ 4*r
, y
, r
);
872 dc
.DrawText(_T("And ellipses"), 0, y
);
873 dc
.DrawEllipse(x
- r
, y
, 2*r
, r
);
874 dc
.DrawEllipse(x
+ r
, y
, 2*r
, r
);
875 dc
.DrawEllipse(x
+ 3*r
, y
, 2*r
, r
);
878 dc
.DrawText(_T("And arcs"), 0, y
);
879 dc
.DrawArc(x
- r
, y
, x
+ r
, y
, x
, y
);
880 dc
.DrawArc(x
+ 4*r
, y
, x
+ 2*r
, y
, x
+ 3*r
, y
);
881 dc
.DrawArc(x
+ 5*r
, y
, x
+ 5*r
, y
, x
+ 6*r
, y
);
884 dc
.DrawEllipticArc(x
- r
, y
, 2*r
, r
, 0, 90);
885 dc
.DrawEllipticArc(x
+ r
, y
, 2*r
, r
, 90, 180);
886 dc
.DrawEllipticArc(x
+ 3*r
, y
, 2*r
, r
, 180, 270);
887 dc
.DrawEllipticArc(x
+ 5*r
, y
, 2*r
, r
, 270, 360);
890 void MyCanvas::DrawSplines(wxDC
& dc
)
893 dc
.DrawText(_T("Some splines"), 10, 5);
895 // values are hardcoded rather than randomly generated
896 // so the output can be compared between native
897 // implementations on platforms with different random
901 const wxPoint
center( R
+ 20, R
+ 20 );
902 const int angles
[7] = { 0, 10, 33, 77, 13, 145, 90 };
903 const int radii
[5] = { 100 , 59, 85, 33, 90 };
907 // background spline calculation
908 unsigned int radius_pos
= 0;
909 unsigned int angle_pos
= 0;
911 for ( int i
= 0; i
< n
; i
++ )
913 angle
+= angles
[ angle_pos
];
914 int r
= R
* radii
[ radius_pos
] / 100;
915 pts
[ i
].x
= center
.x
+ (wxCoord
)( r
* cos( M_PI
* angle
/ 180.0) );
916 pts
[ i
].y
= center
.y
+ (wxCoord
)( r
* sin( M_PI
* angle
/ 180.0) );
919 if ( angle_pos
>= WXSIZEOF(angles
) ) angle_pos
= 0;
922 if ( radius_pos
>= WXSIZEOF(radii
) ) radius_pos
= 0;
925 // background spline drawing
926 dc
.SetPen(*wxRED_PEN
);
927 dc
.DrawSpline(WXSIZEOF(pts
), pts
);
929 // less detailed spline calculation
930 wxPoint letters
[4][5];
932 letters
[0][0] = wxPoint( 0,1); // O O
933 letters
[0][1] = wxPoint( 1,3); // * *
934 letters
[0][2] = wxPoint( 2,2); // * O *
935 letters
[0][3] = wxPoint( 3,3); // * * * *
936 letters
[0][4] = wxPoint( 4,1); // O O
938 letters
[1][0] = wxPoint( 5,1); // O*O
939 letters
[1][1] = wxPoint( 6,1); // *
940 letters
[1][2] = wxPoint( 7,2); // O
941 letters
[1][3] = wxPoint( 8,3); // *
942 letters
[1][4] = wxPoint( 9,3); // O*O
944 letters
[2][0] = wxPoint( 5,3); // O*O
945 letters
[2][1] = wxPoint( 6,3); // *
946 letters
[2][2] = wxPoint( 7,2); // O
947 letters
[2][3] = wxPoint( 8,1); // *
948 letters
[2][4] = wxPoint( 9,1); // O*O
950 letters
[3][0] = wxPoint(10,0); // O O
951 letters
[3][1] = wxPoint(11,3); // * *
952 letters
[3][2] = wxPoint(12,1); // * O *
953 letters
[3][3] = wxPoint(13,3); // * * * *
954 letters
[3][4] = wxPoint(14,0); // O O
956 const int dx
= 2 * R
/ letters
[3][4].x
;
957 const int h
[4] = { -R
/2, 0, R
/4, R
/2 };
959 for ( int m
= 0; m
< 4; m
++ )
961 for ( int n
= 0; n
< 5; n
++ )
963 letters
[m
][n
].x
= center
.x
- R
+ letters
[m
][n
].x
* dx
;
964 letters
[m
][n
].y
= center
.y
+ h
[ letters
[m
][n
].y
];
967 dc
.SetPen( wxPen( wxT("blue"), 1, wxDOT
) );
968 dc
.DrawLines(5, letters
[m
]);
969 dc
.SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
970 dc
.DrawSpline(5, letters
[m
]);
974 dc
.DrawText(_T("Splines not supported."), 10, 5);
978 void MyCanvas::DrawGradients(wxDC
& dc
)
981 wxRect
r(10, 10, 100, 100);
982 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxRIGHT
);
985 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxLEFT
);
988 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxDOWN
);
991 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxUP
);
995 r
= wxRect(200, 10, 100, 100);
996 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
);
999 dc
.GradientFillConcentric(r
, *wxWHITE
, *wxBLUE
);
1002 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
, wxPoint(0, 0));
1005 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
, wxPoint(100, 100));
1008 void MyCanvas::DrawRegions(wxDC
& dc
)
1010 dc
.DrawText(_T("You should see a red rect partly covered by a cyan one ")
1011 _T("on the left"), 10, 5);
1012 dc
.DrawText(_T("and 5 smileys from which 4 are partially clipped on the right"),
1013 10, 5 + dc
.GetCharHeight());
1014 dc
.DrawText(_T("The second copy should be identical but right part of it ")
1015 _T("should be offset by 10 pixels."),
1016 10, 5 + 2*dc
.GetCharHeight());
1018 DrawRegionsHelper(dc
, 10, true);
1019 DrawRegionsHelper(dc
, 350, false);
1022 void MyCanvas::DrawRegionsHelper(wxDC
& dc
, wxCoord x
, bool firstTime
)
1026 dc
.DestroyClippingRegion();
1027 dc
.SetBrush( *wxWHITE_BRUSH
);
1028 dc
.SetPen( *wxTRANSPARENT_PEN
);
1029 dc
.DrawRectangle( x
, y
, 310, 310 );
1031 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 270 );
1033 dc
.SetBrush( *wxRED_BRUSH
);
1034 dc
.DrawRectangle( x
, y
, 310, 310 );
1036 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 100 );
1038 dc
.SetBrush( *wxCYAN_BRUSH
);
1039 dc
.DrawRectangle( x
, y
, 310, 310 );
1041 dc
.DestroyClippingRegion();
1043 wxRegion
region(x
+ 110, y
+ 20, 100, 270);
1044 #if !defined(__WXMOTIF__) && !defined(__WXMAC__)
1046 region
.Offset(10, 10);
1048 dc
.SetClippingRegion(region
);
1050 dc
.SetBrush( *wxGREY_BRUSH
);
1051 dc
.DrawRectangle( x
, y
, 310, 310 );
1053 if (m_smile_bmp
.Ok())
1055 dc
.DrawBitmap( m_smile_bmp
, x
+ 150, y
+ 150, true );
1056 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 10, true );
1057 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 280, true );
1058 dc
.DrawBitmap( m_smile_bmp
, x
+ 100, y
+ 70, true );
1059 dc
.DrawBitmap( m_smile_bmp
, x
+ 200, y
+ 70, true );
1063 void MyCanvas::OnPaint(wxPaintEvent
&WXUNUSED(event
))
1068 m_owner
->PrepareDC(dc
);
1070 dc
.SetBackgroundMode( m_owner
->m_backgroundMode
);
1071 if ( m_owner
->m_backgroundBrush
.Ok() )
1072 dc
.SetBackground( m_owner
->m_backgroundBrush
);
1073 if ( m_owner
->m_colourForeground
.Ok() )
1074 dc
.SetTextForeground( m_owner
->m_colourForeground
);
1075 if ( m_owner
->m_colourBackground
.Ok() )
1076 dc
.SetTextBackground( m_owner
->m_colourBackground
);
1078 if ( m_owner
->m_textureBackground
) {
1079 if ( ! m_owner
->m_backgroundBrush
.Ok() ) {
1080 wxColour
clr(0,128,0);
1081 wxBrush
b(clr
, wxSOLID
);
1082 dc
.SetBackground(b
);
1087 dc
.SetClippingRegion(100, 100, 100, 100);
1091 if ( m_owner
->m_textureBackground
)
1093 dc
.SetPen(*wxMEDIUM_GREY_PEN
);
1094 for ( int i
= 0; i
< 200; i
++ )
1095 dc
.DrawLine(0, i
*10, i
*10, 0);
1121 DrawTestLines( 0, 100, 0, dc
);
1122 DrawTestLines( 0, 320, 1, dc
);
1123 DrawTestLines( 0, 540, 2, dc
);
1124 DrawTestLines( 0, 760, 6, dc
);
1128 DrawTestBrushes(dc
);
1140 DrawWithLogicalOps(dc
);
1152 void MyCanvas::OnMouseMove(wxMouseEvent
&event
)
1155 wxClientDC
dc(this);
1157 m_owner
->PrepareDC(dc
);
1159 wxPoint pos
= event
.GetPosition();
1160 long x
= dc
.DeviceToLogicalX( pos
.x
);
1161 long y
= dc
.DeviceToLogicalY( pos
.y
);
1163 str
.Printf( wxT("Current mouse position: %d,%d"), (int)x
, (int)y
);
1164 m_owner
->SetStatusText( str
);
1167 #endif // wxUSE_STATUSBAR
1170 // ----------------------------------------------------------------------------
1172 // ----------------------------------------------------------------------------
1174 // the event tables connect the wxWidgets events with the functions (event
1175 // handlers) which process them. It can be also done at run-time, but for the
1176 // simple menu events like this the static method is much simpler.
1177 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1178 EVT_MENU (File_Quit
, MyFrame::OnQuit
)
1179 EVT_MENU (File_About
, MyFrame::OnAbout
)
1180 EVT_MENU (File_Clip
, MyFrame::OnClip
)
1182 EVT_MENU_RANGE(MenuShow_First
, MenuShow_Last
, MyFrame::OnShow
)
1184 EVT_MENU_RANGE(MenuOption_First
, MenuOption_Last
, MyFrame::OnOption
)
1187 // frame constructor
1188 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
1189 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
,
1190 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
1192 // set the frame icon
1193 SetIcon(wxICON(mondrian
));
1195 wxMenu
*menuFile
= new wxMenu
;
1196 menuFile
->Append(File_ShowDefault
, _T("&Default screen\tF1"));
1197 menuFile
->Append(File_ShowText
, _T("&Text screen\tF2"));
1198 menuFile
->Append(File_ShowLines
, _T("&Lines screen\tF3"));
1199 menuFile
->Append(File_ShowBrushes
, _T("&Brushes screen\tF4"));
1200 menuFile
->Append(File_ShowPolygons
, _T("&Polygons screen\tF5"));
1201 menuFile
->Append(File_ShowMask
, _T("&Mask screen\tF6"));
1202 menuFile
->Append(File_ShowOps
, _T("&ROP screen\tF7"));
1203 menuFile
->Append(File_ShowRegions
, _T("Re&gions screen\tF8"));
1204 menuFile
->Append(File_ShowCircles
, _T("&Circles screen\tF9"));
1205 menuFile
->Append(File_ShowSplines
, _T("&Splines screen\tF11"));
1206 menuFile
->Append(File_ShowGradients
, _T("&Gradients screen\tF12"));
1207 menuFile
->AppendSeparator();
1208 menuFile
->AppendCheckItem(File_Clip
, _T("&Clip\tCtrl-C"), _T("Clip/unclip drawing"));
1209 menuFile
->AppendSeparator();
1210 menuFile
->Append(File_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
1211 menuFile
->AppendSeparator();
1212 menuFile
->Append(File_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
1214 wxMenu
*menuMapMode
= new wxMenu
;
1215 menuMapMode
->Append( MapMode_Text
, _T("&TEXT map mode") );
1216 menuMapMode
->Append( MapMode_Lometric
, _T("&LOMETRIC map mode") );
1217 menuMapMode
->Append( MapMode_Twips
, _T("T&WIPS map mode") );
1218 menuMapMode
->Append( MapMode_Points
, _T("&POINTS map mode") );
1219 menuMapMode
->Append( MapMode_Metric
, _T("&METRIC map mode") );
1221 wxMenu
*menuUserScale
= new wxMenu
;
1222 menuUserScale
->Append( UserScale_StretchHoriz
, _T("Stretch &horizontally\tCtrl-H") );
1223 menuUserScale
->Append( UserScale_ShrinkHoriz
, _T("Shrin&k horizontally\tCtrl-G") );
1224 menuUserScale
->Append( UserScale_StretchVertic
, _T("Stretch &vertically\tCtrl-V") );
1225 menuUserScale
->Append( UserScale_ShrinkVertic
, _T("&Shrink vertically\tCtrl-W") );
1226 menuUserScale
->AppendSeparator();
1227 menuUserScale
->Append( UserScale_Restore
, _T("&Restore to normal\tCtrl-0") );
1229 wxMenu
*menuAxis
= new wxMenu
;
1230 menuAxis
->AppendCheckItem( AxisMirror_Horiz
, _T("Mirror horizontally\tCtrl-M") );
1231 menuAxis
->AppendCheckItem( AxisMirror_Vertic
, _T("Mirror vertically\tCtrl-N") );
1233 wxMenu
*menuLogical
= new wxMenu
;
1234 menuLogical
->Append( LogicalOrigin_MoveDown
, _T("Move &down\tCtrl-D") );
1235 menuLogical
->Append( LogicalOrigin_MoveUp
, _T("Move &up\tCtrl-U") );
1236 menuLogical
->Append( LogicalOrigin_MoveLeft
, _T("Move &right\tCtrl-L") );
1237 menuLogical
->Append( LogicalOrigin_MoveRight
, _T("Move &left\tCtrl-R") );
1238 menuLogical
->AppendSeparator();
1239 menuLogical
->Append( LogicalOrigin_Set
, _T("Set to (&100, 100)\tShift-Ctrl-1") );
1240 menuLogical
->Append( LogicalOrigin_Restore
, _T("&Restore to normal\tShift-Ctrl-0") );
1242 wxMenu
*menuColour
= new wxMenu
;
1244 menuColour
->Append( Colour_TextForeground
, _T("Text &foreground...") );
1245 menuColour
->Append( Colour_TextBackground
, _T("Text &background...") );
1246 menuColour
->Append( Colour_Background
, _T("Background &colour...") );
1247 #endif // wxUSE_COLOURDLG
1248 menuColour
->AppendCheckItem( Colour_BackgroundMode
, _T("&Opaque/transparent\tCtrl-B") );
1249 menuColour
->AppendCheckItem( Colour_TextureBackgound
, _T("Draw textured back&ground\tCtrl-T") );
1251 // now append the freshly created menu to the menu bar...
1252 wxMenuBar
*menuBar
= new wxMenuBar
;
1253 menuBar
->Append(menuFile
, _T("&File"));
1254 menuBar
->Append(menuMapMode
, _T("&Mode"));
1255 menuBar
->Append(menuUserScale
, _T("&Scale"));
1256 menuBar
->Append(menuAxis
, _T("&Axis"));
1257 menuBar
->Append(menuLogical
, _T("&Origin"));
1258 menuBar
->Append(menuColour
, _T("&Colours"));
1260 // ... and attach this menu bar to the frame
1261 SetMenuBar(menuBar
);
1265 SetStatusText(_T("Welcome to wxWidgets!"));
1266 #endif // wxUSE_STATUSBAR
1268 m_mapMode
= wxMM_TEXT
;
1271 m_xLogicalOrigin
= 0;
1272 m_yLogicalOrigin
= 0;
1274 m_yAxisReversed
= false;
1275 m_backgroundMode
= wxSOLID
;
1276 m_colourForeground
= *wxRED
;
1277 m_colourBackground
= *wxBLUE
;
1278 m_textureBackground
= false;
1280 m_canvas
= new MyCanvas( this );
1281 m_canvas
->SetScrollbars( 10, 10, 100, 240 );
1286 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
1288 // true is to force the frame to close
1292 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
1295 msg
.Printf( wxT("This is the about dialog of the drawing sample.\n")
1296 wxT("This sample tests various primitive drawing functions\n")
1297 wxT("(without any attempts to prevent flicker).\n")
1298 wxT("Copyright (c) Robert Roebling 1999")
1301 wxMessageBox(msg
, _T("About Drawing"), wxOK
| wxICON_INFORMATION
, this);
1304 void MyFrame::OnClip(wxCommandEvent
& event
)
1306 m_canvas
->Clip(event
.IsChecked());
1309 void MyFrame::OnShow(wxCommandEvent
& event
)
1311 m_canvas
->ToShow((ScreenToShow
)(event
.GetId() - MenuShow_First
));
1314 void MyFrame::OnOption(wxCommandEvent
& event
)
1316 switch (event
.GetId())
1319 m_mapMode
= wxMM_TEXT
;
1321 case MapMode_Lometric
:
1322 m_mapMode
= wxMM_LOMETRIC
;
1325 m_mapMode
= wxMM_TWIPS
;
1327 case MapMode_Points
:
1328 m_mapMode
= wxMM_POINTS
;
1330 case MapMode_Metric
:
1331 m_mapMode
= wxMM_METRIC
;
1334 case LogicalOrigin_MoveDown
:
1335 m_yLogicalOrigin
+= 10;
1337 case LogicalOrigin_MoveUp
:
1338 m_yLogicalOrigin
-= 10;
1340 case LogicalOrigin_MoveLeft
:
1341 m_xLogicalOrigin
+= 10;
1343 case LogicalOrigin_MoveRight
:
1344 m_xLogicalOrigin
-= 10;
1346 case LogicalOrigin_Set
:
1348 m_yLogicalOrigin
= -100;
1350 case LogicalOrigin_Restore
:
1352 m_yLogicalOrigin
= 0;
1355 case UserScale_StretchHoriz
:
1356 m_xUserScale
*= 1.10;
1358 case UserScale_ShrinkHoriz
:
1359 m_xUserScale
/= 1.10;
1361 case UserScale_StretchVertic
:
1362 m_yUserScale
*= 1.10;
1364 case UserScale_ShrinkVertic
:
1365 m_yUserScale
/= 1.10;
1367 case UserScale_Restore
:
1372 case AxisMirror_Vertic
:
1373 m_yAxisReversed
= !m_yAxisReversed
;
1375 case AxisMirror_Horiz
:
1376 m_xAxisReversed
= !m_xAxisReversed
;
1380 case Colour_TextForeground
:
1381 m_colourForeground
= SelectColour();
1383 case Colour_TextBackground
:
1384 m_colourBackground
= SelectColour();
1386 case Colour_Background
:
1388 wxColour col
= SelectColour();
1391 m_backgroundBrush
.SetColour(col
);
1395 #endif // wxUSE_COLOURDLG
1397 case Colour_BackgroundMode
:
1398 m_backgroundMode
= m_backgroundMode
== wxSOLID
? wxTRANSPARENT
1402 case Colour_TextureBackgound
:
1403 m_textureBackground
= ! m_textureBackground
;
1411 m_canvas
->Refresh();
1414 void MyFrame::PrepareDC(wxDC
& dc
)
1416 dc
.SetLogicalOrigin( m_xLogicalOrigin
, m_yLogicalOrigin
);
1417 dc
.SetAxisOrientation( !m_xAxisReversed
, m_yAxisReversed
);
1418 dc
.SetUserScale( m_xUserScale
, m_yUserScale
);
1419 dc
.SetMapMode( m_mapMode
);
1423 wxColour
MyFrame::SelectColour()
1427 wxColourDialog
dialog(this, &data
);
1429 if ( dialog
.ShowModal() == wxID_OK
)
1431 col
= dialog
.GetColourData().GetColour();
1436 #endif // wxUSE_COLOURDLG