1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: shows and tests wxDC features
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "drawing.cpp"
21 #pragma interface "drawing.cpp"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
31 // for all others, include the necessary headers (this file is usually all you
32 // need because it includes almost all "standard" wxWindows headers
37 #include "wx/colordlg.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
42 // the application icon
43 #if defined(__WXGTK__) || defined(__WXMOTIF__)
44 #include "mondrian.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // Define a new application type, each program should derive a class from wxApp
52 class MyApp
: public wxApp
55 // override base class virtuals
56 // ----------------------------
58 // this one is called on application startup and is a good place for the app
59 // initialization (doing it here and not in the ctor allows to have an error
60 // return: if OnInit() returns false, the application terminates)
61 virtual bool OnInit();
66 // Define a new frame type: this is going to be our main frame
67 class MyFrame
: public wxFrame
71 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
73 // event handlers (these functions should _not_ be virtual)
74 void OnQuit(wxCommandEvent
& event
);
75 void OnAbout(wxCommandEvent
& event
);
76 void OnOption(wxCommandEvent
&event
);
78 wxColour
SelectColour();
79 void PrepareDC(wxDC
& dc
);
89 wxColour m_colourForeground
, // these are _text_ colours
91 wxBrush m_backgroundBrush
;
95 // any class wishing to process wxWindows events must use this macro
99 // define a scrollable canvas for drawing onto
100 class MyCanvas
: public wxScrolledWindow
103 MyCanvas( MyFrame
*parent
);
105 void DrawTestPoly( int x
, int y
, wxDC
&dc
,int transparent
);
106 void DrawTestLines( int x
, int y
, int width
, wxDC
&dc
);
107 void OnPaint(wxPaintEvent
&event
);
108 void OnMouseMove(wxMouseEvent
&event
);
114 DECLARE_EVENT_TABLE()
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 // IDs for the controls and the menu commands
130 MapMode_Text
= MenuOption_First
,
136 UserScale_StretchHoriz
,
137 UserScale_ShrinkHoriz
,
138 UserScale_StretchVertic
,
139 UserScale_ShrinkVertic
,
145 LogicalOrigin_MoveDown
,
146 LogicalOrigin_MoveUp
,
147 LogicalOrigin_MoveLeft
,
148 LogicalOrigin_MoveRight
,
150 Colour_TextForeground
,
151 Colour_TextBackground
,
153 Colour_BackgroundMode
,
155 MenuOption_Last
= Colour_BackgroundMode
158 // ----------------------------------------------------------------------------
159 // event tables and other macros for wxWindows
160 // ----------------------------------------------------------------------------
163 // Create a new application object: this macro will allow wxWindows to create
164 // the application object during program execution (it's better than using a
165 // static object for many reasons) and also declares the accessor function
166 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
170 // ============================================================================
172 // ============================================================================
174 // ----------------------------------------------------------------------------
175 // the application class
176 // ----------------------------------------------------------------------------
178 // `Main program' equivalent: the program execution "starts" here
181 // Create the main application window
182 MyFrame
*frame
= new MyFrame("Drawing sample",
183 wxPoint(50, 50), wxSize(550, 340));
185 // Show it and tell the application that it's our main window
189 // success: wxApp::OnRun() will be called which will enter the main message
190 // loop and the application will run. If we returned FALSE here, the
191 // application would exit immediately.
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 // the event tables connect the wxWindows events with the functions (event
200 // handlers) which process them.
201 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
202 EVT_PAINT (MyCanvas::OnPaint
)
203 EVT_MOTION (MyCanvas::OnMouseMove
)
206 MyCanvas::MyCanvas( MyFrame
*parent
) : wxScrolledWindow( parent
)
211 //draw a polygon and an overlapping rectangle
212 //is transparent is 1, the fill pattern are made transparent
213 //is transparent is 2, the fill pattern are made transparent but inversed
214 //is transparent is 0 the text for and background color will be used to represent/map
215 //the colors of the monochrome bitmap pixels to the fillpattern
217 //i miss_used the the menu items for setting so called back and fore ground color
218 //just to show how the those colors do influence the fillpatterns
219 //just play with those,
221 //variations are endless using other logical functions
222 void MyCanvas::DrawTestPoly( int x
, int y
,wxDC
&dc
,int transparent
)
227 //this if run from ide project file
228 sprintf(pathfile
,"./drawing/pat%i.bmp",4);
229 wxBitmap
* nonMonoBitmap4
= new wxBitmap(32,32,-1);
230 nonMonoBitmap4
->LoadFile(pathfile
,wxBITMAP_TYPE_BMP
);
232 sprintf(pathfile
,"./drawing/pat%i.bmp",36);
233 wxBitmap
* nonMonoBitmap36
= new wxBitmap(32,32,-1);
234 nonMonoBitmap36
->LoadFile(pathfile
,wxBITMAP_TYPE_BMP
);
236 sprintf(pathfile
,"./pat%i.bmp",4);
237 wxBitmap
* nonMonoBitmap4
= new wxBitmap(32,32,-1);
238 nonMonoBitmap4
->LoadFile(pathfile
,wxBITMAP_TYPE_BMP
);
240 sprintf(pathfile
,"./pat%i.bmp",36);
241 wxBitmap
* nonMonoBitmap36
= new wxBitmap(32,32,-1);
242 nonMonoBitmap36
->LoadFile(pathfile
,wxBITMAP_TYPE_BMP
);
245 if ( !nonMonoBitmap4
->Ok() || !nonMonoBitmap36
->Ok() )
247 static bool s_errorGiven
= FALSE
;
251 wxLogError("Couldn't find bitmap files near the program file, "
252 "please copy them there.");
258 //set mask to monochrome bitmap based on color bitmap
259 wxColour
white("WHITE");
260 wxPen _Pen
= wxPen(white
,1,wxSOLID
);
261 wxColour
black("BLACK");
263 wxMask
* monochrome_mask4
= new wxMask(*nonMonoBitmap4
,black
);
264 nonMonoBitmap4
->SetMask(monochrome_mask4
);
266 wxMask
* monochrome_mask36
= new wxMask(*nonMonoBitmap36
,black
);
267 nonMonoBitmap36
->SetMask(monochrome_mask36
);
269 wxBrush
* _brush4
= new wxBrush(*nonMonoBitmap4
);
270 wxBrush
* _brush36
= new wxBrush(*nonMonoBitmap36
);
273 todraw
[0].x
=(long)x
+100;
274 todraw
[0].y
=(long)y
+100;
275 todraw
[1].x
=(long)x
+300;
276 todraw
[1].y
=(long)y
+100;
277 todraw
[2].x
=(long)x
+300;
278 todraw
[2].y
=(long)y
+300;
279 todraw
[3].x
=(long)x
+150;
280 todraw
[3].y
=(long)y
+350;
281 todraw
[4].x
=(long)x
+100;
282 todraw
[4].y
=(long)y
+300;
300 dc
.SetPen( wxPen( "black", 4, wxSOLID
) );
301 dc
.SetBrush( *_brush4
);
302 dc
.SetTextForeground(*wxGREEN
);
303 // dc.SetTextBackground(*wxBLUE);
304 dc
.SetTextBackground(m_owner
->m_colourForeground
);
305 dc
.SetLogicalFunction(wxCOPY
);
306 dc
.DrawPolygon(5,todraw
,0,0,wxWINDING_RULE
);
308 //don't understand hwo but the outline is also depending on logicalfunction
309 dc
.SetPen( wxPen( "red", 4, wxSOLID
) );
310 dc
.SetBrush( *_brush36
);
311 dc
.SetTextForeground(*wxCYAN
);
312 // dc.SetTextBackground(*wxRED);
313 dc
.SetTextBackground(m_owner
->m_colourBackground
);
314 dc
.SetLogicalFunction(wxCOPY
);
315 dc
.DrawRectangle( x
+10, y
+10, 200, 200 );
316 dc
.SetBrush(wxNullBrush
);
317 dc
.SetPen(wxNullPen
);
320 case 1: //now with transparent fillpatterns
323 wxBitmap
* _blitbitmap
= new wxBitmap(600,400);
324 wxMemoryDC
* _memDC
= new wxMemoryDC();
325 // wxBrush _clearbrush(*wxGREEN,wxSOLID);
326 wxBrush
_clearbrush(*wxBLACK
,wxSOLID
);
327 _memDC
->SelectObject(*_blitbitmap
);
328 _memDC
->BeginDrawing();
329 _memDC
->SetBackground(_clearbrush
);
331 _memDC
->SetBackground(wxNullBrush
);
333 _memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
334 _memDC
->SetBrush( wxNullBrush
);
335 _memDC
->SetBrush( *_brush4
);
336 _memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
337 _memDC
->SetTextBackground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
338 _memDC
->SetLogicalFunction(wxAND_INVERT
);
340 // BLACK OUT the opaque pixels and leave the rest as is
341 _memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
343 // Set background and foreground colors for fill pattern
344 //the previous blacked out pixels are now merged with the layer color
345 //while the non blacked out pixels stay as they are.
346 _memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
348 //now define what will be the color of the fillpattern parts that are not transparent
349 // _memDC->SetTextBackground(*wxBLUE);
350 _memDC
->SetTextBackground(m_owner
->m_colourForeground
);
351 _memDC
->SetLogicalFunction(wxOR
);
354 //don't understand how but the outline is also depending on logicalfunction
355 _memDC
->SetPen( wxPen( "red", 4, wxSOLID
) );
356 _memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
358 _memDC
->SetLogicalFunction(wxCOPY
);
360 _memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
361 _memDC
->SetBrush( wxNullBrush
);
362 _memDC
->SetBrush( *_brush36
);
363 _memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
364 _memDC
->SetTextBackground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
365 _memDC
->SetLogicalFunction(wxAND_INVERT
);
367 _memDC
->DrawRectangle( 10, 10, 200, 200 );
369 // Set background and foreground colors for fill pattern
370 //the previous blacked out pixels are now merged with the layer color
371 //while the non blacked out pixels stay as they are.
372 _memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
373 //now define what will be the color of the fillpattern parts that are not transparent
374 // _memDC->SetTextBackground(*wxRED);
375 _memDC
->SetTextBackground(m_owner
->m_colourBackground
);
376 _memDC
->SetLogicalFunction(wxOR
);
378 //don't understand how but the outline is also depending on logicalfunction
379 _memDC
->SetPen( wxPen( "yellow", 4, wxSOLID
) );
380 _memDC
->DrawRectangle( 10, 10, 200, 200 );
382 _memDC
->SetBrush(wxNullBrush
);
383 _memDC
->SetPen(wxNullPen
);
385 _memDC
->EndDrawing();
386 dc
.Blit(x
,y
,600,400,_memDC
,0,0,wxCOPY
);
391 case 2: //now with transparent inversed fillpatterns
393 wxBitmap
* _blitbitmap
= new wxBitmap(600,400);
394 wxMemoryDC
* _memDC
= new wxMemoryDC();
395 wxBrush
_clearbrush(*wxWHITE
,wxSOLID
);
396 _memDC
->SelectObject(*_blitbitmap
);
397 _memDC
->BeginDrawing();
398 _memDC
->SetBackground(_clearbrush
);
400 _memDC
->SetBackground(wxNullBrush
);
402 _memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
403 _memDC
->SetBrush( *_brush4
);
404 _memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
405 _memDC
->SetTextForeground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
406 _memDC
->SetLogicalFunction(wxAND_INVERT
);
408 // BLACK OUT the opaque pixels and leave the rest as is
409 _memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
411 // Set background and foreground colors for fill pattern
412 //the previous blacked out pixels are now merged with the layer color
413 //while the non blacked out pixels stay as they are.
414 _memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
416 //now define what will be the color of the fillpattern parts that are not transparent
417 _memDC
->SetTextForeground(m_owner
->m_colourForeground
);
418 _memDC
->SetLogicalFunction(wxOR
);
421 //don't understand how but the outline is also depending on logicalfunction
422 _memDC
->SetPen( wxPen( "red", 4, wxSOLID
) );
423 _memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
425 _memDC
->SetLogicalFunction(wxCOPY
);
427 _memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
428 _memDC
->SetBrush( *_brush36
);
429 _memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
430 _memDC
->SetTextForeground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
431 _memDC
->SetLogicalFunction(wxAND_INVERT
);
433 _memDC
->DrawRectangle( 10,10, 200, 200 );
435 // Set background and foreground colors for fill pattern
436 //the previous blacked out pixels are now merged with the layer color
437 //while the non blacked out pixels stay as they are.
438 _memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
439 //now define what will be the color of the fillpattern parts that are not transparent
440 _memDC
->SetTextForeground(m_owner
->m_colourBackground
);
441 _memDC
->SetLogicalFunction(wxOR
);
443 //don't understand how but the outline is also depending on logicalfunction
444 _memDC
->SetPen( wxPen( "yellow", 4, wxSOLID
) );
445 _memDC
->DrawRectangle( 10, 10, 200, 200 );
447 _memDC
->SetBrush(wxNullBrush
);
448 _memDC
->SetPen(wxNullPen
);
449 dc
.Blit(x
,y
,600,400,_memDC
,0,0,wxCOPY
);
459 void MyCanvas::DrawTestLines( int x
, int y
, int width
, wxDC
&dc
)
461 dc
.SetPen( wxPen( "black", width
, wxSOLID
) );
462 dc
.SetBrush( *wxRED_BRUSH
);
463 dc
.DrawRectangle( x
+10, y
+10, 100, 190 );
465 dc
.SetPen( wxPen( "black", width
, wxSOLID
) );
466 dc
.DrawLine( x
+20, y
+20, 100, y
+20 );
467 dc
.SetPen( wxPen( "black", width
, wxDOT
) );
468 dc
.DrawLine( x
+20, y
+30, 100, y
+30 );
469 dc
.SetPen( wxPen( "black", width
, wxSHORT_DASH
) );
470 dc
.DrawLine( x
+20, y
+40, 100, y
+40 );
471 dc
.SetPen( wxPen( "black", width
, wxLONG_DASH
) );
472 dc
.DrawLine( x
+20, y
+50, 100, y
+50 );
473 dc
.SetPen( wxPen( "black", width
, wxDOT_DASH
) );
474 dc
.DrawLine( x
+20, y
+60, 100, y
+60 );
476 dc
.SetPen( wxPen( "black", width
, wxBDIAGONAL_HATCH
) );
477 dc
.DrawLine( x
+20, y
+70, 100, y
+70 );
478 dc
.SetPen( wxPen( "black", width
, wxCROSSDIAG_HATCH
) );
479 dc
.DrawLine( x
+20, y
+80, 100, y
+80 );
480 dc
.SetPen( wxPen( "black", width
, wxFDIAGONAL_HATCH
) );
481 dc
.DrawLine( x
+20, y
+90, 100, y
+90 );
482 dc
.SetPen( wxPen( "black", width
, wxCROSS_HATCH
) );
483 dc
.DrawLine( x
+20, y
+100, 100, y
+100 );
484 dc
.SetPen( wxPen( "black", width
, wxHORIZONTAL_HATCH
) );
485 dc
.DrawLine( x
+20, y
+110, 100, y
+110 );
486 dc
.SetPen( wxPen( "black", width
, wxVERTICAL_HATCH
) );
487 dc
.DrawLine( x
+20, y
+120, 100, y
+120 );
489 wxPen
ud( "black", width
, wxUSER_DASH
);
492 ud
.SetDashes( 1, dash1
);
493 dc
.DrawLine( x
+20, y
+140, 100, y
+140 );
495 ud
.SetDashes( 1, dash1
);
496 dc
.DrawLine( x
+20, y
+150, 100, y
+150 );
498 ud
.SetDashes( 1, dash1
);
499 dc
.DrawLine( x
+20, y
+160, 100, y
+160 );
501 ud
.SetDashes( 1, dash1
);
502 dc
.DrawLine( x
+20, y
+170, 100, y
+170 );
506 void MyCanvas::OnPaint(wxPaintEvent
&WXUNUSED(event
))
510 m_owner
->PrepareDC(dc
);
512 dc
.SetBackgroundMode( m_owner
->m_backgroundMode
);
513 if ( m_owner
->m_backgroundBrush
.Ok() )
514 dc
.SetBackground( m_owner
->m_backgroundBrush
);
515 if ( m_owner
->m_colourForeground
.Ok() )
516 dc
.SetTextForeground( m_owner
->m_colourForeground
);
517 if ( m_owner
->m_colourBackground
.Ok() )
518 dc
.SetTextBackground( m_owner
->m_colourBackground
);
521 dc
.DrawCircle(0, 0, 10);
522 #if !(defined __WXGTK__) && !(defined __WXMOTIF__)
523 // not implemented in wxGTK or wxMOTIF :-(
524 dc
.FloodFill(0, 0, wxColour(255, 0, 0));
527 // set underlined font for testing
528 dc
.SetFont( wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, TRUE
) );
529 dc
.DrawText( "This is text", 110, 10 );
530 dc
.DrawRotatedText( "That is text", 60, 30, -45 );
532 dc
.SetFont( *wxNORMAL_FONT
);
535 dc
. SetBackgroundMode(wxTRANSPARENT
);
537 for ( int n
= -180; n
< 180; n
+= 30 )
539 text
.Printf(" %d rotated text", n
);
540 dc
.DrawRotatedText(text
, 400, 400, n
);
543 dc
.SetFont( wxFont( 18, wxSWISS
, wxNORMAL
, wxNORMAL
) );
545 dc
.DrawText( "This is Swiss 18pt text.", 110, 40 );
550 dc
.GetTextExtent( "This is Swiss 18pt text.", &length
, &height
, &descent
);
551 text
.Printf( "Dimensions are length %ld, height %ld, descent %ld", length
, height
, descent
);
552 dc
.DrawText( text
, 110, 80 );
554 dc
.DrawRectangle( 100, 40, 4, height
);
556 text
.Printf( "CharHeight() returns: %d", dc
.GetCharHeight() );
557 dc
.DrawText( text
, 110, 120 );
560 dc
.DrawIcon( wxICON(mondrian
), 310, 40 );
562 DrawTestLines( 0, 200, 0, dc
);
564 DrawTestLines( 0, 400, 1, dc
);
566 DrawTestLines( 0, 600, 2, dc
);
568 DrawTestLines( 0, 800, 6, dc
);
570 DrawTestPoly( 0, 1000, dc
,0);
571 DrawTestPoly( 33, 1400, dc
,1);
572 DrawTestPoly( 43, 1900, dc
,2);
575 void MyCanvas::OnMouseMove(wxMouseEvent
&event
)
579 m_owner
->PrepareDC(dc
);
581 wxPoint pos
= event
.GetPosition();
582 long x
= dc
.DeviceToLogicalX( pos
.x
);
583 long y
= dc
.DeviceToLogicalY( pos
.y
);
585 str
.Printf( "Current mouse position: %d,%d", (int)x
, (int)y
);
586 m_owner
->SetStatusText( str
);
589 // ----------------------------------------------------------------------------
591 // ----------------------------------------------------------------------------
593 // the event tables connect the wxWindows events with the functions (event
594 // handlers) which process them. It can be also done at run-time, but for the
595 // simple menu events like this the static method is much simpler.
596 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
597 EVT_MENU (Minimal_Quit
, MyFrame::OnQuit
)
598 EVT_MENU (Minimal_About
, MyFrame::OnAbout
)
599 EVT_MENU_RANGE(MenuOption_First
, MenuOption_Last
, MyFrame::OnOption
)
603 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
604 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
606 // set the frame icon
607 SetIcon(wxICON(mondrian
));
609 wxMenu
*menuFile
= new wxMenu
;
610 menuFile
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
611 menuFile
->AppendSeparator();
612 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
614 wxMenu
*menuMapMode
= new wxMenu
;
615 menuMapMode
->Append( MapMode_Text
, "&TEXT map mode" );
616 menuMapMode
->Append( MapMode_Lometric
, "&LOMETRIC map mode" );
617 menuMapMode
->Append( MapMode_Twips
, "T&WIPS map mode" );
618 menuMapMode
->Append( MapMode_Points
, "&POINTS map mode" );
619 menuMapMode
->Append( MapMode_Metric
, "&METRIC map mode" );
621 wxMenu
*menuUserScale
= new wxMenu
;
622 menuUserScale
->Append( UserScale_StretchHoriz
, "Stretch horizontally\tCtrl-H" );
623 menuUserScale
->Append( UserScale_ShrinkHoriz
, "Shrink horizontally\tCtrl-G" );
624 menuUserScale
->Append( UserScale_StretchVertic
, "Stretch vertically\tCtrl-V" );
625 menuUserScale
->Append( UserScale_ShrinkVertic
, "Shrink vertically\tCtrl-W" );
626 menuUserScale
->AppendSeparator();
627 menuUserScale
->Append( UserScale_Restore
, "Restore to normal\tCtrl-0" );
629 wxMenu
*menuAxis
= new wxMenu
;
630 menuAxis
->Append( AxisMirror_Horiz
, "Mirror horizontally\tCtrl-M", "", TRUE
);
631 menuAxis
->Append( AxisMirror_Vertic
, "Mirror vertically\tCtrl-N", "", TRUE
);
633 wxMenu
*menuLogical
= new wxMenu
;
634 menuLogical
->Append( LogicalOrigin_MoveDown
, "Move &down\tCtrl-D" );
635 menuLogical
->Append( LogicalOrigin_MoveUp
, "Move &up\tCtrl-U" );
636 menuLogical
->Append( LogicalOrigin_MoveLeft
, "Move &right\tCtrl-L" );
637 menuLogical
->Append( LogicalOrigin_MoveRight
, "Move &left\tCtrl-R" );
639 wxMenu
*menuColour
= new wxMenu
;
640 menuColour
->Append( Colour_TextForeground
, "Text foreground..." );
641 menuColour
->Append( Colour_TextBackground
, "Text background..." );
642 menuColour
->Append( Colour_Background
, "Background colour..." );
643 menuColour
->Append( Colour_BackgroundMode
, "Opaque/transparent\tCtrl-B", "", TRUE
);
645 // now append the freshly created menu to the menu bar...
646 wxMenuBar
*menuBar
= new wxMenuBar
;
647 menuBar
->Append(menuFile
, "&File");
648 menuBar
->Append(menuMapMode
, "&MapMode");
649 menuBar
->Append(menuUserScale
, "&UserScale");
650 menuBar
->Append(menuAxis
, "&Axis");
651 menuBar
->Append(menuLogical
, "&LogicalOrigin");
652 menuBar
->Append(menuColour
, "&Colours");
654 // ... and attach this menu bar to the frame
657 // create a status bar just for fun (by default with 1 pane only)
659 SetStatusText("Welcome to wxWindows!");
661 m_mapMode
= wxMM_TEXT
;
664 m_xLogicalOrigin
= 0;
665 m_yLogicalOrigin
= 0;
667 m_yAxisReversed
= FALSE
;
668 m_backgroundMode
= wxSOLID
;
669 m_colourForeground
= *wxRED
;
670 m_colourBackground
= *wxBLUE
;
672 m_canvas
= new MyCanvas( this );
673 m_canvas
->SetScrollbars( 10, 10, 100, 240 );
678 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
680 // TRUE is to force the frame to close
684 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
687 msg
.Printf( _T("This is the about dialog of the drawing sample.\n")
688 _T("Copyright (c) Robert Roebling 1999")
691 wxMessageBox(msg
, "About Drawing", wxOK
| wxICON_INFORMATION
, this);
694 void MyFrame::OnOption(wxCommandEvent
&event
)
696 switch (event
.GetInt())
699 m_mapMode
= wxMM_TEXT
;
701 case MapMode_Lometric
:
702 m_mapMode
= wxMM_LOMETRIC
;
705 m_mapMode
= wxMM_TWIPS
;
708 m_mapMode
= wxMM_POINTS
;
711 m_mapMode
= wxMM_METRIC
;
714 case LogicalOrigin_MoveDown
:
715 m_yLogicalOrigin
+= 10;
717 case LogicalOrigin_MoveUp
:
718 m_yLogicalOrigin
-= 10;
720 case LogicalOrigin_MoveLeft
:
721 m_xLogicalOrigin
+= 10;
723 case LogicalOrigin_MoveRight
:
724 m_xLogicalOrigin
-= 10;
727 case UserScale_StretchHoriz
:
728 m_xUserScale
*= 1.10;
730 case UserScale_ShrinkHoriz
:
731 m_xUserScale
/= 1.10;
733 case UserScale_StretchVertic
:
734 m_yUserScale
*= 1.10;
736 case UserScale_ShrinkVertic
:
737 m_yUserScale
/= 1.10;
739 case UserScale_Restore
:
744 case AxisMirror_Vertic
:
745 m_yAxisReversed
= !m_yAxisReversed
;
747 case AxisMirror_Horiz
:
748 m_xAxisReversed
= !m_xAxisReversed
;
751 case Colour_TextForeground
:
752 m_colourForeground
= SelectColour();
754 case Colour_TextBackground
:
755 m_colourBackground
= SelectColour();
757 case Colour_Background
:
759 wxColour col
= SelectColour();
762 m_backgroundBrush
.SetColour(col
);
766 case Colour_BackgroundMode
:
767 m_backgroundMode
= m_backgroundMode
== wxSOLID
? wxTRANSPARENT
779 void MyFrame::PrepareDC(wxDC
& dc
)
781 dc
.SetMapMode( m_mapMode
);
782 dc
.SetUserScale( m_xUserScale
, m_yUserScale
);
783 dc
.SetLogicalOrigin( m_xLogicalOrigin
, m_yLogicalOrigin
);
784 dc
.SetAxisOrientation( !m_xAxisReversed
, m_yAxisReversed
);
787 wxColour
MyFrame::SelectColour()
791 wxColourDialog
dialog(this, &data
);
793 if ( dialog
.ShowModal() == wxID_OK
)
795 col
= dialog
.GetColourData().GetColour();