PageRenderTime 49ms CodeModel.GetById 12ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llstatgraph.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 157 lines | 104 code | 22 blank | 31 comment | 5 complexity | 46b2315536fedc7130683df6afcd2eeb MD5 | raw file
  1/** 
  2 * @file llstatgraph.cpp
  3 * @brief Simpler compact stat graph with tooltip
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27//#include "llviewerprecompiledheaders.h"
 28#include "linden_common.h"
 29
 30#include "llstatgraph.h"
 31#include "llrender.h"
 32
 33#include "llmath.h"
 34#include "llui.h"
 35#include "llstat.h"
 36#include "llgl.h"
 37#include "llglheaders.h"
 38//#include "llviewercontrol.h"
 39
 40///////////////////////////////////////////////////////////////////////////////////
 41
 42LLStatGraph::LLStatGraph(const LLView::Params& p)
 43:	LLView(p)
 44{
 45	mStatp = NULL;
 46	setToolTip(p.name());
 47	mNumThresholds = 3;
 48	mThresholdColors[0] = LLColor4(0.f, 1.f, 0.f, 1.f);
 49	mThresholdColors[1] = LLColor4(1.f, 1.f, 0.f, 1.f);
 50	mThresholdColors[2] = LLColor4(1.f, 0.f, 0.f, 1.f);
 51	mThresholdColors[3] = LLColor4(1.f, 0.f, 0.f, 1.f);
 52	mThresholds[0] = 50.f;
 53	mThresholds[1] = 75.f;
 54	mThresholds[2] = 100.f;
 55	mMin = 0.f;
 56	mMax = 125.f;
 57	mPerSec = TRUE;
 58	mValue = 0.f;
 59	mPrecision = 0;
 60}
 61
 62void LLStatGraph::draw()
 63{
 64	F32 range, frac;
 65	range = mMax - mMin;
 66	if (mStatp)
 67	{
 68		if (mPerSec)
 69		{
 70			mValue = mStatp->getMeanPerSec();
 71		}
 72		else
 73		{
 74			mValue = mStatp->getMean();
 75		}
 76	}
 77	frac = (mValue - mMin) / range;
 78	frac = llmax(0.f, frac);
 79	frac = llmin(1.f, frac);
 80
 81	if (mUpdateTimer.getElapsedTimeF32() > 0.5f)
 82	{
 83		std::string format_str;
 84		std::string tmp_str;
 85		format_str = llformat("%%s%%.%df%%s", mPrecision);
 86		tmp_str = llformat(format_str.c_str(), mLabel.c_str(), mValue, mUnits.c_str());
 87		setToolTip(tmp_str);
 88
 89		mUpdateTimer.reset();
 90	}
 91
 92	LLColor4 color;
 93
 94	S32 i;
 95	for (i = 0; i < mNumThresholds - 1; i++)
 96	{
 97		if (mThresholds[i] > mValue)
 98		{
 99			break;
100		}
101	}
102
103	//gl_drop_shadow(0,  getRect().getHeight(), getRect().getWidth(), 0,
104	//				LLUIColorTable::instance().getColor("ColorDropShadow"), 
105	//				(S32) gSavedSettings.getF32("DropShadowFloater") );
106
107	color = LLUIColorTable::instance().getColor( "MenuDefaultBgColor" );
108	gGL.color4fv(color.mV);
109	gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, TRUE);
110
111	gGL.color4fv(LLColor4::black.mV);
112	gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, FALSE);
113	
114	color = mThresholdColors[i];
115	gGL.color4fv(color.mV);
116	gl_rect_2d(1, llround(frac*getRect().getHeight()), getRect().getWidth() - 1, 0, TRUE);
117}
118
119void LLStatGraph::setValue(const LLSD& value)
120{
121	mValue = (F32)value.asReal();
122}
123
124void LLStatGraph::setMin(const F32 min)
125{
126	mMin = min;
127}
128
129void LLStatGraph::setMax(const F32 max)
130{
131	mMax = max;
132}
133
134void LLStatGraph::setStat(LLStat *statp)
135{
136	mStatp = statp;
137}
138
139void LLStatGraph::setLabel(const std::string& label)
140{
141	mLabel = label;
142}
143
144void LLStatGraph::setUnits(const std::string& units)
145{
146	mUnits = units;
147}
148
149void LLStatGraph::setPrecision(const S32 precision)
150{
151	mPrecision = precision;
152}
153
154void LLStatGraph::setThreshold(const S32 i, F32 value)
155{
156	mThresholds[i] = value;
157}