]> git.saurik.com Git - wxWidgets.git/blob - samples/plot/plot.cpp
Added an OS/2 section to the sql defines
[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, double startY, double endY ) :
43 wxPlotCurve( offsetY, startY, endY ) {}
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 );
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, "wxPlotWindow 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( 0, -1.5, 1.5 ) );
121 m_plot->Add( new MyPlotCurve( 50, -1.5, 1.5 ) );
122
123 m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
124 wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
125 delete old_log;
126
127 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
128
129 topsizer->Add( m_plot, 1, wxEXPAND );
130 topsizer->Add( m_log, 0, wxEXPAND );
131
132 SetAutoLayout( TRUE );
133 SetSizer( topsizer );
134 }
135
136 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
137 {
138 Close( TRUE );
139 }
140
141 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
142 {
143 (void)wxMessageBox( "wxPlotWindow Demo\n"
144 "Robert Roebling (c) 1999,2000",
145 "About wxPlotWindow Demo", wxICON_INFORMATION | wxOK );
146 }
147
148 //-----------------------------------------------------------------------------
149 // MyApp
150 //-----------------------------------------------------------------------------
151
152 bool MyApp::OnInit()
153 {
154 wxFrame *frame = new MyFrame();
155 frame->Show( TRUE );
156
157 return TRUE;
158 }
159