X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/41328253cd662fa5996fed29a05b3619d98de013..6dfec4b8d901b13f11745a1371083a0b8c1c6980:/contrib/samples/canvas/test/test.cpp diff --git a/contrib/samples/canvas/test/test.cpp b/contrib/samples/canvas/test/test.cpp index 26e88ece40..d9e9199a98 100644 --- a/contrib/samples/canvas/test/test.cpp +++ b/contrib/samples/canvas/test/test.cpp @@ -52,27 +52,70 @@ MywxCanvasImage::MywxCanvasImage( const wxImage &image, double x, double y, doub void MywxCanvasImage::OnMouse(wxMouseEvent &event) { - static bool first=false; static int dx=0; static int dy=0; int x = event.GetX(); int y = event.GetY(); - if (event.m_leftDown) - { if (!first) - { - first=true; - dx=x; - dy=y; - } - Move(m_area.x+x-dx,m_area.y+y-dy); + if (event.LeftDown()) + { + dx=x; + dy=y; CaptureMouse(); + } + else if (event.LeftUp()) + { + ReleaseMouse(); } else if (IsCapturedMouse()) + { + Move(m_area.x+x-dx,m_area.y+y-dy); + m_owner->UpdateNow(); + } +} + +class MywxCanvasObjectGroupRef: public wxCanvasObjectGroupRef +{ +public: + MywxCanvasObjectGroupRef(double x, double y, wxCanvasObjectGroup* group); + + void OnMouse(wxMouseEvent &event); + + DECLARE_EVENT_TABLE() +}; + +BEGIN_EVENT_TABLE(MywxCanvasObjectGroupRef,wxCanvasObjectGroupRef) + EVT_MOUSE_EVENTS( MywxCanvasObjectGroupRef::OnMouse ) +END_EVENT_TABLE() + +MywxCanvasObjectGroupRef::MywxCanvasObjectGroupRef(double x, double y,wxCanvasObjectGroup* group) + :wxCanvasObjectGroupRef(x,y,group) +{ +} + +void MywxCanvasObjectGroupRef::OnMouse(wxMouseEvent &event) +{ + static int dx=0; + static int dy=0; + + //new position of object + int x = m_owner->GetDeviceX( event.GetX()); + int y = m_owner->GetDeviceY( event.GetY()); + + if (event.LeftDown()) + { + dx=x; + dy=y; + CaptureMouse(); + } + else if (event.LeftUp()) { ReleaseMouse(); - first=false; - dx=0;dy=0; + } + else if (IsCapturedMouse()) + { + Move(m_x+x-dx,m_y+y-dy); + m_owner->UpdateNow(); } } @@ -97,6 +140,10 @@ public: wxCanvasObject *m_sm2; wxCanvasObject *m_sm3; wxCanvasObject *m_sm4; + + MywxCanvasObjectGroupRef *m_ref; + MywxCanvasObjectGroupRef *m_ref2; + wxTimer *m_timer; wxTextCtrl *m_log; @@ -155,42 +202,78 @@ MyFrame::MyFrame() m_canvas = new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); - m_canvas->SetArea( 400, 600 ); + m_canvas->SetArea( 1000,1000 ); m_canvas->SetColour( 255, 255, 255 ); + wxBitmap bitmap( smile_xpm ); wxImage image( bitmap ); - m_sm1 = new wxCanvasImage( image, 0,70,16,16 ); + m_sm1 = new wxCanvasImage( image, 0,70,32,32 ); m_canvas->Append( m_sm1 ); int i; for (i = 10; i < 300; i+=10) - m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) ); + { + wxCanvasRect *r = new wxCanvasRect( i,50,3,140 ); + r->SetBrush( *wxRED_BRUSH ); + m_canvas->Append( r ); + } m_sm2 = new wxCanvasImage( image, 0,140,24,24 ); m_canvas->Append( m_sm2 ); for (i = 15; i < 300; i+=10) - m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) ); + m_canvas->Append( new wxCanvasRect( i,50,3,140 ) ); wxButton *button = new wxButton( m_canvas, -1, "Hello", wxPoint(80,50) ); m_canvas->Append( new wxCanvasControl( button ) ); - m_canvas->Append( new wxCanvasText( "Hello", 180, 50, - wxGetApp().GetFontPath() + "/times.ttf", 20 ) ); + m_canvas->Append( new wxCanvasText( "How are you?", 180, 10, + wxGetApp().GetFontPath() + "/times.ttf", 8 ) ); + + m_canvas->Append( new wxCanvasText( "How are you?", 180, 20, + wxGetApp().GetFontPath() + "/times.ttf", 10 ) ); + + m_canvas->Append( new wxCanvasText( "How are you?", 180, 30, + wxGetApp().GetFontPath() + "/times.ttf", 12 ) ); m_sm3 = new wxCanvasImage( image, 0,210,32,32 ); m_canvas->Append( m_sm3 ); for (i = 10; i < 300; i+=10) - m_canvas->Append( new wxCanvasLine( 10,-15,i,300, 0,255,0 ) ); + m_canvas->Append( new wxCanvasLine( 10,-15,i,300 ) ); + + m_sm4 = new MywxCanvasImage( image, 0,270,64,32 ); + m_canvas->Append( m_sm4 ); + // m_canvas->Append( new wxCanvasLine( 10,-1500e6,50,300000e6, 0,255,0 ) ); // m_canvas->Append( new wxCanvasLine( 10,-150000,50,300000, 0,255,0 ) ); - m_sm4 = new MywxCanvasImage( image, 0,270,64,32 ); - m_canvas->Append( m_sm4 ); +/* + //make a group of wxCanvasObjects + wxCanvasObjectGroup* group1 = new wxCanvasObjectGroup(); + group1->Prepend( new wxCanvasLine( 10,-35,50,190 ) ); + group1->Prepend( new wxCanvasImage( image, 4,38,32,32 ) ); + group1->Prepend( new wxCanvasRect(20,-20,50,170,0,20,240 ) ); + + //make another group of wxCanvasObjects + wxCanvasObjectGroup* group2 = new wxCanvasObjectGroup(); + group2->Prepend( new wxCanvasImage( image, 60,38,52,32 ) ); + group2->Prepend( new wxCanvasRect(10,20,104,52,10,40,10 ) ); + + //this a reference to group2 put into group1 + wxCanvasObjectGroupRef* m_subref = new wxCanvasObjectGroupRef(60,50, group2); + group1->Prepend( m_subref ); + + //now make two refrences to group1 into root group of the canvas + m_ref = new MywxCanvasObjectGroupRef(40,200, group1); + m_canvas->Prepend( m_ref ); + + m_ref2 = new MywxCanvasObjectGroupRef(80,350, group1); + m_canvas->Prepend( m_ref2 ); +*/ m_log = new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE ); wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); @@ -220,10 +303,14 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) ) { - m_sm1->Move( m_sm1->GetX()+1, m_sm1->GetY() ); + m_sm1->Move( m_sm1->GetX()+1, m_sm1 ->GetY() ); m_sm2->Move( m_sm2->GetX()+1, m_sm2->GetY() ); m_sm3->Move( m_sm3->GetX()+1, m_sm3->GetY() ); - m_sm4->Move( m_sm4->GetX()+1, m_sm4->GetY() ); + m_sm4->Move( m_sm4->GetX()+2, m_sm4->GetY() ); +/* + m_ref->Move( m_ref->GetPosX()+1, m_ref->GetPosY() ); + m_ref2->Move( m_ref2->GetPosX()+2, m_ref2->GetPosY() ); +*/ wxWakeUpIdle(); }