PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llloadingindicator.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 100 lines | 47 code | 16 blank | 37 comment | 4 complexity | 9b244a685691f4eea8a3a8d56860ebe3 MD5 | raw file
  1/** 
  2 * @file llloadingindicator.cpp
  3 * @brief Perpetual loading indicator
  4 *
  5 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29#include "llloadingindicator.h"
 30
 31// Linden library includes
 32#include "llsingleton.h"
 33
 34// Project includes
 35#include "lluictrlfactory.h"
 36#include "lluiimage.h"
 37#include "boost/foreach.hpp"
 38
 39// registered in llui.cpp to avoid being left out by MS linker
 40//static LLDefaultChildRegistry::Register<LLLoadingIndicator> r("loading_indicator");
 41
 42///////////////////////////////////////////////////////////////////////////////
 43// LLLoadingIndicator class
 44///////////////////////////////////////////////////////////////////////////////
 45
 46LLLoadingIndicator::LLLoadingIndicator(const Params& p)
 47:	LLUICtrl(p), 
 48	mImagesPerSec(p.images_per_sec > 0 ? p.images_per_sec : 1.0f), 
 49	mCurImageIdx(0)
 50{
 51}
 52
 53void LLLoadingIndicator::initFromParams(const Params& p)
 54{
 55	BOOST_FOREACH(LLUIImage* image, p.images.image)
 56	{
 57		mImages.push_back(image);
 58	}
 59
 60	// Start timer for switching images.
 61	start();
 62}
 63
 64void LLLoadingIndicator::draw()
 65{
 66	// Time to switch to the next image?
 67	if (mImageSwitchTimer.getStarted() && mImageSwitchTimer.hasExpired())
 68	{
 69		// Switch to the next image.
 70		if (!mImages.empty())
 71		{
 72			mCurImageIdx = (mCurImageIdx + 1) % mImages.size();
 73		}
 74
 75		// Restart timer.
 76		start();
 77	}
 78
 79	LLUIImagePtr cur_image = mImages.empty() ? LLUIImagePtr(NULL) : mImages[mCurImageIdx];
 80
 81	// Draw current image.
 82	if( cur_image.notNull() )
 83	{
 84		cur_image->draw(getLocalRect(), LLColor4::white % getDrawContext().mAlpha);
 85	}
 86
 87	LLUICtrl::draw();
 88}
 89
 90void LLLoadingIndicator::stop()
 91{
 92	mImageSwitchTimer.stop();
 93}
 94
 95void LLLoadingIndicator::start()
 96{
 97	mImageSwitchTimer.start();
 98	F32 period = 1.0f / (mImages.size() * mImagesPerSec);
 99	mImageSwitchTimer.setTimerExpirySec(period);
100}