From 1dedd3de05503067b36096007eeb0bb6a6204587 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 19 Apr 2011 16:16:54 -0700 Subject: EXP-648 FIX As a developer, I want to be able to specify param blocks that use Multiple for a sequence of images Factored out param block data classes so that specialized param block types, such as LLUIImage, LLFontGL, LLRect, etc. can be stored in a Multiple context Converted loading_indicator to take image sequence from XUI deprecated name-value pairs for LLUIColor values, and put them in colors.xml --- indra/llui/llloadingindicator.cpp | 67 ++++++++++++--------------------------- 1 file changed, 20 insertions(+), 47 deletions(-) (limited to 'indra/llui/llloadingindicator.cpp') diff --git a/indra/llui/llloadingindicator.cpp b/indra/llui/llloadingindicator.cpp index 7b29d92ea0..8a0f875808 100644 --- a/indra/llui/llloadingindicator.cpp +++ b/indra/llui/llloadingindicator.cpp @@ -39,56 +39,24 @@ //static LLDefaultChildRegistry::Register r("loading_indicator"); /////////////////////////////////////////////////////////////////////////////// -// LLLoadingIndicator::Data class +// LLLoadingIndicator class /////////////////////////////////////////////////////////////////////////////// -/** - * Pre-loaded images shared by all instances of the widget - */ -class LLLoadingIndicator::Data: public LLSingleton +LLLoadingIndicator::LLLoadingIndicator(const Params& p) +: LLUICtrl(p), + mImagesPerSec(p.images_per_sec > 0 ? p.images_per_sec : 1.0f), + mCurImageIdx(0) { -public: - /*virtual*/ void initSingleton(); // from LLSingleton - - LLPointer getNextImage(S8& idx) const; - U8 getImagesCount() const { return NIMAGES; } -private: - - static const U8 NIMAGES = 12; - LLPointer mImages[NIMAGES]; -}; +} -// virtual -// Called right after the instance gets constructed. -void LLLoadingIndicator::Data::initSingleton() +void LLLoadingIndicator::initFromParams(const Params& p) { - // Load images. - for (U8 i = 0; i < NIMAGES; ++i) + for (LLInitParam::ParamIterator::const_iterator it = p.images().image.begin(), end_it = p.images().image.end(); + it != end_it; + ++it) { - std::string img_name = llformat("Progress_%d", i+1); - mImages[i] = LLUI::getUIImage(img_name, 0); - llassert(mImages[i]); + mImages.push_back(it->getValue()); } -} - -LLPointer LLLoadingIndicator::Data::getNextImage(S8& idx) const -{ - // Calculate next index, performing array bounds checking. - idx = (idx >= NIMAGES || idx < 0) ? 0 : (idx + 1) % NIMAGES; - return mImages[idx]; -} - -/////////////////////////////////////////////////////////////////////////////// -// LLLoadingIndicator class -/////////////////////////////////////////////////////////////////////////////// - -LLLoadingIndicator::LLLoadingIndicator(const Params& p) -: LLUICtrl(p) - , mRotationsPerSec(p.rotations_per_sec > 0 ? p.rotations_per_sec : 1.0f) - , mCurImageIdx(-1) -{ - // Select initial image. - mCurImagep = Data::instance().getNextImage(mCurImageIdx); // Start timer for switching images. start(); @@ -100,16 +68,21 @@ void LLLoadingIndicator::draw() if (mImageSwitchTimer.getStarted() && mImageSwitchTimer.hasExpired()) { // Switch to the next image. - mCurImagep = Data::instance().getNextImage(mCurImageIdx); + if (!mImages.empty()) + { + mCurImageIdx = (mCurImageIdx + 1) % mImages.size(); + } // Restart timer. start(); } + LLUIImagePtr cur_image = mImages.empty() ? NULL : mImages[mCurImageIdx]; + // Draw current image. - if( mCurImagep.notNull() ) + if( cur_image.notNull() ) { - mCurImagep->draw(getLocalRect(), LLColor4::white % getDrawContext().mAlpha); + cur_image->draw(getLocalRect(), LLColor4::white % getDrawContext().mAlpha); } LLUICtrl::draw(); @@ -123,6 +96,6 @@ void LLLoadingIndicator::stop() void LLLoadingIndicator::start() { mImageSwitchTimer.start(); - F32 period = 1.0f / (Data::instance().getImagesCount() * mRotationsPerSec); + F32 period = 1.0f / (mImages.size() * mImagesPerSec); mImageSwitchTimer.setTimerExpirySec(period); } -- cgit v1.3 From c82219934dfc20d8e4401ed875f9c59c16ab922c Mon Sep 17 00:00:00 2001 From: Leslie Linden Date: Wed, 20 Apr 2011 17:30:06 -0700 Subject: mac and linux build fixes --- indra/llui/llloadingindicator.cpp | 2 +- indra/llxuixml/llinitparam.h | 53 +++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 25 deletions(-) (limited to 'indra/llui/llloadingindicator.cpp') diff --git a/indra/llui/llloadingindicator.cpp b/indra/llui/llloadingindicator.cpp index 8a0f875808..c4eec1835c 100644 --- a/indra/llui/llloadingindicator.cpp +++ b/indra/llui/llloadingindicator.cpp @@ -77,7 +77,7 @@ void LLLoadingIndicator::draw() start(); } - LLUIImagePtr cur_image = mImages.empty() ? NULL : mImages[mCurImageIdx]; + LLUIImagePtr cur_image = mImages.empty() ? LLUIImagePtr(NULL) : mImages[mCurImageIdx]; // Draw current image. if( cur_image.notNull() ) diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index 39ba32e537..858f8405b4 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -100,7 +100,7 @@ namespace LLInitParam class TypeValuesHelper { public: - typedef std::map value_name_map_t; + typedef typename std::map value_name_map_t; //TODO: cache key by index to save on param block size void setValueName(const std::string& value_name) @@ -121,7 +121,7 @@ namespace LLInitParam static bool getValueFromName(const std::string& name, T& value) { value_name_map_t* map = getValueNames(); - value_name_map_t::iterator found_it = map->find(name); + typename value_name_map_t::iterator found_it = map->find(name); if (found_it == map->end()) return false; value = found_it->second; @@ -151,7 +151,7 @@ namespace LLInitParam static std::vector sValues; value_name_map_t* map = getValueNames(); - for (value_name_map_t::iterator it = map->begin(), end_it = map->end(); + for (typename value_name_map_t::iterator it = map->begin(), end_it = map->end(); it != end_it; ++it) { @@ -598,6 +598,7 @@ namespace LLInitParam typedef const T& value_assignment_t; typedef TypedParam self_t; typedef NAME_VALUE_LOOKUP name_value_lookup_t; + typedef ParamValue param_value_t; TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) : Param(block_descriptor.mCurrentBlockPtr) @@ -704,7 +705,7 @@ namespace LLInitParam void set(value_assignment_t val, bool flag_as_provided = true) { setValue(val); - clearValueName(); + param_value_t::clearValueName(); setProvided(flag_as_provided); Param::enclosingBlock().paramChanged(*this, flag_as_provided); } @@ -718,9 +719,9 @@ namespace LLInitParam } // implicit conversion - operator value_assignment_t() const { return getValue(); } + operator value_assignment_t() const { return param_value_t::getValue(); } // explicit conversion - value_assignment_t operator()() const { return getValue(); } + value_assignment_t operator()() const { return param_value_t::getValue(); } protected: @@ -752,10 +753,11 @@ namespace LLInitParam typedef value_const_t& value_assignment_t; typedef TypedParam self_t; typedef NAME_VALUE_LOOKUP name_value_lookup_t; + typedef ParamValue param_value_t; TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) : Param(block_descriptor.mCurrentBlockPtr), - ParamValue(value) + param_value_t(value) { if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { @@ -840,23 +842,23 @@ namespace LLInitParam bool isProvided() const { // only validate block when it hasn't already passed validation with current data - if (Param::anyProvided() && mValidatedVersion < getLastChangeVersion()) + if (Param::anyProvided() && param_value_t::mValidatedVersion < param_value_t::getLastChangeVersion()) { // a sub-block is "provided" when it has been filled in enough to be valid - mValidated = validateBlock(false); - mValidatedVersion = getLastChangeVersion(); + param_value_t::mValidated = param_value_t::validateBlock(false); + param_value_t::mValidatedVersion = param_value_t::getLastChangeVersion(); } - return Param::anyProvided() && mValidated; + return Param::anyProvided() && param_value_t::mValidated; } // assign block contents to this param-that-is-a-block void set(value_assignment_t val, bool flag_as_provided = true) { setValue(val); - clearValueName(); + param_value_t::clearValueName(); // force revalidation of block by clearing known provided version // next call to isProvided() will update provision status based on validity - mValidatedVersion = -1; + param_value_t::mValidatedVersion = -1; setProvided(flag_as_provided); Param::enclosingBlock().paramChanged(*this, flag_as_provided); } @@ -883,9 +885,9 @@ namespace LLInitParam } // implicit conversion - operator value_assignment_t() const { return getValue(); } + operator value_assignment_t() const { return param_value_t::getValue(); } // explicit conversion - value_assignment_t operator()() const { return getValue(); } + value_assignment_t operator()() const { return param_value_t::getValue(); } protected: @@ -897,7 +899,7 @@ namespace LLInitParam if (src_typed_param.isProvided() && (overwrite || !dst_typed_param.isProvided())) { - if (dst_typed_param.merge(selfBlockDescriptor(), src_typed_param, overwrite)) + if (dst_typed_param.merge(param_value_t::selfBlockDescriptor(), src_typed_param, overwrite)) { dst_typed_param.clearValueName(); return true; @@ -914,14 +916,15 @@ namespace LLInitParam { public: typedef TypedParam self_t; - typedef typename std::vector > container_t; + typedef ParamValue param_value_t; + typedef typename std::vector container_t; typedef const container_t& value_assignment_t; typedef VALUE_TYPE value_t; typedef NAME_VALUE_LOOKUP name_value_lookup_t; TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) - : Param(block_descriptor.mCurrentBlockPtr), + : Param(block_descriptor.mCurrentBlockPtr) { std::copy(value.begin(), value.end(), std::back_inserter(mValues)); @@ -1033,7 +1036,7 @@ namespace LLInitParam value_t& add() { - mValues.push_back(ParamValue(value_t())); + mValues.push_back(param_value_t(value_t())); setProvided(true); Param::enclosingBlock().paramChanged(*this, true); return mValues.back(); @@ -1041,7 +1044,7 @@ namespace LLInitParam void add(const value_t& item) { - mValues.push_back(ParamValue(item)); + mValues.push_back(param_value_t(item)); setProvided(true); Param::enclosingBlock().paramChanged(*this, true); } @@ -1567,6 +1570,7 @@ namespace LLInitParam typedef TypedParam::value> super_t; typedef Batch self_t; typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::value_t value_t; struct BatchDefaultValue : public ParamDescriptor::UserData { @@ -1589,7 +1593,7 @@ namespace LLInitParam if (param_descriptorp) { param_descriptorp->mDeserializeFunc = &deserializeParam; - param_descriptorp->mUserData = new BatchDefaultValue(new _value_t(val)); + param_descriptorp->mUserData = new BatchDefaultValue(new param_value_t(val)); } } } @@ -1707,7 +1711,7 @@ namespace LLInitParam typedef ParamValue > derived_t; typedef CustomParamValue self_t; - typedef Block block_t; + typedef Block block_t; typedef const T& value_assignment_t; CustomParamValue(const T& value = T()) @@ -1796,7 +1800,7 @@ namespace LLInitParam if (block_t::validateBlock(emit_errors)) { // clear stale keyword associated with old value - clearValueName(); + TypeValues::clearValueName(); mValueAge = BLOCK_AUTHORITATIVE; static_cast(const_cast(this))->updateValueFromBlock(); return true; @@ -1828,10 +1832,11 @@ namespace LLInitParam void setValue(value_assignment_t val) { + derived_t& typed_param = static_cast(*this); // set param version number to be up to date, so we ignore block contents mValueAge = VALUE_AUTHORITATIVE; mValue = val; - clearValueName(); + typed_param.clearValueName(); static_cast(const_cast(this))->updateBlockFromValue(); } -- cgit v1.3