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