Visual Computing Library
Loading...
Searching...
No Matches
text_buffer_manager.h
1/*
2 * Copyright 2013 Jeremie Roy. All rights reserved.
3 * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
4 */
5
6#ifndef VCL_BGFX_TEXT_FONT_TEXT_BUFFER_MANAGER_H
7#define VCL_BGFX_TEXT_FONT_TEXT_BUFFER_MANAGER_H
8
9#include "font_manager.h"
10
11namespace bgfx {
12
13BGFX_HANDLE(TextBufferHandle)
14
15#define MAX_TEXT_BUFFER_COUNT 64
16
18struct BufferType
19{
20 enum Enum
21 {
22 Static,
23 Dynamic,
24 Transient,
25 };
26};
27
29enum TextStyleFlags
30{
31 STYLE_NORMAL = 0,
32 STYLE_OVERLINE = 1,
33 STYLE_UNDERLINE = 1 << 1,
34 STYLE_STRIKE_THROUGH = 1 << 2,
35 STYLE_BACKGROUND = 1 << 3,
36};
37
38struct TextRectangle
39{
40 float width, height;
41};
42
43class TextBuffer;
44class TextBufferManager
45{
46public:
47 TextBufferManager(FontManager* _fontManager);
48 ~TextBufferManager();
49
50 TextBufferHandle createTextBuffer(uint32_t _type, BufferType::Enum _bufferType);
51 void destroyTextBuffer(TextBufferHandle _handle);
52 void submitTextBuffer(TextBufferHandle _handle, bgfx::ViewId _id, int32_t _depth = 0);
53
54 void setStyle(TextBufferHandle _handle, uint32_t _flags = STYLE_NORMAL);
55 void setTextColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
56 void setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
57
58 void setOverlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
59 void setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
60 void setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
61
62 void setOutlineWidth(TextBufferHandle _handle, float _outlineWidth = 3.0f);
63 void setOutlineColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
64
65 void setDropShadowOffset(TextBufferHandle _handle, float _u, float _v);
66 void setDropShadowColor(TextBufferHandle _handle, uint32_t _rgba = 0x000000FF);
67 void setDropShadowSoftener(TextBufferHandle _handle, float smoother = 1.0f);
68
69 void setPenPosition(TextBufferHandle _handle, float _x, float _y);
70
72 void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char* _string, const char* _end = NULL);
73
75 void appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t* _string, const wchar_t* _end = NULL);
76
78 void appendAtlasFace(TextBufferHandle _handle, uint16_t _faceIndex);
79
81 void clearTextBuffer(TextBufferHandle _handle);
82
84 TextRectangle getRectangle(TextBufferHandle _handle) const;
85
86private:
87 struct BufferCache
88 {
89 uint16_t indexBufferHandleIdx;
90 uint16_t vertexBufferHandleIdx;
91 TextBuffer* textBuffer;
92 BufferType::Enum bufferType;
93 uint32_t fontType;
94 };
95
96 BufferCache* m_textBuffers;
97 bx::HandleAllocT<MAX_TEXT_BUFFER_COUNT> m_textBufferHandles;
98 FontManager* m_fontManager;
99 bgfx::VertexLayout m_vertexLayout;
100 bgfx::UniformHandle s_texColor;
101 bgfx::UniformHandle u_dropShadowColor;
102 bgfx::UniformHandle u_params;
103};
104
105} // namespace bgfx
106
107#endif // VCL_BGFX_TEXT_FONT_TEXT_BUFFER_MANAGER_H