llhudtext.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLHUDTEXT_H
00033 #define LL_LLHUDTEXT_H
00034 
00035 #include "llmemory.h"
00036 #include "lldarrayptr.h"
00037 
00038 #include "llhudobject.h"
00039 #include "v4color.h"
00040 #include "v4coloru.h"
00041 #include "v2math.h"
00042 #include "llrect.h"
00043 #include "llframetimer.h"
00044 #include "llfontgl.h"
00045 #include <set>
00046 #include <vector>
00047 #include "lldarray.h"
00048 
00049 // Renders a 2D text billboard floating at the location specified.
00050 class LLDrawable;
00051 class LLHUDText;
00052 
00053 struct lltextobject_further_away
00054 {
00055         bool operator()(const LLPointer<LLHUDText>& lhs, const LLPointer<LLHUDText>& rhs) const;
00056 };
00057 
00058 class LLHUDText : public LLHUDObject
00059 {
00060 protected:
00061         class LLHUDTextSegment
00062         {
00063         public:
00064                 LLHUDTextSegment(const LLWString& text, const LLFontGL::StyleFlags style, const LLColor4& color)
00065                         : mColor(color), mStyle(style), mText(text) {}
00066                 F32 getWidth(const LLFontGL* font);
00067                 const LLWString& getText() const { return mText; };
00068                 void clearFontWidthMap() { mFontWidthMap.clear(); }
00069                 
00070                 LLColor4                                mColor;
00071                 LLFontGL::StyleFlags    mStyle;
00072         private:
00073                 LLWString                               mText;
00074                 std::map<const LLFontGL*, F32> mFontWidthMap;
00075         };
00076 
00077 public:
00078         typedef enum e_text_alignment
00079         {
00080                 ALIGN_TEXT_LEFT,
00081                 ALIGN_TEXT_CENTER
00082         } ETextAlignment;
00083 
00084         typedef enum e_vert_alignment
00085         {
00086                 ALIGN_VERT_TOP,
00087                 ALIGN_VERT_CENTER
00088         } EVertAlignment;
00089 
00090 public:
00091         void setStringUTF8(const std::string &utf8string);
00092         void setString(const LLWString &wstring);
00093         void clearString();
00094         void addLine(const std::string &text, const LLColor4& color, const LLFontGL::StyleFlags style = LLFontGL::NORMAL);
00095         void addLine(const LLWString &wtext, const LLColor4& color, const LLFontGL::StyleFlags style = LLFontGL::NORMAL);
00096         void setLabel(const std::string &label);
00097         void setLabel(const LLWString &label);
00098         void setDropShadow(const BOOL do_shadow);
00099         void setFont(const LLFontGL* font);
00100         void setColor(const LLColor4 &color);
00101         void setBackgroundColor(const LLColor4 &color);
00102         void setUsePixelSize(const BOOL use_pixel_size);
00103         void setZCompare(const BOOL zcompare);
00104         void setDoFade(const BOOL do_fade);
00105         void setVisibleOffScreen(BOOL visible) { mVisibleOffScreen = visible; }
00106         
00107         // mMaxLines of -1 means unlimited lines.
00108         void setMaxLines(S32 max_lines) { mMaxLines = max_lines; }
00109         void setFadeDistance(F32 fade_distance, F32 fade_range) { mFadeDistance = fade_distance; mFadeRange = fade_range; }
00110         void updateVisibility();
00111         LLVector2 updateScreenPos(LLVector2 &offset_target);
00112         void updateSize();
00113         void setMass(F32 mass) { mMass = llmax(0.1f, mass); }
00114         void setTextAlignment(ETextAlignment alignment) { mTextAlignment = alignment; }
00115         void setVertAlignment(EVertAlignment alignment) { mVertAlignment = alignment; }
00116         /*virtual*/ void markDead();
00117         friend class LLHUDObject;
00118         /*virtual*/ F32 getDistance() const { return mLastDistance; }
00119         void setUseBubble(BOOL use_bubble) { mUseBubble = use_bubble; }
00120         S32  getLOD() { return mLOD; }
00121         BOOL getVisible() { return mVisible; }
00122         BOOL getHidden() const { return mHidden; }
00123         void setHidden( BOOL hide ) { mHidden = hide; }
00124         void setOnHUDAttachment(BOOL on_hud) { mOnHUDAttachment = on_hud; }
00125         static void renderAllHUD();
00126         static void addPickable(std::set<LLViewerObject*> &pick_list);
00127         static void reshape();
00128 protected:
00129         LLHUDText(const U8 type);
00130 
00131         /*virtual*/ void render();
00132         /*virtual*/ void renderForSelect();
00133         void renderText(BOOL for_select);
00134         static void updateAll();
00135         void setLOD(S32 lod);
00136         S32 getMaxLines();
00137 
00138 private:
00139         ~LLHUDText();
00140         BOOL                    mOnHUD;
00141         BOOL                    mUseBubble;
00142         BOOL                    mDropShadow;
00143         BOOL                    mDoFade;
00144         F32                             mFadeRange;
00145         F32                             mFadeDistance;
00146         F32                             mLastDistance;
00147         BOOL                    mUsePixelSize;
00148         BOOL                    mZCompare;
00149         BOOL                    mVisibleOffScreen;
00150         BOOL                    mOffscreen;
00151         LLColor4                mColor;
00152         LLColor4                mBackgroundColor;
00153         LLVector3               mScale;
00154         F32                             mWidth;
00155         F32                             mHeight;
00156         LLColor4U               mPickColor;
00157         const LLFontGL* mFontp;
00158         const LLFontGL* mBoldFontp;
00159         LLRectf                 mSoftScreenRect;
00160         LLVector3               mPositionAgent;
00161         LLVector2               mPositionOffset;
00162         LLVector2               mTargetPositionOffset;
00163         F32                             mMass;
00164         S32                             mMaxLines;
00165         S32                             mOffsetY;
00166         F32                             mRadius;
00167         std::vector<LLHUDTextSegment> mTextSegments;
00168         std::vector<LLHUDTextSegment> mLabelSegments;
00169         LLFrameTimer    mResizeTimer;
00170         ETextAlignment  mTextAlignment;
00171         EVertAlignment  mVertAlignment;
00172         S32                             mLOD;
00173         BOOL                    mHidden;
00174 
00175         static std::set<LLPointer<LLHUDText> > sTextObjects;
00176         static std::vector<LLPointer<LLHUDText> > sVisibleTextObjects;
00177         static std::vector<LLPointer<LLHUDText> > sVisibleHUDTextObjects;
00178         typedef std::set<LLPointer<LLHUDText> >::iterator TextObjectIterator;
00179         typedef std::vector<LLPointer<LLHUDText> >::iterator VisibleTextObjectIterator;
00180 };
00181 
00182 #endif // LL_LLHUDTEXT_H

Generated on Thu Jul 1 06:08:43 2010 for Second Life Viewer by  doxygen 1.4.7