text width and height
parent
595917d0b5
commit
3610837803
|
@ -1,7 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
include(FetchContent)
|
||||
|
||||
set(BLT_GRAPHICS_VERSION 1.1.2)
|
||||
set(BLT_GRAPHICS_VERSION 1.1.3)
|
||||
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
|
||||
|
||||
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
||||
|
|
|
@ -122,6 +122,8 @@ namespace blt::gfx
|
|||
static constexpr blt::vec2f DEFAULT_SCALE{1, 1};
|
||||
static constexpr blt::vec4 DEFAULT_COLOR = blt::make_color(0.8, 0.8, 0.8);
|
||||
|
||||
struct compiled_text_t;
|
||||
|
||||
struct render_context_t
|
||||
{
|
||||
blt::vec2f position, bounds;
|
||||
|
@ -130,9 +132,14 @@ namespace blt::gfx
|
|||
float current_size = 0;
|
||||
float rotation = 0;
|
||||
|
||||
explicit render_context_t(float current_size): current_size(current_size)
|
||||
compiled_text_t* text_ptr;
|
||||
|
||||
explicit render_context_t(float current_size, compiled_text_t* associated_text): current_size(current_size), text_ptr(associated_text)
|
||||
{}
|
||||
|
||||
[[nodiscard]] compiled_text_t& getAssociatedText() const
|
||||
{ return *text_ptr; }
|
||||
|
||||
render_context_t& setPosition(float x, float y)
|
||||
{
|
||||
position = {x, y};
|
||||
|
@ -312,6 +319,12 @@ namespace blt::gfx
|
|||
[[nodiscard]] float getRotation() const
|
||||
{ return rotation; }
|
||||
|
||||
[[nodiscard]] float getTextWidth() const
|
||||
{ return text_width; }
|
||||
|
||||
[[nodiscard]] float getTextHeight() const
|
||||
{ return text_height; }
|
||||
|
||||
void save_to(render_context_t& save)
|
||||
{
|
||||
save.position = position;
|
||||
|
@ -363,6 +376,8 @@ namespace blt::gfx
|
|||
float z_index = 0;
|
||||
float current_size = 0;
|
||||
float rotation = 0;
|
||||
float text_width = 0;
|
||||
float text_height = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
|
@ -218,7 +218,7 @@ namespace blt::gfx
|
|||
for (auto& [text, list] : render_list)
|
||||
{
|
||||
text->bind();
|
||||
render_context_t before{text->current_size};
|
||||
render_context_t before{text->current_size, text};
|
||||
text->save_to(before);
|
||||
for (const auto& context : list)
|
||||
{
|
||||
|
@ -310,7 +310,7 @@ namespace blt::gfx
|
|||
}
|
||||
|
||||
auto& vec = render_list[ptr];
|
||||
vec.emplace_back(size);
|
||||
vec.emplace_back(size, ptr);
|
||||
return vec.back();
|
||||
}
|
||||
|
||||
|
@ -427,6 +427,8 @@ namespace blt::gfx
|
|||
draw_count += 6;
|
||||
global_x += static_cast<float>(ch.glyph.advance >> 6);
|
||||
}
|
||||
text_width = global_x * scale.x();
|
||||
text_height = -(global_y - generator.get_generated_size()) * scale.y();
|
||||
|
||||
// BLT_TRACE("size: %ld %ld %ld", draw_count, vertices.size(), vertices.size() / 4);
|
||||
|
||||
|
|
Loading…
Reference in New Issue