]>
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
);
75 DECLARE_DYNAMIC_CLASS(MyFrame
)
81 class MyApp
: public wxApp
84 virtual bool OnInit();
93 const int ID_QUIT
= 108;
94 const int ID_ABOUT
= 109;
96 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
98 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
99 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
100 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
101 EVT_PLOT_CLICKED ( -1, MyFrame::OnPlotClick
)
102 EVT_PLOT_DOUBLECLICKED ( -1, MyFrame::OnPlotDClick
)
106 : wxFrame( (wxFrame
*)NULL
, -1, _T("wxPlotWindow sample"),
107 wxPoint(20,20), wxSize(470,500) )
109 wxMenu
*file_menu
= new wxMenu();
110 file_menu
->Append( ID_ABOUT
, _T("&About.."));
111 file_menu
->Append( ID_QUIT
, _T("E&xit\tAlt-X"));
113 wxMenuBar
*menu_bar
= new wxMenuBar();
114 menu_bar
->Append(file_menu
, _T("&File"));
116 SetMenuBar( menu_bar
);
119 int widths
[] = { -1, 100 };
120 SetStatusWidths( 2, widths
);
122 m_plot
= new wxPlotWindow( this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER
| wxPLOT_DEFAULT
);
123 m_plot
->SetUnitsPerValue( 0.01 );
124 // m_plot->SetScrollOnThumbRelease( TRUE );
126 m_plot
->Add( new MyPlotCurve( 0, -1.5, 1.5 ) );
127 m_plot
->Add( new MyPlotCurve( 50, -1.5, 1.5 ) );
128 wxPlotOnOffCurve
*oo
= new wxPlotOnOffCurve( 10 );
132 oo
->Add( 1000, 2000 );
135 m_log
= new wxTextCtrl( this, -1, _T("This is the log window.\n"), wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE
);
136 wxLog
*old_log
= wxLog::SetActiveTarget( new wxLogTextCtrl( m_log
) );
139 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
141 topsizer
->Add( m_plot
, 1, wxEXPAND
);
142 topsizer
->Add( m_log
, 0, wxEXPAND
);
144 SetAutoLayout( TRUE
);
145 SetSizer( topsizer
);
148 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
153 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
155 (void)wxMessageBox( _T("wxPlotWindow Demo\n"
156 "Robert Roebling (c) 1999,2000"),
157 _T("About wxPlotWindow Demo"), wxICON_INFORMATION
| wxOK
);
160 void MyFrame::OnPlotClick( wxPlotEvent
&event
)
162 double x
= event
.GetPosition() * m_plot
->GetUnitsPerValue();
163 double y
= event
.GetCurve()->GetY( event
.GetPosition() );
164 wxLogMessage( _T("Clicked on curve at x coordinate: %f, value: %f"), x
, y
);
167 void MyFrame::OnPlotDClick( wxPlotEvent
&event
)
169 double x
= event
.GetPosition() * m_plot
->GetUnitsPerValue();
170 double y
= event
.GetCurve()->GetY( event
.GetPosition() );
171 wxLogMessage( _T("Double clicked on curve at x coordinate: %f, value: %f"), x
, y
);
174 //-----------------------------------------------------------------------------
176 //-----------------------------------------------------------------------------
180 wxFrame
*frame
= new MyFrame();