lltexglobalcolor.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * @file lltexlayerglobalcolor.cpp
  3. * @brief Color for texture layers.
  4. *
  5. * $LicenseInfo:firstyear=2008&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, 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 "lltexglobalcolor.h"
  34. #include "llavatarappearance.h"
  35. #include "lltexlayer.h"
  36. class LLWearable;
  37. //-----------------------------------------------------------------------------
  38. // LLTexGlobalColor
  39. //-----------------------------------------------------------------------------
  40. LLTexGlobalColor::LLTexGlobalColor(LLAvatarAppearance* appearance)
  41. : mAvatarAppearance(appearance),
  42. mInfo(NULL)
  43. {
  44. }
  45. #if 0 // mParamColorList are LLViewerVisualParam and get deleted with
  46. // ~LLCharacter()
  47. LLTexGlobalColor::~LLTexGlobalColor()
  48. {
  49. std::for_each(mParamColorList.begin(), mParamColorList.end(),
  50. DeletePointer());
  51. mParamColorList.clear();
  52. }
  53. #endif
  54. bool LLTexGlobalColor::setInfo(LLTexGlobalColorInfo* info)
  55. {
  56. llassert(mInfo == NULL);
  57. mInfo = info;
  58. #if 0 // No ID
  59. mID = info->mID;
  60. #endif
  61. mParamGlobalColorList.reserve(mInfo->mParamColorInfoList.size());
  62. for (param_color_info_list_t::iterator
  63. iter = mInfo->mParamColorInfoList.begin(),
  64. end = mInfo->mParamColorInfoList.end();
  65. iter != end; ++iter)
  66. {
  67. LLTexParamGlobalColor* param_color = new LLTexParamGlobalColor(this);
  68. if (!param_color->setInfo(*iter, true))
  69. {
  70. mInfo = NULL;
  71. return false;
  72. }
  73. mParamGlobalColorList.push_back(param_color);
  74. }
  75. return true;
  76. }
  77. // Sum of color params
  78. LLColor4 LLTexGlobalColor::getColor() const
  79. {
  80. if (mParamGlobalColorList.empty())
  81. {
  82. return LLColor4(1.f, 1.f, 1.f, 1.f);
  83. }
  84. LLColor4 net_color(0.f, 0.f, 0.f, 0.f);
  85. LLTexLayer::calculateTexLayerColor(mParamGlobalColorList, net_color);
  86. return net_color;
  87. }
  88. const std::string& LLTexGlobalColor::getName() const
  89. {
  90. return mInfo->mName;
  91. }
  92. //-----------------------------------------------------------------------------
  93. // LLTexParamGlobalColor
  94. //-----------------------------------------------------------------------------
  95. LLTexParamGlobalColor::LLTexParamGlobalColor(LLTexGlobalColor* tex_global_color)
  96. : LLTexLayerParamColor(tex_global_color->getAvatarAppearance()),
  97. mTexGlobalColor(tex_global_color)
  98. {
  99. }
  100. LLTexParamGlobalColor::LLTexParamGlobalColor(const LLTexParamGlobalColor& other)
  101. : LLTexLayerParamColor(other),
  102. mTexGlobalColor(other.mTexGlobalColor)
  103. {
  104. }
  105. //-----------------------------------------------------------------------------
  106. // ~LLTexParamGlobalColor
  107. //-----------------------------------------------------------------------------
  108. //virtual
  109. LLViewerVisualParam* LLTexParamGlobalColor::cloneParam(LLWearable* wearable) const
  110. {
  111. return new LLTexParamGlobalColor(*this);
  112. }
  113. void LLTexParamGlobalColor::onGlobalColorChanged(bool upload_bake)
  114. {
  115. mAvatarAppearance->onGlobalColorChanged(mTexGlobalColor, upload_bake);
  116. }
  117. //-----------------------------------------------------------------------------
  118. // LLTexGlobalColorInfo
  119. //-----------------------------------------------------------------------------
  120. LLTexGlobalColorInfo::~LLTexGlobalColorInfo()
  121. {
  122. for_each(mParamColorInfoList.begin(), mParamColorInfoList.end(),
  123. DeletePointer());
  124. mParamColorInfoList.clear();
  125. }
  126. bool LLTexGlobalColorInfo::parseXml(LLXmlTreeNode* node)
  127. {
  128. // name attribute
  129. static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name");
  130. if (!node->getFastAttributeString(name_string, mName))
  131. {
  132. llwarns << "<global_color> element is missing name attribute."
  133. << llendl;
  134. return false;
  135. }
  136. // <param> sub-element
  137. for (LLXmlTreeNode* child = node->getChildByName("param"); child;
  138. child = node->getNextNamedChild())
  139. {
  140. if (child->getChildByName("param_color"))
  141. {
  142. // <param><param_color/></param>
  143. LLTexLayerParamColorInfo* info = new LLTexLayerParamColorInfo();
  144. if (!info->parseXml(child))
  145. {
  146. delete info;
  147. return false;
  148. }
  149. mParamColorInfoList.push_back(info);
  150. }
  151. }
  152. return true;
  153. }