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 --- .../integration_tests/llui_libtest/llwidgetreg.cpp | 2 + indra/llui/CMakeLists.txt | 2 + indra/llui/llloadingindicator.cpp | 135 +++++++++++++++++++++ indra/llui/llloadingindicator.h | 93 ++++++++++++++ indra/llui/llui.cpp | 4 + indra/llui/lluifwd.h | 1 + .../skins/default/textures/icons/Progress_1.png | Bin 0 -> 464 bytes .../skins/default/textures/icons/Progress_10.png | Bin 0 -> 461 bytes .../skins/default/textures/icons/Progress_11.png | Bin 0 -> 471 bytes .../skins/default/textures/icons/Progress_12.png | Bin 0 -> 457 bytes .../skins/default/textures/icons/Progress_2.png | Bin 0 -> 461 bytes .../skins/default/textures/icons/Progress_3.png | Bin 0 -> 487 bytes .../skins/default/textures/icons/Progress_4.png | Bin 0 -> 466 bytes .../skins/default/textures/icons/Progress_5.png | Bin 0 -> 477 bytes .../skins/default/textures/icons/Progress_6.png | Bin 0 -> 460 bytes .../skins/default/textures/icons/Progress_7.png | Bin 0 -> 483 bytes .../skins/default/textures/icons/Progress_8.png | Bin 0 -> 467 bytes .../skins/default/textures/icons/Progress_9.png | Bin 0 -> 483 bytes indra/newview/skins/default/textures/textures.xml | 13 ++ .../default/xui/en/widgets/loading_indicator.xml | 8 ++ 20 files changed, 258 insertions(+) create mode 100644 indra/llui/llloadingindicator.cpp create mode 100644 indra/llui/llloadingindicator.h create mode 100644 indra/newview/skins/default/textures/icons/Progress_1.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_10.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_11.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_12.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_2.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_3.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_4.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_5.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_6.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_7.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_8.png create mode 100644 indra/newview/skins/default/textures/icons/Progress_9.png create mode 100644 indra/newview/skins/default/xui/en/widgets/loading_indicator.xml diff --git a/indra/integration_tests/llui_libtest/llwidgetreg.cpp b/indra/integration_tests/llui_libtest/llwidgetreg.cpp index c6e2e79a09..57c39243fb 100644 --- a/indra/integration_tests/llui_libtest/llwidgetreg.cpp +++ b/indra/integration_tests/llui_libtest/llwidgetreg.cpp @@ -37,6 +37,7 @@ #include "llcombobox.h" #include "llcontainerview.h" #include "lliconctrl.h" +#include "llloadingindicator.h" #include "llmenubutton.h" #include "llmenugl.h" #include "llmultislider.h" @@ -72,6 +73,7 @@ void LLWidgetReg::initClass(bool register_widgets) LLDefaultChildRegistry::Register flyout_button("flyout_button"); LLDefaultChildRegistry::Register container_view("container_view"); LLDefaultChildRegistry::Register icon("icon"); + LLDefaultChildRegistry::Register loading_indicator("loading_indicator"); LLDefaultChildRegistry::Register line_editor("line_editor"); LLDefaultChildRegistry::Register menu_item_separator("menu_item_separator"); LLDefaultChildRegistry::Register menu_item_call_gl("menu_item_call"); 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 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); +} 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 + { + Optional 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 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 gUntranslated; static LLDefaultChildRegistry::Register register_filter_editor("filter_editor"); static LLDefaultChildRegistry::Register register_flyout_button("flyout_button"); static LLDefaultChildRegistry::Register register_search_editor("search_editor"); + +// register other widgets which otherwise may not be linked in static LLDefaultChildRegistry::Register register_menu_button("menu_button"); +static LLDefaultChildRegistry::Register 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; diff --git a/indra/newview/skins/default/textures/icons/Progress_1.png b/indra/newview/skins/default/textures/icons/Progress_1.png new file mode 100644 index 0000000000..58b56003c4 Binary files /dev/null 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 new file mode 100644 index 0000000000..07fe0be8a3 Binary files /dev/null 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 new file mode 100644 index 0000000000..215d68cc46 Binary files /dev/null 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 new file mode 100644 index 0000000000..d755588621 Binary files /dev/null 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 new file mode 100644 index 0000000000..6640ee227b Binary files /dev/null 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 new file mode 100644 index 0000000000..5decbe977e Binary files /dev/null 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 new file mode 100644 index 0000000000..56e81c17aa Binary files /dev/null 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 new file mode 100644 index 0000000000..a89bf2ac62 Binary files /dev/null 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 new file mode 100644 index 0000000000..233c479540 Binary files /dev/null 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 new file mode 100644 index 0000000000..631d7a6819 Binary files /dev/null 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 new file mode 100644 index 0000000000..ac0e3f13f7 Binary files /dev/null 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 new file mode 100644 index 0000000000..17fb4a0335 Binary files /dev/null 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 84a99ba92a..1080ff347c 100644 --- a/indra/newview/skins/default/textures/textures.xml +++ b/indra/newview/skins/default/textures/textures.xml @@ -580,4 +580,17 @@ with the same filename but different name + + + + + + + + + + + + + diff --git a/indra/newview/skins/default/xui/en/widgets/loading_indicator.xml b/indra/newview/skins/default/xui/en/widgets/loading_indicator.xml new file mode 100644 index 0000000000..6040d24128 --- /dev/null +++ b/indra/newview/skins/default/xui/en/widgets/loading_indicator.xml @@ -0,0 +1,8 @@ + + -- cgit v1.2.3