| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | #include "general.h" |
|---|
| 10 | #include "bitmeter.h" |
|---|
| 11 | #include "xosview.h" |
|---|
| 12 | |
|---|
| 13 | CVSID("$Id: bitmeter.cc,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $"); |
|---|
| 14 | CVSID_DOT_H(BITMETER_H_CVSID); |
|---|
| 15 | |
|---|
| 16 | BitMeter::BitMeter( XOSView *parent, |
|---|
| 17 | const char *title, const char *legend, int numBits, |
|---|
| 18 | int docaptions, int, int dousedlegends) |
|---|
| 19 | : Meter( parent, title, legend, docaptions, dousedlegends, dousedlegends ), |
|---|
| 20 | bits_(NULL), lastbits_(NULL), disabled_(false) { |
|---|
| 21 | setNumBits(numBits); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | BitMeter::~BitMeter( void ){ |
|---|
| 25 | delete [] bits_; |
|---|
| 26 | delete [] lastbits_; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | void BitMeter::setNumBits(int n){ |
|---|
| 30 | numbits_ = n; |
|---|
| 31 | delete [] bits_; |
|---|
| 32 | delete [] lastbits_; |
|---|
| 33 | |
|---|
| 34 | bits_ = new char[numbits_]; |
|---|
| 35 | lastbits_ = new char[numbits_]; |
|---|
| 36 | |
|---|
| 37 | for ( int i = 0 ; i < numbits_ ; i++ ) |
|---|
| 38 | bits_[i] = lastbits_[i] = 0; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | void BitMeter::disableMeter ( void ) { |
|---|
| 42 | disabled_ = true; |
|---|
| 43 | onColor_ = parent_->allocColor ("gray"); |
|---|
| 44 | offColor_ = onColor_; |
|---|
| 45 | Meter::legend ("Disabled"); |
|---|
| 46 | |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | void BitMeter::checkResources( void ){ |
|---|
| 50 | Meter::checkResources(); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | void BitMeter::checkevent( void ){ |
|---|
| 54 | drawBits(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | void BitMeter::drawBits( int manditory ){ |
|---|
| 58 | static int pass = 1; |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | int x1 = x_ + 0, x2; |
|---|
| 63 | |
|---|
| 64 | for ( int i = 0 ; i < numbits_ ; i++ ){ |
|---|
| 65 | if ( i != (numbits_ - 1) ) |
|---|
| 66 | x2 = x_ + ((i + 1) * (width_+1)) / numbits_ - 1; |
|---|
| 67 | else |
|---|
| 68 | x2 = x_ + (width_+1) - 1; |
|---|
| 69 | |
|---|
| 70 | if ( (bits_[i] != lastbits_[i]) || manditory ){ |
|---|
| 71 | if ( bits_[i] && pass ) |
|---|
| 72 | parent_->setForeground( onColor_ ); |
|---|
| 73 | else |
|---|
| 74 | parent_->setForeground( offColor_ ); |
|---|
| 75 | |
|---|
| 76 | parent_->drawFilledRectangle( x1, y_, x2 - x1, height_); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | lastbits_[i] = bits_[i]; |
|---|
| 80 | |
|---|
| 81 | x1 = x2 + 2; |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | void BitMeter::draw( void ){ |
|---|
| 86 | parent_->lineWidth( 1 ); |
|---|
| 87 | parent_->setForeground( parent_->foreground() ); |
|---|
| 88 | parent_->drawFilledRectangle( x_ -1, y_ - 1, width_ + 2, height_ + 2 ); |
|---|
| 89 | |
|---|
| 90 | parent_->lineWidth( 0 ); |
|---|
| 91 | |
|---|
| 92 | if ( dolegends_ ){ |
|---|
| 93 | parent_->setForeground( textcolor_ ); |
|---|
| 94 | |
|---|
| 95 | int offset; |
|---|
| 96 | if ( dousedlegends_ ) |
|---|
| 97 | offset = parent_->textWidth( "XXXXXXXXX" ); |
|---|
| 98 | else |
|---|
| 99 | offset = parent_->textWidth( "XXXXX" ); |
|---|
| 100 | |
|---|
| 101 | parent_->drawString( x_ - offset + 1, y_ + height_, title_ ); |
|---|
| 102 | parent_->setForeground( onColor_ ); |
|---|
| 103 | if(docaptions_) |
|---|
| 104 | { |
|---|
| 105 | parent_->drawString( x_, y_ - 5, legend_ ); |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | drawBits( 1 ); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void BitMeter::setBits(int startbit, unsigned char values){ |
|---|
| 113 | unsigned char mask = 1; |
|---|
| 114 | for (int i = startbit ; i < startbit + 8 ; i++){ |
|---|
| 115 | bits_[i] = values & mask; |
|---|
| 116 | mask = mask << 1; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|