Upstream tarball 20080304
[amule.git] / src / OScopeCtrl.h
blobd508638b5370678231c3a0615b42b58dd6f5b64d
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef OSCOPECTRL_H
27 #define OSCOPECTRL_H
29 #ifndef NULL
30 #define NULL 0
31 #endif
33 #include <wx/control.h> // Needed for wxControl
34 #include <wx/timer.h> // Needed for wxTimer
35 #include <wx/pen.h>
37 #include "Color.h" // Needed for COLORREF and RGB
38 #include "Statistics.h" // Needed for StatsGraphType
40 class wxMemoryDC;
42 /////////////////////////////////////////////////////////////////////////////
43 // COScopeCtrl window
45 #define TIMER_OSCOPE 7641
47 class COScopeCtrl : public wxControl
49 friend class CStatisticsDlg;
51 public:
52 COScopeCtrl(int NTrends, int nDecimals, StatsGraphType type, wxWindow* parent=NULL);
53 ~COScopeCtrl();
55 void SetRange(float dLower, float dUpper, unsigned iTrend = 0);
56 void SetRanges(float dLower, float dUpper);
57 void SetXUnits(const wxString& string,
58 const wxString& XMin = wxEmptyString, const wxString& XMax = wxEmptyString);
59 void SetYUnits(const wxString& string,
60 const wxString& YMin = wxEmptyString, const wxString& YMax = wxEmptyString);
61 void SetBackgroundColor(COLORREF color);
62 void SetGridColor(COLORREF color);
63 void SetPlotColor(COLORREF color, unsigned iTrend = 0);
64 COLORREF GetPlotColor(unsigned iTrend = 0) {return pdsTrends[iTrend].crPlot;}
65 float GetUpperLimit() { return pdsTrends[0].fUpperLimit; }
66 void Reset(double sNewPeriod);
67 void Stop();
68 void RecreateGraph(bool bRefresh=true);
69 void RecreateGrid();
70 void AppendPoints(double sTimestamp, const std::vector<float *> &apf);
71 void DelayPoints() { nDelayedPoints++; }
72 unsigned GetPlotHeightPixels() { return nPlotHeight; }
73 unsigned GetPlotWidthPoints() { return nPlotWidth/nShiftPixels; }
74 wxBitmap* GetBitmapPlot() { return bmapPlot; }
75 wxBitmap* GetBitmapGrid() { return bmapGrid; }
77 StatsGraphType graph_type;
79 public:
80 unsigned nTrends;
81 unsigned nXGrids;
82 unsigned nYGrids;
83 unsigned nShiftPixels; // amount to shift with each new point
84 unsigned nYDecimals;
86 wxString strXUnits, strXMin, strXMax;
87 wxString strYUnits, strYMin, strYMax;
88 COLORREF crBackground;
89 COLORREF crGrid;
91 typedef struct PlotDataStruct {
92 COLORREF crPlot; // data plot color
93 wxPen penPlot;
94 unsigned yPrev;
95 float fPrev;
96 float fLowerLimit; // lower bounds
97 float fUpperLimit; // upper bounds
98 float fVertScale;
99 } PlotData_t ;
102 protected:
103 DECLARE_EVENT_TABLE()
104 PlotData_t *pdsTrends;
106 int nClientHeight;
107 int nClientWidth;
108 int nPlotHeight;
109 int nPlotWidth;
111 RECT rectClient;
112 RECT rectPlot;
113 wxBrush brushBack;
115 wxMemoryDC* dcGrid;
116 wxMemoryDC* dcPlot;
117 wxMemoryDC* memDC;
118 wxBitmap* memBitmap;
119 wxBitmap* bmapOldGrid;
120 wxBitmap* bmapOldPlot;
121 wxBitmap* bmapGrid;
122 wxBitmap* bmapPlot;
123 void InvalidateGraph() { InvalidateCtrl(true, false); }
124 void InvalidateGrid() { InvalidateCtrl(false, true); }
126 private:
127 int oldwidth, oldheight;
128 bool bRecreateGrid, bRecreateGraph, bStopped;
129 int nDelayedPoints;
130 double sLastTimestamp;
131 double sLastPeriod;
132 wxTimer timerRedraw;
133 void OnTimer(wxTimerEvent& evt);
134 void OnPaint(wxPaintEvent& evt);
135 void OnSize(wxSizeEvent& evt);
136 void ShiftGraph(unsigned cntPoints);
137 void PlotHistory(unsigned cntPoints, bool bShiftGraph, bool bRefresh);
138 void DrawPoints(const std::vector<float *> &apf, unsigned cntPoints);
139 unsigned GetPlotY(float fPlot, PlotData_t* ppds);
140 void InvalidateCtrl(bool bInvalidateGraph = true, bool bInvalidateGrid = true);
141 void DoBlit();
144 #endif // OSCOPECTRL_H
145 // File_checked_for_headers