PageRenderTime 428ms CodeModel.GetById 141ms app.highlight 95ms RepoModel.GetById 187ms app.codeStats 0ms

/indra/newview/llhudnametag.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 185 lines | 124 code | 22 blank | 39 comment | 0 complexity | 690fc0b3177f9579c93b04d6c810b8c7 MD5 | raw file
  1/** 
  2 * @file llhudnametag.h
  3 * @brief Name tags for avatars
  4 * @author James Cook
  5 *
  6 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LLHUDNAMETAG_H
 29#define LLHUDNAMETAG_H
 30
 31#include "llpointer.h"
 32
 33#include "llhudobject.h"
 34#include "v4color.h"
 35//#include "v4coloru.h"
 36#include "v2math.h"
 37#include "llrect.h"
 38//#include "llframetimer.h"
 39#include "llfontgl.h"
 40#include <set>
 41#include <vector>
 42
 43class LLDrawable;
 44class LLHUDNameTag;
 45
 46struct llhudnametag_further_away
 47{
 48	bool operator()(const LLPointer<LLHUDNameTag>& lhs, const LLPointer<LLHUDNameTag>& rhs) const;
 49};
 50
 51class LLHUDNameTag : public LLHUDObject
 52{
 53protected:
 54	class LLHUDTextSegment
 55	{
 56	public:
 57		LLHUDTextSegment(const LLWString& text, const LLFontGL::StyleFlags style, const LLColor4& color, const LLFontGL* font)
 58		:	mColor(color),
 59			mStyle(style),
 60			mText(text),
 61			mFont(font)
 62		{}
 63		F32 getWidth(const LLFontGL* font);
 64		const LLWString& getText() const { return mText; }
 65		void clearFontWidthMap() { mFontWidthMap.clear(); }
 66		
 67		LLColor4				mColor;
 68		LLFontGL::StyleFlags	mStyle;
 69		const LLFontGL*			mFont;
 70	private:
 71		LLWString				mText;
 72		std::map<const LLFontGL*, F32> mFontWidthMap;
 73	};
 74
 75public:
 76	typedef enum e_text_alignment
 77	{
 78		ALIGN_TEXT_LEFT,
 79		ALIGN_TEXT_CENTER
 80	} ETextAlignment;
 81
 82	typedef enum e_vert_alignment
 83	{
 84		ALIGN_VERT_TOP,
 85		ALIGN_VERT_CENTER
 86	} EVertAlignment;
 87
 88public:
 89	// Set entire string, eliminating existing lines
 90	void setString(const std::string& text_utf8);
 91
 92	void clearString();
 93
 94	// Add text a line at a time, allowing custom formatting
 95	void addLine(const std::string &text_utf8, const LLColor4& color, const LLFontGL::StyleFlags style = LLFontGL::NORMAL, const LLFontGL* font = NULL);
 96
 97	// For bubble chat, set the part above the chat text
 98	void setLabel(const std::string& label_utf8);
 99	void addLabel(const std::string& label_utf8);
100
101	// Sets the default font for lines with no font specified
102	void setFont(const LLFontGL* font);
103	void setColor(const LLColor4 &color);
104	void setAlpha(F32 alpha);
105	void setZCompare(const BOOL zcompare);
106	void setDoFade(const BOOL do_fade);
107	void setVisibleOffScreen(BOOL visible) { mVisibleOffScreen = visible; }
108	
109	// mMaxLines of -1 means unlimited lines.
110	void setMaxLines(S32 max_lines) { mMaxLines = max_lines; }
111	void setFadeDistance(F32 fade_distance, F32 fade_range) { mFadeDistance = fade_distance; mFadeRange = fade_range; }
112	void updateVisibility();
113	LLVector2 updateScreenPos(LLVector2 &offset_target);
114	void updateSize();
115//	void setMass(F32 mass) { mMass = llmax(0.1f, mass); }
116	void setTextAlignment(ETextAlignment alignment) { mTextAlignment = alignment; }
117	void setVertAlignment(EVertAlignment alignment) { mVertAlignment = alignment; }
118	/*virtual*/ void markDead();
119	friend class LLHUDObject;
120	/*virtual*/ F32 getDistance() const { return mLastDistance; }
121	//void setUseBubble(BOOL use_bubble) { mUseBubble = use_bubble; }
122	S32  getLOD() { return mLOD; }
123	BOOL getVisible() { return mVisible; }
124	BOOL getHidden() const { return mHidden; }
125	void setHidden( BOOL hide ) { mHidden = hide; }
126	void shift(const LLVector3& offset);
127
128	BOOL lineSegmentIntersect(const LLVector3& start, const LLVector3& end, LLVector3& intersection, BOOL debug_render = FALSE);
129
130	static void shiftAll(const LLVector3& offset);
131	static void addPickable(std::set<LLViewerObject*> &pick_list);
132	static void reshape();
133	static void setDisplayText(BOOL flag) { sDisplayText = flag ; }
134
135protected:
136	LLHUDNameTag(const U8 type);
137
138	/*virtual*/ void render();
139	/*virtual*/ void renderForSelect();
140	void renderText(BOOL for_select);
141	static void updateAll();
142	void setLOD(S32 lod);
143	S32 getMaxLines();
144
145private:
146	~LLHUDNameTag();
147	BOOL			mDoFade;
148	F32				mFadeRange;
149	F32				mFadeDistance;
150	F32				mLastDistance;
151	BOOL			mZCompare;
152	BOOL			mVisibleOffScreen;
153	BOOL			mOffscreen;
154	LLColor4		mColor;
155//	LLVector3		mScale;
156	F32				mWidth;
157	F32				mHeight;
158//	LLColor4U		mPickColor;
159	const LLFontGL*	mFontp;
160	const LLFontGL*	mBoldFontp;
161	LLRectf			mSoftScreenRect;
162	LLVector3		mPositionAgent;
163	LLVector2		mPositionOffset;
164	LLVector2		mTargetPositionOffset;
165	F32				mMass;
166	S32				mMaxLines;
167	S32				mOffsetY;
168	F32				mRadius;
169	std::vector<LLHUDTextSegment> mTextSegments;
170	std::vector<LLHUDTextSegment> mLabelSegments;
171//	LLFrameTimer	mResizeTimer;
172	ETextAlignment	mTextAlignment;
173	EVertAlignment	mVertAlignment;
174	S32				mLOD;
175	BOOL			mHidden;
176
177	static BOOL    sDisplayText ;
178	static std::set<LLPointer<LLHUDNameTag> > sTextObjects;
179	static std::vector<LLPointer<LLHUDNameTag> > sVisibleTextObjects;
180//	static std::vector<LLPointer<LLHUDNameTag> > sVisibleHUDTextObjects;
181	typedef std::set<LLPointer<LLHUDNameTag> >::iterator TextObjectIterator;
182	typedef std::vector<LLPointer<LLHUDNameTag> >::iterator VisibleTextObjectIterator;
183};
184
185#endif