]> git.saurik.com Git - wxWidgets.git/blob - samples/plot/plot.cpp
Add draft wxPlotWindow
[wxWidgets.git] / samples / plot / plot.cpp
1 /*
2 * Program: wxPlotWindow
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1999, Robert Roebling
7 *
8 */
9
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20
21 #include "wx/plot.h"
22
23 #include "wx/image.h"
24 #include "wx/listctrl.h"
25 #include "wx/sizer.h"
26 #include "wx/log.h"
27 #include "wx/intl.h"
28
29 #include <math.h>
30
31 // derived classes
32
33 class MyPlotCurve;
34 class MyFrame;
35 class MyApp;
36
37 // MyPlotCurve
38
39 class MyPlotCurve: public wxPlotCurve
40 {
41 public:
42 MyPlotCurve( int offsetY ) :
43 wxPlotCurve( offsetY ) {}
44
45 virtual wxInt32 GetStartX()
46 { return 0; }
47 virtual wxInt32 GetEndX()
48 { return 10000; }
49
50 virtual double GetY( wxInt32 x )
51 {
52 double dx = x;
53 dx /= 100;
54 return sin( dx )+1;
55 }
56 };
57
58 // MyFrame
59
60 class MyFrame: public wxFrame
61 {
62 public:
63 MyFrame();
64
65 void OnAbout( wxCommandEvent &event );
66 void OnQuit( wxCommandEvent &event );
67
68 wxPlotWindow *m_plot;
69 wxTextCtrl *m_log;
70
71 private:
72 DECLARE_DYNAMIC_CLASS(MyFrame)
73 DECLARE_EVENT_TABLE()
74 };
75
76 // MyApp
77
78 class MyApp: public wxApp
79 {
80 public:
81 virtual bool OnInit();
82 };
83
84 // main program
85
86 IMPLEMENT_APP(MyApp)
87
88 // MyFrame
89
90 const int ID_QUIT = 108;
91 const int ID_ABOUT = 109;
92
93 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
94
95 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
96 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
97 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
98 END_EVENT_TABLE()
99
100 MyFrame::MyFrame()
101 : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
102 wxPoint(20,20), wxSize(470,500) )
103 {
104 wxMenu *file_menu = new wxMenu();
105 file_menu->Append( ID_ABOUT, "&About..");
106 file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
107
108 wxMenuBar *menu_bar = new wxMenuBar();
109 menu_bar->Append(file_menu, "&File");
110
111 SetMenuBar( menu_bar );
112
113 CreateStatusBar(2);
114 int widths[] = { -1, 100 };
115 SetStatusWidths( 2, widths );
116
117 m_plot = new wxPlotWindow( this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER );
118 m_plot->SetScrollbars( 10, 10, 500, 0 );
119
120 m_plot->Add( new MyPlotCurve(100) );
121 m_plot->Add( new MyPlotCurve(40) );
122 m_plot->Add( new MyPlotCurve(30) );
123
124 m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
125 wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
126 delete old_log;
127
128 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
129
130 topsizer->Add( m_plot, 1, wxEXPAND );
131 topsizer->Add( m_log, 0, wxEXPAND );
132
133 SetAutoLayout( TRUE );
134 SetSizer( topsizer );
135 }
136
137 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
138 {
139 Close( TRUE );
140 }
141
142 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
143 {
144 (void)wxMessageBox( "wxScroll demo II\n"
145 "Robert Roebling (c) 1998",
146 "About wxScroll II Demo", wxICON_INFORMATION | wxOK );
147 }
148
149 //-----------------------------------------------------------------------------
150 // MyApp
151 //-----------------------------------------------------------------------------
152
153 bool MyApp::OnInit()
154 {
155 wxFrame *frame = new MyFrame();
156 frame->Show( TRUE );
157
158 return TRUE;
159 }
160