diff options
author | Vadim Savchuk <vsavchuk@productengine.com> | 2010-04-27 16:39:19 +0300 |
---|---|---|
committer | Vadim Savchuk <vsavchuk@productengine.com> | 2010-04-27 16:39:19 +0300 |
commit | 17f2234a96d11a78726a77285b77dd25721ab8ce (patch) | |
tree | 92c2ca6483a9744c92c551a143d8ff8c55d31f4a /indra/llui | |
parent | 2696e375097c2e45102bede0e7d33175feea080b (diff) |
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
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | indra/llui/llloadingindicator.cpp | 135 | ||||
-rw-r--r-- | indra/llui/llloadingindicator.h | 93 | ||||
-rw-r--r-- | indra/llui/llui.cpp | 4 | ||||
-rw-r--r-- | indra/llui/lluifwd.h | 1 |
5 files changed, 235 insertions, 0 deletions
diff --git a/indra/llui/CMakeLists.txt b/indra/llui/CMakeLists.txt index 532b6b6524..3ecab90756 100644 --- a/indra/llui/CMakeLists.txt +++ b/indra/llui/CMakeLists.txt @@ -52,6 +52,7 @@ set(llui_SOURCE_FILES llkeywords.cpp lllayoutstack.cpp lllineeditor.cpp + llloadingindicator.cpp lllocalcliprect.cpp llmenubutton.cpp llmenugl.cpp @@ -144,6 +145,7 @@ set(llui_HEADER_FILES lllayoutstack.h lllazyvalue.h lllineeditor.h + llloadingindicator.h lllocalcliprect.h llmenubutton.h llmenugl.h 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<LLLoadingIndicator> r("loading_indicator"); + +/////////////////////////////////////////////////////////////////////////////// +// LLLoadingIndicator::Data class +/////////////////////////////////////////////////////////////////////////////// + +/** + * Pre-loaded images shared by all instances of the widget + */ +class LLLoadingIndicator::Data: public LLSingleton<LLLoadingIndicator::Data> +{ +public: + /*virtual*/ void initSingleton(); // from LLSingleton + + LLPointer<LLUIImage> getNextImage(S8& idx) const; + U8 getImagesCount() const { return NIMAGES; } +private: + + static const U8 NIMAGES = 12; + LLPointer<LLUIImage> 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<LLUIImage> 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); +} diff --git a/indra/llui/llloadingindicator.h b/indra/llui/llloadingindicator.h new file mode 100644 index 0000000000..32dd1fead8 --- /dev/null +++ b/indra/llui/llloadingindicator.h @@ -0,0 +1,93 @@ +/** + * @file llloadingindicator.h + * @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$ + */ + +#ifndef LL_LLLOADINGINDICATOR_H +#define LL_LLLOADINGINDICATOR_H + +#include "lluictrl.h" + +/////////////////////////////////////////////////////////////////////////////// +// class LLLoadingIndicator +/////////////////////////////////////////////////////////////////////////////// + +/** + * Perpetual loading indicator (a la MacOSX or YouTube) + * + * Number of rotations per second can be overriden + * with the "roations_per_sec" parameter. + * + * Can start/stop spinning. + * + * @see start() + * @see stop() + */ +class LLLoadingIndicator +: public LLUICtrl +{ + LOG_CLASS(LLLoadingIndicator); +public: + struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> + { + Optional<F32> rotations_per_sec; + Params() + : rotations_per_sec("rotations_per_sec", 1.0f) + {} + }; + + virtual ~LLLoadingIndicator() {} + + // llview overrides + virtual void draw(); + + /** + * Stop spinning. + */ + void stop(); + + /** + * Start spinning. + */ + void start(); + +private: + LLLoadingIndicator(const Params&); + friend class LLUICtrlFactory; + + class Data; + + F32 mRotationsPerSec; + S8 mCurImageIdx; + LLPointer<LLUIImage> mCurImagep; + LLFrameTimer mImageSwitchTimer; +}; + +#endif // LL_LLLOADINGINDICATOR_H diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index f9a4ed7285..bf12384a28 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -56,6 +56,7 @@ #include "llfloaterreg.h" #include "llmenugl.h" #include "llmenubutton.h" +#include "llloadingindicator.h" #include "llwindow.h" // for registration @@ -94,7 +95,10 @@ std::list<std::string> gUntranslated; static LLDefaultChildRegistry::Register<LLFilterEditor> register_filter_editor("filter_editor"); static LLDefaultChildRegistry::Register<LLFlyoutButton> register_flyout_button("flyout_button"); static LLDefaultChildRegistry::Register<LLSearchEditor> register_search_editor("search_editor"); + +// register other widgets which otherwise may not be linked in static LLDefaultChildRegistry::Register<LLMenuButton> register_menu_button("menu_button"); +static LLDefaultChildRegistry::Register<LLLoadingIndicator> register_loading_indicator("loading_indicator"); // diff --git a/indra/llui/lluifwd.h b/indra/llui/lluifwd.h index f99bb39fdd..d6047b943c 100644 --- a/indra/llui/lluifwd.h +++ b/indra/llui/lluifwd.h @@ -39,6 +39,7 @@ class LLComboBox; class LLDragHandle; class LLFloater; class LLIconCtrl; +class LLLoadingIndicator; class LLLineEditor; class LLMenuGL; class LLPanel; |