root/foundation-apps/grosview-maxx/meter.cc

Revision 2, 1.8 KB (checked in by emasson, 3 years ago)

initial import for the community edition

Line 
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// $Id: meter.cc,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $
8//
9#include "general.h"
10#include "meter.h"
11#include "xosview.h"
12
13CVSID("$Id: meter.cc,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $");
14CVSID_DOT_H(METER_H_CVSID);
15
16Meter::Meter( XOSView *parent, const char *title, const char *legend,
17              int docaptions, int dolegends, int dousedlegends ) {
18  title_ = legend_ = NULL;
19  Meter::title( title );
20  Meter::legend( legend );
21  parent_ = parent;
22  docaptions_ = docaptions;
23  dolegends_ = dolegends;
24  dousedlegends_ = dousedlegends;
25  priority_ = 1;
26  counter_ = 0;
27  resize( parent->xoff(), parent->newypos(), parent->width() - 10, 10 );
28
29}
30
31Meter::~Meter( void ){
32  if ( title_ )
33        delete[] title_;
34  if ( legend_ )
35        delete[] legend_;
36}
37
38void Meter::checkResources( void ){
39  textcolor_ = parent_->allocColor( parent_->getResource( "meterLabelColor") );
40}
41
42void Meter::title( const char *title ){
43
44  if ( title_ )
45        delete[] title_;
46
47  int len = strlen(title);
48  title_ = new char[len + 1];
49  strncpy( title_, title, len );
50  title_[len] = '\0'; // strncpy() will not null terminate if s2 > len
51}
52
53void Meter::legend( const char *legend ){
54
55  if ( legend_ )
56          delete[] legend_;
57
58  int len = strlen(legend);
59  legend_ = new char[len + 1];
60  strncpy( legend_, legend, len );
61  legend_[len] = '\0'; // strncpy() will not null terminate if s2 > len
62}
63
64void Meter::resize( int x, int y, int width, int height ){
65  x_ = x;
66  y_ = y;
67  width_ = (width>=0) ? width : 0;    // fix for cosmetical bug:
68  height_ = (height>=0) ? height : 0; // beware of values < 0 !
69  width_ &= ~1;                       // only allow even width_ values
70}
Note: See TracBrowser for help on using the browser.