]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/plot/plot.cpp
2 * Program: wxPlotWindow
4 * Author: Robert Roebling
6 * Copyright: (C) 1999, Robert Roebling
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
21 #include "wx/plot/plot.h"
24 #include "wx/listctrl.h"
39 class MyPlotCurve
: public wxPlotCurve
42 MyPlotCurve( int offsetY
, double startY
, double endY
) :
43 wxPlotCurve( offsetY
, startY
, endY
) {}
45 virtual wxInt32
GetStartX()
47 virtual wxInt32
GetEndX()
50 virtual double GetY( wxInt32 x
)
60 class MyFrame
: public wxFrame
65 void OnAbout( wxCommandEvent
&event
);
66 void OnQuit( wxCommandEvent
&event
);
68 void OnPlotClick( wxPlotEvent
&event
);
69 void OnPlotDClick( wxPlotEvent
&event
);
77 DECLARE_DYNAMIC_CLASS(MyFrame
)
83 class MyApp
: public wxApp
86 virtual bool OnInit();
95 const int ID_QUIT
= 108;
96 const int ID_ABOUT
= 109;
98 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
100 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
101 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
102 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
103 EVT_PLOT_CLICKED ( -1, MyFrame::OnPlotClick
)
104 EVT_PLOT_DOUBLECLICKED ( -1, MyFrame::OnPlotDClick
)
108 : wxFrame( (wxFrame
*)NULL
, -1, _T("wxPlotWindow sample"),
109 wxPoint(20,20), wxSize(470,500) )
111 wxMenu
*file_menu
= new wxMenu();
112 file_menu
->Append( ID_ABOUT
, _T("&About.."));
113 file_menu
->Append( ID_QUIT
, _T("E&xit\tAlt-X"));
115 wxMenuBar
*menu_bar
= new wxMenuBar();
116 menu_bar
->Append(file_menu
, _T("&File"));
118 SetMenuBar( menu_bar
);
122 int widths
[] = { -1, 100 };
123 SetStatusWidths( 2, widths
);
124 #endif // wxUSE_STATUSBAR
126 m_plot
= new wxPlotWindow( this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER
| wxPLOT_DEFAULT
);
127 m_plot
->SetUnitsPerValue( 0.01 );
128 // m_plot->SetScrollOnThumbRelease( TRUE );
130 m_plot
->Add( new MyPlotCurve( 0, -1.5, 1.5 ) );
131 m_plot
->Add( new MyPlotCurve( 50, -1.5, 1.5 ) );
132 wxPlotOnOffCurve
*oo
= new wxPlotOnOffCurve( 10 );
136 oo
->Add( 1000, 2000 );
140 m_log
= new wxTextCtrl( this, -1, _T("This is the log window.\n"), wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE
);
141 wxLog
*old_log
= wxLog::SetActiveTarget( new wxLogTextCtrl( m_log
) );
145 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
147 topsizer
->Add( m_plot
, 1, wxEXPAND
);
149 topsizer
->Add( m_log
, 0, wxEXPAND
);
152 SetAutoLayout( true );
153 SetSizer( topsizer
);
156 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
161 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
163 (void)wxMessageBox( _T("wxPlotWindow Demo\n")
164 _T("Robert Roebling (c) 1999,2000"),
165 _T("About wxPlotWindow Demo"), wxICON_INFORMATION
| wxOK
);
168 void MyFrame::OnPlotClick( wxPlotEvent
&event
)
170 double x
= event
.GetPosition() * m_plot
->GetUnitsPerValue();
171 double y
= event
.GetCurve()->GetY( event
.GetPosition() );
172 wxLogMessage( _T("Clicked on curve at x coordinate: %f, value: %f"), x
, y
);
175 void MyFrame::OnPlotDClick( wxPlotEvent
&event
)
177 double x
= event
.GetPosition() * m_plot
->GetUnitsPerValue();
178 double y
= event
.GetCurve()->GetY( event
.GetPosition() );
179 wxLogMessage( _T("Double clicked on curve at x coordinate: %f, value: %f"), x
, y
);
182 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
188 wxFrame
*frame
= new MyFrame();