X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0f0c61d0ada7f9c096a6f375825e715f4076d27d..f3c0f9e75f16f7b636bdf7cd1b821e41e0f61592:/samples/drawing/drawing.cpp?ds=sidebyside diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index cbb669192f..ec4d74558e 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -75,7 +75,8 @@ public: void OnOption(wxCommandEvent &event); void OnMouseMove(wxMouseEvent &event); - wxColour SelectColour() const; + wxColour SelectColour(); + void PrepareDC(wxDC& dc); protected: int m_backgroundMode; @@ -218,8 +219,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) menuUserScale->Append( UserScale_Restore, "Restore to normal\tCtrl-0" ); wxMenu *menuAxis = new wxMenu; - menuAxis->Append( AxisMirror_Horiz, "Mirror horizontally\tCtrl-\\", "", TRUE ); - menuAxis->Append( AxisMirror_Vertic, "Mirror vertically\tCtrl-/", "", TRUE ); + menuAxis->Append( AxisMirror_Horiz, "Mirror horizontally\tCtrl-M", "", TRUE ); + menuAxis->Append( AxisMirror_Vertic, "Mirror vertically\tCtrl-N", "", TRUE ); wxMenu *menuLogical = new wxMenu; menuLogical->Append( LogicalOrigin_MoveDown, "Move &down\tCtrl-D" ); @@ -363,13 +364,18 @@ void MyFrame::OnOption(wxCommandEvent &event) Refresh(); } -void MyFrame::OnPaint(wxPaintEvent &WXUNUSED(event) ) +void MyFrame::PrepareDC(wxDC& dc) { - wxPaintDC dc(this); dc.SetMapMode( m_mapMode ); dc.SetUserScale( m_xUserScale, m_yUserScale ); dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin ); - dc.SetAxisOrientation( m_xAxisReversed, m_yAxisReversed ); + dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed ); +} + +void MyFrame::OnPaint(wxPaintEvent &WXUNUSED(event) ) +{ + wxPaintDC dc(this); + PrepareDC(dc); dc.SetBackgroundMode( m_backgroundMode ); if ( m_backgroundBrush.Ok() ) @@ -379,8 +385,52 @@ void MyFrame::OnPaint(wxPaintEvent &WXUNUSED(event) ) if ( m_colourBackground.Ok() ) dc.SetTextBackground( m_colourBackground ); + // mark the origin + dc.DrawCircle(0, 0, 10); +#ifndef __WXGTK__ // not implemented in wxGTK :-( + dc.FloodFill(0, 0, wxColour(255, 0, 0)); +#endif // __WXGTK__ + dc.DrawRectangle( 10, 10, 90, 90 ); - dc.DrawRoundedRectangle( 10, 110, 90, 90, 5 ); + dc.DrawRoundedRectangle( 110, 10, 90, 90, 5 ); + + dc.SetPen( *wxWHITE_PEN ); + dc.DrawLine( 10, 110, 100, 110 ); + dc.SetPen( *wxBLACK_PEN ); + dc.DrawLine( 100, 110, 100, 200 ); + dc.SetPen( *wxWHITE_PEN ); + dc.DrawLine( 100, 200, 10, 200 ); + dc.SetPen( *wxBLACK_PEN ); + dc.DrawLine( 10, 200, 10, 110 ); + + wxPen white_butt( "white", 1, wxSOLID ); + white_butt.SetCap( wxCAP_BUTT ); + wxPen black_butt( "black", 1, wxSOLID ); + black_butt.SetCap( wxCAP_BUTT ); + + dc.SetPen( white_butt ); + dc.DrawLine( 110, 110, 200, 110 ); + dc.SetPen( black_butt ); + dc.DrawLine( 200, 110, 200, 200 ); + dc.SetPen( white_butt ); + dc.DrawLine( 200, 200, 110, 200 ); + dc.SetPen( black_butt ); + dc.DrawLine( 110, 200, 110, 110 ); + + wxPen white_miter( "white", 1, wxSOLID ); + white_miter.SetJoin( wxJOIN_MITER ); + wxPen black_miter( "black", 1, wxSOLID ); + black_miter.SetJoin( wxJOIN_MITER ); + + dc.SetPen( white_miter ); + dc.DrawLine( 210, 110, 300, 110 ); + dc.SetPen( black_miter ); + dc.DrawLine( 300, 110, 300, 200 ); + dc.SetPen( white_miter ); + dc.DrawLine( 300, 200, 210, 200 ); + dc.SetPen( black_miter ); + dc.DrawLine( 210, 200, 210, 110 ); + dc.DrawText( "This is text\n(on multiple lines)", 110, 10 ); @@ -390,9 +440,7 @@ void MyFrame::OnPaint(wxPaintEvent &WXUNUSED(event) ) void MyFrame::OnMouseMove(wxMouseEvent &event) { wxClientDC dc(this); - dc.SetMapMode( m_mapMode ); - dc.SetUserScale( m_xUserScale, m_yUserScale ); - dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin ); + PrepareDC(dc); wxPoint pos = event.GetPosition(); long x = dc.DeviceToLogicalX( pos.x ); @@ -402,7 +450,7 @@ void MyFrame::OnMouseMove(wxMouseEvent &event) SetStatusText( str ); } -wxColour MyFrame::SelectColour() const +wxColour MyFrame::SelectColour() { wxColour col; wxColourData data; @@ -410,7 +458,7 @@ wxColour MyFrame::SelectColour() const if ( dialog.ShowModal() == wxID_OK ) { - col = data.GetColour(); + col = dialog.GetColourData().GetColour(); } return col;