]> git.saurik.com Git - wxWidgets.git/blame - samples/drawing/drawing.cpp
Line endings fixes in bakefile-generated files.
[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"
888dde65 36#include "wx/dcgraph.h"
8a021e00 37#include "wx/overlay.h"
795b5a8b 38#include "wx/graphics.h"
e0ac7d94 39#include "wx/filename.h"
8c6b0819 40#include "wx/metafile.h"
f31a4cb2 41
8a021e00
SC
42#define TEST_CAIRO_EVERYWHERE 0
43
aba99005 44// ----------------------------------------------------------------------------
795b5a8b 45// resources
aba99005 46// ----------------------------------------------------------------------------
568708e2 47
aba99005 48// the application icon
e7092398 49#ifndef wxHAS_IMAGES_IN_RESOURCES
3cb332c1 50 #include "../sample.xpm"
aba99005
RR
51#endif
52
568708e2
VZ
53// ----------------------------------------------------------------------------
54// global variables
55// ----------------------------------------------------------------------------
56
f6bcfd97
BP
57static wxBitmap *gs_bmpNoMask = NULL,
58 *gs_bmpWithColMask = NULL,
59 *gs_bmpMask = NULL,
60 *gs_bmpWithMask = NULL,
61 *gs_bmp4 = NULL,
62 *gs_bmp4_mono = NULL,
63 *gs_bmp36 = NULL;
568708e2 64
aba99005
RR
65// ----------------------------------------------------------------------------
66// private classes
67// ----------------------------------------------------------------------------
68
69// Define a new application type, each program should derive a class from wxApp
70class MyApp : public wxApp
71{
72public:
73 // override base class virtuals
74 // ----------------------------
75
76 // this one is called on application startup and is a good place for the app
77 // initialization (doing it here and not in the ctor allows to have an error
78 // return: if OnInit() returns false, the application terminates)
79 virtual bool OnInit();
568708e2 80
f6bcfd97
BP
81 virtual int OnExit() { DeleteBitmaps(); return 0; }
82
568708e2 83protected:
f6bcfd97
BP
84 void DeleteBitmaps();
85
568708e2 86 bool LoadImages();
aba99005
RR
87};
88
b62c3631
RR
89class MyCanvas;
90
aba99005
RR
91// Define a new frame type: this is going to be our main frame
92class MyFrame : public wxFrame
93{
94public:
95 // ctor(s)
96 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
97
98 // event handlers (these functions should _not_ be virtual)
99 void OnQuit(wxCommandEvent& event);
100 void OnAbout(wxCommandEvent& event);
204dd9a7 101 void OnClip(wxCommandEvent& event);
f31a4cb2
SC
102#if wxUSE_GRAPHICS_CONTEXT
103 void OnGraphicContext(wxCommandEvent& event);
104#endif
8c6b0819
VZ
105 void OnCopy(wxCommandEvent& event);
106 void OnSave(wxCommandEvent& event);
568708e2 107 void OnShow(wxCommandEvent &event);
aba99005 108 void OnOption(wxCommandEvent &event);
aba99005 109
960a83cc 110#if wxUSE_COLOURDLG
220af862 111 wxColour SelectColour();
960a83cc 112#endif // wxUSE_COLOURDLG
220af862 113 void PrepareDC(wxDC& dc);
0f0c61d0 114
b62c3631 115 int m_backgroundMode;
1edc9f45 116 int m_textureBackground;
89efaf2b 117 wxMappingMode m_mapMode;
b62c3631
RR
118 double m_xUserScale;
119 double m_yUserScale;
120 int m_xLogicalOrigin;
121 int m_yLogicalOrigin;
122 bool m_xAxisReversed,
123 m_yAxisReversed;
124 wxColour m_colourForeground, // these are _text_ colours
125 m_colourBackground;
126 wxBrush m_backgroundBrush;
127 MyCanvas *m_canvas;
aba99005
RR
128
129private:
be5a51fb 130 // any class wishing to process wxWidgets events must use this macro
aba99005
RR
131 DECLARE_EVENT_TABLE()
132};
133
b62c3631
RR
134// define a scrollable canvas for drawing onto
135class MyCanvas: public wxScrolledWindow
136{
137public:
138 MyCanvas( MyFrame *parent );
1e7fd311 139
b62c3631 140 void OnPaint(wxPaintEvent &event);
bf0c00c6 141 void OnMouseMove(wxMouseEvent &event);
8a021e00
SC
142 void OnMouseDown(wxMouseEvent &event);
143 void OnMouseUp(wxMouseEvent &event);
4786aabd 144
f65e33a3 145 void ToShow(int show) { m_show = show; Refresh(); }
568708e2 146
204dd9a7
VZ
147 // set or remove the clipping region
148 void Clip(bool clip) { m_clip = clip; Refresh(); }
f31a4cb2
SC
149#if wxUSE_GRAPHICS_CONTEXT
150 void UseGraphicContext(bool use) { m_useContext = use; Refresh(); }
151#endif
5707e433 152 void Draw(wxDC& dc);
204dd9a7 153
b62c3631 154protected:
e3b81044
VZ
155 enum DrawMode
156 {
157 Draw_Normal,
158 Draw_Stretch
159 };
160
568708e2 161 void DrawTestLines( int x, int y, int width, wxDC &dc );
6386110d
VZ
162 void DrawTestPoly(wxDC& dc);
163 void DrawTestBrushes(wxDC& dc);
568708e2 164 void DrawText(wxDC& dc);
e3b81044 165 void DrawImages(wxDC& dc, DrawMode mode);
81278df2 166 void DrawWithLogicalOps(wxDC& dc);
f31a4cb2
SC
167#if wxUSE_GRAPHICS_CONTEXT
168 void DrawAlpha(wxDC& dc);
7a5c82b1 169 void DrawGraphics(wxGraphicsContext* gc);
f31a4cb2 170#endif
bc3cedfa 171 void DrawRegions(wxDC& dc);
f6bcfd97 172 void DrawCircles(wxDC& dc);
b11729f1 173 void DrawSplines(wxDC& dc);
568708e2 174 void DrawDefault(wxDC& dc);
213ad8e7 175 void DrawGradients(wxDC& dc);
4786aabd 176
4cbcae16 177 void DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime);
8e0e4b1b 178
b62c3631 179private:
568708e2
VZ
180 MyFrame *m_owner;
181
f65e33a3 182 int m_show;
0e09f76e
RR
183 wxBitmap m_smile_bmp;
184 wxIcon m_std_icon;
204dd9a7 185 bool m_clip;
8a021e00
SC
186 wxOverlay m_overlay;
187 bool m_rubberBand;
188 wxPoint m_anchorpoint;
189 wxPoint m_currentpoint;
f31a4cb2
SC
190#if wxUSE_GRAPHICS_CONTEXT
191 bool m_useContext ;
192#endif
568708e2 193
b62c3631
RR
194 DECLARE_EVENT_TABLE()
195};
196
aba99005
RR
197// ----------------------------------------------------------------------------
198// constants
199// ----------------------------------------------------------------------------
200
201// IDs for the controls and the menu commands
202enum
203{
204 // menu items
b11729f1
WS
205 File_Quit = wxID_EXIT,
206 File_About = wxID_ABOUT,
568708e2 207
b11729f1 208 MenuShow_First = wxID_HIGHEST,
568708e2
VZ
209 File_ShowDefault = MenuShow_First,
210 File_ShowText,
211 File_ShowLines,
6386110d 212 File_ShowBrushes,
568708e2
VZ
213 File_ShowPolygons,
214 File_ShowMask,
e3b81044 215 File_ShowMaskStretch,
81278df2 216 File_ShowOps,
bc3cedfa 217 File_ShowRegions,
f6bcfd97 218 File_ShowCircles,
b11729f1 219 File_ShowSplines,
f31a4cb2
SC
220#if wxUSE_GRAPHICS_CONTEXT
221 File_ShowAlpha,
7a5c82b1 222 File_ShowGraphics,
f31a4cb2 223#endif
213ad8e7
VZ
224 File_ShowGradients,
225 MenuShow_Last = File_ShowGradients,
0f0c61d0 226
204dd9a7 227 File_Clip,
f31a4cb2
SC
228#if wxUSE_GRAPHICS_CONTEXT
229 File_GraphicContext,
230#endif
8c6b0819
VZ
231 File_Copy,
232 File_Save,
204dd9a7 233
0f0c61d0
VZ
234 MenuOption_First,
235
236 MapMode_Text = MenuOption_First,
aba99005
RR
237 MapMode_Lometric,
238 MapMode_Twips,
239 MapMode_Points,
240 MapMode_Metric,
0f0c61d0 241
aba99005
RR
242 UserScale_StretchHoriz,
243 UserScale_ShrinkHoriz,
244 UserScale_StretchVertic,
245 UserScale_ShrinkVertic,
0f0c61d0
VZ
246 UserScale_Restore,
247
aba99005
RR
248 AxisMirror_Horiz,
249 AxisMirror_Vertic,
0f0c61d0 250
aba99005
RR
251 LogicalOrigin_MoveDown,
252 LogicalOrigin_MoveUp,
253 LogicalOrigin_MoveLeft,
254 LogicalOrigin_MoveRight,
fb576291
VZ
255 LogicalOrigin_Set,
256 LogicalOrigin_Restore,
0f0c61d0 257
960a83cc 258#if wxUSE_COLOURDLG
0f0c61d0
VZ
259 Colour_TextForeground,
260 Colour_TextBackground,
261 Colour_Background,
960a83cc 262#endif // wxUSE_COLOURDLG
0f0c61d0 263 Colour_BackgroundMode,
1edc9f45 264 Colour_TextureBackgound,
0f0c61d0 265
1edc9f45 266 MenuOption_Last = Colour_TextureBackgound
aba99005
RR
267};
268
269// ----------------------------------------------------------------------------
be5a51fb 270// event tables and other macros for wxWidgets
aba99005
RR
271// ----------------------------------------------------------------------------
272
aba99005 273
be5a51fb 274// Create a new application object: this macro will allow wxWidgets to create
aba99005
RR
275// the application object during program execution (it's better than using a
276// static object for many reasons) and also declares the accessor function
277// wxGetApp() which will return the reference of the right type (i.e. MyApp and
278// not wxApp)
279IMPLEMENT_APP(MyApp)
280
281// ============================================================================
282// implementation
283// ============================================================================
284
285// ----------------------------------------------------------------------------
286// the application class
287// ----------------------------------------------------------------------------
288
568708e2
VZ
289bool MyApp::LoadImages()
290{
f6bcfd97
BP
291 gs_bmpNoMask = new wxBitmap;
292 gs_bmpWithColMask = new wxBitmap;
293 gs_bmpMask = new wxBitmap;
294 gs_bmpWithMask = new wxBitmap;
295 gs_bmp4 = new wxBitmap;
296 gs_bmp4_mono = new wxBitmap;
297 gs_bmp36 = new wxBitmap;
298
568708e2 299 wxPathList pathList;
e0ac7d94
VZ
300 // special hack for Unix in-tree sample build, don't do this in real
301 // programs, use wxStandardPaths instead
302 pathList.Add(wxFileName(argv[0]).GetPath());
9a83f860
VZ
303 pathList.Add(wxT("."));
304 pathList.Add(wxT(".."));
305 pathList.Add(wxT("../.."));
568708e2 306
9a83f860 307 wxString path = pathList.FindValidPath(wxT("pat4.bmp"));
568708e2 308 if ( !path )
9da8feef 309 return false;
f6bcfd97 310
e1208c31 311 /* 4 colour bitmap */
f6bcfd97 312 gs_bmp4->LoadFile(path, wxBITMAP_TYPE_BMP);
e1208c31 313 /* turn into mono-bitmap */
f6bcfd97
BP
314 gs_bmp4_mono->LoadFile(path, wxBITMAP_TYPE_BMP);
315 wxMask* mask4 = new wxMask(*gs_bmp4_mono, *wxBLACK);
316 gs_bmp4_mono->SetMask(mask4);
568708e2 317
9a83f860 318 path = pathList.FindValidPath(wxT("pat36.bmp"));
568708e2 319 if ( !path )
9da8feef 320 return false;
f6bcfd97
BP
321 gs_bmp36->LoadFile(path, wxBITMAP_TYPE_BMP);
322 wxMask* mask36 = new wxMask(*gs_bmp36, *wxBLACK);
323 gs_bmp36->SetMask(mask36);
568708e2 324
9a83f860 325 path = pathList.FindValidPath(wxT("image.bmp"));
568708e2 326 if ( !path )
9da8feef 327 return false;
f6bcfd97
BP
328 gs_bmpNoMask->LoadFile(path, wxBITMAP_TYPE_BMP);
329 gs_bmpWithMask->LoadFile(path, wxBITMAP_TYPE_BMP);
330 gs_bmpWithColMask->LoadFile(path, wxBITMAP_TYPE_BMP);
568708e2 331
9a83f860 332 path = pathList.FindValidPath(wxT("mask.bmp"));
568708e2 333 if ( !path )
9da8feef 334 return false;
f6bcfd97 335 gs_bmpMask->LoadFile(path, wxBITMAP_TYPE_BMP);
b9de1315 336
f6bcfd97
BP
337 wxMask *mask = new wxMask(*gs_bmpMask, *wxBLACK);
338 gs_bmpWithMask->SetMask(mask);
568708e2 339
f6bcfd97
BP
340 mask = new wxMask(*gs_bmpWithColMask, *wxWHITE);
341 gs_bmpWithColMask->SetMask(mask);
568708e2 342
9da8feef 343 return true;
568708e2
VZ
344}
345
aba99005
RR
346// `Main program' equivalent: the program execution "starts" here
347bool MyApp::OnInit()
348{
45e6e6f8
VZ
349 if ( !wxApp::OnInit() )
350 return false;
351
aba99005 352 // Create the main application window
9a83f860 353 MyFrame *frame = new MyFrame(wxT("Drawing sample"),
5db56cd2 354 wxDefaultPosition, wxSize(550, 840));
aba99005 355
18f42b94 356 // Show it
9da8feef 357 frame->Show(true);
aba99005 358
568708e2
VZ
359 if ( !LoadImages() )
360 {
4693b20c
MB
361 wxLogError(wxT("Can't load one of the bitmap files needed ")
362 wxT("for this sample from the current or parent ")
363 wxT("directory, please copy them there."));
568708e2 364
e0ac7d94
VZ
365 // still continue, the sample can be used without images too if they're
366 // missing for whatever reason
568708e2 367 }
8c6b0819
VZ
368#if wxUSE_LIBPNG
369 wxImage::AddHandler( new wxPNGHandler );
370#endif
568708e2 371
9da8feef 372 return true;
aba99005
RR
373}
374
f6bcfd97
BP
375void MyApp::DeleteBitmaps()
376{
5276b0a5
VZ
377 wxDELETE(gs_bmpNoMask);
378 wxDELETE(gs_bmpWithColMask);
379 wxDELETE(gs_bmpMask);
380 wxDELETE(gs_bmpWithMask);
381 wxDELETE(gs_bmp4);
382 wxDELETE(gs_bmp4_mono);
383 wxDELETE(gs_bmp36);
f6bcfd97
BP
384}
385
aba99005 386// ----------------------------------------------------------------------------
b62c3631 387// MyCanvas
aba99005
RR
388// ----------------------------------------------------------------------------
389
be5a51fb 390// the event tables connect the wxWidgets events with the functions (event
b62c3631
RR
391// handlers) which process them.
392BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
393 EVT_PAINT (MyCanvas::OnPaint)
bf0c00c6 394 EVT_MOTION (MyCanvas::OnMouseMove)
8a021e00
SC
395 EVT_LEFT_DOWN (MyCanvas::OnMouseDown)
396 EVT_LEFT_UP (MyCanvas::OnMouseUp)
b62c3631
RR
397END_EVENT_TABLE()
398
c4218a74 399#include "smile.xpm"
0e09f76e 400
c4218a74 401MyCanvas::MyCanvas(MyFrame *parent)
9da8feef 402 : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
c4218a74 403 wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE)
b62c3631 404{
b97fa7cf 405 m_owner = parent;
f65e33a3 406 m_show = File_ShowDefault;
0e09f76e 407 m_smile_bmp = wxBitmap(smile_xpm);
389d906b 408 m_std_icon = wxArtProvider::GetIcon(wxART_INFORMATION);
9da8feef 409 m_clip = false;
8a021e00 410 m_rubberBand = false;
f31a4cb2
SC
411#if wxUSE_GRAPHICS_CONTEXT
412 m_useContext = false;
413#endif
b97fa7cf
VZ
414}
415
6386110d 416void MyCanvas::DrawTestBrushes(wxDC& dc)
b97fa7cf 417{
6386110d
VZ
418 static const wxCoord WIDTH = 200;
419 static const wxCoord HEIGHT = 80;
420
421 wxCoord x = 10,
422 y = 10;
423
de914436 424 dc.SetBrush(*wxGREEN_BRUSH);
6386110d 425 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
9a83f860 426 dc.DrawText(wxT("Solid green"), x + 10, y + 10);
6386110d
VZ
427
428 y += HEIGHT;
0856cb25 429 dc.SetBrush(wxBrush(*wxRED, wxBRUSHSTYLE_CROSSDIAG_HATCH));
6386110d 430 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
1910265f
VZ
431 dc.DrawText(wxT("Diagonally hatched red"), x + 10, y + 10);
432
433 y += HEIGHT;
0856cb25 434 dc.SetBrush(wxBrush(*wxBLUE, wxBRUSHSTYLE_CROSS_HATCH));
1910265f
VZ
435 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
436 dc.DrawText(wxT("Cross hatched blue"), x + 10, y + 10);
437
438 y += HEIGHT;
0856cb25 439 dc.SetBrush(wxBrush(*wxCYAN, wxBRUSHSTYLE_VERTICAL_HATCH));
1910265f
VZ
440 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
441 dc.DrawText(wxT("Vertically hatched cyan"), x + 10, y + 10);
442
443 y += HEIGHT;
0856cb25 444 dc.SetBrush(wxBrush(*wxBLACK, wxBRUSHSTYLE_HORIZONTAL_HATCH));
1910265f
VZ
445 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
446 dc.DrawText(wxT("Horizontally hatched black"), x + 10, y + 10);
6386110d
VZ
447
448 y += HEIGHT;
449 dc.SetBrush(wxBrush(*gs_bmpMask));
450 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
9a83f860 451 dc.DrawText(wxT("Stipple mono"), x + 10, y + 10);
6386110d
VZ
452
453 y += HEIGHT;
454 dc.SetBrush(wxBrush(*gs_bmpNoMask));
455 dc.DrawRectangle(x, y, WIDTH, HEIGHT);
9a83f860 456 dc.DrawText(wxT("Stipple colour"), x + 10, y + 10);
6386110d 457}
b97fa7cf 458
6386110d
VZ
459void MyCanvas::DrawTestPoly(wxDC& dc)
460{
0856cb25 461 wxBrush brushHatch(*wxRED, wxBRUSHSTYLE_FDIAGONAL_HATCH);
6386110d
VZ
462 dc.SetBrush(brushHatch);
463
464 wxPoint star[5];
465 star[0] = wxPoint(100, 60);
466 star[1] = wxPoint(60, 150);
467 star[2] = wxPoint(160, 100);
468 star[3] = wxPoint(40, 100);
469 star[4] = wxPoint(140, 150);
470
9a83f860
VZ
471 dc.DrawText(wxT("You should see two (irregular) stars below, the left one ")
472 wxT("hatched"), 10, 10);
473 dc.DrawText(wxT("except for the central region and the right ")
474 wxT("one entirely hatched"), 10, 30);
475 dc.DrawText(wxT("The third star only has a hatched outline"), 10, 50);
163dc80e
VZ
476
477 dc.DrawPolygon(WXSIZEOF(star), star, 0, 30);
478 dc.DrawPolygon(WXSIZEOF(star), star, 160, 30, wxWINDING_RULE);
479
480 wxPoint star2[10];
481 star2[0] = wxPoint(0, 100);
482 star2[1] = wxPoint(-59, -81);
483 star2[2] = wxPoint(95, 31);
484 star2[3] = wxPoint(-95, 31);
485 star2[4] = wxPoint(59, -81);
486 star2[5] = wxPoint(0, 80);
487 star2[6] = wxPoint(-47, -64);
488 star2[7] = wxPoint(76, 24);
489 star2[8] = wxPoint(-76, 24);
490 star2[9] = wxPoint(47, -64);
491 int count[2] = {5, 5};
492
493 dc.DrawPolyPolygon(WXSIZEOF(count), count, star2, 450, 150);
b62c3631
RR
494}
495
1e7fd311 496void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc )
b62c3631 497{
de914436 498 dc.SetPen( wxPen( *wxBLACK, width ) );
1e7fd311 499 dc.SetBrush( *wxRED_BRUSH );
4693b20c 500 dc.DrawText(wxString::Format(wxT("Testing lines of width %d"), width), x + 10, y - 10);
9a8c7620 501 dc.DrawRectangle( x+10, y+10, 100, 190 );
4786aabd 502
9a83f860 503 dc.DrawText(wxT("Solid/dot/short dash/long dash/dot dash"), x + 150, y + 10);
de914436 504 dc.SetPen( wxPen( *wxBLACK, width ) );
696e1ea0 505 dc.DrawLine( x+20, y+20, 100, y+20 );
0856cb25 506 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_DOT) );
696e1ea0 507 dc.DrawLine( x+20, y+30, 100, y+30 );
0856cb25 508 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_SHORT_DASH) );
696e1ea0 509 dc.DrawLine( x+20, y+40, 100, y+40 );
0856cb25 510 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_LONG_DASH) );
696e1ea0 511 dc.DrawLine( x+20, y+50, 100, y+50 );
0856cb25 512 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_DOT_DASH) );
696e1ea0 513 dc.DrawLine( x+20, y+60, 100, y+60 );
1e7fd311 514
9a83f860 515 dc.DrawText(wxT("Misc hatches"), x + 150, y + 70);
0856cb25 516 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_BDIAGONAL_HATCH) );
696e1ea0 517 dc.DrawLine( x+20, y+70, 100, y+70 );
0856cb25 518 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_CROSSDIAG_HATCH) );
696e1ea0 519 dc.DrawLine( x+20, y+80, 100, y+80 );
0856cb25 520 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_FDIAGONAL_HATCH) );
696e1ea0 521 dc.DrawLine( x+20, y+90, 100, y+90 );
0856cb25 522 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_CROSS_HATCH) );
696e1ea0 523 dc.DrawLine( x+20, y+100, 100, y+100 );
0856cb25 524 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_HORIZONTAL_HATCH) );
696e1ea0 525 dc.DrawLine( x+20, y+110, 100, y+110 );
0856cb25 526 dc.SetPen( wxPen( *wxBLACK, width, wxPENSTYLE_VERTICAL_HATCH) );
696e1ea0 527 dc.DrawLine( x+20, y+120, 100, y+120 );
1e7fd311 528
9a83f860 529 dc.DrawText(wxT("User dash"), x + 150, y + 140);
0856cb25 530 wxPen ud( *wxBLACK, width, wxPENSTYLE_USER_DASH );
e2a5251d
VZ
531 wxDash dash1[6];
532 dash1[0] = 8; // Long dash <---------+
533 dash1[1] = 2; // Short gap |
534 dash1[2] = 3; // Short dash |
535 dash1[3] = 2; // Short gap |
536 dash1[4] = 3; // Short dash |
537 dash1[5] = 2; // Short gap and repeat +
538 ud.SetDashes( 6, dash1 );
539 dc.SetPen( ud );
696e1ea0 540 dc.DrawLine( x+20, y+140, 100, y+140 );
e2a5251d
VZ
541 dash1[0] = 5; // Make first dash shorter
542 ud.SetDashes( 6, dash1 );
543 dc.SetPen( ud );
696e1ea0 544 dc.DrawLine( x+20, y+150, 100, y+150 );
e2a5251d
VZ
545 dash1[2] = 5; // Make second dash longer
546 ud.SetDashes( 6, dash1 );
547 dc.SetPen( ud );
696e1ea0 548 dc.DrawLine( x+20, y+160, 100, y+160 );
e2a5251d
VZ
549 dash1[4] = 5; // Make third dash longer
550 ud.SetDashes( 6, dash1 );
551 dc.SetPen( ud );
696e1ea0 552 dc.DrawLine( x+20, y+170, 100, y+170 );
b62c3631
RR
553}
554
568708e2 555void MyCanvas::DrawDefault(wxDC& dc)
b62c3631 556{
d9a1b218
PC
557 // Draw circle centered at the origin, then flood fill it with a different
558 // color. Done with a wxMemoryDC because Blit (used by generic
559 // wxDoFloodFill) from a window that is being painted gives unpredictable
560 // results on wxGTK
561 {
562 wxImage img(21, 21, false);
563 img.Clear(1);
564 wxBitmap bmp(img);
565 {
566 wxMemoryDC mdc(bmp);
567 mdc.SetBrush(dc.GetBrush());
568 mdc.SetPen(dc.GetPen());
569 mdc.DrawCircle(10, 10, 10);
570 wxColour c;
571 if (mdc.GetPixel(11, 11, &c))
572 {
573 mdc.SetBrush(wxColour(128, 128, 0));
574 mdc.FloodFill(11, 11, c, wxFLOOD_SURFACE);
575 }
576 }
577 bmp.SetMask(new wxMask(bmp, wxColour(1, 1, 1)));
578 dc.DrawBitmap(bmp, -10, -10, true);
579 }
11fdee42 580
cd9da200
VZ
581 dc.DrawCheckMark(5, 80, 15, 15);
582 dc.DrawCheckMark(25, 80, 30, 30);
583 dc.DrawCheckMark(60, 80, 60, 60);
584
0e09f76e 585 // this is the test for "blitting bitmap into DC damages selected brush" bug
0e09f76e 586 wxCoord rectSize = m_std_icon.GetWidth() + 10;
cd9da200 587 wxCoord x = 100;
11f26ea0
VZ
588 dc.SetPen(*wxTRANSPARENT_PEN);
589 dc.SetBrush( *wxGREEN_BRUSH );
cd9da200 590 dc.DrawRectangle(x, 10, rectSize, rectSize);
9da8feef 591 dc.DrawBitmap(m_std_icon, x + 5, 15, true);
cd9da200
VZ
592 x += rectSize + 10;
593 dc.DrawRectangle(x, 10, rectSize, rectSize);
0e09f76e 594 dc.DrawIcon(m_std_icon, x + 5, 15);
cd9da200
VZ
595 x += rectSize + 10;
596 dc.DrawRectangle(x, 10, rectSize, rectSize);
11f26ea0
VZ
597
598 // test for "transparent" bitmap drawing (it intersects with the last
599 // rectangle above)
600 //dc.SetBrush( *wxTRANSPARENT_BRUSH );
d6f0a4b3 601
a1b806b9 602 if (m_smile_bmp.IsOk())
9da8feef 603 dc.DrawBitmap(m_smile_bmp, x + rectSize - 20, rectSize - 10, true);
107a1787 604
ff7c6c9c 605 dc.SetBrush( *wxBLACK_BRUSH );
107a1787
RR
606 dc.DrawRectangle( 0, 160, 1000, 300 );
607
608 // draw lines
609 wxBitmap bitmap(20,70);
610 wxMemoryDC memdc;
611 memdc.SelectObject( bitmap );
612 memdc.SetBrush( *wxBLACK_BRUSH );
613 memdc.SetPen( *wxWHITE_PEN );
614 memdc.DrawRectangle(0,0,20,70);
615 memdc.DrawLine( 10,0,10,70 );
81278df2 616
d4aa3a4b 617 // to the right
4c45f240 618 wxPen pen = *wxRED_PEN;
4c45f240 619 memdc.SetPen(pen);
107a1787
RR
620 memdc.DrawLine( 10, 5,10, 5 );
621 memdc.DrawLine( 10,10,11,10 );
622 memdc.DrawLine( 10,15,12,15 );
623 memdc.DrawLine( 10,20,13,20 );
81278df2 624
d4aa3a4b
RR
625/*
626 memdc.SetPen(*wxRED_PEN);
107a1787
RR
627 memdc.DrawLine( 12, 5,12, 5 );
628 memdc.DrawLine( 12,10,13,10 );
629 memdc.DrawLine( 12,15,14,15 );
630 memdc.DrawLine( 12,20,15,20 );
d4aa3a4b 631*/
81278df2 632
107a1787
RR
633 // same to the left
634 memdc.DrawLine( 10,25,10,25 );
635 memdc.DrawLine( 10,30, 9,30 );
636 memdc.DrawLine( 10,35, 8,35 );
637 memdc.DrawLine( 10,40, 7,40 );
638
639 // XOR draw lines
d4aa3a4b 640 dc.SetPen(*wxWHITE_PEN);
107a1787
RR
641 memdc.SetLogicalFunction( wxINVERT );
642 memdc.SetPen( *wxWHITE_PEN );
643 memdc.DrawLine( 10,50,10,50 );
644 memdc.DrawLine( 10,55,11,55 );
645 memdc.DrawLine( 10,60,12,60 );
646 memdc.DrawLine( 10,65,13,65 );
81278df2 647
107a1787
RR
648 memdc.DrawLine( 12,50,12,50 );
649 memdc.DrawLine( 12,55,13,55 );
650 memdc.DrawLine( 12,60,14,60 );
651 memdc.DrawLine( 12,65,15,65 );
81278df2 652
107a1787
RR
653 memdc.SelectObject( wxNullBitmap );
654 dc.DrawBitmap( bitmap, 10, 170 );
389d906b 655 wxImage image = bitmap.ConvertToImage();
107a1787 656 image.Rescale( 60,210 );
389d906b 657 bitmap = wxBitmap(image);
107a1787 658 dc.DrawBitmap( bitmap, 50, 170 );
81278df2 659
b9de1315 660 // test the rectangle outline drawing - there should be one pixel between
ff7c6c9c
RR
661 // the rect and the lines
662 dc.SetPen(*wxWHITE_PEN);
663 dc.SetBrush( *wxTRANSPARENT_BRUSH );
ff7c6c9c 664 dc.DrawRectangle(150, 170, 49, 29);
107a1787 665 dc.DrawRectangle(200, 170, 49, 29);
ff7c6c9c 666 dc.SetPen(*wxWHITE_PEN);
107a1787
RR
667 dc.DrawLine(250, 210, 250, 170);
668 dc.DrawLine(260, 200, 150, 200);
b9de1315
VZ
669
670 // test the rectangle filled drawing - there should be one pixel between
ff7c6c9c
RR
671 // the rect and the lines
672 dc.SetPen(*wxTRANSPARENT_PEN);
673 dc.SetBrush( *wxWHITE_BRUSH );
674 dc.DrawRectangle(300, 170, 49, 29);
568708e2 675 dc.DrawRectangle(350, 170, 49, 29);
ff7c6c9c 676 dc.SetPen(*wxWHITE_PEN);
b9de1315
VZ
677 dc.DrawLine(400, 170, 400, 210);
678 dc.DrawLine(300, 200, 410, 200);
679
3d2d8da1
RR
680 // a few more tests of this kind
681 dc.SetPen(*wxRED_PEN);
682 dc.SetBrush( *wxWHITE_BRUSH );
683 dc.DrawRectangle(300, 220, 1, 1);
684 dc.DrawRectangle(310, 220, 2, 2);
685 dc.DrawRectangle(320, 220, 3, 3);
686 dc.DrawRectangle(330, 220, 4, 4);
687
688 dc.SetPen(*wxTRANSPARENT_PEN);
689 dc.SetBrush( *wxWHITE_BRUSH );
690 dc.DrawRectangle(300, 230, 1, 1);
691 dc.DrawRectangle(310, 230, 2, 2);
692 dc.DrawRectangle(320, 230, 3, 3);
693 dc.DrawRectangle(330, 230, 4, 4);
694
b9de1315
VZ
695 // and now for filled rect with outline
696 dc.SetPen(*wxRED_PEN);
697 dc.SetBrush( *wxWHITE_BRUSH );
698 dc.DrawRectangle(500, 170, 49, 29);
699 dc.DrawRectangle(550, 170, 49, 29);
700 dc.SetPen(*wxWHITE_PEN);
701 dc.DrawLine(600, 170, 600, 210);
702 dc.DrawLine(500, 200, 610, 200);
703
704 // test the rectangle outline drawing - there should be one pixel between
ff7c6c9c
RR
705 // the rect and the lines
706 dc.SetPen(*wxWHITE_PEN);
707 dc.SetBrush( *wxTRANSPARENT_BRUSH );
ff7c6c9c 708 dc.DrawRoundedRectangle(150, 270, 49, 29, 6);
107a1787 709 dc.DrawRoundedRectangle(200, 270, 49, 29, 6);
ff7c6c9c 710 dc.SetPen(*wxWHITE_PEN);
107a1787
RR
711 dc.DrawLine(250, 270, 250, 310);
712 dc.DrawLine(150, 300, 260, 300);
b9de1315
VZ
713
714 // test the rectangle filled drawing - there should be one pixel between
ff7c6c9c
RR
715 // the rect and the lines
716 dc.SetPen(*wxTRANSPARENT_PEN);
717 dc.SetBrush( *wxWHITE_BRUSH );
718 dc.DrawRoundedRectangle(300, 270, 49, 29, 6);
719 dc.DrawRoundedRectangle(350, 270, 49, 29, 6);
720 dc.SetPen(*wxWHITE_PEN);
b9de1315
VZ
721 dc.DrawLine(400, 270, 400, 310);
722 dc.DrawLine(300, 300, 410, 300);
ff7c6c9c 723
b14c14ff
JS
724 // Added by JACS to demonstrate bizarre behaviour.
725 // With a size of 70, we get a missing red RHS,
3103e8a9 726 // and the height is too small, so we get yellow
b14c14ff
JS
727 // showing. With a size of 40, it draws as expected:
728 // it just shows a white rectangle with red outline.
729 int totalWidth = 70;
730 int totalHeight = 70;
731 wxBitmap bitmap2(totalWidth, totalHeight);
732
733 wxMemoryDC memdc2;
734 memdc2.SelectObject(bitmap2);
735
de914436 736 memdc2.SetBackground(*wxYELLOW_BRUSH);
d6f0a4b3 737 memdc2.Clear();
b14c14ff 738
b14c14ff
JS
739 // Now draw a white rectangle with red outline. It should
740 // entirely eclipse the yellow background.
741 memdc2.SetPen(*wxRED_PEN);
742 memdc2.SetBrush(*wxWHITE_BRUSH);
743
744 memdc2.DrawRectangle(0, 0, totalWidth, totalHeight);
745
b14c14ff
JS
746 memdc2.SetPen(wxNullPen);
747 memdc2.SetBrush(wxNullBrush);
cd9da200 748 memdc2.SelectObject(wxNullBitmap);
b14c14ff
JS
749
750 dc.DrawBitmap(bitmap2, 500, 270);
d6f0a4b3
JS
751
752 // Repeat, but draw directly on dc
753 // Draw a yellow rectangle filling the bitmap
754
755 x = 600; int y = 270;
de914436
PC
756 dc.SetPen(*wxYELLOW_PEN);
757 dc.SetBrush(*wxYELLOW_BRUSH);
d6f0a4b3
JS
758 dc.DrawRectangle(x, y, totalWidth, totalHeight);
759
760 // Now draw a white rectangle with red outline. It should
761 // entirely eclipse the yellow background.
762 dc.SetPen(*wxRED_PEN);
763 dc.SetBrush(*wxWHITE_BRUSH);
764
765 dc.DrawRectangle(x, y, totalWidth, totalHeight);
568708e2
VZ
766}
767
768void MyCanvas::DrawText(wxDC& dc)
769{
9a8c7620 770 // set underlined font for testing
9da8feef 771 dc.SetFont( wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, true) );
9a83f860
VZ
772 dc.DrawText( wxT("This is text"), 110, 10 );
773 dc.DrawRotatedText( wxT("That is text"), 20, 10, -45 );
9a8c7620 774
4770df95
VZ
775 // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
776 // under Win9x (it is not TrueType)
777 dc.SetFont( *wxSWISS_FONT );
b62c3631 778
696e1ea0 779 wxString text;
f6bcfd97 780 dc.SetBackgroundMode(wxTRANSPARENT);
696e1ea0
VZ
781
782 for ( int n = -180; n < 180; n += 30 )
783 {
4693b20c 784 text.Printf(wxT(" %d rotated text"), n);
696e1ea0
VZ
785 dc.DrawRotatedText(text , 400, 400, n);
786 }
95724b1a 787
196c87f4 788 dc.SetFont( wxFont( 18, wxSWISS, wxNORMAL, wxNORMAL ) );
c45a644e 789
9a83f860 790 dc.DrawText( wxT("This is Swiss 18pt text."), 110, 40 );
c45a644e 791
6f207e66
VS
792 wxCoord length;
793 wxCoord height;
794 wxCoord descent;
9a83f860 795 dc.GetTextExtent( wxT("This is Swiss 18pt text."), &length, &height, &descent );
e22fa4d7 796 text.Printf( wxT("Dimensions are length %d, height %d, descent %d"), length, height, descent );
c45a644e
RR
797 dc.DrawText( text, 110, 80 );
798
4693b20c 799 text.Printf( wxT("CharHeight() returns: %d"), dc.GetCharHeight() );
c45a644e
RR
800 dc.DrawText( text, 110, 120 );
801
568708e2 802 dc.DrawRectangle( 100, 40, 4, height );
f6bcfd97
BP
803
804 // test the logical function effect
805 wxCoord y = 150;
806 dc.SetLogicalFunction(wxINVERT);
e928566f 807 // text drawing should ignore logical function
9a83f860 808 dc.DrawText( wxT("There should be a text below"), 110, 150 );
f6bcfd97
BP
809 dc.DrawRectangle( 110, y, 100, height );
810
f6bcfd97 811 y += height;
9a83f860 812 dc.DrawText( wxT("Visible text"), 110, y );
f6bcfd97 813 dc.DrawRectangle( 110, y, 100, height );
9a83f860 814 dc.DrawText( wxT("Visible text"), 110, y );
f6bcfd97
BP
815 dc.DrawRectangle( 110, y, 100, height );
816 dc.SetLogicalFunction(wxCOPY);
817
818 y += height;
819 dc.DrawRectangle( 110, y, 100, height );
9a83f860 820 dc.DrawText( wxT("Another visible text"), 110, y );
a5bb4514
VZ
821
822 y += height;
823 dc.DrawText("And\nmore\ntext on\nmultiple\nlines", 110, y);
568708e2
VZ
824}
825
81278df2 826static const struct
568708e2 827{
81278df2 828 const wxChar *name;
89efaf2b 829 wxRasterOperationMode rop;
81278df2
VZ
830} rasterOperations[] =
831{
4693b20c
MB
832 { wxT("wxAND"), wxAND },
833 { wxT("wxAND_INVERT"), wxAND_INVERT },
834 { wxT("wxAND_REVERSE"), wxAND_REVERSE },
835 { wxT("wxCLEAR"), wxCLEAR },
836 { wxT("wxCOPY"), wxCOPY },
837 { wxT("wxEQUIV"), wxEQUIV },
838 { wxT("wxINVERT"), wxINVERT },
839 { wxT("wxNAND"), wxNAND },
840 { wxT("wxNO_OP"), wxNO_OP },
841 { wxT("wxOR"), wxOR },
842 { wxT("wxOR_INVERT"), wxOR_INVERT },
843 { wxT("wxOR_REVERSE"), wxOR_REVERSE },
844 { wxT("wxSET"), wxSET },
845 { wxT("wxSRC_INVERT"), wxSRC_INVERT },
846 { wxT("wxXOR"), wxXOR },
81278df2 847};
568708e2 848
e3b81044 849void MyCanvas::DrawImages(wxDC& dc, DrawMode mode)
81278df2 850{
9a83f860 851 dc.DrawText(wxT("original image"), 0, 0);
f6bcfd97 852 dc.DrawBitmap(*gs_bmpNoMask, 0, 20, 0);
9a83f860 853 dc.DrawText(wxT("with colour mask"), 0, 100);
9da8feef 854 dc.DrawBitmap(*gs_bmpWithColMask, 0, 120, true);
9a83f860 855 dc.DrawText(wxT("the mask image"), 0, 200);
f6bcfd97 856 dc.DrawBitmap(*gs_bmpMask, 0, 220, 0);
9a83f860 857 dc.DrawText(wxT("masked image"), 0, 300);
9da8feef 858 dc.DrawBitmap(*gs_bmpWithMask, 0, 320, true);
568708e2 859
f6bcfd97
BP
860 int cx = gs_bmpWithColMask->GetWidth(),
861 cy = gs_bmpWithColMask->GetHeight();
568708e2
VZ
862
863 wxMemoryDC memDC;
864 for ( size_t n = 0; n < WXSIZEOF(rasterOperations); n++ )
865 {
866 wxCoord x = 120 + 150*(n%4),
867 y = 20 + 100*(n/4);
4786aabd 868
568708e2 869 dc.DrawText(rasterOperations[n].name, x, y - 20);
f6bcfd97 870 memDC.SelectObject(*gs_bmpWithColMask);
e3b81044
VZ
871 if ( mode == Draw_Stretch )
872 {
873 dc.StretchBlit(x, y, cx, cy, &memDC, 0, 0, cx/2, cy/2,
874 rasterOperations[n].rop, true);
875 }
876 else
877 {
878 dc.Blit(x, y, cx, cy, &memDC, 0, 0, rasterOperations[n].rop, true);
879 }
568708e2
VZ
880 }
881}
882
81278df2
VZ
883void MyCanvas::DrawWithLogicalOps(wxDC& dc)
884{
885 static const wxCoord w = 60;
886 static const wxCoord h = 60;
887
888 // reuse the text colour here
de914436 889 dc.SetPen(wxPen(m_owner->m_colourForeground));
11f26ea0 890 dc.SetBrush(*wxTRANSPARENT_BRUSH);
81278df2 891
5888ef1e
VZ
892 size_t n;
893 for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
81278df2
VZ
894 {
895 wxCoord x = 20 + 150*(n%4),
896 y = 20 + 100*(n/4);
897
898 dc.DrawText(rasterOperations[n].name, x, y - 20);
899 dc.SetLogicalFunction(rasterOperations[n].rop);
11f26ea0 900 dc.DrawRectangle(x, y, w, h);
81278df2
VZ
901 dc.DrawLine(x, y, x + w, y + h);
902 dc.DrawLine(x + w, y, x, y + h);
903 }
c1d139da
GRG
904
905 // now some filled rectangles
de914436 906 dc.SetBrush(wxBrush(m_owner->m_colourForeground));
c1d139da 907
5888ef1e 908 for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
c1d139da
GRG
909 {
910 wxCoord x = 20 + 150*(n%4),
911 y = 500 + 100*(n/4);
912
913 dc.DrawText(rasterOperations[n].name, x, y - 20);
914 dc.SetLogicalFunction(rasterOperations[n].rop);
915 dc.DrawRectangle(x, y, w, h);
916 }
81278df2
VZ
917}
918
f31a4cb2 919#if wxUSE_GRAPHICS_CONTEXT
ad0b4329 920#ifdef __WXGTK20__
84e0e526 921void MyCanvas::DrawAlpha(wxDC& WXUNUSED(dummyDC))
ad0b4329 922#else
f31a4cb2 923void MyCanvas::DrawAlpha(wxDC& dc)
ad0b4329 924#endif
f31a4cb2 925{
ad0b4329
RR
926#ifdef __WXGTK__
927 wxGCDC dc( this );
928 PrepareDC( dc );
929#endif
930
f31a4cb2
SC
931 wxDouble margin = 20 ;
932 wxDouble width = 180 ;
933 wxDouble radius = 30 ;
e3b81044 934
de914436
PC
935 dc.SetPen( wxPen( wxColour( 128, 0, 0 ), 12 ));
936 dc.SetBrush(*wxRED_BRUSH);
e3b81044 937
f31a4cb2 938 wxRect r(margin,margin+width*0.66,width,width) ;
e3b81044 939
f31a4cb2 940 dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
e3b81044 941
de914436
PC
942 dc.SetPen( wxPen( wxColour( 0, 0, 128 ), 12));
943 dc.SetBrush(*wxBLUE_BRUSH);
e3b81044 944
f31a4cb2 945 r.Offset( width * 0.8 , - width * 0.66 ) ;
e3b81044 946
f31a4cb2 947 dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
e3b81044 948
de914436
PC
949 dc.SetPen( wxPen( wxColour( 128, 128, 0 ), 12));
950 dc.SetBrush( wxBrush( wxColour( 192, 192, 0)));
f31a4cb2
SC
951
952 r.Offset( width * 0.8 , width *0.5 ) ;
e3b81044 953
f31a4cb2 954 dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
e3b81044 955
f31a4cb2
SC
956 dc.SetPen( *wxTRANSPARENT_PEN ) ;
957 dc.SetBrush( wxBrush( wxColour(255,255,128,128) ) );
958 dc.DrawRoundedRectangle( 0 , margin + width / 2 , width * 3 , 100 , radius) ;
e3b81044 959
ad0b4329
RR
960 dc.SetTextForeground( wxColour(255,255,0,128) );
961 dc.SetFont( wxFont( 40, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_NORMAL ) );
962 dc.DrawText( wxT("Hello!"), 120, 80 );
f31a4cb2
SC
963}
964
965#endif
966
7a5c82b1
SC
967#if wxUSE_GRAPHICS_CONTEXT
968
969const int BASE = 80.0;
970const int BASE2 = BASE/2;
971const int BASE4 = BASE/4;
972
973static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
974
975
976// modeled along Robin Dunn's GraphicsContext.py sample
977
978void MyCanvas::DrawGraphics(wxGraphicsContext* gc)
979{
980 wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
981 gc->SetFont(font,*wxBLACK);
4ee4c7b9 982
7a5c82b1
SC
983 // make a path that contains a circle and some lines, centered at 0,0
984 wxGraphicsPath path = gc->CreatePath() ;
985 path.AddCircle( 0, 0, BASE2 );
986 path.MoveToPoint(0, -BASE2);
987 path.AddLineToPoint(0, BASE2);
988 path.MoveToPoint(-BASE2, 0);
989 path.AddLineToPoint(BASE2, 0);
990 path.CloseSubpath();
991 path.AddRectangle(-BASE4, -BASE4/2, BASE2, BASE4);
4ee4c7b9 992
7a5c82b1 993 // Now use that path to demonstrate various capbilites of the grpahics context
4ee4c7b9 994 gc->PushState(); // save current translation/scale/other state
7a5c82b1
SC
995 gc->Translate(60, 75); // reposition the context origin
996
de914436 997 gc->SetPen(wxPen("navy"));
7a5c82b1 998 gc->SetBrush(wxBrush("pink"));
4ee4c7b9 999
7a5c82b1
SC
1000 for( int i = 0 ; i < 3 ; ++i )
1001 {
1002 wxString label;
1003 switch( i )
1004 {
1005 case 0 :
1006 label = "StrokePath";
1007 break;
1008 case 1 :
1009 label = "FillPath";
1010 break;
1011 case 2 :
1012 label = "DrawPath";
1013 break;
1014 }
1015 wxDouble w, h;
1016 gc->GetTextExtent(label, &w, &h, NULL, NULL);
1017 gc->DrawText(label, -w/2, -BASE2-h-4);
1018 switch( i )
1019 {
1020 case 0 :
1021 gc->StrokePath(path);
1022 break;
1023 case 1 :
1024 gc->FillPath(path);
1025 break;
1026 case 2 :
1027 gc->DrawPath(path);
1028 break;
1029 }
1030 gc->Translate(2*BASE, 0);
1031 }
4ee4c7b9 1032
7a5c82b1
SC
1033 gc->PopState(); // restore saved state
1034 gc->PushState(); // save it again
1035 gc->Translate(60, 200); // offset to the lower part of the window
4ee4c7b9 1036
7a5c82b1
SC
1037 gc->DrawText("Scale", 0, -BASE2);
1038 gc->Translate(0, 20);
1039
1040 gc->SetBrush(wxBrush(wxColour(178, 34, 34, 128)));// 128 == half transparent
1041 for( int i = 0 ; i < 8 ; ++i )
1042 {
1043 gc->Scale(1.08, 1.08); // increase scale by 8%
4ee4c7b9 1044 gc->Translate(5,5);
7a5c82b1
SC
1045 gc->DrawPath(path);
1046 }
1047
1048 gc->PopState(); // restore saved state
1049 gc->PushState(); // save it again
4ee4c7b9
VZ
1050 gc->Translate(400, 200);
1051
7a5c82b1
SC
1052 gc->DrawText("Rotate", 0, -BASE2);
1053
1054 // Move the origin over to the next location
1055 gc->Translate(0, 75);
1056
1057 // draw our path again, rotating it about the central point,
1058 // and changing colors as we go
1059 for ( int angle = 0 ; angle < 360 ; angle += 30 )
1060 {
4ee4c7b9 1061 gc->PushState(); // save this new current state so we can
7a5c82b1
SC
1062 // pop back to it at the end of the loop
1063 wxImage::RGBValue val = wxImage::HSVtoRGB(wxImage::HSVValue(float(angle)/360, 1, 1));
1064 gc->SetBrush(wxBrush(wxColour(val.red, val.green, val.blue, 64)));
1065 gc->SetPen(wxPen(wxColour(val.red, val.green, val.blue, 128)));
4ee4c7b9 1066
7a5c82b1
SC
1067 // use translate to artfully reposition each drawn path
1068 gc->Translate(1.5 * BASE2 * cos(DegToRad(angle)),
1069 1.5 * BASE2 * sin(DegToRad(angle)));
4ee4c7b9 1070
7a5c82b1
SC
1071 // use Rotate to rotate the path
1072 gc->Rotate(DegToRad(angle));
1073
1074 // now draw it
1075 gc->DrawPath(path);
1076 gc->PopState();
1077 }
1078 gc->PopState();
ce6b1014
VZ
1079
1080 gc->PushState();
1081 gc->Translate(60, 400);
1082 gc->DrawText("Scaled smiley inside a square", 0, 0);
1083 gc->DrawRectangle(BASE2, BASE2, 100, 100);
1084 gc->DrawBitmap(m_smile_bmp, BASE2, BASE2, 100, 100);
1085 gc->PopState();
7a5c82b1 1086}
ce6b1014 1087#endif // wxUSE_GRAPHICS_CONTEXT
7a5c82b1 1088
f6bcfd97
BP
1089void MyCanvas::DrawCircles(wxDC& dc)
1090{
1091 int x = 100,
1092 y = 100,
1093 r = 20;
1094
d9d2dcd8
RR
1095 dc.SetPen( *wxRED_PEN );
1096 dc.SetBrush( *wxGREEN_BRUSH );
1097
9a83f860 1098 dc.DrawText(wxT("Some circles"), 0, y);
d9d2dcd8
RR
1099 dc.DrawCircle(x, y, r);
1100 dc.DrawCircle(x + 2*r, y, r);
1101 dc.DrawCircle(x + 4*r, y, r);
1102
1103 y += 2*r;
9a83f860 1104 dc.DrawText(wxT("And ellipses"), 0, y);
d9d2dcd8
RR
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);
1108
1109 y += 2*r;
9a83f860 1110 dc.DrawText(wxT("And arcs"), 0, y);
d9d2dcd8
RR
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);
1114
1115 y += 2*r;
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);
e3b81044 1120
d9d2dcd8 1121 // same as above, just transparent brush
e3b81044 1122
d9d2dcd8
RR
1123 dc.SetPen( *wxRED_PEN );
1124 dc.SetBrush( *wxTRANSPARENT_BRUSH );
1125
1126 y += 2*r;
9a83f860 1127 dc.DrawText(wxT("Some circles"), 0, y);
f6bcfd97
BP
1128 dc.DrawCircle(x, y, r);
1129 dc.DrawCircle(x + 2*r, y, r);
1130 dc.DrawCircle(x + 4*r, y, r);
1131
1132 y += 2*r;
9a83f860 1133 dc.DrawText(wxT("And ellipses"), 0, y);
f6bcfd97
BP
1134 dc.DrawEllipse(x - r, y, 2*r, r);
1135 dc.DrawEllipse(x + r, y, 2*r, r);
1136 dc.DrawEllipse(x + 3*r, y, 2*r, r);
1137
1138 y += 2*r;
9a83f860 1139 dc.DrawText(wxT("And arcs"), 0, y);
f6bcfd97
BP
1140 dc.DrawArc(x - r, y, x + r, y, x, y);
1141 dc.DrawArc(x + 4*r, y, x + 2*r, y, x + 3*r, y);
1142 dc.DrawArc(x + 5*r, y, x + 5*r, y, x + 6*r, y);
1143
1144 y += 2*r;
1145 dc.DrawEllipticArc(x - r, y, 2*r, r, 0, 90);
1146 dc.DrawEllipticArc(x + r, y, 2*r, r, 90, 180);
1147 dc.DrawEllipticArc(x + 3*r, y, 2*r, r, 180, 270);
1148 dc.DrawEllipticArc(x + 5*r, y, 2*r, r, 270, 360);
e3b81044 1149
f6bcfd97
BP
1150}
1151
b11729f1
WS
1152void MyCanvas::DrawSplines(wxDC& dc)
1153{
1154#if wxUSE_SPLINES
9a83f860 1155 dc.DrawText(wxT("Some splines"), 10, 5);
b11729f1
WS
1156
1157 // values are hardcoded rather than randomly generated
1158 // so the output can be compared between native
1159 // implementations on platforms with different random
1160 // generators
1161
1162 const int R = 300;
1163 const wxPoint center( R + 20, R + 20 );
1164 const int angles[7] = { 0, 10, 33, 77, 13, 145, 90 };
1165 const int radii[5] = { 100 , 59, 85, 33, 90 };
1166 const int n = 200;
1167 wxPoint pts[n];
1168
1169 // background spline calculation
1170 unsigned int radius_pos = 0;
1171 unsigned int angle_pos = 0;
1172 int angle = 0;
1173 for ( int i = 0; i < n; i++ )
1174 {
1175 angle += angles[ angle_pos ];
1176 int r = R * radii[ radius_pos ] / 100;
1177 pts[ i ].x = center.x + (wxCoord)( r * cos( M_PI * angle / 180.0) );
1178 pts[ i ].y = center.y + (wxCoord)( r * sin( M_PI * angle / 180.0) );
1179
1180 angle_pos++;
1181 if ( angle_pos >= WXSIZEOF(angles) ) angle_pos = 0;
1182
1183 radius_pos++;
1184 if ( radius_pos >= WXSIZEOF(radii) ) radius_pos = 0;
1185 }
1186
1187 // background spline drawing
1188 dc.SetPen(*wxRED_PEN);
1189 dc.DrawSpline(WXSIZEOF(pts), pts);
1190
1191 // less detailed spline calculation
1192 wxPoint letters[4][5];
1193 // w
1194 letters[0][0] = wxPoint( 0,1); // O O
1195 letters[0][1] = wxPoint( 1,3); // * *
1196 letters[0][2] = wxPoint( 2,2); // * O *
1197 letters[0][3] = wxPoint( 3,3); // * * * *
1198 letters[0][4] = wxPoint( 4,1); // O O
1199 // x1
1200 letters[1][0] = wxPoint( 5,1); // O*O
1201 letters[1][1] = wxPoint( 6,1); // *
1202 letters[1][2] = wxPoint( 7,2); // O
1203 letters[1][3] = wxPoint( 8,3); // *
1204 letters[1][4] = wxPoint( 9,3); // O*O
1205 // x2
1206 letters[2][0] = wxPoint( 5,3); // O*O
1207 letters[2][1] = wxPoint( 6,3); // *
1208 letters[2][2] = wxPoint( 7,2); // O
1209 letters[2][3] = wxPoint( 8,1); // *
1210 letters[2][4] = wxPoint( 9,1); // O*O
1211 // W
1212 letters[3][0] = wxPoint(10,0); // O O
1213 letters[3][1] = wxPoint(11,3); // * *
1214 letters[3][2] = wxPoint(12,1); // * O *
1215 letters[3][3] = wxPoint(13,3); // * * * *
1216 letters[3][4] = wxPoint(14,0); // O O
1217
1218 const int dx = 2 * R / letters[3][4].x;
1219 const int h[4] = { -R/2, 0, R/4, R/2 };
1220
1221 for ( int m = 0; m < 4; m++ )
1222 {
1223 for ( int n = 0; n < 5; n++ )
1224 {
1225 letters[m][n].x = center.x - R + letters[m][n].x * dx;
1226 letters[m][n].y = center.y + h[ letters[m][n].y ];
1227 }
1228
de914436 1229 dc.SetPen( wxPen( *wxBLUE, 1, wxDOT) );
b11729f1 1230 dc.DrawLines(5, letters[m]);
de914436 1231 dc.SetPen( wxPen( *wxBLACK, 4) );
b11729f1
WS
1232 dc.DrawSpline(5, letters[m]);
1233 }
1234
1235#else
9a83f860 1236 dc.DrawText(wxT("Splines not supported."), 10, 5);
b11729f1
WS
1237#endif
1238}
1239
213ad8e7
VZ
1240void MyCanvas::DrawGradients(wxDC& dc)
1241{
2c8f21f8
VZ
1242 static const int TEXT_HEIGHT = 15;
1243
213ad8e7 1244 // LHS: linear
2c8f21f8 1245 wxRect r(10, 10, 50, 50);
9a83f860 1246 dc.DrawText(wxT("wxRIGHT"), r.x, r.y);
2c8f21f8 1247 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1248 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxRIGHT);
1249
2c8f21f8 1250 r.Offset(0, r.height + 10);
9a83f860 1251 dc.DrawText(wxT("wxLEFT"), r.x, r.y);
2c8f21f8 1252 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1253 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxLEFT);
1254
2c8f21f8 1255 r.Offset(0, r.height + 10);
9a83f860 1256 dc.DrawText(wxT("wxDOWN"), r.x, r.y);
2c8f21f8 1257 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1258 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxDOWN);
1259
2c8f21f8 1260 r.Offset(0, r.height + 10);
9a83f860 1261 dc.DrawText(wxT("wxUP"), r.x, r.y);
2c8f21f8 1262 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1263 dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxUP);
1264
4ee4c7b9 1265 wxRect gfr = wxRect(r);
213ad8e7
VZ
1266
1267 // RHS: concentric
2c8f21f8 1268 r = wxRect(200, 10, 50, 50);
9a83f860 1269 dc.DrawText(wxT("Blue inside"), r.x, r.y);
2c8f21f8 1270 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1271 dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE);
1272
2c8f21f8 1273 r.Offset(0, r.height + 10);
9a83f860 1274 dc.DrawText(wxT("White inside"), r.x, r.y);
2c8f21f8 1275 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1276 dc.GradientFillConcentric(r, *wxWHITE, *wxBLUE);
1277
2c8f21f8 1278 r.Offset(0, r.height + 10);
9a83f860 1279 dc.DrawText(wxT("Blue in top left corner"), r.x, r.y);
2c8f21f8 1280 r.Offset(0, TEXT_HEIGHT);
213ad8e7
VZ
1281 dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE, wxPoint(0, 0));
1282
2c8f21f8 1283 r.Offset(0, r.height + 10);
9a83f860 1284 dc.DrawText(wxT("Blue in bottom right corner"), r.x, r.y);
2c8f21f8
VZ
1285 r.Offset(0, TEXT_HEIGHT);
1286 dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE, wxPoint(r.width, r.height));
5f77ee3b
VZ
1287
1288 // check that the area filled by the gradient is exactly the interior of
1289 // the rectangle
1290 r.x = 350;
1291 r.y = 30;
1292 dc.DrawText("The interior should be filled but", r.x, r.y);
1293 r.y += 15;
1294 dc.DrawText(" the red border should remain visible:", r.x, r.y);
1295 r.y += 15;
1296
1297 r.width =
1298 r.height = 50;
1299 wxRect r2 = r;
1300 r2.x += 60;
1301 wxRect r3 = r;
1302 r3.y += 60;
1303 wxRect r4 = r2;
1304 r4.y += 60;
ea92bb67 1305 dc.SetPen(*wxRED_PEN);
5f77ee3b
VZ
1306 dc.DrawRectangle(r);
1307 r.Deflate(1);
ea92bb67 1308 dc.GradientFillLinear(r, *wxGREEN, *wxBLACK, wxNORTH);
5f77ee3b
VZ
1309 dc.DrawRectangle(r2);
1310 r2.Deflate(1);
ea92bb67 1311 dc.GradientFillLinear(r2, *wxBLACK, *wxGREEN, wxSOUTH);
5f77ee3b
VZ
1312 dc.DrawRectangle(r3);
1313 r3.Deflate(1);
ea92bb67 1314 dc.GradientFillLinear(r3, *wxGREEN, *wxBLACK, wxEAST);
5f77ee3b
VZ
1315 dc.DrawRectangle(r4);
1316 r4.Deflate(1);
ea92bb67 1317 dc.GradientFillLinear(r4, *wxBLACK, *wxGREEN, wxWEST);
4ee4c7b9
VZ
1318
1319#if wxUSE_GRAPHICS_CONTEXT
1320 if (m_useContext)
1321 {
1322 wxGCDC &gdc = (wxGCDC&)dc;
1323 wxGraphicsContext *gc = gdc.GetGraphicsContext();
1324 wxGraphicsPath pth;
1325 wxGraphicsGradientStops stops;
1326
1327 gfr.Offset(0, gfr.height + 10);
1328 dc.DrawText(wxT("Linear Gradient with Stops"), gfr.x, gfr.y);
1329 gfr.Offset(0, TEXT_HEIGHT);
1330
ea92bb67 1331 stops = wxGraphicsGradientStops(*wxRED, *wxBLUE);
4ee4c7b9 1332 stops.Add(wxColour(255,255,0), 0.33f);
ea92bb67 1333 stops.Add(*wxGREEN, 0.67f);
4ee4c7b9
VZ
1334
1335 gc->SetBrush(gc->CreateLinearGradientBrush(gfr.x, gfr.y,
1336 gfr.x + gfr.width, gfr.y + gfr.height,
1337 stops));
1338 pth = gc->CreatePath();
1339 pth.MoveToPoint(gfr.x,gfr.y);
1340 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y);
1341 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y+gfr.height);
1342 pth.AddLineToPoint(gfr.x,gfr.y+gfr.height);
1343 pth.CloseSubpath();
1344 gc->FillPath(pth);
1345
1346 gfr.Offset(0, gfr.height + 10);
1347 dc.DrawText(wxT("Radial Gradient with Stops"), gfr.x, gfr.y);
1348 gfr.Offset(0, TEXT_HEIGHT);
1349
1350 gc->SetBrush(gc->CreateRadialGradientBrush(gfr.x + gfr.width / 2,
1351 gfr.y + gfr.height / 2,
1352 gfr.x + gfr.width / 2,
1353 gfr.y + gfr.height / 2,
1354 gfr.width / 2,
1355 stops));
1356 pth = gc->CreatePath();
1357 pth.MoveToPoint(gfr.x,gfr.y);
1358 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y);
1359 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y+gfr.height);
1360 pth.AddLineToPoint(gfr.x,gfr.y+gfr.height);
1361 pth.CloseSubpath();
1362 gc->FillPath(pth);
1363
1364 gfr.Offset(0, gfr.height + 10);
1365 dc.DrawText(wxT("Linear Gradient with Stops and Gaps"), gfr.x, gfr.y);
1366 gfr.Offset(0, TEXT_HEIGHT);
1367
ea92bb67 1368 stops = wxGraphicsGradientStops(*wxRED, *wxBLUE);
4ee4c7b9
VZ
1369 stops.Add(wxColour(255,255,0), 0.33f);
1370 stops.Add(wxTransparentColour, 0.33f);
1371 stops.Add(wxTransparentColour, 0.67f);
ea92bb67 1372 stops.Add(*wxGREEN, 0.67f);
4ee4c7b9
VZ
1373
1374 gc->SetBrush(gc->CreateLinearGradientBrush(gfr.x, gfr.y + gfr.height,
1375 gfr.x + gfr.width, gfr.y,
1376 stops));
1377 pth = gc->CreatePath();
1378 pth.MoveToPoint(gfr.x,gfr.y);
1379 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y);
1380 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y+gfr.height);
1381 pth.AddLineToPoint(gfr.x,gfr.y+gfr.height);
1382 pth.CloseSubpath();
1383 gc->FillPath(pth);
1384
1385 gfr.Offset(0, gfr.height + 10);
1386 dc.DrawText(wxT("Radial Gradient with Stops and Gaps"), gfr.x, gfr.y);
1387 gfr.Offset(0, TEXT_HEIGHT);
1388
1389 gc->SetBrush(gc->CreateRadialGradientBrush(gfr.x + gfr.width / 2,
1390 gfr.y + gfr.height / 2,
1391 gfr.x + gfr.width / 2,
1392 gfr.y + gfr.height / 2,
1393 gfr.width / 2,
1394 stops));
1395 pth = gc->CreatePath();
1396 pth.MoveToPoint(gfr.x,gfr.y);
1397 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y);
1398 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y+gfr.height);
1399 pth.AddLineToPoint(gfr.x,gfr.y+gfr.height);
1400 pth.CloseSubpath();
1401 gc->FillPath(pth);
1402
1403 gfr.Offset(0, gfr.height + 10);
1404 dc.DrawText(wxT("Gradients with Stops and Transparency"), gfr.x, gfr.y);
1405 gfr.Offset(0, TEXT_HEIGHT);
1406
ea92bb67
PC
1407 stops = wxGraphicsGradientStops(*wxRED, wxTransparentColour);
1408 stops.Add(*wxRED, 0.33f);
4ee4c7b9
VZ
1409 stops.Add(wxTransparentColour, 0.33f);
1410 stops.Add(wxTransparentColour, 0.67f);
ea92bb67
PC
1411 stops.Add(*wxBLUE, 0.67f);
1412 stops.Add(*wxBLUE, 1.0f);
4ee4c7b9
VZ
1413
1414 pth = gc->CreatePath();
1415 pth.MoveToPoint(gfr.x,gfr.y);
1416 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y);
1417 pth.AddLineToPoint(gfr.x + gfr.width,gfr.y+gfr.height);
1418 pth.AddLineToPoint(gfr.x,gfr.y+gfr.height);
1419 pth.CloseSubpath();
1420
1421 gc->SetBrush(gc->CreateRadialGradientBrush(gfr.x + gfr.width / 2,
1422 gfr.y + gfr.height / 2,
1423 gfr.x + gfr.width / 2,
1424 gfr.y + gfr.height / 2,
1425 gfr.width / 2,
1426 stops));
1427 gc->FillPath(pth);
1428
1429 stops = wxGraphicsGradientStops(wxColour(255,0,0, 128), wxColour(0,0,255, 128));
1430 stops.Add(wxColour(255,255,0,128), 0.33f);
1431 stops.Add(wxColour(0,255,0,128), 0.67f);
1432
1433 gc->SetBrush(gc->CreateLinearGradientBrush(gfr.x, gfr.y,
1434 gfr.x + gfr.width, gfr.y,
1435 stops));
1436 gc->FillPath(pth);
1437 }
1438#endif // wxUSE_GRAPHICS_CONTEXT
213ad8e7
VZ
1439}
1440
bc3cedfa
RR
1441void MyCanvas::DrawRegions(wxDC& dc)
1442{
9a83f860
VZ
1443 dc.DrawText(wxT("You should see a red rect partly covered by a cyan one ")
1444 wxT("on the left"), 10, 5);
1445 dc.DrawText(wxT("and 5 smileys from which 4 are partially clipped on the right"),
8e0e4b1b 1446 10, 5 + dc.GetCharHeight());
9a83f860
VZ
1447 dc.DrawText(wxT("The second copy should be identical but right part of it ")
1448 wxT("should be offset by 10 pixels."),
4cbcae16 1449 10, 5 + 2*dc.GetCharHeight());
8e0e4b1b 1450
9da8feef
WS
1451 DrawRegionsHelper(dc, 10, true);
1452 DrawRegionsHelper(dc, 350, false);
8e0e4b1b 1453}
c4218a74 1454
4cbcae16 1455void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime)
8e0e4b1b 1456{
4cbcae16
VZ
1457 wxCoord y = 100;
1458
8e0e4b1b 1459 dc.DestroyClippingRegion();
bc3cedfa
RR
1460 dc.SetBrush( *wxWHITE_BRUSH );
1461 dc.SetPen( *wxTRANSPARENT_PEN );
4cbcae16 1462 dc.DrawRectangle( x, y, 310, 310 );
c4218a74 1463
4cbcae16 1464 dc.SetClippingRegion( x + 10, y + 10, 100, 270 );
c4218a74 1465
bc3cedfa 1466 dc.SetBrush( *wxRED_BRUSH );
4cbcae16 1467 dc.DrawRectangle( x, y, 310, 310 );
c4218a74 1468
4cbcae16 1469 dc.SetClippingRegion( x + 10, y + 10, 100, 100 );
993f97ee 1470
993f97ee 1471 dc.SetBrush( *wxCYAN_BRUSH );
4cbcae16
VZ
1472 dc.DrawRectangle( x, y, 310, 310 );
1473
1474 dc.DestroyClippingRegion();
1475
1476 wxRegion region(x + 110, y + 20, 100, 270);
8a28bf76 1477#if !defined(__WXMOTIF__)
4cbcae16
VZ
1478 if ( !firstTime )
1479 region.Offset(10, 10);
4cae9a20 1480#endif
795b5a8b 1481 dc.SetDeviceClippingRegion(region);
c4218a74 1482
bc3cedfa 1483 dc.SetBrush( *wxGREY_BRUSH );
4cbcae16 1484 dc.DrawRectangle( x, y, 310, 310 );
c4218a74 1485
a1b806b9 1486 if (m_smile_bmp.IsOk())
5d25c050 1487 {
9da8feef
WS
1488 dc.DrawBitmap( m_smile_bmp, x + 150, y + 150, true );
1489 dc.DrawBitmap( m_smile_bmp, x + 130, y + 10, true );
1490 dc.DrawBitmap( m_smile_bmp, x + 130, y + 280, true );
1491 dc.DrawBitmap( m_smile_bmp, x + 100, y + 70, true );
1492 dc.DrawBitmap( m_smile_bmp, x + 200, y + 70, true );
5d25c050 1493 }
bc3cedfa
RR
1494}
1495
568708e2
VZ
1496void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
1497{
f31a4cb2 1498 wxPaintDC pdc(this);
8c6b0819
VZ
1499 Draw(pdc);
1500}
f31a4cb2 1501
5707e433 1502void MyCanvas::Draw(wxDC& pdc)
8c6b0819 1503{
f31a4cb2 1504#if wxUSE_GRAPHICS_CONTEXT
8a021e00 1505 wxGCDC gdc;
5707e433
VZ
1506 wxGraphicsRenderer* const renderer = wxGraphicsRenderer::
1507#if TEST_CAIRO_EVERYWHERE
1508 GetCairoRenderer()
8a021e00 1509#else
5707e433 1510 GetDefaultRenderer()
8a021e00 1511#endif
5707e433
VZ
1512 ;
1513
1514 wxGraphicsContext* context;
1515 if ( wxPaintDC *paintdc = wxDynamicCast(&pdc, wxPaintDC) )
1516 {
1517 context = renderer->CreateContext(*paintdc);
1518 }
1519 else if ( wxMemoryDC *memdc = wxDynamicCast(&pdc, wxMemoryDC) )
1520 {
1521 context = renderer->CreateContext(*memdc);
1522 }
1523#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
1524 else if ( wxMetafileDC *metadc = wxDynamicCast(&pdc, wxMetafileDC) )
1525 {
1526 context = renderer->CreateContext(*metadc);
1527 }
1528#endif
1529 else
1530 {
1531 wxFAIL_MSG( "Unknown wxDC kind" );
1532 return;
1533 }
1534
1535 gdc.SetGraphicsContext(context);
1536
f31a4cb2
SC
1537 wxDC &dc = m_useContext ? (wxDC&) gdc : (wxDC&) pdc ;
1538#else
1539 wxDC &dc = pdc ;
1540#endif
1541
568708e2 1542 PrepareDC(dc);
c4218a74 1543
568708e2
VZ
1544 m_owner->PrepareDC(dc);
1545
1546 dc.SetBackgroundMode( m_owner->m_backgroundMode );
a1b806b9 1547 if ( m_owner->m_backgroundBrush.IsOk() )
568708e2 1548 dc.SetBackground( m_owner->m_backgroundBrush );
a1b806b9 1549 if ( m_owner->m_colourForeground.IsOk() )
568708e2 1550 dc.SetTextForeground( m_owner->m_colourForeground );
a1b806b9 1551 if ( m_owner->m_colourBackground.IsOk() )
568708e2 1552 dc.SetTextBackground( m_owner->m_colourBackground );
4786aabd 1553
1edc9f45 1554 if ( m_owner->m_textureBackground) {
a1b806b9 1555 if ( ! m_owner->m_backgroundBrush.IsOk() ) {
de914436 1556 dc.SetBackground(wxBrush(wxColour(0, 128, 0)));
1edc9f45 1557 }
047473c9
RD
1558 }
1559
204dd9a7
VZ
1560 if ( m_clip )
1561 dc.SetClippingRegion(100, 100, 100, 100);
1562
e1208c31 1563 dc.Clear();
1edc9f45 1564
204dd9a7
VZ
1565 if ( m_owner->m_textureBackground )
1566 {
1edc9f45 1567 dc.SetPen(*wxMEDIUM_GREY_PEN);
204dd9a7 1568 for ( int i = 0; i < 200; i++ )
1edc9f45
RD
1569 dc.DrawLine(0, i*10, i*10, 0);
1570 }
1571
568708e2
VZ
1572 switch ( m_show )
1573 {
f65e33a3 1574 case File_ShowDefault:
568708e2
VZ
1575 DrawDefault(dc);
1576 break;
1e7fd311 1577
f65e33a3 1578 case File_ShowCircles:
f6bcfd97
BP
1579 DrawCircles(dc);
1580 break;
1581
f65e33a3 1582 case File_ShowSplines:
b11729f1
WS
1583 DrawSplines(dc);
1584 break;
1585
f65e33a3 1586 case File_ShowRegions:
bc3cedfa
RR
1587 DrawRegions(dc);
1588 break;
1589
f65e33a3 1590 case File_ShowText:
568708e2
VZ
1591 DrawText(dc);
1592 break;
1e7fd311 1593
f65e33a3 1594 case File_ShowLines:
568708e2 1595 DrawTestLines( 0, 100, 0, dc );
f6bcfd97
BP
1596 DrawTestLines( 0, 320, 1, dc );
1597 DrawTestLines( 0, 540, 2, dc );
1598 DrawTestLines( 0, 760, 6, dc );
568708e2 1599 break;
1e7fd311 1600
f65e33a3 1601 case File_ShowBrushes:
6386110d
VZ
1602 DrawTestBrushes(dc);
1603 break;
1604
f65e33a3 1605 case File_ShowPolygons:
6386110d 1606 DrawTestPoly(dc);
568708e2 1607 break;
1e7fd311 1608
f65e33a3 1609 case File_ShowMask:
e3b81044
VZ
1610 DrawImages(dc, Draw_Normal);
1611 break;
1612
f65e33a3 1613 case File_ShowMaskStretch:
e3b81044 1614 DrawImages(dc, Draw_Stretch);
568708e2 1615 break;
81278df2 1616
f65e33a3 1617 case File_ShowOps:
81278df2
VZ
1618 DrawWithLogicalOps(dc);
1619 break;
e3b81044 1620
f31a4cb2 1621#if wxUSE_GRAPHICS_CONTEXT
f65e33a3 1622 case File_ShowAlpha:
f31a4cb2
SC
1623 DrawAlpha(dc);
1624 break;
f65e33a3 1625 case File_ShowGraphics:
7a5c82b1
SC
1626 DrawGraphics(gdc.GetGraphicsContext());
1627 break;
f31a4cb2 1628#endif
213ad8e7 1629
f65e33a3 1630 case File_ShowGradients:
213ad8e7
VZ
1631 DrawGradients(dc);
1632 break;
e95c145c
WS
1633
1634 default:
1635 break;
568708e2 1636 }
b62c3631
RR
1637}
1638
bf0c00c6
RR
1639void MyCanvas::OnMouseMove(wxMouseEvent &event)
1640{
960a83cc 1641#if wxUSE_STATUSBAR
8a021e00
SC
1642 {
1643 wxClientDC dc(this);
1644 PrepareDC(dc);
1645 m_owner->PrepareDC(dc);
1646
1647 wxPoint pos = event.GetPosition();
1648 long x = dc.DeviceToLogicalX( pos.x );
1649 long y = dc.DeviceToLogicalY( pos.y );
1650 wxString str;
1651 str.Printf( wxT("Current mouse position: %d,%d"), (int)x, (int)y );
1652 m_owner->SetStatusText( str );
1653 }
4ee4c7b9 1654
8a021e00
SC
1655 if ( m_rubberBand )
1656 {
1657 int x,y, xx, yy ;
1658 event.GetPosition(&x,&y);
1659 CalcUnscrolledPosition( x, y, &xx, &yy );
1660 m_currentpoint = wxPoint( xx , yy ) ;
1661 wxRect newrect ( m_anchorpoint , m_currentpoint ) ;
1662
1663 wxClientDC dc( this ) ;
1664 PrepareDC( dc ) ;
1665
1666 wxDCOverlay overlaydc( m_overlay, &dc );
1667 overlaydc.Clear();
e630cd04 1668#ifdef __WXMAC__
8a021e00
SC
1669 dc.SetPen( *wxGREY_PEN );
1670 dc.SetBrush( wxColour( 192,192,192,64 ) );
1671#else
0856cb25 1672 dc.SetPen( wxPen( *wxLIGHT_GREY, 2 ) );
8a021e00
SC
1673 dc.SetBrush( *wxTRANSPARENT_BRUSH );
1674#endif
1675 dc.DrawRectangle( newrect );
1676 }
960a83cc
WS
1677#else
1678 wxUnusedVar(event);
1679#endif // wxUSE_STATUSBAR
bf0c00c6
RR
1680}
1681
8a021e00
SC
1682void MyCanvas::OnMouseDown(wxMouseEvent &event)
1683{
4ee4c7b9
VZ
1684 int x,y,xx,yy ;
1685 event.GetPosition(&x,&y);
8a021e00
SC
1686 CalcUnscrolledPosition( x, y, &xx, &yy );
1687 m_anchorpoint = wxPoint( xx , yy ) ;
1688 m_currentpoint = m_anchorpoint ;
1689 m_rubberBand = true ;
1690 CaptureMouse() ;
1691}
1692
1693void MyCanvas::OnMouseUp(wxMouseEvent &event)
1694{
1695 if ( m_rubberBand )
1696 {
5f0d3411 1697 ReleaseMouse();
8a021e00
SC
1698 {
1699 wxClientDC dc( this );
1700 PrepareDC( dc );
1701 wxDCOverlay overlaydc( m_overlay, &dc );
1702 overlaydc.Clear();
1703 }
1704 m_overlay.Reset();
1705 m_rubberBand = false;
1706
8fa11bb2 1707 wxPoint endpoint = CalcUnscrolledPosition(event.GetPosition());
8a021e00 1708
8fa11bb2
VZ
1709 // Don't pop up the message box if nothing was actually selected.
1710 if ( endpoint != m_anchorpoint )
1711 {
1712 wxLogMessage("Selected rectangle from (%d, %d) to (%d, %d)",
1713 m_anchorpoint.x, m_anchorpoint.y,
1714 endpoint.x, endpoint.y);
1715 }
8a021e00
SC
1716 }
1717}
1718
b62c3631
RR
1719// ----------------------------------------------------------------------------
1720// MyFrame
1721// ----------------------------------------------------------------------------
1722
be5a51fb 1723// the event tables connect the wxWidgets events with the functions (event
b62c3631
RR
1724// handlers) which process them. It can be also done at run-time, but for the
1725// simple menu events like this the static method is much simpler.
1726BEGIN_EVENT_TABLE(MyFrame, wxFrame)
568708e2
VZ
1727 EVT_MENU (File_Quit, MyFrame::OnQuit)
1728 EVT_MENU (File_About, MyFrame::OnAbout)
204dd9a7 1729 EVT_MENU (File_Clip, MyFrame::OnClip)
f31a4cb2
SC
1730#if wxUSE_GRAPHICS_CONTEXT
1731 EVT_MENU (File_GraphicContext, MyFrame::OnGraphicContext)
1732#endif
8c6b0819
VZ
1733 EVT_MENU (File_Copy, MyFrame::OnCopy)
1734 EVT_MENU (File_Save, MyFrame::OnSave)
568708e2
VZ
1735
1736 EVT_MENU_RANGE(MenuShow_First, MenuShow_Last, MyFrame::OnShow)
1737
b62c3631
RR
1738 EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption)
1739END_EVENT_TABLE()
1740
aba99005
RR
1741// frame constructor
1742MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
9da8feef 1743 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size,
c4218a74 1744 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
aba99005
RR
1745{
1746 // set the frame icon
3cb332c1 1747 SetIcon(wxICON(sample));
aba99005
RR
1748
1749 wxMenu *menuFile = new wxMenu;
9a83f860
VZ
1750 menuFile->Append(File_ShowDefault, wxT("&Default screen\tF1"));
1751 menuFile->Append(File_ShowText, wxT("&Text screen\tF2"));
1752 menuFile->Append(File_ShowLines, wxT("&Lines screen\tF3"));
1753 menuFile->Append(File_ShowBrushes, wxT("&Brushes screen\tF4"));
1754 menuFile->Append(File_ShowPolygons, wxT("&Polygons screen\tF5"));
1755 menuFile->Append(File_ShowMask, wxT("&Mask screen\tF6"));
1756 menuFile->Append(File_ShowMaskStretch, wxT("1/&2 scaled mask\tShift-F6"));
1757 menuFile->Append(File_ShowOps, wxT("&Raster operations screen\tF7"));
1758 menuFile->Append(File_ShowRegions, wxT("Re&gions screen\tF8"));
1759 menuFile->Append(File_ShowCircles, wxT("&Circles screen\tF9"));
f31a4cb2 1760#if wxUSE_GRAPHICS_CONTEXT
9a83f860 1761 menuFile->Append(File_ShowAlpha, wxT("&Alpha screen\tF10"));
f31a4cb2 1762#endif
8c6b0819 1763 menuFile->Append(File_ShowSplines, wxT("Spl&ines screen\tF11"));
9a83f860 1764 menuFile->Append(File_ShowGradients, wxT("&Gradients screen\tF12"));
7a5c82b1 1765#if wxUSE_GRAPHICS_CONTEXT
9a83f860 1766 menuFile->Append(File_ShowGraphics, wxT("&Graphics screen"));
7a5c82b1 1767#endif
568708e2 1768 menuFile->AppendSeparator();
9a83f860 1769 menuFile->AppendCheckItem(File_Clip, wxT("&Clip\tCtrl-C"), wxT("Clip/unclip drawing"));
f31a4cb2 1770#if wxUSE_GRAPHICS_CONTEXT
9a83f860 1771 menuFile->AppendCheckItem(File_GraphicContext, wxT("&Use GraphicContext\tCtrl-Y"), wxT("Use GraphicContext"));
f31a4cb2 1772#endif
204dd9a7 1773 menuFile->AppendSeparator();
8c6b0819
VZ
1774#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
1775 menuFile->Append(File_Copy, wxT("Copy to clipboard"));
1776#endif
1777 menuFile->Append(File_Save, wxT("&Save...\tCtrl-S"), wxT("Save drawing to file"));
1778 menuFile->AppendSeparator();
2d143b66 1779 menuFile->Append(File_About, wxT("&About\tCtrl-A"), wxT("Show about dialog"));
aba99005 1780 menuFile->AppendSeparator();
9a83f860 1781 menuFile->Append(File_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
0f0c61d0 1782
aba99005 1783 wxMenu *menuMapMode = new wxMenu;
9a83f860
VZ
1784 menuMapMode->Append( MapMode_Text, wxT("&TEXT map mode") );
1785 menuMapMode->Append( MapMode_Lometric, wxT("&LOMETRIC map mode") );
1786 menuMapMode->Append( MapMode_Twips, wxT("T&WIPS map mode") );
1787 menuMapMode->Append( MapMode_Points, wxT("&POINTS map mode") );
1788 menuMapMode->Append( MapMode_Metric, wxT("&METRIC map mode") );
0f0c61d0 1789
aba99005 1790 wxMenu *menuUserScale = new wxMenu;
9a83f860
VZ
1791 menuUserScale->Append( UserScale_StretchHoriz, wxT("Stretch &horizontally\tCtrl-H") );
1792 menuUserScale->Append( UserScale_ShrinkHoriz, wxT("Shrin&k horizontally\tCtrl-G") );
1793 menuUserScale->Append( UserScale_StretchVertic, wxT("Stretch &vertically\tCtrl-V") );
1794 menuUserScale->Append( UserScale_ShrinkVertic, wxT("&Shrink vertically\tCtrl-W") );
0f0c61d0 1795 menuUserScale->AppendSeparator();
9a83f860 1796 menuUserScale->Append( UserScale_Restore, wxT("&Restore to normal\tCtrl-0") );
0f0c61d0 1797
aba99005 1798 wxMenu *menuAxis = new wxMenu;
9a83f860
VZ
1799 menuAxis->AppendCheckItem( AxisMirror_Horiz, wxT("Mirror horizontally\tCtrl-M") );
1800 menuAxis->AppendCheckItem( AxisMirror_Vertic, wxT("Mirror vertically\tCtrl-N") );
0f0c61d0 1801
aba99005 1802 wxMenu *menuLogical = new wxMenu;
9a83f860
VZ
1803 menuLogical->Append( LogicalOrigin_MoveDown, wxT("Move &down\tCtrl-D") );
1804 menuLogical->Append( LogicalOrigin_MoveUp, wxT("Move &up\tCtrl-U") );
1805 menuLogical->Append( LogicalOrigin_MoveLeft, wxT("Move &right\tCtrl-L") );
1806 menuLogical->Append( LogicalOrigin_MoveRight, wxT("Move &left\tCtrl-R") );
fb576291 1807 menuLogical->AppendSeparator();
9a83f860
VZ
1808 menuLogical->Append( LogicalOrigin_Set, wxT("Set to (&100, 100)\tShift-Ctrl-1") );
1809 menuLogical->Append( LogicalOrigin_Restore, wxT("&Restore to normal\tShift-Ctrl-0") );
aba99005 1810
0f0c61d0 1811 wxMenu *menuColour = new wxMenu;
960a83cc 1812#if wxUSE_COLOURDLG
9a83f860
VZ
1813 menuColour->Append( Colour_TextForeground, wxT("Text &foreground...") );
1814 menuColour->Append( Colour_TextBackground, wxT("Text &background...") );
1815 menuColour->Append( Colour_Background, wxT("Background &colour...") );
960a83cc 1816#endif // wxUSE_COLOURDLG
9a83f860
VZ
1817 menuColour->AppendCheckItem( Colour_BackgroundMode, wxT("&Opaque/transparent\tCtrl-B") );
1818 menuColour->AppendCheckItem( Colour_TextureBackgound, wxT("Draw textured back&ground\tCtrl-T") );
0f0c61d0 1819
aba99005
RR
1820 // now append the freshly created menu to the menu bar...
1821 wxMenuBar *menuBar = new wxMenuBar;
9a83f860
VZ
1822 menuBar->Append(menuFile, wxT("&File"));
1823 menuBar->Append(menuMapMode, wxT("&Mode"));
1824 menuBar->Append(menuUserScale, wxT("&Scale"));
1825 menuBar->Append(menuAxis, wxT("&Axis"));
1826 menuBar->Append(menuLogical, wxT("&Origin"));
1827 menuBar->Append(menuColour, wxT("&Colours"));
aba99005
RR
1828
1829 // ... and attach this menu bar to the frame
1830 SetMenuBar(menuBar);
1831
960a83cc 1832#if wxUSE_STATUSBAR
aba99005 1833 CreateStatusBar(2);
9a83f860 1834 SetStatusText(wxT("Welcome to wxWidgets!"));
960a83cc 1835#endif // wxUSE_STATUSBAR
0f0c61d0 1836
aba99005
RR
1837 m_mapMode = wxMM_TEXT;
1838 m_xUserScale = 1.0;
1839 m_yUserScale = 1.0;
1840 m_xLogicalOrigin = 0;
1841 m_yLogicalOrigin = 0;
0f0c61d0 1842 m_xAxisReversed =
9da8feef 1843 m_yAxisReversed = false;
0f0c61d0 1844 m_backgroundMode = wxSOLID;
4ee4c7b9
VZ
1845 m_colourForeground = *wxBLACK;
1846 m_colourBackground = *wxLIGHT_GREY;
9da8feef 1847 m_textureBackground = false;
aba99005 1848
b62c3631 1849 m_canvas = new MyCanvas( this );
b97fa7cf 1850 m_canvas->SetScrollbars( 10, 10, 100, 240 );
b62c3631 1851}
aba99005
RR
1852
1853// event handlers
1854
1855void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
1856{
9da8feef
WS
1857 // true is to force the frame to close
1858 Close(true);
aba99005
RR
1859}
1860
1861void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
1862{
1863 wxString msg;
c916e13b
RR
1864 msg.Printf( wxT("This is the about dialog of the drawing sample.\n")
1865 wxT("This sample tests various primitive drawing functions\n")
6386110d 1866 wxT("(without any attempts to prevent flicker).\n")
c916e13b 1867 wxT("Copyright (c) Robert Roebling 1999")
aba99005
RR
1868 );
1869
9a83f860 1870 wxMessageBox(msg, wxT("About Drawing"), wxOK | wxICON_INFORMATION, this);
aba99005
RR
1871}
1872
204dd9a7
VZ
1873void MyFrame::OnClip(wxCommandEvent& event)
1874{
1875 m_canvas->Clip(event.IsChecked());
1876}
1877
f31a4cb2
SC
1878#if wxUSE_GRAPHICS_CONTEXT
1879void MyFrame::OnGraphicContext(wxCommandEvent& event)
1880{
1881 m_canvas->UseGraphicContext(event.IsChecked());
1882}
1883#endif
1884
8c6b0819
VZ
1885void MyFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
1886{
1887#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
1888 wxMetafileDC dc;
1889 if (!dc.IsOk())
1890 return;
1891 m_canvas->Draw(dc);
1892 wxMetafile *mf = dc.Close();
1893 if (!mf)
1894 return;
1895 mf->SetClipboard();
1896 delete mf;
1897#endif
1898}
1899
1900void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event))
1901{
1902 wxFileDialog dlg(this, wxT("Save as bitmap"), wxT(""), wxT(""),
1903#if wxUSE_LIBPNG
1904 wxT("PNG image (*.png)|*.png;*.PNG|")
1905#endif
1906 wxT("Bitmap image (*.bmp)|*.bmp;*.BMP"),
1907 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1908 if (dlg.ShowModal() == wxID_OK)
1909 {
1910 wxBitmap bmp(500, 800);
1911 wxMemoryDC mdc(bmp);
1912 m_canvas->Draw(mdc);
1913 bmp.ConvertToImage().SaveFile(dlg.GetPath());
1914 }
1915}
1916
568708e2
VZ
1917void MyFrame::OnShow(wxCommandEvent& event)
1918{
f65e33a3 1919 m_canvas->ToShow(event.GetId());
568708e2
VZ
1920}
1921
1922void MyFrame::OnOption(wxCommandEvent& event)
aba99005 1923{
3ca6a5f0 1924 switch (event.GetId())
aba99005
RR
1925 {
1926 case MapMode_Text:
b9857632 1927 m_mapMode = wxMM_TEXT;
0f0c61d0 1928 break;
aba99005
RR
1929 case MapMode_Lometric:
1930 m_mapMode = wxMM_LOMETRIC;
0f0c61d0
VZ
1931 break;
1932 case MapMode_Twips:
aba99005 1933 m_mapMode = wxMM_TWIPS;
0f0c61d0
VZ
1934 break;
1935 case MapMode_Points:
aba99005 1936 m_mapMode = wxMM_POINTS;
0f0c61d0
VZ
1937 break;
1938 case MapMode_Metric:
aba99005 1939 m_mapMode = wxMM_METRIC;
0f0c61d0
VZ
1940 break;
1941
1942 case LogicalOrigin_MoveDown:
1943 m_yLogicalOrigin += 10;
1944 break;
1945 case LogicalOrigin_MoveUp:
1946 m_yLogicalOrigin -= 10;
1947 break;
1948 case LogicalOrigin_MoveLeft:
1949 m_xLogicalOrigin += 10;
1950 break;
1951 case LogicalOrigin_MoveRight:
1952 m_xLogicalOrigin -= 10;
1953 break;
fb576291
VZ
1954 case LogicalOrigin_Set:
1955 m_xLogicalOrigin =
1956 m_yLogicalOrigin = -100;
1957 break;
1958 case LogicalOrigin_Restore:
1959 m_xLogicalOrigin =
1960 m_yLogicalOrigin = 0;
1961 break;
0f0c61d0
VZ
1962
1963 case UserScale_StretchHoriz:
1964 m_xUserScale *= 1.10;
1965 break;
1966 case UserScale_ShrinkHoriz:
1967 m_xUserScale /= 1.10;
1968 break;
1969 case UserScale_StretchVertic:
1970 m_yUserScale *= 1.10;
1971 break;
1972 case UserScale_ShrinkVertic:
1973 m_yUserScale /= 1.10;
1974 break;
1975 case UserScale_Restore:
1976 m_xUserScale =
1977 m_yUserScale = 1.0;
1978 break;
1979
1980 case AxisMirror_Vertic:
1981 m_yAxisReversed = !m_yAxisReversed;
1982 break;
1983 case AxisMirror_Horiz:
1984 m_xAxisReversed = !m_xAxisReversed;
1985 break;
1986
960a83cc 1987#if wxUSE_COLOURDLG
0f0c61d0
VZ
1988 case Colour_TextForeground:
1989 m_colourForeground = SelectColour();
1990 break;
1991 case Colour_TextBackground:
1992 m_colourBackground = SelectColour();
1993 break;
1994 case Colour_Background:
1995 {
1996 wxColour col = SelectColour();
a1b806b9 1997 if ( col.IsOk() )
0f0c61d0
VZ
1998 {
1999 m_backgroundBrush.SetColour(col);
2000 }
2001 }
2002 break;
960a83cc
WS
2003#endif // wxUSE_COLOURDLG
2004
0f0c61d0
VZ
2005 case Colour_BackgroundMode:
2006 m_backgroundMode = m_backgroundMode == wxSOLID ? wxTRANSPARENT
2007 : wxSOLID;
2008 break;
2009
1edc9f45
RD
2010 case Colour_TextureBackgound:
2011 m_textureBackground = ! m_textureBackground;
2012 break;
2013
0f0c61d0
VZ
2014 default:
2015 // skip Refresh()
2016 return;
aba99005 2017 }
0f0c61d0 2018
1e7fd311 2019 m_canvas->Refresh();
aba99005
RR
2020}
2021
220af862 2022void MyFrame::PrepareDC(wxDC& dc)
aba99005 2023{
0f0c61d0 2024 dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin );
428db2ea 2025 dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed );
fb576291
VZ
2026 dc.SetUserScale( m_xUserScale, m_yUserScale );
2027 dc.SetMapMode( m_mapMode );
220af862
VZ
2028}
2029
960a83cc 2030#if wxUSE_COLOURDLG
220af862 2031wxColour MyFrame::SelectColour()
0f0c61d0
VZ
2032{
2033 wxColour col;
2034 wxColourData data;
2035 wxColourDialog dialog(this, &data);
2036
2037 if ( dialog.ShowModal() == wxID_OK )
2038 {
428db2ea 2039 col = dialog.GetColourData().GetColour();
0f0c61d0
VZ
2040 }
2041
2042 return col;
aba99005 2043}
960a83cc 2044#endif // wxUSE_COLOURDLG