PageRenderTime 23ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltexglobalcolor.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 152 lines | 93 code | 18 blank | 41 comment | 9 complexity | c4e4b2f15edcde29019961ca61322002 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltexlayerglobalcolor.cpp
  3. * @brief Color for texture layers.
  4. *
  5. * $LicenseInfo:firstyear=2008&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 "llviewerprecompiledheaders.h"
  27. #include "llagent.h"
  28. #include "lltexlayer.h"
  29. #include "llvoavatar.h"
  30. #include "llwearable.h"
  31. #include "lltexglobalcolor.h"
  32. //-----------------------------------------------------------------------------
  33. // LLTexGlobalColor
  34. //-----------------------------------------------------------------------------
  35. LLTexGlobalColor::LLTexGlobalColor(LLVOAvatar* avatar)
  36. :
  37. mAvatar(avatar),
  38. mInfo(NULL)
  39. {
  40. }
  41. LLTexGlobalColor::~LLTexGlobalColor()
  42. {
  43. // mParamColorList are LLViewerVisualParam's and get deleted with ~LLCharacter()
  44. //std::for_each(mParamColorList.begin(), mParamColorList.end(), DeletePointer());
  45. }
  46. BOOL LLTexGlobalColor::setInfo(LLTexGlobalColorInfo *info)
  47. {
  48. llassert(mInfo == NULL);
  49. mInfo = info;
  50. //mID = info->mID; // No ID
  51. mParamGlobalColorList.reserve(mInfo->mParamColorInfoList.size());
  52. for (param_color_info_list_t::iterator iter = mInfo->mParamColorInfoList.begin();
  53. iter != mInfo->mParamColorInfoList.end();
  54. iter++)
  55. {
  56. LLTexParamGlobalColor* param_color = new LLTexParamGlobalColor(this);
  57. if (!param_color->setInfo(*iter, TRUE))
  58. {
  59. mInfo = NULL;
  60. return FALSE;
  61. }
  62. mParamGlobalColorList.push_back(param_color);
  63. }
  64. return TRUE;
  65. }
  66. LLColor4 LLTexGlobalColor::getColor() const
  67. {
  68. // Sum of color params
  69. if (mParamGlobalColorList.empty())
  70. return LLColor4(1.f, 1.f, 1.f, 1.f);
  71. LLColor4 net_color(0.f, 0.f, 0.f, 0.f);
  72. LLTexLayer::calculateTexLayerColor(mParamGlobalColorList, net_color);
  73. return net_color;
  74. }
  75. const std::string& LLTexGlobalColor::getName() const
  76. {
  77. return mInfo->mName;
  78. }
  79. //-----------------------------------------------------------------------------
  80. // LLTexParamGlobalColor
  81. //-----------------------------------------------------------------------------
  82. LLTexParamGlobalColor::LLTexParamGlobalColor(LLTexGlobalColor* tex_global_color) :
  83. LLTexLayerParamColor(tex_global_color->getAvatar()),
  84. mTexGlobalColor(tex_global_color)
  85. {
  86. }
  87. /*virtual*/ LLViewerVisualParam* LLTexParamGlobalColor::cloneParam(LLWearable* wearable) const
  88. {
  89. LLTexParamGlobalColor *new_param = new LLTexParamGlobalColor(mTexGlobalColor);
  90. *new_param = *this;
  91. return new_param;
  92. }
  93. void LLTexParamGlobalColor::onGlobalColorChanged(bool upload_bake)
  94. {
  95. mAvatar->onGlobalColorChanged(mTexGlobalColor, upload_bake);
  96. }
  97. //-----------------------------------------------------------------------------
  98. // LLTexGlobalColorInfo
  99. //-----------------------------------------------------------------------------
  100. LLTexGlobalColorInfo::LLTexGlobalColorInfo()
  101. {
  102. }
  103. LLTexGlobalColorInfo::~LLTexGlobalColorInfo()
  104. {
  105. for_each(mParamColorInfoList.begin(), mParamColorInfoList.end(), DeletePointer());
  106. }
  107. BOOL LLTexGlobalColorInfo::parseXml(LLXmlTreeNode* node)
  108. {
  109. // name attribute
  110. static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name");
  111. if (!node->getFastAttributeString(name_string, mName))
  112. {
  113. llwarns << "<global_color> element is missing name attribute." << llendl;
  114. return FALSE;
  115. }
  116. // <param> sub-element
  117. for (LLXmlTreeNode* child = node->getChildByName("param");
  118. child;
  119. child = node->getNextNamedChild())
  120. {
  121. if (child->getChildByName("param_color"))
  122. {
  123. // <param><param_color/></param>
  124. LLTexLayerParamColorInfo* info = new LLTexLayerParamColorInfo();
  125. if (!info->parseXml(child))
  126. {
  127. delete info;
  128. return FALSE;
  129. }
  130. mParamColorInfoList.push_back(info);
  131. }
  132. }
  133. return TRUE;
  134. }