PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llprogressbar.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 87 lines | 49 code | 13 blank | 25 comment | 0 complexity | bddb94abd3f5710ecfbc48e3e76a14e4 MD5 | raw file
 1/** 
 2 * @file llprogressbar.cpp
 3 * @brief LLProgressBar class implementation
 4 *
 5 * $LicenseInfo:firstyear=2002&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 "llprogressbar.h"
30
31#include "indra_constants.h"
32#include "llmath.h"
33#include "llgl.h"
34#include "llui.h"
35#include "llfontgl.h"
36#include "lltimer.h"
37#include "llglheaders.h"
38
39#include "llfocusmgr.h"
40#include "lluictrlfactory.h"
41#include "lluiimage.h"
42
43static LLDefaultChildRegistry::Register<LLProgressBar> r("progress_bar");
44
45LLProgressBar::Params::Params()
46:	image_bar("image_bar"),
47	image_fill("image_fill"),
48	color_bar("color_bar"),
49	color_bg("color_bg")
50{}
51
52
53LLProgressBar::LLProgressBar(const LLProgressBar::Params& p) 
54:	LLUICtrl(p),
55	mImageBar(p.image_bar),
56	mImageFill(p.image_fill),
57	mColorBackground(p.color_bg()),
58	mColorBar(p.color_bar()),
59	mPercentDone(0.f)
60{}
61
62LLProgressBar::~LLProgressBar()
63{
64	gFocusMgr.releaseFocusIfNeeded( this );
65}
66
67void LLProgressBar::draw()
68{
69	static LLTimer timer;
70	F32 alpha = getDrawContext().mAlpha;
71	
72	LLColor4 image_bar_color = mColorBackground.get();
73	image_bar_color.setAlpha(alpha);
74	mImageBar->draw(getLocalRect(), image_bar_color);
75
76	alpha *= 0.5f + 0.5f*0.5f*(1.f + (F32)sin(3.f*timer.getElapsedTimeF32()));
77	LLColor4 bar_color = mColorBar.get();
78	bar_color.mV[VALPHA] *= alpha; // modulate alpha
79	LLRect progress_rect = getLocalRect();
80	progress_rect.mRight = llround(getRect().getWidth() * (mPercentDone / 100.f));
81	mImageFill->draw(progress_rect, bar_color);
82}
83
84void LLProgressBar::setValue(const LLSD& value)
85{
86	mPercentDone = llclamp((F32)value.asReal(), 0.f, 100.f);
87}