Euphoria
font.h
Go to the documentation of this file.
1#pragma once
2
3
4#include <map>
5#include <memory>
6
7#include "base/vec2.h"
8#include "base/vec3.h"
9#include "base/colors.h"
10#include "base/rect.h"
11
12#include "core/loadedfont.h"
13// #include "core/ui_text.h"
14
15#include "render/texture.h"
16
17
18namespace eu::render
19{
20 struct SpriteBatch;
21
22 // todo(Gustav): separate rendering and the rest and move to core
23
24 struct Glyph
25 {
26 Rect sprite_rect; // relative to 0,0
27 Rect texture_rect; // image texture uvs
28 int code_point; // the character or string id
29 float advance;
30
32 (
33 const Rect& sprite,
34 const Rect& texture,
35 int ch,
36 float ad
37 );
38 };
39
40 using CharToGlyphMap = std::map<int, std::shared_ptr<Glyph>>;
41
42 struct DrawableFont;
43
56
57
59 {
63 bool hi;
64
66 (
67 const Texture2d* texture,
68 const Rect& sprite_rect,
69 const Rect& texture_rect,
70 bool hi
71 );
72 };
73
74
76 {
77 std::vector<TextDrawCommand> commands;
78
79 void
81 (
82 const Texture2d* texture,
83 const Rect& sprite_rect,
84 const Rect& texture_rect,
85 bool hi
86 );
87
88 void
90 (
92 const v2& start_position,
93 const Rgb& base_color,
94 const Rgb& hi_color
95 );
96
97 [[nodiscard]] Rect
98 get_extents() const;
99 };
100
101
103 {
104 public:
107
109 void operator=(const DrawableText&) = delete;
111 void operator=(DrawableText&&) = delete;
112
113 void
114 set_text(const std::string& new_text);
115
116 void
118
119 void
121
122 void
124
125 void
127 (
129 const v2& p,
130 const Rgb& base_hi_color
131 ) const;
132
133 void
135 (
137 const v2& p,
138 const Rgb& base_color,
139 const Rgb& hi_color
140 ) const;
141
142 Rect
143 get_extents() const;
144
145 void
146 compile() const;
147
148 private:
149 const DrawableFont* font;
150 float size;
151 std::string text;
152 Align alignment;
153
154 bool use_background;
155 float background_alpha;
156
157 // updated in Compile function
158 mutable bool is_dirty;
159 mutable ListOfTextDrawCommands commands;
160 };
161
162
164
165
167 {
168 float line_height = 1;
169 std::unique_ptr<Texture2d> texture;
172 std::map<std::string, int> private_use_aliases;
173
175 (
177 );
178
179 // todo(Gustav): expose background property and move this away from font
180 void
182 (
184 float alpha,
185 const Rect& where
186 ) const;
187
189 (const std::string& text, float size) const;
190 };
191}
std::map< std::pair< int, int >, float > KerningMap
Definition loadedfont.h:45
std::map< int, std::shared_ptr< Glyph > > CharToGlyphMap
Definition font.h:40
A (inclusive) range between two values.
Definition range.h:19
Represents color in gamma (non-linear) space (aka sRGB).
Definition colors.h:14
core::KerningMap kernings
Definition font.h:171
CharToGlyphMap char_to_glyph
Definition font.h:170
std::map< std::string, int > private_use_aliases
Definition font.h:172
DrawableFont(const MemoryChunk &font_file)
std::unique_ptr< Texture2d > texture
Definition font.h:169
void draw_background(SpriteBatch *renderer, float alpha, const Rect &where) const
ListOfTextDrawCommands compile_list(const std::string &text, float size) const
void set_text(const std::string &new_text)
DrawableText(DrawableFont *the_font)
void operator=(DrawableText &&)=delete
DrawableText(DrawableText &&other)=delete
void set_size(float new_size)
void operator=(const DrawableText &)=delete
void set_background(bool new_use_background, float new_alpha=0.5f)
void draw(SpriteBatch *renderer, const v2 &p, const Rgb &base_hi_color) const
DrawableText(const DrawableText &other)=delete
void set_alignment(Align new_alignment)
void draw(SpriteBatch *renderer, const v2 &p, const Rgb &base_color, const Rgb &hi_color) const
Rect sprite_rect
Definition font.h:26
float advance
Definition font.h:29
Rect texture_rect
Definition font.h:27
Glyph(const Rect &sprite, const Rect &texture, int ch, float ad)
void draw(SpriteBatch *renderer, const v2 &start_position, const Rgb &base_color, const Rgb &hi_color)
std::vector< TextDrawCommand > commands
Definition font.h:77
void add(const Texture2d *texture, const Rect &sprite_rect, const Rect &texture_rect, bool hi)
const Texture2d * texture
Definition font.h:60
TextDrawCommand(const Texture2d *texture, const Rect &sprite_rect, const Rect &texture_rect, bool hi)
A 2d image texture.
Definition texture.h:89
a 2d vector
Definition vec2.h:17