X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a11672a469f036436838911c268cb2f8d5da5bf8..830efc9b0cb87eae22d4435af7858175017522ab:/samples/drawing/drawing.cpp diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index e08e04250d..6e15c9c541 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -37,6 +37,7 @@ #include "wx/colordlg.h" #include "wx/image.h" +#include "wx/artprov.h" // ---------------------------------------------------------------------------- // ressources @@ -114,6 +115,7 @@ public: // event handlers (these functions should _not_ be virtual) void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); + void OnClip(wxCommandEvent& event); void OnShow(wxCommandEvent &event); void OnOption(wxCommandEvent &event); @@ -150,6 +152,9 @@ public: void Show(ScreenToShow show) { m_show = show; Refresh(); } + // set or remove the clipping region + void Clip(bool clip) { m_clip = clip; Refresh(); } + protected: void DrawTestLines( int x, int y, int width, wxDC &dc ); void DrawTestPoly(wxDC& dc); @@ -169,6 +174,7 @@ private: ScreenToShow m_show; wxBitmap m_smile_bmp; wxIcon m_std_icon; + bool m_clip; DECLARE_EVENT_TABLE() }; @@ -196,6 +202,8 @@ enum File_ShowCircles, MenuShow_Last = File_ShowCircles, + File_Clip, + MenuOption_First, MapMode_Text = MenuOption_First, @@ -368,7 +376,7 @@ MyCanvas::MyCanvas(MyFrame *parent) m_owner = parent; m_show = Show_Default; m_smile_bmp = wxBitmap(smile_xpm); - m_std_icon = wxTheApp->GetStdIcon(wxICON_INFORMATION); + m_std_icon = wxArtProvider::GetIcon(wxART_INFORMATION); } void MyCanvas::DrawTestBrushes(wxDC& dc) @@ -474,10 +482,12 @@ void MyCanvas::DrawDefault(wxDC& dc) { // mark the origin dc.DrawCircle(0, 0, 10); -#if !(defined __WXGTK__) && !(defined __WXMOTIF__) && !(defined __WXMGL__) - // not implemented in wxGTK or wxMOTIF :-( - dc.FloodFill(0, 0, wxColour(255, 0, 0)); -#endif // + + //flood fill using brush, starting at 1,1 and replacing whatever colour we find there + dc.SetBrush(wxBrush(wxColour(128,128,0), wxSOLID)); + wxColour tmpColour ; + dc.GetPixel(1,1, &tmpColour); + dc.FloodFill(1,1, tmpColour, wxFLOOD_SURFACE); dc.DrawCheckMark(5, 80, 15, 15); dc.DrawCheckMark(25, 80, 30, 30); @@ -553,9 +563,9 @@ void MyCanvas::DrawDefault(wxDC& dc) memdc.SelectObject( wxNullBitmap ); dc.DrawBitmap( bitmap, 10, 170 ); - wxImage image( bitmap ); + wxImage image = bitmap.ConvertToImage(); image.Rescale( 60,210 ); - bitmap = image.ConvertToBitmap(); + bitmap = wxBitmap(image); dc.DrawBitmap( bitmap, 50, 170 ); // test the rectangle outline drawing - there should be one pixel between @@ -875,9 +885,10 @@ void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime) dc.DestroyClippingRegion(); wxRegion region(x + 110, y + 20, 100, 270); +#if !defined(__WXMOTIF__) && !defined(__WXMAC__) if ( !firstTime ) region.Offset(10, 10); - +#endif dc.SetClippingRegion(region); dc.SetBrush( *wxGREY_BRUSH ); @@ -915,11 +926,15 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) } } + if ( m_clip ) + dc.SetClippingRegion(100, 100, 100, 100); + dc.Clear(); - if ( m_owner->m_textureBackground) { + if ( m_owner->m_textureBackground ) + { dc.SetPen(*wxMEDIUM_GREY_PEN); - for (int i=0; i<200; i++) + for ( int i = 0; i < 200; i++ ) dc.DrawLine(0, i*10, i*10, 0); } @@ -990,6 +1005,7 @@ void MyCanvas::OnMouseMove(wxMouseEvent &event) BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU (File_Quit, MyFrame::OnQuit) EVT_MENU (File_About, MyFrame::OnAbout) + EVT_MENU (File_Clip, MyFrame::OnClip) EVT_MENU_RANGE(MenuShow_First, MenuShow_Last, MyFrame::OnShow) @@ -1015,6 +1031,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) menuFile->Append(File_ShowRegions, "Re&gions screen\tF8"); menuFile->Append(File_ShowCircles, "&Circles screen\tF9"); menuFile->AppendSeparator(); + menuFile->AppendCheckItem(File_Clip, "&Clip\tCtrl-C", "Clip/unclip drawing"); + menuFile->AppendSeparator(); menuFile->Append(File_About, "&About...\tCtrl-A", "Show about dialog"); menuFile->AppendSeparator(); menuFile->Append(File_Quit, "E&xit\tAlt-X", "Quit this program"); @@ -1106,6 +1124,11 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxMessageBox(msg, "About Drawing", wxOK | wxICON_INFORMATION, this); } +void MyFrame::OnClip(wxCommandEvent& event) +{ + m_canvas->Clip(event.IsChecked()); +} + void MyFrame::OnShow(wxCommandEvent& event) { m_canvas->Show((ScreenToShow)(event.GetId() - MenuShow_First));