PageRenderTime 243ms CodeModel.GetById 121ms app.highlight 12ms RepoModel.GetById 108ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28#include "llagent.h"
 29#include "lltexlayer.h"
 30#include "llvoavatar.h"
 31#include "llwearable.h"
 32#include "lltexglobalcolor.h"
 33
 34//-----------------------------------------------------------------------------
 35// LLTexGlobalColor
 36//-----------------------------------------------------------------------------
 37
 38LLTexGlobalColor::LLTexGlobalColor(LLVOAvatar* avatar) 
 39	:
 40	mAvatar(avatar),
 41	mInfo(NULL)
 42{
 43}
 44
 45LLTexGlobalColor::~LLTexGlobalColor()
 46{
 47	// mParamColorList are LLViewerVisualParam's and get deleted with ~LLCharacter()
 48	//std::for_each(mParamColorList.begin(), mParamColorList.end(), DeletePointer());
 49}
 50
 51BOOL LLTexGlobalColor::setInfo(LLTexGlobalColorInfo *info)
 52{
 53	llassert(mInfo == NULL);
 54	mInfo = info;
 55	//mID = info->mID; // No ID
 56
 57	mParamGlobalColorList.reserve(mInfo->mParamColorInfoList.size());
 58	for (param_color_info_list_t::iterator iter = mInfo->mParamColorInfoList.begin(); 
 59		 iter != mInfo->mParamColorInfoList.end(); 
 60		 iter++)
 61	{
 62		LLTexParamGlobalColor* param_color = new LLTexParamGlobalColor(this);
 63		if (!param_color->setInfo(*iter, TRUE))
 64		{
 65			mInfo = NULL;
 66			return FALSE;
 67		}
 68		mParamGlobalColorList.push_back(param_color);
 69	}
 70	
 71	return TRUE;
 72}
 73
 74LLColor4 LLTexGlobalColor::getColor() const
 75{
 76	// Sum of color params
 77	if (mParamGlobalColorList.empty())
 78		return LLColor4(1.f, 1.f, 1.f, 1.f);
 79
 80	LLColor4 net_color(0.f, 0.f, 0.f, 0.f);
 81	LLTexLayer::calculateTexLayerColor(mParamGlobalColorList, net_color);
 82	return net_color;
 83}
 84
 85const std::string& LLTexGlobalColor::getName() const
 86{ 
 87	return mInfo->mName; 
 88}
 89
 90//-----------------------------------------------------------------------------
 91// LLTexParamGlobalColor
 92//-----------------------------------------------------------------------------
 93LLTexParamGlobalColor::LLTexParamGlobalColor(LLTexGlobalColor* tex_global_color) :
 94	LLTexLayerParamColor(tex_global_color->getAvatar()),
 95	mTexGlobalColor(tex_global_color)
 96{
 97}
 98
 99/*virtual*/ LLViewerVisualParam* LLTexParamGlobalColor::cloneParam(LLWearable* wearable) const
100{
101	LLTexParamGlobalColor *new_param = new LLTexParamGlobalColor(mTexGlobalColor);
102	*new_param = *this;
103	return new_param;
104}
105
106void LLTexParamGlobalColor::onGlobalColorChanged(bool upload_bake)
107{
108	mAvatar->onGlobalColorChanged(mTexGlobalColor, upload_bake);
109}
110
111//-----------------------------------------------------------------------------
112// LLTexGlobalColorInfo
113//-----------------------------------------------------------------------------
114
115LLTexGlobalColorInfo::LLTexGlobalColorInfo()
116{
117}
118
119
120LLTexGlobalColorInfo::~LLTexGlobalColorInfo()
121{
122	for_each(mParamColorInfoList.begin(), mParamColorInfoList.end(), DeletePointer());
123}
124
125BOOL LLTexGlobalColorInfo::parseXml(LLXmlTreeNode* node)
126{
127	// name attribute
128	static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name");
129	if (!node->getFastAttributeString(name_string, mName))
130	{
131		llwarns << "<global_color> element is missing name attribute." << llendl;
132		return FALSE;
133	}
134	// <param> sub-element
135	for (LLXmlTreeNode* child = node->getChildByName("param");
136		 child;
137		 child = node->getNextNamedChild())
138	{
139		if (child->getChildByName("param_color"))
140		{
141			// <param><param_color/></param>
142			LLTexLayerParamColorInfo* info = new LLTexLayerParamColorInfo();
143			if (!info->parseXml(child))
144			{
145				delete info;
146				return FALSE;
147			}
148			mParamColorInfoList.push_back(info);
149		}
150	}
151	return TRUE;
152}