Display text
This commit is contained in:
parent
241c9f7031
commit
5283a4487e
|
@ -34,7 +34,7 @@ static void update() {
|
|||
const auto end_pos = cursor.write(FontWriter::Position::create(0, 32), "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!");
|
||||
cursor.write(end_pos, "\x1b[0;7;7mJaby was\nhere c:");
|
||||
|
||||
new_font_writer.write(Make::PositionI16(8, 8), "012345");
|
||||
new_font_writer.write(Make::PositionI16(8, 8), "012345 ABCDEFGHIJKL\nabcedfghijkl");
|
||||
paco.update();
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,8 @@ namespace JabyEngine {
|
|||
return Position{.x = x, .y = y};
|
||||
}
|
||||
};
|
||||
typedef Position<int16_t> PositionI16;
|
||||
typedef Position<uint16_t> PositionU16;
|
||||
|
||||
template<typename T>
|
||||
struct Size {
|
||||
|
@ -151,6 +153,10 @@ namespace JabyEngine {
|
|||
return Size{w, h};
|
||||
}
|
||||
};
|
||||
typedef Size<int16_t> SizeI16;
|
||||
typedef Size<uint16_t> SizeU16;
|
||||
// Type used for primitives
|
||||
typedef PositionI16 Vertex;
|
||||
|
||||
template<typename T>
|
||||
struct Area {
|
||||
|
@ -173,6 +179,8 @@ namespace JabyEngine {
|
|||
return this->position.move(this->size.width, this->size.height);
|
||||
}
|
||||
};
|
||||
typedef Area<int16_t> AreaI16;
|
||||
typedef Area<uint16_t> AreaU16;
|
||||
|
||||
// Type used for primitives
|
||||
struct PageOffset : public internal::XYMovement<PageOffset, uint8_t> {
|
||||
|
@ -189,20 +197,15 @@ namespace JabyEngine {
|
|||
static constexpr PageOffset create(uint8_t u, uint8_t v) {
|
||||
return PageOffset{.x = u, .y = v}; //< Activate x and y to use XYMovement during constexpr
|
||||
}
|
||||
|
||||
static constexpr PageOffset from_tile_id(int16_t id, int16_t row_count, SizeI16 size) {
|
||||
const auto x = id%row_count;
|
||||
const auto y = id/row_count;
|
||||
|
||||
return PageOffset::create(static_cast<int16_t>(size.width*x), static_cast<int16_t>(size.height*y));
|
||||
}
|
||||
};
|
||||
|
||||
typedef Position<int16_t> PositionI16;
|
||||
typedef Position<uint16_t> PositionU16;
|
||||
|
||||
typedef Size<int16_t> SizeI16;
|
||||
typedef Size<uint16_t> SizeU16;
|
||||
|
||||
typedef Area<int16_t> AreaI16;
|
||||
typedef Area<uint16_t> AreaU16;
|
||||
|
||||
// Type used for primitives
|
||||
typedef PositionI16 Vertex;
|
||||
|
||||
struct VertexColor {
|
||||
Vertex position;
|
||||
Color24 color;
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue