llfloaterobjectweights.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * @file llfloaterobjectweights.cpp
  3. * @brief LLFloaterObjectWeights class implementation
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewergpl$
  6. *
  7. * Copyright (c) 2012, 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 "llviewerprecompiledheaders.h"
  33. #include "llfloaterobjectweights.h"
  34. #include "lltextbox.h"
  35. #include "lluictrlfactory.h"
  36. #include "llselectmgr.h"
  37. constexpr F32 UPDATE_INTERVAL = 1.f;
  38. LLFloaterObjectWeights::LLFloaterObjectWeights(const LLSD&)
  39. : mParentFloater(NULL)
  40. {
  41. LLUICtrlFactory::getInstance()->buildFloater(this,
  42. "floater_object_weights.xml");
  43. }
  44. //virtual
  45. bool LLFloaterObjectWeights::postBuild()
  46. {
  47. mObjectCount = getChild<LLTextBox>("selected_objects_count");
  48. mObjectImpact = getChild<LLTextBox>("objects_impact");
  49. mObjectPhysics = getChild<LLTextBox>("objects_physics_cost");
  50. mPrimCount = getChild<LLTextBox>("selected_prims_count");
  51. mPrimImpact = getChild<LLTextBox>("prims_impact");
  52. mPrimPhysics = getChild<LLTextBox>("prims_physics_cost");
  53. mPrimStreaming = getChild<LLTextBox>("streaming_cost");
  54. mPrimTriangles = getChild<LLTextBox>("triangle_count");
  55. refresh();
  56. return true;
  57. }
  58. //virtual
  59. void LLFloaterObjectWeights::refresh()
  60. {
  61. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  62. bool enabled = !selection->isEmpty();
  63. mObjectCount->setVisible(enabled);
  64. mObjectImpact->setVisible(enabled);
  65. mObjectPhysics->setVisible(enabled);
  66. mPrimCount->setVisible(enabled);
  67. mPrimImpact->setVisible(enabled);
  68. mPrimPhysics->setVisible(enabled);
  69. mPrimStreaming->setVisible(enabled);
  70. mPrimTriangles->setVisible(enabled);
  71. if (enabled)
  72. {
  73. mObjectCount->setText(llformat("%d", selection->getRootObjectCount()));
  74. mObjectImpact->setText(llformat("%f",
  75. selection->getSelectedLinksetCost()));
  76. mObjectPhysics->setText(llformat("%f",
  77. selection->getSelectedLinksetPhysicsCost()));
  78. mPrimCount->setText(llformat("%d", selection->getObjectCount()));
  79. mPrimImpact->setText(llformat("%f",
  80. selection->getSelectedObjectCost()));
  81. mPrimPhysics->setText(llformat("%f",
  82. selection->getSelectedPhysicsCost()));
  83. S32 total, visible;
  84. mPrimStreaming->setText(llformat("%f",
  85. selection->getSelectedObjectStreamingCost(&total,
  86. &visible)));
  87. mPrimTriangles->setText(llformat("%d",
  88. selection->getSelectedObjectTriangleCount(&total)));
  89. }
  90. }
  91. //virtual
  92. void LLFloaterObjectWeights::draw()
  93. {
  94. if (mUpdateTimer.hasExpired())
  95. {
  96. refresh();
  97. mUpdateTimer.setTimerExpirySec(UPDATE_INTERVAL);
  98. }
  99. LLFloater::draw();
  100. }
  101. //static
  102. void LLFloaterObjectWeights::show(LLFloater* parent)
  103. {
  104. LLFloaterObjectWeights* self = findInstance();
  105. if (self)
  106. {
  107. self->open();
  108. self->refresh();
  109. if (self->mParentFloater == parent)
  110. {
  111. // Called by the same parent. We are done !
  112. return;
  113. }
  114. // Reparent to the new floater
  115. if (self->mParentFloater)
  116. {
  117. self->mParentFloater->removeDependentFloater(self);
  118. }
  119. }
  120. else
  121. {
  122. self = getInstance(); // creates a new instance
  123. }
  124. if (parent && self)
  125. {
  126. self->mParentFloater = parent;
  127. parent->addDependentFloater(self);
  128. }
  129. }