File: meter.cc

package info (click to toggle)
xosview 1.7.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,000 kB
  • ctags: 1,200
  • sloc: cpp: 7,317; sh: 1,760; ansic: 368; makefile: 46; awk: 20
file content (64 lines) | stat: -rw-r--r-- 1,711 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//  
//  Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov )
//
//  This file may be distributed under terms of the GPL
//
//
// $Id: meter.cc,v 1.9 1999/11/12 05:13:21 romberg Exp $
//
#include "general.h"
#include "meter.h"
#include "xosview.h"

CVSID("$Id: meter.cc,v 1.9 1999/11/12 05:13:21 romberg Exp $");
CVSID_DOT_H(METER_H_CVSID);

Meter::Meter( XOSView *parent, const char *title, const char *legend, 
              int docaptions, int dolegends, int dousedlegends ) {
  title_ = legend_ = NULL;
  Meter::title( title );
  Meter::legend( legend );
  parent_ = parent;
  docaptions_ = docaptions;
  dolegends_ = dolegends;
  dousedlegends_ = dousedlegends;
  priority_ = 1;
  counter_ = 0;
  resize( parent->xoff(), parent->newypos(), parent->width() - 10, 10 );

}

Meter::~Meter( void ){
  delete[] title_;
  delete[] legend_;
}

void Meter::checkResources( void ){
  textcolor_ = parent_->allocColor( parent_->getResource( "meterLabelColor") );
}

void Meter::title( const char *title ){
  delete[] title_;
  int len = strlen(title);
  title_ = new char[len + 1];
  strncpy( title_, title, len );
  title_[len] = '\0'; // strncpy() will not null terminate if s2 > len
}

void Meter::legend( const char *legend ){
  delete[] legend_;
  int len = strlen(legend);
  legend_ = new char[len + 1];
  strncpy( legend_, legend, len );
  legend_[len] = '\0'; // strncpy() will not null terminate if s2 > len
}

void Meter::resize( int x, int y, int width, int height ){
  x_ = x;
  y_ = y;
  width_ = (width>=0) ? width : 0;    // fix for cosmetical bug:
  height_ = (height>=0) ? height : 0; // beware of values < 0 !
  width_ &= ~1;                       // only allow even width_ values
}