X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/981b25083e41288f142e717f917e709347c34a02..f1567cddead054974c4a079ed8ee2c798ef998dc:/samples/plot/plot.cpp?ds=sidebyside diff --git a/samples/plot/plot.cpp b/samples/plot/plot.cpp index 760c941451..447944fd7b 100644 --- a/samples/plot/plot.cpp +++ b/samples/plot/plot.cpp @@ -39,19 +39,19 @@ class MyApp; class MyPlotCurve: public wxPlotCurve { public: - MyPlotCurve( int offsetY ) : - wxPlotCurve( offsetY ) {} + MyPlotCurve( int offsetY, double startY, double endY ) : + wxPlotCurve( offsetY, startY, endY ) {} virtual wxInt32 GetStartX() { return 0; } virtual wxInt32 GetEndX() - { return 10000; } + { return 7000; } virtual double GetY( wxInt32 x ) { double dx = x; dx /= 100; - return sin( dx )+1; + return sin( dx ); } }; @@ -64,6 +64,9 @@ public: void OnAbout( wxCommandEvent &event ); void OnQuit( wxCommandEvent &event ); + + void OnPlotClick( wxPlotEvent &event ); + void OnPlotDClick( wxPlotEvent &event ); wxPlotWindow *m_plot; wxTextCtrl *m_log; @@ -93,12 +96,14 @@ const int ID_ABOUT = 109; IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) BEGIN_EVENT_TABLE(MyFrame,wxFrame) - EVT_MENU (ID_ABOUT, MyFrame::OnAbout) - EVT_MENU (ID_QUIT, MyFrame::OnQuit) + EVT_MENU (ID_ABOUT, MyFrame::OnAbout) + EVT_MENU (ID_QUIT, MyFrame::OnQuit) + EVT_PLOT_CLICKED ( -1, MyFrame::OnPlotClick) + EVT_PLOT_DOUBLECLICKED ( -1, MyFrame::OnPlotDClick) END_EVENT_TABLE() MyFrame::MyFrame() - : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample", + : wxFrame( (wxFrame *)NULL, -1, "wxPlotWindow sample", wxPoint(20,20), wxSize(470,500) ) { wxMenu *file_menu = new wxMenu(); @@ -114,12 +119,17 @@ MyFrame::MyFrame() int widths[] = { -1, 100 }; SetStatusWidths( 2, widths ); - m_plot = new wxPlotWindow( this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER ); - m_plot->SetScrollbars( 10, 10, 500, 0 ); - - m_plot->Add( new MyPlotCurve(100) ); - m_plot->Add( new MyPlotCurve(40) ); - m_plot->Add( new MyPlotCurve(30) ); + m_plot = new wxPlotWindow( this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER | wxPLOT_DEFAULT ); + m_plot->SetUnitsPerValue( 0.01 ); + + m_plot->Add( new MyPlotCurve( 0, -1.5, 1.5 ) ); + m_plot->Add( new MyPlotCurve( 50, -1.5, 1.5 ) ); + wxPlotOnOffCurve *oo = new wxPlotOnOffCurve( 10 ); + oo->Add( 10, 20 ); + oo->Add( 25, 30 ); + oo->Add( 100, 400 ); + oo->Add( 1000, 2000 ); + m_plot->Add( oo ); m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE ); wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); @@ -141,9 +151,23 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) { - (void)wxMessageBox( "wxScroll demo II\n" - "Robert Roebling (c) 1998", - "About wxScroll II Demo", wxICON_INFORMATION | wxOK ); + (void)wxMessageBox( "wxPlotWindow Demo\n" + "Robert Roebling (c) 1999,2000", + "About wxPlotWindow Demo", wxICON_INFORMATION | wxOK ); +} + +void MyFrame::OnPlotClick( wxPlotEvent &event ) +{ + double x = event.GetPosition() * m_plot->GetUnitsPerValue(); + double y = event.GetCurve()->GetY( event.GetPosition() ); + wxLogMessage( "Clicked on curve at x coordinate: %f, value: %f", x, y ); +} + +void MyFrame::OnPlotDClick( wxPlotEvent &event ) +{ + double x = event.GetPosition() * m_plot->GetUnitsPerValue(); + double y = event.GetCurve()->GetY( event.GetPosition() ); + wxLogMessage( "Double clicked on curve at x coordinate: %f, value: %f", x, y ); } //-----------------------------------------------------------------------------