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()
369 wxDELETE(gs_bmpNoMask
);
370 wxDELETE(gs_bmpWithColMask
);
371 wxDELETE(gs_bmpMask
);
372 wxDELETE(gs_bmpWithMask
);
374 wxDELETE(gs_bmp4_mono
);
378 // ----------------------------------------------------------------------------
380 // ----------------------------------------------------------------------------
382 // the event tables connect the wxWidgets events with the functions (event
383 // handlers) which process them.
384 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
385 EVT_PAINT (MyCanvas::OnPaint
)
386 EVT_MOTION (MyCanvas::OnMouseMove
)
387 EVT_LEFT_DOWN (MyCanvas::OnMouseDown
)
388 EVT_LEFT_UP (MyCanvas::OnMouseUp
)
393 MyCanvas::MyCanvas(MyFrame
*parent
)
394 : wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
395 wxHSCROLL
| wxVSCROLL
| wxNO_FULL_REPAINT_ON_RESIZE
)
398 m_show
= File_ShowDefault
;
399 m_smile_bmp
= wxBitmap(smile_xpm
);
400 m_std_icon
= wxArtProvider::GetIcon(wxART_INFORMATION
);
402 m_rubberBand
= false;
403 #if wxUSE_GRAPHICS_CONTEXT
404 m_useContext
= false;
408 void MyCanvas::DrawTestBrushes(wxDC
& dc
)
410 static const wxCoord WIDTH
= 200;
411 static const wxCoord HEIGHT
= 80;
416 dc
.SetBrush(wxBrush(*wxGREEN
, wxSOLID
));
417 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
418 dc
.DrawText(wxT("Solid green"), x
+ 10, y
+ 10);
421 dc
.SetBrush(wxBrush(*wxRED
, wxCROSSDIAG_HATCH
));
422 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
423 dc
.DrawText(wxT("Hatched red"), x
+ 10, y
+ 10);
426 dc
.SetBrush(wxBrush(*gs_bmpMask
));
427 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
428 dc
.DrawText(wxT("Stipple mono"), x
+ 10, y
+ 10);
431 dc
.SetBrush(wxBrush(*gs_bmpNoMask
));
432 dc
.DrawRectangle(x
, y
, WIDTH
, HEIGHT
);
433 dc
.DrawText(wxT("Stipple colour"), x
+ 10, y
+ 10);
436 void MyCanvas::DrawTestPoly(wxDC
& dc
)
438 wxBrush
brushHatch(*wxRED
, wxFDIAGONAL_HATCH
);
439 dc
.SetBrush(brushHatch
);
442 star
[0] = wxPoint(100, 60);
443 star
[1] = wxPoint(60, 150);
444 star
[2] = wxPoint(160, 100);
445 star
[3] = wxPoint(40, 100);
446 star
[4] = wxPoint(140, 150);
448 dc
.DrawText(wxT("You should see two (irregular) stars below, the left one ")
449 wxT("hatched"), 10, 10);
450 dc
.DrawText(wxT("except for the central region and the right ")
451 wxT("one entirely hatched"), 10, 30);
452 dc
.DrawText(wxT("The third star only has a hatched outline"), 10, 50);
454 dc
.DrawPolygon(WXSIZEOF(star
), star
, 0, 30);
455 dc
.DrawPolygon(WXSIZEOF(star
), star
, 160, 30, wxWINDING_RULE
);
458 star2
[0] = wxPoint(0, 100);
459 star2
[1] = wxPoint(-59, -81);
460 star2
[2] = wxPoint(95, 31);
461 star2
[3] = wxPoint(-95, 31);
462 star2
[4] = wxPoint(59, -81);
463 star2
[5] = wxPoint(0, 80);
464 star2
[6] = wxPoint(-47, -64);
465 star2
[7] = wxPoint(76, 24);
466 star2
[8] = wxPoint(-76, 24);
467 star2
[9] = wxPoint(47, -64);
468 int count
[2] = {5, 5};
470 dc
.DrawPolyPolygon(WXSIZEOF(count
), count
, star2
, 450, 150);
473 void MyCanvas::DrawTestLines( int x
, int y
, int width
, wxDC
&dc
)
475 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
476 dc
.SetBrush( *wxRED_BRUSH
);
477 dc
.DrawText(wxString::Format(wxT("Testing lines of width %d"), width
), x
+ 10, y
- 10);
478 dc
.DrawRectangle( x
+10, y
+10, 100, 190 );
480 dc
.DrawText(wxT("Solid/dot/short dash/long dash/dot dash"), x
+ 150, y
+ 10);
481 dc
.SetPen( wxPen( wxT("black"), width
, wxSOLID
) );
482 dc
.DrawLine( x
+20, y
+20, 100, y
+20 );
483 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT
) );
484 dc
.DrawLine( x
+20, y
+30, 100, y
+30 );
485 dc
.SetPen( wxPen( wxT("black"), width
, wxSHORT_DASH
) );
486 dc
.DrawLine( x
+20, y
+40, 100, y
+40 );
487 dc
.SetPen( wxPen( wxT("black"), width
, wxLONG_DASH
) );
488 dc
.DrawLine( x
+20, y
+50, 100, y
+50 );
489 dc
.SetPen( wxPen( wxT("black"), width
, wxDOT_DASH
) );
490 dc
.DrawLine( x
+20, y
+60, 100, y
+60 );
492 dc
.DrawText(wxT("Misc hatches"), x
+ 150, y
+ 70);
493 dc
.SetPen( wxPen( wxT("black"), width
, wxBDIAGONAL_HATCH
) );
494 dc
.DrawLine( x
+20, y
+70, 100, y
+70 );
495 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSSDIAG_HATCH
) );
496 dc
.DrawLine( x
+20, y
+80, 100, y
+80 );
497 dc
.SetPen( wxPen( wxT("black"), width
, wxFDIAGONAL_HATCH
) );
498 dc
.DrawLine( x
+20, y
+90, 100, y
+90 );
499 dc
.SetPen( wxPen( wxT("black"), width
, wxCROSS_HATCH
) );
500 dc
.DrawLine( x
+20, y
+100, 100, y
+100 );
501 dc
.SetPen( wxPen( wxT("black"), width
, wxHORIZONTAL_HATCH
) );
502 dc
.DrawLine( x
+20, y
+110, 100, y
+110 );
503 dc
.SetPen( wxPen( wxT("black"), width
, wxVERTICAL_HATCH
) );
504 dc
.DrawLine( x
+20, y
+120, 100, y
+120 );
506 dc
.DrawText(wxT("User dash"), x
+ 150, y
+ 140);
507 wxPen
ud( wxT("black"), width
, wxUSER_DASH
);
509 dash1
[0] = 8; // Long dash <---------+
510 dash1
[1] = 2; // Short gap |
511 dash1
[2] = 3; // Short dash |
512 dash1
[3] = 2; // Short gap |
513 dash1
[4] = 3; // Short dash |
514 dash1
[5] = 2; // Short gap and repeat +
515 ud
.SetDashes( 6, dash1
);
517 dc
.DrawLine( x
+20, y
+140, 100, y
+140 );
518 dash1
[0] = 5; // Make first dash shorter
519 ud
.SetDashes( 6, dash1
);
521 dc
.DrawLine( x
+20, y
+150, 100, y
+150 );
522 dash1
[2] = 5; // Make second dash longer
523 ud
.SetDashes( 6, dash1
);
525 dc
.DrawLine( x
+20, y
+160, 100, y
+160 );
526 dash1
[4] = 5; // Make third dash longer
527 ud
.SetDashes( 6, dash1
);
529 dc
.DrawLine( x
+20, y
+170, 100, y
+170 );
532 void MyCanvas::DrawDefault(wxDC
& dc
)
535 dc
.DrawCircle(0, 0, 10);
537 #if !defined(wxMAC_USE_CORE_GRAPHICS) || !wxMAC_USE_CORE_GRAPHICS
538 // GetPixel and FloodFill not supported by Mac OS X CoreGraphics
539 // (FloodFill uses Blit from a non-wxMemoryDC)
540 //flood fill using brush, starting at 1,1 and replacing whatever colour we find there
541 dc
.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID
));
544 dc
.GetPixel(1,1, &tmpColour
);
545 dc
.FloodFill(1,1, tmpColour
, wxFLOOD_SURFACE
);
548 dc
.DrawCheckMark(5, 80, 15, 15);
549 dc
.DrawCheckMark(25, 80, 30, 30);
550 dc
.DrawCheckMark(60, 80, 60, 60);
552 // this is the test for "blitting bitmap into DC damages selected brush" bug
553 wxCoord rectSize
= m_std_icon
.GetWidth() + 10;
555 dc
.SetPen(*wxTRANSPARENT_PEN
);
556 dc
.SetBrush( *wxGREEN_BRUSH
);
557 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
558 dc
.DrawBitmap(m_std_icon
, x
+ 5, 15, true);
560 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
561 dc
.DrawIcon(m_std_icon
, x
+ 5, 15);
563 dc
.DrawRectangle(x
, 10, rectSize
, rectSize
);
565 // test for "transparent" bitmap drawing (it intersects with the last
567 //dc.SetBrush( *wxTRANSPARENT_BRUSH );
569 if (m_smile_bmp
.Ok())
570 dc
.DrawBitmap(m_smile_bmp
, x
+ rectSize
- 20, rectSize
- 10, true);
572 dc
.SetBrush( *wxBLACK_BRUSH
);
573 dc
.DrawRectangle( 0, 160, 1000, 300 );
576 wxBitmap
bitmap(20,70);
578 memdc
.SelectObject( bitmap
);
579 memdc
.SetBrush( *wxBLACK_BRUSH
);
580 memdc
.SetPen( *wxWHITE_PEN
);
581 memdc
.DrawRectangle(0,0,20,70);
582 memdc
.DrawLine( 10,0,10,70 );
585 wxPen pen
= *wxRED_PEN
;
587 memdc
.DrawLine( 10, 5,10, 5 );
588 memdc
.DrawLine( 10,10,11,10 );
589 memdc
.DrawLine( 10,15,12,15 );
590 memdc
.DrawLine( 10,20,13,20 );
593 memdc.SetPen(*wxRED_PEN);
594 memdc.DrawLine( 12, 5,12, 5 );
595 memdc.DrawLine( 12,10,13,10 );
596 memdc.DrawLine( 12,15,14,15 );
597 memdc.DrawLine( 12,20,15,20 );
601 memdc
.DrawLine( 10,25,10,25 );
602 memdc
.DrawLine( 10,30, 9,30 );
603 memdc
.DrawLine( 10,35, 8,35 );
604 memdc
.DrawLine( 10,40, 7,40 );
607 dc
.SetPen(*wxWHITE_PEN
);
608 memdc
.SetLogicalFunction( wxINVERT
);
609 memdc
.SetPen( *wxWHITE_PEN
);
610 memdc
.DrawLine( 10,50,10,50 );
611 memdc
.DrawLine( 10,55,11,55 );
612 memdc
.DrawLine( 10,60,12,60 );
613 memdc
.DrawLine( 10,65,13,65 );
615 memdc
.DrawLine( 12,50,12,50 );
616 memdc
.DrawLine( 12,55,13,55 );
617 memdc
.DrawLine( 12,60,14,60 );
618 memdc
.DrawLine( 12,65,15,65 );
620 memdc
.SelectObject( wxNullBitmap
);
621 dc
.DrawBitmap( bitmap
, 10, 170 );
622 wxImage image
= bitmap
.ConvertToImage();
623 image
.Rescale( 60,210 );
624 bitmap
= wxBitmap(image
);
625 dc
.DrawBitmap( bitmap
, 50, 170 );
627 // test the rectangle outline drawing - there should be one pixel between
628 // the rect and the lines
629 dc
.SetPen(*wxWHITE_PEN
);
630 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
631 dc
.DrawRectangle(150, 170, 49, 29);
632 dc
.DrawRectangle(200, 170, 49, 29);
633 dc
.SetPen(*wxWHITE_PEN
);
634 dc
.DrawLine(250, 210, 250, 170);
635 dc
.DrawLine(260, 200, 150, 200);
637 // test the rectangle filled drawing - there should be one pixel between
638 // the rect and the lines
639 dc
.SetPen(*wxTRANSPARENT_PEN
);
640 dc
.SetBrush( *wxWHITE_BRUSH
);
641 dc
.DrawRectangle(300, 170, 49, 29);
642 dc
.DrawRectangle(350, 170, 49, 29);
643 dc
.SetPen(*wxWHITE_PEN
);
644 dc
.DrawLine(400, 170, 400, 210);
645 dc
.DrawLine(300, 200, 410, 200);
647 // a few more tests of this kind
648 dc
.SetPen(*wxRED_PEN
);
649 dc
.SetBrush( *wxWHITE_BRUSH
);
650 dc
.DrawRectangle(300, 220, 1, 1);
651 dc
.DrawRectangle(310, 220, 2, 2);
652 dc
.DrawRectangle(320, 220, 3, 3);
653 dc
.DrawRectangle(330, 220, 4, 4);
655 dc
.SetPen(*wxTRANSPARENT_PEN
);
656 dc
.SetBrush( *wxWHITE_BRUSH
);
657 dc
.DrawRectangle(300, 230, 1, 1);
658 dc
.DrawRectangle(310, 230, 2, 2);
659 dc
.DrawRectangle(320, 230, 3, 3);
660 dc
.DrawRectangle(330, 230, 4, 4);
662 // and now for filled rect with outline
663 dc
.SetPen(*wxRED_PEN
);
664 dc
.SetBrush( *wxWHITE_BRUSH
);
665 dc
.DrawRectangle(500, 170, 49, 29);
666 dc
.DrawRectangle(550, 170, 49, 29);
667 dc
.SetPen(*wxWHITE_PEN
);
668 dc
.DrawLine(600, 170, 600, 210);
669 dc
.DrawLine(500, 200, 610, 200);
671 // test the rectangle outline drawing - there should be one pixel between
672 // the rect and the lines
673 dc
.SetPen(*wxWHITE_PEN
);
674 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
675 dc
.DrawRoundedRectangle(150, 270, 49, 29, 6);
676 dc
.DrawRoundedRectangle(200, 270, 49, 29, 6);
677 dc
.SetPen(*wxWHITE_PEN
);
678 dc
.DrawLine(250, 270, 250, 310);
679 dc
.DrawLine(150, 300, 260, 300);
681 // test the rectangle filled drawing - there should be one pixel between
682 // the rect and the lines
683 dc
.SetPen(*wxTRANSPARENT_PEN
);
684 dc
.SetBrush( *wxWHITE_BRUSH
);
685 dc
.DrawRoundedRectangle(300, 270, 49, 29, 6);
686 dc
.DrawRoundedRectangle(350, 270, 49, 29, 6);
687 dc
.SetPen(*wxWHITE_PEN
);
688 dc
.DrawLine(400, 270, 400, 310);
689 dc
.DrawLine(300, 300, 410, 300);
691 // Added by JACS to demonstrate bizarre behaviour.
692 // With a size of 70, we get a missing red RHS,
693 // and the height is too small, so we get yellow
694 // showing. With a size of 40, it draws as expected:
695 // it just shows a white rectangle with red outline.
697 int totalHeight
= 70;
698 wxBitmap
bitmap2(totalWidth
, totalHeight
);
701 memdc2
.SelectObject(bitmap2
);
703 wxColour
clr(255, 255, 0);
704 wxBrush
yellowBrush(clr
, wxSOLID
);
705 memdc2
.SetBackground(yellowBrush
);
708 wxPen
yellowPen(clr
, 1, wxSOLID
);
710 // Now draw a white rectangle with red outline. It should
711 // entirely eclipse the yellow background.
712 memdc2
.SetPen(*wxRED_PEN
);
713 memdc2
.SetBrush(*wxWHITE_BRUSH
);
715 memdc2
.DrawRectangle(0, 0, totalWidth
, totalHeight
);
717 memdc2
.SetPen(wxNullPen
);
718 memdc2
.SetBrush(wxNullBrush
);
719 memdc2
.SelectObject(wxNullBitmap
);
721 dc
.DrawBitmap(bitmap2
, 500, 270);
723 // Repeat, but draw directly on dc
724 // Draw a yellow rectangle filling the bitmap
726 x
= 600; int y
= 270;
727 dc
.SetPen(yellowPen
);
728 dc
.SetBrush(yellowBrush
);
729 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
731 // Now draw a white rectangle with red outline. It should
732 // entirely eclipse the yellow background.
733 dc
.SetPen(*wxRED_PEN
);
734 dc
.SetBrush(*wxWHITE_BRUSH
);
736 dc
.DrawRectangle(x
, y
, totalWidth
, totalHeight
);
739 void MyCanvas::DrawText(wxDC
& dc
)
741 // set underlined font for testing
742 dc
.SetFont( wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, true) );
743 dc
.DrawText( wxT("This is text"), 110, 10 );
744 dc
.DrawRotatedText( wxT("That is text"), 20, 10, -45 );
746 // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
747 // under Win9x (it is not TrueType)
748 dc
.SetFont( *wxSWISS_FONT
);
751 dc
.SetBackgroundMode(wxTRANSPARENT
);
753 for ( int n
= -180; n
< 180; n
+= 30 )
755 text
.Printf(wxT(" %d rotated text"), n
);
756 dc
.DrawRotatedText(text
, 400, 400, n
);
759 dc
.SetFont( wxFont( 18, wxSWISS
, wxNORMAL
, wxNORMAL
) );
761 dc
.DrawText( wxT("This is Swiss 18pt text."), 110, 40 );
766 dc
.GetTextExtent( wxT("This is Swiss 18pt text."), &length
, &height
, &descent
);
767 text
.Printf( wxT("Dimensions are length %d, height %d, descent %d"), length
, height
, descent
);
768 dc
.DrawText( text
, 110, 80 );
770 text
.Printf( wxT("CharHeight() returns: %d"), dc
.GetCharHeight() );
771 dc
.DrawText( text
, 110, 120 );
773 dc
.DrawRectangle( 100, 40, 4, height
);
775 // test the logical function effect
777 dc
.SetLogicalFunction(wxINVERT
);
778 // text drawing should ignore logical function
779 dc
.DrawText( wxT("There should be a text below"), 110, 150 );
780 dc
.DrawRectangle( 110, y
, 100, height
);
783 dc
.DrawText( wxT("Visible text"), 110, y
);
784 dc
.DrawRectangle( 110, y
, 100, height
);
785 dc
.DrawText( wxT("Visible text"), 110, y
);
786 dc
.DrawRectangle( 110, y
, 100, height
);
787 dc
.SetLogicalFunction(wxCOPY
);
790 dc
.DrawRectangle( 110, y
, 100, height
);
791 dc
.DrawText( wxT("Another visible text"), 110, y
);
794 dc
.DrawText("And\nmore\ntext on\nmultiple\nlines", 110, y
);
800 wxRasterOperationMode rop
;
801 } rasterOperations
[] =
803 { wxT("wxAND"), wxAND
},
804 { wxT("wxAND_INVERT"), wxAND_INVERT
},
805 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
806 { wxT("wxCLEAR"), wxCLEAR
},
807 { wxT("wxCOPY"), wxCOPY
},
808 { wxT("wxEQUIV"), wxEQUIV
},
809 { wxT("wxINVERT"), wxINVERT
},
810 { wxT("wxNAND"), wxNAND
},
811 { wxT("wxNO_OP"), wxNO_OP
},
812 { wxT("wxOR"), wxOR
},
813 { wxT("wxOR_INVERT"), wxOR_INVERT
},
814 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
815 { wxT("wxSET"), wxSET
},
816 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
817 { wxT("wxXOR"), wxXOR
},
820 void MyCanvas::DrawImages(wxDC
& dc
, DrawMode mode
)
822 dc
.DrawText(wxT("original image"), 0, 0);
823 dc
.DrawBitmap(*gs_bmpNoMask
, 0, 20, 0);
824 dc
.DrawText(wxT("with colour mask"), 0, 100);
825 dc
.DrawBitmap(*gs_bmpWithColMask
, 0, 120, true);
826 dc
.DrawText(wxT("the mask image"), 0, 200);
827 dc
.DrawBitmap(*gs_bmpMask
, 0, 220, 0);
828 dc
.DrawText(wxT("masked image"), 0, 300);
829 dc
.DrawBitmap(*gs_bmpWithMask
, 0, 320, true);
831 int cx
= gs_bmpWithColMask
->GetWidth(),
832 cy
= gs_bmpWithColMask
->GetHeight();
835 for ( size_t n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
837 wxCoord x
= 120 + 150*(n%4
),
840 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
841 memDC
.SelectObject(*gs_bmpWithColMask
);
842 if ( mode
== Draw_Stretch
)
844 dc
.StretchBlit(x
, y
, cx
, cy
, &memDC
, 0, 0, cx
/2, cy
/2,
845 rasterOperations
[n
].rop
, true);
849 dc
.Blit(x
, y
, cx
, cy
, &memDC
, 0, 0, rasterOperations
[n
].rop
, true);
854 void MyCanvas::DrawWithLogicalOps(wxDC
& dc
)
856 static const wxCoord w
= 60;
857 static const wxCoord h
= 60;
859 // reuse the text colour here
860 dc
.SetPen(wxPen(m_owner
->m_colourForeground
, 1, wxSOLID
));
861 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
864 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
866 wxCoord x
= 20 + 150*(n%4
),
869 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
870 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
871 dc
.DrawRectangle(x
, y
, w
, h
);
872 dc
.DrawLine(x
, y
, x
+ w
, y
+ h
);
873 dc
.DrawLine(x
+ w
, y
, x
, y
+ h
);
876 // now some filled rectangles
877 dc
.SetBrush(wxBrush(m_owner
->m_colourForeground
, wxSOLID
));
879 for ( n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
881 wxCoord x
= 20 + 150*(n%4
),
884 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
885 dc
.SetLogicalFunction(rasterOperations
[n
].rop
);
886 dc
.DrawRectangle(x
, y
, w
, h
);
890 #if wxUSE_GRAPHICS_CONTEXT
892 void MyCanvas::DrawAlpha(wxDC
& WXUNUSED(dummyDC
))
894 void MyCanvas::DrawAlpha(wxDC
& dc
)
902 wxDouble margin
= 20 ;
903 wxDouble width
= 180 ;
904 wxDouble radius
= 30 ;
906 dc
.SetPen( wxPen( wxColour( 128, 0, 0, 255 ),12, wxSOLID
));
907 dc
.SetBrush( wxBrush( wxColour( 255, 0, 0, 255),wxSOLID
));
909 wxRect
r(margin
,margin
+width
*0.66,width
,width
) ;
911 dc
.DrawRoundedRectangle( r
.x
, r
.y
, r
.width
, r
.width
, radius
) ;
913 dc
.SetPen( wxPen( wxColour( 0, 0, 128, 255 ),12, wxSOLID
));
914 dc
.SetBrush( wxBrush( wxColour( 0, 0, 255, 255),wxSOLID
));
916 r
.Offset( width
* 0.8 , - width
* 0.66 ) ;
918 dc
.DrawRoundedRectangle( r
.x
, r
.y
, r
.width
, r
.width
, radius
) ;
920 dc
.SetPen( wxPen( wxColour( 128, 128, 0, 255 ),12, wxSOLID
));
921 dc
.SetBrush( wxBrush( wxColour( 192, 192, 0, 255),wxSOLID
));
923 r
.Offset( width
* 0.8 , width
*0.5 ) ;
925 dc
.DrawRoundedRectangle( r
.x
, r
.y
, r
.width
, r
.width
, radius
) ;
927 dc
.SetPen( *wxTRANSPARENT_PEN
) ;
928 dc
.SetBrush( wxBrush( wxColour(255,255,128,128) ) );
929 dc
.DrawRoundedRectangle( 0 , margin
+ width
/ 2 , width
* 3 , 100 , radius
) ;
931 dc
.SetTextForeground( wxColour(255,255,0,128) );
932 dc
.SetFont( wxFont( 40, wxFONTFAMILY_SWISS
, wxFONTSTYLE_ITALIC
, wxFONTWEIGHT_NORMAL
) );
933 dc
.DrawText( wxT("Hello!"), 120, 80 );
938 #if wxUSE_GRAPHICS_CONTEXT
940 const int BASE
= 80.0;
941 const int BASE2
= BASE
/2;
942 const int BASE4
= BASE
/4;
944 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
947 // modeled along Robin Dunn's GraphicsContext.py sample
949 void MyCanvas::DrawGraphics(wxGraphicsContext
* gc
)
951 wxFont font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
952 gc
->SetFont(font
,*wxBLACK
);
954 // make a path that contains a circle and some lines, centered at 0,0
955 wxGraphicsPath path
= gc
->CreatePath() ;
956 path
.AddCircle( 0, 0, BASE2
);
957 path
.MoveToPoint(0, -BASE2
);
958 path
.AddLineToPoint(0, BASE2
);
959 path
.MoveToPoint(-BASE2
, 0);
960 path
.AddLineToPoint(BASE2
, 0);
962 path
.AddRectangle(-BASE4
, -BASE4
/2, BASE2
, BASE4
);
964 // Now use that path to demonstrate various capbilites of the grpahics context
965 gc
->PushState(); // save current translation/scale/other state
966 gc
->Translate(60, 75); // reposition the context origin
968 gc
->SetPen(wxPen("navy", 1));
969 gc
->SetBrush(wxBrush("pink"));
971 for( int i
= 0 ; i
< 3 ; ++i
)
977 label
= "StrokePath";
987 gc
->GetTextExtent(label
, &w
, &h
, NULL
, NULL
);
988 gc
->DrawText(label
, -w
/2, -BASE2
-h
-4);
992 gc
->StrokePath(path
);
1001 gc
->Translate(2*BASE
, 0);
1004 gc
->PopState(); // restore saved state
1005 gc
->PushState(); // save it again
1006 gc
->Translate(60, 200); // offset to the lower part of the window
1008 gc
->DrawText("Scale", 0, -BASE2
);
1009 gc
->Translate(0, 20);
1011 gc
->SetBrush(wxBrush(wxColour(178, 34, 34, 128)));// 128 == half transparent
1012 for( int i
= 0 ; i
< 8 ; ++i
)
1014 gc
->Scale(1.08, 1.08); // increase scale by 8%
1019 gc
->PopState(); // restore saved state
1020 gc
->PushState(); // save it again
1021 gc
->Translate(400, 200);
1023 gc
->DrawText("Rotate", 0, -BASE2
);
1025 // Move the origin over to the next location
1026 gc
->Translate(0, 75);
1028 // draw our path again, rotating it about the central point,
1029 // and changing colors as we go
1030 for ( int angle
= 0 ; angle
< 360 ; angle
+= 30 )
1032 gc
->PushState(); // save this new current state so we can
1033 // pop back to it at the end of the loop
1034 wxImage::RGBValue val
= wxImage::HSVtoRGB(wxImage::HSVValue(float(angle
)/360, 1, 1));
1035 gc
->SetBrush(wxBrush(wxColour(val
.red
, val
.green
, val
.blue
, 64)));
1036 gc
->SetPen(wxPen(wxColour(val
.red
, val
.green
, val
.blue
, 128)));
1038 // use translate to artfully reposition each drawn path
1039 gc
->Translate(1.5 * BASE2
* cos(DegToRad(angle
)),
1040 1.5 * BASE2
* sin(DegToRad(angle
)));
1042 // use Rotate to rotate the path
1043 gc
->Rotate(DegToRad(angle
));
1052 gc
->Translate(60, 400);
1053 gc
->DrawText("Scaled smiley inside a square", 0, 0);
1054 gc
->DrawRectangle(BASE2
, BASE2
, 100, 100);
1055 gc
->DrawBitmap(m_smile_bmp
, BASE2
, BASE2
, 100, 100);
1058 #endif // wxUSE_GRAPHICS_CONTEXT
1060 void MyCanvas::DrawCircles(wxDC
& dc
)
1066 dc
.SetPen( *wxRED_PEN
);
1067 dc
.SetBrush( *wxGREEN_BRUSH
);
1069 dc
.DrawText(wxT("Some circles"), 0, y
);
1070 dc
.DrawCircle(x
, y
, r
);
1071 dc
.DrawCircle(x
+ 2*r
, y
, r
);
1072 dc
.DrawCircle(x
+ 4*r
, y
, r
);
1075 dc
.DrawText(wxT("And ellipses"), 0, y
);
1076 dc
.DrawEllipse(x
- r
, y
, 2*r
, r
);
1077 dc
.DrawEllipse(x
+ r
, y
, 2*r
, r
);
1078 dc
.DrawEllipse(x
+ 3*r
, y
, 2*r
, r
);
1081 dc
.DrawText(wxT("And arcs"), 0, y
);
1082 dc
.DrawArc(x
- r
, y
, x
+ r
, y
, x
, y
);
1083 dc
.DrawArc(x
+ 4*r
, y
, x
+ 2*r
, y
, x
+ 3*r
, y
);
1084 dc
.DrawArc(x
+ 5*r
, y
, x
+ 5*r
, y
, x
+ 6*r
, y
);
1087 dc
.DrawEllipticArc(x
- r
, y
, 2*r
, r
, 0, 90);
1088 dc
.DrawEllipticArc(x
+ r
, y
, 2*r
, r
, 90, 180);
1089 dc
.DrawEllipticArc(x
+ 3*r
, y
, 2*r
, r
, 180, 270);
1090 dc
.DrawEllipticArc(x
+ 5*r
, y
, 2*r
, r
, 270, 360);
1092 // same as above, just transparent brush
1094 dc
.SetPen( *wxRED_PEN
);
1095 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1098 dc
.DrawText(wxT("Some circles"), 0, y
);
1099 dc
.DrawCircle(x
, y
, r
);
1100 dc
.DrawCircle(x
+ 2*r
, y
, r
);
1101 dc
.DrawCircle(x
+ 4*r
, y
, r
);
1104 dc
.DrawText(wxT("And ellipses"), 0, y
);
1105 dc
.DrawEllipse(x
- r
, y
, 2*r
, r
);
1106 dc
.DrawEllipse(x
+ r
, y
, 2*r
, r
);
1107 dc
.DrawEllipse(x
+ 3*r
, y
, 2*r
, r
);
1110 dc
.DrawText(wxT("And arcs"), 0, y
);
1111 dc
.DrawArc(x
- r
, y
, x
+ r
, y
, x
, y
);
1112 dc
.DrawArc(x
+ 4*r
, y
, x
+ 2*r
, y
, x
+ 3*r
, y
);
1113 dc
.DrawArc(x
+ 5*r
, y
, x
+ 5*r
, y
, x
+ 6*r
, y
);
1116 dc
.DrawEllipticArc(x
- r
, y
, 2*r
, r
, 0, 90);
1117 dc
.DrawEllipticArc(x
+ r
, y
, 2*r
, r
, 90, 180);
1118 dc
.DrawEllipticArc(x
+ 3*r
, y
, 2*r
, r
, 180, 270);
1119 dc
.DrawEllipticArc(x
+ 5*r
, y
, 2*r
, r
, 270, 360);
1123 void MyCanvas::DrawSplines(wxDC
& dc
)
1126 dc
.DrawText(wxT("Some splines"), 10, 5);
1128 // values are hardcoded rather than randomly generated
1129 // so the output can be compared between native
1130 // implementations on platforms with different random
1134 const wxPoint
center( R
+ 20, R
+ 20 );
1135 const int angles
[7] = { 0, 10, 33, 77, 13, 145, 90 };
1136 const int radii
[5] = { 100 , 59, 85, 33, 90 };
1140 // background spline calculation
1141 unsigned int radius_pos
= 0;
1142 unsigned int angle_pos
= 0;
1144 for ( int i
= 0; i
< n
; i
++ )
1146 angle
+= angles
[ angle_pos
];
1147 int r
= R
* radii
[ radius_pos
] / 100;
1148 pts
[ i
].x
= center
.x
+ (wxCoord
)( r
* cos( M_PI
* angle
/ 180.0) );
1149 pts
[ i
].y
= center
.y
+ (wxCoord
)( r
* sin( M_PI
* angle
/ 180.0) );
1152 if ( angle_pos
>= WXSIZEOF(angles
) ) angle_pos
= 0;
1155 if ( radius_pos
>= WXSIZEOF(radii
) ) radius_pos
= 0;
1158 // background spline drawing
1159 dc
.SetPen(*wxRED_PEN
);
1160 dc
.DrawSpline(WXSIZEOF(pts
), pts
);
1162 // less detailed spline calculation
1163 wxPoint letters
[4][5];
1165 letters
[0][0] = wxPoint( 0,1); // O O
1166 letters
[0][1] = wxPoint( 1,3); // * *
1167 letters
[0][2] = wxPoint( 2,2); // * O *
1168 letters
[0][3] = wxPoint( 3,3); // * * * *
1169 letters
[0][4] = wxPoint( 4,1); // O O
1171 letters
[1][0] = wxPoint( 5,1); // O*O
1172 letters
[1][1] = wxPoint( 6,1); // *
1173 letters
[1][2] = wxPoint( 7,2); // O
1174 letters
[1][3] = wxPoint( 8,3); // *
1175 letters
[1][4] = wxPoint( 9,3); // O*O
1177 letters
[2][0] = wxPoint( 5,3); // O*O
1178 letters
[2][1] = wxPoint( 6,3); // *
1179 letters
[2][2] = wxPoint( 7,2); // O
1180 letters
[2][3] = wxPoint( 8,1); // *
1181 letters
[2][4] = wxPoint( 9,1); // O*O
1183 letters
[3][0] = wxPoint(10,0); // O O
1184 letters
[3][1] = wxPoint(11,3); // * *
1185 letters
[3][2] = wxPoint(12,1); // * O *
1186 letters
[3][3] = wxPoint(13,3); // * * * *
1187 letters
[3][4] = wxPoint(14,0); // O O
1189 const int dx
= 2 * R
/ letters
[3][4].x
;
1190 const int h
[4] = { -R
/2, 0, R
/4, R
/2 };
1192 for ( int m
= 0; m
< 4; m
++ )
1194 for ( int n
= 0; n
< 5; n
++ )
1196 letters
[m
][n
].x
= center
.x
- R
+ letters
[m
][n
].x
* dx
;
1197 letters
[m
][n
].y
= center
.y
+ h
[ letters
[m
][n
].y
];
1200 dc
.SetPen( wxPen( wxT("blue"), 1, wxDOT
) );
1201 dc
.DrawLines(5, letters
[m
]);
1202 dc
.SetPen( wxPen( wxT("black"), 4, wxSOLID
) );
1203 dc
.DrawSpline(5, letters
[m
]);
1207 dc
.DrawText(wxT("Splines not supported."), 10, 5);
1211 void MyCanvas::DrawGradients(wxDC
& dc
)
1213 static const int TEXT_HEIGHT
= 15;
1216 wxRect
r(10, 10, 50, 50);
1217 dc
.DrawText(wxT("wxRIGHT"), r
.x
, r
.y
);
1218 r
.Offset(0, TEXT_HEIGHT
);
1219 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxRIGHT
);
1221 r
.Offset(0, r
.height
+ 10);
1222 dc
.DrawText(wxT("wxLEFT"), r
.x
, r
.y
);
1223 r
.Offset(0, TEXT_HEIGHT
);
1224 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxLEFT
);
1226 r
.Offset(0, r
.height
+ 10);
1227 dc
.DrawText(wxT("wxDOWN"), r
.x
, r
.y
);
1228 r
.Offset(0, TEXT_HEIGHT
);
1229 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxDOWN
);
1231 r
.Offset(0, r
.height
+ 10);
1232 dc
.DrawText(wxT("wxUP"), r
.x
, r
.y
);
1233 r
.Offset(0, TEXT_HEIGHT
);
1234 dc
.GradientFillLinear(r
, *wxWHITE
, *wxBLUE
, wxUP
);
1236 wxRect gfr
= wxRect(r
);
1239 r
= wxRect(200, 10, 50, 50);
1240 dc
.DrawText(wxT("Blue inside"), r
.x
, r
.y
);
1241 r
.Offset(0, TEXT_HEIGHT
);
1242 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
);
1244 r
.Offset(0, r
.height
+ 10);
1245 dc
.DrawText(wxT("White inside"), r
.x
, r
.y
);
1246 r
.Offset(0, TEXT_HEIGHT
);
1247 dc
.GradientFillConcentric(r
, *wxWHITE
, *wxBLUE
);
1249 r
.Offset(0, r
.height
+ 10);
1250 dc
.DrawText(wxT("Blue in top left corner"), r
.x
, r
.y
);
1251 r
.Offset(0, TEXT_HEIGHT
);
1252 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
, wxPoint(0, 0));
1254 r
.Offset(0, r
.height
+ 10);
1255 dc
.DrawText(wxT("Blue in bottom right corner"), r
.x
, r
.y
);
1256 r
.Offset(0, TEXT_HEIGHT
);
1257 dc
.GradientFillConcentric(r
, *wxBLUE
, *wxWHITE
, wxPoint(r
.width
, r
.height
));
1259 // check that the area filled by the gradient is exactly the interior of
1263 dc
.DrawText("The interior should be filled but", r
.x
, r
.y
);
1265 dc
.DrawText(" the red border should remain visible:", r
.x
, r
.y
);
1276 dc
.SetPen(wxPen(wxColour(255, 0, 0)));
1277 dc
.DrawRectangle(r
);
1279 dc
.GradientFillLinear(r
, wxColour(0,255,0), wxColour(0,0,0), wxNORTH
);
1280 dc
.DrawRectangle(r2
);
1282 dc
.GradientFillLinear(r2
, wxColour(0,0,0), wxColour(0,255,0), wxSOUTH
);
1283 dc
.DrawRectangle(r3
);
1285 dc
.GradientFillLinear(r3
, wxColour(0,255,0), wxColour(0,0,0), wxEAST
);
1286 dc
.DrawRectangle(r4
);
1288 dc
.GradientFillLinear(r4
, wxColour(0,0,0), wxColour(0,255,0), wxWEST
);
1290 #if wxUSE_GRAPHICS_CONTEXT
1293 wxGCDC
&gdc
= (wxGCDC
&)dc
;
1294 wxGraphicsContext
*gc
= gdc
.GetGraphicsContext();
1296 wxGraphicsGradientStops stops
;
1298 gfr
.Offset(0, gfr
.height
+ 10);
1299 dc
.DrawText(wxT("Linear Gradient with Stops"), gfr
.x
, gfr
.y
);
1300 gfr
.Offset(0, TEXT_HEIGHT
);
1302 stops
= wxGraphicsGradientStops(wxColour(255,0,0), wxColour(0,0,255));
1303 stops
.Add(wxColour(255,255,0), 0.33f
);
1304 stops
.Add(wxColour(0,255,0), 0.67f
);
1306 gc
->SetBrush(gc
->CreateLinearGradientBrush(gfr
.x
, gfr
.y
,
1307 gfr
.x
+ gfr
.width
, gfr
.y
+ gfr
.height
,
1309 pth
= gc
->CreatePath();
1310 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1311 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1312 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1313 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1317 gfr
.Offset(0, gfr
.height
+ 10);
1318 dc
.DrawText(wxT("Radial Gradient with Stops"), gfr
.x
, gfr
.y
);
1319 gfr
.Offset(0, TEXT_HEIGHT
);
1321 gc
->SetBrush(gc
->CreateRadialGradientBrush(gfr
.x
+ gfr
.width
/ 2,
1322 gfr
.y
+ gfr
.height
/ 2,
1323 gfr
.x
+ gfr
.width
/ 2,
1324 gfr
.y
+ gfr
.height
/ 2,
1327 pth
= gc
->CreatePath();
1328 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1329 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1330 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1331 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1335 gfr
.Offset(0, gfr
.height
+ 10);
1336 dc
.DrawText(wxT("Linear Gradient with Stops and Gaps"), gfr
.x
, gfr
.y
);
1337 gfr
.Offset(0, TEXT_HEIGHT
);
1339 stops
= wxGraphicsGradientStops(wxColour(255,0,0), wxColour(0,0,255));
1340 stops
.Add(wxColour(255,255,0), 0.33f
);
1341 stops
.Add(wxTransparentColour
, 0.33f
);
1342 stops
.Add(wxTransparentColour
, 0.67f
);
1343 stops
.Add(wxColour(0,255,0), 0.67f
);
1345 gc
->SetBrush(gc
->CreateLinearGradientBrush(gfr
.x
, gfr
.y
+ gfr
.height
,
1346 gfr
.x
+ gfr
.width
, gfr
.y
,
1348 pth
= gc
->CreatePath();
1349 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1350 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1351 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1352 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1356 gfr
.Offset(0, gfr
.height
+ 10);
1357 dc
.DrawText(wxT("Radial Gradient with Stops and Gaps"), gfr
.x
, gfr
.y
);
1358 gfr
.Offset(0, TEXT_HEIGHT
);
1360 gc
->SetBrush(gc
->CreateRadialGradientBrush(gfr
.x
+ gfr
.width
/ 2,
1361 gfr
.y
+ gfr
.height
/ 2,
1362 gfr
.x
+ gfr
.width
/ 2,
1363 gfr
.y
+ gfr
.height
/ 2,
1366 pth
= gc
->CreatePath();
1367 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1368 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1369 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1370 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1374 gfr
.Offset(0, gfr
.height
+ 10);
1375 dc
.DrawText(wxT("Gradients with Stops and Transparency"), gfr
.x
, gfr
.y
);
1376 gfr
.Offset(0, TEXT_HEIGHT
);
1378 stops
= wxGraphicsGradientStops(wxColour(255,0,0), wxTransparentColour
);
1379 stops
.Add(wxColour(255,0,0), 0.33f
);
1380 stops
.Add(wxTransparentColour
, 0.33f
);
1381 stops
.Add(wxTransparentColour
, 0.67f
);
1382 stops
.Add(wxColour(0,0,255), 0.67f
);
1383 stops
.Add(wxColour(0,0,255), 1.0f
);
1385 pth
= gc
->CreatePath();
1386 pth
.MoveToPoint(gfr
.x
,gfr
.y
);
1387 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
);
1388 pth
.AddLineToPoint(gfr
.x
+ gfr
.width
,gfr
.y
+gfr
.height
);
1389 pth
.AddLineToPoint(gfr
.x
,gfr
.y
+gfr
.height
);
1392 gc
->SetBrush(gc
->CreateRadialGradientBrush(gfr
.x
+ gfr
.width
/ 2,
1393 gfr
.y
+ gfr
.height
/ 2,
1394 gfr
.x
+ gfr
.width
/ 2,
1395 gfr
.y
+ gfr
.height
/ 2,
1400 stops
= wxGraphicsGradientStops(wxColour(255,0,0, 128), wxColour(0,0,255, 128));
1401 stops
.Add(wxColour(255,255,0,128), 0.33f
);
1402 stops
.Add(wxColour(0,255,0,128), 0.67f
);
1404 gc
->SetBrush(gc
->CreateLinearGradientBrush(gfr
.x
, gfr
.y
,
1405 gfr
.x
+ gfr
.width
, gfr
.y
,
1409 #endif // wxUSE_GRAPHICS_CONTEXT
1412 void MyCanvas::DrawRegions(wxDC
& dc
)
1414 dc
.DrawText(wxT("You should see a red rect partly covered by a cyan one ")
1415 wxT("on the left"), 10, 5);
1416 dc
.DrawText(wxT("and 5 smileys from which 4 are partially clipped on the right"),
1417 10, 5 + dc
.GetCharHeight());
1418 dc
.DrawText(wxT("The second copy should be identical but right part of it ")
1419 wxT("should be offset by 10 pixels."),
1420 10, 5 + 2*dc
.GetCharHeight());
1422 DrawRegionsHelper(dc
, 10, true);
1423 DrawRegionsHelper(dc
, 350, false);
1426 void MyCanvas::DrawRegionsHelper(wxDC
& dc
, wxCoord x
, bool firstTime
)
1430 dc
.DestroyClippingRegion();
1431 dc
.SetBrush( *wxWHITE_BRUSH
);
1432 dc
.SetPen( *wxTRANSPARENT_PEN
);
1433 dc
.DrawRectangle( x
, y
, 310, 310 );
1435 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 270 );
1437 dc
.SetBrush( *wxRED_BRUSH
);
1438 dc
.DrawRectangle( x
, y
, 310, 310 );
1440 dc
.SetClippingRegion( x
+ 10, y
+ 10, 100, 100 );
1442 dc
.SetBrush( *wxCYAN_BRUSH
);
1443 dc
.DrawRectangle( x
, y
, 310, 310 );
1445 dc
.DestroyClippingRegion();
1447 wxRegion
region(x
+ 110, y
+ 20, 100, 270);
1448 #if !defined(__WXMOTIF__)
1450 region
.Offset(10, 10);
1452 dc
.SetDeviceClippingRegion(region
);
1454 dc
.SetBrush( *wxGREY_BRUSH
);
1455 dc
.DrawRectangle( x
, y
, 310, 310 );
1457 if (m_smile_bmp
.Ok())
1459 dc
.DrawBitmap( m_smile_bmp
, x
+ 150, y
+ 150, true );
1460 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 10, true );
1461 dc
.DrawBitmap( m_smile_bmp
, x
+ 130, y
+ 280, true );
1462 dc
.DrawBitmap( m_smile_bmp
, x
+ 100, y
+ 70, true );
1463 dc
.DrawBitmap( m_smile_bmp
, x
+ 200, y
+ 70, true );
1467 #if TEST_CAIRO_EVERYWHERE
1468 extern wxGraphicsRenderer
* gCairoRenderer
;
1471 void MyCanvas::OnPaint(wxPaintEvent
&WXUNUSED(event
))
1473 wxPaintDC
pdc(this);
1475 #if wxUSE_GRAPHICS_CONTEXT
1476 #if TEST_CAIRO_EVERYWHERE
1478 gdc
.SetGraphicsContext( gCairoRenderer
->CreateContext( pdc
) );
1482 wxDC
&dc
= m_useContext
? (wxDC
&) gdc
: (wxDC
&) pdc
;
1489 m_owner
->PrepareDC(dc
);
1491 dc
.SetBackgroundMode( m_owner
->m_backgroundMode
);
1492 if ( m_owner
->m_backgroundBrush
.Ok() )
1493 dc
.SetBackground( m_owner
->m_backgroundBrush
);
1494 if ( m_owner
->m_colourForeground
.Ok() )
1495 dc
.SetTextForeground( m_owner
->m_colourForeground
);
1496 if ( m_owner
->m_colourBackground
.Ok() )
1497 dc
.SetTextBackground( m_owner
->m_colourBackground
);
1499 if ( m_owner
->m_textureBackground
) {
1500 if ( ! m_owner
->m_backgroundBrush
.Ok() ) {
1501 wxColour
clr(0,128,0);
1502 wxBrush
b(clr
, wxSOLID
);
1503 dc
.SetBackground(b
);
1508 dc
.SetClippingRegion(100, 100, 100, 100);
1512 if ( m_owner
->m_textureBackground
)
1514 dc
.SetPen(*wxMEDIUM_GREY_PEN
);
1515 for ( int i
= 0; i
< 200; i
++ )
1516 dc
.DrawLine(0, i
*10, i
*10, 0);
1521 case File_ShowDefault
:
1525 case File_ShowCircles
:
1529 case File_ShowSplines
:
1533 case File_ShowRegions
:
1541 case File_ShowLines
:
1542 DrawTestLines( 0, 100, 0, dc
);
1543 DrawTestLines( 0, 320, 1, dc
);
1544 DrawTestLines( 0, 540, 2, dc
);
1545 DrawTestLines( 0, 760, 6, dc
);
1548 case File_ShowBrushes
:
1549 DrawTestBrushes(dc
);
1552 case File_ShowPolygons
:
1557 DrawImages(dc
, Draw_Normal
);
1560 case File_ShowMaskStretch
:
1561 DrawImages(dc
, Draw_Stretch
);
1565 DrawWithLogicalOps(dc
);
1568 #if wxUSE_GRAPHICS_CONTEXT
1569 case File_ShowAlpha
:
1572 case File_ShowGraphics
:
1573 DrawGraphics(gdc
.GetGraphicsContext());
1577 case File_ShowGradients
:
1586 void MyCanvas::OnMouseMove(wxMouseEvent
&event
)
1590 wxClientDC
dc(this);
1592 m_owner
->PrepareDC(dc
);
1594 wxPoint pos
= event
.GetPosition();
1595 long x
= dc
.DeviceToLogicalX( pos
.x
);
1596 long y
= dc
.DeviceToLogicalY( pos
.y
);
1598 str
.Printf( wxT("Current mouse position: %d,%d"), (int)x
, (int)y
);
1599 m_owner
->SetStatusText( str
);
1605 event
.GetPosition(&x
,&y
);
1606 CalcUnscrolledPosition( x
, y
, &xx
, &yy
);
1607 m_currentpoint
= wxPoint( xx
, yy
) ;
1608 wxRect
newrect ( m_anchorpoint
, m_currentpoint
) ;
1610 wxClientDC
dc( this ) ;
1613 wxDCOverlay
overlaydc( m_overlay
, &dc
);
1616 dc
.SetPen( *wxGREY_PEN
);
1617 dc
.SetBrush( wxColour( 192,192,192,64 ) );
1619 dc
.SetPen( wxPen( *wxLIGHT_GREY
, 2, wxSOLID
) );
1620 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1622 dc
.DrawRectangle( newrect
);
1626 #endif // wxUSE_STATUSBAR
1629 void MyCanvas::OnMouseDown(wxMouseEvent
&event
)
1632 event
.GetPosition(&x
,&y
);
1633 CalcUnscrolledPosition( x
, y
, &xx
, &yy
);
1634 m_anchorpoint
= wxPoint( xx
, yy
) ;
1635 m_currentpoint
= m_anchorpoint
;
1636 m_rubberBand
= true ;
1640 void MyCanvas::OnMouseUp(wxMouseEvent
&event
)
1646 wxClientDC
dc( this );
1648 wxDCOverlay
overlaydc( m_overlay
, &dc
);
1652 m_rubberBand
= false;
1655 event
.GetPosition(&x
,&y
);
1656 CalcUnscrolledPosition( x
, y
, &xx
, &yy
);
1659 str
.Printf( wxT("Rectangle selection from %d,%d to %d,%d"),
1660 m_anchorpoint
.x
, m_anchorpoint
.y
, (int)xx
, (int)yy
);
1661 wxMessageBox( str
, wxT("Rubber-Banding") );
1666 // ----------------------------------------------------------------------------
1668 // ----------------------------------------------------------------------------
1670 // the event tables connect the wxWidgets events with the functions (event
1671 // handlers) which process them. It can be also done at run-time, but for the
1672 // simple menu events like this the static method is much simpler.
1673 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
1674 EVT_MENU (File_Quit
, MyFrame::OnQuit
)
1675 EVT_MENU (File_About
, MyFrame::OnAbout
)
1676 EVT_MENU (File_Clip
, MyFrame::OnClip
)
1677 #if wxUSE_GRAPHICS_CONTEXT
1678 EVT_MENU (File_GraphicContext
, MyFrame::OnGraphicContext
)
1681 EVT_MENU_RANGE(MenuShow_First
, MenuShow_Last
, MyFrame::OnShow
)
1683 EVT_MENU_RANGE(MenuOption_First
, MenuOption_Last
, MyFrame::OnOption
)
1686 // frame constructor
1687 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
1688 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
,
1689 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
1691 // set the frame icon
1692 SetIcon(wxICON(sample
));
1694 wxMenu
*menuFile
= new wxMenu
;
1695 menuFile
->Append(File_ShowDefault
, wxT("&Default screen\tF1"));
1696 menuFile
->Append(File_ShowText
, wxT("&Text screen\tF2"));
1697 menuFile
->Append(File_ShowLines
, wxT("&Lines screen\tF3"));
1698 menuFile
->Append(File_ShowBrushes
, wxT("&Brushes screen\tF4"));
1699 menuFile
->Append(File_ShowPolygons
, wxT("&Polygons screen\tF5"));
1700 menuFile
->Append(File_ShowMask
, wxT("&Mask screen\tF6"));
1701 menuFile
->Append(File_ShowMaskStretch
, wxT("1/&2 scaled mask\tShift-F6"));
1702 menuFile
->Append(File_ShowOps
, wxT("&Raster operations screen\tF7"));
1703 menuFile
->Append(File_ShowRegions
, wxT("Re&gions screen\tF8"));
1704 menuFile
->Append(File_ShowCircles
, wxT("&Circles screen\tF9"));
1705 #if wxUSE_GRAPHICS_CONTEXT
1706 menuFile
->Append(File_ShowAlpha
, wxT("&Alpha screen\tF10"));
1708 menuFile
->Append(File_ShowSplines
, wxT("&Splines screen\tF11"));
1709 menuFile
->Append(File_ShowGradients
, wxT("&Gradients screen\tF12"));
1710 #if wxUSE_GRAPHICS_CONTEXT
1711 menuFile
->Append(File_ShowGraphics
, wxT("&Graphics screen"));
1713 menuFile
->AppendSeparator();
1714 menuFile
->AppendCheckItem(File_Clip
, wxT("&Clip\tCtrl-C"), wxT("Clip/unclip drawing"));
1715 #if wxUSE_GRAPHICS_CONTEXT
1716 menuFile
->AppendCheckItem(File_GraphicContext
, wxT("&Use GraphicContext\tCtrl-Y"), wxT("Use GraphicContext"));
1718 menuFile
->AppendSeparator();
1719 menuFile
->Append(File_About
, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
1720 menuFile
->AppendSeparator();
1721 menuFile
->Append(File_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
1723 wxMenu
*menuMapMode
= new wxMenu
;
1724 menuMapMode
->Append( MapMode_Text
, wxT("&TEXT map mode") );
1725 menuMapMode
->Append( MapMode_Lometric
, wxT("&LOMETRIC map mode") );
1726 menuMapMode
->Append( MapMode_Twips
, wxT("T&WIPS map mode") );
1727 menuMapMode
->Append( MapMode_Points
, wxT("&POINTS map mode") );
1728 menuMapMode
->Append( MapMode_Metric
, wxT("&METRIC map mode") );
1730 wxMenu
*menuUserScale
= new wxMenu
;
1731 menuUserScale
->Append( UserScale_StretchHoriz
, wxT("Stretch &horizontally\tCtrl-H") );
1732 menuUserScale
->Append( UserScale_ShrinkHoriz
, wxT("Shrin&k horizontally\tCtrl-G") );
1733 menuUserScale
->Append( UserScale_StretchVertic
, wxT("Stretch &vertically\tCtrl-V") );
1734 menuUserScale
->Append( UserScale_ShrinkVertic
, wxT("&Shrink vertically\tCtrl-W") );
1735 menuUserScale
->AppendSeparator();
1736 menuUserScale
->Append( UserScale_Restore
, wxT("&Restore to normal\tCtrl-0") );
1738 wxMenu
*menuAxis
= new wxMenu
;
1739 menuAxis
->AppendCheckItem( AxisMirror_Horiz
, wxT("Mirror horizontally\tCtrl-M") );
1740 menuAxis
->AppendCheckItem( AxisMirror_Vertic
, wxT("Mirror vertically\tCtrl-N") );
1742 wxMenu
*menuLogical
= new wxMenu
;
1743 menuLogical
->Append( LogicalOrigin_MoveDown
, wxT("Move &down\tCtrl-D") );
1744 menuLogical
->Append( LogicalOrigin_MoveUp
, wxT("Move &up\tCtrl-U") );
1745 menuLogical
->Append( LogicalOrigin_MoveLeft
, wxT("Move &right\tCtrl-L") );
1746 menuLogical
->Append( LogicalOrigin_MoveRight
, wxT("Move &left\tCtrl-R") );
1747 menuLogical
->AppendSeparator();
1748 menuLogical
->Append( LogicalOrigin_Set
, wxT("Set to (&100, 100)\tShift-Ctrl-1") );
1749 menuLogical
->Append( LogicalOrigin_Restore
, wxT("&Restore to normal\tShift-Ctrl-0") );
1751 wxMenu
*menuColour
= new wxMenu
;
1753 menuColour
->Append( Colour_TextForeground
, wxT("Text &foreground...") );
1754 menuColour
->Append( Colour_TextBackground
, wxT("Text &background...") );
1755 menuColour
->Append( Colour_Background
, wxT("Background &colour...") );
1756 #endif // wxUSE_COLOURDLG
1757 menuColour
->AppendCheckItem( Colour_BackgroundMode
, wxT("&Opaque/transparent\tCtrl-B") );
1758 menuColour
->AppendCheckItem( Colour_TextureBackgound
, wxT("Draw textured back&ground\tCtrl-T") );
1760 // now append the freshly created menu to the menu bar...
1761 wxMenuBar
*menuBar
= new wxMenuBar
;
1762 menuBar
->Append(menuFile
, wxT("&File"));
1763 menuBar
->Append(menuMapMode
, wxT("&Mode"));
1764 menuBar
->Append(menuUserScale
, wxT("&Scale"));
1765 menuBar
->Append(menuAxis
, wxT("&Axis"));
1766 menuBar
->Append(menuLogical
, wxT("&Origin"));
1767 menuBar
->Append(menuColour
, wxT("&Colours"));
1769 // ... and attach this menu bar to the frame
1770 SetMenuBar(menuBar
);
1774 SetStatusText(wxT("Welcome to wxWidgets!"));
1775 #endif // wxUSE_STATUSBAR
1777 m_mapMode
= wxMM_TEXT
;
1780 m_xLogicalOrigin
= 0;
1781 m_yLogicalOrigin
= 0;
1783 m_yAxisReversed
= false;
1784 m_backgroundMode
= wxSOLID
;
1785 m_colourForeground
= *wxBLACK
;
1786 m_colourBackground
= *wxLIGHT_GREY
;
1787 m_textureBackground
= false;
1789 m_canvas
= new MyCanvas( this );
1790 m_canvas
->SetScrollbars( 10, 10, 100, 240 );
1795 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
1797 // true is to force the frame to close
1801 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
1804 msg
.Printf( wxT("This is the about dialog of the drawing sample.\n")
1805 wxT("This sample tests various primitive drawing functions\n")
1806 wxT("(without any attempts to prevent flicker).\n")
1807 wxT("Copyright (c) Robert Roebling 1999")
1810 wxMessageBox(msg
, wxT("About Drawing"), wxOK
| wxICON_INFORMATION
, this);
1813 void MyFrame::OnClip(wxCommandEvent
& event
)
1815 m_canvas
->Clip(event
.IsChecked());
1818 #if wxUSE_GRAPHICS_CONTEXT
1819 void MyFrame::OnGraphicContext(wxCommandEvent
& event
)
1821 m_canvas
->UseGraphicContext(event
.IsChecked());
1825 void MyFrame::OnShow(wxCommandEvent
& event
)
1827 m_canvas
->ToShow(event
.GetId());
1830 void MyFrame::OnOption(wxCommandEvent
& event
)
1832 switch (event
.GetId())
1835 m_mapMode
= wxMM_TEXT
;
1837 case MapMode_Lometric
:
1838 m_mapMode
= wxMM_LOMETRIC
;
1841 m_mapMode
= wxMM_TWIPS
;
1843 case MapMode_Points
:
1844 m_mapMode
= wxMM_POINTS
;
1846 case MapMode_Metric
:
1847 m_mapMode
= wxMM_METRIC
;
1850 case LogicalOrigin_MoveDown
:
1851 m_yLogicalOrigin
+= 10;
1853 case LogicalOrigin_MoveUp
:
1854 m_yLogicalOrigin
-= 10;
1856 case LogicalOrigin_MoveLeft
:
1857 m_xLogicalOrigin
+= 10;
1859 case LogicalOrigin_MoveRight
:
1860 m_xLogicalOrigin
-= 10;
1862 case LogicalOrigin_Set
:
1864 m_yLogicalOrigin
= -100;
1866 case LogicalOrigin_Restore
:
1868 m_yLogicalOrigin
= 0;
1871 case UserScale_StretchHoriz
:
1872 m_xUserScale
*= 1.10;
1874 case UserScale_ShrinkHoriz
:
1875 m_xUserScale
/= 1.10;
1877 case UserScale_StretchVertic
:
1878 m_yUserScale
*= 1.10;
1880 case UserScale_ShrinkVertic
:
1881 m_yUserScale
/= 1.10;
1883 case UserScale_Restore
:
1888 case AxisMirror_Vertic
:
1889 m_yAxisReversed
= !m_yAxisReversed
;
1891 case AxisMirror_Horiz
:
1892 m_xAxisReversed
= !m_xAxisReversed
;
1896 case Colour_TextForeground
:
1897 m_colourForeground
= SelectColour();
1899 case Colour_TextBackground
:
1900 m_colourBackground
= SelectColour();
1902 case Colour_Background
:
1904 wxColour col
= SelectColour();
1907 m_backgroundBrush
.SetColour(col
);
1911 #endif // wxUSE_COLOURDLG
1913 case Colour_BackgroundMode
:
1914 m_backgroundMode
= m_backgroundMode
== wxSOLID
? wxTRANSPARENT
1918 case Colour_TextureBackgound
:
1919 m_textureBackground
= ! m_textureBackground
;
1927 m_canvas
->Refresh();
1930 void MyFrame::PrepareDC(wxDC
& dc
)
1932 dc
.SetLogicalOrigin( m_xLogicalOrigin
, m_yLogicalOrigin
);
1933 dc
.SetAxisOrientation( !m_xAxisReversed
, m_yAxisReversed
);
1934 dc
.SetUserScale( m_xUserScale
, m_yUserScale
);
1935 dc
.SetMapMode( m_mapMode
);
1939 wxColour
MyFrame::SelectColour()
1943 wxColourDialog
dialog(this, &data
);
1945 if ( dialog
.ShowModal() == wxID_OK
)
1947 col
= dialog
.GetColourData().GetColour();
1952 #endif // wxUSE_COLOURDLG