X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..b771aa29dd34686cc92ef4675978b1fdc1a47a29:/samples/drawing/drawing.cpp?ds=sidebyside diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 831b75f128..0e8f8ee757 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -43,7 +43,7 @@ // ---------------------------------------------------------------------------- // the application icon -#if defined(__WXGTK__) || defined(__WXMOTIF__) +#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) #include "mondrian.xpm" #endif @@ -159,6 +159,8 @@ protected: void DrawCircles(wxDC& dc); void DrawDefault(wxDC& dc); + void DrawRegionsHelper(wxDC& dc, wxCoord x); + private: MyFrame *m_owner; @@ -344,9 +346,11 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) EVT_MOTION (MyCanvas::OnMouseMove) END_EVENT_TABLE() -#include "../image/smile.xpm" +#include "smile.xpm" -MyCanvas::MyCanvas( MyFrame *parent ) : wxScrolledWindow( parent ) +MyCanvas::MyCanvas(MyFrame *parent) + : wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize, + wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE) { m_owner = parent; m_show = Show_Default; @@ -361,13 +365,14 @@ MyCanvas::MyCanvas( MyFrame *parent ) : wxScrolledWindow( parent ) // the colors of the monochrome bitmap pixels to the fillpattern // // I abused the the menu items for setting so called back and fore ground color -// just to show how the those colors do influence the fillpatterns just play -// with those, and with the code variations are endless using other logical +// just to show how the those colors do influence the fillpatterns just play +// with those, and with the code variations are endless using other logical // functions. void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent ) { - wxBrush* brush4 = new wxBrush(*gs_bmp4); +// wxBrush* brush4 = new wxBrush(*gs_bmp4); + wxBrush* brush4 = new wxBrush(*wxBLACK,wxFDIAGONAL_HATCH); wxBrush* brush4_mono = new wxBrush(*gs_bmp4_mono); wxBrush* brush36 = new wxBrush(*gs_bmp36); @@ -410,15 +415,15 @@ void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent ) dc.SetTextForeground(*wxCYAN); dc.SetTextBackground(m_owner->m_colourBackground); dc.DrawRectangle( x+10, y+10, 200, 200 ); - + dc.SetPen( wxPen( "green", 4, wxSOLID) ); dc.SetBrush( *brush4_mono ); dc.SetTextForeground(*wxCYAN); dc.SetTextBackground(m_owner->m_colourBackground); dc.DrawRectangle( x+50, y+50, 200, 200 ); - + dc.DrawCircle( x+400, y+50, 130 ); - + dc.SetBrush(wxNullBrush); dc.SetPen(wxNullPen); break; @@ -982,32 +987,52 @@ void MyCanvas::DrawCircles(wxDC& dc) void MyCanvas::DrawRegions(wxDC& dc) { + dc.DrawText("You should see a red rect partly covered by a cyan one " + "on the left", 10, 5); + dc.DrawText("and 5 smileys from which 4 are partially clipped on the " + "right (2 copies should be identical)", + 10, 5 + dc.GetCharHeight()); + + DrawRegionsHelper(dc, 10); + DrawRegionsHelper(dc, 350); +} + +void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x) +{ + dc.DestroyClippingRegion(); dc.SetBrush( *wxWHITE_BRUSH ); dc.SetPen( *wxTRANSPARENT_PEN ); - dc.DrawRectangle( 10,10,310,310 ); - - dc.SetClippingRegion( 20,20,100,270 ); - + dc.DrawRectangle( x,50,310,310 ); + + dc.SetClippingRegion( x+10,60,100,270 ); + dc.SetBrush( *wxRED_BRUSH ); - dc.DrawRectangle( 10,10,310,310 ); + dc.DrawRectangle( x,50,310,310 ); + + dc.SetClippingRegion( x+10,60,100,100 ); - dc.SetClippingRegion( 20,20,100,100 ); - dc.SetBrush( *wxCYAN_BRUSH ); - dc.DrawRectangle( 10,10,310,310 ); + dc.DrawRectangle( x,50,310,310 ); + + // when drawing the left half, destroy the clipping region, when drawing + // the right one - leave it + // + // normally it shouldn't make any difference as SetClippingRegion() + // replaces the old clipping region + if ( x < 300 ) + dc.DestroyClippingRegion(); + dc.SetClippingRegion( x+110,70,100,270 ); - dc.DestroyClippingRegion(); - dc.SetClippingRegion( 120,30,100,270 ); - dc.SetBrush( *wxGREY_BRUSH ); - dc.DrawRectangle( 10,10,310,310 ); - + dc.DrawRectangle( x,50,310,310 ); + if (m_smile_bmp.Ok()) { - dc.DrawBitmap( m_smile_bmp, 140, 20, TRUE ); - dc.DrawBitmap( m_smile_bmp, 140, 290, TRUE ); - dc.DrawBitmap( m_smile_bmp, 110, 80, TRUE ); - dc.DrawBitmap( m_smile_bmp, 210, 80, TRUE ); + dc.DrawBitmap( m_smile_bmp, x+150, 200, TRUE ); + dc.DrawBitmap( m_smile_bmp, x+130, 60, TRUE ); + dc.DrawBitmap( m_smile_bmp, x+130, 330, TRUE ); + dc.DrawBitmap( m_smile_bmp, x+100, 120, TRUE ); + dc.DrawBitmap( m_smile_bmp, x+200, 120, TRUE ); } } @@ -1015,6 +1040,7 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) { wxPaintDC dc(this); PrepareDC(dc); + m_owner->PrepareDC(dc); dc.SetBackgroundMode( m_owner->m_backgroundMode ); @@ -1080,6 +1106,13 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) case Show_Ops: DrawWithLogicalOps(dc); break; + + default: + { + dc.SetPen( *wxBLACK_PEN ); + dc.DrawLine( 0,0,100,100 ); + } + } } @@ -1115,7 +1148,8 @@ END_EVENT_TABLE() // frame constructor MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame((wxFrame *)NULL, -1, title, pos, size) + : wxFrame((wxFrame *)NULL, -1, title, pos, size, + wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) { // set the frame icon SetIcon(wxICON(mondrian)); @@ -1220,12 +1254,12 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnShow(wxCommandEvent& event) { - m_canvas->Show((ScreenToShow)(event.GetInt() - MenuShow_First)); + m_canvas->Show((ScreenToShow)(event.GetId() - MenuShow_First)); } void MyFrame::OnOption(wxCommandEvent& event) { - switch (event.GetInt()) + switch (event.GetId()) { case MapMode_Text: m_mapMode = wxMM_TEXT;