PageRenderTime 55ms CodeModel.GetById 27ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/lliconctrl.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 121 lines | 75 code | 16 blank | 30 comment | 10 complexity | fd643af34d8c86d871de0a1fd3676412 MD5 | raw file
  1/** 
  2 * @file lliconctrl.cpp
  3 * @brief LLIconCtrl base class
  4 *
  5 * $LicenseInfo:firstyear=2001&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 "lliconctrl.h"
 30
 31// Linden library includes 
 32
 33// Project includes
 34#include "llcontrol.h"
 35#include "llui.h"
 36#include "lluictrlfactory.h"
 37#include "lluiimage.h"
 38
 39static LLDefaultChildRegistry::Register<LLIconCtrl> r("icon");
 40
 41LLIconCtrl::Params::Params()
 42:	image("image_name"),
 43	color("color"),
 44	use_draw_context_alpha("use_draw_context_alpha", true),
 45	scale_image("scale_image")
 46{}
 47
 48LLIconCtrl::LLIconCtrl(const LLIconCtrl::Params& p)
 49:	LLUICtrl(p),
 50	mColor(p.color()),
 51	mImagep(p.image),
 52	mUseDrawContextAlpha(p.use_draw_context_alpha),
 53	mPriority(0),
 54	mDrawWidth(0),
 55	mDrawHeight(0)
 56{
 57	if (mImagep.notNull())
 58	{
 59		LLUICtrl::setValue(mImagep->getName());
 60	}
 61}
 62
 63LLIconCtrl::~LLIconCtrl()
 64{
 65	mImagep = NULL;
 66}
 67
 68
 69void LLIconCtrl::draw()
 70{
 71	if( mImagep.notNull() )
 72	{
 73		const F32 alpha = mUseDrawContextAlpha ? getDrawContext().mAlpha : getCurrentTransparency();
 74		mImagep->draw(getLocalRect(), mColor.get() % alpha );
 75	}
 76
 77	LLUICtrl::draw();
 78}
 79
 80// virtual
 81// value might be a string or a UUID
 82void LLIconCtrl::setValue(const LLSD& value )
 83{
 84	LLSD tvalue(value);
 85	if (value.isString() && LLUUID::validate(value.asString()))
 86	{
 87		//RN: support UUIDs masquerading as strings
 88		tvalue = LLSD(LLUUID(value.asString()));
 89	}
 90	LLUICtrl::setValue(tvalue);
 91	if (tvalue.isUUID())
 92	{
 93		mImagep = LLUI::getUIImageByID(tvalue.asUUID(), mPriority);
 94	}
 95	else
 96	{
 97		mImagep = LLUI::getUIImage(tvalue.asString(), mPriority);
 98	}
 99
100	setIconImageDrawSize();
101}
102
103std::string LLIconCtrl::getImageName() const
104{
105	if (getValue().isString())
106		return getValue().asString();
107	else
108		return std::string();
109}
110
111void LLIconCtrl::setIconImageDrawSize()
112{
113	if(mImagep.notNull() && mDrawWidth && mDrawHeight)
114	{
115		if(mImagep->getImage().notNull())
116		{
117			mImagep->getImage()->setKnownDrawSize(mDrawWidth, mDrawHeight) ;
118		}
119	}
120}
121