aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llstatbar.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llstatbar.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llstatbar.cpp')
-rw-r--r--linden/indra/newview/llstatbar.cpp302
1 files changed, 302 insertions, 0 deletions
diff --git a/linden/indra/newview/llstatbar.cpp b/linden/indra/newview/llstatbar.cpp
new file mode 100644
index 0000000..b23840a
--- /dev/null
+++ b/linden/indra/newview/llstatbar.cpp
@@ -0,0 +1,302 @@
1/**
2 * @file llstatbar.cpp
3 * @brief A little map of the world with network information
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llstatbar.h"
31
32#include "llmath.h"
33#include "llui.h"
34#include "llgl.h"
35#include "llfontgl.h"
36
37#include "llstat.h"
38
39///////////////////////////////////////////////////////////////////////////////////
40
41LLStatBar::LLStatBar(const std::string& name, const LLRect& rect)
42 : LLView(name, rect, TRUE)
43{
44 mMinBar = 0.f;
45 mMaxBar = 50.f;
46 mStatp = NULL;
47 mTickSpacing = 10.f;
48 mLabelSpacing = 10.f;
49 mPrecision = 0;
50 mUpdatesPerSec = 5;
51 mLabel = name;
52 mPerSec = TRUE;
53 mValue = 0.f;
54 mDisplayBar = TRUE;
55 mDisplayHistory = FALSE;
56 mDisplayMean = TRUE;
57}
58
59BOOL LLStatBar::handleMouseDown(S32 x, S32 y, MASK mask)
60{
61 if (mDisplayBar)
62 {
63 if (mDisplayHistory)
64 {
65 mDisplayBar = FALSE;
66 mDisplayHistory = FALSE;
67 }
68 else
69 {
70 mDisplayHistory = TRUE;
71 }
72 }
73 else
74 {
75 mDisplayBar = TRUE;
76 }
77
78 LLView* parent = getParent();
79 parent->reshape(parent->getRect().getWidth(), parent->getRect().getHeight(), FALSE);
80
81 return FALSE;
82}
83
84EWidgetType LLStatBar::getWidgetType() const
85{
86 return WIDGET_TYPE_STAT_BAR;
87}
88
89LLString LLStatBar::getWidgetTag() const
90{
91 return LL_STAT_BAR_TAG;
92}
93
94void LLStatBar::draw()
95{
96 if (!mStatp)
97 {
98// llinfos << "No stats for statistics bar!" << llendl;
99 return;
100 }
101
102 // Get the values.
103 F32 current, min, max, mean;
104 if (mPerSec)
105 {
106 current = mStatp->getCurrentPerSec();
107 min = mStatp->getMinPerSec();
108 max = mStatp->getMaxPerSec();
109 mean = mStatp->getMeanPerSec();
110 }
111 else
112 {
113 current = mStatp->getCurrent();
114 min = mStatp->getMin();
115 max = mStatp->getMax();
116 mean = mStatp->getMean();
117 }
118
119
120 if ((mUpdatesPerSec == 0.f) || (mUpdateTimer.getElapsedTimeF32() > 1.f/mUpdatesPerSec) || (mValue == 0.f))
121 {
122 if (mDisplayMean)
123 {
124 mValue = mean;
125 }
126 else
127 {
128 mValue = current;
129 }
130 mUpdateTimer.reset();
131 }
132
133 S32 width = mRect.getWidth() - 40;
134 S32 max_width = width;
135 S32 bar_top = mRect.getHeight() - 15; // 16 pixels from top.
136 S32 bar_height = bar_top - 20;
137 S32 tick_height = 4;
138 S32 tick_width = 1;
139 S32 left, top, right, bottom;
140
141 F32 value_scale = max_width/(mMaxBar - mMinBar);
142
143 LLFontGL::sMonospace->renderUTF8(mLabel, 0, 0, mRect.getHeight(), LLColor4(1.f, 1.f, 1.f, 1.f),
144 LLFontGL::LEFT, LLFontGL::TOP);
145
146 char value_format[64];
147 char value_str[256];
148 if (!mUnitLabel.empty())
149 {
150 sprintf(value_format, "%%.%df%%s", mPrecision);
151 sprintf(value_str, value_format, mValue, mUnitLabel.c_str());
152 }
153 else
154 {
155 sprintf(value_format, "%%.%df", mPrecision);
156 sprintf(value_str, value_format, mValue);
157 }
158
159 // Draw the value.
160 LLFontGL::sMonospace->renderUTF8(value_str, 0, width, mRect.getHeight(),
161 LLColor4(1.f, 1.f, 1.f, 0.5f),
162 LLFontGL::RIGHT, LLFontGL::TOP);
163
164 sprintf(value_format, "%%.%df", mPrecision);
165 if (mDisplayBar)
166 {
167 char tick_label[256];
168
169 // Draw the tick marks.
170 F32 tick_value;
171 top = bar_top;
172 bottom = bar_top - bar_height - tick_height/2;
173
174 LLGLSUIDefault gls_ui;
175 LLGLSNoTexture gls_no_texture;
176 for (tick_value = mMinBar; tick_value <= mMaxBar; tick_value += mTickSpacing)
177 {
178 left = llfloor((tick_value - mMinBar)*value_scale);
179 right = left + tick_width;
180 gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.1f));
181 }
182
183 // Draw the tick labels (and big ticks).
184 bottom = bar_top - bar_height - tick_height;
185 for (tick_value = mMinBar; tick_value <= mMaxBar; tick_value += mLabelSpacing)
186 {
187 left = llfloor((tick_value - mMinBar)*value_scale);
188 right = left + tick_width;
189 gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.25f));
190
191 sprintf(tick_label, value_format, tick_value);
192 // draw labels for the tick marks
193 LLFontGL::sMonospace->renderUTF8(tick_label, 0, left - 1, bar_top - bar_height - tick_height,
194 LLColor4(1.f, 1.f, 1.f, 0.5f),
195 LLFontGL::LEFT, LLFontGL::TOP);
196 }
197
198 // Now, draw the bars
199 top = bar_top;
200 bottom = bar_top - bar_height;
201
202 // draw background bar.
203 left = 0;
204 right = width;
205 gl_rect_2d(left, top, right, bottom, LLColor4(0.f, 0.f, 0.f, 0.25f));
206
207 if (mStatp->getNumValues() == 0)
208 {
209 // No data, don't draw anything...
210 return;
211 }
212 // draw min and max
213 left = (S32) ((min - mMinBar) * value_scale);
214
215 if (left < 0)
216 {
217 left = 0;
218 llwarns << "Min:" << min << llendl;
219 }
220
221 right = (S32) ((max - mMinBar) * value_scale);
222 gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 0.25f));
223
224 S32 num_values = mStatp->getNumValues() - 1;
225 if (mDisplayHistory)
226 {
227 S32 i;
228 for (i = 0; i < num_values; i++)
229 {
230 if (i == mStatp->getNextBin())
231 {
232 continue;
233 }
234 if (mPerSec)
235 {
236 left = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale);
237 right = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale) + 1;
238 gl_rect_2d(left, bottom+i+1, right, bottom+i, LLColor4(1.f, 0.f, 0.f, 1.f));
239 }
240 else
241 {
242 left = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale);
243 right = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale) + 1;
244 gl_rect_2d(left, bottom+i+1, right, bottom+i, LLColor4(1.f, 0.f, 0.f, 1.f));
245 }
246 }
247 }
248 else
249 {
250 // draw current
251 left = (S32) ((current - mMinBar) * value_scale) - 1;
252 right = (S32) ((current - mMinBar) * value_scale) + 1;
253 gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 1.f));
254 }
255
256 // draw mean bar
257 top = bar_top + 2;
258 bottom = bar_top - bar_height - 2;
259 left = (S32) ((mean - mMinBar) * value_scale) - 1;
260 right = (S32) ((mean - mMinBar) * value_scale) + 1;
261 gl_rect_2d(left, top, right, bottom, LLColor4(0.f, 1.f, 0.f, 1.f));
262 }
263
264 LLView::draw();
265}
266
267const LLString& LLStatBar::getLabel() const
268{
269 return mLabel;
270}
271
272void LLStatBar::setLabel(const LLString& label)
273{
274 mLabel = label;
275}
276
277void LLStatBar::setUnitLabel(const LLString& unit_label)
278{
279 mUnitLabel = unit_label;
280}
281
282LLRect LLStatBar::getRequiredRect()
283{
284 LLRect rect;
285
286 if (mDisplayBar)
287 {
288 if (mDisplayHistory)
289 {
290 rect.mTop = 67;
291 }
292 else
293 {
294 rect.mTop = 40;
295 }
296 }
297 else
298 {
299 rect.mTop = 14;
300 }
301 return rect;
302}