Visualization Library 2.0.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Text.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Text_INCLUDE_ONCE
33 #define Text_INCLUDE_ONCE
34 
35 #include <vlGraphics/Font.hpp>
37 #include <vlCore/vlnamespace.hpp>
38 #include <vlCore/String.hpp>
39 #include <vlCore/Rect.hpp>
40 #include <map>
41 
42 namespace vl
43 {
51  {
53 
54  public:
55  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),
56  mInterlineSpacing(5), mAlignment(AlignBottom|AlignLeft), mViewportAlignment(AlignBottom|AlignLeft), mMargin(5), mMode(Text2D), mLayout(LeftToRightText), mTextAlignment(TextAlignLeft),
57  mBorderEnabled(false), mBackgroundEnabled(false), mOutlineEnabled(false), mShadowEnabled(false), mKerningEnabled(true)
58  {
59  VL_DEBUG_SET_OBJECT_NAME()
60  }
61 
62  const String& text() const { return mText; }
63  void setText(const String& text) { mText = text; }
64 
65  const fvec4& color() const { return mColor; }
66  void setColor(const fvec4& color) { mColor = color; }
67 
68  const fvec4& borderColor() const { return mBorderColor; }
69  void setBorderColor(const fvec4& border_color) { mBorderColor = border_color; }
70 
71  const fvec4& outlineColor() const { return mOutlineColor; }
72  void setOutlineColor(const fvec4& outline_color) { mOutlineColor = outline_color; }
73 
74  const fvec4& backgroundColor() const { return mBackgroundColor; }
75  void setBackgroundColor(const fvec4& background_color) { mBackgroundColor = background_color; }
76 
77  const fvec4& shadowColor() const { return mShadowColor; }
78  void setShadowColor(const fvec4& shadow_color) { mShadowColor = shadow_color; }
79 
80  const fvec2& shadowVector() const { return mShadowVector; }
81  void setShadowVector(const fvec2& shadow_vector) { mShadowVector = shadow_vector; }
82 
83  int margin() const { return mMargin; }
84  void setMargin(int margin) { mMargin = margin; }
85 
86  const Font* font() const { return mFont.get(); }
87  Font* font() { return mFont.get(); }
88  void setFont(Font* font) { mFont = font; }
89 
90  const fmat4 matrix() const { return mMatrix; }
91  void setMatrix(const fmat4& matrix) { mMatrix = matrix; }
92 
93  int alignment() const { return mAlignment; }
94  void setAlignment(int align) { mAlignment = align; }
95 
96  int viewportAlignment() const { return mViewportAlignment; }
97  void setViewportAlignment(int align) { mViewportAlignment = align; }
98 
99  float interlineSpacing() const { return mInterlineSpacing; }
100  void setInterlineSpacing(float spacing) { mInterlineSpacing = spacing; }
101 
102  ETextMode mode() const { return mMode; }
103  void setMode(ETextMode mode) { mMode = mode; }
104 
105  ETextLayout layout() const { return mLayout; }
106  void setLayout(ETextLayout layout) { mLayout = layout; }
107 
108  ETextAlign textAlignment() const { return mTextAlignment; }
109  void setTextAlignment(ETextAlign align) { mTextAlignment = align; }
110 
111  bool borderEnabled() const { return mBorderEnabled; }
112  void setBorderEnabled(bool border) { mBorderEnabled = border; }
113 
114  bool backgroundEnabled() const { return mBackgroundEnabled; }
115  void setBackgroundEnabled(bool background) { mBackgroundEnabled = background; }
116 
117  bool kerningEnabled() const { return mKerningEnabled; }
118  void setKerningEnabled(bool kerning) { mKerningEnabled = kerning; }
119 
120  bool outlineEnabled() const { return mOutlineEnabled; }
121  void setOutlineEnabled(bool outline) { mOutlineEnabled = outline; }
122 
123  bool shadowEnabled() const { return mShadowEnabled; }
124  void setShadowEnabled(bool shadow) { mShadowEnabled = shadow; }
125 
126  virtual void render_Implementation(const Actor* actor, const Shader* shader, const Camera* camera, OpenGLContext* gl_context) const;
127  void computeBounds_Implementation() { setBoundingBox(AABB()); setBoundingSphere(Sphere()); }
128  AABB boundingRect() const;
129  AABB boundingRect(const String& text) const;
130  AABB boundingRectTransformed(vec3& a, vec3& b, vec3& c, vec3& d, const Camera* camera, const Actor* actor=NULL) const;
131  AABB boundingRectTransformed(const Camera* camera, const Actor* actor=NULL) const;
132 
133  void translate(float x, float y, float z);
134  void rotate(float degrees, float x, float y, float z);
135  void resetMatrix();
136 
137  // Renderable interface implementation.
138 
140 
141  virtual void deleteBufferObject() {}
142 
143  protected:
144  void renderText(const Actor*, const Camera* camera, const fvec4& color, const fvec2& offset) const;
145  void renderBackground(const Actor* actor, const Camera* camera) const;
146  void renderBorder(const Actor* actor, const Camera* camera) const;
147  AABB rawboundingRect(const String& text) const;
148 
149  protected:
150  mutable ref<Font> mFont;
162  int mMargin;
171  };
172 }
173 
174 #endif
Associates a Renderable object to an Effect and Transform.
Definition: Actor.hpp:130
void computeBounds_Implementation()
Definition: Text.hpp:127
int margin() const
Definition: Text.hpp:83
int mMargin
Definition: Text.hpp:162
int alignment() const
Definition: Text.hpp:93
void setShadowColor(const fvec4 &shadow_color)
Definition: Text.hpp:78
fvec4 mColor
Definition: Text.hpp:152
Font * font()
Definition: Text.hpp:87
ETextAlign mTextAlignment
Definition: Text.hpp:165
bool borderEnabled() const
Definition: Text.hpp:111
ETextLayout mLayout
Definition: Text.hpp:164
A Renderable that renders text with a given Font.
Definition: Text.hpp:50
int mViewportAlignment
Definition: Text.hpp:161
T degrees(T radians)
Definition: glsl_math.hpp:173
const fvec2 & shadowVector() const
Definition: Text.hpp:80
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
A font to be used with a Text renderable.
Definition: Font.hpp:127
fvec4 mOutlineColor
Definition: Text.hpp:155
bool mKerningEnabled
Definition: Text.hpp:170
fvec4 mShadowColor
Definition: Text.hpp:156
void setText(const String &text)
Definition: Text.hpp:63
String mText
Definition: Text.hpp:151
bool kerningEnabled() const
Definition: Text.hpp:117
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
fvec4 mBorderColor
Definition: Text.hpp:153
bool mShadowEnabled
Definition: Text.hpp:169
void setInterlineSpacing(float spacing)
Definition: Text.hpp:100
void setFont(Font *font)
Definition: Text.hpp:88
const fvec4 & backgroundColor() const
Definition: Text.hpp:74
void setBorderEnabled(bool border)
Definition: Text.hpp:112
bool outlineEnabled() const
Definition: Text.hpp:120
int viewportAlignment() const
Definition: Text.hpp:96
virtual void updateDirtyBufferObject(EBufferObjectUpdateMode)
Uploads the data stored in the local buffers on the GPU memory.
Definition: Text.hpp:139
ETextMode mode() const
Definition: Text.hpp:102
const fvec4 & borderColor() const
Definition: Text.hpp:68
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
int mAlignment
Definition: Text.hpp:160
const fvec4 & color() const
Definition: Text.hpp:65
Visualization Library main namespace.
ref< Font > mFont
Definition: Text.hpp:150
void setMode(ETextMode mode)
Definition: Text.hpp:103
void setKerningEnabled(bool kerning)
Definition: Text.hpp:118
void setBackgroundColor(const fvec4 &background_color)
Definition: Text.hpp:75
void setOutlineColor(const fvec4 &outline_color)
Definition: Text.hpp:72
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
virtual void deleteBufferObject()
Destroys the BufferObject (vertex buffer objects) associated to this a Renderable.
Definition: Text.hpp:141
float mInterlineSpacing
Definition: Text.hpp:159
ETextMode mMode
Definition: Text.hpp:163
bool backgroundEnabled() const
Definition: Text.hpp:114
void setShadowVector(const fvec2 &shadow_vector)
Definition: Text.hpp:81
ETextLayout
An abstract class that represents all the objects that can be rendered.
Definition: Renderable.hpp:58
bool mBackgroundEnabled
Definition: Text.hpp:167
ETextAlign
fvec4 mBackgroundColor
Definition: Text.hpp:154
bool mBorderEnabled
Definition: Text.hpp:166
bool shadowEnabled() const
Definition: Text.hpp:123
void setLayout(ETextLayout layout)
Definition: Text.hpp:106
EBufferObjectUpdateMode
#define NULL
Definition: OpenGLDefs.hpp:81
Manages most of the OpenGL rendering states responsible of the final aspect of the rendered objects...
Definition: Shader.hpp:1830
The Sphere class defines a sphere using a center and a radius using vl::real precision.
Definition: Sphere.hpp:43
Text()
Definition: Text.hpp:55
const fvec4 & outlineColor() const
Definition: Text.hpp:71
void setColor(const fvec4 &color)
Definition: Text.hpp:66
fmat4 mMatrix
Definition: Text.hpp:158
fvec2 mShadowVector
Definition: Text.hpp:157
void setShadowEnabled(bool shadow)
Definition: Text.hpp:124
void setMargin(int margin)
Definition: Text.hpp:84
const fvec4 & shadowColor() const
Definition: Text.hpp:77
void setViewportAlignment(int align)
Definition: Text.hpp:97
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
const String & text() const
Definition: Text.hpp:62
ETextAlign textAlignment() const
Definition: Text.hpp:108
const Font * font() const
Definition: Text.hpp:86
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:50
ETextLayout layout() const
Definition: Text.hpp:105
void setBorderColor(const fvec4 &border_color)
Definition: Text.hpp:69
void setAlignment(int align)
Definition: Text.hpp:94
Visualization Library&#39;s enums in the &#39;vl&#39; namespace.
void setMatrix(const fmat4 &matrix)
Definition: Text.hpp:91
const fmat4 matrix() const
Definition: Text.hpp:90
void setBackgroundEnabled(bool background)
Definition: Text.hpp:115
float interlineSpacing() const
Definition: Text.hpp:99
bool mOutlineEnabled
Definition: Text.hpp:168
void setTextAlignment(ETextAlign align)
Definition: Text.hpp:109
void setOutlineEnabled(bool outline)
Definition: Text.hpp:121