1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
26 #include <nel/misc/command.h>
28 extern NL3D::UTextContext
*TextContext
;
34 using namespace NLMISC
;
43 bool CGraph::Display
= true;
44 bool CGraph::DisplayAverageValue
= true;
45 UDriver
*CGraph::_Driver
= NULL
;
46 vector
<CGraph
*> *CGraph::_Graphs
= NULL
;
53 void CGraph::render (uint page
)
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 ()
73 // Display the background
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
);
87 lineCol
.set (BackColor
.R
, BackColor
.G
, BackColor
.B
, 255);
91 lineCol
.set (255,255,255,BackColor
.A
);
94 float pos
= X
+Width
-1;
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
;
114 _Driver
->drawLine (vect1
.x
, vect1
.y
, pos
, PrevY
, lineCol
);
117 if ((*it
) > Peak
) Peak
= *it
;
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
);
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
);
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
)
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
;
185 Values
.back() += value
;
187 // if (Values.back() > Peak)
188 // Peak = Values.back();