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