Display text

This commit is contained in:
2023-12-01 14:31:32 -05:00
parent 90731c1e52
commit cd9f90bcd4
4 changed files with 43 additions and 23 deletions

View File

@@ -4,8 +4,8 @@
namespace JabyEngine {
class FontWriter {
private:
GPU::TexPage::Linked tex_page;
FontBufferInfo prim_buffer;
GPU::TexPage::Linked tex_page;
FontPrimitive* cur_primitive;
void setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size);
@@ -14,8 +14,8 @@ namespace JabyEngine {
static constexpr FontWriter empty() {
FontWriter instance;
instance.tex_page = {0};
instance.prim_buffer = FontBufferInfo::empty();
instance.tex_page = {0};
instance.cur_primitive = nullptr;
return instance;
}
@@ -24,7 +24,7 @@ namespace JabyEngine {
FontWriter::setup(buffer_info, vram_dst, Make::SizeI16(font_info.FontSize.width, font_info.FontSize.height));
}
void write(GPU::PositionI16 pos, const char* str);
void render();
GPU::PositionI16 write(GPU::PositionI16 pos, const char* str);
void render();
};
}

View File

@@ -5,8 +5,8 @@
namespace JabyEngine {
void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) {
this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked();
this->prim_buffer = buffer_info;
this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked();
this->cur_primitive = buffer_info.double_buffer[GPU::Display::current_id];
for(size_t buffer_id = 0; buffer_id < 2; buffer_id++) {
@@ -19,19 +19,36 @@ namespace JabyEngine {
}
}
void FontWriter :: write(GPU::PositionI16 pos, const char* str) {
GPU::PositionI16 FontWriter :: write(GPU::PositionI16 pos, const char* str) {
const auto* primitive_end = &this->prim_buffer.double_buffer[GPU::Display::current_id][this->prim_buffer.single_buffer_length];
const auto font_size = this->prim_buffer.double_buffer[0][0]->size;
const auto row_count = 256/font_size.width;
const auto old_x = pos.x;
while(this->cur_primitive < primitive_end && *str != '\0') {
auto& primitive = *this->cur_primitive;
const auto cur_char = *str++;
if(cur_char == '\n') {
pos.x = old_x;
pos.y += font_size.height;
continue;
}
this->cur_primitive++;
str++;
primitive->position = pos;
if(cur_char == ' ') {
pos.x += font_size.width;
continue;
}
auto& primitive = *this->cur_primitive++;
primitive->position = pos;
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, font_size);
primitive->color = GPU::Color24::Grey();
primitive.concat(*this->cur_primitive);
pos.move(primitive->size.width, 0);
}
return pos;
}
void FontWriter :: render() {