/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. //#include "llviewerprecompiledheaders.h"
  27. #include "linden_common.h"
  28. #include "llstatgraph.h"
  29. #include "llrender.h"
  30. #include "llmath.h"
  31. #include "llui.h"
  32. #include "llstat.h"
  33. #include "llgl.h"
  34. #include "llglheaders.h"
  35. //#include "llviewercontrol.h"
  36. ///////////////////////////////////////////////////////////////////////////////////
  37. LLStatGraph::LLStatGraph(const LLView::Params& p)
  38. : LLView(p)
  39. {
  40. mStatp = NULL;
  41. setToolTip(p.name());
  42. mNumThresholds = 3;
  43. mThresholdColors[0] = LLColor4(0.f, 1.f, 0.f, 1.f);
  44. mThresholdColors[1] = LLColor4(1.f, 1.f, 0.f, 1.f);
  45. mThresholdColors[2] = LLColor4(1.f, 0.f, 0.f, 1.f);
  46. mThresholdColors[3] = LLColor4(1.f, 0.f, 0.f, 1.f);
  47. mThresholds[0] = 50.f;
  48. mThresholds[1] = 75.f;
  49. mThresholds[2] = 100.f;
  50. mMin = 0.f;
  51. mMax = 125.f;
  52. mPerSec = TRUE;
  53. mValue = 0.f;
  54. mPrecision = 0;
  55. }
  56. void LLStatGraph::draw()
  57. {
  58. F32 range, frac;
  59. range = mMax - mMin;
  60. if (mStatp)
  61. {
  62. if (mPerSec)
  63. {
  64. mValue = mStatp->getMeanPerSec();
  65. }
  66. else
  67. {
  68. mValue = mStatp->getMean();
  69. }
  70. }
  71. frac = (mValue - mMin) / range;
  72. frac = llmax(0.f, frac);
  73. frac = llmin(1.f, frac);
  74. if (mUpdateTimer.getElapsedTimeF32() > 0.5f)
  75. {
  76. std::string format_str;
  77. std::string tmp_str;
  78. format_str = llformat("%%s%%.%df%%s", mPrecision);
  79. tmp_str = llformat(format_str.c_str(), mLabel.c_str(), mValue, mUnits.c_str());
  80. setToolTip(tmp_str);
  81. mUpdateTimer.reset();
  82. }
  83. LLColor4 color;
  84. S32 i;
  85. for (i = 0; i < mNumThresholds - 1; i++)
  86. {
  87. if (mThresholds[i] > mValue)
  88. {
  89. break;
  90. }
  91. }
  92. //gl_drop_shadow(0, getRect().getHeight(), getRect().getWidth(), 0,
  93. // LLUIColorTable::instance().getColor("ColorDropShadow"),
  94. // (S32) gSavedSettings.getF32("DropShadowFloater") );
  95. color = LLUIColorTable::instance().getColor( "MenuDefaultBgColor" );
  96. gGL.color4fv(color.mV);
  97. gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, TRUE);
  98. gGL.color4fv(LLColor4::black.mV);
  99. gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, FALSE);
  100. color = mThresholdColors[i];
  101. gGL.color4fv(color.mV);
  102. gl_rect_2d(1, llround(frac*getRect().getHeight()), getRect().getWidth() - 1, 0, TRUE);
  103. }
  104. void LLStatGraph::setValue(const LLSD& value)
  105. {
  106. mValue = (F32)value.asReal();
  107. }
  108. void LLStatGraph::setMin(const F32 min)
  109. {
  110. mMin = min;
  111. }
  112. void LLStatGraph::setMax(const F32 max)
  113. {
  114. mMax = max;
  115. }
  116. void LLStatGraph::setStat(LLStat *statp)
  117. {
  118. mStatp = statp;
  119. }
  120. void LLStatGraph::setLabel(const std::string& label)
  121. {
  122. mLabel = label;
  123. }
  124. void LLStatGraph::setUnits(const std::string& units)
  125. {
  126. mUnits = units;
  127. }
  128. void LLStatGraph::setPrecision(const S32 precision)
  129. {
  130. mPrecision = precision;
  131. }
  132. void LLStatGraph::setThreshold(const S32 i, F32 value)
  133. {
  134. mThresholds[i] = value;
  135. }