"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/bitmeter.cc" (11 Jul 2020, 2471 Bytes) of package /linux/misc/xosview-1.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "bitmeter.cc" see the Fossies "Dox" file reference documentation.

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