/
gltextcomposer.h
135 lines (115 loc) · 4.27 KB
/
gltextcomposer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/** @file gltextcomposer.h
*
* @authors Copyright (c) 2013-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBAPPFW_GLTEXTCOMPOSER_H
#define LIBAPPFW_GLTEXTCOMPOSER_H
#include <QVector>
#include <de/Font>
#include <de/Atlas>
#include <de/GLBuffer>
#include <de/Painter>
#include "../ui/defs.h"
#include "../FontLineWrapping"
namespace de {
/**
* Allocates and releases lines of text on an atlas and produces geometry for
* drawing the text.
*
* Relies on a pre-existing FontLineWrapping where the text content has been
* wrapped onto multiple lines and laid out appropriately.
*
* @ingroup appfw
*/
class LIBAPPFW_PUBLIC GLTextComposer : public Asset
{
/*public:
typedef Vertex2TexRgba Vertex;
typedef GLBufferT<Vertex> VertexBuf;
typedef VertexBuf::Builder Vertices;*/
public:
GLTextComposer();
void setAtlas(Atlas &atlas);
void setWrapping(FontLineWrapping const &wrappedLines);
void setText(String const &text);
void setStyledText(String const &styledText);
void setText(String const &text, Font::RichFormat const &format);
/**
* Sets the range of visible lines.
*
* @param visibleLineRange Visible range of lines.
*/
void setRange(Rangei const &visibleLineRange);
Rangei range() const;
/**
* Makes sure all the lines are allocated on the atlas. After this all the
* allocated lines match the ones in the wrapping. This must be called
* before makeVertices().
*
* @return @c true, if any allocations were changed and makeVertices()
* should be called again.
*/
bool update();
/**
* Forces all the text to be rerasterized.
*/
void forceUpdate();
/**
* Releases all the allocations from the atlas.
*/
void release();
/**
* Releases the allocated lines that are outside the current range.
*/
void releaseLinesOutsideRange();
void makeVertices(GuiVertexBuilder &triStrip,
Vector2i const &topLeft,
ui::Alignment const &lineAlign,
Vector4f const &color = Vector4f(1, 1, 1, 1));
/**
* Generates vertices for all the text lines and concatenates them onto the existing
* triangle strip in @a triStrip.
*
* @param triStrip Vertices for a triangle strip.
* @param rect Rectangle inside which the text will be placed.
* @param alignInRect Alignment within @a rect.
* @param lineAlign Horizontal alignment for each line within the paragraph.
* @param color Vertex color for the generated vertices.
*/
void makeVertices(GuiVertexBuilder &triStrip,
Rectanglei const &rect,
ui::Alignment const &alignInRect,
ui::Alignment const &lineAlign,
Vector4f const &color = Vector4f(1, 1, 1, 1));
/**
* Returns the maximum width of the generated vertices. This is only valid after
* makeVertices() has been called.
*
* This may be larger than the maximum width as determined by FontLineWrapping if
* tabbed lines are used in the text. This is because text segments are aligned
* with tab stops only during makeVertices().
*
* @todo Ideally tab stop alignment should be done in FontLineWrapping, so that the
* maximum width would be known prior to generating the vertices.
*
* @return Maximum width of the generated vertices.
*/
int verticesMaxWidth() const;
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif // LIBAPPFW_GLTEXTCOMPOSER_H