X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e7fd311087384fb80f17a124d673aeb6a8fa9b8..6d693bb4fc299b7375dd4da9d878768d80ceaf55:/samples/drawing/drawing.cpp diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index a85be22c80..7027220821 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -74,7 +74,6 @@ public: void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnOption(wxCommandEvent &event); - void OnMouseMove(wxMouseEvent &event); wxColour SelectColour(); void PrepareDC(wxDC& dc); @@ -105,6 +104,7 @@ public: void DrawTestLines( int x, int y, int width, wxDC &dc ); void OnPaint(wxPaintEvent &event); + void OnMouseMove(wxMouseEvent &event); protected: MyFrame *m_owner; @@ -199,6 +199,7 @@ bool MyApp::OnInit() // handlers) which process them. BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) EVT_PAINT (MyCanvas::OnPaint) + EVT_MOTION (MyCanvas::OnMouseMove) END_EVENT_TABLE() MyCanvas::MyCanvas( MyFrame *parent ) @@ -270,24 +271,57 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) // mark the origin dc.DrawCircle(0, 0, 10); -#ifndef __WXGTK__ // not implemented in wxGTK :-( +#if !(defined __WXGTK__) && !(defined __WXMOTIF__) + // not implemented in wxGTK or wxMOTIF :-( dc.FloodFill(0, 0, wxColour(255, 0, 0)); -#endif // __WXGTK__ +#endif // dc.DrawText( "This is text", 110, 10 ); - dc.DrawIcon( wxICON(mondrian), 110, 40 ); + dc.SetFont( wxFont( 18, wxSWISS, 0, 0 ) ); + + dc.DrawText( "This is Swiss 18pt text.", 110, 40 ); + + long length; + long height; + long descent; + dc.GetTextExtent( "This is Swiss 18pt text.", &length, &height, &descent ); + wxString text; + text.Printf( "Dimensions are length %ld, height %ld, descent %ld", length, height, descent ); + dc.DrawText( text, 110, 80 ); + + dc.DrawRectangle( 100, 40, 4, height ); + + text.Printf( "CharHeight() returns: %d", dc.GetCharHeight() ); + dc.DrawText( text, 110, 120 ); + + + dc.DrawIcon( wxICON(mondrian), 310, 40 ); - DrawTestLines( 0, 20, 0, dc ); + DrawTestLines( 0, 200, 0, dc ); - DrawTestLines( 0, 220, 1, dc ); + DrawTestLines( 0, 400, 1, dc ); - DrawTestLines( 0, 420, 2, dc ); + DrawTestLines( 0, 600, 2, dc ); - DrawTestLines( 0, 620, 6, dc ); + DrawTestLines( 0, 800, 6, dc ); } +void MyCanvas::OnMouseMove(wxMouseEvent &event) +{ + wxClientDC dc(this); + PrepareDC(dc); + m_owner->PrepareDC(dc); + + wxPoint pos = event.GetPosition(); + long x = dc.DeviceToLogicalX( pos.x ); + long y = dc.DeviceToLogicalY( pos.y ); + wxString str; + str.Printf( "Current mouse position: %d,%d", (int)x, (int)y ); + m_owner->SetStatusText( str ); +} + // ---------------------------------------------------------------------------- // MyFrame // ---------------------------------------------------------------------------- @@ -296,7 +330,6 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) // handlers) which process them. It can be also done at run-time, but for the // simple menu events like this the static method is much simpler. BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MOTION (MyFrame::OnMouseMove) EVT_MENU (Minimal_Quit, MyFrame::OnQuit) EVT_MENU (Minimal_About, MyFrame::OnAbout) EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption) @@ -485,19 +518,6 @@ void MyFrame::PrepareDC(wxDC& dc) dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed ); } -void MyFrame::OnMouseMove(wxMouseEvent &event) -{ - wxClientDC dc(this); - PrepareDC(dc); - - wxPoint pos = event.GetPosition(); - long x = dc.DeviceToLogicalX( pos.x ); - long y = dc.DeviceToLogicalY( pos.y ); - wxString str; - str.Printf( "Current mouse position: %d,%d", (int)x, (int)y ); - SetStatusText( str ); -} - wxColour MyFrame::SelectColour() { wxColour col;