]> git.saurik.com Git - wxWidgets.git/blame - samples/drawing/drawing.cpp
made GetStrings() const (patch 1655975)
[wxWidgets.git] / samples / drawing / drawing.cpp
CommitLineData
aba99005 1/////////////////////////////////////////////////////////////////////////////
b11729f1 2// Name: samples/drawing/drawing.cpp
0f0c61d0 3// Purpose: shows and tests wxDC features
aba99005
RR
4// Author: Robert Roebling
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Robert Roebling
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
568708e2 19
aba99005
RR
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27// for all others, include the necessary headers (this file is usually all you
be5a51fb 28// need because it includes almost all "standard" wxWidgets headers
aba99005
RR
29#ifndef WX_PRECOMP
30 #include "wx/wx.h"
31#endif
32
0f0c61d0 33#include "wx/colordlg.h"
107a1787 34#include "wx/image.h"
389d906b 35#include "wx/artprov.h"
0f0c61d0 36
3abcf424 37#define wxTEST_GRAPHICS 1
f31a4cb2
SC
38
39#if wxTEST_GRAPHICS
40#include "wx/graphics.h"
41#if wxUSE_GRAPHICS_CONTEXT == 0
12534a36
SC
42#undef wxTEST_GRAPHICS
43#define wxTEST_GRAPHICS 0
f31a4cb2
SC
44#endif
45#else
46#undef wxUSE_GRAPHICS_CONTEXT
47#define wxUSE_GRAPHICS_CONTEXT 0
48#endif
49
aba99005
RR
50// ----------------------------------------------------------------------------
51// ressources
52// ----------------------------------------------------------------------------
568708e2 53
aba99005 54// the application icon
a11672a4 55#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
aba99005
RR
56 #include "mondrian.xpm"
57#endif
58
568708e2
VZ
59// ----------------------------------------------------------------------------
60// constants
61// ----------------------------------------------------------------------------
62
63// what do we show on screen (there are too many shapes to put them all on
64// screen simultaneously)
65enum ScreenToShow
66{
67 Show_Default,
68 Show_Text,
69 Show_Lines,
6386110d 70 Show_Brushes,
568708e2 71 Show_Polygons,
81278df2 72 Show_Mask,
bc3cedfa 73 Show_Ops,
f6bcfd97 74 Show_Regions,
b11729f1 75 Show_Circles,
213ad8e7 76 Show_Splines,
f31a4cb2
SC
77#if wxUSE_GRAPHICS_CONTEXT
78 Show_Alpha,
79#endif
213ad8e7
VZ
80 Show_Gradient,
81 Show_Max
568708e2
VZ
82};
83
84// ----------------------------------------------------------------------------
85// global variables
86// ----------------------------------------------------------------------------
87
f6bcfd97
BP
88static wxBitmap *gs_bmpNoMask = NULL,
89 *gs_bmpWithColMask = NULL,
90 *gs_bmpMask = NULL,
91 *gs_bmpWithMask = NULL,
92 *gs_bmp4 = NULL,
93 *gs_bmp4_mono = NULL,
94 *gs_bmp36 = NULL;
568708e2 95
aba99005
RR
96// ----------------------------------------------------------------------------
97// private classes
98// ----------------------------------------------------------------------------
99
100// Define a new application type, each program should derive a class from wxApp
101class MyApp : public wxApp
102{
103public:
104 // override base class virtuals
105 // ----------------------------
106
107 // this one is called on application startup and is a good place for the app
108 // initialization (doing it here and not in the ctor allows to have an error
109 // return: if OnInit() returns false, the application terminates)
110 virtual bool OnInit();
568708e2 111
f6bcfd97
BP
112 virtual int OnExit() { DeleteBitmaps(); return 0; }
113
568708e2 114protected:
f6bcfd97
BP
115 void DeleteBitmaps();
116
568708e2 117 bool LoadImages();
aba99005
RR
118};
119
b62c3631
RR
120class MyCanvas;
121
aba99005
RR
122// Define a new frame type: this is going to be our main frame
123class MyFrame : public wxFrame
124{
125public:
126 // ctor(s)
127 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
128
129 // event handlers (these functions should _not_ be virtual)
130 void OnQuit(wxCommandEvent& event);
131 void OnAbout(wxCommandEvent& event);
204dd9a7 132 void OnClip(wxCommandEvent& event);
f31a4cb2
SC
133#if wxUSE_GRAPHICS_CONTEXT
134 void OnGraphicContext(wxCommandEvent& event);
135#endif
568708e2 136 void OnShow(wxCommandEvent &event);
aba99005 137 void OnOption(wxCommandEvent &event);
aba99005 138
960a83cc 139#if wxUSE_COLOURDLG
220af862 140 wxColour SelectColour();
960a83cc 141#endif // wxUSE_COLOURDLG
220af862 142 void PrepareDC(wxDC& dc);
0f0c61d0 143
b62c3631 144 int m_backgroundMode;
1edc9f45 145 int m_textureBackground;
b62c3631
RR
146 int m_mapMode;
147 double m_xUserScale;
148 double m_yUserScale;
149 int m_xLogicalOrigin;
150 int m_yLogicalOrigin;
151 bool m_xAxisReversed,
152 m_yAxisReversed;
153 wxColour m_colourForeground, // these are _text_ colours
154 m_colourBackground;
155 wxBrush m_backgroundBrush;
156 MyCanvas *m_canvas;
aba99005
RR
157
158private:
be5a51fb 159 // any class wishing to process wxWidgets events must use this macro
aba99005
RR
160 DECLARE_EVENT_TABLE()
161};
162
b62c3631
RR
163// define a scrollable canvas for drawing onto
164class MyCanvas: public wxScrolledWindow
165{
166public:
167 MyCanvas( MyFrame *parent );
1e7fd311 168
b62c3631 169 void OnPaint(wxPaintEvent &event);
bf0c00c6 170 void OnMouseMove(wxMouseEvent &event);
4786aabd 171
dacaa6f1 172 void ToShow(ScreenToShow show) { m_show = show; Refresh(); }
568708e2 173
204dd9a7
VZ
174 // set or remove the clipping region
175 void Clip(bool clip) { m_clip = clip; Refresh(); }
f31a4cb2
SC
176#if wxUSE_GRAPHICS_CONTEXT
177 void UseGraphicContext(bool use) { m_useContext = use; Refresh(); }
178#endif
204dd9a7 179
b62c3631 180protected:
568708e2 181 void DrawTestLines( int x, int y, int width, wxDC &dc );
6386110d
VZ
182 void DrawTestPoly(wxDC& dc);
183 void DrawTestBrushes(wxDC& dc);
568708e2
VZ
184 void DrawText(wxDC& dc);
185 void DrawImages(wxDC& dc);
81278df2 186 void DrawWithLogicalOps(wxDC& dc);
f31a4cb2
SC
187#if wxUSE_GRAPHICS_CONTEXT
188 void DrawAlpha(wxDC& dc);
189#endif
bc3cedfa 190 void DrawRegions(wxDC& dc);
f6bcfd97 191 void DrawCircles(wxDC& dc);
b11729f1 192 void DrawSplines(wxDC& dc);
568708e2 193 void DrawDefault(wxDC& dc);
213ad8e7 194 void DrawGradients(wxDC& dc);
4786aabd 195
4cbcae16 196 void DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime);
8e0e4b1b 197
b62c3631 198private:
568708e2
VZ
199 MyFrame *m_owner;
200
201 ScreenToShow m_show;
0e09f76e
RR
202 wxBitmap m_smile_bmp;
203 wxIcon m_std_icon;
204dd9a7 204 bool m_clip;
f31a4cb2
SC
205#if wxUSE_GRAPHICS_CONTEXT
206 bool m_useContext ;
207#endif
568708e2 208
b62c3631
RR
209 DECLARE_EVENT_TABLE()
210};
211
aba99005
RR
212// ----------------------------------------------------------------------------
213// constants
214// ----------------------------------------------------------------------------
215
216// IDs for the controls and the menu commands
217enum
218{
219 // menu items
b11729f1
WS
220 File_Quit = wxID_EXIT,
221 File_About = wxID_ABOUT,
568708e2 222
b11729f1 223 MenuShow_First = wxID_HIGHEST,
568708e2
VZ
224 File_ShowDefault = MenuShow_First,
225 File_ShowText,
226 File_ShowLines,
6386110d 227 File_ShowBrushes,
568708e2
VZ
228 File_ShowPolygons,
229 File_ShowMask,
81278df2 230 File_ShowOps,
bc3cedfa 231 File_ShowRegions,
f6bcfd97 232 File_ShowCircles,
b11729f1 233 File_ShowSplines,
f31a4cb2
SC
234#if wxUSE_GRAPHICS_CONTEXT
235 File_ShowAlpha,
236#endif
213ad8e7
VZ
237 File_ShowGradients,
238 MenuShow_Last = File_ShowGradients,
0f0c61d0 239
204dd9a7 240 File_Clip,
f31a4cb2
SC
241#if wxUSE_GRAPHICS_CONTEXT
242 File_GraphicContext,
243#endif
204dd9a7 244
0f0c61d0
VZ
245 MenuOption_First,
246
247 MapMode_Text = MenuOption_First,
aba99005
RR
248 MapMode_Lometric,
249 MapMode_Twips,
250 MapMode_Points,
251 MapMode_Metric,
0f0c61d0 252
aba99005
RR
253 UserScale_StretchHoriz,
254 UserScale_ShrinkHoriz,
255 UserScale_StretchVertic,
256 UserScale_ShrinkVertic,
0f0c61d0
VZ
257 UserScale_Restore,
258
aba99005
RR
259 AxisMirror_Horiz,
260 AxisMirror_Vertic,
0f0c61d0 261
aba99005
RR
262 LogicalOrigin_MoveDown,
263 LogicalOrigin_MoveUp,
264 LogicalOrigin_MoveLeft,
265 LogicalOrigin_MoveRight,
fb576291
VZ
266 LogicalOrigin_Set,
267 LogicalOrigin_Restore,
0f0c61d0 268
960a83cc 269#if wxUSE_COLOURDLG
0f0c61d0
VZ
270 Colour_TextForeground,
271 Colour_TextBackground,
272 Colour_Background,
960a83cc 273#endif // wxUSE_COLOURDLG
0f0c61d0 274 Colour_BackgroundMode,
1edc9f45 275 Colour_TextureBackgound,
0f0c61d0 276
1edc9f45 277 MenuOption_Last = Colour_TextureBackgound
aba99005
RR
278};
279
280// ----------------------------------------------------------------------------
be5a51fb 281// event tables and other macros for wxWidgets
aba99005
RR
282// ----------------------------------------------------------------------------
283
aba99005 284
be5a51fb 285// Create a new application object: this macro will allow wxWidgets to create
aba99005
RR
286// the application object during program execution (it's better than using a
287// static object for many reasons) and also declares the accessor function
288// wxGetApp() which will return the reference of the right type (i.e. MyApp and
289// not wxApp)
290IMPLEMENT_APP(MyApp)
291
292// ============================================================================
293// implementation
294// ============================================================================
295
296// ----------------------------------------------------------------------------
297// the application class
298// ----------------------------------------------------------------------------
299
568708e2
VZ
300bool MyApp::LoadImages()
301{
f6bcfd97
BP
302 gs_bmpNoMask = new wxBitmap;
303 gs_bmpWithColMask = new wxBitmap;
304 gs_bmpMask = new wxBitmap;
305 gs_bmpWithMask = new wxBitmap;
306 gs_bmp4 = new wxBitmap;
307 gs_bmp4_mono = new wxBitmap;
308 gs_bmp36 = new wxBitmap;
309
568708e2 310 wxPathList pathList;
ab1ca7b3
MB
311 pathList.Add(_T("."));
312 pathList.Add(_T(".."));
568708e2 313
ab1ca7b3 314 wxString path = pathList.FindValidPath(_T("pat4.bmp"));
568708e2 315 if ( !path )
9da8feef 316 return false;
f6bcfd97 317
e1208c31 318 /* 4 colour bitmap */
f6bcfd97 319 gs_bmp4->LoadFile(path, wxBITMAP_TYPE_BMP);
e1208c31 320 /* turn into mono-bitmap */
f6bcfd97
BP
321 gs_bmp4_mono->LoadFile(path, wxBITMAP_TYPE_BMP);
322 wxMask* mask4 = new wxMask(*gs_bmp4_mono, *wxBLACK);
323 gs_bmp4_mono->SetMask(mask4);
568708e2 324
ab1ca7b3 325 path = pathList.FindValidPath(_T("pat36.bmp"));
568708e2 326 if ( !path )
9da8feef 327 return false;
f6bcfd97
BP
328 gs_bmp36->LoadFile(path, wxBITMAP_TYPE_BMP);
329 wxMask* mask36 = new wxMask(*gs_bmp36, *wxBLACK);
330 gs_bmp36->SetMask(mask36);
568708e2 331
ab1ca7b3 332 path = pathList.FindValidPath(_T("image.bmp"));
568708e2 333 if ( !path )
9da8feef 334 return false;
f6bcfd97
BP
335 gs_bmpNoMask->LoadFile(path, wxBITMAP_TYPE_BMP);
336 gs_bmpWithMask->LoadFile(path, wxBITMAP_TYPE_BMP);
337 gs_bmpWithColMask->LoadFile(path, wxBITMAP_TYPE_BMP);
568708e2 338
ab1ca7b3 339 path = pathList.FindValidPath(_T("mask.bmp"));
568708e2 340 if ( !path )
9da8feef 341 return false;
f6bcfd97 342 gs_bmpMask->LoadFile(path, wxBITMAP_TYPE_BMP);
b9de1315 343
f6bcfd97
BP
344 wxMask *mask = new wxMask(*gs_bmpMask, *wxBLACK);
345 gs_bmpWithMask->SetMask(mask);
568708e2 346
f6bcfd97
BP
347 mask = new wxMask(*gs_bmpWithColMask, *wxWHITE);
348 gs_bmpWithColMask->SetMask(mask);
568708e2 349
9da8feef 350 return true;
568708e2
VZ
351}
352
aba99005
RR
353// `Main program' equivalent: the program execution "starts" here
354bool MyApp::OnInit()
355{
45e6e6f8
VZ
356 if ( !wxApp::OnInit() )
357 return false;
358
aba99005 359 // Create the main application window
ab1ca7b3 360 MyFrame *frame = new MyFrame(_T("Drawing sample"),
b62c3631 361 wxPoint(50, 50), wxSize(550, 340));
aba99005
RR
362
363 // Show it and tell the application that it's our main window
9da8feef 364 frame->Show(true);
aba99005
RR
365 SetTopWindow(frame);
366
568708e2
VZ
367 if ( !LoadImages() )
368 {
4693b20c
MB
369 wxLogError(wxT("Can't load one of the bitmap files needed ")
370 wxT("for this sample from the current or parent ")
371 wxT("directory, please copy them there."));
568708e2
VZ
372
373 // stop here
f6bcfd97
BP
374 DeleteBitmaps();
375
9da8feef 376 return false;
568708e2
VZ
377 }
378
379 // ok, continue
9da8feef 380 return true;
aba99005
RR
381}
382
f6bcfd97
BP
383void MyApp::DeleteBitmaps()
384{
385 delete gs_bmpNoMask;
386 delete gs_bmpWithColMask;
387 delete gs_bmpMask;
388 delete gs_bmpWithMask;
389 delete gs_bmp4;
390 delete gs_bmp4_mono;
391 delete gs_bmp36;
17b898bb
VZ
392
393 gs_bmpNoMask = NULL;
394 gs_bmpWithColMask = NULL;
395 gs_bmpMask = NULL;
396 gs_bmpWithMask = NULL;
397 gs_bmp4 = NULL;
398 gs_bmp4_mono = NULL;
399 gs_bmp36 = NULL;
f6bcfd97
BP
400}
401
aba99005 402// ----------------------------------------------------------------------------
b62c3631 403// MyCanvas
aba99005
RR
404// ----------------------------------------------------------------------------
405
be5a51fb 406// the event tables connect the wxWidgets events with the functions (event
b62c3631
RR
407// handlers) which process them.
408BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
409 EVT_PAINT (MyCanvas::OnPaint)
bf0c00c6 410 EVT_MOTION (MyCanvas::OnMouseMove)
b62c3631
RR
411END_EVENT_TABLE()
412
c4218a74 413#include "smile.xpm"
0e09f76e 414
c4218a74 415MyCanvas::MyCanvas(MyFrame *parent)
9da8feef 416 : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
c4218a74 417 wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE)
b62c3631 418{
b97fa7cf 419 m_owner = parent;
568708e2 420 m_show = Show_Default;
0e09f76e 421 m_smile_bmp = wxBitmap(smile_xpm);
389d906b 422 m_std_icon = wxArtProvider::GetIcon(wxART_INFORMATION);
9da8feef 423 m_clip = false;
f31a4cb2
SC
424#if wxUSE_GRAPHICS_CONTEXT
425 m_useContext = false;
426#endif
b97fa7cf
VZ
427}
428
6386110d 429void MyCanvas::DrawTestBrushes(wxDC& dc)
b97fa7cf 430{
6386110d
VZ
431 static const wxCoord WIDTH = 200;
432 static const wxCoord HEIGHT = 80;
433
434 wxCoord x = 10,
435 y = 10;
436
437 dc.SetBrush(wxBrush(*wxGREEN, wxSOLID));
438 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
ab1ca7b3 439 dc.DrawText(_T("Solid green"), x + 10, y + 10);
6386110d
VZ
440
441 y += HEIGHT;
442 dc.SetBrush(wxBrush(*wxRED, wxCROSSDIAG_HATCH));
443 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
ab1ca7b3 444 dc.DrawText(_T("Hatched red"), x + 10, y + 10);
6386110d
VZ
445
446 y += HEIGHT;
447 dc.SetBrush(wxBrush(*gs_bmpMask));
448 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
ab1ca7b3 449 dc.DrawText(_T("Stipple mono"), x + 10, y + 10);
6386110d
VZ
450
451 y += HEIGHT;
452 dc.SetBrush(wxBrush(*gs_bmpNoMask));
453 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
ab1ca7b3 454 dc.DrawText(_T("Stipple colour"), x + 10, y + 10);
6386110d 455}
b97fa7cf 456
6386110d
VZ
457void MyCanvas::DrawTestPoly(wxDC& dc)
458{
459 wxBrush brushHatch(*wxRED, wxFDIAGONAL_HATCH);
460 dc.SetBrush(brushHatch);
461
462 wxPoint star[5];
463 star[0] = wxPoint(100, 60);
464 star[1] = wxPoint(60, 150);
465 star[2] = wxPoint(160, 100);
466 star[3] = wxPoint(40, 100);
467 star[4] = wxPoint(140, 150);
468
ab1ca7b3
MB
469 dc.DrawText(_T("You should see two (irregular) stars below, the left one ")
470 _T("hatched"), 10, 10);
471 dc.DrawText(_T("except for the central region and the right ")
472 _T("one entirely hatched"), 10, 30);
163dc80e
VZ
473 dc.DrawText(_T("The third star only has a hatched outline"), 10, 50);
474
475 dc.DrawPolygon(WXSIZEOF(star), star, 0, 30);
476 dc.DrawPolygon(WXSIZEOF(star), star, 160, 30, wxWINDING_RULE);
477
478 wxPoint star2[10];
479 star2[0] = wxPoint(0, 100);
480 star2[1] = wxPoint(-59, -81);
481 star2[2] = wxPoint(95, 31);
482 star2[3] = wxPoint(-95, 31);
483 star2[4] = wxPoint(59, -81);
484 star2[5] = wxPoint(0, 80);
485 star2[6] = wxPoint(-47, -64);
486 star2[7] = wxPoint(76, 24);
487 star2[8] = wxPoint(-76, 24);
488 star2[9] = wxPoint(47, -64);
489 int count[2] = {5, 5};
490
491 dc.DrawPolyPolygon(WXSIZEOF(count), count, star2, 450, 150);
b62c3631
RR
492}
493
1e7fd311 494void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc )
b62c3631 495{
a60b1f5d 496 dc.SetPen( wxPen( wxT("black"), width, wxSOLID) );
1e7fd311 497 dc.SetBrush( *wxRED_BRUSH );
4693b20c 498 dc.DrawText(wxString::Format(wxT("Testing lines of width %d"), width), x + 10, y - 10);
9a8c7620 499 dc.DrawRectangle( x+10, y+10, 100, 190 );
4786aabd 500
ab1ca7b3 501 dc.DrawText(_T("Solid/dot/short dash/long dash/dot dash"), x + 150, y + 10);
a60b1f5d 502 dc.SetPen( wxPen( wxT("black"), width, wxSOLID) );
696e1ea0 503 dc.DrawLine( x+20, y+20, 100, y+20 );
a60b1f5d 504 dc.SetPen( wxPen( wxT("black"), width, wxDOT) );
696e1ea0 505 dc.DrawLine( x+20, y+30, 100, y+30 );
a60b1f5d 506 dc.SetPen( wxPen( wxT("black"), width, wxSHORT_DASH) );
696e1ea0 507 dc.DrawLine( x+20, y+40, 100, y+40 );
a60b1f5d 508 dc.SetPen( wxPen( wxT("black"), width, wxLONG_DASH) );
696e1ea0 509 dc.DrawLine( x+20, y+50, 100, y+50 );
a60b1f5d 510 dc.SetPen( wxPen( wxT("black"), width, wxDOT_DASH) );
696e1ea0 511 dc.DrawLine( x+20, y+60, 100, y+60 );
1e7fd311 512
ab1ca7b3 513 dc.DrawText(_T("Misc hatches"), x + 150, y + 70);
a60b1f5d 514 dc.SetPen( wxPen( wxT("black"), width, wxBDIAGONAL_HATCH) );
696e1ea0 515 dc.DrawLine( x+20, y+70, 100, y+70 );
a60b1f5d 516 dc.SetPen( wxPen( wxT("black"), width, wxCROSSDIAG_HATCH) );
696e1ea0 517 dc.DrawLine( x+20, y+80, 100, y+80 );
a60b1f5d 518 dc.SetPen( wxPen( wxT("black"), width, wxFDIAGONAL_HATCH) );
696e1ea0 519 dc.DrawLine( x+20, y+90, 100, y+90 );
a60b1f5d 520 dc.SetPen( wxPen( wxT("black"), width, wxCROSS_HATCH) );
696e1ea0 521 dc.DrawLine( x+20, y+100, 100, y+100 );
a60b1f5d 522 dc.SetPen( wxPen( wxT("black"), width, wxHORIZONTAL_HATCH) );
696e1ea0 523 dc.DrawLine( x+20, y+110, 100, y+110 );
a60b1f5d 524 dc.SetPen( wxPen( wxT("black"), width, wxVERTICAL_HATCH) );
696e1ea0 525 dc.DrawLine( x+20, y+120, 100, y+120 );
1e7fd311 526
ab1ca7b3 527 dc.DrawText(_T("User dash"), x + 150, y + 140);
a60b1f5d 528 wxPen ud( wxT("black"), width, wxUSER_DASH );
e2a5251d
VZ
529 wxDash dash1[6];
530 dash1[0] = 8; // Long dash <---------+
531 dash1[1] = 2; // Short gap |
532 dash1[2] = 3; // Short dash |
533 dash1[3] = 2; // Short gap |
534 dash1[4] = 3; // Short dash |
535 dash1[5] = 2; // Short gap and repeat +
536 ud.SetDashes( 6, dash1 );
537 dc.SetPen( ud );
696e1ea0 538 dc.DrawLine( x+20, y+140, 100, y+140 );
e2a5251d
VZ
539 dash1[0] = 5; // Make first dash shorter
540 ud.SetDashes( 6, dash1 );
541 dc.SetPen( ud );
696e1ea0 542 dc.DrawLine( x+20, y+150, 100, y+150 );
e2a5251d
VZ
543 dash1[2] = 5; // Make second dash longer
544 ud.SetDashes( 6, dash1 );
545 dc.SetPen( ud );
696e1ea0 546 dc.DrawLine( x+20, y+160, 100, y+160 );
e2a5251d
VZ
547 dash1[4] = 5; // Make third dash longer
548 ud.SetDashes( 6, dash1 );
549 dc.SetPen( ud );
696e1ea0 550 dc.DrawLine( x+20, y+170, 100, y+170 );
b62c3631
RR
551}
552
568708e2 553void MyCanvas::DrawDefault(wxDC& dc)
b62c3631 554{
b62c3631
RR
555 // mark the origin
556 dc.DrawCircle(0, 0, 10);
f88c1a17 557
e95c145c 558#if !defined(wxMAC_USE_CORE_GRAPHICS) || !wxMAC_USE_CORE_GRAPHICS
f1e5c798
JS
559 // GetPixel and FloodFill not supported by Mac OS X CoreGraphics
560 // (FloodFill uses Blit from a non-wxMemoryDC)
f88c1a17
JS
561 //flood fill using brush, starting at 1,1 and replacing whatever colour we find there
562 dc.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID));
f1e5c798 563
f88c1a17
JS
564 wxColour tmpColour ;
565 dc.GetPixel(1,1, &tmpColour);
566 dc.FloodFill(1,1, tmpColour, wxFLOOD_SURFACE);
f1e5c798 567#endif
11fdee42 568
cd9da200
VZ
569 dc.DrawCheckMark(5, 80, 15, 15);
570 dc.DrawCheckMark(25, 80, 30, 30);
571 dc.DrawCheckMark(60, 80, 60, 60);
572
0e09f76e 573 // this is the test for "blitting bitmap into DC damages selected brush" bug
0e09f76e 574 wxCoord rectSize = m_std_icon.GetWidth() + 10;
cd9da200 575 wxCoord x = 100;
11f26ea0
VZ
576 dc.SetPen(*wxTRANSPARENT_PEN);
577 dc.SetBrush( *wxGREEN_BRUSH );
cd9da200 578 dc.DrawRectangle(x, 10, rectSize, rectSize);
9da8feef 579 dc.DrawBitmap(m_std_icon, x + 5, 15, true);
cd9da200
VZ
580 x += rectSize + 10;
581 dc.DrawRectangle(x, 10, rectSize, rectSize);
0e09f76e 582 dc.DrawIcon(m_std_icon, x + 5, 15);
cd9da200
VZ
583 x += rectSize + 10;
584 dc.DrawRectangle(x, 10, rectSize, rectSize);
11f26ea0
VZ
585
586 // test for "transparent" bitmap drawing (it intersects with the last
587 // rectangle above)
588 //dc.SetBrush( *wxTRANSPARENT_BRUSH );
d6f0a4b3 589
0e09f76e 590 if (m_smile_bmp.Ok())
9da8feef 591 dc.DrawBitmap(m_smile_bmp, x + rectSize - 20, rectSize - 10, true);
107a1787 592
ff7c6c9c 593 dc.SetBrush( *wxBLACK_BRUSH );
107a1787
RR
594 dc.DrawRectangle( 0, 160, 1000, 300 );
595
596 // draw lines
597 wxBitmap bitmap(20,70);
598 wxMemoryDC memdc;
599 memdc.SelectObject( bitmap );
600 memdc.SetBrush( *wxBLACK_BRUSH );
601 memdc.SetPen( *wxWHITE_PEN );
602 memdc.DrawRectangle(0,0,20,70);
603 memdc.DrawLine( 10,0,10,70 );
81278df2 604
d4aa3a4b 605 // to the right
4c45f240 606 wxPen pen = *wxRED_PEN;
4c45f240 607 memdc.SetPen(pen);
107a1787
RR
608 memdc.DrawLine( 10, 5,10, 5 );
609 memdc.DrawLine( 10,10,11,10 );
610 memdc.DrawLine( 10,15,12,15 );
611 memdc.DrawLine( 10,20,13,20 );
81278df2 612
d4aa3a4b
RR
613/*
614 memdc.SetPen(*wxRED_PEN);
107a1787
RR
615 memdc.DrawLine( 12, 5,12, 5 );
616 memdc.DrawLine( 12,10,13,10 );
617 memdc.DrawLine( 12,15,14,15 );
618 memdc.DrawLine( 12,20,15,20 );
d4aa3a4b 619*/
81278df2 620
107a1787
RR
621 // same to the left
622 memdc.DrawLine( 10,25,10,25 );
623 memdc.DrawLine( 10,30, 9,30 );
624 memdc.DrawLine( 10,35, 8,35 );
625 memdc.DrawLine( 10,40, 7,40 );
626
627 // XOR draw lines
d4aa3a4b 628 dc.SetPen(*wxWHITE_PEN);
107a1787
RR
629 memdc.SetLogicalFunction( wxINVERT );
630 memdc.SetPen( *wxWHITE_PEN );
631 memdc.DrawLine( 10,50,10,50 );
632 memdc.DrawLine( 10,55,11,55 );
633 memdc.DrawLine( 10,60,12,60 );
634 memdc.DrawLine( 10,65,13,65 );
81278df2 635
107a1787
RR
636 memdc.DrawLine( 12,50,12,50 );
637 memdc.DrawLine( 12,55,13,55 );
638 memdc.DrawLine( 12,60,14,60 );
639 memdc.DrawLine( 12,65,15,65 );
81278df2 640
107a1787
RR
641 memdc.SelectObject( wxNullBitmap );
642 dc.DrawBitmap( bitmap, 10, 170 );
389d906b 643 wxImage image = bitmap.ConvertToImage();
107a1787 644 image.Rescale( 60,210 );
389d906b 645 bitmap = wxBitmap(image);
107a1787 646 dc.DrawBitmap( bitmap, 50, 170 );
81278df2 647
b9de1315 648 // test the rectangle outline drawing - there should be one pixel between
ff7c6c9c
RR
649 // the rect and the lines
650 dc.SetPen(*wxWHITE_PEN);
651 dc.SetBrush( *wxTRANSPARENT_BRUSH );
ff7c6c9c 652 dc.DrawRectangle(150, 170, 49, 29);
107a1787 653 dc.DrawRectangle(200, 170, 49, 29);
ff7c6c9c 654 dc.SetPen(*wxWHITE_PEN);
107a1787
RR
655 dc.DrawLine(250, 210, 250, 170);
656 dc.DrawLine(260, 200, 150, 200);
b9de1315
VZ
657
658 // test the rectangle filled drawing - there should be one pixel between
ff7c6c9c
RR
659 // the rect and the lines
660 dc.SetPen(*wxTRANSPARENT_PEN);
661 dc.SetBrush( *wxWHITE_BRUSH );
662 dc.DrawRectangle(300, 170, 49, 29);
568708e2 663 dc.DrawRectangle(350, 170, 49, 29);
ff7c6c9c 664 dc.SetPen(*wxWHITE_PEN);
b9de1315
VZ
665 dc.DrawLine(400, 170, 400, 210);
666 dc.DrawLine(300, 200, 410, 200);
667
3d2d8da1
RR
668 // a few more tests of this kind
669 dc.SetPen(*wxRED_PEN);
670 dc.SetBrush( *wxWHITE_BRUSH );
671 dc.DrawRectangle(300, 220, 1, 1);
672 dc.DrawRectangle(310, 220, 2, 2);
673 dc.DrawRectangle(320, 220, 3, 3);
674 dc.DrawRectangle(330, 220, 4, 4);
675
676 dc.SetPen(*wxTRANSPARENT_PEN);
677 dc.SetBrush( *wxWHITE_BRUSH );
678 dc.DrawRectangle(300, 230, 1, 1);
679 dc.DrawRectangle(310, 230, 2, 2);
680 dc.DrawRectangle(320, 230, 3, 3);
681 dc.DrawRectangle(330, 230, 4, 4);
682
b9de1315
VZ
683 // and now for filled rect with outline
684 dc.SetPen(*wxRED_PEN);
685 dc.SetBrush( *wxWHITE_BRUSH );
686 dc.DrawRectangle(500, 170, 49, 29);
687 dc.DrawRectangle(550, 170, 49, 29);
688 dc.SetPen(*wxWHITE_PEN);
689 dc.DrawLine(600, 170, 600, 210);
690 dc.DrawLine(500, 200, 610, 200);
691
692 // test the rectangle outline drawing - there should be one pixel between
ff7c6c9c
RR
693 // the rect and the lines
694 dc.SetPen(*wxWHITE_PEN);
695 dc.SetBrush( *wxTRANSPARENT_BRUSH );
ff7c6c9c 696 dc.DrawRoundedRectangle(150, 270, 49, 29, 6);
107a1787 697 dc.DrawRoundedRectangle(200, 270, 49, 29, 6);
ff7c6c9c 698 dc.SetPen(*wxWHITE_PEN);
107a1787
RR
699 dc.DrawLine(250, 270, 250, 310);
700 dc.DrawLine(150, 300, 260, 300);
b9de1315
VZ
701
702 // test the rectangle filled drawing - there should be one pixel between
ff7c6c9c
RR
703 // the rect and the lines
704 dc.SetPen(*wxTRANSPARENT_PEN);
705 dc.SetBrush( *wxWHITE_BRUSH );
706 dc.DrawRoundedRectangle(300, 270, 49, 29, 6);
707 dc.DrawRoundedRectangle(350, 270, 49, 29, 6);
708 dc.SetPen(*wxWHITE_PEN);
b9de1315
VZ
709 dc.DrawLine(400, 270, 400, 310);
710 dc.DrawLine(300, 300, 410, 300);
ff7c6c9c 711
b14c14ff
JS
712 // Added by JACS to demonstrate bizarre behaviour.
713 // With a size of 70, we get a missing red RHS,
3103e8a9 714 // and the height is too small, so we get yellow
b14c14ff
JS
715 // showing. With a size of 40, it draws as expected:
716 // it just shows a white rectangle with red outline.
717 int totalWidth = 70;
718 int totalHeight = 70;
719 wxBitmap bitmap2(totalWidth, totalHeight);
720
721 wxMemoryDC memdc2;
722 memdc2.SelectObject(bitmap2);
723
925e9792
WS
724 wxColour clr(255, 255, 0);
725 wxBrush yellowBrush(clr, wxSOLID);
d6f0a4b3
JS
726 memdc2.SetBackground(yellowBrush);
727 memdc2.Clear();
b14c14ff 728
925e9792 729 wxPen yellowPen(clr, 1, wxSOLID);
b14c14ff
JS
730
731 // Now draw a white rectangle with red outline. It should
732 // entirely eclipse the yellow background.
733 memdc2.SetPen(*wxRED_PEN);
734 memdc2.SetBrush(*wxWHITE_BRUSH);
735
736 memdc2.DrawRectangle(0, 0, totalWidth, totalHeight);
737
b14c14ff
JS
738 memdc2.SetPen(wxNullPen);
739 memdc2.SetBrush(wxNullBrush);
cd9da200 740 memdc2.SelectObject(wxNullBitmap);
b14c14ff
JS
741
742 dc.DrawBitmap(bitmap2, 500, 270);
d6f0a4b3
JS
743
744 // Repeat, but draw directly on dc
745 // Draw a yellow rectangle filling the bitmap
746
747 x = 600; int y = 270;
748 dc.SetPen(yellowPen);
749 dc.SetBrush(yellowBrush);
750 dc.DrawRectangle(x, y, totalWidth, totalHeight);
751
752 // Now draw a white rectangle with red outline. It should
753 // entirely eclipse the yellow background.
754 dc.SetPen(*wxRED_PEN);
755 dc.SetBrush(*wxWHITE_BRUSH);
756
757 dc.DrawRectangle(x, y, totalWidth, totalHeight);
568708e2
VZ
758}
759
760void MyCanvas::DrawText(wxDC& dc)
761{
9a8c7620 762 // set underlined font for testing
9da8feef 763 dc.SetFont( wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, true) );
ab1ca7b3
MB
764 dc.DrawText( _T("This is text"), 110, 10 );
765 dc.DrawRotatedText( _T("That is text"), 20, 10, -45 );
9a8c7620 766
4770df95
VZ
767 // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
768 // under Win9x (it is not TrueType)
769 dc.SetFont( *wxSWISS_FONT );
b62c3631 770
696e1ea0 771 wxString text;
f6bcfd97 772 dc.SetBackgroundMode(wxTRANSPARENT);
696e1ea0
VZ
773
774 for ( int n = -180; n < 180; n += 30 )
775 {
4693b20c 776 text.Printf(wxT(" %d rotated text"), n);
696e1ea0
VZ
777 dc.DrawRotatedText(text , 400, 400, n);
778 }
95724b1a 779
196c87f4 780 dc.SetFont( wxFont( 18, wxSWISS, wxNORMAL, wxNORMAL ) );
c45a644e 781
ab1ca7b3 782 dc.DrawText( _T("This is Swiss 18pt text."), 110, 40 );
c45a644e
RR
783
784 long length;
785 long height;
786 long descent;
ab1ca7b3 787 dc.GetTextExtent( _T("This is Swiss 18pt text."), &length, &height, &descent );
4693b20c 788 text.Printf( wxT("Dimensions are length %ld, height %ld, descent %ld"), length, height, descent );
c45a644e
RR
789 dc.DrawText( text, 110, 80 );
790
4693b20c 791 text.Printf( wxT("CharHeight() returns: %d"), dc.GetCharHeight() );
c45a644e
RR
792 dc.DrawText( text, 110, 120 );
793
568708e2 794 dc.DrawRectangle( 100, 40, 4, height );
f6bcfd97
BP
795
796 // test the logical function effect
797 wxCoord y = 150;
798 dc.SetLogicalFunction(wxINVERT);
ab1ca7b3 799 dc.DrawText( _T("There should be no text below"), 110, 150 );
f6bcfd97
BP
800 dc.DrawRectangle( 110, y, 100, height );
801
802 // twice drawn inverted should result in invisible
803 y += height;
ab1ca7b3 804 dc.DrawText( _T("Invisible text"), 110, y );
f6bcfd97 805 dc.DrawRectangle( 110, y, 100, height );
ab1ca7b3 806 dc.DrawText( _T("Invisible text"), 110, y );
f6bcfd97
BP
807 dc.DrawRectangle( 110, y, 100, height );
808 dc.SetLogicalFunction(wxCOPY);
809
810 y += height;
811 dc.DrawRectangle( 110, y, 100, height );
ab1ca7b3 812 dc.DrawText( _T("Visible text"), 110, y );
568708e2
VZ
813}
814
81278df2 815static const struct
568708e2 816{
81278df2
VZ
817 const wxChar *name;
818 int rop;
819} rasterOperations[] =
820{
4693b20c
MB
821 { wxT("wxAND"), wxAND },
822 { wxT("wxAND_INVERT"), wxAND_INVERT },
823 { wxT("wxAND_REVERSE"), wxAND_REVERSE },
824 { wxT("wxCLEAR"), wxCLEAR },
825 { wxT("wxCOPY"), wxCOPY },
826 { wxT("wxEQUIV"), wxEQUIV },
827 { wxT("wxINVERT"), wxINVERT },
828 { wxT("wxNAND"), wxNAND },
829 { wxT("wxNO_OP"), wxNO_OP },
830 { wxT("wxOR"), wxOR },
831 { wxT("wxOR_INVERT"), wxOR_INVERT },
832 { wxT("wxOR_REVERSE"), wxOR_REVERSE },
833 { wxT("wxSET"), wxSET },
834 { wxT("wxSRC_INVERT"), wxSRC_INVERT },
835 { wxT("wxXOR"), wxXOR },
81278df2 836};
568708e2 837
81278df2
VZ
838void MyCanvas::DrawImages(wxDC& dc)
839{
ab1ca7b3 840 dc.DrawText(_T("original image"), 0, 0);
f6bcfd97 841 dc.DrawBitmap(*gs_bmpNoMask, 0, 20, 0);
ab1ca7b3 842 dc.DrawText(_T("with colour mask"), 0, 100);
9da8feef 843 dc.DrawBitmap(*gs_bmpWithColMask, 0, 120, true);
ab1ca7b3 844 dc.DrawText(_T("the mask image"), 0, 200);
f6bcfd97 845 dc.DrawBitmap(*gs_bmpMask, 0, 220, 0);
ab1ca7b3 846 dc.DrawText(_T("masked image"), 0, 300);
9da8feef 847 dc.DrawBitmap(*gs_bmpWithMask, 0, 320, true);
568708e2 848
f6bcfd97
BP
849 int cx = gs_bmpWithColMask->GetWidth(),
850 cy = gs_bmpWithColMask->GetHeight();
568708e2
VZ
851
852 wxMemoryDC memDC;
853 for ( size_t n = 0; n < WXSIZEOF(rasterOperations); n++ )
854 {
855 wxCoord x = 120 + 150*(n%4),
856 y = 20 + 100*(n/4);
4786aabd 857
568708e2 858 dc.DrawText(rasterOperations[n].name, x, y - 20);
f6bcfd97 859 memDC.SelectObject(*gs_bmpWithColMask);
9da8feef 860 dc.Blit(x, y, cx, cy, &memDC, 0, 0, rasterOperations[n].rop, true);
568708e2
VZ
861 }
862}
863
81278df2
VZ
864void MyCanvas::DrawWithLogicalOps(wxDC& dc)
865{
866 static const wxCoord w = 60;
867 static const wxCoord h = 60;
868
869 // reuse the text colour here
870 dc.SetPen(wxPen(m_owner->m_colourForeground, 1, wxSOLID));
11f26ea0 871 dc.SetBrush(*wxTRANSPARENT_BRUSH);
81278df2 872
5888ef1e
VZ
873 size_t n;
874 for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
81278df2
VZ
875 {
876 wxCoord x = 20 + 150*(n%4),
877 y = 20 + 100*(n/4);
878
879 dc.DrawText(rasterOperations[n].name, x, y - 20);
880 dc.SetLogicalFunction(rasterOperations[n].rop);
11f26ea0 881 dc.DrawRectangle(x, y, w, h);
81278df2
VZ
882 dc.DrawLine(x, y, x + w, y + h);
883 dc.DrawLine(x + w, y, x, y + h);
884 }
c1d139da
GRG
885
886 // now some filled rectangles
887 dc.SetBrush(wxBrush(m_owner->m_colourForeground, wxSOLID));
888
5888ef1e 889 for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
c1d139da
GRG
890 {
891 wxCoord x = 20 + 150*(n%4),
892 y = 500 + 100*(n/4);
893
894 dc.DrawText(rasterOperations[n].name, x, y - 20);
895 dc.SetLogicalFunction(rasterOperations[n].rop);
896 dc.DrawRectangle(x, y, w, h);
897 }
81278df2
VZ
898}
899
f31a4cb2 900#if wxUSE_GRAPHICS_CONTEXT
ad0b4329
RR
901#ifdef __WXGTK20__
902void MyCanvas::DrawAlpha(wxDC& no_dc)
903#else
f31a4cb2 904void MyCanvas::DrawAlpha(wxDC& dc)
ad0b4329 905#endif
f31a4cb2 906{
ad0b4329
RR
907#ifdef __WXGTK__
908 wxGCDC dc( this );
909 PrepareDC( dc );
910#endif
911
f31a4cb2
SC
912 wxDouble margin = 20 ;
913 wxDouble width = 180 ;
914 wxDouble radius = 30 ;
915
916 dc.SetPen( wxPen( wxColour( 128, 0, 0, 255 ),12, wxSOLID));
917 dc.SetBrush( wxBrush( wxColour( 255, 0, 0, 255),wxSOLID));
918
919 wxRect r(margin,margin+width*0.66,width,width) ;
920
921 dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
922
923 dc.SetPen( wxPen( wxColour( 0, 0, 128, 255 ),12, wxSOLID));
924 dc.SetBrush( wxBrush( wxColour( 0, 0, 255, 255),wxSOLID));
925
926 r.Offset( width * 0.8 , - width * 0.66 ) ;
927
928 dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
929
930 dc.SetPen( wxPen( wxColour( 128, 128, 0, 255 ),12, wxSOLID));
931 dc.SetBrush( wxBrush( wxColour( 192, 192, 0, 255),wxSOLID));
932
933 r.Offset( width * 0.8 , width *0.5 ) ;
934
935 dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
936
937 dc.SetPen( *wxTRANSPARENT_PEN ) ;
938 dc.SetBrush( wxBrush( wxColour(255,255,128,128) ) );
939 dc.DrawRoundedRectangle( 0 , margin + width / 2 , width * 3 , 100 , radius) ;
ad0b4329
RR
940
941 dc.SetTextForeground( wxColour(255,255,0,128) );
942 dc.SetFont( wxFont( 40, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_NORMAL ) );
943 dc.DrawText( wxT("Hello!"), 120, 80 );
f31a4cb2
SC
944}
945
946#endif
947
f6bcfd97
BP
948void MyCanvas::DrawCircles(wxDC& dc)
949{
950 int x = 100,
951 y = 100,
952 r = 20;
953
d9d2dcd8
RR
954 dc.SetPen( *wxRED_PEN );
955 dc.SetBrush( *wxGREEN_BRUSH );
956
957 dc.DrawText(_T("Some circles"), 0, y);
958 dc.DrawCircle(x, y, r);
959 dc.DrawCircle(x + 2*r, y, r);
960 dc.DrawCircle(x + 4*r, y, r);
961
962 y += 2*r;
963 dc.DrawText(_T("And ellipses"), 0, y);
964 dc.DrawEllipse(x - r, y, 2*r, r);
965 dc.DrawEllipse(x + r, y, 2*r, r);
966 dc.DrawEllipse(x + 3*r, y, 2*r, r);
967
968 y += 2*r;
969 dc.DrawText(_T("And arcs"), 0, y);
970 dc.DrawArc(x - r, y, x + r, y, x, y);
971 dc.DrawArc(x + 4*r, y, x + 2*r, y, x + 3*r, y);
972 dc.DrawArc(x + 5*r, y, x + 5*r, y, x + 6*r, y);
973
974 y += 2*r;
975 dc.DrawEllipticArc(x - r, y, 2*r, r, 0, 90);
976 dc.DrawEllipticArc(x + r, y, 2*r, r, 90, 180);
977 dc.DrawEllipticArc(x + 3*r, y, 2*r, r, 180, 270);
978 dc.DrawEllipticArc(x + 5*r, y, 2*r, r, 270, 360);
979
980 // same as above, just transparent brush
981
982 dc.SetPen( *wxRED_PEN );
983 dc.SetBrush( *wxTRANSPARENT_BRUSH );
984
985 y += 2*r;
ab1ca7b3 986 dc.DrawText(_T("Some circles"), 0, y);
f6bcfd97
BP
987 dc.DrawCircle(x, y, r);
988 dc.DrawCircle(x + 2*r, y, r);
989 dc.DrawCircle(x + 4*r, y, r);
990
991 y += 2*r;
ab1ca7b3 992 dc.DrawText(_T("And ellipses"), 0, y);
f6bcfd97
BP
993 dc.DrawEllipse(x - r, y, 2*r, r);
994 dc.DrawEllipse(x + r, y, 2*r, r);
995 dc.DrawEllipse(x + 3*r, y, 2*r, r);
996
997 y += 2*r;
ab1ca7b3 998 dc.DrawText(_T("And arcs"), 0, y);
f6bcfd97
BP
999 dc.DrawArc(x - r, y, x + r, y, x, y);
1000 dc.DrawArc(x + 4*r, y, x + 2*r, y, x + 3*r, y);
1001 dc.DrawArc(x + 5*r, y, x + 5*r, y, x + 6*r, y);
1002
1003 y += 2*r;
1004 dc.DrawEllipticArc(x - r, y, 2*r, r, 0, 90);
1005 dc.DrawEllipticArc(x + r, y, 2*r, r, 90, 180);
1006 dc.DrawEllipticArc(x + 3*r, y, 2*r, r, 180, 270);
1007 dc.DrawEllipticArc(x + 5*r, y, 2*r, r, 270, 360);
d9d2dcd8 1008
f6bcfd97
BP
1009}
1010
b11729f1
WS
1011void MyCanvas::DrawSplines(wxDC& dc)
1012{
1013#if wxUSE_SPLINES
1014 dc.DrawText(_T("Some splines"), 10, 5);
1015
1016 // values are hardcoded rather than randomly generated
1017 // so the output can be compared between native
1018 // implementations on platforms with different random
1019 // generators
1020
1021 const int R = 300;
1022 const wxPoint center( R + 20, R + 20 );
1023 const int angles[7] = { 0, 10, 33, 77, 13, 145, 90 };
1024 const int radii[5] = { 100 , 59, 85, 33, 90 };
1025 const int n = 200;
1026 wxPoint pts[n];
1027
1028 // background spline calculation
1029 unsigned int radius_pos = 0;
1030 unsigned int angle_pos = 0;
1031 int angle = 0;
1032 for ( int i = 0; i < n; i++ )
1033 {
1034 angle += angles[ angle_pos ];
1035 int r = R * radii[ radius_pos ] / 100;
1036 pts[ i ].x = center.x + (wxCoord)( r * cos( M_PI * angle / 180.0) );
1037 pts[ i ].y = center.y + (wxCoord)( r * sin( M_PI * angle / 180.0) );
1038
1039 angle_pos++;
1040 if ( angle_pos >= WXSIZEOF(angles) ) angle_pos = 0;
1041
1042 radius_pos++;
1043 if ( radius_pos >= WXSIZEOF(radii) ) radius_pos = 0;
1044 }
1045
1046 // background spline drawing
1047 dc.SetPen(*wxRED_PEN);
1048 dc.DrawSpline(WXSIZEOF(pts), pts);
1049
1050 // less detailed spline calculation
1051 wxPoint letters[4][5];
1052 // w
1053 letters[0][0] = wxPoint( 0,1); // O O
1054 letters[0][1] = wxPoint( 1,3); // * *
1055 letters[0][2] = wxPoint( 2,2); // * O *
1056 letters[0][3] = wxPoint( 3,3); // * * * *
1057 letters[0][4] = wxPoint( 4,1); // O O
1058 // x1
1059 letters[1][0] = wxPoint( 5,1); // O*O
1060 letters[1][1] = wxPoint( 6,1); // *
1061 letters[1][2] = wxPoint( 7,2); // O
1062 letters[1][3] = wxPoint( 8,3); // *
1063 letters[1][4] = wxPoint( 9,3); // O*O
1064 // x2
1065 letters[2][0] = wxPoint( 5,3); // O*O
1066 letters[2][1] = wxPoint( 6,3); // *
1067 letters[2][2] = wxPoint( 7,2); // O
1068 letters[2][3] = wxPoint( 8,1); // *
1069 letters[2][4] = wxPoint( 9,1); // O*O
1070 // W
1071 letters[3][0] = wxPoint(10,0); // O O
1072 letters[3][1] = wxPoint(11,3); // * *
1073 letters[3][2] = wxPoint(12,1); // * O *
1074 letters[3][3] = wxPoint(13,3); // * * * *
1075 letters[3][4] = wxPoint(14,0); // O O
1076
1077 const int dx = 2 * R / letters[3][4].x;
1078 const int h[4] = { -R/2, 0, R/4, R/2 };
1079
1080 for ( int m = 0; m < 4; m++ )
1081 {
1082 for ( int n = 0; n < 5; n++ )
1083 {
1084 letters[m][n].x = center.x - R + letters[m][n].x * dx;
1085 letters[m][n].y = center.y + h[ letters[m][n].y ];
1086 }
1087
1088 dc.SetPen( wxPen( wxT("blue"), 1, wxDOT) );
1089 dc.DrawLines(5, letters[m]);
1090 dc.SetPen( wxPen( wxT("black"), 4, wxSOLID) );
1091 dc.DrawSpline(5, letters[m]);
1092 }
1093
1094#else
1095 dc.DrawText(_T("Splines not supported."), 10, 5);
1096#endif
1097}
1098
213ad8e7
VZ
1099void MyCanvas::DrawGradients(wxDC& dc)
1100{
2c8f21f8
VZ
1101 static const int TEXT_HEIGHT = 15;
1102
213ad8e7 1103 // LHS: linear
2c8f21f8
VZ
1104 wxRect r(10, 10, 50, 50);
1105 dc.DrawText(_T("wxRIGHT"), r.x, r.y);
1106 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1107 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxRIGHT);
1108
2c8f21f8
VZ
1109 r.Offset(0, r.height + 10);
1110 dc.DrawText(_T("wxLEFT"), r.x, r.y);
1111 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1112 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxLEFT);
1113
2c8f21f8
VZ
1114 r.Offset(0, r.height + 10);
1115 dc.DrawText(_T("wxDOWN"), r.x, r.y);
1116 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1117 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxDOWN);
1118
2c8f21f8
VZ
1119 r.Offset(0, r.height + 10);
1120 dc.DrawText(_T("wxUP"), r.x, r.y);
1121 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1122 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxUP);
1123
1124
1125 // RHS: concentric
2c8f21f8
VZ
1126 r = wxRect(200, 10, 50, 50);
1127 dc.DrawText(_T("Blue inside"), r.x, r.y);
1128 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1129 dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE);
1130
2c8f21f8
VZ
1131 r.Offset(0, r.height + 10);
1132 dc.DrawText(_T("White inside"), r.x, r.y);
1133 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1134 dc.GradientFillConcentric(r, *wxWHITE, *wxBLUE);
1135
2c8f21f8
VZ
1136 r.Offset(0, r.height + 10);
1137 dc.DrawText(_T("Blue in top left corner"), r.x, r.y);
1138 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1139 dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE, wxPoint(0, 0));
1140
2c8f21f8
VZ
1141 r.Offset(0, r.height + 10);
1142 dc.DrawText(_T("Blue in bottom right corner"), r.x, r.y);
1143 r.Offset(0, TEXT_HEIGHT);
1144 dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE, wxPoint(r.width, r.height));
213ad8e7
VZ
1145}
1146
bc3cedfa
RR
1147void MyCanvas::DrawRegions(wxDC& dc)
1148{
ab1ca7b3
MB
1149 dc.DrawText(_T("You should see a red rect partly covered by a cyan one ")
1150 _T("on the left"), 10, 5);
1151 dc.DrawText(_T("and 5 smileys from which 4 are partially clipped on the right"),
8e0e4b1b 1152 10, 5 + dc.GetCharHeight());
ab1ca7b3
MB
1153 dc.DrawText(_T("The second copy should be identical but right part of it ")
1154 _T("should be offset by 10 pixels."),
4cbcae16 1155 10, 5 + 2*dc.GetCharHeight());
8e0e4b1b 1156
9da8feef
WS
1157 DrawRegionsHelper(dc, 10, true);
1158 DrawRegionsHelper(dc, 350, false);
8e0e4b1b 1159}
c4218a74 1160
4cbcae16 1161void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime)
8e0e4b1b 1162{
4cbcae16
VZ
1163 wxCoord y = 100;
1164
8e0e4b1b 1165 dc.DestroyClippingRegion();
bc3cedfa
RR
1166 dc.SetBrush( *wxWHITE_BRUSH );
1167 dc.SetPen( *wxTRANSPARENT_PEN );
4cbcae16 1168 dc.DrawRectangle( x, y, 310, 310 );
c4218a74 1169
4cbcae16 1170 dc.SetClippingRegion( x + 10, y + 10, 100, 270 );
c4218a74 1171
bc3cedfa 1172 dc.SetBrush( *wxRED_BRUSH );
4cbcae16 1173 dc.DrawRectangle( x, y, 310, 310 );
c4218a74 1174
4cbcae16 1175 dc.SetClippingRegion( x + 10, y + 10, 100, 100 );
993f97ee 1176
993f97ee 1177 dc.SetBrush( *wxCYAN_BRUSH );
4cbcae16
VZ
1178 dc.DrawRectangle( x, y, 310, 310 );
1179
1180 dc.DestroyClippingRegion();
1181
1182 wxRegion region(x + 110, y + 20, 100, 270);
13a2eea0 1183#if !defined(__WXMOTIF__) && !defined(__WXMAC__)
4cbcae16
VZ
1184 if ( !firstTime )
1185 region.Offset(10, 10);
4cae9a20 1186#endif
4cbcae16 1187 dc.SetClippingRegion(region);
c4218a74 1188
bc3cedfa 1189 dc.SetBrush( *wxGREY_BRUSH );
4cbcae16 1190 dc.DrawRectangle( x, y, 310, 310 );
c4218a74 1191
5d25c050
RR
1192 if (m_smile_bmp.Ok())
1193 {
9da8feef
WS
1194 dc.DrawBitmap( m_smile_bmp, x + 150, y + 150, true );
1195 dc.DrawBitmap( m_smile_bmp, x + 130, y + 10, true );
1196 dc.DrawBitmap( m_smile_bmp, x + 130, y + 280, true );
1197 dc.DrawBitmap( m_smile_bmp, x + 100, y + 70, true );
1198 dc.DrawBitmap( m_smile_bmp, x + 200, y + 70, true );
5d25c050 1199 }
bc3cedfa
RR
1200}
1201
568708e2
VZ
1202void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
1203{
f31a4cb2
SC
1204 wxPaintDC pdc(this);
1205
1206#if wxUSE_GRAPHICS_CONTEXT
1207 wxGCDC gdc( pdc ) ;
1208 wxDC &dc = m_useContext ? (wxDC&) gdc : (wxDC&) pdc ;
1209#else
1210 wxDC &dc = pdc ;
1211#endif
1212
568708e2 1213 PrepareDC(dc);
c4218a74 1214
568708e2
VZ
1215 m_owner->PrepareDC(dc);
1216
1217 dc.SetBackgroundMode( m_owner->m_backgroundMode );
1218 if ( m_owner->m_backgroundBrush.Ok() )
1219 dc.SetBackground( m_owner->m_backgroundBrush );
1220 if ( m_owner->m_colourForeground.Ok() )
1221 dc.SetTextForeground( m_owner->m_colourForeground );
1222 if ( m_owner->m_colourBackground.Ok() )
1223 dc.SetTextBackground( m_owner->m_colourBackground );
4786aabd 1224
1edc9f45 1225 if ( m_owner->m_textureBackground) {
047473c9 1226 if ( ! m_owner->m_backgroundBrush.Ok() ) {
925e9792
WS
1227 wxColour clr(0,128,0);
1228 wxBrush b(clr, wxSOLID);
1edc9f45
RD
1229 dc.SetBackground(b);
1230 }
047473c9
RD
1231 }
1232
204dd9a7
VZ
1233 if ( m_clip )
1234 dc.SetClippingRegion(100, 100, 100, 100);
1235
e1208c31 1236 dc.Clear();
1edc9f45 1237
204dd9a7
VZ
1238 if ( m_owner->m_textureBackground )
1239 {
1edc9f45 1240 dc.SetPen(*wxMEDIUM_GREY_PEN);
204dd9a7 1241 for ( int i = 0; i < 200; i++ )
1edc9f45
RD
1242 dc.DrawLine(0, i*10, i*10, 0);
1243 }
1244
568708e2
VZ
1245 switch ( m_show )
1246 {
1247 case Show_Default:
1248 DrawDefault(dc);
1249 break;
1e7fd311 1250
f6bcfd97
BP
1251 case Show_Circles:
1252 DrawCircles(dc);
1253 break;
1254
b11729f1
WS
1255 case Show_Splines:
1256 DrawSplines(dc);
1257 break;
1258
bc3cedfa
RR
1259 case Show_Regions:
1260 DrawRegions(dc);
1261 break;
1262
568708e2
VZ
1263 case Show_Text:
1264 DrawText(dc);
1265 break;
1e7fd311 1266
568708e2
VZ
1267 case Show_Lines:
1268 DrawTestLines( 0, 100, 0, dc );
f6bcfd97
BP
1269 DrawTestLines( 0, 320, 1, dc );
1270 DrawTestLines( 0, 540, 2, dc );
1271 DrawTestLines( 0, 760, 6, dc );
568708e2 1272 break;
1e7fd311 1273
6386110d
VZ
1274 case Show_Brushes:
1275 DrawTestBrushes(dc);
1276 break;
1277
568708e2 1278 case Show_Polygons:
6386110d 1279 DrawTestPoly(dc);
568708e2 1280 break;
1e7fd311 1281
568708e2
VZ
1282 case Show_Mask:
1283 DrawImages(dc);
1284 break;
81278df2
VZ
1285
1286 case Show_Ops:
1287 DrawWithLogicalOps(dc);
1288 break;
f31a4cb2
SC
1289
1290#if wxUSE_GRAPHICS_CONTEXT
1291 case Show_Alpha:
1292 DrawAlpha(dc);
1293 break;
1294#endif
213ad8e7
VZ
1295
1296 case Show_Gradient:
1297 DrawGradients(dc);
1298 break;
e95c145c
WS
1299
1300 default:
1301 break;
568708e2 1302 }
b62c3631
RR
1303}
1304
bf0c00c6
RR
1305void MyCanvas::OnMouseMove(wxMouseEvent &event)
1306{
960a83cc 1307#if wxUSE_STATUSBAR
bf0c00c6
RR
1308 wxClientDC dc(this);
1309 PrepareDC(dc);
1310 m_owner->PrepareDC(dc);
1311
1312 wxPoint pos = event.GetPosition();
1313 long x = dc.DeviceToLogicalX( pos.x );
1314 long y = dc.DeviceToLogicalY( pos.y );
1315 wxString str;
4693b20c 1316 str.Printf( wxT("Current mouse position: %d,%d"), (int)x, (int)y );
bf0c00c6 1317 m_owner->SetStatusText( str );
960a83cc
WS
1318#else
1319 wxUnusedVar(event);
1320#endif // wxUSE_STATUSBAR
bf0c00c6
RR
1321}
1322
b62c3631
RR
1323// ----------------------------------------------------------------------------
1324// MyFrame
1325// ----------------------------------------------------------------------------
1326
be5a51fb 1327// the event tables connect the wxWidgets events with the functions (event
b62c3631
RR
1328// handlers) which process them. It can be also done at run-time, but for the
1329// simple menu events like this the static method is much simpler.
1330BEGIN_EVENT_TABLE(MyFrame, wxFrame)
568708e2
VZ
1331 EVT_MENU (File_Quit, MyFrame::OnQuit)
1332 EVT_MENU (File_About, MyFrame::OnAbout)
204dd9a7 1333 EVT_MENU (File_Clip, MyFrame::OnClip)
f31a4cb2
SC
1334#if wxUSE_GRAPHICS_CONTEXT
1335 EVT_MENU (File_GraphicContext, MyFrame::OnGraphicContext)
1336#endif
568708e2
VZ
1337
1338 EVT_MENU_RANGE(MenuShow_First, MenuShow_Last, MyFrame::OnShow)
1339
b62c3631
RR
1340 EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption)
1341END_EVENT_TABLE()
1342
aba99005
RR
1343// frame constructor
1344MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
9da8feef 1345 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size,
c4218a74 1346 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
aba99005
RR
1347{
1348 // set the frame icon
1349 SetIcon(wxICON(mondrian));
1350
1351 wxMenu *menuFile = new wxMenu;
ab1ca7b3
MB
1352 menuFile->Append(File_ShowDefault, _T("&Default screen\tF1"));
1353 menuFile->Append(File_ShowText, _T("&Text screen\tF2"));
1354 menuFile->Append(File_ShowLines, _T("&Lines screen\tF3"));
1355 menuFile->Append(File_ShowBrushes, _T("&Brushes screen\tF4"));
1356 menuFile->Append(File_ShowPolygons, _T("&Polygons screen\tF5"));
1357 menuFile->Append(File_ShowMask, _T("&Mask screen\tF6"));
1358 menuFile->Append(File_ShowOps, _T("&ROP screen\tF7"));
1359 menuFile->Append(File_ShowRegions, _T("Re&gions screen\tF8"));
1360 menuFile->Append(File_ShowCircles, _T("&Circles screen\tF9"));
f31a4cb2
SC
1361#if wxUSE_GRAPHICS_CONTEXT
1362 menuFile->Append(File_ShowAlpha, _T("&Alpha screen\tF10"));
1363#endif
213ad8e7
VZ
1364 menuFile->Append(File_ShowSplines, _T("&Splines screen\tF11"));
1365 menuFile->Append(File_ShowGradients, _T("&Gradients screen\tF12"));
568708e2 1366 menuFile->AppendSeparator();
ab1ca7b3 1367 menuFile->AppendCheckItem(File_Clip, _T("&Clip\tCtrl-C"), _T("Clip/unclip drawing"));
f31a4cb2
SC
1368#if wxUSE_GRAPHICS_CONTEXT
1369 menuFile->AppendCheckItem(File_GraphicContext, _T("&Use GraphicContext\tCtrl-Y"), _T("Use GraphicContext"));
1370#endif
204dd9a7 1371 menuFile->AppendSeparator();
ab1ca7b3 1372 menuFile->Append(File_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
aba99005 1373 menuFile->AppendSeparator();
ab1ca7b3 1374 menuFile->Append(File_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
0f0c61d0 1375
aba99005 1376 wxMenu *menuMapMode = new wxMenu;
ab1ca7b3
MB
1377 menuMapMode->Append( MapMode_Text, _T("&TEXT map mode") );
1378 menuMapMode->Append( MapMode_Lometric, _T("&LOMETRIC map mode") );
1379 menuMapMode->Append( MapMode_Twips, _T("T&WIPS map mode") );
1380 menuMapMode->Append( MapMode_Points, _T("&POINTS map mode") );
1381 menuMapMode->Append( MapMode_Metric, _T("&METRIC map mode") );
0f0c61d0 1382
aba99005 1383 wxMenu *menuUserScale = new wxMenu;
ab1ca7b3
MB
1384 menuUserScale->Append( UserScale_StretchHoriz, _T("Stretch &horizontally\tCtrl-H") );
1385 menuUserScale->Append( UserScale_ShrinkHoriz, _T("Shrin&k horizontally\tCtrl-G") );
1386 menuUserScale->Append( UserScale_StretchVertic, _T("Stretch &vertically\tCtrl-V") );
1387 menuUserScale->Append( UserScale_ShrinkVertic, _T("&Shrink vertically\tCtrl-W") );
0f0c61d0 1388 menuUserScale->AppendSeparator();
ab1ca7b3 1389 menuUserScale->Append( UserScale_Restore, _T("&Restore to normal\tCtrl-0") );
0f0c61d0 1390
aba99005 1391 wxMenu *menuAxis = new wxMenu;
2153bf89
DS
1392 menuAxis->AppendCheckItem( AxisMirror_Horiz, _T("Mirror horizontally\tCtrl-M") );
1393 menuAxis->AppendCheckItem( AxisMirror_Vertic, _T("Mirror vertically\tCtrl-N") );
0f0c61d0 1394
aba99005 1395 wxMenu *menuLogical = new wxMenu;
ab1ca7b3
MB
1396 menuLogical->Append( LogicalOrigin_MoveDown, _T("Move &down\tCtrl-D") );
1397 menuLogical->Append( LogicalOrigin_MoveUp, _T("Move &up\tCtrl-U") );
1398 menuLogical->Append( LogicalOrigin_MoveLeft, _T("Move &right\tCtrl-L") );
1399 menuLogical->Append( LogicalOrigin_MoveRight, _T("Move &left\tCtrl-R") );
fb576291 1400 menuLogical->AppendSeparator();
ab1ca7b3
MB
1401 menuLogical->Append( LogicalOrigin_Set, _T("Set to (&100, 100)\tShift-Ctrl-1") );
1402 menuLogical->Append( LogicalOrigin_Restore, _T("&Restore to normal\tShift-Ctrl-0") );
aba99005 1403
0f0c61d0 1404 wxMenu *menuColour = new wxMenu;
960a83cc 1405#if wxUSE_COLOURDLG
ab1ca7b3
MB
1406 menuColour->Append( Colour_TextForeground, _T("Text &foreground...") );
1407 menuColour->Append( Colour_TextBackground, _T("Text &background...") );
1408 menuColour->Append( Colour_Background, _T("Background &colour...") );
960a83cc 1409#endif // wxUSE_COLOURDLG
2153bf89
DS
1410 menuColour->AppendCheckItem( Colour_BackgroundMode, _T("&Opaque/transparent\tCtrl-B") );
1411 menuColour->AppendCheckItem( Colour_TextureBackgound, _T("Draw textured back&ground\tCtrl-T") );
0f0c61d0 1412
aba99005
RR
1413 // now append the freshly created menu to the menu bar...
1414 wxMenuBar *menuBar = new wxMenuBar;
ab1ca7b3
MB
1415 menuBar->Append(menuFile, _T("&File"));
1416 menuBar->Append(menuMapMode, _T("&Mode"));
1417 menuBar->Append(menuUserScale, _T("&Scale"));
1418 menuBar->Append(menuAxis, _T("&Axis"));
1419 menuBar->Append(menuLogical, _T("&Origin"));
1420 menuBar->Append(menuColour, _T("&Colours"));
aba99005
RR
1421
1422 // ... and attach this menu bar to the frame
1423 SetMenuBar(menuBar);
1424
960a83cc 1425#if wxUSE_STATUSBAR
aba99005 1426 CreateStatusBar(2);
be5a51fb 1427 SetStatusText(_T("Welcome to wxWidgets!"));
960a83cc 1428#endif // wxUSE_STATUSBAR
0f0c61d0 1429
aba99005
RR
1430 m_mapMode = wxMM_TEXT;
1431 m_xUserScale = 1.0;
1432 m_yUserScale = 1.0;
1433 m_xLogicalOrigin = 0;
1434 m_yLogicalOrigin = 0;
0f0c61d0 1435 m_xAxisReversed =
9da8feef 1436 m_yAxisReversed = false;
0f0c61d0 1437 m_backgroundMode = wxSOLID;
b97fa7cf
VZ
1438 m_colourForeground = *wxRED;
1439 m_colourBackground = *wxBLUE;
9da8feef 1440 m_textureBackground = false;
aba99005 1441
b62c3631 1442 m_canvas = new MyCanvas( this );
b97fa7cf 1443 m_canvas->SetScrollbars( 10, 10, 100, 240 );
b62c3631 1444}
aba99005
RR
1445
1446// event handlers
1447
1448void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
1449{
9da8feef
WS
1450 // true is to force the frame to close
1451 Close(true);
aba99005
RR
1452}
1453
1454void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
1455{
1456 wxString msg;
c916e13b
RR
1457 msg.Printf( wxT("This is the about dialog of the drawing sample.\n")
1458 wxT("This sample tests various primitive drawing functions\n")
6386110d 1459 wxT("(without any attempts to prevent flicker).\n")
c916e13b 1460 wxT("Copyright (c) Robert Roebling 1999")
aba99005
RR
1461 );
1462
ab1ca7b3 1463 wxMessageBox(msg, _T("About Drawing"), wxOK | wxICON_INFORMATION, this);
aba99005
RR
1464}
1465
204dd9a7
VZ
1466void MyFrame::OnClip(wxCommandEvent& event)
1467{
1468 m_canvas->Clip(event.IsChecked());
1469}
1470
f31a4cb2
SC
1471#if wxUSE_GRAPHICS_CONTEXT
1472void MyFrame::OnGraphicContext(wxCommandEvent& event)
1473{
1474 m_canvas->UseGraphicContext(event.IsChecked());
1475}
1476#endif
1477
568708e2
VZ
1478void MyFrame::OnShow(wxCommandEvent& event)
1479{
dacaa6f1 1480 m_canvas->ToShow((ScreenToShow)(event.GetId() - MenuShow_First));
568708e2
VZ
1481}
1482
1483void MyFrame::OnOption(wxCommandEvent& event)
aba99005 1484{
3ca6a5f0 1485 switch (event.GetId())
aba99005
RR
1486 {
1487 case MapMode_Text:
b9857632 1488 m_mapMode = wxMM_TEXT;
0f0c61d0 1489 break;
aba99005
RR
1490 case MapMode_Lometric:
1491 m_mapMode = wxMM_LOMETRIC;
0f0c61d0
VZ
1492 break;
1493 case MapMode_Twips:
aba99005 1494 m_mapMode = wxMM_TWIPS;
0f0c61d0
VZ
1495 break;
1496 case MapMode_Points:
aba99005 1497 m_mapMode = wxMM_POINTS;
0f0c61d0
VZ
1498 break;
1499 case MapMode_Metric:
aba99005 1500 m_mapMode = wxMM_METRIC;
0f0c61d0
VZ
1501 break;
1502
1503 case LogicalOrigin_MoveDown:
1504 m_yLogicalOrigin += 10;
1505 break;
1506 case LogicalOrigin_MoveUp:
1507 m_yLogicalOrigin -= 10;
1508 break;
1509 case LogicalOrigin_MoveLeft:
1510 m_xLogicalOrigin += 10;
1511 break;
1512 case LogicalOrigin_MoveRight:
1513 m_xLogicalOrigin -= 10;
1514 break;
fb576291
VZ
1515 case LogicalOrigin_Set:
1516 m_xLogicalOrigin =
1517 m_yLogicalOrigin = -100;
1518 break;
1519 case LogicalOrigin_Restore:
1520 m_xLogicalOrigin =
1521 m_yLogicalOrigin = 0;
1522 break;
0f0c61d0
VZ
1523
1524 case UserScale_StretchHoriz:
1525 m_xUserScale *= 1.10;
1526 break;
1527 case UserScale_ShrinkHoriz:
1528 m_xUserScale /= 1.10;
1529 break;
1530 case UserScale_StretchVertic:
1531 m_yUserScale *= 1.10;
1532 break;
1533 case UserScale_ShrinkVertic:
1534 m_yUserScale /= 1.10;
1535 break;
1536 case UserScale_Restore:
1537 m_xUserScale =
1538 m_yUserScale = 1.0;
1539 break;
1540
1541 case AxisMirror_Vertic:
1542 m_yAxisReversed = !m_yAxisReversed;
1543 break;
1544 case AxisMirror_Horiz:
1545 m_xAxisReversed = !m_xAxisReversed;
1546 break;
1547
960a83cc 1548#if wxUSE_COLOURDLG
0f0c61d0
VZ
1549 case Colour_TextForeground:
1550 m_colourForeground = SelectColour();
1551 break;
1552 case Colour_TextBackground:
1553 m_colourBackground = SelectColour();
1554 break;
1555 case Colour_Background:
1556 {
1557 wxColour col = SelectColour();
1558 if ( col.Ok() )
1559 {
1560 m_backgroundBrush.SetColour(col);
1561 }
1562 }
1563 break;
960a83cc
WS
1564#endif // wxUSE_COLOURDLG
1565
0f0c61d0
VZ
1566 case Colour_BackgroundMode:
1567 m_backgroundMode = m_backgroundMode == wxSOLID ? wxTRANSPARENT
1568 : wxSOLID;
1569 break;
1570
1edc9f45
RD
1571 case Colour_TextureBackgound:
1572 m_textureBackground = ! m_textureBackground;
1573 break;
1574
0f0c61d0
VZ
1575 default:
1576 // skip Refresh()
1577 return;
aba99005 1578 }
0f0c61d0 1579
1e7fd311 1580 m_canvas->Refresh();
aba99005
RR
1581}
1582
220af862 1583void MyFrame::PrepareDC(wxDC& dc)
aba99005 1584{
0f0c61d0 1585 dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin );
428db2ea 1586 dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed );
fb576291
VZ
1587 dc.SetUserScale( m_xUserScale, m_yUserScale );
1588 dc.SetMapMode( m_mapMode );
220af862
VZ
1589}
1590
960a83cc 1591#if wxUSE_COLOURDLG
220af862 1592wxColour MyFrame::SelectColour()
0f0c61d0
VZ
1593{
1594 wxColour col;
1595 wxColourData data;
1596 wxColourDialog dialog(this, &data);
1597
1598 if ( dialog.ShowModal() == wxID_OK )
1599 {
428db2ea 1600 col = dialog.GetColourData().GetColour();
0f0c61d0
VZ
1601 }
1602
1603 return col;
aba99005 1604}
960a83cc 1605#endif // wxUSE_COLOURDLG