| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | #ifndef _METER_H_ |
|---|
| 10 | #define _METER_H_ |
|---|
| 11 | |
|---|
| 12 | #define METER_H_CVSID "$Id: meter.h,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $" |
|---|
| 13 | |
|---|
| 14 | #include <stdio.h> |
|---|
| 15 | #include "xosview.h" // To grab MAX_SAMPLES_PER_SECOND. |
|---|
| 16 | |
|---|
| 17 | class XOSView; |
|---|
| 18 | |
|---|
| 19 | class Meter { |
|---|
| 20 | public: |
|---|
| 21 | Meter( XOSView *parent, const char *title = "", const char *legend ="", |
|---|
| 22 | int docaptions = 0, int dolegends = 0, int dousedlegends = 0 ); |
|---|
| 23 | virtual ~Meter( void ); |
|---|
| 24 | |
|---|
| 25 | virtual const char *name( void ) const { return "Meter"; } |
|---|
| 26 | void resize( int x, int y, int width, int height ); |
|---|
| 27 | virtual void checkevent( void ) = 0; |
|---|
| 28 | virtual void draw( void ) = 0; |
|---|
| 29 | void title( const char *title ); |
|---|
| 30 | const char *title( void ) { return title_; } |
|---|
| 31 | void legend( const char *legend ); |
|---|
| 32 | const char *legend( void ) { return legend_; } |
|---|
| 33 | void docaptions( int val ) { docaptions_ = val; } |
|---|
| 34 | void dolegends( int val ) { dolegends_ = val; } |
|---|
| 35 | void dousedlegends( int val ) { dousedlegends_ = val; } |
|---|
| 36 | int requestevent( void ){ |
|---|
| 37 | if (priority_ == 0) { |
|---|
| 38 | fprintf(stderr, "Warning: meter %s had an invalid priority " |
|---|
| 39 | "of 0. Resetting to 1...\n", name()); |
|---|
| 40 | priority_ = 1; |
|---|
| 41 | } |
|---|
| 42 | int rval = counter_ % priority_; |
|---|
| 43 | counter_ = (counter_ + 1) % priority_; |
|---|
| 44 | return !rval; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | int getX() const { return x_; } |
|---|
| 48 | int getY() const { return y_; } |
|---|
| 49 | int getWidth() const { return width_; } |
|---|
| 50 | int getHeight() const { return height_; } |
|---|
| 51 | |
|---|
| 52 | virtual void checkResources( void ); |
|---|
| 53 | |
|---|
| 54 | protected: |
|---|
| 55 | XOSView *parent_; |
|---|
| 56 | int x_, y_, width_, height_, docaptions_, dolegends_, dousedlegends_; |
|---|
| 57 | int priority_, counter_; |
|---|
| 58 | char *title_, *legend_; |
|---|
| 59 | unsigned long textcolor_; |
|---|
| 60 | double samplesPerSecond() { return 1.0*MAX_SAMPLES_PER_SECOND/priority_; } |
|---|
| 61 | double secondsPerSample() { return 1.0/samplesPerSecond(); } |
|---|
| 62 | |
|---|
| 63 | private: |
|---|
| 64 | }; |
|---|
| 65 | |
|---|
| 66 | #endif |
|---|