# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/Text.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.org                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef Text_INCLUDE_ONCE
    00033 #define Text_INCLUDE_ONCE
    00034
    00035 #include <vlGraphics/Font.hpp>
    00036 #include <vlGraphics/Renderable.hpp>
    00037 #include <vlCore/vlnamespace.hpp>
    00038 #include <vlCore/String.hpp>
    00039 #include <vlCore/Rect.hpp>
    00040 #include <map>
    00041
    00042 namespace vl
    00043 {
    00050   class VLGRAPHICS_EXPORT Text: public Renderable
    00051   {
    00052     VL_INSTRUMENT_CLASS(vl::Text, Renderable)
    00053
    00054   public:
    00055     Text(): mColor(1,1,1,1), mBorderColor(0,0,0,1), mBackgroundColor(1,1,1,1), mOutlineColor(0,0,0,1), mShadowColor(0,0,0,0.5f), mShadowVector(2,-2),
    00056       mInterlineSpacing(5), mAlignment(AlignBottom|AlignLeft), mViewportAlignment(AlignBottom|AlignLeft), mMargin(5), mMode(Text2D), mLayout(LeftToRightText), mTextAlignment(TextAlignLeft),
    00057       mBorderEnabled(false), mBackgroundEnabled(false), mOutlineEnabled(false), mShadowEnabled(false), mKerningEnabled(true)
    00058     {
    00059       VL_DEBUG_SET_OBJECT_NAME()
    00060     }
    00061
    00062     const String& text() const { return mText; }
    00063     void setText(const String& text) { mText = text; }
    00064
    00065     const fvec4& color() const { return mColor; }
    00066     void setColor(const fvec4& color) { mColor = color; }
    00067
    00068     const fvec4& borderColor() const { return mBorderColor; }
    00069     void setBorderColor(const fvec4& border_color) { mBorderColor = border_color; }
    00070
    00071     const fvec4& outlineColor() const { return mOutlineColor; }
    00072     void setOutlineColor(const fvec4& outline_color) { mOutlineColor = outline_color; }
    00073
    00074     const fvec4& backgroundColor() const { return mBackgroundColor; }
    00075     void setBackgroundColor(const fvec4& background_color) { mBackgroundColor = background_color; }
    00076
    00077     const fvec4& shadowColor() const { return mShadowColor; }
    00078     void setShadowColor(const fvec4& shadow_color) { mShadowColor = shadow_color; }
    00079
    00080     const fvec2& shadowVector() const { return mShadowVector; }
    00081     void setShadowVector(const fvec2& shadow_vector) { mShadowVector = shadow_vector; }
    00082
    00083     int margin() const { return mMargin; }
    00084     void setMargin(int margin) { mMargin = margin; }
    00085
    00086     const Font* font() const { return mFont.get(); }
    00087     Font* font() { return mFont.get(); }
    00088     void setFont(Font* font) { mFont = font; }
    00089
    00090     const fmat4 matrix() const { return mMatrix; }
    00091     void setMatrix(const fmat4& matrix) { mMatrix = matrix; }
    00092
    00093     int  alignment() const { return mAlignment; }
    00094     void setAlignment(int  align) { mAlignment = align; }
    00095
    00096     int  viewportAlignment() const { return mViewportAlignment; }
    00097     void setViewportAlignment(int  align) { mViewportAlignment = align; }
    00098
    00099     float interlineSpacing() const { return mInterlineSpacing; }
    00100     void setInterlineSpacing(float spacing) { mInterlineSpacing = spacing; }
    00101
    00102     ETextMode mode() const { return mMode; }
    00103     void setMode(ETextMode mode) { mMode = mode; }
    00104
    00105     ETextLayout layout() const { return mLayout; }
    00106     void setLayout(ETextLayout layout) { mLayout = layout; }
    00107
    00108     ETextAlign textAlignment() const { return mTextAlignment; }
    00109     void setTextAlignment(ETextAlign align) { mTextAlignment = align; }
    00110
    00111     bool borderEnabled() const { return mBorderEnabled; }
    00112     void setBorderEnabled(bool border) { mBorderEnabled = border; }
    00113
    00114     bool backgroundEnabled() const { return mBackgroundEnabled; }
    00115     void setBackgroundEnabled(bool background) { mBackgroundEnabled = background; }
    00116
    00117     bool kerningEnabled() const { return mKerningEnabled; }
    00118     void setKerningEnabled(bool kerning) { mKerningEnabled = kerning; }
    00119
    00120     bool outlineEnabled() const { return mOutlineEnabled; }
    00121     void setOutlineEnabled(bool outline) { mOutlineEnabled = outline; }
    00122
    00123     bool shadowEnabled() const { return mShadowEnabled; }
    00124     void setShadowEnabled(bool shadow) { mShadowEnabled = shadow; }
    00125
    00126     virtual void render_Implementation(const Actor* actor, const Shader* shader, const Camera* camera, OpenGLContext* gl_context) const;
    00127     void computeBounds_Implementation() { setBoundingBox(AABB()); setBoundingSphere(Sphere()); }
    00128     AABB boundingRect() const;
    00129     AABB boundingRect(const String& text) const;
    00130     AABB boundingRectTransformed(vec3& a, vec3& b, vec3& c, vec3& d, const Camera* camera, const Actor* actor=NULL) const;
    00131     AABB boundingRectTransformed(const Camera* camera, const Actor* actor=NULL) const;
    00132
    00133     void translate(float x, float y, float z);
    00134     void rotate(float degrees, float x, float y, float z);
    00135     void resetMatrix();
    00136
    00137     // Renderable interface implementation.
    00138
    00139     virtual void updateDirtyBufferObject(EBufferObjectUpdateMode) {}
    00140
    00141     virtual void deleteBufferObject() {}
    00142
    00143   protected:
    00144     void renderText(const Actor*, const Camera* camera, const fvec4& color, const fvec2& offset) const;
    00145     void renderBackground(const Actor* actor, const Camera* camera) const;
    00146     void renderBorder(const Actor* actor, const Camera* camera) const;
    00147     AABB rawboundingRect(const String& text) const;
    00148
    00149   protected:
    00150     mutable ref<Font> mFont;
    00151     String mText;
    00152     fvec4 mColor;
    00153     fvec4 mBorderColor;
    00154     fvec4 mBackgroundColor;
    00155     fvec4 mOutlineColor;
    00156     fvec4 mShadowColor;
    00157     fvec2 mShadowVector;
    00158     fmat4 mMatrix;
    00159     float mInterlineSpacing;
    00160     int mAlignment;
    00161     int mViewportAlignment;
    00162     int mMargin;
    00163     ETextMode mMode;
    00164     ETextLayout mLayout;
    00165     ETextAlign mTextAlignment;
    00166     bool mBorderEnabled;
    00167     bool mBackgroundEnabled;
    00168     bool mOutlineEnabled;
    00169     bool mShadowEnabled;
    00170     bool mKerningEnabled;
    00171   };
    00172 }
    00173
    00174 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:44.
Permission is granted to use this page to write and publish articles regarding Visualization Library.