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 #if defined(__GNUG__) && !defined(__APPLE__)
21 #pragma implementation
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" wxWidgets headers
38 #include "wx/colordlg.h"
40 #include "wx/artprov.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // the application icon
47 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
48 #include "mondrian.xpm"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // what do we show on screen (there are too many shapes to put them all on
56 // screen simultaneously)
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 static wxBitmap
*gs_bmpNoMask
= NULL
,
76 *gs_bmpWithColMask
= NULL
,
78 *gs_bmpWithMask
= NULL
,
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // Define a new application type, each program should derive a class from wxApp
88 class MyApp
: public wxApp
91 // override base class virtuals
92 // ----------------------------
94 // this one is called on application startup and is a good place for the app
95 // initialization (doing it here and not in the ctor allows to have an error
96 // return: if OnInit() returns false, the application terminates)
97 virtual bool OnInit();
99 virtual int OnExit() { DeleteBitmaps(); return 0; }
102 void DeleteBitmaps();
109 // Define a new frame type: this is going to be our main frame
110 class MyFrame
: public wxFrame
114 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
116 // event handlers (these functions should _not_ be virtual)
117 void OnQuit(wxCommandEvent
& event
);
118 void OnAbout(wxCommandEvent
& event
);
119 void OnClip(wxCommandEvent
& event
);
120 void OnShow(wxCommandEvent
&event
);
121 void OnOption(wxCommandEvent
&event
);
124 wxColour
SelectColour();
125 #endif // wxUSE_COLOURDLG
126 void PrepareDC(wxDC
& dc
);
128 int m_backgroundMode
;
129 int m_textureBackground
;
133 int m_xLogicalOrigin
;
134 int m_yLogicalOrigin
;
135 bool m_xAxisReversed
,
137 wxColour m_colourForeground
, // these are _text_ colours
139 wxBrush m_backgroundBrush
;
143 // any class wishing to process wxWidgets events must use this macro
144 DECLARE_EVENT_TABLE()
147 // define a scrollable canvas for drawing onto
148 class MyCanvas
: public wxScrolledWindow
151 MyCanvas( MyFrame
*parent
);
153 void OnPaint(wxPaintEvent
&event
);
154 void OnMouseMove(wxMouseEvent
&event
);
156 void ToShow(ScreenToShow show
) { m_show
= show
; Refresh(); }
158 // set or remove the clipping region
159 void Clip(bool clip
) { m_clip
= clip
; Refresh(); }
162 void DrawTestLines( int x
, int y
, int width
, wxDC
&dc
);
163 void DrawTestPoly(wxDC
& dc
);
164 void DrawTestBrushes(wxDC
& dc
);
165 void DrawText(wxDC
& dc
);
166 void DrawImages(wxDC
& dc
);
167 void DrawWithLogicalOps(wxDC
& dc
);
168 void DrawRegions(wxDC
& dc
);
169 void DrawCircles(wxDC
& dc
);
170 void DrawSplines(wxDC
& dc
);
171 void DrawDefault(wxDC
& dc
);
173 void DrawRegionsHelper(wxDC
& dc
, wxCoord x
, bool firstTime
);
179 wxBitmap m_smile_bmp
;
183 DECLARE_EVENT_TABLE()
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 // IDs for the controls and the menu commands
194 File_Quit
= wxID_EXIT
,
195 File_About
= wxID_ABOUT
,
197 MenuShow_First
= wxID_HIGHEST
,
198 File_ShowDefault
= MenuShow_First
,
208 MenuShow_Last
= File_ShowSplines
,
214 MapMode_Text
= MenuOption_First
,
220 UserScale_StretchHoriz
,
221 UserScale_ShrinkHoriz
,
222 UserScale_StretchVertic
,
223 UserScale_ShrinkVertic
,
229 LogicalOrigin_MoveDown
,
230 LogicalOrigin_MoveUp
,
231 LogicalOrigin_MoveLeft
,
232 LogicalOrigin_MoveRight
,
234 LogicalOrigin_Restore
,
237 Colour_TextForeground
,
238 Colour_TextBackground
,
240 #endif // wxUSE_COLOURDLG
241 Colour_BackgroundMode
,
242 Colour_TextureBackgound
,
244 MenuOption_Last
= Colour_TextureBackgound
247 // ----------------------------------------------------------------------------
248 // event tables and other macros for wxWidgets
249 // ----------------------------------------------------------------------------
252 // Create a new application object: this macro will allow wxWidgets to create
253 // the application object during program execution (it's better than using a
254 // static object for many reasons) and also declares the accessor function
255 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
259 // ============================================================================
261 // ============================================================================
263 // ----------------------------------------------------------------------------
264 // the application class
265 // ----------------------------------------------------------------------------
267 bool MyApp::LoadImages()
269 gs_bmpNoMask
= new wxBitmap
;
270 gs_bmpWithColMask
= new wxBitmap
;
271 gs_bmpMask
= new wxBitmap
;
272 gs_bmpWithMask
= new wxBitmap
;
273 gs_bmp4
= new wxBitmap
;
274 gs_bmp4_mono
= new wxBitmap
;
275 gs_bmp36
= new wxBitmap
;
278 pathList
.Add(_T("."));
279 pathList
.Add(_T(".."));
281 wxString path
= pathList
.FindValidPath(_T("pat4.bmp"));
285 /* 4 colour bitmap */
286 gs_bmp4
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
287 /* turn into mono-bitmap */
288 gs_bmp4_mono
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
289 wxMask
* mask4
= new wxMask(*gs_bmp4_mono
, *wxBLACK
);
290 gs_bmp4_mono
->SetMask(mask4
);
292 path
= pathList
.FindValidPath(_T("pat36.bmp"));
295 gs_bmp36
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
296 wxMask
* mask36
= new wxMask(*gs_bmp36
, *wxBLACK
);
297 gs_bmp36
->SetMask(mask36
);
299 path
= pathList
.FindValidPath(_T("image.bmp"));
302 gs_bmpNoMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
303 gs_bmpWithMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
304 gs_bmpWithColMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
306 path
= pathList
.FindValidPath(_T("mask.bmp"));
309 gs_bmpMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
311 wxMask
*mask
= new wxMask(*gs_bmpMask
, *wxBLACK
);
312 gs_bmpWithMask
->SetMask(mask
);
314 mask
= new wxMask(*gs_bmpWithColMask
, *wxWHITE
);
315 gs_bmpWithColMask
->SetMask(mask
);
320 // `Main program' equivalent: the program execution "starts" here
323 // Create the main application window
324 MyFrame
*frame
= new MyFrame(_T("Drawing sample"),
325 wxPoint(50, 50), wxSize(550, 340));
327 // Show it and tell the application that it's our main window
333 wxLogError(wxT("Can't load one of the bitmap files needed ")
334 wxT("for this sample from the current or parent ")
335 wxT("directory, please copy them there."));
347 void MyApp::DeleteBitmaps()
350 delete gs_bmpWithColMask
;
352 delete gs_bmpWithMask
;
358 gs_bmpWithColMask
= NULL
;
360 gs_bmpWithMask
= NULL
;
366 // ----------------------------------------------------------------------------
368 // ----------------------------------------------------------------------------
370 // the event tables connect the wxWidgets events with the functions (event
371 // handlers) which process them.
372 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
373 EVT_PAINT (MyCanvas::OnPaint
)
374 EVT_MOTION (MyCanvas::OnMouseMove
)
379 MyCanvas::MyCanvas(MyFrame
*parent
)
380 : wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
381 wxHSCROLL
| wxVSCROLL
| wxNO_FULL_REPAINT_ON_RESIZE
)
384 m_show
= Show_Default
;
385 m_smile_bmp
= wxBitmap(smile_xpm
);
386 m_std_icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
390 void MyCanvas::DrawTestBrushes(wxDC
& dc
)
392 static const wxCoord WIDTH
= 200;
393 static const wxCoord HEIGHT
= 80;
398 dc
.SetBrush(wxBrush(*wxGREEN
, wxSOLID
));
399 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
400 dc
.DrawText(_T("Solid green"), x
+ 10, y
+ 10);
403 dc
.SetBrush(wxBrush(*wxRED
, wxCROSSDIAG_HATCH
));
404 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
405 dc
.DrawText(_T("Hatched red"), x
+ 10, y
+ 10);
408 dc
.SetBrush(wxBrush(*gs_bmpMask
));
409 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
410 dc
.DrawText(_T("Stipple mono"), x
+ 10, y
+ 10);
413 dc
.SetBrush(wxBrush(*gs_bmpNoMask
));
414 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
415 dc
.DrawText(_T("Stipple colour"), x
+ 10, y
+ 10);
418 void MyCanvas::DrawTestPoly(wxDC
& dc
)
420 wxBrush
brushHatch(*wxRED
, wxFDIAGONAL_HATCH
);
421 dc
.SetBrush(brushHatch
);
424 star
[0] = wxPoint(100, 60);
425 star
[1] = wxPoint(60, 150);
426 star
[2] = wxPoint(160, 100);
427 star
[3] = wxPoint(40, 100);
428 star
[4] = wxPoint(140, 150);
430 dc
.DrawText(_T("You should see two (irregular) stars below, the left one ")
431 _T("hatched"), 10, 10);
432 dc
.DrawText(_T("except for the central region and the right ")
433 _T("one entirely hatched"), 10, 30);
434 dc
.DrawText(_T("The third star only has a hatched outline"), 10, 50);
436 dc
.DrawPolygon(WXSIZEOF(star
), star
, 0, 30);
437 dc
.DrawPolygon(WXSIZEOF(star
), star
, 160, 30, wxWINDING_RULE
);
440 star2
[0] = wxPoint(0, 100);
441 star2
[1] = wxPoint(-59, -81);
442 star2
[2] = wxPoint(95, 31);
443 star2
[3] = wxPoint(-95, 31);
444 star2
[4] = wxPoint(59, -81);
445 star2
[5] = wxPoint(0, 80);
446 star2
[6] = wxPoint(-47, -64);
447 star2
[7] = wxPoint(76, 24);
448 star2
[8] = wxPoint(-76, 24);
449 star2
[9] = wxPoint(47, -64);
450 int count
[2] = {5, 5};
452 dc
.DrawPolyPolygon(WXSIZEOF(count
), count
, star2
, 450, 150);
455 void MyCanvas::DrawTestLines( int x
, int y
, int width
, wxDC
&dc
)
457 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
458 dc
.SetBrush( *wxRED_BRUSH
);
459 dc
.DrawText(wxString::Format(wxT("Testing lines of width %d"), width
), x
+ 10, y
- 10);
460 dc
.DrawRectangle( x
+10, y
+10, 100, 190 );
462 dc
.DrawText(_T("Solid/dot/short dash/long dash/dot dash"), x
+ 150, y
+ 10);
463 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
464 dc
.DrawLine( x
+20, y
+20, 100, y
+20 );
465 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT
) );
466 dc
.DrawLine( x
+20, y
+30, 100, y
+30 );
467 dc
.SetPen( wxPen( wxT("black"), width
, wxSHORT_DASH
) );
468 dc
.DrawLine( x
+20, y
+40, 100, y
+40 );
469 dc
.SetPen( wxPen( wxT("black"), width
, wxLONG_DASH
) );
470 dc
.DrawLine( x
+20, y
+50, 100, y
+50 );
471 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT_DASH
) );
472 dc
.DrawLine( x
+20, y
+60, 100, y
+60 );
474 dc
.DrawText(_T("Misc hatches"), x
+ 150, y
+ 70);
475 dc
.SetPen( wxPen( wxT("black"), width
, wxBDIAGONAL_HATCH
) );
476 dc
.DrawLine( x
+20, y
+70, 100, y
+70 );
477 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSSDIAG_HATCH
) );
478 dc
.DrawLine( x
+20, y
+80, 100, y
+80 );
479 dc
.SetPen( wxPen( wxT("black"), width
, wxFDIAGONAL_HATCH
) );
480 dc
.DrawLine( x
+20, y
+90, 100, y
+90 );
481 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSS_HATCH
) );
482 dc
.DrawLine( x
+20, y
+100, 100, y
+100 );
483 dc
.SetPen( wxPen( wxT("black"), width
, wxHORIZONTAL_HATCH
) );
484 dc
.DrawLine( x
+20, y
+110, 100, y
+110 );
485 dc
.SetPen( wxPen( wxT("black"), width
, wxVERTICAL_HATCH
) );
486 dc
.DrawLine( x
+20, y
+120, 100, y
+120 );
488 dc
.DrawText(_T("User dash"), x
+ 150, y
+ 140);
489 wxPen
ud( wxT("black"), width
, wxUSER_DASH
);
491 dash1
[0] = 8; // Long dash <---------+
492 dash1
[1] = 2; // Short gap |
493 dash1
[2] = 3; // Short dash |
494 dash1
[3] = 2; // Short gap |
495 dash1
[4] = 3; // Short dash |
496 dash1
[5] = 2; // Short gap and repeat +
497 ud
.SetDashes( 6, dash1
);
499 dc
.DrawLine( x
+20, y
+140, 100, y
+140 );
500 dash1
[0] = 5; // Make first dash shorter
501 ud
.SetDashes( 6, dash1
);
503 dc
.DrawLine( x
+20, y
+150, 100, y
+150 );
504 dash1
[2] = 5; // Make second dash longer
505 ud
.SetDashes( 6, dash1
);
507 dc
.DrawLine( x
+20, y
+160, 100, y
+160 );
508 dash1
[4] = 5; // Make third dash longer
509 ud
.SetDashes( 6, dash1
);
511 dc
.DrawLine( x
+20, y
+170, 100, y
+170 );
514 void MyCanvas::DrawDefault(wxDC
& dc
)
517 dc
.DrawCircle(0, 0, 10);
519 #if !wxMAC_USE_CORE_GRAPHICS
520 // GetPixel and FloodFill not supported by Mac OS X CoreGraphics
521 // (FloodFill uses Blit from a non-wxMemoryDC)
522 //flood fill using brush, starting at 1,1 and replacing whatever colour we find there
523 dc
.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID
));
526 dc
.GetPixel(1,1, &tmpColour
);
527 dc
.FloodFill(1,1, tmpColour
, wxFLOOD_SURFACE
);
530 dc
.DrawCheckMark(5, 80, 15, 15);
531 dc
.DrawCheckMark(25, 80, 30, 30);
532 dc
.DrawCheckMark(60, 80, 60, 60);
534 // this is the test for "blitting bitmap into DC damages selected brush" bug
535 wxCoord rectSize
= m_std_icon
.GetWidth() + 10;
537 dc
.SetPen(*wxTRANSPARENT_PEN
);
538 dc
.SetBrush( *wxGREEN_BRUSH
);
539 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
540 dc
.DrawBitmap(m_std_icon
, x
+ 5, 15, true);
542 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
543 dc
.DrawIcon(m_std_icon
, x
+ 5, 15);
545 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
547 // test for "transparent" bitmap drawing (it intersects with the last
549 //dc.SetBrush( *wxTRANSPARENT_BRUSH );
551 if (m_smile_bmp
.Ok())
552 dc
.DrawBitmap(m_smile_bmp
, x
+ rectSize
- 20, rectSize
- 10, true);
554 dc
.SetBrush( *wxBLACK_BRUSH
);
555 dc
.DrawRectangle( 0, 160, 1000, 300 );
558 wxBitmap
bitmap(20,70);
560 memdc
.SelectObject( bitmap
);
561 memdc
.SetBrush( *wxBLACK_BRUSH
);
562 memdc
.SetPen( *wxWHITE_PEN
);
563 memdc
.DrawRectangle(0,0,20,70);
564 memdc
.DrawLine( 10,0,10,70 );
567 wxPen pen
= *wxRED_PEN
;
569 memdc
.DrawLine( 10, 5,10, 5 );
570 memdc
.DrawLine( 10,10,11,10 );
571 memdc
.DrawLine( 10,15,12,15 );
572 memdc
.DrawLine( 10,20,13,20 );
575 memdc.SetPen(*wxRED_PEN);
576 memdc.DrawLine( 12, 5,12, 5 );
577 memdc.DrawLine( 12,10,13,10 );
578 memdc.DrawLine( 12,15,14,15 );
579 memdc.DrawLine( 12,20,15,20 );
583 memdc
.DrawLine( 10,25,10,25 );
584 memdc
.DrawLine( 10,30, 9,30 );
585 memdc
.DrawLine( 10,35, 8,35 );
586 memdc
.DrawLine( 10,40, 7,40 );
589 dc
.SetPen(*wxWHITE_PEN
);
590 memdc
.SetLogicalFunction( wxINVERT
);
591 memdc
.SetPen( *wxWHITE_PEN
);
592 memdc
.DrawLine( 10,50,10,50 );
593 memdc
.DrawLine( 10,55,11,55 );
594 memdc
.DrawLine( 10,60,12,60 );
595 memdc
.DrawLine( 10,65,13,65 );
597 memdc
.DrawLine( 12,50,12,50 );
598 memdc
.DrawLine( 12,55,13,55 );
599 memdc
.DrawLine( 12,60,14,60 );
600 memdc
.DrawLine( 12,65,15,65 );
602 memdc
.SelectObject( wxNullBitmap
);
603 dc
.DrawBitmap( bitmap
, 10, 170 );
604 wxImage image
= bitmap
.ConvertToImage();
605 image
.Rescale( 60,210 );
606 bitmap
= wxBitmap(image
);
607 dc
.DrawBitmap( bitmap
, 50, 170 );
609 // test the rectangle outline drawing - there should be one pixel between
610 // the rect and the lines
611 dc
.SetPen(*wxWHITE_PEN
);
612 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
613 dc
.DrawRectangle(150, 170, 49, 29);
614 dc
.DrawRectangle(200, 170, 49, 29);
615 dc
.SetPen(*wxWHITE_PEN
);
616 dc
.DrawLine(250, 210, 250, 170);
617 dc
.DrawLine(260, 200, 150, 200);
619 // test the rectangle filled drawing - there should be one pixel between
620 // the rect and the lines
621 dc
.SetPen(*wxTRANSPARENT_PEN
);
622 dc
.SetBrush( *wxWHITE_BRUSH
);
623 dc
.DrawRectangle(300, 170, 49, 29);
624 dc
.DrawRectangle(350, 170, 49, 29);
625 dc
.SetPen(*wxWHITE_PEN
);
626 dc
.DrawLine(400, 170, 400, 210);
627 dc
.DrawLine(300, 200, 410, 200);
629 // a few more tests of this kind
630 dc
.SetPen(*wxRED_PEN
);
631 dc
.SetBrush( *wxWHITE_BRUSH
);
632 dc
.DrawRectangle(300, 220, 1, 1);
633 dc
.DrawRectangle(310, 220, 2, 2);
634 dc
.DrawRectangle(320, 220, 3, 3);
635 dc
.DrawRectangle(330, 220, 4, 4);
637 dc
.SetPen(*wxTRANSPARENT_PEN
);
638 dc
.SetBrush( *wxWHITE_BRUSH
);
639 dc
.DrawRectangle(300, 230, 1, 1);
640 dc
.DrawRectangle(310, 230, 2, 2);
641 dc
.DrawRectangle(320, 230, 3, 3);
642 dc
.DrawRectangle(330, 230, 4, 4);
644 // and now for filled rect with outline
645 dc
.SetPen(*wxRED_PEN
);
646 dc
.SetBrush( *wxWHITE_BRUSH
);
647 dc
.DrawRectangle(500, 170, 49, 29);
648 dc
.DrawRectangle(550, 170, 49, 29);
649 dc
.SetPen(*wxWHITE_PEN
);
650 dc
.DrawLine(600, 170, 600, 210);
651 dc
.DrawLine(500, 200, 610, 200);
653 // test the rectangle outline drawing - there should be one pixel between
654 // the rect and the lines
655 dc
.SetPen(*wxWHITE_PEN
);
656 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
657 dc
.DrawRoundedRectangle(150, 270, 49, 29, 6);
658 dc
.DrawRoundedRectangle(200, 270, 49, 29, 6);
659 dc
.SetPen(*wxWHITE_PEN
);
660 dc
.DrawLine(250, 270, 250, 310);
661 dc
.DrawLine(150, 300, 260, 300);
663 // test the rectangle filled drawing - there should be one pixel between
664 // the rect and the lines
665 dc
.SetPen(*wxTRANSPARENT_PEN
);
666 dc
.SetBrush( *wxWHITE_BRUSH
);
667 dc
.DrawRoundedRectangle(300, 270, 49, 29, 6);
668 dc
.DrawRoundedRectangle(350, 270, 49, 29, 6);
669 dc
.SetPen(*wxWHITE_PEN
);
670 dc
.DrawLine(400, 270, 400, 310);
671 dc
.DrawLine(300, 300, 410, 300);
673 // Added by JACS to demonstrate bizarre behaviour.
674 // With a size of 70, we get a missing red RHS,
675 // and the height is too small, so we get yellow
676 // showing. With a size of 40, it draws as expected:
677 // it just shows a white rectangle with red outline.
679 int totalHeight
= 70;
680 wxBitmap
bitmap2(totalWidth
, totalHeight
);
683 memdc2
.SelectObject(bitmap2
);
685 wxColour
clr(255, 255, 0);
686 wxBrush
yellowBrush(clr
, wxSOLID
);
687 memdc2
.SetBackground(yellowBrush
);
690 wxPen
yellowPen(clr
, 1, wxSOLID
);
692 // Now draw a white rectangle with red outline. It should
693 // entirely eclipse the yellow background.
694 memdc2
.SetPen(*wxRED_PEN
);
695 memdc2
.SetBrush(*wxWHITE_BRUSH
);
697 memdc2
.DrawRectangle(0, 0, totalWidth
, totalHeight
);
699 memdc2
.SetPen(wxNullPen
);
700 memdc2
.SetBrush(wxNullBrush
);
701 memdc2
.SelectObject(wxNullBitmap
);
703 dc
.DrawBitmap(bitmap2
, 500, 270);
705 // Repeat, but draw directly on dc
706 // Draw a yellow rectangle filling the bitmap
708 x
= 600; int y
= 270;
709 dc
.SetPen(yellowPen
);
710 dc
.SetBrush(yellowBrush
);
711 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
713 // Now draw a white rectangle with red outline. It should
714 // entirely eclipse the yellow background.
715 dc
.SetPen(*wxRED_PEN
);
716 dc
.SetBrush(*wxWHITE_BRUSH
);
718 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
721 void MyCanvas::DrawText(wxDC
& dc
)
723 // set underlined font for testing
724 dc
.SetFont( wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, true) );
725 dc
.DrawText( _T("This is text"), 110, 10 );
726 dc
.DrawRotatedText( _T("That is text"), 20, 10, -45 );
728 // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
729 // under Win9x (it is not TrueType)
730 dc
.SetFont( *wxSWISS_FONT
);
733 dc
.SetBackgroundMode(wxTRANSPARENT
);
735 for ( int n
= -180; n
< 180; n
+= 30 )
737 text
.Printf(wxT(" %d rotated text"), n
);
738 dc
.DrawRotatedText(text
, 400, 400, n
);
741 dc
.SetFont( wxFont( 18, wxSWISS
, wxNORMAL
, wxNORMAL
) );
743 dc
.DrawText( _T("This is Swiss 18pt text."), 110, 40 );
748 dc
.GetTextExtent( _T("This is Swiss 18pt text."), &length
, &height
, &descent
);
749 text
.Printf( wxT("Dimensions are length %ld, height %ld, descent %ld"), length
, height
, descent
);
750 dc
.DrawText( text
, 110, 80 );
752 text
.Printf( wxT("CharHeight() returns: %d"), dc
.GetCharHeight() );
753 dc
.DrawText( text
, 110, 120 );
755 dc
.DrawRectangle( 100, 40, 4, height
);
757 // test the logical function effect
759 dc
.SetLogicalFunction(wxINVERT
);
760 dc
.DrawText( _T("There should be no text below"), 110, 150 );
761 dc
.DrawRectangle( 110, y
, 100, height
);
763 // twice drawn inverted should result in invisible
765 dc
.DrawText( _T("Invisible text"), 110, y
);
766 dc
.DrawRectangle( 110, y
, 100, height
);
767 dc
.DrawText( _T("Invisible text"), 110, y
);
768 dc
.DrawRectangle( 110, y
, 100, height
);
769 dc
.SetLogicalFunction(wxCOPY
);
772 dc
.DrawRectangle( 110, y
, 100, height
);
773 dc
.DrawText( _T("Visible text"), 110, y
);
780 } rasterOperations
[] =
782 { wxT("wxAND"), wxAND
},
783 { wxT("wxAND_INVERT"), wxAND_INVERT
},
784 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
785 { wxT("wxCLEAR"), wxCLEAR
},
786 { wxT("wxCOPY"), wxCOPY
},
787 { wxT("wxEQUIV"), wxEQUIV
},
788 { wxT("wxINVERT"), wxINVERT
},
789 { wxT("wxNAND"), wxNAND
},
790 { wxT("wxNO_OP"), wxNO_OP
},
791 { wxT("wxOR"), wxOR
},
792 { wxT("wxOR_INVERT"), wxOR_INVERT
},
793 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
794 { wxT("wxSET"), wxSET
},
795 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
796 { wxT("wxXOR"), wxXOR
},
799 void MyCanvas::DrawImages(wxDC
& dc
)
801 dc
.DrawText(_T("original image"), 0, 0);
802 dc
.DrawBitmap(*gs_bmpNoMask
, 0, 20, 0);
803 dc
.DrawText(_T("with colour mask"), 0, 100);
804 dc
.DrawBitmap(*gs_bmpWithColMask
, 0, 120, true);
805 dc
.DrawText(_T("the mask image"), 0, 200);
806 dc
.DrawBitmap(*gs_bmpMask
, 0, 220, 0);
807 dc
.DrawText(_T("masked image"), 0, 300);
808 dc
.DrawBitmap(*gs_bmpWithMask
, 0, 320, true);
810 int cx
= gs_bmpWithColMask
->GetWidth(),
811 cy
= gs_bmpWithColMask
->GetHeight();
814 for ( size_t n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
816 wxCoord x
= 120 + 150*(n%4
),
819 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
820 memDC
.SelectObject(*gs_bmpWithColMask
);
821 dc
.Blit(x
, y
, cx
, cy
, &memDC
, 0, 0, rasterOperations
[n
].rop
, true);
825 void MyCanvas::DrawWithLogicalOps(wxDC
& dc
)
827 static const wxCoord w
= 60;
828 static const wxCoord h
= 60;
830 // reuse the text colour here
831 dc
.SetPen(wxPen(m_owner
->m_colourForeground
, 1, wxSOLID
));
832 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
835 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
837 wxCoord x
= 20 + 150*(n%4
),
840 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
841 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
842 dc
.DrawRectangle(x
, y
, w
, h
);
843 dc
.DrawLine(x
, y
, x
+ w
, y
+ h
);
844 dc
.DrawLine(x
+ w
, y
, x
, y
+ h
);
847 // now some filled rectangles
848 dc
.SetBrush(wxBrush(m_owner
->m_colourForeground
, wxSOLID
));
850 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
852 wxCoord x
= 20 + 150*(n%4
),
855 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
856 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
857 dc
.DrawRectangle(x
, y
, w
, h
);
861 void MyCanvas::DrawCircles(wxDC
& dc
)
867 dc
.DrawText(_T("Some circles"), 0, y
);
868 dc
.DrawCircle(x
, y
, r
);
869 dc
.DrawCircle(x
+ 2*r
, y
, r
);
870 dc
.DrawCircle(x
+ 4*r
, y
, r
);
873 dc
.DrawText(_T("And ellipses"), 0, y
);
874 dc
.DrawEllipse(x
- r
, y
, 2*r
, r
);
875 dc
.DrawEllipse(x
+ r
, y
, 2*r
, r
);
876 dc
.DrawEllipse(x
+ 3*r
, y
, 2*r
, r
);
879 dc
.DrawText(_T("And arcs"), 0, y
);
880 dc
.DrawArc(x
- r
, y
, x
+ r
, y
, x
, y
);
881 dc
.DrawArc(x
+ 4*r
, y
, x
+ 2*r
, y
, x
+ 3*r
, y
);
882 dc
.DrawArc(x
+ 5*r
, y
, x
+ 5*r
, y
, x
+ 6*r
, y
);
885 dc
.DrawEllipticArc(x
- r
, y
, 2*r
, r
, 0, 90);
886 dc
.DrawEllipticArc(x
+ r
, y
, 2*r
, r
, 90, 180);
887 dc
.DrawEllipticArc(x
+ 3*r
, y
, 2*r
, r
, 180, 270);
888 dc
.DrawEllipticArc(x
+ 5*r
, y
, 2*r
, r
, 270, 360);
891 void MyCanvas::DrawSplines(wxDC
& dc
)
894 dc
.DrawText(_T("Some splines"), 10, 5);
896 // values are hardcoded rather than randomly generated
897 // so the output can be compared between native
898 // implementations on platforms with different random
902 const wxPoint
center( R
+ 20, R
+ 20 );
903 const int angles
[7] = { 0, 10, 33, 77, 13, 145, 90 };
904 const int radii
[5] = { 100 , 59, 85, 33, 90 };
908 // background spline calculation
909 unsigned int radius_pos
= 0;
910 unsigned int angle_pos
= 0;
912 for ( int i
= 0; i
< n
; i
++ )
914 angle
+= angles
[ angle_pos
];
915 int r
= R
* radii
[ radius_pos
] / 100;
916 pts
[ i
].x
= center
.x
+ (wxCoord
)( r
* cos( M_PI
* angle
/ 180.0) );
917 pts
[ i
].y
= center
.y
+ (wxCoord
)( r
* sin( M_PI
* angle
/ 180.0) );
920 if ( angle_pos
>= WXSIZEOF(angles
) ) angle_pos
= 0;
923 if ( radius_pos
>= WXSIZEOF(radii
) ) radius_pos
= 0;
926 // background spline drawing
927 dc
.SetPen(*wxRED_PEN
);
928 dc
.DrawSpline(WXSIZEOF(pts
), pts
);
930 // less detailed spline calculation
931 wxPoint letters
[4][5];
933 letters
[0][0] = wxPoint( 0,1); // O O
934 letters
[0][1] = wxPoint( 1,3); // * *
935 letters
[0][2] = wxPoint( 2,2); // * O *
936 letters
[0][3] = wxPoint( 3,3); // * * * *
937 letters
[0][4] = wxPoint( 4,1); // O O
939 letters
[1][0] = wxPoint( 5,1); // O*O
940 letters
[1][1] = wxPoint( 6,1); // *
941 letters
[1][2] = wxPoint( 7,2); // O
942 letters
[1][3] = wxPoint( 8,3); // *
943 letters
[1][4] = wxPoint( 9,3); // O*O
945 letters
[2][0] = wxPoint( 5,3); // O*O
946 letters
[2][1] = wxPoint( 6,3); // *
947 letters
[2][2] = wxPoint( 7,2); // O
948 letters
[2][3] = wxPoint( 8,1); // *
949 letters
[2][4] = wxPoint( 9,1); // O*O
951 letters
[3][0] = wxPoint(10,0); // O O
952 letters
[3][1] = wxPoint(11,3); // * *
953 letters
[3][2] = wxPoint(12,1); // * O *
954 letters
[3][3] = wxPoint(13,3); // * * * *
955 letters
[3][4] = wxPoint(14,0); // O O
957 const int dx
= 2 * R
/ letters
[3][4].x
;
958 const int h
[4] = { -R
/2, 0, R
/4, R
/2 };
960 for ( int m
= 0; m
< 4; m
++ )
962 for ( int n
= 0; n
< 5; n
++ )
964 letters
[m
][n
].x
= center
.x
- R
+ letters
[m
][n
].x
* dx
;
965 letters
[m
][n
].y
= center
.y
+ h
[ letters
[m
][n
].y
];
968 dc
.SetPen( wxPen( wxT("blue"), 1, wxDOT
) );
969 dc
.DrawLines(5, letters
[m
]);
970 dc
.SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
971 dc
.DrawSpline(5, letters
[m
]);
975 dc
.DrawText(_T("Splines not supported."), 10, 5);
979 void MyCanvas::DrawRegions(wxDC
& dc
)
981 dc
.DrawText(_T("You should see a red rect partly covered by a cyan one ")
982 _T("on the left"), 10, 5);
983 dc
.DrawText(_T("and 5 smileys from which 4 are partially clipped on the right"),
984 10, 5 + dc
.GetCharHeight());
985 dc
.DrawText(_T("The second copy should be identical but right part of it ")
986 _T("should be offset by 10 pixels."),
987 10, 5 + 2*dc
.GetCharHeight());
989 DrawRegionsHelper(dc
, 10, true);
990 DrawRegionsHelper(dc
, 350, false);
993 void MyCanvas::DrawRegionsHelper(wxDC
& dc
, wxCoord x
, bool firstTime
)
997 dc
.DestroyClippingRegion();
998 dc
.SetBrush( *wxWHITE_BRUSH
);
999 dc
.SetPen( *wxTRANSPARENT_PEN
);
1000 dc
.DrawRectangle( x
, y
, 310, 310 );
1002 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 270 );
1004 dc
.SetBrush( *wxRED_BRUSH
);
1005 dc
.DrawRectangle( x
, y
, 310, 310 );
1007 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 100 );
1009 dc
.SetBrush( *wxCYAN_BRUSH
);
1010 dc
.DrawRectangle( x
, y
, 310, 310 );
1012 dc
.DestroyClippingRegion();
1014 wxRegion
region(x
+ 110, y
+ 20, 100, 270);
1015 #if !defined(__WXMOTIF__) && !defined(__WXMAC__)
1017 region
.Offset(10, 10);
1019 dc
.SetClippingRegion(region
);
1021 dc
.SetBrush( *wxGREY_BRUSH
);
1022 dc
.DrawRectangle( x
, y
, 310, 310 );
1024 if (m_smile_bmp
.Ok())
1026 dc
.DrawBitmap( m_smile_bmp
, x
+ 150, y
+ 150, true );
1027 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 10, true );
1028 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 280, true );
1029 dc
.DrawBitmap( m_smile_bmp
, x
+ 100, y
+ 70, true );
1030 dc
.DrawBitmap( m_smile_bmp
, x
+ 200, y
+ 70, true );
1034 void MyCanvas::OnPaint(wxPaintEvent
&WXUNUSED(event
))
1039 m_owner
->PrepareDC(dc
);
1041 dc
.SetBackgroundMode( m_owner
->m_backgroundMode
);
1042 if ( m_owner
->m_backgroundBrush
.Ok() )
1043 dc
.SetBackground( m_owner
->m_backgroundBrush
);
1044 if ( m_owner
->m_colourForeground
.Ok() )
1045 dc
.SetTextForeground( m_owner
->m_colourForeground
);
1046 if ( m_owner
->m_colourBackground
.Ok() )
1047 dc
.SetTextBackground( m_owner
->m_colourBackground
);
1049 if ( m_owner
->m_textureBackground
) {
1050 if ( ! m_owner
->m_backgroundBrush
.Ok() ) {
1051 wxColour
clr(0,128,0);
1052 wxBrush
b(clr
, wxSOLID
);
1053 dc
.SetBackground(b
);
1058 dc
.SetClippingRegion(100, 100, 100, 100);
1062 if ( m_owner
->m_textureBackground
)
1064 dc
.SetPen(*wxMEDIUM_GREY_PEN
);
1065 for ( int i
= 0; i
< 200; i
++ )
1066 dc
.DrawLine(0, i
*10, i
*10, 0);
1092 DrawTestLines( 0, 100, 0, dc
);
1093 DrawTestLines( 0, 320, 1, dc
);
1094 DrawTestLines( 0, 540, 2, dc
);
1095 DrawTestLines( 0, 760, 6, dc
);
1099 DrawTestBrushes(dc
);
1111 DrawWithLogicalOps(dc
);
1116 void MyCanvas::OnMouseMove(wxMouseEvent
&event
)
1119 wxClientDC
dc(this);
1121 m_owner
->PrepareDC(dc
);
1123 wxPoint pos
= event
.GetPosition();
1124 long x
= dc
.DeviceToLogicalX( pos
.x
);
1125 long y
= dc
.DeviceToLogicalY( pos
.y
);
1127 str
.Printf( wxT("Current mouse position: %d,%d"), (int)x
, (int)y
);
1128 m_owner
->SetStatusText( str
);
1131 #endif // wxUSE_STATUSBAR
1134 // ----------------------------------------------------------------------------
1136 // ----------------------------------------------------------------------------
1138 // the event tables connect the wxWidgets events with the functions (event
1139 // handlers) which process them. It can be also done at run-time, but for the
1140 // simple menu events like this the static method is much simpler.
1141 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1142 EVT_MENU (File_Quit
, MyFrame::OnQuit
)
1143 EVT_MENU (File_About
, MyFrame::OnAbout
)
1144 EVT_MENU (File_Clip
, MyFrame::OnClip
)
1146 EVT_MENU_RANGE(MenuShow_First
, MenuShow_Last
, MyFrame::OnShow
)
1148 EVT_MENU_RANGE(MenuOption_First
, MenuOption_Last
, MyFrame::OnOption
)
1151 // frame constructor
1152 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
1153 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
,
1154 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
1156 // set the frame icon
1157 SetIcon(wxICON(mondrian
));
1159 wxMenu
*menuFile
= new wxMenu
;
1160 menuFile
->Append(File_ShowDefault
, _T("&Default screen\tF1"));
1161 menuFile
->Append(File_ShowText
, _T("&Text screen\tF2"));
1162 menuFile
->Append(File_ShowLines
, _T("&Lines screen\tF3"));
1163 menuFile
->Append(File_ShowBrushes
, _T("&Brushes screen\tF4"));
1164 menuFile
->Append(File_ShowPolygons
, _T("&Polygons screen\tF5"));
1165 menuFile
->Append(File_ShowMask
, _T("&Mask screen\tF6"));
1166 menuFile
->Append(File_ShowOps
, _T("&ROP screen\tF7"));
1167 menuFile
->Append(File_ShowRegions
, _T("Re&gions screen\tF8"));
1168 menuFile
->Append(File_ShowCircles
, _T("&Circles screen\tF9"));
1169 menuFile
->Append(File_ShowSplines
, _T("&Splines screen"));
1170 menuFile
->AppendSeparator();
1171 menuFile
->AppendCheckItem(File_Clip
, _T("&Clip\tCtrl-C"), _T("Clip/unclip drawing"));
1172 menuFile
->AppendSeparator();
1173 menuFile
->Append(File_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
1174 menuFile
->AppendSeparator();
1175 menuFile
->Append(File_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
1177 wxMenu
*menuMapMode
= new wxMenu
;
1178 menuMapMode
->Append( MapMode_Text
, _T("&TEXT map mode") );
1179 menuMapMode
->Append( MapMode_Lometric
, _T("&LOMETRIC map mode") );
1180 menuMapMode
->Append( MapMode_Twips
, _T("T&WIPS map mode") );
1181 menuMapMode
->Append( MapMode_Points
, _T("&POINTS map mode") );
1182 menuMapMode
->Append( MapMode_Metric
, _T("&METRIC map mode") );
1184 wxMenu
*menuUserScale
= new wxMenu
;
1185 menuUserScale
->Append( UserScale_StretchHoriz
, _T("Stretch &horizontally\tCtrl-H") );
1186 menuUserScale
->Append( UserScale_ShrinkHoriz
, _T("Shrin&k horizontally\tCtrl-G") );
1187 menuUserScale
->Append( UserScale_StretchVertic
, _T("Stretch &vertically\tCtrl-V") );
1188 menuUserScale
->Append( UserScale_ShrinkVertic
, _T("&Shrink vertically\tCtrl-W") );
1189 menuUserScale
->AppendSeparator();
1190 menuUserScale
->Append( UserScale_Restore
, _T("&Restore to normal\tCtrl-0") );
1192 wxMenu
*menuAxis
= new wxMenu
;
1193 menuAxis
->AppendCheckItem( AxisMirror_Horiz
, _T("Mirror horizontally\tCtrl-M") );
1194 menuAxis
->AppendCheckItem( AxisMirror_Vertic
, _T("Mirror vertically\tCtrl-N") );
1196 wxMenu
*menuLogical
= new wxMenu
;
1197 menuLogical
->Append( LogicalOrigin_MoveDown
, _T("Move &down\tCtrl-D") );
1198 menuLogical
->Append( LogicalOrigin_MoveUp
, _T("Move &up\tCtrl-U") );
1199 menuLogical
->Append( LogicalOrigin_MoveLeft
, _T("Move &right\tCtrl-L") );
1200 menuLogical
->Append( LogicalOrigin_MoveRight
, _T("Move &left\tCtrl-R") );
1201 menuLogical
->AppendSeparator();
1202 menuLogical
->Append( LogicalOrigin_Set
, _T("Set to (&100, 100)\tShift-Ctrl-1") );
1203 menuLogical
->Append( LogicalOrigin_Restore
, _T("&Restore to normal\tShift-Ctrl-0") );
1205 wxMenu
*menuColour
= new wxMenu
;
1207 menuColour
->Append( Colour_TextForeground
, _T("Text &foreground...") );
1208 menuColour
->Append( Colour_TextBackground
, _T("Text &background...") );
1209 menuColour
->Append( Colour_Background
, _T("Background &colour...") );
1210 #endif // wxUSE_COLOURDLG
1211 menuColour
->AppendCheckItem( Colour_BackgroundMode
, _T("&Opaque/transparent\tCtrl-B") );
1212 menuColour
->AppendCheckItem( Colour_TextureBackgound
, _T("Draw textured back&ground\tCtrl-T") );
1214 // now append the freshly created menu to the menu bar...
1215 wxMenuBar
*menuBar
= new wxMenuBar
;
1216 menuBar
->Append(menuFile
, _T("&File"));
1217 menuBar
->Append(menuMapMode
, _T("&Mode"));
1218 menuBar
->Append(menuUserScale
, _T("&Scale"));
1219 menuBar
->Append(menuAxis
, _T("&Axis"));
1220 menuBar
->Append(menuLogical
, _T("&Origin"));
1221 menuBar
->Append(menuColour
, _T("&Colours"));
1223 // ... and attach this menu bar to the frame
1224 SetMenuBar(menuBar
);
1228 SetStatusText(_T("Welcome to wxWidgets!"));
1229 #endif // wxUSE_STATUSBAR
1231 m_mapMode
= wxMM_TEXT
;
1234 m_xLogicalOrigin
= 0;
1235 m_yLogicalOrigin
= 0;
1237 m_yAxisReversed
= false;
1238 m_backgroundMode
= wxSOLID
;
1239 m_colourForeground
= *wxRED
;
1240 m_colourBackground
= *wxBLUE
;
1241 m_textureBackground
= false;
1243 m_canvas
= new MyCanvas( this );
1244 m_canvas
->SetScrollbars( 10, 10, 100, 240 );
1249 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
1251 // true is to force the frame to close
1255 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
1258 msg
.Printf( wxT("This is the about dialog of the drawing sample.\n")
1259 wxT("This sample tests various primitive drawing functions\n")
1260 wxT("(without any attempts to prevent flicker).\n")
1261 wxT("Copyright (c) Robert Roebling 1999")
1264 wxMessageBox(msg
, _T("About Drawing"), wxOK
| wxICON_INFORMATION
, this);
1267 void MyFrame::OnClip(wxCommandEvent
& event
)
1269 m_canvas
->Clip(event
.IsChecked());
1272 void MyFrame::OnShow(wxCommandEvent
& event
)
1274 m_canvas
->ToShow((ScreenToShow
)(event
.GetId() - MenuShow_First
));
1277 void MyFrame::OnOption(wxCommandEvent
& event
)
1279 switch (event
.GetId())
1282 m_mapMode
= wxMM_TEXT
;
1284 case MapMode_Lometric
:
1285 m_mapMode
= wxMM_LOMETRIC
;
1288 m_mapMode
= wxMM_TWIPS
;
1290 case MapMode_Points
:
1291 m_mapMode
= wxMM_POINTS
;
1293 case MapMode_Metric
:
1294 m_mapMode
= wxMM_METRIC
;
1297 case LogicalOrigin_MoveDown
:
1298 m_yLogicalOrigin
+= 10;
1300 case LogicalOrigin_MoveUp
:
1301 m_yLogicalOrigin
-= 10;
1303 case LogicalOrigin_MoveLeft
:
1304 m_xLogicalOrigin
+= 10;
1306 case LogicalOrigin_MoveRight
:
1307 m_xLogicalOrigin
-= 10;
1309 case LogicalOrigin_Set
:
1311 m_yLogicalOrigin
= -100;
1313 case LogicalOrigin_Restore
:
1315 m_yLogicalOrigin
= 0;
1318 case UserScale_StretchHoriz
:
1319 m_xUserScale
*= 1.10;
1321 case UserScale_ShrinkHoriz
:
1322 m_xUserScale
/= 1.10;
1324 case UserScale_StretchVertic
:
1325 m_yUserScale
*= 1.10;
1327 case UserScale_ShrinkVertic
:
1328 m_yUserScale
/= 1.10;
1330 case UserScale_Restore
:
1335 case AxisMirror_Vertic
:
1336 m_yAxisReversed
= !m_yAxisReversed
;
1338 case AxisMirror_Horiz
:
1339 m_xAxisReversed
= !m_xAxisReversed
;
1343 case Colour_TextForeground
:
1344 m_colourForeground
= SelectColour();
1346 case Colour_TextBackground
:
1347 m_colourBackground
= SelectColour();
1349 case Colour_Background
:
1351 wxColour col
= SelectColour();
1354 m_backgroundBrush
.SetColour(col
);
1358 #endif // wxUSE_COLOURDLG
1360 case Colour_BackgroundMode
:
1361 m_backgroundMode
= m_backgroundMode
== wxSOLID
? wxTRANSPARENT
1365 case Colour_TextureBackgound
:
1366 m_textureBackground
= ! m_textureBackground
;
1374 m_canvas
->Refresh();
1377 void MyFrame::PrepareDC(wxDC
& dc
)
1379 dc
.SetLogicalOrigin( m_xLogicalOrigin
, m_yLogicalOrigin
);
1380 dc
.SetAxisOrientation( !m_xAxisReversed
, m_yAxisReversed
);
1381 dc
.SetUserScale( m_xUserScale
, m_yUserScale
);
1382 dc
.SetMapMode( m_mapMode
);
1386 wxColour
MyFrame::SelectColour()
1390 wxColourDialog
dialog(this, &data
);
1392 if ( dialog
.ShowModal() == wxID_OK
)
1394 col
= dialog
.GetColourData().GetColour();
1399 #endif // wxUSE_COLOURDLG