xosview  1.23
About: xosview is an X Windows based system monitor (cpu, memory, swap and network usage; interrupt and serial activities; load average).
  Fossies Dox: xosview-1.23.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

bitmeter.cc
Go to the documentation of this file.
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 
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) {
16 }
17 
19  delete [] bits_;
20  delete [] lastbits_;
21 }
22 
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");
39  Meter::legend ("Disabled");
40 
41 }
42 
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 )
67  else
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 );
82  parent_->drawFilledRectangle( x_ -1, y_ - 1, width_ + 2, height_ + 2 );
83 
84  parent_->lineWidth( 0 );
85 
86  if ( dolegends_ ){
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_ );
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 }
virtual ~BitMeter(void)
Definition: bitmeter.cc:18
bool disabled_
Definition: bitmeter.h:33
void drawBits(int mandatory=0)
Definition: bitmeter.cc:51
char * lastbits_
Definition: bitmeter.h:31
int numBits(void) const
Definition: bitmeter.h:25
unsigned long onColor_
Definition: bitmeter.h:30
void setNumBits(int n)
Definition: bitmeter.cc:23
unsigned long offColor_
Definition: bitmeter.h:30
char * bits_
Definition: bitmeter.h:31
void setBits(int startbit, unsigned char values)
Definition: bitmeter.cc:106
void checkResources(void)
Definition: bitmeter.cc:43
void disableMeter(void)
Definition: bitmeter.cc:35
BitMeter(XOSView *parent, const char *title="", const char *legend="", int numBits=1, int docaptions=0, int dolegends=0, int dousedlegends=0)
Definition: bitmeter.cc:10
void checkevent(void)
Definition: bitmeter.cc:47
void draw(void)
Definition: bitmeter.cc:79
int numbits_
Definition: bitmeter.h:32
Definition: meter.h:14
int x_
Definition: meter.h:53
int docaptions_
Definition: meter.h:53
int dolegends_
Definition: meter.h:53
virtual void checkResources(void)
Definition: meter.cc:33
int y_
Definition: meter.h:53
int dousedlegends_
Definition: meter.h:53
int width_
Definition: meter.h:53
char * legend_
Definition: meter.h:55
unsigned long textcolor_
Definition: meter.h:56
const char * legend(void)
Definition: meter.h:27
char * title_
Definition: meter.h:55
XOSView * parent_
Definition: meter.h:52
int height_
Definition: meter.h:53
unsigned long foreground(void)
Definition: xwin.h:53
unsigned long allocColor(const char *name)
Definition: xwin.cc:383
void setForeground(unsigned long pixelvalue)
Definition: xwin.h:38
void drawString(int x, int y, const char *str)
Definition: xwin.h:69
void lineWidth(int width)
Definition: xwin.h:57
int textWidth(const char *str, int n)
Definition: xwin.h:73
void drawFilledRectangle(int x, int y, int width, int height)
Definition: xwin.h:67