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

/indra/llui/lluiimage.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 124 lines | 74 code | 22 blank | 28 comment | 0 complexity | ad77bf428f0b4397f8f460af698fc27f MD5 | raw file
  1/** 
  2 * @file lluiimage.h
  3 * @brief wrapper for images used in the UI that handles smart scaling, etc.
  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#ifndef LL_LLUIIMAGE_H
 28#define LL_LLUIIMAGE_H
 29
 30#include "v4color.h"
 31#include "llpointer.h"
 32#include "llrefcount.h"
 33#include "llrefcount.h"
 34#include "llrect.h"
 35#include <boost/function.hpp>
 36#include <boost/signals2.hpp>
 37#include "llinitparam.h"
 38#include "lltexture.h"
 39
 40extern const LLColor4 UI_VERTEX_COLOR;
 41
 42class LLUIImage : public LLRefCount
 43{
 44public:
 45	typedef boost::signals2::signal<void (void)> image_loaded_signal_t;
 46
 47	LLUIImage(const std::string& name, LLPointer<LLTexture> image);
 48	virtual ~LLUIImage();
 49
 50	void setClipRegion(const LLRectf& region);
 51	void setScaleRegion(const LLRectf& region);
 52
 53	LLPointer<LLTexture> getImage() { return mImage; }
 54	const LLPointer<LLTexture>& getImage() const { return mImage; }
 55
 56	void draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color = UI_VERTEX_COLOR) const;
 57	void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const;
 58	void draw(const LLRect& rect, const LLColor4& color = UI_VERTEX_COLOR) const { draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
 59	
 60	void drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const;
 61	void drawSolid(const LLRect& rect, const LLColor4& color) const { drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
 62	void drawSolid(S32 x, S32 y, const LLColor4& color) const { drawSolid(x, y, getWidth(), getHeight(), color); }
 63
 64	void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const;
 65	void drawBorder(const LLRect& rect, const LLColor4& color, S32 border_width) const { drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color, border_width); }
 66	void drawBorder(S32 x, S32 y, const LLColor4& color, S32 border_width) const { drawBorder(x, y, getWidth(), getHeight(), color, border_width); }
 67	
 68	const std::string& getName() const { return mName; }
 69
 70	virtual S32 getWidth() const;
 71	virtual S32 getHeight() const;
 72
 73	// returns dimensions of underlying textures, which might not be equal to ui image portion
 74	S32 getTextureWidth() const;
 75	S32 getTextureHeight() const;
 76
 77	boost::signals2::connection addLoadedCallback( const image_loaded_signal_t::slot_type& cb );
 78
 79	void onImageLoaded();
 80
 81protected:
 82	image_loaded_signal_t* mImageLoaded;
 83
 84	std::string			mName;
 85	LLRectf				mScaleRegion;
 86	LLRectf				mClipRegion;
 87	LLPointer<LLTexture> mImage;
 88	BOOL				mUniformScaling;
 89	BOOL				mNoClip;
 90};
 91
 92namespace LLInitParam
 93{
 94	template<>
 95	class ParamValue<LLUIImage*, TypeValues<LLUIImage*> > 
 96	:	public CustomParamValue<LLUIImage*>
 97	{
 98		typedef boost::add_reference<boost::add_const<LLUIImage*>::type>::type	T_const_ref;
 99		typedef CustomParamValue<LLUIImage*> super_t;
100	public:
101		Optional<std::string> name;
102
103		ParamValue(LLUIImage* const& image)
104		:	super_t(image)
105		{
106			updateBlockFromValue(false);
107			addSynonym(name, "name");
108		}
109
110		void updateValueFromBlock();
111		void updateBlockFromValue(bool make_block_authoritative);
112	};
113
114	// Need custom comparison function for our test app, which only loads
115	// LLUIImage* as NULL.
116	template<>
117	struct ParamCompare<LLUIImage*, false>
118	{
119		static bool equals(LLUIImage* const &a, LLUIImage* const &b);
120	};
121}
122
123typedef LLPointer<LLUIImage> LLUIImagePtr;
124#endif