]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: plot.h | |
3 | // Purpose: wxPlotWindow | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 12/1/2000 | |
7 | // Copyright: (c) Robert Roebling | |
8 | // RCS-ID: $Id$ | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_PLOT_H_ | |
13 | #define _WX_PLOT_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "plot.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_PLOT | |
22 | ||
23 | #include "wx/scrolwin.h" | |
24 | #include "wx/event.h" | |
25 | ||
26 | //----------------------------------------------------------------------------- | |
27 | // classes | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | class WXDLLEXPORT wxPlotEvent; | |
31 | class WXDLLEXPORT wxPlotCurve; | |
32 | class WXDLLEXPORT wxPlotArea; | |
33 | class WXDLLEXPORT wxPlotXAxisArea; | |
34 | class WXDLLEXPORT wxPlotYAxisArea; | |
35 | class WXDLLEXPORT wxPlotWindow; | |
36 | ||
37 | //----------------------------------------------------------------------------- | |
38 | // consts | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | #define wxPLOT_X_AXIS 0x0004 | |
42 | #define wxPLOT_Y_AXIS 0x0008 | |
43 | #define wxPLOT_BUTTON_MOVE 0x0010 | |
44 | #define wxPLOT_BUTTON_ZOOM 0x0020 | |
45 | #define wxPLOT_BUTTON_ENLARGE 0x0040 | |
46 | ||
47 | #define wxPLOT_BUTTON_ALL (wxPLOT_BUTTON_MOVE|wxPLOT_BUTTON_ZOOM|wxPLOT_BUTTON_ENLARGE) | |
48 | #define wxPLOT_DEFAULT (wxPLOT_X_AXIS|wxPLOT_Y_AXIS | wxPLOT_BUTTON_ALL) | |
49 | ||
50 | //----------------------------------------------------------------------------- | |
51 | // wxPlotEvent | |
52 | //----------------------------------------------------------------------------- | |
53 | ||
54 | class WXDLLEXPORT wxPlotEvent: public wxNotifyEvent | |
55 | { | |
56 | public: | |
57 | wxPlotEvent( wxEventType commandType = wxEVT_NULL, int id = 0 ); | |
58 | ||
59 | wxPlotCurve *GetCurve() | |
60 | { return m_curve; } | |
61 | void SetCurve( wxPlotCurve *curve ) | |
62 | { m_curve = curve; } | |
63 | ||
64 | double GetZoom() | |
65 | { return m_zoom; } | |
66 | void SetZoom( double zoom ) | |
67 | { m_zoom = zoom; } | |
68 | ||
69 | wxInt32 GetPosition() | |
70 | { return m_position; } | |
71 | void SetPosition( wxInt32 pos ) | |
72 | { m_position = pos; } | |
73 | ||
74 | private: | |
75 | wxPlotCurve *m_curve; | |
76 | double m_zoom; | |
77 | wxInt32 m_position; | |
78 | }; | |
79 | ||
80 | //----------------------------------------------------------------------------- | |
81 | // wxPlotCurve | |
82 | //----------------------------------------------------------------------------- | |
83 | ||
84 | class WXDLLEXPORT wxPlotCurve: public wxObject | |
85 | { | |
86 | public: | |
87 | wxPlotCurve( int offsetY, double startY, double endY ); | |
88 | ||
89 | virtual wxInt32 GetStartX() = 0; | |
90 | virtual wxInt32 GetEndX() = 0; | |
91 | ||
92 | virtual double GetY( wxInt32 x ) = 0; | |
93 | ||
94 | void SetStartY( double startY ) | |
95 | { m_startY = startY; } | |
96 | double GetStartY() | |
97 | { return m_startY; } | |
98 | void SetEndY( double endY ) | |
99 | { m_endY = endY; } | |
100 | double GetEndY() | |
101 | { return m_endY; } | |
102 | void SetOffsetY( int offsetY ) | |
103 | { m_offsetY = offsetY; } | |
104 | int GetOffsetY() | |
105 | { return m_offsetY; } | |
106 | ||
107 | private: | |
108 | int m_offsetY; | |
109 | double m_startY; | |
110 | double m_endY; | |
111 | ||
112 | DECLARE_ABSTRACT_CLASS(wxPlotCurve) | |
113 | }; | |
114 | ||
115 | //----------------------------------------------------------------------------- | |
116 | // wxPlotArea | |
117 | //----------------------------------------------------------------------------- | |
118 | ||
119 | class WXDLLEXPORT wxPlotArea: public wxWindow | |
120 | { | |
121 | public: | |
122 | wxPlotArea() {} | |
123 | wxPlotArea( wxPlotWindow *parent ); | |
124 | ||
125 | void OnPaint( wxPaintEvent &event ); | |
126 | void OnMouse( wxMouseEvent &event ); | |
127 | ||
128 | void DrawCurve( wxDC *dc, wxPlotCurve *curve, int from = -1, int to = -1 ); | |
129 | void DeleteCurve( wxPlotCurve *curve, int from = -1, int to = -1 ); | |
130 | ||
131 | virtual void ScrollWindow( int dx, int dy, const wxRect *rect ); | |
132 | ||
133 | private: | |
134 | wxPlotWindow *m_owner; | |
135 | bool m_zooming; | |
136 | ||
137 | DECLARE_CLASS(wxPlotArea) | |
138 | DECLARE_EVENT_TABLE() | |
139 | }; | |
140 | ||
141 | //----------------------------------------------------------------------------- | |
142 | // wxPlotXAxisArea | |
143 | //----------------------------------------------------------------------------- | |
144 | ||
145 | class WXDLLEXPORT wxPlotXAxisArea: public wxWindow | |
146 | { | |
147 | public: | |
148 | wxPlotXAxisArea() {} | |
149 | wxPlotXAxisArea( wxPlotWindow *parent ); | |
150 | ||
151 | void OnPaint( wxPaintEvent &event ); | |
152 | void OnMouse( wxMouseEvent &event ); | |
153 | ||
154 | private: | |
155 | wxPlotWindow *m_owner; | |
156 | ||
157 | DECLARE_CLASS(wxPlotXAxisArea) | |
158 | DECLARE_EVENT_TABLE() | |
159 | }; | |
160 | ||
161 | //----------------------------------------------------------------------------- | |
162 | // wxPlotYAxisArea | |
163 | //----------------------------------------------------------------------------- | |
164 | ||
165 | class WXDLLEXPORT wxPlotYAxisArea: public wxWindow | |
166 | { | |
167 | public: | |
168 | wxPlotYAxisArea() {} | |
169 | wxPlotYAxisArea( wxPlotWindow *parent ); | |
170 | ||
171 | void OnPaint( wxPaintEvent &event ); | |
172 | void OnMouse( wxMouseEvent &event ); | |
173 | ||
174 | private: | |
175 | wxPlotWindow *m_owner; | |
176 | ||
177 | DECLARE_CLASS(wxPlotYAxisArea) | |
178 | DECLARE_EVENT_TABLE() | |
179 | }; | |
180 | ||
181 | //----------------------------------------------------------------------------- | |
182 | // wxPlotWindow | |
183 | //----------------------------------------------------------------------------- | |
184 | ||
185 | class WXDLLEXPORT wxPlotWindow: public wxScrolledWindow | |
186 | { | |
187 | public: | |
188 | wxPlotWindow() {} | |
189 | wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flags = wxPLOT_DEFAULT ); | |
190 | ~wxPlotWindow(); | |
191 | ||
192 | // curve accessors | |
193 | // --------------- | |
194 | ||
195 | void Add( wxPlotCurve *curve ); | |
196 | size_t GetCount(); | |
197 | wxPlotCurve *GetAt( size_t n ); | |
198 | ||
199 | void SetCurrent( wxPlotCurve* current ); | |
200 | wxPlotCurve *GetCurrent(); | |
201 | ||
202 | void Delete( wxPlotCurve* curve ); | |
203 | ||
204 | // vertical representation | |
205 | // ----------------------- | |
206 | ||
207 | void Move( wxPlotCurve* curve, int pixels_up ); | |
208 | void Enlarge( wxPlotCurve *curve, double factor ); | |
209 | ||
210 | // horizontal representation | |
211 | // ------------------------- | |
212 | ||
213 | void SetUnitsPerValue( double upv ); | |
214 | double GetUnitsPerValue() | |
215 | { return m_xUnitsPerValue; } | |
216 | ||
217 | void SetZoom( double zoom ); | |
218 | double GetZoom() | |
219 | { return m_xZoom; } | |
220 | ||
221 | // options | |
222 | // ------- | |
223 | ||
224 | void SetScrollOnThumbRelease( bool scrollOnThumbRelease = TRUE ) | |
225 | { m_scrollOnThumbRelease = scrollOnThumbRelease; } | |
226 | bool GetScrollOnThumbRelease() | |
227 | { return m_scrollOnThumbRelease; } | |
228 | ||
229 | void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre = TRUE ) | |
230 | { m_enlargeAroundWindowCentre = enlargeAroundWindowCentre; } | |
231 | bool GetEnlargeAroundWindowCentre() | |
232 | { return m_enlargeAroundWindowCentre; } | |
233 | ||
234 | // events (may be overridden) | |
235 | // -------------------------- | |
236 | ||
237 | void OnMoveUp( wxCommandEvent& event ); | |
238 | void OnMoveDown( wxCommandEvent& event ); | |
239 | ||
240 | void OnEnlarge( wxCommandEvent& event ); | |
241 | void OnShrink( wxCommandEvent& event ); | |
242 | void OnZoomIn( wxCommandEvent& event ); | |
243 | void OnZoomOut( wxCommandEvent& event ); | |
244 | ||
245 | void OnScroll2( wxScrollWinEvent& event ); | |
246 | ||
247 | // utilities | |
248 | // --------- | |
249 | ||
250 | void RedrawEverything(); | |
251 | void RedrawXAxis(); | |
252 | void RedrawYAxis(); | |
253 | ||
254 | void ResetScrollbar(); | |
255 | ||
256 | private: | |
257 | friend wxPlotArea; | |
258 | friend wxPlotXAxisArea; | |
259 | friend wxPlotYAxisArea; | |
260 | ||
261 | double m_xUnitsPerValue; | |
262 | double m_xZoom; | |
263 | ||
264 | wxList m_curves; | |
265 | wxPlotArea *m_area; | |
266 | wxPlotXAxisArea *m_xaxis; | |
267 | wxPlotYAxisArea *m_yaxis; | |
268 | wxPlotCurve *m_current; | |
269 | ||
270 | bool m_scrollOnThumbRelease; | |
271 | bool m_enlargeAroundWindowCentre; | |
272 | ||
273 | DECLARE_CLASS(wxPlotWindow) | |
274 | DECLARE_EVENT_TABLE() | |
275 | }; | |
276 | ||
277 | // ---------------------------------------------------------------------------- | |
278 | // calendar events macros | |
279 | // ---------------------------------------------------------------------------- | |
280 | ||
281 | #define EVT_PLOT(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
282 | #define EVT_PLOT_SEL_CHANGING(id, fn) { wxEVT_PLOT_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
283 | #define EVT_PLOT_SEL_CHANGED(id, fn) { wxEVT_PLOT_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
284 | #define EVT_PLOT_CLICKED(id, fn) { wxEVT_PLOT_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
285 | #define EVT_PLOT_DOUBLECLICKED(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
286 | #define EVT_PLOT_ZOOM_IN(id, fn) { wxEVT_PLOT_ZOOM_IN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
287 | #define EVT_PLOT_ZOOM_OUT(id, fn) { wxEVT_PLOT_ZOOM_OUT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
288 | #define EVT_PLOT_VALUE_SEL_CREATING(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
289 | #define EVT_PLOT_VALUE_SEL_CREATED(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
290 | #define EVT_PLOT_VALUE_SEL_CHANGING(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
291 | #define EVT_PLOT_VALUE_SEL_CHANGED(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
292 | #define EVT_PLOT_AREA_SEL_CREATING(id, fn) { wxEVT_PLOT_AREA_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
293 | #define EVT_PLOT_AREA_SEL_CREATED(id, fn) { wxEVT_PLOT_AREA_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
294 | #define EVT_PLOT_AREA_SEL_CHANGING(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
295 | #define EVT_PLOT_AREA_SEL_CHANGED(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
296 | #define EVT_PLOT_BEGIN_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
297 | #define EVT_PLOT_END_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
298 | #define EVT_PLOT_BEGIN_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
299 | #define EVT_PLOT_END_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
300 | #define EVT_PLOT_BEGIN_TITLE_EDIT(id, fn) { wxEVT_PLOT_BEGIN_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
301 | #define EVT_PLOT_END_TITLE_EDIT(id, fn) { wxEVT_PLOT_END_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, | |
302 | ||
303 | #endif // wxUSE_PLOT | |
304 | ||
305 | #endif | |
306 | // _WX_PLOT_H_ |