Unravel Engine C++ Reference
Loading...
Searching...
No Matches
text_buffer_manager.h
Go to the documentation of this file.
1/*
2 * Copyright 2013 Jeremie Roy. All rights reserved.
3 * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
4 */
5
6#ifndef TEXT_BUFFER_MANAGER_H_HEADER_GUARD
7#define TEXT_BUFFER_MANAGER_H_HEADER_GUARD
8
9#include "font_manager.h"
10
11namespace gfx
12{
13BGFX_HANDLE(text_buffer_handle)
14
15#define MAX_TEXT_BUFFER_COUNT 1024
16
19{
26};
27
38
40{
41 float width{}, height{};
42};
43
44class text_buffer;
46{
47public:
50
51 auto create_text_buffer(uint32_t type, buffer_type::Enum btype) -> text_buffer_handle;
52 void destroy_text_buffer(text_buffer_handle handle);
53 void submit_text_buffer(text_buffer_handle handle,
54 font_handle fhandle,
55 bgfx::ViewId id,
56 uint64_t state = 0,
57 int32_t depth = 0);
58
59 void set_style(text_buffer_handle handle, uint32_t flags = style_normal);
60 void set_text_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
61 void set_background_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
62 void set_foreground_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
63
64 void set_overline_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
65 void set_underline_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
66 void set_strike_through_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
67
68 void set_outline_width(text_buffer_handle handle, float outline_width = 3.0f);
69 void set_outline_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
70
71 void set_drop_shadow_offset(text_buffer_handle handle, float u, float v);
72 void set_drop_shadow_color(text_buffer_handle handle, uint32_t rgba = 0x000000FF);
73 void set_drop_shadow_softener(text_buffer_handle handle, float smoother = 1.0f);
74
75 void set_pen_origin(text_buffer_handle handle, float x, float y);
76 void set_pen_position(text_buffer_handle handle, float x, float y);
77 void get_pen_position(text_buffer_handle handle, float* x, float* y);
78
79 void set_apply_kerning(text_buffer_handle handle, bool apply_kerning);
80
82 void append_text(text_buffer_handle handle, font_handle fhandle, const char* string, const char* end = nullptr);
83
85 void append_text(text_buffer_handle handle,
86 font_handle fhandle,
87 const wchar_t* string,
88 const wchar_t* end = nullptr);
89
91 void append_atlas_face(text_buffer_handle handle, font_handle fhandle, uint16_t face_index);
92
94 void clear_text_buffer(text_buffer_handle handle);
95
97 auto get_rectangle(text_buffer_handle handle) const -> text_rectangle;
98
99private:
100 struct buffer_cache
101 {
102 uint16_t index_buffer_handle_idx{};
103 uint16_t vertex_buffer_handle_idx{};
104 text_buffer* buffer{};
106 uint32_t font_type{};
107 };
108
109 buffer_cache* text_buffers_ = new buffer_cache[MAX_TEXT_BUFFER_COUNT];
110 bx::HandleAllocT<MAX_TEXT_BUFFER_COUNT> text_buffer_handles_;
111 font_manager* font_manager_{};
112 bgfx::VertexLayout vertex_layout_;
113 bgfx::UniformHandle s_tex_color_;
114 bgfx::UniformHandle u_drop_shadow_color_;
115 bgfx::UniformHandle u_params_;
116 bgfx::ProgramHandle basic_program_;
117 bgfx::ProgramHandle distance_program_;
118 bgfx::ProgramHandle distance_subpixel_program_;
119 bgfx::ProgramHandle distance_outline_program_;
120 bgfx::ProgramHandle distance_outline_image_program_;
121 bgfx::ProgramHandle distance_drop_shadow_program_;
122 bgfx::ProgramHandle distance_drop_shadow_image_program_;
123 bgfx::ProgramHandle distance_outline_drop_shadow_image_program_;
124};
125} // namespace gfx
126#endif // TEXT_BUFFER_MANAGER_H_HEADER_GUARD
manifold_type type
void set_pen_origin(text_buffer_handle handle, float x, float y)
void set_foreground_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
void destroy_text_buffer(text_buffer_handle handle)
void set_strike_through_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
void set_drop_shadow_softener(text_buffer_handle handle, float smoother=1.0f)
auto create_text_buffer(uint32_t type, buffer_type::Enum btype) -> text_buffer_handle
void set_style(text_buffer_handle handle, uint32_t flags=style_normal)
void clear_text_buffer(text_buffer_handle handle)
Clear the text buffer and reset its state (pen/color).
void set_outline_width(text_buffer_handle handle, float outline_width=3.0f)
void set_drop_shadow_offset(text_buffer_handle handle, float u, float v)
text_buffer_manager(font_manager *font_manager)
void submit_text_buffer(text_buffer_handle handle, font_handle fhandle, bgfx::ViewId id, uint64_t state=0, int32_t depth=0)
void set_drop_shadow_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
void set_apply_kerning(text_buffer_handle handle, bool apply_kerning)
void set_text_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
void set_background_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
void append_text(text_buffer_handle handle, font_handle fhandle, const char *string, const char *end=nullptr)
Append an ASCII/utf-8 string to the buffer using current pen position and color.
void get_pen_position(text_buffer_handle handle, float *x, float *y)
void set_pen_position(text_buffer_handle handle, float x, float y)
void set_underline_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
void set_outline_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
void set_overline_color(text_buffer_handle handle, uint32_t rgba=0x000000FF)
auto get_rectangle(text_buffer_handle handle) const -> text_rectangle
Return the rectangular size of the current text buffer (including all its content).
void append_atlas_face(text_buffer_handle handle, font_handle fhandle, uint16_t face_index)
Append a whole face of the atlas cube, mostly used for debugging and visualizing atlas.
text_style_flags
special style effect (can be combined)
@ style_strike_through
void end(encoder *_encoder)
Definition graphics.cpp:270
float y
float x
type of vertex and index buffer to use with a TextBuffer
#define MAX_TEXT_BUFFER_COUNT
gfx::uniform_handle handle
Definition uniform.cpp:9