]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/plot/plot.cpp
Regenerate the msvc makefiles after TARGET_CPU option added
[wxWidgets.git] / contrib / samples / plot / plot.cpp
CommitLineData
298a3f2e
WS
1/////////////////////////////////////////////////////////////////////////////
2// Name: plot.cpp
3// Purpose: wxPlotWindow sample
4// Author: Robert Roebling
5// Modified by:
6// Created:
7// Copyright: (C) 1999, Robert Roebling
8// RCS-ID: $Id$
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
8556b795
RR
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
adb85931 23#include "wx/plot/plot.h"
8556b795
RR
24
25#include "wx/image.h"
26#include "wx/listctrl.h"
27#include "wx/sizer.h"
28#include "wx/log.h"
29#include "wx/intl.h"
298a3f2e 30#include "wx/math.h"
8556b795
RR
31
32// derived classes
33
34class MyPlotCurve;
35class MyFrame;
36class MyApp;
37
38// MyPlotCurve
39
40class MyPlotCurve: public wxPlotCurve
41{
42public:
298a3f2e 43 MyPlotCurve( int offsetY, double startY, double endY ) :
8556b795 44 wxPlotCurve( offsetY, startY, endY ) {}
298a3f2e 45
8556b795
RR
46 virtual wxInt32 GetStartX()
47 { return 0; }
48 virtual wxInt32 GetEndX()
49 { return 7000; }
298a3f2e 50
8556b795 51 virtual double GetY( wxInt32 x )
298a3f2e 52 {
8556b795
RR
53 double dx = x;
54 dx /= 100;
55 return sin( dx );
56 }
57};
58
59// MyFrame
60
61class MyFrame: public wxFrame
62{
63public:
64 MyFrame();
65
66 void OnAbout( wxCommandEvent &event );
67 void OnQuit( wxCommandEvent &event );
298a3f2e 68
8556b795
RR
69 void OnPlotClick( wxPlotEvent &event );
70 void OnPlotDClick( wxPlotEvent &event );
71
298a3f2e
WS
72private:
73
8556b795 74 wxPlotWindow *m_plot;
fa0d3447 75#if wxUSE_LOG
8556b795 76 wxTextCtrl *m_log;
fa0d3447 77#endif // wxUSE_LOG
8556b795 78
8556b795
RR
79 DECLARE_DYNAMIC_CLASS(MyFrame)
80 DECLARE_EVENT_TABLE()
81};
82
83// MyApp
84
85class MyApp: public wxApp
86{
87public:
88 virtual bool OnInit();
89};
90
91// main program
92
93IMPLEMENT_APP(MyApp)
94
95// MyFrame
96
8556b795
RR
97IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
98
99BEGIN_EVENT_TABLE(MyFrame,wxFrame)
298a3f2e
WS
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)
8556b795
RR
104END_EVENT_TABLE()
105
106MyFrame::MyFrame()
298a3f2e 107 : wxFrame( (wxFrame *)NULL, wxID_ANY, _T("wxPlotWindow sample"),
8556b795
RR
108 wxPoint(20,20), wxSize(470,500) )
109{
298a3f2e
WS
110 wxMenu *fileMenu = new wxMenu();
111 fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit this program"));
112
113 wxMenu *helpMenu = new wxMenu;
114 helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show about dialog"));
8556b795 115
298a3f2e
WS
116 wxMenuBar *menuBar = new wxMenuBar();
117 menuBar->Append(fileMenu, _T("&File"));
118 menuBar->Append(helpMenu, _T("&Help"));
8556b795 119
298a3f2e 120 SetMenuBar( menuBar );
8556b795 121
d96cdd4a 122#if wxUSE_STATUSBAR
8556b795
RR
123 CreateStatusBar(2);
124 int widths[] = { -1, 100 };
125 SetStatusWidths( 2, widths );
d96cdd4a 126#endif // wxUSE_STATUSBAR
8556b795 127
298a3f2e 128 m_plot = new wxPlotWindow( this, wxID_ANY, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER | wxPLOT_DEFAULT );
8556b795 129 m_plot->SetUnitsPerValue( 0.01 );
298a3f2e 130// m_plot->SetScrollOnThumbRelease( true );
8556b795 131
8fb816ff
MW
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 );
138
8556b795
RR
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 );
142 oo->Add( 10, 20 );
143 oo->Add( 25, 30 );
144 oo->Add( 100, 400 );
145 oo->Add( 1000, 2000 );
146 m_plot->Add( oo );
298a3f2e 147
fa0d3447 148#if wxUSE_LOG
298a3f2e 149 m_log = new wxTextCtrl( this, wxID_ANY, _T("This is the log window.\n"), wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
8556b795
RR
150 wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
151 delete old_log;
fa0d3447 152#endif // wxUSE_LOG
298a3f2e 153
8556b795 154 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
298a3f2e 155
8556b795 156 topsizer->Add( m_plot, 1, wxEXPAND );
fa0d3447 157#if wxUSE_LOG
8556b795 158 topsizer->Add( m_log, 0, wxEXPAND );
fa0d3447 159#endif // wxUSE_LOG
8556b795 160
fa0d3447 161 SetAutoLayout( true );
8556b795 162 SetSizer( topsizer );
298a3f2e
WS
163 topsizer->Fit(this);
164 topsizer->SetSizeHints(this);
8556b795
RR
165}
166
167void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
168{
298a3f2e 169 Close( true );
8556b795
RR
170}
171
172void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
173{
298a3f2e
WS
174 (void)wxMessageBox( _T("wxPlotWindow Demo\n")
175 _T("Robert Roebling (c) 1999,2000"),
176 _T("About wxPlotWindow Demo"), wxICON_INFORMATION | wxOK );
8556b795
RR
177}
178
179void MyFrame::OnPlotClick( wxPlotEvent &event )
180{
181 double x = event.GetPosition() * m_plot->GetUnitsPerValue();
182 double y = event.GetCurve()->GetY( event.GetPosition() );
f7a8c129 183 wxLogMessage( _T("Clicked on curve at x coordinate: %f, value: %f"), x, y );
8556b795
RR
184}
185
186void MyFrame::OnPlotDClick( wxPlotEvent &event )
187{
188 double x = event.GetPosition() * m_plot->GetUnitsPerValue();
189 double y = event.GetCurve()->GetY( event.GetPosition() );
f7a8c129 190 wxLogMessage( _T("Double clicked on curve at x coordinate: %f, value: %f"), x, y );
8556b795
RR
191}
192
193//-----------------------------------------------------------------------------
194// MyApp
195//-----------------------------------------------------------------------------
196
197bool MyApp::OnInit()
198{
199 wxFrame *frame = new MyFrame();
298a3f2e 200 frame->Show( true );
8556b795 201
298a3f2e 202 return true;
8556b795
RR
203}
204