Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / graph.cpp
blobc9f7407f6b54dd5e48a6d9efd6c7d415958b8ea0
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "stdpch.h"
24 #include "graph.h"
26 #include <nel/misc/command.h>
28 extern NL3D::UTextContext *TextContext;
31 // Namespaces
34 using namespace NLMISC;
35 using namespace NL3D;
36 using namespace std;
39 // Variables
43 bool CGraph::Display = true;
44 bool CGraph::DisplayAverageValue = true;
45 UDriver *CGraph::_Driver = NULL;
46 vector<CGraph*> *CGraph::_Graphs = NULL;
50 // Classes
53 void CGraph::render (uint page)
55 if (!Display) return;
57 if (_Driver == NULL) return;
58 if (_Graphs == NULL) return;
60 for (uint i = 0; i < _Graphs->size(); i++)
62 // Graph in all info pages
63 if ((*_Graphs)[i]->Page == page)
64 (*_Graphs)[i]->renderGraph ();
68 void CGraph::renderGraph ()
70 if (_Driver == NULL)
71 return;
73 // Display the background
74 uint32 w, h;
75 _Driver->getWindowSize (w, h);
76 float ScreenWidth = (float) w;
77 float ScreenHeight = (float) h;
78 _Driver->setMatrixMode2D (CFrustum (0.0f, ScreenWidth, 0.0f, ScreenHeight, -1.0f, 1.0f, false));
79 _Driver->drawQuad (X, Y, X+Width, Y+Height, BackColor);
81 Peak = 0.0f;
82 float sum = 0.0f;
84 CRGBA lineCol;
85 if ( LineMode )
87 lineCol.set (BackColor.R, BackColor.G, BackColor.B, 255);
89 else
91 lineCol.set (255,255,255,BackColor.A);
94 float pos = X+Width-1;
95 uint i = 0;
96 for (deque<float>::reverse_iterator it = Values.rbegin(); it != Values.rend(); it++)
98 float value = (*it) * Height / MaxValue;
99 if (value > Height) value = Height;
101 CVector vect1;
102 if ( LineMode )
104 vect1.x = pos-1;
105 vect1.y = PrevY;
107 else
109 vect1.x = pos;
110 vect1.y = Y;
112 PrevY = Y + value;
114 _Driver->drawLine (vect1.x, vect1.y, pos, PrevY, lineCol);
116 pos--;
117 if ((*it) > Peak) Peak = *it;
118 sum += *it;
119 i++;
123 // Display max
124 float value = Peak * Height / MaxValue;
125 if (value > Height) value = Height;
126 float peakval = Y+value;
127 CRGBA frontCol (min(BackColor.R*2,255),min(BackColor.G*2,255),min(BackColor.B*2,255),min(BackColor.A*2,255));
128 _Driver->drawLine (X, peakval, X+Width, peakval, frontCol);
130 // Display average
131 float average = sum / favoid0((float)Values.size());
132 value = average * Height / MaxValue;
133 if (value > Height) value = Height;
134 float avrval = Y+value;
135 _Driver->drawLine (X, avrval, X+Width, avrval, frontCol);
137 if (TextContext != NULL)
139 TextContext->setShaded (false);
140 TextContext->setShadeOutline(false);
141 TextContext->setHotSpot (UTextContext::MiddleLeft);
142 TextContext->setColor (frontCol);
143 TextContext->setFontSize (10);
144 TextContext->printfAt ((X+Width+2)/ScreenWidth, peakval/ScreenHeight, "%.2f", Peak);
146 if (DisplayAverageValue)
148 // don't display the average value if they are superposed
149 if (avrval+5<peakval-5 || avrval-5>peakval+5)
151 TextContext->printfAt ((X+Width+2)/ScreenWidth, avrval/ScreenHeight, "%.2f", average);
155 // Display name
156 TextContext->setHotSpot (UTextContext::TopLeft);
157 TextContext->printfAt ((X+1)/ScreenWidth, (Y+Height-1)/ScreenHeight, Name.c_str());
162 void CGraph::addOneValue (float value)
164 if (value < 0.0f) value = 0.0f;
166 Values.push_back (value);
167 while (Values.size () > Width)
168 Values.pop_front ();
170 // if (Values.back() > Peak)
171 // Peak = Values.back();
175 void CGraph::addValue (float value)
177 TTime currentTime = ryzomGetLocalTime ();
179 while (Values.size () == 0 || currentTime > CurrentQuantumStart + Quantum)
181 CurrentQuantumStart += Quantum;
182 addOneValue ();
185 Values.back() += value;
187 // if (Values.back() > Peak)
188 // Peak = Values.back();