Debian Codegraph @

src/LomiriMetrics/bitmaptext_p.h

raw
1 // Copyright © 2016 Canonical Ltd.
2 // Author: Loïc Molinari <[email protected]>
3 //
4 // This file is part of Lomiri UI Toolkit.
5 //
6 // Lomiri UI Toolkit is free software: you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published by the
8 // Free Software Foundation; version 3.
9 //
10 // Lomiri UI Toolkit is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 // for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with Lomiri UI Toolkit. If not, see <http://www.gnu.org/licenses/>.
17
18 #ifndef BITMAPTEXT_P_H
19 #define BITMAPTEXT_P_H
20
21 #include <QtGui/QOpenGLFunctions>
22
23 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
24 #include <LomiriMetrics-Qt6/private/lomirimetricsglobal_p.h>
25 #else
26 #include <LomiriMetrics/private/lomirimetricsglobal_p.h>
27 #endif
28
29 // BitmapText renders a monospaced bitmap Latin-1 encoded text (128 characters)
30 // stored in a single texture atlas using OpenGL. The font is generated by
31 // bitmap-text-builder and stored in the bitmaptextfont_p.h header.
32 class LOMIRI_METRICS_PRIVATE_EXPORT BitmapText
33 {
34 public:
35 BitmapText();
36 ~BitmapText();
37
38 // Allocates/Deletes the OpenGL resources. finalize() is not called at
39 // destruction, it must be explicitly called to free the resources at the
40 // right time in a thread with the same OpenGL context bound than at
41 // initialize().
42 bool initialize();
43 void finalize();
44
45 // Sets the text. Characters below 32 and above 126 included are ignored
46 // apart from line feeds (10). Implies a reallocation of internal data. Must
47 // be called in a thread with the same OpenGL context bound than at
48 // initialize().
49 void setText(const char* text);
50
51 // Updates the current text at the given index. In order to avoid expensive
52 // layout updates, line feeds can't be added nor removed. Updates of
53 // characters below 32 and above 126 in the new text are ignored.
54 void updateText(const char* text, int index, int length);
55
56 // Binds the BitmapText's shader program. Must be called prior to
57 // setTransform, setOpacity and render calls.
58 void bindProgram();
59
60 // Sets the viewport size and text position. Origin is at top/left. Must be
61 // set correctly prior to rendering for correct results. Must be called in a
62 // thread with the same OpenGL context bound than at initialize().
63 void setTransform(const QSize& viewportSize, const QPointF& position);
64
65 // Sets the text opacity. Must be called in a thread with the same OpenGL
66 // context bound than at initialize().
67 void setOpacity(float opacity);
68
69 // Renders the text. Must be called in a thread with the same OpenGL context
70 // bound than at initialize().
71 void render();
72
73 private:
74 struct Vertex {
75 float x, y, s, t;
76 };
77 enum {
78 NotEmpty = (1 << 0),
79 #if !defined(QT_NO_DEBUG)
80 Initialized = (1 << 1)
81 #endif
82 };
83
84 QOpenGLFunctions* m_functions;
85 #if !defined QT_NO_DEBUG
86 QOpenGLContext* m_context;
87 #endif
88 Vertex* m_vertexBuffer;
89 int* m_textToVertexBuffer;
90 int m_textLength;
91 int m_characterCount;
92 int m_currentFont;
93 GLuint m_program;
94 GLint m_programTransform;
95 GLint m_programOpacity;
96 GLuint m_vertexShaderObject;
97 GLuint m_fragmentShaderObject;
98 GLuint m_texture;
99 GLuint m_indexBuffer;
100 quint8 m_flags;
101 };
102
103 #endif // BITMAPTEXT_P_H