X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/70bdacfc8edfbd1b713d0438a6385a7e1520b28d..ff83a7701caa5615f8a2cee0ce2cc216a22af19a:/samples/drawing/drawing.cpp?ds=sidebyside diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 1d6f9e8718..76af6243ef 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 ) @@ -211,46 +212,46 @@ void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc ) { dc.SetPen( wxPen( "black", width, wxSOLID) ); dc.SetBrush( *wxRED_BRUSH ); - dc.DrawRectangle( x+10, y+10, 400, 190 ); + dc.DrawRectangle( x+10, y+10, 100, 190 ); dc.SetPen( wxPen( "black", width, wxSOLID) ); - dc.DrawLine( x+20, y+20, 390, y+20 ); + dc.DrawLine( x+20, y+20, 100, y+20 ); dc.SetPen( wxPen( "black", width, wxDOT) ); - dc.DrawLine( x+20, y+30, 390, y+30 ); + dc.DrawLine( x+20, y+30, 100, y+30 ); dc.SetPen( wxPen( "black", width, wxSHORT_DASH) ); - dc.DrawLine( x+20, y+40, 390, y+40 ); + dc.DrawLine( x+20, y+40, 100, y+40 ); dc.SetPen( wxPen( "black", width, wxLONG_DASH) ); - dc.DrawLine( x+20, y+50, 390, y+50 ); + dc.DrawLine( x+20, y+50, 100, y+50 ); dc.SetPen( wxPen( "black", width, wxDOT_DASH) ); - dc.DrawLine( x+20, y+60, 390, y+60 ); + dc.DrawLine( x+20, y+60, 100, y+60 ); dc.SetPen( wxPen( "black", width, wxBDIAGONAL_HATCH) ); - dc.DrawLine( x+20, y+70, 390, y+70 ); + dc.DrawLine( x+20, y+70, 100, y+70 ); dc.SetPen( wxPen( "black", width, wxCROSSDIAG_HATCH) ); - dc.DrawLine( x+20, y+80, 390, y+80 ); + dc.DrawLine( x+20, y+80, 100, y+80 ); dc.SetPen( wxPen( "black", width, wxFDIAGONAL_HATCH) ); - dc.DrawLine( x+20, y+90, 390, y+90 ); + dc.DrawLine( x+20, y+90, 100, y+90 ); dc.SetPen( wxPen( "black", width, wxCROSS_HATCH) ); - dc.DrawLine( x+20, y+100, 390, y+100 ); + dc.DrawLine( x+20, y+100, 100, y+100 ); dc.SetPen( wxPen( "black", width, wxHORIZONTAL_HATCH) ); - dc.DrawLine( x+20, y+110, 390, y+110 ); + dc.DrawLine( x+20, y+110, 100, y+110 ); dc.SetPen( wxPen( "black", width, wxVERTICAL_HATCH) ); - dc.DrawLine( x+20, y+120, 390, y+120 ); + dc.DrawLine( x+20, y+120, 100, y+120 ); wxPen ud( "black", width, wxUSER_DASH ); wxDash dash1[1]; dash1[0] = 0; ud.SetDashes( 1, dash1 ); - dc.DrawLine( x+20, y+140, 390, y+140 ); + dc.DrawLine( x+20, y+140, 100, y+140 ); dash1[0] = 1; ud.SetDashes( 1, dash1 ); - dc.DrawLine( x+20, y+150, 390, y+150 ); + dc.DrawLine( x+20, y+150, 100, y+150 ); dash1[0] = 2; ud.SetDashes( 1, dash1 ); - dc.DrawLine( x+20, y+160, 390, y+160 ); + dc.DrawLine( x+20, y+160, 100, y+160 ); dash1[0] = 0xFF; ud.SetDashes( 1, dash1 ); - dc.DrawLine( x+20, y+170, 390, y+170 ); + dc.DrawLine( x+20, y+170, 100, y+170 ); } @@ -275,9 +276,23 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) dc.FloodFill(0, 0, wxColour(255, 0, 0)); #endif // + // set underlined font for testing + dc.SetFont( wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, TRUE) ); dc.DrawText( "This is text", 110, 10 ); + dc.DrawRotatedText( "That is text", 60, 30, -45 ); + + dc.SetFont( *wxNORMAL_FONT ); + + wxString text; + dc. SetBackgroundMode(wxTRANSPARENT); + + for ( int n = -180; n < 180; n += 30 ) + { + text.Printf(" %d rotated text", n); + dc.DrawRotatedText(text , 400, 400, n); + } - dc.SetFont( wxFont( 18, wxSWISS, 0, 0 ) ); + dc.SetFont( wxFont( 18, wxSWISS, wxNORMAL, wxNORMAL ) ); dc.DrawText( "This is Swiss 18pt text.", 110, 40 ); @@ -285,7 +300,6 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) 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 ); @@ -307,6 +321,20 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) } +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 // ---------------------------------------------------------------------------- @@ -315,7 +343,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) @@ -504,19 +531,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;