Skip to content
Snippets Groups Projects
Commit 17f2234a authored by Vadim Savchuk's avatar Vadim Savchuk
Browse files

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
parent 2696e375
No related branches found
No related tags found
No related merge requests found
Showing
with 258 additions and 0 deletions
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "llcombobox.h" #include "llcombobox.h"
#include "llcontainerview.h" #include "llcontainerview.h"
#include "lliconctrl.h" #include "lliconctrl.h"
#include "llloadingindicator.h"
#include "llmenubutton.h" #include "llmenubutton.h"
#include "llmenugl.h" #include "llmenugl.h"
#include "llmultislider.h" #include "llmultislider.h"
...@@ -72,6 +73,7 @@ void LLWidgetReg::initClass(bool register_widgets) ...@@ -72,6 +73,7 @@ void LLWidgetReg::initClass(bool register_widgets)
LLDefaultChildRegistry::Register<LLFlyoutButton> flyout_button("flyout_button"); LLDefaultChildRegistry::Register<LLFlyoutButton> flyout_button("flyout_button");
LLDefaultChildRegistry::Register<LLContainerView> container_view("container_view"); LLDefaultChildRegistry::Register<LLContainerView> container_view("container_view");
LLDefaultChildRegistry::Register<LLIconCtrl> icon("icon"); LLDefaultChildRegistry::Register<LLIconCtrl> icon("icon");
LLDefaultChildRegistry::Register<LLLoadingIndicator> loading_indicator("loading_indicator");
LLDefaultChildRegistry::Register<LLLineEditor> line_editor("line_editor"); LLDefaultChildRegistry::Register<LLLineEditor> line_editor("line_editor");
LLDefaultChildRegistry::Register<LLMenuItemSeparatorGL> menu_item_separator("menu_item_separator"); LLDefaultChildRegistry::Register<LLMenuItemSeparatorGL> menu_item_separator("menu_item_separator");
LLDefaultChildRegistry::Register<LLMenuItemCallGL> menu_item_call_gl("menu_item_call"); LLDefaultChildRegistry::Register<LLMenuItemCallGL> menu_item_call_gl("menu_item_call");
......
...@@ -52,6 +52,7 @@ set(llui_SOURCE_FILES ...@@ -52,6 +52,7 @@ set(llui_SOURCE_FILES
llkeywords.cpp llkeywords.cpp
lllayoutstack.cpp lllayoutstack.cpp
lllineeditor.cpp lllineeditor.cpp
llloadingindicator.cpp
lllocalcliprect.cpp lllocalcliprect.cpp
llmenubutton.cpp llmenubutton.cpp
llmenugl.cpp llmenugl.cpp
...@@ -144,6 +145,7 @@ set(llui_HEADER_FILES ...@@ -144,6 +145,7 @@ set(llui_HEADER_FILES
lllayoutstack.h lllayoutstack.h
lllazyvalue.h lllazyvalue.h
lllineeditor.h lllineeditor.h
llloadingindicator.h
lllocalcliprect.h lllocalcliprect.h
llmenubutton.h llmenubutton.h
llmenugl.h llmenugl.h
......
/**
* @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);
}
/**
* @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
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "llfloaterreg.h" #include "llfloaterreg.h"
#include "llmenugl.h" #include "llmenugl.h"
#include "llmenubutton.h" #include "llmenubutton.h"
#include "llloadingindicator.h"
#include "llwindow.h" #include "llwindow.h"
// for registration // for registration
...@@ -94,7 +95,10 @@ std::list<std::string> gUntranslated; ...@@ -94,7 +95,10 @@ std::list<std::string> gUntranslated;
static LLDefaultChildRegistry::Register<LLFilterEditor> register_filter_editor("filter_editor"); static LLDefaultChildRegistry::Register<LLFilterEditor> register_filter_editor("filter_editor");
static LLDefaultChildRegistry::Register<LLFlyoutButton> register_flyout_button("flyout_button"); static LLDefaultChildRegistry::Register<LLFlyoutButton> register_flyout_button("flyout_button");
static LLDefaultChildRegistry::Register<LLSearchEditor> register_search_editor("search_editor"); 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<LLMenuButton> register_menu_button("menu_button");
static LLDefaultChildRegistry::Register<LLLoadingIndicator> register_loading_indicator("loading_indicator");
// //
......
...@@ -39,6 +39,7 @@ class LLComboBox; ...@@ -39,6 +39,7 @@ class LLComboBox;
class LLDragHandle; class LLDragHandle;
class LLFloater; class LLFloater;
class LLIconCtrl; class LLIconCtrl;
class LLLoadingIndicator;
class LLLineEditor; class LLLineEditor;
class LLMenuGL; class LLMenuGL;
class LLPanel; class LLPanel;
......
indra/newview/skins/default/textures/icons/Progress_1.png

464 B

indra/newview/skins/default/textures/icons/Progress_10.png

461 B

indra/newview/skins/default/textures/icons/Progress_11.png

471 B

indra/newview/skins/default/textures/icons/Progress_12.png

457 B

indra/newview/skins/default/textures/icons/Progress_2.png

461 B

indra/newview/skins/default/textures/icons/Progress_3.png

487 B

indra/newview/skins/default/textures/icons/Progress_4.png

466 B

indra/newview/skins/default/textures/icons/Progress_5.png

477 B

indra/newview/skins/default/textures/icons/Progress_6.png

460 B

indra/newview/skins/default/textures/icons/Progress_7.png

483 B

indra/newview/skins/default/textures/icons/Progress_8.png

467 B

indra/newview/skins/default/textures/icons/Progress_9.png

483 B

...@@ -580,4 +580,17 @@ with the same filename but different name ...@@ -580,4 +580,17 @@ with the same filename but different name
<texture name="default_profile_picture.j2c" /> <texture name="default_profile_picture.j2c" />
<texture name="locked_image.j2c" /> <texture name="locked_image.j2c" />
<texture name="Progress_1" file_name="icons/Progress_1.png" preload="false" />
<texture name="Progress_2" file_name="icons/Progress_2.png" preload="false" />
<texture name="Progress_3" file_name="icons/Progress_3.png" preload="false" />
<texture name="Progress_4" file_name="icons/Progress_4.png" preload="false" />
<texture name="Progress_5" file_name="icons/Progress_5.png" preload="false" />
<texture name="Progress_6" file_name="icons/Progress_6.png" preload="false" />
<texture name="Progress_7" file_name="icons/Progress_7.png" preload="false" />
<texture name="Progress_8" file_name="icons/Progress_8.png" preload="false" />
<texture name="Progress_9" file_name="icons/Progress_9.png" preload="false" />
<texture name="Progress_10" file_name="icons/Progress_10.png" preload="false" />
<texture name="Progress_11" file_name="icons/Progress_11.png" preload="false" />
<texture name="Progress_12" file_name="icons/Progress_12.png" preload="false" />
</textures> </textures>
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<loading_indicator
follows="left|top"
mouse_opaque="false"
name="loading_indicator"
rotations_per_sec="1.0"
tab_stop="false"
/>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment