diff options
author | Frederico Linhares <fred@linhares.blue> | 2025-08-14 20:29:46 -0300 |
---|---|---|
committer | Frederico Linhares <fred@linhares.blue> | 2025-08-14 20:29:46 -0300 |
commit | 1bf7b0621d2b47b33fe2bfc9218094131d49d54f (patch) | |
tree | 6dd7ca186ff2f357a6b7dbde5868f79462d8fe6b /src | |
parent | 0109e0b57d0a7ee211952a838719a69a68db6af6 (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/blu_cat/gra/text.cpp | 50 | ||||
-rw-r--r-- | src/blu_cat/gra/text.hpp | 4 |
2 files changed, 44 insertions, 10 deletions
diff --git a/src/blu_cat/gra/text.cpp b/src/blu_cat/gra/text.cpp index 4f8a31a..42341a3 100644 --- a/src/blu_cat/gra/text.cpp +++ b/src/blu_cat/gra/text.cpp @@ -22,27 +22,59 @@ namespace BluCat::GRA { Text::Text( - const BitmapFont &font, const char *str, const I32F x, const I32F y): + const BitmapFont &font, const char *str, const I32F x, const I32F y, + F32 z_index): x{x}, y{y}, - height{font.height}, - z_index{4.5f} + width{0}, + height{0}, + z_index{z_index} { const std::vector<UI32> text{BluCat::GRA::Character::str_to_unicode(str)}; - this->width = text.size() * font.width; + this->letters.reserve(text.size()); + + I32F current_column{0}; + I32F current_line{0}; for(I32F index{0}; index < text.size(); index++) { - if(str[index] == 32) continue; + switch(str[index]) + { + case 10: + if((current_column + 1) * font.width > this->width) + this->width = (current_column + 1) * font.width; + current_column = 0; + current_line++; + continue; + + case 32: + current_column++; + continue; + } glm::vec4 rect{ - x + index * font.width, - y, - x + (index + 1) * font.width, - y + font.height}; + x + current_column * font.width, + y + current_line * font.height, + x + (current_column + 1) * font.width, + y + (current_line + 1) * font.height}; this->letters.emplace_back(font.characters.at(text[index]).sprite, rect); + current_column++; } + + if((current_column + 1) * font.width > this->width) + this->width = (current_column + 1) * font.width; + this->height = font.height * (current_line + 1); +} + +Text::Text(): + letters(0), + x{0}, + y{0}, + width{0}, + height{0}, + z_index{4.5f} +{ } void diff --git a/src/blu_cat/gra/text.hpp b/src/blu_cat/gra/text.hpp index dc085e9..5b7dcde 100644 --- a/src/blu_cat/gra/text.hpp +++ b/src/blu_cat/gra/text.hpp @@ -34,7 +34,9 @@ struct Text I32F x, y, width, height; F32 z_index; - Text(const BitmapFont &font, const char *str, const I32F x, const I32F y); + Text(const BitmapFont &font, const char *str, const I32F x, const I32F y, + F32 z_index); + Text(); void draw(); |