00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llstatgraph.h"
00035 #include "llglimmediate.h"
00036
00037 #include "llmath.h"
00038 #include "llui.h"
00039 #include "llstat.h"
00040 #include "llgl.h"
00041 #include "llglheaders.h"
00042 #include "llviewercontrol.h"
00043
00045
00046 LLStatGraph::LLStatGraph(const std::string& name, const LLRect& rect)
00047 : LLView(name, rect, TRUE)
00048 {
00049 mStatp = NULL;
00050 setToolTip(name);
00051 mNumThresholds = 3;
00052 mThresholdColors[0] = LLColor4(0.f, 1.f, 0.f, 1.f);
00053 mThresholdColors[1] = LLColor4(1.f, 1.f, 0.f, 1.f);
00054 mThresholdColors[2] = LLColor4(1.f, 0.f, 0.f, 1.f);
00055 mThresholdColors[3] = LLColor4(1.f, 0.f, 0.f, 1.f);
00056 mThresholds[0] = 50.f;
00057 mThresholds[1] = 75.f;
00058 mThresholds[2] = 100.f;
00059 mMin = 0.f;
00060 mMax = 125.f;
00061 mPerSec = TRUE;
00062 mValue = 0.f;
00063 mPrecision = 0;
00064 }
00065
00066 void LLStatGraph::draw()
00067 {
00068 F32 range, frac;
00069 range = mMax - mMin;
00070 if (mStatp)
00071 {
00072 if (mPerSec)
00073 {
00074 mValue = mStatp->getMeanPerSec();
00075 }
00076 else
00077 {
00078 mValue = mStatp->getMean();
00079 }
00080 }
00081 frac = (mValue - mMin) / range;
00082 frac = llmax(0.f, frac);
00083 frac = llmin(1.f, frac);
00084
00085 if (mUpdateTimer.getElapsedTimeF32() > 0.5f)
00086 {
00087 std::string format_str;
00088 std::string tmp_str;
00089 format_str = llformat("%%s%%.%df%%s", mPrecision);
00090 tmp_str = llformat(format_str.c_str(), mLabel.c_str(), mValue, mUnits.c_str());
00091 setToolTip(tmp_str);
00092
00093 mUpdateTimer.reset();
00094 }
00095
00096 LLColor4 color;
00097
00098 S32 i;
00099 for (i = 0; i < mNumThresholds - 1; i++)
00100 {
00101 if (mThresholds[i] > mValue)
00102 {
00103 break;
00104 }
00105 }
00106
00107
00108
00109
00110
00111 color = gColors.getColor( "MenuDefaultBgColor" );
00112 gGL.color4fv(color.mV);
00113 gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, TRUE);
00114
00115 gGL.color4fv(LLColor4::black.mV);
00116 gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, FALSE);
00117
00118 color = mThresholdColors[i];
00119 gGL.color4fv(color.mV);
00120 gl_rect_2d(1, llround(frac*getRect().getHeight()), getRect().getWidth() - 1, 0, TRUE);
00121 }
00122
00123 void LLStatGraph::setValue(const LLSD& value)
00124 {
00125 mValue = (F32)value.asReal();
00126 }
00127
00128 void LLStatGraph::setMin(const F32 min)
00129 {
00130 mMin = min;
00131 }
00132
00133 void LLStatGraph::setMax(const F32 max)
00134 {
00135 mMax = max;
00136 }
00137
00138 void LLStatGraph::setStat(LLStat *statp)
00139 {
00140 mStatp = statp;
00141 }
00142
00143 void LLStatGraph::setLabel(const char *label)
00144 {
00145 mLabel = label;
00146 }
00147
00148 void LLStatGraph::setUnits(const char *units)
00149 {
00150 mUnits = units;
00151 }
00152
00153 void LLStatGraph::setPrecision(const S32 precision)
00154 {
00155 mPrecision = precision;
00156 }
00157
00158 void LLStatGraph::setThreshold(const S32 i, F32 value)
00159 {
00160 mThresholds[i] = value;
00161 }