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

/indra/llui/llbadge.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 174 lines | 98 code | 40 blank | 36 comment | 5 complexity | d7f45d19ace3d8b1348acb10defe9e60 MD5 | raw file
  1/** 
  2 * @file llbadge.h
  3 * @brief Header for badges
  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#ifndef LL_LLBADGE_H
 28#define LL_LLBADGE_H
 29
 30#include <string>
 31
 32#include "lluicolor.h"
 33#include "lluictrl.h"
 34#include "llstring.h"
 35#include "lluiimage.h"
 36#include "llview.h"
 37
 38//
 39// Declarations
 40//
 41
 42class LLFontGL;
 43class LLScrollContainer;
 44class LLUICtrlFactory;
 45
 46//
 47// Relative Position Alignment
 48//
 49
 50namespace LLRelPos
 51{
 52	enum Location
 53	{
 54		CENTER	= 0,
 55
 56		LEFT	= (1 << 0),
 57		RIGHT	= (1 << 1),
 58
 59		TOP		= (1 << 2),
 60		BOTTOM	= (1 << 3),
 61
 62		BOTTOM_LEFT		= (BOTTOM | LEFT),
 63		BOTTOM_RIGHT	= (BOTTOM | RIGHT),
 64
 65		TOP_LEFT		= (TOP | LEFT),
 66		TOP_RIGHT		= (TOP | RIGHT),
 67	};
 68
 69	inline bool IsBottom(Location relPos)	{ return (relPos & BOTTOM) == BOTTOM; }
 70	inline bool IsCenter(Location relPos)	{ return (relPos == CENTER); }
 71	inline bool IsLeft(Location relPos)		{ return (relPos & LEFT) == LEFT; }
 72	inline bool IsRight(Location relPos)	{ return (relPos & RIGHT) == RIGHT; }
 73	inline bool IsTop(Location relPos)		{ return (relPos & TOP) == TOP; }
 74}
 75
 76// NOTE: This needs to occur before Optional<LLRelPos::Location> declaration for proper compilation.
 77namespace LLInitParam
 78{
 79	template<>
 80	struct TypeValues<LLRelPos::Location> : public TypeValuesHelper<LLRelPos::Location>
 81	{
 82		static void declareValues();
 83	};
 84}
 85
 86//
 87// Classes
 88//
 89
 90class LLBadge
 91: public LLUICtrl
 92{
 93public:
 94	struct Params 
 95	: public LLInitParam::Block<Params, LLUICtrl::Params>
 96	{
 97		Optional< LLHandle<LLView> >	owner;	// Mandatory in code but not in xml
 98		
 99		Optional< LLUIImage* >			border_image;
100		Optional< LLUIColor >			border_color;
101
102		Optional< LLUIImage* >			image;
103		Optional< LLUIColor >			image_color;
104		
105		Optional< std::string >			label;
106		Optional< LLUIColor >			label_color;
107
108		Optional< S32 >					label_offset_horiz;
109		Optional< S32 >					label_offset_vert;
110
111		Optional< LLRelPos::Location >	location;
112		Optional< S32 >					location_offset_hcenter;
113		Optional< S32 >					location_offset_vcenter;
114		Optional< U32 >					location_percent_hcenter;
115		Optional< U32 >					location_percent_vcenter;
116
117		Optional< F32 >					padding_horiz;
118		Optional< F32 >					padding_vert;
119		
120		Params();
121		
122		bool equals(const Params&) const;
123	};
124	
125protected:
126	friend class LLUICtrlFactory;
127	LLBadge(const Params& p);
128
129public:
130
131	~LLBadge();
132
133	bool				addToView(LLView * view);
134
135	virtual void		draw();
136
137	const std::string	getLabel() const { return wstring_to_utf8str(mLabel); }
138	void				setLabel( const LLStringExplicit& label);
139
140private:
141	LLPointer< LLUIImage >	mBorderImage;
142	LLUIColor				mBorderColor;
143
144	const LLFontGL*			mGLFont;
145	
146	LLPointer< LLUIImage >	mImage;
147	LLUIColor				mImageColor;
148	
149	LLUIString				mLabel;
150	LLUIColor				mLabelColor;
151
152	S32						mLabelOffsetHoriz;
153	S32						mLabelOffsetVert;
154
155	LLRelPos::Location		mLocation;
156	S32						mLocationOffsetHCenter;
157	S32						mLocationOffsetVCenter;
158	F32						mLocationPercentHCenter;
159	F32						mLocationPercentVCenter;
160	
161	LLHandle< LLView >		mOwner;
162
163	F32						mPaddingHoriz;
164	F32						mPaddingVert;
165
166	LLScrollContainer*		mParentScroller;
167};
168
169// Build time optimization, generate once in .cpp file
170#ifndef LLBADGE_CPP
171extern template class LLBadge* LLView::getChild<class LLBadge>(const std::string& name, BOOL recurse) const;
172#endif
173
174#endif  // LL_LLBADGE_H