From 17f2234a96d11a78726a77285b77dd25721ab8ce Mon Sep 17 00:00:00 2001 From: Vadim Savchuk Date: Tue, 27 Apr 2010 16:39:19 +0300 Subject: Implemented perpetual loading indicator widget (EXT-6596). Simple perpetual loading indicator a la MacOS X or YouTube. Implements spinning by changing pre-defined images. The images are hardcoded, shared by all instances of the widget. Number of rotations per second can be changed via params. Reviewed by Mike at https://codereview.productengine.com/secondlife/r/320/ --HG-- branch : product-engine --- indra/llui/llloadingindicator.cpp | 135 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 indra/llui/llloadingindicator.cpp (limited to 'indra/llui/llloadingindicator.cpp') diff --git a/indra/llui/llloadingindicator.cpp b/indra/llui/llloadingindicator.cpp new file mode 100644 index 0000000000..8dec6ea9df --- /dev/null +++ b/indra/llui/llloadingindicator.cpp @@ -0,0 +1,135 @@ +/** + * @file llloadingindicator.cpp + * @brief Perpetual loading indicator + * + * $LicenseInfo:firstyear=2010&license=viewergpl$ + * + * Copyright (c) 2010, Linden Research, Inc. + * + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llloadingindicator.h" + +// Linden library includes +#include "llsingleton.h" + +// Project includes +#include "lluictrlfactory.h" +#include "lluiimage.h" + +static LLDefaultChildRegistry::Register r("loading_indicator"); + +/////////////////////////////////////////////////////////////////////////////// +// LLLoadingIndicator::Data class +/////////////////////////////////////////////////////////////////////////////// + +/** + * Pre-loaded images shared by all instances of the widget + */ +class LLLoadingIndicator::Data: public LLSingleton +{ +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() +{ + // Load images. + for (U8 i = 0; i < NIMAGES; ++i) + { + std::string img_name = llformat("Progress_%d", i+1); + mImages[i] = LLUI::getUIImage(img_name, 0); + llassert(mImages[i]); + } +} + +LLPointer LLLoadingIndicator::Data::getNextImage(S8& idx) const +{ + // Actually selects previous image because + // current images seem to be in wrong order; + // performs array bounds checking. + idx = idx > 0 ? llmin(NIMAGES-1, idx-1) : NIMAGES-1; + 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(); +} + +void LLLoadingIndicator::draw() +{ + // Time to switch to the next image? + if (mImageSwitchTimer.getStarted() && mImageSwitchTimer.hasExpired()) + { + // Switch to the next image. + mCurImagep = Data::instance().getNextImage(mCurImageIdx); + + // Restart timer. + start(); + } + + // Draw current image. + if( mCurImagep.notNull() ) + { + mCurImagep->draw(getLocalRect(), LLColor4::white % getDrawContext().mAlpha); + } + + LLUICtrl::draw(); +} + +void LLLoadingIndicator::stop() +{ + mImageSwitchTimer.stop(); +} + +void LLLoadingIndicator::start() +{ + mImageSwitchTimer.start(); + F32 period = 1.0f / (Data::instance().getImagesCount() * mRotationsPerSec); + mImageSwitchTimer.setTimerExpirySec(period); +} -- cgit v1.3 From 7d78440d9d3052ac81cee77199bca0f5414f2805 Mon Sep 17 00:00:00 2001 From: Vadim Savchuk Date: Tue, 27 Apr 2010 22:35:54 +0300 Subject: Additional commit for EXT-6956 (Create perpetual loading indicator widget). - Made the indicator rotate clockwise (by flipping the images and reversing the order they're traversed). - The textures are now preloaded. Approved by Erica. --HG-- branch : product-engine --- indra/llui/llloadingindicator.cpp | 6 ++---- .../skins/default/textures/icons/Progress_1.png | Bin 464 -> 470 bytes .../skins/default/textures/icons/Progress_10.png | Bin 461 -> 461 bytes .../skins/default/textures/icons/Progress_11.png | Bin 471 -> 475 bytes .../skins/default/textures/icons/Progress_12.png | Bin 457 -> 455 bytes .../skins/default/textures/icons/Progress_2.png | Bin 461 -> 453 bytes .../skins/default/textures/icons/Progress_3.png | Bin 487 -> 454 bytes .../skins/default/textures/icons/Progress_4.png | Bin 466 -> 454 bytes .../skins/default/textures/icons/Progress_5.png | Bin 477 -> 468 bytes .../skins/default/textures/icons/Progress_6.png | Bin 460 -> 462 bytes .../skins/default/textures/icons/Progress_7.png | Bin 483 -> 469 bytes .../skins/default/textures/icons/Progress_8.png | Bin 467 -> 454 bytes .../skins/default/textures/icons/Progress_9.png | Bin 483 -> 469 bytes indra/newview/skins/default/textures/textures.xml | 24 ++++++++++----------- 14 files changed, 14 insertions(+), 16 deletions(-) (limited to 'indra/llui/llloadingindicator.cpp') diff --git a/indra/llui/llloadingindicator.cpp b/indra/llui/llloadingindicator.cpp index 8dec6ea9df..f8b029e19c 100644 --- a/indra/llui/llloadingindicator.cpp +++ b/indra/llui/llloadingindicator.cpp @@ -78,10 +78,8 @@ void LLLoadingIndicator::Data::initSingleton() LLPointer LLLoadingIndicator::Data::getNextImage(S8& idx) const { - // Actually selects previous image because - // current images seem to be in wrong order; - // performs array bounds checking. - idx = idx > 0 ? llmin(NIMAGES-1, idx-1) : NIMAGES-1; + // Calculate next index, performing array bounds checking. + idx = (idx >= NIMAGES || idx < 0) ? 0 : (idx + 1) % NIMAGES; return mImages[idx]; } diff --git a/indra/newview/skins/default/textures/icons/Progress_1.png b/indra/newview/skins/default/textures/icons/Progress_1.png index 58b56003c4..5d6efbfa2a 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_1.png and b/indra/newview/skins/default/textures/icons/Progress_1.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_10.png b/indra/newview/skins/default/textures/icons/Progress_10.png index 07fe0be8a3..28203324f1 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_10.png and b/indra/newview/skins/default/textures/icons/Progress_10.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_11.png b/indra/newview/skins/default/textures/icons/Progress_11.png index 215d68cc46..6b87be0c3f 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_11.png and b/indra/newview/skins/default/textures/icons/Progress_11.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_12.png b/indra/newview/skins/default/textures/icons/Progress_12.png index d755588621..089d58b090 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_12.png and b/indra/newview/skins/default/textures/icons/Progress_12.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_2.png b/indra/newview/skins/default/textures/icons/Progress_2.png index 6640ee227b..94cb73b1f7 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_2.png and b/indra/newview/skins/default/textures/icons/Progress_2.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_3.png b/indra/newview/skins/default/textures/icons/Progress_3.png index 5decbe977e..a04a5b5263 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_3.png and b/indra/newview/skins/default/textures/icons/Progress_3.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_4.png b/indra/newview/skins/default/textures/icons/Progress_4.png index 56e81c17aa..a467098d82 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_4.png and b/indra/newview/skins/default/textures/icons/Progress_4.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_5.png b/indra/newview/skins/default/textures/icons/Progress_5.png index a89bf2ac62..ea64f1d907 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_5.png and b/indra/newview/skins/default/textures/icons/Progress_5.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_6.png b/indra/newview/skins/default/textures/icons/Progress_6.png index 233c479540..fe4447935f 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_6.png and b/indra/newview/skins/default/textures/icons/Progress_6.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_7.png b/indra/newview/skins/default/textures/icons/Progress_7.png index 631d7a6819..64fa294771 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_7.png and b/indra/newview/skins/default/textures/icons/Progress_7.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_8.png b/indra/newview/skins/default/textures/icons/Progress_8.png index ac0e3f13f7..a1c9a7f2eb 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_8.png and b/indra/newview/skins/default/textures/icons/Progress_8.png differ diff --git a/indra/newview/skins/default/textures/icons/Progress_9.png b/indra/newview/skins/default/textures/icons/Progress_9.png index 17fb4a0335..f3e9723184 100644 Binary files a/indra/newview/skins/default/textures/icons/Progress_9.png and b/indra/newview/skins/default/textures/icons/Progress_9.png differ diff --git a/indra/newview/skins/default/textures/textures.xml b/indra/newview/skins/default/textures/textures.xml index 1080ff347c..bbb82d86b1 100644 --- a/indra/newview/skins/default/textures/textures.xml +++ b/indra/newview/skins/default/textures/textures.xml @@ -580,17 +580,17 @@ with the same filename but different name - - - - - - - - - - - - + + + + + + + + + + + + -- cgit v1.3