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 // ----------------------------------------------------------------------------
21 #pragma implementation "drawing.cpp"
22 #pragma interface "drawing.cpp"
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers
38 #include "wx/colordlg.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // the application icon
45 #if defined(__WXGTK__) || defined(__WXMOTIF__)
46 #include "mondrian.xpm"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 // what do we show on screen (there are too many shapes to put them all on
54 // screen simultaneously)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 static wxBitmap gs_bmpNoMask
,
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 // Define a new application type, each program should derive a class from wxApp
80 class MyApp
: public wxApp
83 // override base class virtuals
84 // ----------------------------
86 // this one is called on application startup and is a good place for the app
87 // initialization (doing it here and not in the ctor allows to have an error
88 // return: if OnInit() returns false, the application terminates)
89 virtual bool OnInit();
97 // Define a new frame type: this is going to be our main frame
98 class MyFrame
: public wxFrame
102 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
104 // event handlers (these functions should _not_ be virtual)
105 void OnQuit(wxCommandEvent
& event
);
106 void OnAbout(wxCommandEvent
& event
);
107 void OnShow(wxCommandEvent
&event
);
108 void OnOption(wxCommandEvent
&event
);
110 wxColour
SelectColour();
111 void PrepareDC(wxDC
& dc
);
113 int m_backgroundMode
;
117 int m_xLogicalOrigin
;
118 int m_yLogicalOrigin
;
119 bool m_xAxisReversed
,
121 wxColour m_colourForeground
, // these are _text_ colours
123 wxBrush m_backgroundBrush
;
127 // any class wishing to process wxWindows events must use this macro
128 DECLARE_EVENT_TABLE()
131 // define a scrollable canvas for drawing onto
132 class MyCanvas
: public wxScrolledWindow
135 MyCanvas( MyFrame
*parent
);
137 void OnPaint(wxPaintEvent
&event
);
138 void OnMouseMove(wxMouseEvent
&event
);
140 void Show(ScreenToShow show
) { m_show
= show
; Refresh(); }
143 void DrawTestPoly( int x
, int y
, wxDC
&dc
,int transparent
);
144 void DrawTestLines( int x
, int y
, int width
, wxDC
&dc
);
145 void DrawText(wxDC
& dc
);
146 void DrawImages(wxDC
& dc
);
147 void DrawDefault(wxDC
& dc
);
154 DECLARE_EVENT_TABLE()
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 // IDs for the controls and the menu commands
169 File_ShowDefault
= MenuShow_First
,
174 MenuShow_Last
= File_ShowMask
,
178 MapMode_Text
= MenuOption_First
,
184 UserScale_StretchHoriz
,
185 UserScale_ShrinkHoriz
,
186 UserScale_StretchVertic
,
187 UserScale_ShrinkVertic
,
193 LogicalOrigin_MoveDown
,
194 LogicalOrigin_MoveUp
,
195 LogicalOrigin_MoveLeft
,
196 LogicalOrigin_MoveRight
,
198 Colour_TextForeground
,
199 Colour_TextBackground
,
201 Colour_BackgroundMode
,
203 MenuOption_Last
= Colour_BackgroundMode
206 // ----------------------------------------------------------------------------
207 // event tables and other macros for wxWindows
208 // ----------------------------------------------------------------------------
211 // Create a new application object: this macro will allow wxWindows to create
212 // the application object during program execution (it's better than using a
213 // static object for many reasons) and also declares the accessor function
214 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
218 // ============================================================================
220 // ============================================================================
222 // ----------------------------------------------------------------------------
223 // the application class
224 // ----------------------------------------------------------------------------
226 bool MyApp::LoadImages()
232 wxString path
= pathList
.FindValidPath("pat4.bmp");
235 gs_bmp4
.LoadFile(path
, wxBITMAP_TYPE_BMP
);
236 wxMask
* mask4
= new wxMask(gs_bmp4
, *wxBLACK
);
237 gs_bmp4
.SetMask(mask4
);
239 path
= pathList
.FindValidPath("pat36.bmp");
242 gs_bmp36
.LoadFile(path
, wxBITMAP_TYPE_BMP
);
243 wxMask
* mask36
= new wxMask(gs_bmp36
, *wxBLACK
);
244 gs_bmp36
.SetMask(mask36
);
246 path
= pathList
.FindValidPath("image.bmp");
249 gs_bmpNoMask
.LoadFile(path
, wxBITMAP_TYPE_BMP
);
250 gs_bmpWithMask
.LoadFile(path
, wxBITMAP_TYPE_BMP
);
251 gs_bmpWithColMask
.LoadFile(path
, wxBITMAP_TYPE_BMP
);
253 path
= pathList
.FindValidPath("mask.bmp");
256 gs_bmpMask
.LoadFile(path
, wxBITMAP_TYPE_BMP
);
257 gs_bmpMask
.SetDepth(1);
259 wxMask
*mask
= new wxMask(gs_bmpMask
);
260 gs_bmpWithMask
.SetMask(mask
);
262 mask
= new wxMask(gs_bmpWithColMask
, *wxWHITE
);
263 gs_bmpWithColMask
.SetMask(mask
);
268 // `Main program' equivalent: the program execution "starts" here
271 // Create the main application window
272 MyFrame
*frame
= new MyFrame("Drawing sample",
273 wxPoint(50, 50), wxSize(550, 340));
275 // Show it and tell the application that it's our main window
281 wxLogError("Can't load one of the bitmap files needed for this sample "
282 "from the current or parent directory, please copy them "
293 // ----------------------------------------------------------------------------
295 // ----------------------------------------------------------------------------
297 // the event tables connect the wxWindows events with the functions (event
298 // handlers) which process them.
299 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
300 EVT_PAINT (MyCanvas::OnPaint
)
301 EVT_MOTION (MyCanvas::OnMouseMove
)
304 MyCanvas::MyCanvas( MyFrame
*parent
) : wxScrolledWindow( parent
)
307 m_show
= Show_Default
;
310 //draw a polygon and an overlapping rectangle
311 //is transparent is 1, the fill pattern are made transparent
312 //is transparent is 2, the fill pattern are made transparent but inversed
313 //is transparent is 0 the text for and background color will be used to represent/map
314 //the colors of the monochrome bitmap pixels to the fillpattern
316 //i miss_used the the menu items for setting so called back and fore ground color
317 //just to show how the those colors do influence the fillpatterns
318 //just play with those,
320 //variations are endless using other logical functions
321 void MyCanvas::DrawTestPoly( int x
, int y
,wxDC
&dc
,int transparent
)
323 wxBrush
* brush4
= new wxBrush(gs_bmp4
);
324 wxBrush
* brush36
= new wxBrush(gs_bmp36
);
327 todraw
[0].x
=(long)x
+100;
328 todraw
[0].y
=(long)y
+100;
329 todraw
[1].x
=(long)x
+300;
330 todraw
[1].y
=(long)y
+100;
331 todraw
[2].x
=(long)x
+300;
332 todraw
[2].y
=(long)y
+300;
333 todraw
[3].x
=(long)x
+150;
334 todraw
[3].y
=(long)y
+350;
335 todraw
[4].x
=(long)x
+100;
336 todraw
[4].y
=(long)y
+300;
354 dc
.SetPen( wxPen( "black", 4, wxSOLID
) );
355 dc
.SetBrush( *brush4
);
356 dc
.SetTextForeground(*wxGREEN
);
357 dc
.SetTextBackground(m_owner
->m_colourForeground
);
358 dc
.SetLogicalFunction(wxCOPY
);
359 dc
.DrawPolygon(5,todraw
,0,0,wxWINDING_RULE
);
361 //don't understand hwo but the outline is also depending on logicalfunction
362 dc
.SetPen( wxPen( "red", 4, wxSOLID
) );
363 dc
.SetBrush( *brush36
);
364 dc
.SetTextForeground(*wxCYAN
);
365 dc
.SetTextBackground(m_owner
->m_colourBackground
);
366 dc
.SetLogicalFunction(wxCOPY
);
367 dc
.DrawRectangle( x
+10, y
+10, 200, 200 );
368 dc
.SetBrush(wxNullBrush
);
369 dc
.SetPen(wxNullPen
);
372 case 1: //now with transparent fillpatterns
375 wxBitmap
* bmpBlit
= new wxBitmap(600,400);
376 wxMemoryDC
* memDC
= new wxMemoryDC();
377 // wxBrush _clearbrush(*wxGREEN,wxSOLID);
378 wxBrush
_clearbrush(*wxBLACK
,wxSOLID
);
379 memDC
->SelectObject(*bmpBlit
);
380 memDC
->BeginDrawing();
381 memDC
->SetBackground(_clearbrush
);
383 memDC
->SetBackground(wxNullBrush
);
385 memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
386 memDC
->SetBrush( wxNullBrush
);
387 memDC
->SetBrush( *brush4
);
388 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
389 memDC
->SetTextBackground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
390 memDC
->SetLogicalFunction(wxAND_INVERT
);
392 // BLACK OUT the opaque pixels and leave the rest as is
393 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
395 // Set background and foreground colors for fill pattern
396 //the previous blacked out pixels are now merged with the layer color
397 //while the non blacked out pixels stay as they are.
398 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
400 //now define what will be the color of the fillpattern parts that are not transparent
401 // memDC->SetTextBackground(*wxBLUE);
402 memDC
->SetTextBackground(m_owner
->m_colourForeground
);
403 memDC
->SetLogicalFunction(wxOR
);
406 //don't understand how but the outline is also depending on logicalfunction
407 memDC
->SetPen( wxPen( "red", 4, wxSOLID
) );
408 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
410 memDC
->SetLogicalFunction(wxCOPY
);
412 memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
413 memDC
->SetBrush( wxNullBrush
);
414 memDC
->SetBrush( *brush36
);
415 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
416 memDC
->SetTextBackground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
417 memDC
->SetLogicalFunction(wxAND_INVERT
);
419 memDC
->DrawRectangle( 10, 10, 200, 200 );
421 // Set background and foreground colors for fill pattern
422 //the previous blacked out pixels are now merged with the layer color
423 //while the non blacked out pixels stay as they are.
424 memDC
->SetTextForeground(*wxBLACK
); // 0s --> 0x000000 (black)
425 //now define what will be the color of the fillpattern parts that are not transparent
426 // memDC->SetTextBackground(*wxRED);
427 memDC
->SetTextBackground(m_owner
->m_colourBackground
);
428 memDC
->SetLogicalFunction(wxOR
);
430 //don't understand how but the outline is also depending on logicalfunction
431 memDC
->SetPen( wxPen( "yellow", 4, wxSOLID
) );
432 memDC
->DrawRectangle( 10, 10, 200, 200 );
434 memDC
->SetBrush(wxNullBrush
);
435 memDC
->SetPen(wxNullPen
);
438 dc
.Blit(x
,y
,600,400,memDC
,0,0,wxCOPY
);
443 case 2: //now with transparent inversed fillpatterns
445 wxBitmap
* bmpBlit
= new wxBitmap(600,400);
446 wxMemoryDC
* memDC
= new wxMemoryDC();
447 wxBrush
_clearbrush(*wxWHITE
,wxSOLID
);
448 memDC
->SelectObject(*bmpBlit
);
449 memDC
->BeginDrawing();
450 memDC
->SetBackground(_clearbrush
);
452 memDC
->SetBackground(wxNullBrush
);
454 memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
455 memDC
->SetBrush( *brush4
);
456 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
457 memDC
->SetTextForeground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
458 memDC
->SetLogicalFunction(wxAND_INVERT
);
460 // BLACK OUT the opaque pixels and leave the rest as is
461 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
463 // Set background and foreground colors for fill pattern
464 //the previous blacked out pixels are now merged with the layer color
465 //while the non blacked out pixels stay as they are.
466 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
468 //now define what will be the color of the fillpattern parts that are not transparent
469 memDC
->SetTextForeground(m_owner
->m_colourForeground
);
470 memDC
->SetLogicalFunction(wxOR
);
473 //don't understand how but the outline is also depending on logicalfunction
474 memDC
->SetPen( wxPen( "red", 4, wxSOLID
) );
475 memDC
->DrawPolygon(5,todraw2
,0,0,wxWINDING_RULE
);
477 memDC
->SetLogicalFunction(wxCOPY
);
479 memDC
->SetPen( wxPen( "black", 4, wxSOLID
) );
480 memDC
->SetBrush( *brush36
);
481 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
482 memDC
->SetTextForeground(*wxWHITE
); // 1s --> 0xFFFFFF (white)
483 memDC
->SetLogicalFunction(wxAND_INVERT
);
485 memDC
->DrawRectangle( 10,10, 200, 200 );
487 // Set background and foreground colors for fill pattern
488 //the previous blacked out pixels are now merged with the layer color
489 //while the non blacked out pixels stay as they are.
490 memDC
->SetTextBackground(*wxBLACK
); // 0s --> 0x000000 (black)
491 //now define what will be the color of the fillpattern parts that are not transparent
492 memDC
->SetTextForeground(m_owner
->m_colourBackground
);
493 memDC
->SetLogicalFunction(wxOR
);
495 //don't understand how but the outline is also depending on logicalfunction
496 memDC
->SetPen( wxPen( "yellow", 4, wxSOLID
) );
497 memDC
->DrawRectangle( 10, 10, 200, 200 );
499 memDC
->SetBrush(wxNullBrush
);
500 memDC
->SetPen(wxNullPen
);
501 dc
.Blit(x
,y
,600,400,memDC
,0,0,wxCOPY
);
511 void MyCanvas::DrawTestLines( int x
, int y
, int width
, wxDC
&dc
)
513 dc
.SetPen( wxPen( "black", width
, wxSOLID
) );
514 dc
.SetBrush( *wxRED_BRUSH
);
515 dc
.DrawRectangle( x
+10, y
+10, 100, 190 );
517 dc
.SetPen( wxPen( "black", width
, wxSOLID
) );
518 dc
.DrawLine( x
+20, y
+20, 100, y
+20 );
519 dc
.SetPen( wxPen( "black", width
, wxDOT
) );
520 dc
.DrawLine( x
+20, y
+30, 100, y
+30 );
521 dc
.SetPen( wxPen( "black", width
, wxSHORT_DASH
) );
522 dc
.DrawLine( x
+20, y
+40, 100, y
+40 );
523 dc
.SetPen( wxPen( "black", width
, wxLONG_DASH
) );
524 dc
.DrawLine( x
+20, y
+50, 100, y
+50 );
525 dc
.SetPen( wxPen( "black", width
, wxDOT_DASH
) );
526 dc
.DrawLine( x
+20, y
+60, 100, y
+60 );
528 dc
.SetPen( wxPen( "black", width
, wxBDIAGONAL_HATCH
) );
529 dc
.DrawLine( x
+20, y
+70, 100, y
+70 );
530 dc
.SetPen( wxPen( "black", width
, wxCROSSDIAG_HATCH
) );
531 dc
.DrawLine( x
+20, y
+80, 100, y
+80 );
532 dc
.SetPen( wxPen( "black", width
, wxFDIAGONAL_HATCH
) );
533 dc
.DrawLine( x
+20, y
+90, 100, y
+90 );
534 dc
.SetPen( wxPen( "black", width
, wxCROSS_HATCH
) );
535 dc
.DrawLine( x
+20, y
+100, 100, y
+100 );
536 dc
.SetPen( wxPen( "black", width
, wxHORIZONTAL_HATCH
) );
537 dc
.DrawLine( x
+20, y
+110, 100, y
+110 );
538 dc
.SetPen( wxPen( "black", width
, wxVERTICAL_HATCH
) );
539 dc
.DrawLine( x
+20, y
+120, 100, y
+120 );
541 wxPen
ud( "black", width
, wxUSER_DASH
);
544 ud
.SetDashes( 1, dash1
);
545 dc
.DrawLine( x
+20, y
+140, 100, y
+140 );
547 ud
.SetDashes( 1, dash1
);
548 dc
.DrawLine( x
+20, y
+150, 100, y
+150 );
550 ud
.SetDashes( 1, dash1
);
551 dc
.DrawLine( x
+20, y
+160, 100, y
+160 );
553 ud
.SetDashes( 1, dash1
);
554 dc
.DrawLine( x
+20, y
+170, 100, y
+170 );
558 void MyCanvas::DrawDefault(wxDC
& dc
)
561 dc
.DrawCircle(0, 0, 10);
562 #if !(defined __WXGTK__) && !(defined __WXMOTIF__)
563 // not implemented in wxGTK or wxMOTIF :-(
564 dc
.FloodFill(0, 0, wxColour(255, 0, 0));
567 dc
.DrawIcon( wxICON(mondrian
), 410, 40 );
569 // test the rectangle drawing - there should be no pixels between the rect
571 dc
.SetPen(*wxTRANSPARENT_PEN
);
572 dc
.DrawRectangle(350, 170, 49, 29);
573 dc
.SetPen(*wxRED_PEN
);
574 dc
.DrawLine(400, 160, 400, 210);
575 dc
.DrawLine(340, 200, 410, 200);
578 void MyCanvas::DrawText(wxDC
& dc
)
580 // set underlined font for testing
581 dc
.SetFont( wxFont(12, wxMODERN
, wxNORMAL
, wxNORMAL
, TRUE
) );
582 dc
.DrawText( "This is text", 110, 10 );
583 dc
.DrawRotatedText( "That is text", 20, 10, -45 );
585 dc
.SetFont( *wxNORMAL_FONT
);
588 dc
. SetBackgroundMode(wxTRANSPARENT
);
590 for ( int n
= -180; n
< 180; n
+= 30 )
592 text
.Printf(" %d rotated text", n
);
593 dc
.DrawRotatedText(text
, 400, 400, n
);
596 dc
.SetFont( wxFont( 18, wxSWISS
, wxNORMAL
, wxNORMAL
) );
598 dc
.DrawText( "This is Swiss 18pt text.", 110, 40 );
603 dc
.GetTextExtent( "This is Swiss 18pt text.", &length
, &height
, &descent
);
604 text
.Printf( "Dimensions are length %ld, height %ld, descent %ld", length
, height
, descent
);
605 dc
.DrawText( text
, 110, 80 );
607 text
.Printf( "CharHeight() returns: %d", dc
.GetCharHeight() );
608 dc
.DrawText( text
, 110, 120 );
610 dc
.DrawRectangle( 100, 40, 4, height
);
613 void MyCanvas::DrawImages(wxDC
& dc
)
619 } rasterOperations
[] =
622 { "wxAND_INVERT", wxAND_INVERT
},
623 { "wxAND_REVERSE", wxAND_REVERSE
},
624 { "wxCLEAR", wxCLEAR
},
625 { "wxCOPY", wxCOPY
},
626 { "wxEQUIV", wxEQUIV
},
627 { "wxINVERT", wxINVERT
},
628 { "wxNAND", wxNAND
},
629 { "wxNO_OP", wxNO_OP
},
631 { "wxOR_INVERT", wxOR_INVERT
},
632 { "wxOR_REVERSE", wxOR_REVERSE
},
634 { "wxSRC_INVERT", wxSRC_INVERT
},
638 dc
.DrawText("original image", 0, 0);
639 dc
.DrawBitmap(gs_bmpNoMask
, 0, 20, 0);
640 dc
.DrawText("with colour mask", 0, 100);
641 dc
.DrawBitmap(gs_bmpWithColMask
, 0, 120, TRUE
);
642 dc
.DrawText("the mask image", 0, 200);
643 dc
.DrawBitmap(gs_bmpMask
, 0, 220, 0);
644 dc
.DrawText("masked image", 0, 300);
645 dc
.DrawBitmap(gs_bmpWithMask
, 0, 320, TRUE
);
647 int cx
= gs_bmpWithColMask
.GetWidth(),
648 cy
= gs_bmpWithColMask
.GetHeight();
651 for ( size_t n
= 0; n
< WXSIZEOF(rasterOperations
); n
++ )
653 wxCoord x
= 120 + 150*(n%4
),
656 dc
.DrawText(rasterOperations
[n
].name
, x
, y
- 20);
657 memDC
.SelectObject(gs_bmpWithColMask
);
658 dc
.Blit(x
, y
, cx
, cy
, &memDC
, 0, 0, rasterOperations
[n
].rop
, TRUE
);
662 void MyCanvas::OnPaint(wxPaintEvent
&WXUNUSED(event
))
666 m_owner
->PrepareDC(dc
);
668 dc
.SetBackgroundMode( m_owner
->m_backgroundMode
);
669 if ( m_owner
->m_backgroundBrush
.Ok() )
670 dc
.SetBackground( m_owner
->m_backgroundBrush
);
671 if ( m_owner
->m_colourForeground
.Ok() )
672 dc
.SetTextForeground( m_owner
->m_colourForeground
);
673 if ( m_owner
->m_colourBackground
.Ok() )
674 dc
.SetTextBackground( m_owner
->m_colourBackground
);
687 DrawTestLines( 0, 100, 0, dc
);
688 DrawTestLines( 0, 300, 1, dc
);
689 DrawTestLines( 0, 500, 2, dc
);
690 DrawTestLines( 0, 700, 6, dc
);
694 DrawTestPoly( 0, 100, dc
, 0 );
695 DrawTestPoly( 33, 500, dc
, 1 );
696 DrawTestPoly( 43, 1000, dc
, 2 );
705 void MyCanvas::OnMouseMove(wxMouseEvent
&event
)
709 m_owner
->PrepareDC(dc
);
711 wxPoint pos
= event
.GetPosition();
712 long x
= dc
.DeviceToLogicalX( pos
.x
);
713 long y
= dc
.DeviceToLogicalY( pos
.y
);
715 str
.Printf( "Current mouse position: %d,%d", (int)x
, (int)y
);
716 m_owner
->SetStatusText( str
);
719 // ----------------------------------------------------------------------------
721 // ----------------------------------------------------------------------------
723 // the event tables connect the wxWindows events with the functions (event
724 // handlers) which process them. It can be also done at run-time, but for the
725 // simple menu events like this the static method is much simpler.
726 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
727 EVT_MENU (File_Quit
, MyFrame::OnQuit
)
728 EVT_MENU (File_About
, MyFrame::OnAbout
)
730 EVT_MENU_RANGE(MenuShow_First
, MenuShow_Last
, MyFrame::OnShow
)
732 EVT_MENU_RANGE(MenuOption_First
, MenuOption_Last
, MyFrame::OnOption
)
736 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
737 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
739 // set the frame icon
740 SetIcon(wxICON(mondrian
));
742 wxMenu
*menuFile
= new wxMenu
;
743 menuFile
->Append(File_ShowDefault
, "&Default screen\tF1");
744 menuFile
->Append(File_ShowText
, "&Text screen\tF2");
745 menuFile
->Append(File_ShowLines
, "&Lines screen\tF3");
746 menuFile
->Append(File_ShowPolygons
, "&Polygons screen\tF4");
747 menuFile
->Append(File_ShowMask
, "wx&Mask screen\tF5");
748 menuFile
->AppendSeparator();
749 menuFile
->Append(File_About
, "&About...\tCtrl-A", "Show about dialog");
750 menuFile
->AppendSeparator();
751 menuFile
->Append(File_Quit
, "E&xit\tAlt-X", "Quit this program");
753 wxMenu
*menuMapMode
= new wxMenu
;
754 menuMapMode
->Append( MapMode_Text
, "&TEXT map mode" );
755 menuMapMode
->Append( MapMode_Lometric
, "&LOMETRIC map mode" );
756 menuMapMode
->Append( MapMode_Twips
, "T&WIPS map mode" );
757 menuMapMode
->Append( MapMode_Points
, "&POINTS map mode" );
758 menuMapMode
->Append( MapMode_Metric
, "&METRIC map mode" );
760 wxMenu
*menuUserScale
= new wxMenu
;
761 menuUserScale
->Append( UserScale_StretchHoriz
, "Stretch horizontally\tCtrl-H" );
762 menuUserScale
->Append( UserScale_ShrinkHoriz
, "Shrink horizontally\tCtrl-G" );
763 menuUserScale
->Append( UserScale_StretchVertic
, "Stretch vertically\tCtrl-V" );
764 menuUserScale
->Append( UserScale_ShrinkVertic
, "Shrink vertically\tCtrl-W" );
765 menuUserScale
->AppendSeparator();
766 menuUserScale
->Append( UserScale_Restore
, "Restore to normal\tCtrl-0" );
768 wxMenu
*menuAxis
= new wxMenu
;
769 menuAxis
->Append( AxisMirror_Horiz
, "Mirror horizontally\tCtrl-M", "", TRUE
);
770 menuAxis
->Append( AxisMirror_Vertic
, "Mirror vertically\tCtrl-N", "", TRUE
);
772 wxMenu
*menuLogical
= new wxMenu
;
773 menuLogical
->Append( LogicalOrigin_MoveDown
, "Move &down\tCtrl-D" );
774 menuLogical
->Append( LogicalOrigin_MoveUp
, "Move &up\tCtrl-U" );
775 menuLogical
->Append( LogicalOrigin_MoveLeft
, "Move &right\tCtrl-L" );
776 menuLogical
->Append( LogicalOrigin_MoveRight
, "Move &left\tCtrl-R" );
778 wxMenu
*menuColour
= new wxMenu
;
779 menuColour
->Append( Colour_TextForeground
, "Text foreground..." );
780 menuColour
->Append( Colour_TextBackground
, "Text background..." );
781 menuColour
->Append( Colour_Background
, "Background colour..." );
782 menuColour
->Append( Colour_BackgroundMode
, "Opaque/transparent\tCtrl-B", "", TRUE
);
784 // now append the freshly created menu to the menu bar...
785 wxMenuBar
*menuBar
= new wxMenuBar
;
786 menuBar
->Append(menuFile
, "&File");
787 menuBar
->Append(menuMapMode
, "&MapMode");
788 menuBar
->Append(menuUserScale
, "&UserScale");
789 menuBar
->Append(menuAxis
, "&Axis");
790 menuBar
->Append(menuLogical
, "&LogicalOrigin");
791 menuBar
->Append(menuColour
, "&Colours");
793 // ... and attach this menu bar to the frame
796 // create a status bar just for fun (by default with 1 pane only)
798 SetStatusText("Welcome to wxWindows!");
800 m_mapMode
= wxMM_TEXT
;
803 m_xLogicalOrigin
= 0;
804 m_yLogicalOrigin
= 0;
806 m_yAxisReversed
= FALSE
;
807 m_backgroundMode
= wxSOLID
;
808 m_colourForeground
= *wxRED
;
809 m_colourBackground
= *wxBLUE
;
811 m_canvas
= new MyCanvas( this );
812 m_canvas
->SetScrollbars( 10, 10, 100, 240 );
817 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
819 // TRUE is to force the frame to close
823 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
826 msg
.Printf( _T("This is the about dialog of the drawing sample.\n")
827 _T("Copyright (c) Robert Roebling 1999")
830 wxMessageBox(msg
, "About Drawing", wxOK
| wxICON_INFORMATION
, this);
833 void MyFrame::OnShow(wxCommandEvent
& event
)
835 m_canvas
->Show((ScreenToShow
)(event
.GetInt() - MenuShow_First
));
838 void MyFrame::OnOption(wxCommandEvent
& event
)
840 switch (event
.GetInt())
843 m_mapMode
= wxMM_TEXT
;
845 case MapMode_Lometric
:
846 m_mapMode
= wxMM_LOMETRIC
;
849 m_mapMode
= wxMM_TWIPS
;
852 m_mapMode
= wxMM_POINTS
;
855 m_mapMode
= wxMM_METRIC
;
858 case LogicalOrigin_MoveDown
:
859 m_yLogicalOrigin
+= 10;
861 case LogicalOrigin_MoveUp
:
862 m_yLogicalOrigin
-= 10;
864 case LogicalOrigin_MoveLeft
:
865 m_xLogicalOrigin
+= 10;
867 case LogicalOrigin_MoveRight
:
868 m_xLogicalOrigin
-= 10;
871 case UserScale_StretchHoriz
:
872 m_xUserScale
*= 1.10;
874 case UserScale_ShrinkHoriz
:
875 m_xUserScale
/= 1.10;
877 case UserScale_StretchVertic
:
878 m_yUserScale
*= 1.10;
880 case UserScale_ShrinkVertic
:
881 m_yUserScale
/= 1.10;
883 case UserScale_Restore
:
888 case AxisMirror_Vertic
:
889 m_yAxisReversed
= !m_yAxisReversed
;
891 case AxisMirror_Horiz
:
892 m_xAxisReversed
= !m_xAxisReversed
;
895 case Colour_TextForeground
:
896 m_colourForeground
= SelectColour();
898 case Colour_TextBackground
:
899 m_colourBackground
= SelectColour();
901 case Colour_Background
:
903 wxColour col
= SelectColour();
906 m_backgroundBrush
.SetColour(col
);
910 case Colour_BackgroundMode
:
911 m_backgroundMode
= m_backgroundMode
== wxSOLID
? wxTRANSPARENT
923 void MyFrame::PrepareDC(wxDC
& dc
)
925 dc
.SetMapMode( m_mapMode
);
926 dc
.SetUserScale( m_xUserScale
, m_yUserScale
);
927 dc
.SetLogicalOrigin( m_xLogicalOrigin
, m_yLogicalOrigin
);
928 dc
.SetAxisOrientation( !m_xAxisReversed
, m_yAxisReversed
);
931 wxColour
MyFrame::SelectColour()
935 wxColourDialog
dialog(this, &data
);
937 if ( dialog
.ShowModal() == wxID_OK
)
939 col
= dialog
.GetColourData().GetColour();