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

superkaramba

graph.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Hans Karlsson                                   *
00003  *   karlsson.h@home.se                                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "graph.h"
00012 #include <tqstring.h>
00013 
00014 Graph::Graph(karamba* k, int x, int y, int w, int h, int nbrPts):
00015   Meter(k, x, y, w, h), lastValue(0)
00016 {
00017 
00018     nbrPoints = (nbrPts==0)? 50:nbrPts ;
00019     ptPtr = 0;
00020     values = new int[nbrPoints];
00021     for(int i = 0; i < nbrPoints; i++)
00022         values[i] = 0;
00023     minValue = 0;
00024     maxValue = 100;
00025 }
00026 
00027 Graph::~Graph()
00028 {
00029     delete[] values;
00030 }
00031 
00032 void Graph::setValue( long v)
00033 {
00034     if( v > maxValue)
00035     {
00036         // maxValue = v;
00037         v = maxValue;
00038     }
00039     if( v < minValue)
00040     {
00041         //minValue = v;
00042         v = minValue;
00043     }
00044     lastValue = v;
00045     values[ptPtr] = (int) (v / (maxValue + 0.0001) * getHeight());
00046     ptPtr = (ptPtr + 1) % nbrPoints;
00047 }
00048 
00049 void Graph::setValue( TQString v )
00050 {
00051   setValue((long)(v.toDouble() + 0.5));
00052 }
00053 
00054 void Graph::mUpdate(TQPainter *p)
00055 {
00056   if (hidden == 0)
00057   {
00058     double step = (getWidth() / (nbrPoints-1.001));
00059     double xPos = 0;
00060     double nextXPos = 0;
00061     p->setPen(color);
00062     for (int i = 0; i < nbrPoints - 1 ; i ++)
00063     {
00064       nextXPos = xPos + step;
00065       p->drawLine(getX() + (int)xPos, getY()+getHeight() -
00066                     (int) values[(ptPtr+i) % nbrPoints] ,
00067                   getX() + (int)nextXPos, getY()+getHeight() -
00068                     (int) values[(ptPtr + i +1) % nbrPoints] );
00069       xPos = nextXPos;
00070     }
00071   }
00072 }
00073 
00074 #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.7.1
This website is maintained by Timothy Pearson.