Display text
This commit is contained in:
@@ -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() {
|
||||
|
Reference in New Issue
Block a user