PageRenderTime 16ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llprogressbar.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 87 lines | 49 code | 13 blank | 25 comment | 0 complexity | bddb94abd3f5710ecfbc48e3e76a14e4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llprogressbar.cpp
  3. * @brief LLProgressBar class implementation
  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 "linden_common.h"
  27. #include "llprogressbar.h"
  28. #include "indra_constants.h"
  29. #include "llmath.h"
  30. #include "llgl.h"
  31. #include "llui.h"
  32. #include "llfontgl.h"
  33. #include "lltimer.h"
  34. #include "llglheaders.h"
  35. #include "llfocusmgr.h"
  36. #include "lluictrlfactory.h"
  37. #include "lluiimage.h"
  38. static LLDefaultChildRegistry::Register<LLProgressBar> r("progress_bar");
  39. LLProgressBar::Params::Params()
  40. : image_bar("image_bar"),
  41. image_fill("image_fill"),
  42. color_bar("color_bar"),
  43. color_bg("color_bg")
  44. {}
  45. LLProgressBar::LLProgressBar(const LLProgressBar::Params& p)
  46. : LLUICtrl(p),
  47. mImageBar(p.image_bar),
  48. mImageFill(p.image_fill),
  49. mColorBackground(p.color_bg()),
  50. mColorBar(p.color_bar()),
  51. mPercentDone(0.f)
  52. {}
  53. LLProgressBar::~LLProgressBar()
  54. {
  55. gFocusMgr.releaseFocusIfNeeded( this );
  56. }
  57. void LLProgressBar::draw()
  58. {
  59. static LLTimer timer;
  60. F32 alpha = getDrawContext().mAlpha;
  61. LLColor4 image_bar_color = mColorBackground.get();
  62. image_bar_color.setAlpha(alpha);
  63. mImageBar->draw(getLocalRect(), image_bar_color);
  64. alpha *= 0.5f + 0.5f*0.5f*(1.f + (F32)sin(3.f*timer.getElapsedTimeF32()));
  65. LLColor4 bar_color = mColorBar.get();
  66. bar_color.mV[VALPHA] *= alpha; // modulate alpha
  67. LLRect progress_rect = getLocalRect();
  68. progress_rect.mRight = llround(getRect().getWidth() * (mPercentDone / 100.f));
  69. mImageFill->draw(progress_rect, bar_color);
  70. }
  71. void LLProgressBar::setValue(const LLSD& value)
  72. {
  73. mPercentDone = llclamp((F32)value.asReal(), 0.f, 100.f);
  74. }