aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcharacter/llvisualparam.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcharacter/llvisualparam.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llcharacter/llvisualparam.cpp')
-rw-r--r--linden/indra/llcharacter/llvisualparam.cpp285
1 files changed, 285 insertions, 0 deletions
diff --git a/linden/indra/llcharacter/llvisualparam.cpp b/linden/indra/llcharacter/llvisualparam.cpp
new file mode 100644
index 0000000..ed8a034
--- /dev/null
+++ b/linden/indra/llcharacter/llvisualparam.cpp
@@ -0,0 +1,285 @@
1/**
2 * @file llvisualparam.cpp
3 * @brief Implementation of LLPolyMesh class.
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28//-----------------------------------------------------------------------------
29// Header Files
30//-----------------------------------------------------------------------------
31#include "linden_common.h"
32
33#include "llvisualparam.h"
34
35//-----------------------------------------------------------------------------
36// LLVisualParamInfo()
37//-----------------------------------------------------------------------------
38LLVisualParamInfo::LLVisualParamInfo()
39 :
40 mID( -1 ),
41 mGroup( VISUAL_PARAM_GROUP_TWEAKABLE ),
42 mMinWeight( 0.f ),
43 mMaxWeight( 1.f ),
44 mDefaultWeight( 0.f ),
45 mSex( SEX_BOTH )
46{
47}
48
49//-----------------------------------------------------------------------------
50// parseXml()
51//-----------------------------------------------------------------------------
52BOOL LLVisualParamInfo::parseXml(LLXmlTreeNode *node)
53{
54 // attribute: id
55 static LLStdStringHandle id_string = LLXmlTree::addAttributeString("id");
56 node->getFastAttributeS32( id_string, mID );
57
58 // attribute: group
59 U32 group = 0;
60 static LLStdStringHandle group_string = LLXmlTree::addAttributeString("group");
61 if( node->getFastAttributeU32( group_string, group ) )
62 {
63 if( group < NUM_VISUAL_PARAM_GROUPS )
64 {
65 mGroup = (EVisualParamGroup)group;
66 }
67 }
68
69 // attribute: value_min, value_max
70 static LLStdStringHandle value_min_string = LLXmlTree::addAttributeString("value_min");
71 static LLStdStringHandle value_max_string = LLXmlTree::addAttributeString("value_max");
72 node->getFastAttributeF32( value_min_string, mMinWeight );
73 node->getFastAttributeF32( value_max_string, mMaxWeight );
74
75 // attribute: value_default
76 F32 default_weight = 0;
77 static LLStdStringHandle value_default_string = LLXmlTree::addAttributeString("value_default");
78 if( node->getFastAttributeF32( value_default_string, default_weight ) )
79 {
80 mDefaultWeight = llclamp( default_weight, mMinWeight, mMaxWeight );
81 if( default_weight != mDefaultWeight )
82 {
83 llwarns << "value_default attribute is out of range in node " << mName << " " << default_weight << llendl;
84 }
85 }
86
87 // attribute: sex
88 LLString sex = "both";
89 static LLStdStringHandle sex_string = LLXmlTree::addAttributeString("sex");
90 node->getFastAttributeString( sex_string, sex ); // optional
91 if( sex == "both" )
92 {
93 mSex = SEX_BOTH;
94 }
95 else if( sex == "male" )
96 {
97 mSex = SEX_MALE;
98 }
99 else if( sex == "female" )
100 {
101 mSex = SEX_FEMALE;
102 }
103 else
104 {
105 llwarns << "Avatar file: <param> has invalid sex attribute: " << sex << llendl;
106 return FALSE;
107 }
108
109 // attribute: name
110 static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name");
111 if( !node->getFastAttributeString( name_string, mName ) )
112 {
113 llwarns << "Avatar file: <param> is missing name attribute" << llendl;
114 return FALSE;
115 }
116
117 // attribute: label
118 static LLStdStringHandle label_string = LLXmlTree::addAttributeString("label");
119 if( !node->getFastAttributeString( label_string, mDisplayName ) )
120 {
121 mDisplayName = mName;
122 }
123
124 // JC - make sure the display name includes the capitalization in the XML file,
125 // not the lowercased version.
126 LLString::toLower(mName);
127
128 // attribute: label_min
129 static LLStdStringHandle label_min_string = LLXmlTree::addAttributeString("label_min");
130 if( !node->getFastAttributeString( label_min_string, mMinName ) )
131 {
132 mMinName = "Less";
133 }
134
135 // attribute: label_max
136 static LLStdStringHandle label_max_string = LLXmlTree::addAttributeString("label_max");
137 if( !node->getFastAttributeString( label_max_string, mMaxName ) )
138 {
139 mMaxName = "More";
140 }
141
142 return TRUE;
143}
144
145//-----------------------------------------------------------------------------
146// LLVisualParam()
147//-----------------------------------------------------------------------------
148LLVisualParam::LLVisualParam()
149 :
150 mCurWeight( 0.f ),
151 mLastWeight( 0.f ),
152 mNext( NULL ),
153 mTargetWeight( 0.f ),
154 mIsAnimating( FALSE ),
155 mID( -1 ),
156 mInfo( 0 )
157{
158}
159
160//-----------------------------------------------------------------------------
161// ~LLVisualParam()
162//-----------------------------------------------------------------------------
163LLVisualParam::~LLVisualParam()
164{
165 delete mNext;
166}
167
168/*
169//=============================================================================
170// These virtual functions should always be overridden,
171// but are included here for use as templates
172//=============================================================================
173
174//-----------------------------------------------------------------------------
175// setInfo()
176//-----------------------------------------------------------------------------
177
178BOOL LLVisualParam::setInfo(LLVisualParamInfo *info)
179{
180 llassert(mInfo == NULL);
181 if (info->mID < 0)
182 return FALSE;
183 mInfo = info;
184 mID = info->mID;
185 setWeight(getDefaultWeight(), FALSE );
186 return TRUE;
187}
188
189//-----------------------------------------------------------------------------
190// parseData()
191//-----------------------------------------------------------------------------
192BOOL LLVisualParam::parseData(LLXmlTreeNode *node)
193{
194 LLVisualParamInfo *info = new LLVisualParamInfo;
195
196 info->parseXml(node);
197 if (!setInfo(info))
198 return FALSE;
199
200 return TRUE;
201}
202*/
203
204//-----------------------------------------------------------------------------
205// setWeight()
206//-----------------------------------------------------------------------------
207void LLVisualParam::setWeight(F32 weight, BOOL set_by_user)
208{
209 if (mIsAnimating)
210 {
211 //RN: allow overshoot
212 mCurWeight = weight;
213 }
214 else if (mInfo)
215 {
216 mCurWeight = llclamp(weight, mInfo->mMinWeight, mInfo->mMaxWeight);
217 }
218 else
219 {
220 mCurWeight = weight;
221 }
222
223 if (mNext)
224 {
225 mNext->setWeight(weight, set_by_user);
226 }
227}
228
229//-----------------------------------------------------------------------------
230// setAnimationTarget()
231//-----------------------------------------------------------------------------
232void LLVisualParam::setAnimationTarget(F32 target_value, BOOL set_by_user)
233{
234 if (getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
235 {
236 if (mInfo)
237 {
238 mTargetWeight = llclamp(target_value, mInfo->mMinWeight, mInfo->mMaxWeight);
239 }
240 else
241 {
242 mTargetWeight = target_value;
243 }
244 }
245 mIsAnimating = TRUE;
246
247 if (mNext)
248 {
249 mNext->setAnimationTarget(target_value, set_by_user);
250 }
251}
252
253//-----------------------------------------------------------------------------
254// setNextParam()
255//-----------------------------------------------------------------------------
256void LLVisualParam::setNextParam( LLVisualParam *next )
257{
258 llassert(!mNext);
259
260 mNext = next;
261}
262
263//-----------------------------------------------------------------------------
264// animate()
265//-----------------------------------------------------------------------------
266void LLVisualParam::animate( F32 delta, BOOL set_by_user )
267{
268 if (mIsAnimating)
269 {
270 F32 new_weight = ((mTargetWeight - mCurWeight) * delta) + mCurWeight;
271 setWeight(new_weight, set_by_user);
272 }
273}
274
275//-----------------------------------------------------------------------------
276// stopAnimating()
277//-----------------------------------------------------------------------------
278void LLVisualParam::stopAnimating(BOOL set_by_user)
279{
280 if (mIsAnimating && getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
281 {
282 mIsAnimating = FALSE;
283 setWeight(mTargetWeight, set_by_user);
284 }
285}