Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://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 CoreText_INCLUDE_ONCE 00033 #define CoreText_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 { 00047 class VLGRAPHICS_EXPORT CoreText: public Renderable 00048 { 00049 VL_INSTRUMENT_CLASS(vl::CoreText, Renderable) 00050 00051 public: 00052 CoreText(): 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), 00053 mTextOrigin(AlignBottom|AlignLeft), mMargin(5), mLayout(LeftToRightText), mTextAlignment(TextAlignLeft), 00054 mBorderEnabled(false), mBackgroundEnabled(false), mOutlineEnabled(false), mShadowEnabled(false), mKerningEnabled(true) 00055 { 00056 VL_DEBUG_SET_OBJECT_NAME() 00057 } 00058 00060 const String& text() const { return mText; } 00062 void setText(const String& text) { mText = text; } 00063 00065 const fvec4& color() const { return mColor; } 00067 void setColor(const fvec4& color) { mColor = color; } 00068 00070 int margin() const { return mMargin; } 00072 void setMargin(int margin) { mMargin = margin; } 00073 00075 const Font* font() const { return mFont.get(); } 00077 Font* font() { return mFont.get(); } 00079 void setFont(Font* font) { mFont = font; } 00080 00082 ETextLayout layout() const { return mLayout; } 00084 void setLayout(ETextLayout layout) { mLayout = layout; } 00085 00087 ETextAlign textAlignment() const { return mTextAlignment; } 00089 void setTextAlignment(ETextAlign align) { mTextAlignment = align; } 00090 00092 int textOrigin() const { return mTextOrigin; } 00094 void setTextOrigin(int align) { mTextOrigin = align; } 00095 00097 bool kerningEnabled() const { return mKerningEnabled; } 00099 void setKerningEnabled(bool kerning) { mKerningEnabled = kerning; } 00100 00102 bool borderEnabled() const { return mBorderEnabled; } 00104 void setBorderEnabled(bool border) { mBorderEnabled = border; } 00105 00107 const fvec4& borderColor() const { return mBorderColor; } 00109 void setBorderColor(const fvec4& border_color) { mBorderColor = border_color; } 00110 00112 bool backgroundEnabled() const { return mBackgroundEnabled; } 00114 void setBackgroundEnabled(bool background) { mBackgroundEnabled = background; } 00115 00117 const fvec4& backgroundColor() const { return mBackgroundColor; } 00119 void setBackgroundColor(const fvec4& background_color) { mBackgroundColor = background_color; } 00120 00122 bool outlineEnabled() const { return mOutlineEnabled; } 00124 void setOutlineEnabled(bool outline) { mOutlineEnabled = outline; } 00125 00127 const fvec4& outlineColor() const { return mOutlineColor; } 00129 void setOutlineColor(const fvec4& outline_color) { mOutlineColor = outline_color; } 00130 00132 bool shadowEnabled() const { return mShadowEnabled; } 00134 void setShadowEnabled(bool shadow) { mShadowEnabled = shadow; } 00135 00137 const fvec4& shadowColor() const { return mShadowColor; } 00139 void setShadowColor(const fvec4& shadow_color) { mShadowColor = shadow_color; } 00140 00142 const fvec2& shadowVector() const { return mShadowVector; } 00144 void setShadowVector(const fvec2& shadow_vector) { mShadowVector = shadow_vector; } 00145 00147 AABB boundingRect() const; 00148 00150 AABB boundingRect(const String& text) const; 00151 00152 // --- Renderable interface implementation --- 00153 00154 virtual void updateDirtyBufferObject(EBufferObjectUpdateMode) {} 00155 00156 virtual void deleteBufferObject() {} 00157 00158 protected: 00159 virtual void render_Implementation(const Actor* actor, const Shader* shader, const Camera* camera, OpenGLContext* gl_context) const; 00160 void computeBounds_Implementation() { setBoundingBox(AABB()); setBoundingSphere(Sphere()); } 00161 00162 void renderText(const Actor*, const Camera* camera, const fvec4& color, const fvec2& offset) const; 00163 void renderBackground(const Actor* actor, const Camera* camera) const; 00164 void renderBorder(const Actor* actor, const Camera* camera) const; 00165 AABB rawboundingRect(const String& text) const; 00166 00167 protected: 00168 mutable ref<Font> mFont; 00169 String mText; 00170 fvec4 mColor; 00171 fvec4 mBorderColor; 00172 fvec4 mBackgroundColor; 00173 fvec4 mOutlineColor; 00174 fvec4 mShadowColor; 00175 fvec2 mShadowVector; 00176 int mTextOrigin; 00177 int mMargin; 00178 ETextLayout mLayout; 00179 ETextAlign mTextAlignment; 00180 bool mBorderEnabled; 00181 bool mBackgroundEnabled; 00182 bool mOutlineEnabled; 00183 bool mShadowEnabled; 00184 bool mKerningEnabled; 00185 }; 00186 } 00187 00188 #endif