PageRenderTime 52ms CodeModel.GetById 39ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llui/lluiimage.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 199 lines | 140 code | 25 blank | 34 comment | 25 complexity | af3bcf41039fe042d5810f33c635d6af MD5 | raw file
  1/** 
  2 * @file lluiimage.cpp
  3 * @brief UI implementation
  4 *
  5 * $LicenseInfo:firstyear=2007&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// Utilities functions the user interface needs
 28
 29//#include "llviewerprecompiledheaders.h"
 30#include "linden_common.h"
 31
 32// Project includes
 33#include "lluiimage.h"
 34#include "llui.h"
 35
 36LLUIImage::LLUIImage(const std::string& name, LLPointer<LLTexture> image)
 37:	mName(name),
 38	mImage(image),
 39	mScaleRegion(0.f, 1.f, 1.f, 0.f),
 40	mClipRegion(0.f, 1.f, 1.f, 0.f),
 41	mUniformScaling(TRUE),
 42	mNoClip(TRUE),
 43	mImageLoaded(NULL)
 44{
 45}
 46
 47LLUIImage::~LLUIImage()
 48{
 49	delete mImageLoaded;
 50}
 51
 52void LLUIImage::setClipRegion(const LLRectf& region) 
 53{ 
 54	mClipRegion = region; 
 55	mNoClip = mClipRegion.mLeft == 0.f
 56				&& mClipRegion.mRight == 1.f
 57				&& mClipRegion.mBottom == 0.f
 58				&& mClipRegion.mTop == 1.f;
 59}
 60
 61void LLUIImage::setScaleRegion(const LLRectf& region) 
 62{ 
 63	mScaleRegion = region; 
 64	mUniformScaling = mScaleRegion.mLeft == 0.f
 65					&& mScaleRegion.mRight == 1.f
 66					&& mScaleRegion.mBottom == 0.f
 67					&& mScaleRegion.mTop == 1.f;
 68}
 69
 70//TODO: move drawing implementation inside class
 71void LLUIImage::draw(S32 x, S32 y, const LLColor4& color) const
 72{
 73	gl_draw_scaled_image(x, y, getWidth(), getHeight(), mImage, color, mClipRegion);
 74}
 75
 76void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const
 77{
 78	if (mUniformScaling)
 79	{
 80		gl_draw_scaled_image(x, y, width, height, mImage, color, mClipRegion);
 81	}
 82	else
 83	{
 84		gl_draw_scaled_image_with_border(
 85			x, y, 
 86			width, height, 
 87			mImage, 
 88			color,
 89			FALSE,
 90			mClipRegion,
 91			mScaleRegion);
 92	}
 93}
 94
 95void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const
 96{
 97	gl_draw_scaled_image_with_border(
 98		x, y, 
 99		width, height, 
100		mImage, 
101		color, 
102		TRUE,
103		mClipRegion,
104		mScaleRegion);
105}
106
107void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const
108{
109	LLRect border_rect;
110	border_rect.setOriginAndSize(x, y, width, height);
111	border_rect.stretch(border_width, border_width);
112	drawSolid(border_rect, color);
113}
114
115S32 LLUIImage::getWidth() const
116{ 
117	// return clipped dimensions of actual image area
118	return llround((F32)mImage->getWidth(0) * mClipRegion.getWidth()); 
119}
120
121S32 LLUIImage::getHeight() const
122{ 
123	// return clipped dimensions of actual image area
124	return llround((F32)mImage->getHeight(0) * mClipRegion.getHeight()); 
125}
126
127S32 LLUIImage::getTextureWidth() const
128{
129	return mImage->getWidth(0);
130}
131
132S32 LLUIImage::getTextureHeight() const
133{
134	return mImage->getHeight(0);
135}
136
137boost::signals2::connection LLUIImage::addLoadedCallback( const image_loaded_signal_t::slot_type& cb ) 
138{
139	if (!mImageLoaded) 
140	{
141		mImageLoaded = new image_loaded_signal_t();
142	}
143	return mImageLoaded->connect(cb);
144}
145
146
147void LLUIImage::onImageLoaded()
148{
149	if (mImageLoaded)
150	{
151		(*mImageLoaded)();
152	}
153}
154
155
156namespace LLInitParam
157{
158	void ParamValue<LLUIImage*, TypeValues<LLUIImage*> >::updateValueFromBlock()
159	{
160		// The keyword "none" is specifically requesting a null image
161		// do not default to current value. Used to overwrite template images. 
162		if (name() == "none")
163		{
164			updateValue(NULL);
165			return;
166		}
167
168		LLUIImage* imagep =  LLUI::getUIImage(name());
169		if (imagep)
170		{
171			updateValue(imagep);
172		}
173	}
174	
175	void ParamValue<LLUIImage*, TypeValues<LLUIImage*> >::updateBlockFromValue(bool make_block_authoritative)
176	{
177		if (getValue() == NULL)
178		{
179			name.set("none", make_block_authoritative);
180		}
181		else
182		{
183			name.set(getValue()->getName(), make_block_authoritative);
184		}
185	}
186
187	
188	bool ParamCompare<LLUIImage*, false>::equals(
189		LLUIImage* const &a,
190		LLUIImage* const &b)
191	{
192		// force all LLUIImages for XML UI export to be "non-default"
193		if (!a && !b)
194			return false;
195		else
196			return (a == b);
197	}
198}
199