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]
CoreText.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 CoreText_INCLUDE_ONCE
33 #define CoreText_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 {
48  {
50 
51  public:
52  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),
53  mTextOrigin(AlignBottom|AlignLeft), mMargin(5), mLayout(LeftToRightText), mTextAlignment(TextAlignLeft),
54  mBorderEnabled(false), mBackgroundEnabled(false), mOutlineEnabled(false), mShadowEnabled(false), mKerningEnabled(true)
55  {
56  VL_DEBUG_SET_OBJECT_NAME()
57  }
58 
60  const String& text() const { return mText; }
62  void setText(const String& text) { mText = text; }
63 
65  const fvec4& color() const { return mColor; }
67  void setColor(const fvec4& color) { mColor = color; }
68 
70  int margin() const { return mMargin; }
72  void setMargin(int margin) { mMargin = margin; }
73 
75  const Font* font() const { return mFont.get(); }
77  Font* font() { return mFont.get(); }
79  void setFont(Font* font) { mFont = font; }
80 
82  ETextLayout layout() const { return mLayout; }
84  void setLayout(ETextLayout layout) { mLayout = layout; }
85 
87  ETextAlign textAlignment() const { return mTextAlignment; }
89  void setTextAlignment(ETextAlign align) { mTextAlignment = align; }
90 
92  int textOrigin() const { return mTextOrigin; }
94  void setTextOrigin(int align) { mTextOrigin = align; }
95 
97  bool kerningEnabled() const { return mKerningEnabled; }
99  void setKerningEnabled(bool kerning) { mKerningEnabled = kerning; }
100 
102  bool borderEnabled() const { return mBorderEnabled; }
104  void setBorderEnabled(bool border) { mBorderEnabled = border; }
105 
107  const fvec4& borderColor() const { return mBorderColor; }
109  void setBorderColor(const fvec4& border_color) { mBorderColor = border_color; }
110 
112  bool backgroundEnabled() const { return mBackgroundEnabled; }
114  void setBackgroundEnabled(bool background) { mBackgroundEnabled = background; }
115 
117  const fvec4& backgroundColor() const { return mBackgroundColor; }
119  void setBackgroundColor(const fvec4& background_color) { mBackgroundColor = background_color; }
120 
122  bool outlineEnabled() const { return mOutlineEnabled; }
124  void setOutlineEnabled(bool outline) { mOutlineEnabled = outline; }
125 
127  const fvec4& outlineColor() const { return mOutlineColor; }
129  void setOutlineColor(const fvec4& outline_color) { mOutlineColor = outline_color; }
130 
132  bool shadowEnabled() const { return mShadowEnabled; }
134  void setShadowEnabled(bool shadow) { mShadowEnabled = shadow; }
135 
137  const fvec4& shadowColor() const { return mShadowColor; }
139  void setShadowColor(const fvec4& shadow_color) { mShadowColor = shadow_color; }
140 
142  const fvec2& shadowVector() const { return mShadowVector; }
144  void setShadowVector(const fvec2& shadow_vector) { mShadowVector = shadow_vector; }
145 
147  AABB boundingRect() const;
148 
150  AABB boundingRect(const String& text) const;
151 
152  // --- Renderable interface implementation ---
153 
155 
156  virtual void deleteBufferObject() {}
157 
158  protected:
159  virtual void render_Implementation(const Actor* actor, const Shader* shader, const Camera* camera, OpenGLContext* gl_context) const;
160  void computeBounds_Implementation() { setBoundingBox(AABB()); setBoundingSphere(Sphere()); }
161 
162  void renderText(const Actor*, const Camera* camera, const fvec4& color, const fvec2& offset) const;
163  void renderBackground(const Actor* actor, const Camera* camera) const;
164  void renderBorder(const Actor* actor, const Camera* camera) const;
165  AABB rawboundingRect(const String& text) const;
166 
167  protected:
168  mutable ref<Font> mFont;
177  int mMargin;
185  };
186 }
187 
188 #endif
Associates a Renderable object to an Effect and Transform.
Definition: Actor.hpp:130
Experimental.
Definition: CoreText.hpp:47
void setKerningEnabled(bool kerning)
If enabled text rendering uses kerning information for better quality results (slower).
Definition: CoreText.hpp:99
const fvec4 & borderColor() const
The color of the rectangular border.
Definition: CoreText.hpp:107
void setOutlineColor(const fvec4 &outline_color)
The color of the character outline.
Definition: CoreText.hpp:129
void setBorderEnabled(bool border)
If true draws a rectangular border around the text.
Definition: CoreText.hpp:104
bool borderEnabled() const
If true draws a rectangular border around the text.
Definition: CoreText.hpp:102
ETextLayout layout() const
Text layout: left to right, right to left.
Definition: CoreText.hpp:82
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
void setShadowColor(const fvec4 &shadow_color)
The color of the text shadow.
Definition: CoreText.hpp:139
virtual void deleteBufferObject()
Destroys the BufferObject (vertex buffer objects) associated to this a Renderable.
Definition: CoreText.hpp:156
void setTextAlignment(ETextAlign align)
Text alignment: left, right, center, justify.
Definition: CoreText.hpp:89
bool mKerningEnabled
Definition: CoreText.hpp:184
void setLayout(ETextLayout layout)
Text layout: left to right, right to left.
Definition: CoreText.hpp:84
void setBackgroundEnabled(bool background)
If true draws a rectangular background below the text.
Definition: CoreText.hpp:114
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
void computeBounds_Implementation()
Definition: CoreText.hpp:160
ETextLayout mLayout
Definition: CoreText.hpp:178
int textOrigin() const
The origin of the text (pivot point for offsetting and rotations).
Definition: CoreText.hpp:92
int margin() const
The margin to be left around the text.
Definition: CoreText.hpp:70
void setFont(Font *font)
The font to be used to render the text.
Definition: CoreText.hpp:79
const fvec4 & backgroundColor() const
The color of the rectangular background.
Definition: CoreText.hpp:117
void setShadowVector(const fvec2 &shadow_vector)
The offset vector of the shadow.
Definition: CoreText.hpp:144
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
fvec4 mShadowColor
Definition: CoreText.hpp:174
Visualization Library main namespace.
bool mShadowEnabled
Definition: CoreText.hpp:183
void setText(const String &text)
The text to be rendered.
Definition: CoreText.hpp:62
void setBackgroundColor(const fvec4 &background_color)
The color of the rectangular background.
Definition: CoreText.hpp:119
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
const fvec4 & color() const
The color of the text.
Definition: CoreText.hpp:65
ETextAlign textAlignment() const
Text alignment: left, right, center, justify.
Definition: CoreText.hpp:87
virtual void updateDirtyBufferObject(EBufferObjectUpdateMode)
Uploads the data stored in the local buffers on the GPU memory.
Definition: CoreText.hpp:154
bool kerningEnabled() const
If enabled text rendering uses kerning information for better quality results (slower).
Definition: CoreText.hpp:97
ETextLayout
An abstract class that represents all the objects that can be rendered.
Definition: Renderable.hpp:58
ETextAlign
const fvec4 & outlineColor() const
The color of the character outline.
Definition: CoreText.hpp:127
void setBorderColor(const fvec4 &border_color)
The color of the rectangular border.
Definition: CoreText.hpp:109
void setColor(const fvec4 &color)
The color of the text.
Definition: CoreText.hpp:67
EBufferObjectUpdateMode
bool outlineEnabled() const
If true the characters are drawn with an outline.
Definition: CoreText.hpp:122
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
bool mOutlineEnabled
Definition: CoreText.hpp:182
const fvec4 & shadowColor() const
The color of the text shadow.
Definition: CoreText.hpp:137
ETextAlign mTextAlignment
Definition: CoreText.hpp:179
fvec4 mColor
Definition: CoreText.hpp:170
void setTextOrigin(int align)
The origin of the text (pivot point for offsetting and rotations).
Definition: CoreText.hpp:94
const fvec2 & shadowVector() const
The offset vector of the shadow.
Definition: CoreText.hpp:142
bool mBorderEnabled
Definition: CoreText.hpp:180
fvec4 mOutlineColor
Definition: CoreText.hpp:173
bool backgroundEnabled() const
If true draws a rectangular background below the text.
Definition: CoreText.hpp:112
bool mBackgroundEnabled
Definition: CoreText.hpp:181
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
Font * font()
The font to be used to render the text.
Definition: CoreText.hpp:77
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:50
bool shadowEnabled() const
If true a sort of shadow is rendered below the text.
Definition: CoreText.hpp:132
String mText
Definition: CoreText.hpp:169
const Font * font() const
The font to be used to render the text.
Definition: CoreText.hpp:75
fvec4 mBorderColor
Definition: CoreText.hpp:171
Visualization Library&#39;s enums in the &#39;vl&#39; namespace.
fvec2 mShadowVector
Definition: CoreText.hpp:175
ref< Font > mFont
Definition: CoreText.hpp:168
void setShadowEnabled(bool shadow)
If true a sort of shadow is rendered below the text.
Definition: CoreText.hpp:134
fvec4 mBackgroundColor
Definition: CoreText.hpp:172
const String & text() const
The text to be rendered.
Definition: CoreText.hpp:60
void setOutlineEnabled(bool outline)
If true the characters are drawn with an outline.
Definition: CoreText.hpp:124
void setMargin(int margin)
The margin to be left around the text.
Definition: CoreText.hpp:72