X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f9032263ab28c99aa037d3b67068b2a1032e8957..60df0f96859fb0131ddfa8b477612a15f4a43790:/contrib/samples/canvas/simple/simple.cpp diff --git a/contrib/samples/canvas/simple/simple.cpp b/contrib/samples/canvas/simple/simple.cpp index 796339e384..192d92749d 100644 --- a/contrib/samples/canvas/simple/simple.cpp +++ b/contrib/samples/canvas/simple/simple.cpp @@ -20,7 +20,7 @@ #include "simple.h" // Include icon header -#if defined(__WXGTK__) || defined(__WXMOTIF__) +#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) #include "mondrian.xpm" #endif @@ -38,6 +38,7 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame) EVT_MENU(ID_QUIT, MyFrame::OnQuit) EVT_CLOSE(MyFrame::OnCloseWindow) + EVT_TIMER(-1, MyFrame::OnTimer) END_EVENT_TABLE() MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title, @@ -47,34 +48,38 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title, CreateMyMenuBar(); CreateStatusBar(1); - SetStatusText( "Welcome!" ); + SetStatusText( "Welcome to wxCanvas sample!" ); SetIcon(wxICON(mondrian)); - // wxCanvas from here - + // Create wxCanvasAdmin and wxCanvas. m_admin = new wxCanvasAdmin; wxCanvas *canvas = new wxCanvas( m_admin, this, -1 ); + + canvas->SetScrollbars( 10, 10, 40, 40 ); + + // The wxCanvasAdmin need to know about all Admin wxCanvas objects. m_admin->Append( canvas ); + + // One wxCanvas is the active one (current rendering and current + // world coordinates). m_admin->SetActive( canvas ); - + // One object group is the root in every canvas. wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0); root->DeleteContents( TRUE ); - wxCanvasRect *rect; - - rect = new wxCanvasRect( 120,10,120,140 ); - rect->SetBrush( *wxRED_BRUSH ); - root->Append( rect ); - -/* + // Bunch of rects and images. wxBitmap bitmap( smile_xpm ); wxImage image( bitmap ); m_smile1 = new wxCanvasImage( image, 0,70,32,32 ); root->Append( m_smile1 ); + wxCanvasCircle *circ = new wxCanvasCircle( 170,70,50 ); + circ->SetBrush( *wxBLUE_BRUSH ); + root->Append( circ ); + int i; for (i = 10; i < 300; i+=10) { @@ -92,9 +97,21 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title, r->SetBrush( *wxRED_BRUSH ); root->Append( r ); } -*/ + // This will call all object and children recursivly so + // all know what their wxCanvasAdmin is. Call at the end. + root->SetAdmin( m_admin ); + + // One object group is the root object. canvas->SetRoot( root ); + + m_timer = new wxTimer( this ); + m_timer->Start( 80, FALSE ); +} + +MyFrame::~MyFrame() +{ + delete m_timer; } void MyFrame::CreateMyMenuBar() @@ -122,6 +139,14 @@ void MyFrame::OnCloseWindow( wxCloseEvent &event ) Destroy(); } +void MyFrame::OnTimer( wxTimerEvent &event ) +{ + m_smile1->MoveRelative( 1, 0); + m_smile2->MoveRelative( 1, 0); + + wxWakeUpIdle(); +} + //------------------------------------------------------------------------------ // MyApp //------------------------------------------------------------------------------