llstatgraph.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file llstatgraph.h
  3. * @brief Simpler compact stat graph with tooltip
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. * Copyright (c) 2009-2021, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLSTATGRAPH_H
  34. #define LL_LLSTATGRAPH_H
  35. #include "llframetimer.h"
  36. #include "llstat.h"
  37. #include "llview.h"
  38. #include "llcolor4.h"
  39. class LLStatGraph : public LLView
  40. {
  41. public:
  42. LLStatGraph(const std::string& name, const LLRect& rect);
  43. void draw() override;
  44. LL_INLINE void setStat(LLStat* statp) { mStatp = statp; }
  45. LL_INLINE void setLabel(const std::string& label) { mLabel = label; }
  46. LL_INLINE void setLabelSuffix(const std::string& s) { mLabelSuffix = s; }
  47. LL_INLINE void setUnits(const std::string& unit1,
  48. const std::string& unit2 = LLStringUtil::null)
  49. {
  50. mUnit1 = unit1;
  51. mUnit2 = unit2;
  52. }
  53. // This is the divisor to apply to the value to switch from unit 1 to
  54. // unit 2. When not specified (or <= 0.f), the switch does not happen.
  55. LL_INLINE void setUnitDivisor(F32 divisor) { mDivisor = divisor; }
  56. LL_INLINE void setPrecision(U32 precision) { mPrecision = precision; }
  57. // Note: logarithmic indicators thresholds are always expressed in % of the
  58. // full range, while the non-log thresholds are an absolute value. HB
  59. LL_INLINE void setThreshold(U32 i, F32 t)
  60. {
  61. if (i < 3)
  62. {
  63. mThresholds[i] = t;
  64. }
  65. }
  66. LL_INLINE void setThresholdColor(U32 i, const LLColor4& color)
  67. {
  68. if (i < 4)
  69. {
  70. mThresholdColors[i] = color;
  71. }
  72. }
  73. LL_INLINE void setMin(F32 min) { mMin = min; updateRange(); }
  74. LL_INLINE void setMax(F32 max) { mMax = max; updateRange(); }
  75. LL_INLINE void setLogScale(bool b = true) { mLogScale = b; updateRange(); }
  76. LL_INLINE void setPerSec(bool b = true) { mPerSec = b; }
  77. LL_INLINE void setValue(const LLSD& value) override { mValue = (F32)value.asReal(); }
  78. LL_INLINE F32 getValueF32() { return mValue; }
  79. LL_INLINE LLStat* getStat() { return mStatp; }
  80. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  81. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  82. void setClickedCallback(void (*cb)(void*), void* userdata = NULL);
  83. private:
  84. void updateRange();
  85. public:
  86. LLStat* mStatp;
  87. private:
  88. void (*mClickedCallback)(void* data);
  89. void* mCallbackUserData;
  90. std::string mLabel;
  91. std::string mLabelSuffix;
  92. std::string mUnit1;
  93. std::string mUnit2;
  94. LLColor4 mThresholdColors[4];
  95. F32 mThresholds[3];
  96. LLFrameTimer mUpdateTimer;
  97. F32 mValue;
  98. F32 mMin;
  99. F32 mMax;
  100. F32 mRange;
  101. F32 mDivisor;
  102. U32 mPrecision; // Number of digits of precision after dot
  103. bool mLogScale;
  104. bool mPerSec;
  105. };
  106. #endif // LL_LLSTATGRAPH_H