PageRenderTime 337ms CodeModel.GetById 323ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llloadingindicator.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 100 lines | 47 code | 16 blank | 37 comment | 4 complexity | 9b244a685691f4eea8a3a8d56860ebe3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llloadingindicator.cpp
  3. * @brief Perpetual loading indicator
  4. *
  5. * $LicenseInfo:firstyear=2010&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 "llloadingindicator.h"
  28. // Linden library includes
  29. #include "llsingleton.h"
  30. // Project includes
  31. #include "lluictrlfactory.h"
  32. #include "lluiimage.h"
  33. #include "boost/foreach.hpp"
  34. // registered in llui.cpp to avoid being left out by MS linker
  35. //static LLDefaultChildRegistry::Register<LLLoadingIndicator> r("loading_indicator");
  36. ///////////////////////////////////////////////////////////////////////////////
  37. // LLLoadingIndicator class
  38. ///////////////////////////////////////////////////////////////////////////////
  39. LLLoadingIndicator::LLLoadingIndicator(const Params& p)
  40. : LLUICtrl(p),
  41. mImagesPerSec(p.images_per_sec > 0 ? p.images_per_sec : 1.0f),
  42. mCurImageIdx(0)
  43. {
  44. }
  45. void LLLoadingIndicator::initFromParams(const Params& p)
  46. {
  47. BOOST_FOREACH(LLUIImage* image, p.images.image)
  48. {
  49. mImages.push_back(image);
  50. }
  51. // Start timer for switching images.
  52. start();
  53. }
  54. void LLLoadingIndicator::draw()
  55. {
  56. // Time to switch to the next image?
  57. if (mImageSwitchTimer.getStarted() && mImageSwitchTimer.hasExpired())
  58. {
  59. // Switch to the next image.
  60. if (!mImages.empty())
  61. {
  62. mCurImageIdx = (mCurImageIdx + 1) % mImages.size();
  63. }
  64. // Restart timer.
  65. start();
  66. }
  67. LLUIImagePtr cur_image = mImages.empty() ? LLUIImagePtr(NULL) : mImages[mCurImageIdx];
  68. // Draw current image.
  69. if( cur_image.notNull() )
  70. {
  71. cur_image->draw(getLocalRect(), LLColor4::white % getDrawContext().mAlpha);
  72. }
  73. LLUICtrl::draw();
  74. }
  75. void LLLoadingIndicator::stop()
  76. {
  77. mImageSwitchTimer.stop();
  78. }
  79. void LLLoadingIndicator::start()
  80. {
  81. mImageSwitchTimer.start();
  82. F32 period = 1.0f / (mImages.size() * mImagesPerSec);
  83. mImageSwitchTimer.setTimerExpirySec(period);
  84. }