PageRenderTime 30ms CodeModel.GetById 12ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llhudtext.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 173 lines | 121 code | 20 blank | 32 comment | 0 complexity | dc799c2070898487f71c310356871369 MD5 | raw file
  1/** 
  2 * @file llhudtext.h
  3 * @brief LLHUDText class definition
  4 *
  5 * $LicenseInfo:firstyear=2002&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_LLHUDTEXT_H
 28#define LL_LLHUDTEXT_H
 29
 30#include "llpointer.h"
 31
 32#include "llhudobject.h"
 33#include "v4color.h"
 34#include "v4coloru.h"
 35#include "v2math.h"
 36#include "llrect.h"
 37#include "llfontgl.h"
 38#include <set>
 39#include <vector>
 40
 41// Renders a 2D text billboard floating at the location specified.
 42class LLDrawable;
 43class LLHUDText;
 44
 45struct lltextobject_further_away
 46{
 47	bool operator()(const LLPointer<LLHUDText>& lhs, const LLPointer<LLHUDText>& rhs) const;
 48};
 49
 50class LLHUDText : public LLHUDObject
 51{
 52protected:
 53	class LLHUDTextSegment
 54	{
 55	public:
 56		LLHUDTextSegment(const LLWString& text, const LLFontGL::StyleFlags style, const LLColor4& color, const LLFontGL* font)
 57		:	mColor(color),
 58			mStyle(style),
 59			mText(text),
 60			mFont(font)
 61		{}
 62		F32 getWidth(const LLFontGL* font);
 63		const LLWString& getText() const { return mText; }
 64		void clearFontWidthMap() { mFontWidthMap.clear(); }
 65		
 66		LLColor4				mColor;
 67		LLFontGL::StyleFlags	mStyle;
 68		const LLFontGL*			mFont;
 69	private:
 70		LLWString				mText;
 71		std::map<const LLFontGL*, F32> mFontWidthMap;
 72	};
 73
 74public:
 75	typedef enum e_text_alignment
 76	{
 77		ALIGN_TEXT_LEFT,
 78		ALIGN_TEXT_CENTER
 79	} ETextAlignment;
 80
 81	typedef enum e_vert_alignment
 82	{
 83		ALIGN_VERT_TOP,
 84		ALIGN_VERT_CENTER
 85	} EVertAlignment;
 86
 87public:
 88	// Set entire string, eliminating existing lines
 89	void setString(const std::string& text_utf8);
 90
 91	void clearString();
 92
 93	// Add text a line at a time, allowing custom formatting
 94	void addLine(const std::string &text_utf8, const LLColor4& color, const LLFontGL::StyleFlags style = LLFontGL::NORMAL, const LLFontGL* font = NULL);
 95
 96	// Sets the default font for lines with no font specified
 97	void setFont(const LLFontGL* font);
 98	void setColor(const LLColor4 &color);
 99	void setAlpha(F32 alpha);
100	void setZCompare(const BOOL zcompare);
101	void setDoFade(const BOOL do_fade);
102//	void setVisibleOffScreen(BOOL visible) { mVisibleOffScreen = visible; }
103	
104	// mMaxLines of -1 means unlimited lines.
105	void setMaxLines(S32 max_lines) { mMaxLines = max_lines; }
106	void setFadeDistance(F32 fade_distance, F32 fade_range) { mFadeDistance = fade_distance; mFadeRange = fade_range; }
107	void updateVisibility();
108	LLVector2 updateScreenPos(LLVector2 &offset_target);
109	void updateSize();
110	void setMass(F32 mass) { mMass = llmax(0.1f, mass); }
111	void setTextAlignment(ETextAlignment alignment) { mTextAlignment = alignment; }
112	void setVertAlignment(EVertAlignment alignment) { mVertAlignment = alignment; }
113	/*virtual*/ void markDead();
114	friend class LLHUDObject;
115	/*virtual*/ F32 getDistance() const { return mLastDistance; }
116	BOOL getVisible() { return mVisible; }
117	BOOL getHidden() const { return mHidden; }
118	void setHidden( BOOL hide ) { mHidden = hide; }
119	void setOnHUDAttachment(BOOL on_hud) { mOnHUDAttachment = on_hud; }
120	void shift(const LLVector3& offset);
121
122	static void shiftAll(const LLVector3& offset);
123	static void renderAllHUD();
124	static void reshape();
125	static void setDisplayText(BOOL flag) { sDisplayText = flag ; }
126
127protected:
128	LLHUDText(const U8 type);
129
130	/*virtual*/ void render();
131	void renderText();
132	static void updateAll();
133	S32 getMaxLines();
134
135private:
136	~LLHUDText();
137	BOOL			mOnHUDAttachment;
138	BOOL			mDoFade;
139	F32				mFadeRange;
140	F32				mFadeDistance;
141	F32				mLastDistance;
142	BOOL			mZCompare;
143//	BOOL			mVisibleOffScreen;
144	BOOL			mOffscreen;
145	LLColor4		mColor;
146	LLVector3		mScale;
147	F32				mWidth;
148	F32				mHeight;
149	LLColor4U		mPickColor;
150	const LLFontGL*	mFontp;
151	const LLFontGL*	mBoldFontp;
152	LLRectf			mSoftScreenRect;
153	LLVector3		mPositionAgent;
154	LLVector2		mPositionOffset;
155	LLVector2		mTargetPositionOffset;
156	F32				mMass;
157	S32				mMaxLines;
158	S32				mOffsetY;
159	F32				mRadius;
160	std::vector<LLHUDTextSegment> mTextSegments;
161	ETextAlignment	mTextAlignment;
162	EVertAlignment	mVertAlignment;
163	BOOL			mHidden;
164
165	static BOOL    sDisplayText ;
166	static std::set<LLPointer<LLHUDText> > sTextObjects;
167	static std::vector<LLPointer<LLHUDText> > sVisibleTextObjects;
168	static std::vector<LLPointer<LLHUDText> > sVisibleHUDTextObjects;
169	typedef std::set<LLPointer<LLHUDText> >::iterator TextObjectIterator;
170	typedef std::vector<LLPointer<LLHUDText> >::iterator VisibleTextObjectIterator;
171};
172
173#endif // LL_LLHUDTEXT_H