llhudtext.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /**
  2. * @file llhudtext.h
  3. * @brief LLHUDText class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLHUDTEXT_H
  33. #define LL_LLHUDTEXT_H
  34. #include <set>
  35. #include <vector>
  36. #include "llfontgl.h"
  37. #include "llrect.h"
  38. #include "llcolor4u.h"
  39. #include "llvector2.h"
  40. #include "llhudobject.h"
  41. // Renders a 2D text billboard floating at the location specified.
  42. class LLDrawable;
  43. class LLHUDText;
  44. class LLHUDText : public LLHUDObject
  45. {
  46. friend class LLHUDObject;
  47. protected:
  48. LOG_CLASS(LLHUDText);
  49. class LLHUDTextSegment
  50. {
  51. public:
  52. LLHUDTextSegment(const LLWString& text,
  53. const LLFontGL::StyleFlags style,
  54. const LLColor4& color)
  55. : mLastFont(NULL),
  56. mColor(color),
  57. mStyle(style),
  58. mText(text)
  59. {
  60. }
  61. LL_INLINE const LLWString& getText() const { return mText; };
  62. LL_INLINE F32 getWidth(const LLFontGL* fontp)
  63. {
  64. if (LL_UNLIKELY(fontp != mLastFont))
  65. {
  66. mLastFont = fontp;
  67. mLastWidth = fontp->getWidthF32(mText.c_str());
  68. }
  69. return mLastWidth;
  70. }
  71. LL_INLINE void clearFontWidthCache() { mLastFont = NULL; }
  72. public:
  73. LLColor4 mColor;
  74. LLFontGL::StyleFlags mStyle;
  75. private:
  76. LLWString mText;
  77. const LLFontGL* mLastFont;
  78. F32 mLastWidth;
  79. };
  80. public:
  81. typedef enum e_text_alignment
  82. {
  83. ALIGN_TEXT_LEFT,
  84. ALIGN_TEXT_CENTER
  85. } ETextAlignment;
  86. typedef enum e_vert_alignment
  87. {
  88. ALIGN_VERT_TOP,
  89. ALIGN_VERT_CENTER
  90. } EVertAlignment;
  91. public:
  92. void markDead() override;
  93. void setStringUTF8(const std::string& utf8string);
  94. void setString(const LLWString& wstring);
  95. void clearString();
  96. void addLine(const std::string& text, const LLColor4& color,
  97. const LLFontGL::StyleFlags style = LLFontGL::NORMAL);
  98. void addLine(const LLWString& wtext, const LLColor4& color,
  99. const LLFontGL::StyleFlags style = LLFontGL::NORMAL);
  100. void setLabel(const std::string& label);
  101. void setLabel(const LLWString& label);
  102. LL_INLINE void setDropShadow(bool b) { mDropShadow = b; }
  103. LL_INLINE void setFont(const LLFontGL* font) { mFontp = font; }
  104. void setColor(const LLColor4& color);
  105. LL_INLINE void setUsePixelSize(bool b) { mUsePixelSize = b; }
  106. LL_INLINE void setZCompare(bool zcompare) { mZCompare = zcompare; }
  107. LL_INLINE void setDoFade(bool do_fade) { mDoFade = do_fade; }
  108. LL_INLINE bool getDoFade() const { return mDoFade; }
  109. LL_INLINE void setVisibleOffScreen(bool b) { mVisibleOffScreen = b; }
  110. // mMaxLines of -1 means unlimited lines.
  111. void setMaxLines(S32 max_lines) { mMaxLines = max_lines; }
  112. LL_INLINE void setFadeDistance(F32 dist, F32 range)
  113. {
  114. mFadeDistance = dist;
  115. mFadeRange = range;
  116. }
  117. void updateVisibility();
  118. LLVector2 updateScreenPos(LLVector2& offset_target);
  119. void updateSize();
  120. LL_INLINE void setMass(F32 mass) { mMass = llmax(0.1f, mass); }
  121. LL_INLINE void setTextAlignment(ETextAlignment a) { mTextAlignment = a; }
  122. LL_INLINE void setVertAlignment(EVertAlignment a) { mVertAlignment = a; }
  123. LL_INLINE F32 getDistance() const override { return mLastDistance; }
  124. LL_INLINE void setUseBubble(bool use_bubble) { mUseBubble = use_bubble; }
  125. LL_INLINE S32 getLOD() { return mLOD; }
  126. LL_INLINE bool getVisible() { return mVisible; }
  127. LL_INLINE bool getHidden() const { return mHidden; }
  128. LL_INLINE void setHidden(bool hide) { mHidden = hide; }
  129. LL_INLINE void setOnHUDAttachment(bool on_hud) { mOnHUDAttachment = on_hud; }
  130. LL_INLINE void shift(const LLVector3& offset) { mPositionAgent += offset; }
  131. bool lineSegmentIntersect(const LLVector4a& start,
  132. const LLVector4a& end,
  133. LLVector4a& intersection,
  134. bool debug_render = false);
  135. static void shiftAll(const LLVector3& offset);
  136. static void renderAllHUD();
  137. static void addPickable(std::set<LLViewerObject*>& pick_list);
  138. static void reshape();
  139. LL_INLINE static void setDisplayText(bool flag) { sDisplayText = flag ; }
  140. private:
  141. ~LLHUDText() override {}
  142. protected:
  143. LLHUDText(U8 type);
  144. void render() override;
  145. void renderText();
  146. static void updateAll();
  147. LL_INLINE void setLOD(S32 lod) { mLOD = lod; }
  148. S32 getMaxLines();
  149. //MK
  150. public:
  151. // This variable is here to allow one to refresh a HUD text by calling
  152. // setStringUTF8, it is set when an update message is received
  153. std::string mLastMessageText;
  154. //mk
  155. private:
  156. const LLFontGL* mFontp;
  157. const LLFontGL* mBoldFontp;
  158. LLVector3 mScale;
  159. LLColor4 mColor;
  160. LLColor4U mPickColor;
  161. LLRectf mSoftScreenRect;
  162. LLVector3 mPositionAgent;
  163. LLVector2 mPositionOffset;
  164. LLVector2 mTargetPositionOffset;
  165. typedef std::vector<LLHUDTextSegment> segments_vec_t;
  166. segments_vec_t mTextSegments;
  167. segments_vec_t mLabelSegments;
  168. S32 mLOD;
  169. S32 mMaxLines;
  170. S32 mOffsetY;
  171. F32 mWidth;
  172. F32 mHeight;
  173. F32 mRadius;
  174. F32 mFadeRange;
  175. F32 mFadeDistance;
  176. F32 mLastDistance;
  177. F32 mMass;
  178. ETextAlignment mTextAlignment;
  179. EVertAlignment mVertAlignment;
  180. bool mHidden;
  181. bool mUseBubble;
  182. bool mDropShadow;
  183. bool mDoFade;
  184. bool mUsePixelSize;
  185. bool mZCompare;
  186. bool mVisibleOffScreen;
  187. bool mOffScreen;
  188. public: // Needed for mkrlinterface.cpp
  189. typedef std::set<LLPointer<LLHUDText> > htobj_list_t;
  190. typedef htobj_list_t::iterator htobj_list_it_t;
  191. static htobj_list_t sTextObjects;
  192. private:
  193. typedef std::vector<LLPointer<LLHUDText> > visible_list_t;
  194. static visible_list_t sVisibleTextObjects;
  195. static visible_list_t sVisibleHUDTextObjects;
  196. static bool sDisplayText;
  197. };
  198. #endif // LL_LLHUDTEXT_H