llvisualparam.cpp

Go to the documentation of this file.
00001 
00032 //-----------------------------------------------------------------------------
00033 // Header Files
00034 //-----------------------------------------------------------------------------
00035 #include "linden_common.h"
00036 
00037 #include "llvisualparam.h"
00038 
00039 //-----------------------------------------------------------------------------
00040 // LLVisualParamInfo()
00041 //-----------------------------------------------------------------------------
00042 LLVisualParamInfo::LLVisualParamInfo()
00043         :
00044         mID( -1 ),
00045         mGroup( VISUAL_PARAM_GROUP_TWEAKABLE ),
00046         mMinWeight( 0.f ),
00047         mMaxWeight( 1.f ),
00048         mDefaultWeight( 0.f ),
00049         mSex( SEX_BOTH )
00050 {
00051 }
00052 
00053 //-----------------------------------------------------------------------------
00054 // parseXml()
00055 //-----------------------------------------------------------------------------
00056 BOOL LLVisualParamInfo::parseXml(LLXmlTreeNode *node)
00057 {
00058         // attribute: id
00059         static LLStdStringHandle id_string = LLXmlTree::addAttributeString("id");
00060         node->getFastAttributeS32( id_string, mID );
00061         
00062         // attribute: group
00063         U32 group = 0;
00064         static LLStdStringHandle group_string = LLXmlTree::addAttributeString("group");
00065         if( node->getFastAttributeU32( group_string, group ) )
00066         {
00067                 if( group < NUM_VISUAL_PARAM_GROUPS )
00068                 {
00069                         mGroup = (EVisualParamGroup)group;
00070                 }
00071         }
00072 
00073         // attribute: value_min, value_max
00074         static LLStdStringHandle value_min_string = LLXmlTree::addAttributeString("value_min");
00075         static LLStdStringHandle value_max_string = LLXmlTree::addAttributeString("value_max");
00076         node->getFastAttributeF32( value_min_string, mMinWeight );
00077         node->getFastAttributeF32( value_max_string, mMaxWeight );
00078 
00079         // attribute: value_default
00080         F32 default_weight = 0;
00081         static LLStdStringHandle value_default_string = LLXmlTree::addAttributeString("value_default");
00082         if( node->getFastAttributeF32( value_default_string, default_weight ) )
00083         {
00084                 mDefaultWeight = llclamp( default_weight, mMinWeight, mMaxWeight );
00085                 if( default_weight != mDefaultWeight )
00086                 {
00087                         llwarns << "value_default attribute is out of range in node " << mName << " " << default_weight << llendl;
00088                 }
00089         }
00090         
00091         // attribute: sex
00092         LLString sex = "both";
00093         static LLStdStringHandle sex_string = LLXmlTree::addAttributeString("sex");
00094         node->getFastAttributeString( sex_string, sex ); // optional
00095         if( sex == "both" )
00096         {
00097                 mSex = SEX_BOTH;
00098         }
00099         else if( sex == "male" )
00100         {
00101                 mSex = SEX_MALE;
00102         }
00103         else if( sex == "female" )
00104         {
00105                 mSex = SEX_FEMALE;
00106         }
00107         else
00108         {
00109                 llwarns << "Avatar file: <param> has invalid sex attribute: " << sex << llendl;
00110                 return FALSE;
00111         }
00112         
00113         // attribute: name
00114         static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name");
00115         if( !node->getFastAttributeString( name_string, mName ) )
00116         {
00117                 llwarns << "Avatar file: <param> is missing name attribute" << llendl;
00118                 return FALSE;
00119         }
00120 
00121         // attribute: label
00122         static LLStdStringHandle label_string = LLXmlTree::addAttributeString("label");
00123         if( !node->getFastAttributeString( label_string, mDisplayName ) )
00124         {
00125                 mDisplayName = mName;
00126         }
00127 
00128         // JC - make sure the display name includes the capitalization in the XML file,
00129         // not the lowercased version.
00130         LLString::toLower(mName);
00131 
00132         // attribute: label_min
00133         static LLStdStringHandle label_min_string = LLXmlTree::addAttributeString("label_min");
00134         if( !node->getFastAttributeString( label_min_string, mMinName ) )
00135         {
00136                 mMinName = "Less";
00137         }
00138 
00139         // attribute: label_max
00140         static LLStdStringHandle label_max_string = LLXmlTree::addAttributeString("label_max");
00141         if( !node->getFastAttributeString( label_max_string, mMaxName ) )
00142         {
00143                 mMaxName = "More";
00144         }
00145 
00146         return TRUE;
00147 }
00148 
00149 //-----------------------------------------------------------------------------
00150 // LLVisualParam()
00151 //-----------------------------------------------------------------------------
00152 LLVisualParam::LLVisualParam()  
00153         :
00154         mCurWeight( 0.f ),
00155         mLastWeight( 0.f ),
00156         mNext( NULL ),
00157         mTargetWeight( 0.f ),
00158         mIsAnimating( FALSE ),
00159         mID( -1 ),
00160         mInfo( 0 )
00161 {
00162 }
00163 
00164 //-----------------------------------------------------------------------------
00165 // ~LLVisualParam()
00166 //-----------------------------------------------------------------------------
00167 LLVisualParam::~LLVisualParam()
00168 {
00169         delete mNext;
00170 }
00171 
00172 /*
00173 //=============================================================================
00174 // These virtual functions should always be overridden,
00175 // but are included here for use as templates
00176 //=============================================================================
00177 
00178 //-----------------------------------------------------------------------------
00179 // setInfo()
00180 //-----------------------------------------------------------------------------
00181 
00182 BOOL LLVisualParam::setInfo(LLVisualParamInfo *info)
00183 {
00184         llassert(mInfo == NULL);
00185         if (info->mID < 0)
00186                 return FALSE;
00187         mInfo = info;
00188         mID = info->mID;
00189         setWeight(getDefaultWeight(), FALSE );
00190         return TRUE;
00191 }
00192 
00193 //-----------------------------------------------------------------------------
00194 // parseData()
00195 //-----------------------------------------------------------------------------
00196 BOOL LLVisualParam::parseData(LLXmlTreeNode *node)
00197 {
00198         LLVisualParamInfo *info = new LLVisualParamInfo;
00199 
00200         info->parseXml(node);
00201         if (!setInfo(info))
00202                 return FALSE;
00203         
00204         return TRUE;
00205 }
00206 */
00207 
00208 //-----------------------------------------------------------------------------
00209 // setWeight()
00210 //-----------------------------------------------------------------------------
00211 void LLVisualParam::setWeight(F32 weight, BOOL set_by_user)
00212 {
00213         if (mIsAnimating)
00214         {
00215                 //RN: allow overshoot
00216                 mCurWeight = weight;
00217         }
00218         else if (mInfo)
00219         {
00220                 mCurWeight = llclamp(weight, mInfo->mMinWeight, mInfo->mMaxWeight);
00221         }
00222         else
00223         {
00224                 mCurWeight = weight;
00225         }
00226         
00227         if (mNext)
00228         {
00229                 mNext->setWeight(weight, set_by_user);
00230         }
00231 }
00232 
00233 //-----------------------------------------------------------------------------
00234 // setAnimationTarget()
00235 //-----------------------------------------------------------------------------
00236 void LLVisualParam::setAnimationTarget(F32 target_value, BOOL set_by_user)
00237 {
00238         if (mInfo)
00239         {
00240                 if (getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
00241                 {
00242                         mTargetWeight = llclamp(target_value, mInfo->mMinWeight, mInfo->mMaxWeight);
00243                 }
00244         }
00245         else
00246         {
00247                 mTargetWeight = target_value;
00248         }
00249         mIsAnimating = TRUE;
00250 
00251         if (mNext)
00252         {
00253                 mNext->setAnimationTarget(target_value, set_by_user);
00254         }
00255 }
00256 
00257 //-----------------------------------------------------------------------------
00258 // setNextParam()
00259 //-----------------------------------------------------------------------------
00260 void LLVisualParam::setNextParam( LLVisualParam *next )
00261 {
00262         llassert(!mNext);
00263 
00264         mNext = next;
00265 }
00266 
00267 //-----------------------------------------------------------------------------
00268 // animate()
00269 //-----------------------------------------------------------------------------
00270 void LLVisualParam::animate( F32 delta, BOOL set_by_user )
00271 {
00272         if (mIsAnimating)
00273         {
00274                 F32 new_weight = ((mTargetWeight - mCurWeight) * delta) + mCurWeight;
00275                 setWeight(new_weight, set_by_user);
00276         }
00277 }
00278 
00279 //-----------------------------------------------------------------------------
00280 // stopAnimating()
00281 //-----------------------------------------------------------------------------
00282 void LLVisualParam::stopAnimating(BOOL set_by_user)
00283 { 
00284         if (mIsAnimating && getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
00285         {
00286                 mIsAnimating = FALSE; 
00287                 setWeight(mTargetWeight, set_by_user);
00288         }
00289 }

Generated on Thu Jul 1 06:09:35 2010 for Second Life Viewer by  doxygen 1.4.7