llprogressbar.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @file llprogressbar.cpp
  3. * @brief LLProgressBar class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llprogressbar.h"
  34. #include "indra_constants.h"
  35. #include "llgl.h"
  36. #include "llglheaders.h"
  37. #include "llimagegl.h"
  38. #include "llmath.h"
  39. #include "lltimer.h"
  40. static const std::string LL_PROGRESS_BAR_TAG = "progress_bar";
  41. static LLRegisterWidget<LLProgressBar> r16(LL_PROGRESS_BAR_TAG);
  42. LLProgressBar::LLProgressBar(const std::string& name, const LLRect& rect)
  43. : LLView(name, rect, false),
  44. mPercentDone(0.f),
  45. mColorBackground(LLUI::sLoginProgressBarBgColor)
  46. {
  47. // Defaults:
  48. setImageBar("progressbar_fill.tga");
  49. setImageShadow("progressbar_track.tga");
  50. }
  51. LLProgressBar::~LLProgressBar()
  52. {
  53. gFocusMgr.releaseFocusIfNeeded(this);
  54. }
  55. void LLProgressBar::draw()
  56. {
  57. static LLTimer timer;
  58. mImageShadow->draw(getLocalRect(), mColorBackground);
  59. LLRect progress_rect = getLocalRect();
  60. progress_rect.mRight = ll_roundp(mPercentDone * 0.01f *
  61. getRect().getWidth());
  62. mImageBar->draw(progress_rect);
  63. }
  64. void LLProgressBar::setPercent(F32 percent)
  65. {
  66. mPercentDone = llclamp(percent, 0.f, 100.f);
  67. }
  68. void LLProgressBar::setImageBar(const std::string& bar_name)
  69. {
  70. mImageBar = LLUI::getUIImage(bar_name);
  71. }
  72. void LLProgressBar::setImageShadow(const std::string& shadow_name)
  73. {
  74. mImageShadow = LLUI::getUIImage(shadow_name);
  75. }
  76. void LLProgressBar::setColorBackground(const LLColor4& c)
  77. {
  78. mColorBackground = c;
  79. }
  80. //virtual
  81. const std::string& LLProgressBar::getTag() const
  82. {
  83. return LL_PROGRESS_BAR_TAG;
  84. }
  85. //virtual
  86. LLXMLNodePtr LLProgressBar::getXML(bool save_children) const
  87. {
  88. LLXMLNodePtr node = LLView::getXML();
  89. node->setName(LL_PROGRESS_BAR_TAG);
  90. return node;
  91. }
  92. //static
  93. LLView* LLProgressBar::fromXML(LLXMLNodePtr node, LLView *parent,
  94. LLUICtrlFactory *factory)
  95. {
  96. std::string name = LL_PROGRESS_BAR_TAG;
  97. node->getAttributeString("name", name);
  98. LLProgressBar *progress = new LLProgressBar(name, LLRect());
  99. std::string image_bar;
  100. if (node->hasAttribute("image_bar"))
  101. {
  102. node->getAttributeString("image_bar", image_bar);
  103. }
  104. if (image_bar != LLStringUtil::null)
  105. {
  106. progress->setImageBar(image_bar);
  107. }
  108. std::string image_shadow;
  109. if (node->hasAttribute("image_shadow"))
  110. {
  111. node->getAttributeString("image_shadow", image_shadow);
  112. }
  113. if (image_shadow != LLStringUtil::null)
  114. {
  115. progress->setImageShadow(image_shadow);
  116. }
  117. LLColor4 color_bg;
  118. if (node->hasAttribute("color_bg"))
  119. {
  120. node->getAttributeColor4("color_bg", color_bg);
  121. progress->setColorBackground(color_bg);
  122. }
  123. progress->initFromXML(node, parent);
  124. return progress;
  125. }