]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/plot/plot.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPlotWindow sample
4 // Author: Robert Roebling
7 // Copyright: (C) 1999, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/plot/plot.h"
26 #include "wx/listctrl.h"
40 class MyPlotCurve
: public wxPlotCurve
43 MyPlotCurve( int offsetY
, double startY
, double endY
) :
44 wxPlotCurve( offsetY
, startY
, endY
) {}
46 virtual wxInt32
GetStartX()
48 virtual wxInt32
GetEndX()
51 virtual double GetY( wxInt32 x
)
61 class MyFrame
: public wxFrame
66 void OnAbout( wxCommandEvent
&event
);
67 void OnQuit( wxCommandEvent
&event
);
69 void OnPlotClick( wxPlotEvent
&event
);
70 void OnPlotDClick( wxPlotEvent
&event
);
79 DECLARE_DYNAMIC_CLASS(MyFrame
)
85 class MyApp
: public wxApp
88 virtual bool OnInit();
97 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
99 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
100 EVT_MENU (wxID_ABOUT
, MyFrame::OnAbout
)
101 EVT_MENU (wxID_EXIT
, MyFrame::OnQuit
)
102 EVT_PLOT_CLICKED (wxID_ANY
, MyFrame::OnPlotClick
)
103 EVT_PLOT_DOUBLECLICKED (wxID_ANY
, MyFrame::OnPlotDClick
)
107 : wxFrame( (wxFrame
*)NULL
, wxID_ANY
, _T("wxPlotWindow sample"),
108 wxPoint(20,20), wxSize(470,500) )
110 wxMenu
*fileMenu
= new wxMenu();
111 fileMenu
->Append( wxID_EXIT
, _T("E&xit\tAlt-X"), _T("Quit this program"));
113 wxMenu
*helpMenu
= new wxMenu
;
114 helpMenu
->Append(wxID_ABOUT
, _T("&About...\tF1"), _T("Show about dialog"));
116 wxMenuBar
*menuBar
= new wxMenuBar();
117 menuBar
->Append(fileMenu
, _T("&File"));
118 menuBar
->Append(helpMenu
, _T("&Help"));
120 SetMenuBar( menuBar
);
124 int widths
[] = { -1, 100 };
125 SetStatusWidths( 2, widths
);
126 #endif // wxUSE_STATUSBAR
128 m_plot
= new wxPlotWindow( this, wxID_ANY
, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER
| wxPLOT_DEFAULT
);
129 m_plot
->SetUnitsPerValue( 0.01 );
130 // m_plot->SetScrollOnThumbRelease( true );
132 //Add a blue, 16pt chart title
133 wxString
titleText( _T("The Chart Title") );
134 wxFont
titleFont( *wxNORMAL_FONT
);
135 titleFont
.SetPointSize( 16 );
136 wxColour
titleColour( *wxBLUE
);
137 m_plot
->AddChartTitle( titleText
, titleFont
, titleColour
);
139 m_plot
->Add( new MyPlotCurve( 0, -1.5, 1.5 ) );
140 m_plot
->Add( new MyPlotCurve( 50, -1.5, 1.5 ) );
141 wxPlotOnOffCurve
*oo
= new wxPlotOnOffCurve( 10 );
145 oo
->Add( 1000, 2000 );
149 m_log
= new wxTextCtrl( this, wxID_ANY
, _T("This is the log window.\n"), wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE
);
150 wxLog
*old_log
= wxLog::SetActiveTarget( new wxLogTextCtrl( m_log
) );
154 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
156 topsizer
->Add( m_plot
, 1, wxEXPAND
);
158 topsizer
->Add( m_log
, 0, wxEXPAND
);
161 SetAutoLayout( true );
162 SetSizer( topsizer
);
164 topsizer
->SetSizeHints(this);
167 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
172 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
174 (void)wxMessageBox( _T("wxPlotWindow Demo\n")
175 _T("Robert Roebling (c) 1999,2000"),
176 _T("About wxPlotWindow Demo"), wxICON_INFORMATION
| wxOK
);
179 void MyFrame::OnPlotClick( wxPlotEvent
&event
)
181 double x
= event
.GetPosition() * m_plot
->GetUnitsPerValue();
182 double y
= event
.GetCurve()->GetY( event
.GetPosition() );
183 wxLogMessage( _T("Clicked on curve at x coordinate: %f, value: %f"), x
, y
);
186 void MyFrame::OnPlotDClick( wxPlotEvent
&event
)
188 double x
= event
.GetPosition() * m_plot
->GetUnitsPerValue();
189 double y
= event
.GetCurve()->GetY( event
.GetPosition() );
190 wxLogMessage( _T("Double clicked on curve at x coordinate: %f, value: %f"), x
, y
);
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
199 wxFrame
*frame
= new MyFrame();