SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLText.h
Go to the documentation of this file.
1 /**
2  * \file SLText.h
3  * \authors Marcus Hudritsch
4  * \date July 2014
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #ifndef SLTEXT_H
12 #define SLTEXT_H
13 
14 #include <SLGLVertexArray.h>
15 #include <SLNode.h>
16 #include <SLTexFont.h>
17 
18 class SLSceneView;
19 class SLRay;
20 class SLAABBox;
21 
22 //-----------------------------------------------------------------------------
23 //! SLText creates a mesh using a textured font from SLTexFont
24 /*!
25 The text is passed as standard string that can contain line breaks (\\n).
26 Line breaks are only inserted if a maxWidth is defined. If the lineHeightFactor
27 is 1.0 the minimal line spacing is used.
28 */
29 class SLText : public SLNode
30 {
31 public:
33  SLTexFont* font, // = SLTexFont::font09,
34  SLCol4f txtCol = SLCol4f::WHITE,
35  SLfloat maxWidth = 0.0f,
36  SLfloat lineHeightFactor = 1.3f);
37 
38  ~SLText() { ; }
39 
40  void drawText(SLSceneView* sv);
41  void statsRec(SLNodeStats& stats) override;
42  SLAABBox& updateAABBRec(SLbool updateAlsoAABBinOS) override;
43  SLbool hitRec(SLRay* ray) override { return false; }
44  void drawMesh(SLSceneView* sv) override { drawText(sv); };
45  void preShade(SLRay* ray) { ; }
46 
47  // Getters
48  SLstring text() { return _text; }
49  SLCol4f color() { return _color; }
51  _maxW,
52  _lineH); }
54  SLint length() { return (SLint)_text.length(); }
55 
56 protected:
57  SLstring _text; //!< Text of the button
58  SLTexFont* _font; //!< Font pointer of the preloaded font
59  SLCol4f _color; //!< RGBA-Color of the text
60  SLfloat _maxW; //!< Max. width in pix. for wrapped text
61  SLfloat _lineH; //!< Line height factor for wrapped text
62  SLGLVertexArray _vao; //!< Vertex array for rendering
63 };
64 //-----------------------------------------------------------------------------
65 #endif
float SLfloat
Definition: SL.h:173
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
Wrapper class around OpenGL Vertex Array Objects (VAO)
Defines an axis aligned bounding box.
Definition: SLAABBox.h:34
SLGLVertexArray encapsulates the core OpenGL drawing.
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
Ray class with ray and intersection properties.
Definition: SLRay.h:40
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
Texture Font class inherits SLGLTexture for alpha blended font rendering.
Definition: SLTexFont.h:40
SLint charsHeight
Definition: SLTexFont.h:69
SLVec2f calcTextSize(const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.5f)
Definition: SLTexFont.cpp:243
SLText creates a mesh using a textured font from SLTexFont.
Definition: SLText.h:30
SLstring text()
Definition: SLText.h:48
void drawMesh(SLSceneView *sv) override
Draws the single mesh.
Definition: SLText.h:44
SLfloat _lineH
Line height factor for wrapped text.
Definition: SLText.h:61
~SLText()
Definition: SLText.h:38
SLbool hitRec(SLRay *ray) override
Definition: SLText.h:43
void drawText(SLSceneView *sv)
Definition: SLText.cpp:46
SLVec2f size()
Definition: SLText.h:50
SLstring _text
Text of the button.
Definition: SLText.h:57
SLGLVertexArray _vao
Vertex array for rendering.
Definition: SLText.h:62
SLText(SLstring text, SLTexFont *font, SLCol4f txtCol=SLCol4f::WHITE, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.3f)
Construct a new SLText::SLText object.
Definition: SLText.cpp:28
void statsRec(SLNodeStats &stats) override
Definition: SLText.cpp:76
void preShade(SLRay *ray)
Definition: SLText.h:45
SLCol4f color()
Definition: SLText.h:49
SLfloat fontHeightPX()
Definition: SLText.h:53
SLint length()
Definition: SLText.h:54
SLTexFont * _font
Font pointer of the preloaded font.
Definition: SLText.h:58
SLfloat _maxW
Max. width in pix. for wrapped text.
Definition: SLText.h:60
SLCol4f _color
RGBA-Color of the text.
Definition: SLText.h:59
SLAABBox & updateAABBRec(SLbool updateAlsoAABBinOS) override
Definition: SLText.cpp:87
static SLVec4 WHITE
Definition: SLVec4.h:215
Struct for scene graph statistics.
Definition: SLNode.h:37