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"
36 #include "wx/dcgraph.h"
37 #include "wx/overlay.h"
38 #include "wx/graphics.h"
39 #include "wx/filename.h"
41 #define TEST_CAIRO_EVERYWHERE 0
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 // the application icon
48 #if !defined(__WXMSW__) && !defined(__WXPM__)
49 #include "../sample.xpm"
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 static wxBitmap
*gs_bmpNoMask
= NULL
,
57 *gs_bmpWithColMask
= NULL
,
59 *gs_bmpWithMask
= NULL
,
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 // Define a new application type, each program should derive a class from wxApp
69 class MyApp
: public wxApp
72 // override base class virtuals
73 // ----------------------------
75 // this one is called on application startup and is a good place for the app
76 // initialization (doing it here and not in the ctor allows to have an error
77 // return: if OnInit() returns false, the application terminates)
78 virtual bool OnInit();
80 virtual int OnExit() { DeleteBitmaps(); return 0; }
90 // Define a new frame type: this is going to be our main frame
91 class MyFrame
: public wxFrame
95 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
97 // event handlers (these functions should _not_ be virtual)
98 void OnQuit(wxCommandEvent
& event
);
99 void OnAbout(wxCommandEvent
& event
);
100 void OnClip(wxCommandEvent
& event
);
101 #if wxUSE_GRAPHICS_CONTEXT
102 void OnGraphicContext(wxCommandEvent
& event
);
104 void OnShow(wxCommandEvent
&event
);
105 void OnOption(wxCommandEvent
&event
);
108 wxColour
SelectColour();
109 #endif // wxUSE_COLOURDLG
110 void PrepareDC(wxDC
& dc
);
112 int m_backgroundMode
;
113 int m_textureBackground
;
114 wxMappingMode m_mapMode
;
117 int m_xLogicalOrigin
;
118 int m_yLogicalOrigin
;
119 bool m_xAxisReversed
,
121 wxColour m_colourForeground
, // these are _text_ colours
123 wxBrush m_backgroundBrush
;
127 // any class wishing to process wxWidgets events must use this macro
128 DECLARE_EVENT_TABLE()
131 // define a scrollable canvas for drawing onto
132 class MyCanvas
: public wxScrolledWindow
135 MyCanvas( MyFrame
*parent
);
137 void OnPaint(wxPaintEvent
&event
);
138 void OnMouseMove(wxMouseEvent
&event
);
139 void OnMouseDown(wxMouseEvent
&event
);
140 void OnMouseUp(wxMouseEvent
&event
);
142 void ToShow(int show
) { m_show
= show
; Refresh(); }
144 // set or remove the clipping region
145 void Clip(bool clip
) { m_clip
= clip
; Refresh(); }
146 #if wxUSE_GRAPHICS_CONTEXT
147 void UseGraphicContext(bool use
) { m_useContext
= use
; Refresh(); }
157 void DrawTestLines( int x
, int y
, int width
, wxDC
&dc
);
158 void DrawTestPoly(wxDC
& dc
);
159 void DrawTestBrushes(wxDC
& dc
);
160 void DrawText(wxDC
& dc
);
161 void DrawImages(wxDC
& dc
, DrawMode mode
);
162 void DrawWithLogicalOps(wxDC
& dc
);
163 #if wxUSE_GRAPHICS_CONTEXT
164 void DrawAlpha(wxDC
& dc
);
165 void DrawGraphics(wxGraphicsContext
* gc
);
167 void DrawRegions(wxDC
& dc
);
168 void DrawCircles(wxDC
& dc
);
169 void DrawSplines(wxDC
& dc
);
170 void DrawDefault(wxDC
& dc
);
171 void DrawGradients(wxDC
& dc
);
173 void DrawRegionsHelper(wxDC
& dc
, wxCoord x
, bool firstTime
);
179 wxBitmap m_smile_bmp
;
184 wxPoint m_anchorpoint
;
185 wxPoint m_currentpoint
;
186 #if wxUSE_GRAPHICS_CONTEXT
190 DECLARE_EVENT_TABLE()
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
197 // IDs for the controls and the menu commands
201 File_Quit
= wxID_EXIT
,
202 File_About
= wxID_ABOUT
,
204 MenuShow_First
= wxID_HIGHEST
,
205 File_ShowDefault
= MenuShow_First
,
211 File_ShowMaskStretch
,
216 #if wxUSE_GRAPHICS_CONTEXT
221 MenuShow_Last
= File_ShowGradients
,
224 #if wxUSE_GRAPHICS_CONTEXT
230 MapMode_Text
= MenuOption_First
,
236 UserScale_StretchHoriz
,
237 UserScale_ShrinkHoriz
,
238 UserScale_StretchVertic
,
239 UserScale_ShrinkVertic
,
245 LogicalOrigin_MoveDown
,
246 LogicalOrigin_MoveUp
,
247 LogicalOrigin_MoveLeft
,
248 LogicalOrigin_MoveRight
,
250 LogicalOrigin_Restore
,
253 Colour_TextForeground
,
254 Colour_TextBackground
,
256 #endif // wxUSE_COLOURDLG
257 Colour_BackgroundMode
,
258 Colour_TextureBackgound
,
260 MenuOption_Last
= Colour_TextureBackgound
263 // ----------------------------------------------------------------------------
264 // event tables and other macros for wxWidgets
265 // ----------------------------------------------------------------------------
268 // Create a new application object: this macro will allow wxWidgets to create
269 // the application object during program execution (it's better than using a
270 // static object for many reasons) and also declares the accessor function
271 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
275 // ============================================================================
277 // ============================================================================
279 // ----------------------------------------------------------------------------
280 // the application class
281 // ----------------------------------------------------------------------------
283 bool MyApp::LoadImages()
285 gs_bmpNoMask
= new wxBitmap
;
286 gs_bmpWithColMask
= new wxBitmap
;
287 gs_bmpMask
= new wxBitmap
;
288 gs_bmpWithMask
= new wxBitmap
;
289 gs_bmp4
= new wxBitmap
;
290 gs_bmp4_mono
= new wxBitmap
;
291 gs_bmp36
= new wxBitmap
;
294 // special hack for Unix in-tree sample build, don't do this in real
295 // programs, use wxStandardPaths instead
296 pathList
.Add(wxFileName(argv
[0]).GetPath());
297 pathList
.Add(wxT("."));
298 pathList
.Add(wxT(".."));
299 pathList
.Add(wxT("../.."));
301 wxString path
= pathList
.FindValidPath(wxT("pat4.bmp"));
305 /* 4 colour bitmap */
306 gs_bmp4
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
307 /* turn into mono-bitmap */
308 gs_bmp4_mono
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
309 wxMask
* mask4
= new wxMask(*gs_bmp4_mono
, *wxBLACK
);
310 gs_bmp4_mono
->SetMask(mask4
);
312 path
= pathList
.FindValidPath(wxT("pat36.bmp"));
315 gs_bmp36
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
316 wxMask
* mask36
= new wxMask(*gs_bmp36
, *wxBLACK
);
317 gs_bmp36
->SetMask(mask36
);
319 path
= pathList
.FindValidPath(wxT("image.bmp"));
322 gs_bmpNoMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
323 gs_bmpWithMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
324 gs_bmpWithColMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
326 path
= pathList
.FindValidPath(wxT("mask.bmp"));
329 gs_bmpMask
->LoadFile(path
, wxBITMAP_TYPE_BMP
);
331 wxMask
*mask
= new wxMask(*gs_bmpMask
, *wxBLACK
);
332 gs_bmpWithMask
->SetMask(mask
);
334 mask
= new wxMask(*gs_bmpWithColMask
, *wxWHITE
);
335 gs_bmpWithColMask
->SetMask(mask
);
340 // `Main program' equivalent: the program execution "starts" here
343 if ( !wxApp::OnInit() )
346 // Create the main application window
347 MyFrame
*frame
= new MyFrame(wxT("Drawing sample"),
348 wxDefaultPosition
, wxSize(550, 840));
350 // Show it and tell the application that it's our main window
356 wxLogError(wxT("Can't load one of the bitmap files needed ")
357 wxT("for this sample from the current or parent ")
358 wxT("directory, please copy them there."));
360 // still continue, the sample can be used without images too if they're
361 // missing for whatever reason
367 void MyApp::DeleteBitmaps()
370 delete gs_bmpWithColMask
;
372 delete gs_bmpWithMask
;
378 gs_bmpWithColMask
= NULL
;
380 gs_bmpWithMask
= NULL
;
386 // ----------------------------------------------------------------------------
388 // ----------------------------------------------------------------------------
390 // the event tables connect the wxWidgets events with the functions (event
391 // handlers) which process them.
392 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
393 EVT_PAINT (MyCanvas::OnPaint
)
394 EVT_MOTION (MyCanvas::OnMouseMove
)
395 EVT_LEFT_DOWN (MyCanvas::OnMouseDown
)
396 EVT_LEFT_UP (MyCanvas::OnMouseUp
)
401 MyCanvas::MyCanvas(MyFrame
*parent
)
402 : wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
403 wxHSCROLL
| wxVSCROLL
| wxNO_FULL_REPAINT_ON_RESIZE
)
406 m_show
= File_ShowDefault
;
407 m_smile_bmp
= wxBitmap(smile_xpm
);
408 m_std_icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
410 m_rubberBand
= false;
411 #if wxUSE_GRAPHICS_CONTEXT
412 m_useContext
= false;
416 void MyCanvas::DrawTestBrushes(wxDC
& dc
)
418 static const wxCoord WIDTH
= 200;
419 static const wxCoord HEIGHT
= 80;
424 dc
.SetBrush(wxBrush(*wxGREEN
, wxSOLID
));
425 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
426 dc
.DrawText(wxT("Solid green"), x
+ 10, y
+ 10);
429 dc
.SetBrush(wxBrush(*wxRED
, wxCROSSDIAG_HATCH
));
430 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
431 dc
.DrawText(wxT("Hatched red"), x
+ 10, y
+ 10);
434 dc
.SetBrush(wxBrush(*gs_bmpMask
));
435 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
436 dc
.DrawText(wxT("Stipple mono"), x
+ 10, y
+ 10);
439 dc
.SetBrush(wxBrush(*gs_bmpNoMask
));
440 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
441 dc
.DrawText(wxT("Stipple colour"), x
+ 10, y
+ 10);
444 void MyCanvas::DrawTestPoly(wxDC
& dc
)
446 wxBrush
brushHatch(*wxRED
, wxFDIAGONAL_HATCH
);
447 dc
.SetBrush(brushHatch
);
450 star
[0] = wxPoint(100, 60);
451 star
[1] = wxPoint(60, 150);
452 star
[2] = wxPoint(160, 100);
453 star
[3] = wxPoint(40, 100);
454 star
[4] = wxPoint(140, 150);
456 dc
.DrawText(wxT("You should see two (irregular) stars below, the left one ")
457 wxT("hatched"), 10, 10);
458 dc
.DrawText(wxT("except for the central region and the right ")
459 wxT("one entirely hatched"), 10, 30);
460 dc
.DrawText(wxT("The third star only has a hatched outline"), 10, 50);
462 dc
.DrawPolygon(WXSIZEOF(star
), star
, 0, 30);
463 dc
.DrawPolygon(WXSIZEOF(star
), star
, 160, 30, wxWINDING_RULE
);
466 star2
[0] = wxPoint(0, 100);
467 star2
[1] = wxPoint(-59, -81);
468 star2
[2] = wxPoint(95, 31);
469 star2
[3] = wxPoint(-95, 31);
470 star2
[4] = wxPoint(59, -81);
471 star2
[5] = wxPoint(0, 80);
472 star2
[6] = wxPoint(-47, -64);
473 star2
[7] = wxPoint(76, 24);
474 star2
[8] = wxPoint(-76, 24);
475 star2
[9] = wxPoint(47, -64);
476 int count
[2] = {5, 5};
478 dc
.DrawPolyPolygon(WXSIZEOF(count
), count
, star2
, 450, 150);
481 void MyCanvas::DrawTestLines( int x
, int y
, int width
, wxDC
&dc
)
483 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
484 dc
.SetBrush( *wxRED_BRUSH
);
485 dc
.DrawText(wxString::Format(wxT("Testing lines of width %d"), width
), x
+ 10, y
- 10);
486 dc
.DrawRectangle( x
+10, y
+10, 100, 190 );
488 dc
.DrawText(wxT("Solid/dot/short dash/long dash/dot dash"), x
+ 150, y
+ 10);
489 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
490 dc
.DrawLine( x
+20, y
+20, 100, y
+20 );
491 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT
) );
492 dc
.DrawLine( x
+20, y
+30, 100, y
+30 );
493 dc
.SetPen( wxPen( wxT("black"), width
, wxSHORT_DASH
) );
494 dc
.DrawLine( x
+20, y
+40, 100, y
+40 );
495 dc
.SetPen( wxPen( wxT("black"), width
, wxLONG_DASH
) );
496 dc
.DrawLine( x
+20, y
+50, 100, y
+50 );
497 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT_DASH
) );
498 dc
.DrawLine( x
+20, y
+60, 100, y
+60 );
500 dc
.DrawText(wxT("Misc hatches"), x
+ 150, y
+ 70);
501 dc
.SetPen( wxPen( wxT("black"), width
, wxBDIAGONAL_HATCH
) );
502 dc
.DrawLine( x
+20, y
+70, 100, y
+70 );
503 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSSDIAG_HATCH
) );
504 dc
.DrawLine( x
+20, y
+80, 100, y
+80 );
505 dc
.SetPen( wxPen( wxT("black"), width
, wxFDIAGONAL_HATCH
) );
506 dc
.DrawLine( x
+20, y
+90, 100, y
+90 );
507 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSS_HATCH
) );
508 dc
.DrawLine( x
+20, y
+100, 100, y
+100 );
509 dc
.SetPen( wxPen( wxT("black"), width
, wxHORIZONTAL_HATCH
) );
510 dc
.DrawLine( x
+20, y
+110, 100, y
+110 );
511 dc
.SetPen( wxPen( wxT("black"), width
, wxVERTICAL_HATCH
) );
512 dc
.DrawLine( x
+20, y
+120, 100, y
+120 );
514 dc
.DrawText(wxT("User dash"), x
+ 150, y
+ 140);
515 wxPen
ud( wxT("black"), width
, wxUSER_DASH
);
517 dash1
[0] = 8; // Long dash <---------+
518 dash1
[1] = 2; // Short gap |
519 dash1
[2] = 3; // Short dash |
520 dash1
[3] = 2; // Short gap |
521 dash1
[4] = 3; // Short dash |
522 dash1
[5] = 2; // Short gap and repeat +
523 ud
.SetDashes( 6, dash1
);
525 dc
.DrawLine( x
+20, y
+140, 100, y
+140 );
526 dash1
[0] = 5; // Make first dash shorter
527 ud
.SetDashes( 6, dash1
);
529 dc
.DrawLine( x
+20, y
+150, 100, y
+150 );
530 dash1
[2] = 5; // Make second dash longer
531 ud
.SetDashes( 6, dash1
);
533 dc
.DrawLine( x
+20, y
+160, 100, y
+160 );
534 dash1
[4] = 5; // Make third dash longer
535 ud
.SetDashes( 6, dash1
);
537 dc
.DrawLine( x
+20, y
+170, 100, y
+170 );
540 void MyCanvas::DrawDefault(wxDC
& dc
)
543 dc
.DrawCircle(0, 0, 10);
545 #if !defined(wxMAC_USE_CORE_GRAPHICS) || !wxMAC_USE_CORE_GRAPHICS
546 // GetPixel and FloodFill not supported by Mac OS X CoreGraphics
547 // (FloodFill uses Blit from a non-wxMemoryDC)
548 //flood fill using brush, starting at 1,1 and replacing whatever colour we find there
549 dc
.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID
));
552 dc
.GetPixel(1,1, &tmpColour
);
553 dc
.FloodFill(1,1, tmpColour
, wxFLOOD_SURFACE
);
556 dc
.DrawCheckMark(5, 80, 15, 15);
557 dc
.DrawCheckMark(25, 80, 30, 30);
558 dc
.DrawCheckMark(60, 80, 60, 60);
560 // this is the test for "blitting bitmap into DC damages selected brush" bug
561 wxCoord rectSize
= m_std_icon
.GetWidth() + 10;
563 dc
.SetPen(*wxTRANSPARENT_PEN
);
564 dc
.SetBrush( *wxGREEN_BRUSH
);
565 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
566 dc
.DrawBitmap(m_std_icon
, x
+ 5, 15, true);
568 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
569 dc
.DrawIcon(m_std_icon
, x
+ 5, 15);
571 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
573 // test for "transparent" bitmap drawing (it intersects with the last
575 //dc.SetBrush( *wxTRANSPARENT_BRUSH );
577 if (m_smile_bmp
.Ok())
578 dc
.DrawBitmap(m_smile_bmp
, x
+ rectSize
- 20, rectSize
- 10, true);
580 dc
.SetBrush( *wxBLACK_BRUSH
);
581 dc
.DrawRectangle( 0, 160, 1000, 300 );
584 wxBitmap
bitmap(20,70);
586 memdc
.SelectObject( bitmap
);
587 memdc
.SetBrush( *wxBLACK_BRUSH
);
588 memdc
.SetPen( *wxWHITE_PEN
);
589 memdc
.DrawRectangle(0,0,20,70);
590 memdc
.DrawLine( 10,0,10,70 );
593 wxPen pen
= *wxRED_PEN
;
595 memdc
.DrawLine( 10, 5,10, 5 );
596 memdc
.DrawLine( 10,10,11,10 );
597 memdc
.DrawLine( 10,15,12,15 );
598 memdc
.DrawLine( 10,20,13,20 );
601 memdc.SetPen(*wxRED_PEN);
602 memdc.DrawLine( 12, 5,12, 5 );
603 memdc.DrawLine( 12,10,13,10 );
604 memdc.DrawLine( 12,15,14,15 );
605 memdc.DrawLine( 12,20,15,20 );
609 memdc
.DrawLine( 10,25,10,25 );
610 memdc
.DrawLine( 10,30, 9,30 );
611 memdc
.DrawLine( 10,35, 8,35 );
612 memdc
.DrawLine( 10,40, 7,40 );
615 dc
.SetPen(*wxWHITE_PEN
);
616 memdc
.SetLogicalFunction( wxINVERT
);
617 memdc
.SetPen( *wxWHITE_PEN
);
618 memdc
.DrawLine( 10,50,10,50 );
619 memdc
.DrawLine( 10,55,11,55 );
620 memdc
.DrawLine( 10,60,12,60 );
621 memdc
.DrawLine( 10,65,13,65 );
623 memdc
.DrawLine( 12,50,12,50 );
624 memdc
.DrawLine( 12,55,13,55 );
625 memdc
.DrawLine( 12,60,14,60 );
626 memdc
.DrawLine( 12,65,15,65 );
628 memdc
.SelectObject( wxNullBitmap
);
629 dc
.DrawBitmap( bitmap
, 10, 170 );
630 wxImage image
= bitmap
.ConvertToImage();
631 image
.Rescale( 60,210 );
632 bitmap
= wxBitmap(image
);
633 dc
.DrawBitmap( bitmap
, 50, 170 );
635 // test the rectangle outline drawing - there should be one pixel between
636 // the rect and the lines
637 dc
.SetPen(*wxWHITE_PEN
);
638 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
639 dc
.DrawRectangle(150, 170, 49, 29);
640 dc
.DrawRectangle(200, 170, 49, 29);
641 dc
.SetPen(*wxWHITE_PEN
);
642 dc
.DrawLine(250, 210, 250, 170);
643 dc
.DrawLine(260, 200, 150, 200);
645 // test the rectangle filled drawing - there should be one pixel between
646 // the rect and the lines
647 dc
.SetPen(*wxTRANSPARENT_PEN
);
648 dc
.SetBrush( *wxWHITE_BRUSH
);
649 dc
.DrawRectangle(300, 170, 49, 29);
650 dc
.DrawRectangle(350, 170, 49, 29);
651 dc
.SetPen(*wxWHITE_PEN
);
652 dc
.DrawLine(400, 170, 400, 210);
653 dc
.DrawLine(300, 200, 410, 200);
655 // a few more tests of this kind
656 dc
.SetPen(*wxRED_PEN
);
657 dc
.SetBrush( *wxWHITE_BRUSH
);
658 dc
.DrawRectangle(300, 220, 1, 1);
659 dc
.DrawRectangle(310, 220, 2, 2);
660 dc
.DrawRectangle(320, 220, 3, 3);
661 dc
.DrawRectangle(330, 220, 4, 4);
663 dc
.SetPen(*wxTRANSPARENT_PEN
);
664 dc
.SetBrush( *wxWHITE_BRUSH
);
665 dc
.DrawRectangle(300, 230, 1, 1);
666 dc
.DrawRectangle(310, 230, 2, 2);
667 dc
.DrawRectangle(320, 230, 3, 3);
668 dc
.DrawRectangle(330, 230, 4, 4);
670 // and now for filled rect with outline
671 dc
.SetPen(*wxRED_PEN
);
672 dc
.SetBrush( *wxWHITE_BRUSH
);
673 dc
.DrawRectangle(500, 170, 49, 29);
674 dc
.DrawRectangle(550, 170, 49, 29);
675 dc
.SetPen(*wxWHITE_PEN
);
676 dc
.DrawLine(600, 170, 600, 210);
677 dc
.DrawLine(500, 200, 610, 200);
679 // test the rectangle outline drawing - there should be one pixel between
680 // the rect and the lines
681 dc
.SetPen(*wxWHITE_PEN
);
682 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
683 dc
.DrawRoundedRectangle(150, 270, 49, 29, 6);
684 dc
.DrawRoundedRectangle(200, 270, 49, 29, 6);
685 dc
.SetPen(*wxWHITE_PEN
);
686 dc
.DrawLine(250, 270, 250, 310);
687 dc
.DrawLine(150, 300, 260, 300);
689 // test the rectangle filled drawing - there should be one pixel between
690 // the rect and the lines
691 dc
.SetPen(*wxTRANSPARENT_PEN
);
692 dc
.SetBrush( *wxWHITE_BRUSH
);
693 dc
.DrawRoundedRectangle(300, 270, 49, 29, 6);
694 dc
.DrawRoundedRectangle(350, 270, 49, 29, 6);
695 dc
.SetPen(*wxWHITE_PEN
);
696 dc
.DrawLine(400, 270, 400, 310);
697 dc
.DrawLine(300, 300, 410, 300);
699 // Added by JACS to demonstrate bizarre behaviour.
700 // With a size of 70, we get a missing red RHS,
701 // and the height is too small, so we get yellow
702 // showing. With a size of 40, it draws as expected:
703 // it just shows a white rectangle with red outline.
705 int totalHeight
= 70;
706 wxBitmap
bitmap2(totalWidth
, totalHeight
);
709 memdc2
.SelectObject(bitmap2
);
711 wxColour
clr(255, 255, 0);
712 wxBrush
yellowBrush(clr
, wxSOLID
);
713 memdc2
.SetBackground(yellowBrush
);
716 wxPen
yellowPen(clr
, 1, wxSOLID
);
718 // Now draw a white rectangle with red outline. It should
719 // entirely eclipse the yellow background.
720 memdc2
.SetPen(*wxRED_PEN
);
721 memdc2
.SetBrush(*wxWHITE_BRUSH
);
723 memdc2
.DrawRectangle(0, 0, totalWidth
, totalHeight
);
725 memdc2
.SetPen(wxNullPen
);
726 memdc2
.SetBrush(wxNullBrush
);
727 memdc2
.SelectObject(wxNullBitmap
);
729 dc
.DrawBitmap(bitmap2
, 500, 270);
731 // Repeat, but draw directly on dc
732 // Draw a yellow rectangle filling the bitmap
734 x
= 600; int y
= 270;
735 dc
.SetPen(yellowPen
);
736 dc
.SetBrush(yellowBrush
);
737 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
739 // Now draw a white rectangle with red outline. It should
740 // entirely eclipse the yellow background.
741 dc
.SetPen(*wxRED_PEN
);
742 dc
.SetBrush(*wxWHITE_BRUSH
);
744 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
747 void MyCanvas::DrawText(wxDC
& dc
)
749 // set underlined font for testing
750 dc
.SetFont( wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, true) );
751 dc
.DrawText( wxT("This is text"), 110, 10 );
752 dc
.DrawRotatedText( wxT("That is text"), 20, 10, -45 );
754 // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
755 // under Win9x (it is not TrueType)
756 dc
.SetFont( *wxSWISS_FONT
);
759 dc
.SetBackgroundMode(wxTRANSPARENT
);
761 for ( int n
= -180; n
< 180; n
+= 30 )
763 text
.Printf(wxT(" %d rotated text"), n
);
764 dc
.DrawRotatedText(text
, 400, 400, n
);
767 dc
.SetFont( wxFont( 18, wxSWISS
, wxNORMAL
, wxNORMAL
) );
769 dc
.DrawText( wxT("This is Swiss 18pt text."), 110, 40 );
774 dc
.GetTextExtent( wxT("This is Swiss 18pt text."), &length
, &height
, &descent
);
775 text
.Printf( wxT("Dimensions are length %ld, height %ld, descent %ld"), length
, height
, descent
);
776 dc
.DrawText( text
, 110, 80 );
778 text
.Printf( wxT("CharHeight() returns: %d"), dc
.GetCharHeight() );
779 dc
.DrawText( text
, 110, 120 );
781 dc
.DrawRectangle( 100, 40, 4, height
);
783 // test the logical function effect
785 dc
.SetLogicalFunction(wxINVERT
);
786 // text drawing should ignore logical function
787 dc
.DrawText( wxT("There should be a text below"), 110, 150 );
788 dc
.DrawRectangle( 110, y
, 100, height
);
791 dc
.DrawText( wxT("Visible text"), 110, y
);
792 dc
.DrawRectangle( 110, y
, 100, height
);
793 dc
.DrawText( wxT("Visible text"), 110, y
);
794 dc
.DrawRectangle( 110, y
, 100, height
);
795 dc
.SetLogicalFunction(wxCOPY
);
798 dc
.DrawRectangle( 110, y
, 100, height
);
799 dc
.DrawText( wxT("Another visible text"), 110, y
);
805 wxRasterOperationMode rop
;
806 } rasterOperations
[] =
808 { wxT("wxAND"), wxAND
},
809 { wxT("wxAND_INVERT"), wxAND_INVERT
},
810 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
811 { wxT("wxCLEAR"), wxCLEAR
},
812 { wxT("wxCOPY"), wxCOPY
},
813 { wxT("wxEQUIV"), wxEQUIV
},
814 { wxT("wxINVERT"), wxINVERT
},
815 { wxT("wxNAND"), wxNAND
},
816 { wxT("wxNO_OP"), wxNO_OP
},
817 { wxT("wxOR"), wxOR
},
818 { wxT("wxOR_INVERT"), wxOR_INVERT
},
819 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
820 { wxT("wxSET"), wxSET
},
821 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
822 { wxT("wxXOR"), wxXOR
},
825 void MyCanvas::DrawImages(wxDC
& dc
, DrawMode mode
)
827 dc
.DrawText(wxT("original image"), 0, 0);
828 dc
.DrawBitmap(*gs_bmpNoMask
, 0, 20, 0);
829 dc
.DrawText(wxT("with colour mask"), 0, 100);
830 dc
.DrawBitmap(*gs_bmpWithColMask
, 0, 120, true);
831 dc
.DrawText(wxT("the mask image"), 0, 200);
832 dc
.DrawBitmap(*gs_bmpMask
, 0, 220, 0);
833 dc
.DrawText(wxT("masked image"), 0, 300);
834 dc
.DrawBitmap(*gs_bmpWithMask
, 0, 320, true);
836 int cx
= gs_bmpWithColMask
->GetWidth(),
837 cy
= gs_bmpWithColMask
->GetHeight();
840 for ( size_t n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
842 wxCoord x
= 120 + 150*(n%4
),
845 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
846 memDC
.SelectObject(*gs_bmpWithColMask
);
847 if ( mode
== Draw_Stretch
)
849 dc
.StretchBlit(x
, y
, cx
, cy
, &memDC
, 0, 0, cx
/2, cy
/2,
850 rasterOperations
[n
].rop
, true);
854 dc
.Blit(x
, y
, cx
, cy
, &memDC
, 0, 0, rasterOperations
[n
].rop
, true);
859 void MyCanvas::DrawWithLogicalOps(wxDC
& dc
)
861 static const wxCoord w
= 60;
862 static const wxCoord h
= 60;
864 // reuse the text colour here
865 dc
.SetPen(wxPen(m_owner
->m_colourForeground
, 1, wxSOLID
));
866 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
869 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
871 wxCoord x
= 20 + 150*(n%4
),
874 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
875 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
876 dc
.DrawRectangle(x
, y
, w
, h
);
877 dc
.DrawLine(x
, y
, x
+ w
, y
+ h
);
878 dc
.DrawLine(x
+ w
, y
, x
, y
+ h
);
881 // now some filled rectangles
882 dc
.SetBrush(wxBrush(m_owner
->m_colourForeground
, wxSOLID
));
884 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
886 wxCoord x
= 20 + 150*(n%4
),
889 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
890 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
891 dc
.DrawRectangle(x
, y
, w
, h
);
895 #if wxUSE_GRAPHICS_CONTEXT
897 void MyCanvas::DrawAlpha(wxDC
& WXUNUSED(dummyDC
))
899 void MyCanvas::DrawAlpha(wxDC
& dc
)
907 wxDouble margin
= 20 ;
908 wxDouble width
= 180 ;
909 wxDouble radius
= 30 ;
911 dc
.SetPen( wxPen( wxColour( 128, 0, 0, 255 ),12, wxSOLID
));
912 dc
.SetBrush( wxBrush( wxColour( 255, 0, 0, 255),wxSOLID
));
914 wxRect
r(margin
,margin
+width
*0.66,width
,width
) ;
916 dc
.DrawRoundedRectangle( r
.x
, r
.y
, r
.width
, r
.width
, radius
) ;
918 dc
.SetPen( wxPen( wxColour( 0, 0, 128, 255 ),12, wxSOLID
));
919 dc
.SetBrush( wxBrush( wxColour( 0, 0, 255, 255),wxSOLID
));
921 r
.Offset( width
* 0.8 , - width
* 0.66 ) ;
923 dc
.DrawRoundedRectangle( r
.x
, r
.y
, r
.width
, r
.width
, radius
) ;
925 dc
.SetPen( wxPen( wxColour( 128, 128, 0, 255 ),12, wxSOLID
));
926 dc
.SetBrush( wxBrush( wxColour( 192, 192, 0, 255),wxSOLID
));
928 r
.Offset( width
* 0.8 , width
*0.5 ) ;
930 dc
.DrawRoundedRectangle( r
.x
, r
.y
, r
.width
, r
.width
, radius
) ;
932 dc
.SetPen( *wxTRANSPARENT_PEN
) ;
933 dc
.SetBrush( wxBrush( wxColour(255,255,128,128) ) );
934 dc
.DrawRoundedRectangle( 0 , margin
+ width
/ 2 , width
* 3 , 100 , radius
) ;
936 dc
.SetTextForeground( wxColour(255,255,0,128) );
937 dc
.SetFont( wxFont( 40, wxFONTFAMILY_SWISS
, wxFONTSTYLE_ITALIC
, wxFONTWEIGHT_NORMAL
) );
938 dc
.DrawText( wxT("Hello!"), 120, 80 );
943 #if wxUSE_GRAPHICS_CONTEXT
945 const int BASE
= 80.0;
946 const int BASE2
= BASE
/2;
947 const int BASE4
= BASE
/4;
949 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
952 // modeled along Robin Dunn's GraphicsContext.py sample
954 void MyCanvas::DrawGraphics(wxGraphicsContext
* gc
)
956 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
957 gc
->SetFont(font
,*wxBLACK
);
959 // make a path that contains a circle and some lines, centered at 0,0
960 wxGraphicsPath path
= gc
->CreatePath() ;
961 path
.AddCircle( 0, 0, BASE2
);
962 path
.MoveToPoint(0, -BASE2
);
963 path
.AddLineToPoint(0, BASE2
);
964 path
.MoveToPoint(-BASE2
, 0);
965 path
.AddLineToPoint(BASE2
, 0);
967 path
.AddRectangle(-BASE4
, -BASE4
/2, BASE2
, BASE4
);
969 // Now use that path to demonstrate various capbilites of the grpahics context
970 gc
->PushState(); // save current translation/scale/other state
971 gc
->Translate(60, 75); // reposition the context origin
973 gc
->SetPen(wxPen("navy", 1));
974 gc
->SetBrush(wxBrush("pink"));
976 for( int i
= 0 ; i
< 3 ; ++i
)
982 label
= "StrokePath";
992 gc
->GetTextExtent(label
, &w
, &h
, NULL
, NULL
);
993 gc
->DrawText(label
, -w
/2, -BASE2
-h
-4);
997 gc
->StrokePath(path
);
1006 gc
->Translate(2*BASE
, 0);
1009 gc
->PopState(); // restore saved state
1010 gc
->PushState(); // save it again
1011 gc
->Translate(60, 200); // offset to the lower part of the window
1013 gc
->DrawText("Scale", 0, -BASE2
);
1014 gc
->Translate(0, 20);
1016 gc
->SetBrush(wxBrush(wxColour(178, 34, 34, 128)));// 128 == half transparent
1017 for( int i
= 0 ; i
< 8 ; ++i
)
1019 gc
->Scale(1.08, 1.08); // increase scale by 8%
1024 gc
->PopState(); // restore saved state
1025 gc
->PushState(); // save it again
1026 gc
->Translate(400, 200);
1028 gc
->DrawText("Rotate", 0, -BASE2
);
1030 // Move the origin over to the next location
1031 gc
->Translate(0, 75);
1033 // draw our path again, rotating it about the central point,
1034 // and changing colors as we go
1035 for ( int angle
= 0 ; angle
< 360 ; angle
+= 30 )
1037 gc
->PushState(); // save this new current state so we can
1038 // pop back to it at the end of the loop
1039 wxImage::RGBValue val
= wxImage::HSVtoRGB(wxImage::HSVValue(float(angle
)/360, 1, 1));
1040 gc
->SetBrush(wxBrush(wxColour(val
.red
, val
.green
, val
.blue
, 64)));
1041 gc
->SetPen(wxPen(wxColour(val
.red
, val
.green
, val
.blue
, 128)));
1043 // use translate to artfully reposition each drawn path
1044 gc
->Translate(1.5 * BASE2
* cos(DegToRad(angle
)),
1045 1.5 * BASE2
* sin(DegToRad(angle
)));
1047 // use Rotate to rotate the path
1048 gc
->Rotate(DegToRad(angle
));
1057 gc
->Translate(60, 400);
1058 gc
->DrawText("Scaled smiley inside a square", 0, 0);
1059 gc
->DrawRectangle(BASE2
, BASE2
, 100, 100);
1060 gc
->DrawBitmap(m_smile_bmp
, BASE2
, BASE2
, 100, 100);
1063 #endif // wxUSE_GRAPHICS_CONTEXT
1065 void MyCanvas::DrawCircles(wxDC
& dc
)
1071 dc
.SetPen( *wxRED_PEN
);
1072 dc
.SetBrush( *wxGREEN_BRUSH
);
1074 dc
.DrawText(wxT("Some circles"), 0, y
);
1075 dc
.DrawCircle(x
, y
, r
);
1076 dc
.DrawCircle(x
+ 2*r
, y
, r
);
1077 dc
.DrawCircle(x
+ 4*r
, y
, r
);
1080 dc
.DrawText(wxT("And ellipses"), 0, y
);
1081 dc
.DrawEllipse(x
- r
, y
, 2*r
, r
);
1082 dc
.DrawEllipse(x
+ r
, y
, 2*r
, r
);
1083 dc
.DrawEllipse(x
+ 3*r
, y
, 2*r
, r
);
1086 dc
.DrawText(wxT("And arcs"), 0, y
);
1087 dc
.DrawArc(x
- r
, y
, x
+ r
, y
, x
, y
);
1088 dc
.DrawArc(x
+ 4*r
, y
, x
+ 2*r
, y
, x
+ 3*r
, y
);
1089 dc
.DrawArc(x
+ 5*r
, y
, x
+ 5*r
, y
, x
+ 6*r
, y
);
1092 dc
.DrawEllipticArc(x
- r
, y
, 2*r
, r
, 0, 90);
1093 dc
.DrawEllipticArc(x
+ r
, y
, 2*r
, r
, 90, 180);
1094 dc
.DrawEllipticArc(x
+ 3*r
, y
, 2*r
, r
, 180, 270);
1095 dc
.DrawEllipticArc(x
+ 5*r
, y
, 2*r
, r
, 270, 360);
1097 // same as above, just transparent brush
1099 dc
.SetPen( *wxRED_PEN
);
1100 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1103 dc
.DrawText(wxT("Some circles"), 0, y
);
1104 dc
.DrawCircle(x
, y
, r
);
1105 dc
.DrawCircle(x
+ 2*r
, y
, r
);
1106 dc
.DrawCircle(x
+ 4*r
, y
, r
);
1109 dc
.DrawText(wxT("And ellipses"), 0, y
);
1110 dc
.DrawEllipse(x
- r
, y
, 2*r
, r
);
1111 dc
.DrawEllipse(x
+ r
, y
, 2*r
, r
);
1112 dc
.DrawEllipse(x
+ 3*r
, y
, 2*r
, r
);
1115 dc
.DrawText(wxT("And arcs"), 0, y
);
1116 dc
.DrawArc(x
- r
, y
, x
+ r
, y
, x
, y
);
1117 dc
.DrawArc(x
+ 4*r
, y
, x
+ 2*r
, y
, x
+ 3*r
, y
);
1118 dc
.DrawArc(x
+ 5*r
, y
, x
+ 5*r
, y
, x
+ 6*r
, y
);
1121 dc
.DrawEllipticArc(x
- r
, y
, 2*r
, r
, 0, 90);
1122 dc
.DrawEllipticArc(x
+ r
, y
, 2*r
, r
, 90, 180);
1123 dc
.DrawEllipticArc(x
+ 3*r
, y
, 2*r
, r
, 180, 270);
1124 dc
.DrawEllipticArc(x
+ 5*r
, y
, 2*r
, r
, 270, 360);
1128 void MyCanvas::DrawSplines(wxDC
& dc
)
1131 dc
.DrawText(wxT("Some splines"), 10, 5);
1133 // values are hardcoded rather than randomly generated
1134 // so the output can be compared between native
1135 // implementations on platforms with different random
1139 const wxPoint
center( R
+ 20, R
+ 20 );
1140 const int angles
[7] = { 0, 10, 33, 77, 13, 145, 90 };
1141 const int radii
[5] = { 100 , 59, 85, 33, 90 };
1145 // background spline calculation
1146 unsigned int radius_pos
= 0;
1147 unsigned int angle_pos
= 0;
1149 for ( int i
= 0; i
< n
; i
++ )
1151 angle
+= angles
[ angle_pos
];
1152 int r
= R
* radii
[ radius_pos
] / 100;
1153 pts
[ i
].x
= center
.x
+ (wxCoord
)( r
* cos( M_PI
* angle
/ 180.0) );
1154 pts
[ i
].y
= center
.y
+ (wxCoord
)( r
* sin( M_PI
* angle
/ 180.0) );
1157 if ( angle_pos
>= WXSIZEOF(angles
) ) angle_pos
= 0;
1160 if ( radius_pos
>= WXSIZEOF(radii
) ) radius_pos
= 0;
1163 // background spline drawing
1164 dc
.SetPen(*wxRED_PEN
);
1165 dc
.DrawSpline(WXSIZEOF(pts
), pts
);
1167 // less detailed spline calculation
1168 wxPoint letters
[4][5];
1170 letters
[0][0] = wxPoint( 0,1); // O O
1171 letters
[0][1] = wxPoint( 1,3); // * *
1172 letters
[0][2] = wxPoint( 2,2); // * O *
1173 letters
[0][3] = wxPoint( 3,3); // * * * *
1174 letters
[0][4] = wxPoint( 4,1); // O O
1176 letters
[1][0] = wxPoint( 5,1); // O*O
1177 letters
[1][1] = wxPoint( 6,1); // *
1178 letters
[1][2] = wxPoint( 7,2); // O
1179 letters
[1][3] = wxPoint( 8,3); // *
1180 letters
[1][4] = wxPoint( 9,3); // O*O
1182 letters
[2][0] = wxPoint( 5,3); // O*O
1183 letters
[2][1] = wxPoint( 6,3); // *
1184 letters
[2][2] = wxPoint( 7,2); // O
1185 letters
[2][3] = wxPoint( 8,1); // *
1186 letters
[2][4] = wxPoint( 9,1); // O*O
1188 letters
[3][0] = wxPoint(10,0); // O O
1189 letters
[3][1] = wxPoint(11,3); // * *
1190 letters
[3][2] = wxPoint(12,1); // * O *
1191 letters
[3][3] = wxPoint(13,3); // * * * *
1192 letters
[3][4] = wxPoint(14,0); // O O
1194 const int dx
= 2 * R
/ letters
[3][4].x
;
1195 const int h
[4] = { -R
/2, 0, R
/4, R
/2 };
1197 for ( int m
= 0; m
< 4; m
++ )
1199 for ( int n
= 0; n
< 5; n
++ )
1201 letters
[m
][n
].x
= center
.x
- R
+ letters
[m
][n
].x
* dx
;
1202 letters
[m
][n
].y
= center
.y
+ h
[ letters
[m
][n
].y
];
1205 dc
.SetPen( wxPen( wxT("blue"), 1, wxDOT
) );
1206 dc
.DrawLines(5, letters
[m
]);
1207 dc
.SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
1208 dc
.DrawSpline(5, letters
[m
]);
1212 dc
.DrawText(wxT("Splines not supported."), 10, 5);
1216 void MyCanvas::DrawGradients(wxDC
& dc
)
1218 static const int TEXT_HEIGHT
= 15;
1221 wxRect
r(10, 10, 50, 50);
1222 dc
.DrawText(wxT("wxRIGHT"), r
.x
, r
.y
);
1223 r
.Offset(0, TEXT_HEIGHT
);
1224 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxRIGHT
);
1226 r
.Offset(0, r
.height
+ 10);
1227 dc
.DrawText(wxT("wxLEFT"), r
.x
, r
.y
);
1228 r
.Offset(0, TEXT_HEIGHT
);
1229 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxLEFT
);
1231 r
.Offset(0, r
.height
+ 10);
1232 dc
.DrawText(wxT("wxDOWN"), r
.x
, r
.y
);
1233 r
.Offset(0, TEXT_HEIGHT
);
1234 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxDOWN
);
1236 r
.Offset(0, r
.height
+ 10);
1237 dc
.DrawText(wxT("wxUP"), r
.x
, r
.y
);
1238 r
.Offset(0, TEXT_HEIGHT
);
1239 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxUP
);
1241 wxRect gfr
= wxRect(r
);
1244 r
= wxRect(200, 10, 50, 50);
1245 dc
.DrawText(wxT("Blue inside"), r
.x
, r
.y
);
1246 r
.Offset(0, TEXT_HEIGHT
);
1247 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
);
1249 r
.Offset(0, r
.height
+ 10);
1250 dc
.DrawText(wxT("White inside"), r
.x
, r
.y
);
1251 r
.Offset(0, TEXT_HEIGHT
);
1252 dc
.GradientFillConcentric(r
, *wxWHITE
, *wxBLUE
);
1254 r
.Offset(0, r
.height
+ 10);
1255 dc
.DrawText(wxT("Blue in top left corner"), r
.x
, r
.y
);
1256 r
.Offset(0, TEXT_HEIGHT
);
1257 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
, wxPoint(0, 0));
1259 r
.Offset(0, r
.height
+ 10);
1260 dc
.DrawText(wxT("Blue in bottom right corner"), r
.x
, r
.y
);
1261 r
.Offset(0, TEXT_HEIGHT
);
1262 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
, wxPoint(r
.width
, r
.height
));
1264 // check that the area filled by the gradient is exactly the interior of
1268 dc
.DrawText("The interior should be filled but", r
.x
, r
.y
);
1270 dc
.DrawText(" the red border should remain visible:", r
.x
, r
.y
);
1281 dc
.SetPen(wxPen(wxColour(255, 0, 0)));
1282 dc
.DrawRectangle(r
);
1284 dc
.GradientFillLinear(r
, wxColour(0,255,0), wxColour(0,0,0), wxNORTH
);
1285 dc
.DrawRectangle(r2
);
1287 dc
.GradientFillLinear(r2
, wxColour(0,0,0), wxColour(0,255,0), wxSOUTH
);
1288 dc
.DrawRectangle(r3
);
1290 dc
.GradientFillLinear(r3
, wxColour(0,255,0), wxColour(0,0,0), wxEAST
);
1291 dc
.DrawRectangle(r4
);
1293 dc
.GradientFillLinear(r4
, wxColour(0,0,0), wxColour(0,255,0), wxWEST
);
1295 #if wxUSE_GRAPHICS_CONTEXT
1298 wxGCDC
&gdc
= (wxGCDC
&)dc
;
1299 wxGraphicsContext
*gc
= gdc
.GetGraphicsContext();
1301 wxGraphicsGradientStops stops
;
1303 gfr
.Offset(0, gfr
.height
+ 10);
1304 dc
.DrawText(wxT("Linear Gradient with Stops"), gfr
.x
, gfr
.y
);
1305 gfr
.Offset(0, TEXT_HEIGHT
);
1307 stops
= wxGraphicsGradientStops(wxColour(255,0,0), wxColour(0,0,255));
1308 stops
.Add(wxColour(255,255,0), 0.33f
);
1309 stops
.Add(wxColour(0,255,0), 0.67f
);
1311 gc
->SetBrush(gc
->CreateLinearGradientBrush(gfr
.x
, gfr
.y
,
1312 gfr
.x
+ gfr
.width
, gfr
.y
+ gfr
.height
,
1314 pth
= gc
->CreatePath();
1315 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1316 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1317 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1318 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1322 gfr
.Offset(0, gfr
.height
+ 10);
1323 dc
.DrawText(wxT("Radial Gradient with Stops"), gfr
.x
, gfr
.y
);
1324 gfr
.Offset(0, TEXT_HEIGHT
);
1326 gc
->SetBrush(gc
->CreateRadialGradientBrush(gfr
.x
+ gfr
.width
/ 2,
1327 gfr
.y
+ gfr
.height
/ 2,
1328 gfr
.x
+ gfr
.width
/ 2,
1329 gfr
.y
+ gfr
.height
/ 2,
1332 pth
= gc
->CreatePath();
1333 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1334 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1335 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1336 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1340 gfr
.Offset(0, gfr
.height
+ 10);
1341 dc
.DrawText(wxT("Linear Gradient with Stops and Gaps"), gfr
.x
, gfr
.y
);
1342 gfr
.Offset(0, TEXT_HEIGHT
);
1344 stops
= wxGraphicsGradientStops(wxColour(255,0,0), wxColour(0,0,255));
1345 stops
.Add(wxColour(255,255,0), 0.33f
);
1346 stops
.Add(wxTransparentColour
, 0.33f
);
1347 stops
.Add(wxTransparentColour
, 0.67f
);
1348 stops
.Add(wxColour(0,255,0), 0.67f
);
1350 gc
->SetBrush(gc
->CreateLinearGradientBrush(gfr
.x
, gfr
.y
+ gfr
.height
,
1351 gfr
.x
+ gfr
.width
, gfr
.y
,
1353 pth
= gc
->CreatePath();
1354 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1355 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1356 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1357 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1361 gfr
.Offset(0, gfr
.height
+ 10);
1362 dc
.DrawText(wxT("Radial Gradient with Stops and Gaps"), gfr
.x
, gfr
.y
);
1363 gfr
.Offset(0, TEXT_HEIGHT
);
1365 gc
->SetBrush(gc
->CreateRadialGradientBrush(gfr
.x
+ gfr
.width
/ 2,
1366 gfr
.y
+ gfr
.height
/ 2,
1367 gfr
.x
+ gfr
.width
/ 2,
1368 gfr
.y
+ gfr
.height
/ 2,
1371 pth
= gc
->CreatePath();
1372 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1373 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1374 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1375 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1379 gfr
.Offset(0, gfr
.height
+ 10);
1380 dc
.DrawText(wxT("Gradients with Stops and Transparency"), gfr
.x
, gfr
.y
);
1381 gfr
.Offset(0, TEXT_HEIGHT
);
1383 stops
= wxGraphicsGradientStops(wxColour(255,0,0), wxTransparentColour
);
1384 stops
.Add(wxColour(255,0,0), 0.33f
);
1385 stops
.Add(wxTransparentColour
, 0.33f
);
1386 stops
.Add(wxTransparentColour
, 0.67f
);
1387 stops
.Add(wxColour(0,0,255), 0.67f
);
1388 stops
.Add(wxColour(0,0,255), 1.0f
);
1390 pth
= gc
->CreatePath();
1391 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1392 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1393 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1394 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1397 gc
->SetBrush(gc
->CreateRadialGradientBrush(gfr
.x
+ gfr
.width
/ 2,
1398 gfr
.y
+ gfr
.height
/ 2,
1399 gfr
.x
+ gfr
.width
/ 2,
1400 gfr
.y
+ gfr
.height
/ 2,
1405 stops
= wxGraphicsGradientStops(wxColour(255,0,0, 128), wxColour(0,0,255, 128));
1406 stops
.Add(wxColour(255,255,0,128), 0.33f
);
1407 stops
.Add(wxColour(0,255,0,128), 0.67f
);
1409 gc
->SetBrush(gc
->CreateLinearGradientBrush(gfr
.x
, gfr
.y
,
1410 gfr
.x
+ gfr
.width
, gfr
.y
,
1414 #endif // wxUSE_GRAPHICS_CONTEXT
1417 void MyCanvas::DrawRegions(wxDC
& dc
)
1419 dc
.DrawText(wxT("You should see a red rect partly covered by a cyan one ")
1420 wxT("on the left"), 10, 5);
1421 dc
.DrawText(wxT("and 5 smileys from which 4 are partially clipped on the right"),
1422 10, 5 + dc
.GetCharHeight());
1423 dc
.DrawText(wxT("The second copy should be identical but right part of it ")
1424 wxT("should be offset by 10 pixels."),
1425 10, 5 + 2*dc
.GetCharHeight());
1427 DrawRegionsHelper(dc
, 10, true);
1428 DrawRegionsHelper(dc
, 350, false);
1431 void MyCanvas::DrawRegionsHelper(wxDC
& dc
, wxCoord x
, bool firstTime
)
1435 dc
.DestroyClippingRegion();
1436 dc
.SetBrush( *wxWHITE_BRUSH
);
1437 dc
.SetPen( *wxTRANSPARENT_PEN
);
1438 dc
.DrawRectangle( x
, y
, 310, 310 );
1440 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 270 );
1442 dc
.SetBrush( *wxRED_BRUSH
);
1443 dc
.DrawRectangle( x
, y
, 310, 310 );
1445 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 100 );
1447 dc
.SetBrush( *wxCYAN_BRUSH
);
1448 dc
.DrawRectangle( x
, y
, 310, 310 );
1450 dc
.DestroyClippingRegion();
1452 wxRegion
region(x
+ 110, y
+ 20, 100, 270);
1453 #if !defined(__WXMOTIF__)
1455 region
.Offset(10, 10);
1457 dc
.SetDeviceClippingRegion(region
);
1459 dc
.SetBrush( *wxGREY_BRUSH
);
1460 dc
.DrawRectangle( x
, y
, 310, 310 );
1462 if (m_smile_bmp
.Ok())
1464 dc
.DrawBitmap( m_smile_bmp
, x
+ 150, y
+ 150, true );
1465 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 10, true );
1466 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 280, true );
1467 dc
.DrawBitmap( m_smile_bmp
, x
+ 100, y
+ 70, true );
1468 dc
.DrawBitmap( m_smile_bmp
, x
+ 200, y
+ 70, true );
1472 #if TEST_CAIRO_EVERYWHERE
1473 extern wxGraphicsRenderer
* gCairoRenderer
;
1476 void MyCanvas::OnPaint(wxPaintEvent
&WXUNUSED(event
))
1478 wxPaintDC
pdc(this);
1480 #if wxUSE_GRAPHICS_CONTEXT
1481 #if TEST_CAIRO_EVERYWHERE
1483 gdc
.SetGraphicsContext( gCairoRenderer
->CreateContext( pdc
) );
1487 wxDC
&dc
= m_useContext
? (wxDC
&) gdc
: (wxDC
&) pdc
;
1494 m_owner
->PrepareDC(dc
);
1496 dc
.SetBackgroundMode( m_owner
->m_backgroundMode
);
1497 if ( m_owner
->m_backgroundBrush
.Ok() )
1498 dc
.SetBackground( m_owner
->m_backgroundBrush
);
1499 if ( m_owner
->m_colourForeground
.Ok() )
1500 dc
.SetTextForeground( m_owner
->m_colourForeground
);
1501 if ( m_owner
->m_colourBackground
.Ok() )
1502 dc
.SetTextBackground( m_owner
->m_colourBackground
);
1504 if ( m_owner
->m_textureBackground
) {
1505 if ( ! m_owner
->m_backgroundBrush
.Ok() ) {
1506 wxColour
clr(0,128,0);
1507 wxBrush
b(clr
, wxSOLID
);
1508 dc
.SetBackground(b
);
1513 dc
.SetClippingRegion(100, 100, 100, 100);
1517 if ( m_owner
->m_textureBackground
)
1519 dc
.SetPen(*wxMEDIUM_GREY_PEN
);
1520 for ( int i
= 0; i
< 200; i
++ )
1521 dc
.DrawLine(0, i
*10, i
*10, 0);
1526 case File_ShowDefault
:
1530 case File_ShowCircles
:
1534 case File_ShowSplines
:
1538 case File_ShowRegions
:
1546 case File_ShowLines
:
1547 DrawTestLines( 0, 100, 0, dc
);
1548 DrawTestLines( 0, 320, 1, dc
);
1549 DrawTestLines( 0, 540, 2, dc
);
1550 DrawTestLines( 0, 760, 6, dc
);
1553 case File_ShowBrushes
:
1554 DrawTestBrushes(dc
);
1557 case File_ShowPolygons
:
1562 DrawImages(dc
, Draw_Normal
);
1565 case File_ShowMaskStretch
:
1566 DrawImages(dc
, Draw_Stretch
);
1570 DrawWithLogicalOps(dc
);
1573 #if wxUSE_GRAPHICS_CONTEXT
1574 case File_ShowAlpha
:
1577 case File_ShowGraphics
:
1578 DrawGraphics(gdc
.GetGraphicsContext());
1582 case File_ShowGradients
:
1591 void MyCanvas::OnMouseMove(wxMouseEvent
&event
)
1595 wxClientDC
dc(this);
1597 m_owner
->PrepareDC(dc
);
1599 wxPoint pos
= event
.GetPosition();
1600 long x
= dc
.DeviceToLogicalX( pos
.x
);
1601 long y
= dc
.DeviceToLogicalY( pos
.y
);
1603 str
.Printf( wxT("Current mouse position: %d,%d"), (int)x
, (int)y
);
1604 m_owner
->SetStatusText( str
);
1610 event
.GetPosition(&x
,&y
);
1611 CalcUnscrolledPosition( x
, y
, &xx
, &yy
);
1612 m_currentpoint
= wxPoint( xx
, yy
) ;
1613 wxRect
newrect ( m_anchorpoint
, m_currentpoint
) ;
1615 wxClientDC
dc( this ) ;
1618 wxDCOverlay
overlaydc( m_overlay
, &dc
);
1621 dc
.SetPen( *wxGREY_PEN
);
1622 dc
.SetBrush( wxColour( 192,192,192,64 ) );
1624 dc
.SetPen( wxPen( *wxLIGHT_GREY
, 2, wxSOLID
) );
1625 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1627 dc
.DrawRectangle( newrect
);
1631 #endif // wxUSE_STATUSBAR
1634 void MyCanvas::OnMouseDown(wxMouseEvent
&event
)
1637 event
.GetPosition(&x
,&y
);
1638 CalcUnscrolledPosition( x
, y
, &xx
, &yy
);
1639 m_anchorpoint
= wxPoint( xx
, yy
) ;
1640 m_currentpoint
= m_anchorpoint
;
1641 m_rubberBand
= true ;
1645 void MyCanvas::OnMouseUp(wxMouseEvent
&event
)
1651 wxClientDC
dc( this );
1653 wxDCOverlay
overlaydc( m_overlay
, &dc
);
1657 m_rubberBand
= false;
1660 event
.GetPosition(&x
,&y
);
1661 CalcUnscrolledPosition( x
, y
, &xx
, &yy
);
1664 str
.Printf( wxT("Rectangle selection from %d,%d to %d,%d"),
1665 m_anchorpoint
.x
, m_anchorpoint
.y
, (int)xx
, (int)yy
);
1666 wxMessageBox( str
, wxT("Rubber-Banding") );
1671 // ----------------------------------------------------------------------------
1673 // ----------------------------------------------------------------------------
1675 // the event tables connect the wxWidgets events with the functions (event
1676 // handlers) which process them. It can be also done at run-time, but for the
1677 // simple menu events like this the static method is much simpler.
1678 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1679 EVT_MENU (File_Quit
, MyFrame::OnQuit
)
1680 EVT_MENU (File_About
, MyFrame::OnAbout
)
1681 EVT_MENU (File_Clip
, MyFrame::OnClip
)
1682 #if wxUSE_GRAPHICS_CONTEXT
1683 EVT_MENU (File_GraphicContext
, MyFrame::OnGraphicContext
)
1686 EVT_MENU_RANGE(MenuShow_First
, MenuShow_Last
, MyFrame::OnShow
)
1688 EVT_MENU_RANGE(MenuOption_First
, MenuOption_Last
, MyFrame::OnOption
)
1691 // frame constructor
1692 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
1693 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
,
1694 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
1696 // set the frame icon
1697 SetIcon(wxICON(sample
));
1699 wxMenu
*menuFile
= new wxMenu
;
1700 menuFile
->Append(File_ShowDefault
, wxT("&Default screen\tF1"));
1701 menuFile
->Append(File_ShowText
, wxT("&Text screen\tF2"));
1702 menuFile
->Append(File_ShowLines
, wxT("&Lines screen\tF3"));
1703 menuFile
->Append(File_ShowBrushes
, wxT("&Brushes screen\tF4"));
1704 menuFile
->Append(File_ShowPolygons
, wxT("&Polygons screen\tF5"));
1705 menuFile
->Append(File_ShowMask
, wxT("&Mask screen\tF6"));
1706 menuFile
->Append(File_ShowMaskStretch
, wxT("1/&2 scaled mask\tShift-F6"));
1707 menuFile
->Append(File_ShowOps
, wxT("&Raster operations screen\tF7"));
1708 menuFile
->Append(File_ShowRegions
, wxT("Re&gions screen\tF8"));
1709 menuFile
->Append(File_ShowCircles
, wxT("&Circles screen\tF9"));
1710 #if wxUSE_GRAPHICS_CONTEXT
1711 menuFile
->Append(File_ShowAlpha
, wxT("&Alpha screen\tF10"));
1713 menuFile
->Append(File_ShowSplines
, wxT("&Splines screen\tF11"));
1714 menuFile
->Append(File_ShowGradients
, wxT("&Gradients screen\tF12"));
1715 #if wxUSE_GRAPHICS_CONTEXT
1716 menuFile
->Append(File_ShowGraphics
, wxT("&Graphics screen"));
1718 menuFile
->AppendSeparator();
1719 menuFile
->AppendCheckItem(File_Clip
, wxT("&Clip\tCtrl-C"), wxT("Clip/unclip drawing"));
1720 #if wxUSE_GRAPHICS_CONTEXT
1721 menuFile
->AppendCheckItem(File_GraphicContext
, wxT("&Use GraphicContext\tCtrl-Y"), wxT("Use GraphicContext"));
1723 menuFile
->AppendSeparator();
1724 menuFile
->Append(File_About
, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
1725 menuFile
->AppendSeparator();
1726 menuFile
->Append(File_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
1728 wxMenu
*menuMapMode
= new wxMenu
;
1729 menuMapMode
->Append( MapMode_Text
, wxT("&TEXT map mode") );
1730 menuMapMode
->Append( MapMode_Lometric
, wxT("&LOMETRIC map mode") );
1731 menuMapMode
->Append( MapMode_Twips
, wxT("T&WIPS map mode") );
1732 menuMapMode
->Append( MapMode_Points
, wxT("&POINTS map mode") );
1733 menuMapMode
->Append( MapMode_Metric
, wxT("&METRIC map mode") );
1735 wxMenu
*menuUserScale
= new wxMenu
;
1736 menuUserScale
->Append( UserScale_StretchHoriz
, wxT("Stretch &horizontally\tCtrl-H") );
1737 menuUserScale
->Append( UserScale_ShrinkHoriz
, wxT("Shrin&k horizontally\tCtrl-G") );
1738 menuUserScale
->Append( UserScale_StretchVertic
, wxT("Stretch &vertically\tCtrl-V") );
1739 menuUserScale
->Append( UserScale_ShrinkVertic
, wxT("&Shrink vertically\tCtrl-W") );
1740 menuUserScale
->AppendSeparator();
1741 menuUserScale
->Append( UserScale_Restore
, wxT("&Restore to normal\tCtrl-0") );
1743 wxMenu
*menuAxis
= new wxMenu
;
1744 menuAxis
->AppendCheckItem( AxisMirror_Horiz
, wxT("Mirror horizontally\tCtrl-M") );
1745 menuAxis
->AppendCheckItem( AxisMirror_Vertic
, wxT("Mirror vertically\tCtrl-N") );
1747 wxMenu
*menuLogical
= new wxMenu
;
1748 menuLogical
->Append( LogicalOrigin_MoveDown
, wxT("Move &down\tCtrl-D") );
1749 menuLogical
->Append( LogicalOrigin_MoveUp
, wxT("Move &up\tCtrl-U") );
1750 menuLogical
->Append( LogicalOrigin_MoveLeft
, wxT("Move &right\tCtrl-L") );
1751 menuLogical
->Append( LogicalOrigin_MoveRight
, wxT("Move &left\tCtrl-R") );
1752 menuLogical
->AppendSeparator();
1753 menuLogical
->Append( LogicalOrigin_Set
, wxT("Set to (&100, 100)\tShift-Ctrl-1") );
1754 menuLogical
->Append( LogicalOrigin_Restore
, wxT("&Restore to normal\tShift-Ctrl-0") );
1756 wxMenu
*menuColour
= new wxMenu
;
1758 menuColour
->Append( Colour_TextForeground
, wxT("Text &foreground...") );
1759 menuColour
->Append( Colour_TextBackground
, wxT("Text &background...") );
1760 menuColour
->Append( Colour_Background
, wxT("Background &colour...") );
1761 #endif // wxUSE_COLOURDLG
1762 menuColour
->AppendCheckItem( Colour_BackgroundMode
, wxT("&Opaque/transparent\tCtrl-B") );
1763 menuColour
->AppendCheckItem( Colour_TextureBackgound
, wxT("Draw textured back&ground\tCtrl-T") );
1765 // now append the freshly created menu to the menu bar...
1766 wxMenuBar
*menuBar
= new wxMenuBar
;
1767 menuBar
->Append(menuFile
, wxT("&File"));
1768 menuBar
->Append(menuMapMode
, wxT("&Mode"));
1769 menuBar
->Append(menuUserScale
, wxT("&Scale"));
1770 menuBar
->Append(menuAxis
, wxT("&Axis"));
1771 menuBar
->Append(menuLogical
, wxT("&Origin"));
1772 menuBar
->Append(menuColour
, wxT("&Colours"));
1774 // ... and attach this menu bar to the frame
1775 SetMenuBar(menuBar
);
1779 SetStatusText(wxT("Welcome to wxWidgets!"));
1780 #endif // wxUSE_STATUSBAR
1782 m_mapMode
= wxMM_TEXT
;
1785 m_xLogicalOrigin
= 0;
1786 m_yLogicalOrigin
= 0;
1788 m_yAxisReversed
= false;
1789 m_backgroundMode
= wxSOLID
;
1790 m_colourForeground
= *wxBLACK
;
1791 m_colourBackground
= *wxLIGHT_GREY
;
1792 m_textureBackground
= false;
1794 m_canvas
= new MyCanvas( this );
1795 m_canvas
->SetScrollbars( 10, 10, 100, 240 );
1800 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
1802 // true is to force the frame to close
1806 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
1809 msg
.Printf( wxT("This is the about dialog of the drawing sample.\n")
1810 wxT("This sample tests various primitive drawing functions\n")
1811 wxT("(without any attempts to prevent flicker).\n")
1812 wxT("Copyright (c) Robert Roebling 1999")
1815 wxMessageBox(msg
, wxT("About Drawing"), wxOK
| wxICON_INFORMATION
, this);
1818 void MyFrame::OnClip(wxCommandEvent
& event
)
1820 m_canvas
->Clip(event
.IsChecked());
1823 #if wxUSE_GRAPHICS_CONTEXT
1824 void MyFrame::OnGraphicContext(wxCommandEvent
& event
)
1826 m_canvas
->UseGraphicContext(event
.IsChecked());
1830 void MyFrame::OnShow(wxCommandEvent
& event
)
1832 m_canvas
->ToShow(event
.GetId());
1835 void MyFrame::OnOption(wxCommandEvent
& event
)
1837 switch (event
.GetId())
1840 m_mapMode
= wxMM_TEXT
;
1842 case MapMode_Lometric
:
1843 m_mapMode
= wxMM_LOMETRIC
;
1846 m_mapMode
= wxMM_TWIPS
;
1848 case MapMode_Points
:
1849 m_mapMode
= wxMM_POINTS
;
1851 case MapMode_Metric
:
1852 m_mapMode
= wxMM_METRIC
;
1855 case LogicalOrigin_MoveDown
:
1856 m_yLogicalOrigin
+= 10;
1858 case LogicalOrigin_MoveUp
:
1859 m_yLogicalOrigin
-= 10;
1861 case LogicalOrigin_MoveLeft
:
1862 m_xLogicalOrigin
+= 10;
1864 case LogicalOrigin_MoveRight
:
1865 m_xLogicalOrigin
-= 10;
1867 case LogicalOrigin_Set
:
1869 m_yLogicalOrigin
= -100;
1871 case LogicalOrigin_Restore
:
1873 m_yLogicalOrigin
= 0;
1876 case UserScale_StretchHoriz
:
1877 m_xUserScale
*= 1.10;
1879 case UserScale_ShrinkHoriz
:
1880 m_xUserScale
/= 1.10;
1882 case UserScale_StretchVertic
:
1883 m_yUserScale
*= 1.10;
1885 case UserScale_ShrinkVertic
:
1886 m_yUserScale
/= 1.10;
1888 case UserScale_Restore
:
1893 case AxisMirror_Vertic
:
1894 m_yAxisReversed
= !m_yAxisReversed
;
1896 case AxisMirror_Horiz
:
1897 m_xAxisReversed
= !m_xAxisReversed
;
1901 case Colour_TextForeground
:
1902 m_colourForeground
= SelectColour();
1904 case Colour_TextBackground
:
1905 m_colourBackground
= SelectColour();
1907 case Colour_Background
:
1909 wxColour col
= SelectColour();
1912 m_backgroundBrush
.SetColour(col
);
1916 #endif // wxUSE_COLOURDLG
1918 case Colour_BackgroundMode
:
1919 m_backgroundMode
= m_backgroundMode
== wxSOLID
? wxTRANSPARENT
1923 case Colour_TextureBackgound
:
1924 m_textureBackground
= ! m_textureBackground
;
1932 m_canvas
->Refresh();
1935 void MyFrame::PrepareDC(wxDC
& dc
)
1937 dc
.SetLogicalOrigin( m_xLogicalOrigin
, m_yLogicalOrigin
);
1938 dc
.SetAxisOrientation( !m_xAxisReversed
, m_yAxisReversed
);
1939 dc
.SetUserScale( m_xUserScale
, m_yUserScale
);
1940 dc
.SetMapMode( m_mapMode
);
1944 wxColour
MyFrame::SelectColour()
1948 wxColourDialog
dialog(this, &data
);
1950 if ( dialog
.ShowModal() == wxID_OK
)
1952 col
= dialog
.GetColourData().GetColour();
1957 #endif // wxUSE_COLOURDLG