• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
graph.cpp
1 /***************************************************************************
2  * Copyright (C) 2003 by Hans Karlsson *
3  * karlsson.h@home.se *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  ***************************************************************************/
10 
11 #include "graph.h"
12 #include <tqstring.h>
13 
14 Graph::Graph(karamba* k, int x, int y, int w, int h, int nbrPts):
15  Meter(k, x, y, w, h), lastValue(0)
16 {
17 
18  nbrPoints = (nbrPts==0)? 50:nbrPts ;
19  ptPtr = 0;
20  values = new int[nbrPoints];
21  for(int i = 0; i < nbrPoints; i++)
22  values[i] = 0;
23  minValue = 0;
24  maxValue = 100;
25 }
26 
27 Graph::~Graph()
28 {
29  delete[] values;
30 }
31 
32 void Graph::setValue( long v)
33 {
34  if( v > maxValue)
35  {
36  // maxValue = v;
37  v = maxValue;
38  }
39  if( v < minValue)
40  {
41  //minValue = v;
42  v = minValue;
43  }
44  lastValue = v;
45  values[ptPtr] = (int) (v / (maxValue + 0.0001) * getHeight());
46  ptPtr = (ptPtr + 1) % nbrPoints;
47 }
48 
49 void Graph::setValue( TQString v )
50 {
51  setValue((long)(v.toDouble() + 0.5));
52 }
53 
54 void Graph::mUpdate(TQPainter *p)
55 {
56  if (hidden == 0)
57  {
58  double step = (getWidth() / (nbrPoints-1.001));
59  double xPos = 0;
60  double nextXPos = 0;
61  p->setPen(color);
62  for (int i = 0; i < nbrPoints - 1 ; i ++)
63  {
64  nextXPos = xPos + step;
65  p->drawLine(getX() + (int)xPos, getY()+getHeight() -
66  (int) values[(ptPtr+i) % nbrPoints] ,
67  getX() + (int)nextXPos, getY()+getHeight() -
68  (int) values[(ptPtr + i +1) % nbrPoints] );
69  xPos = nextXPos;
70  }
71  }
72 }
73 
74 #include "graph.moc"

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.8.13
This website is maintained by Timothy Pearson.