Introduce Kern space
This commit is contained in:
parent
ff9186ea67
commit
e1c0f2bcb1
|
@ -7,8 +7,29 @@ namespace JabyEngine {
|
||||||
using FontPrimitive = GPU::SPRT::Linked;
|
using FontPrimitive = GPU::SPRT::Linked;
|
||||||
|
|
||||||
struct FontInfo {
|
struct FontInfo {
|
||||||
|
struct RenderInfo {
|
||||||
|
GPU::SizeU8 font_size;
|
||||||
|
GPU::SizeU8 kern_size;
|
||||||
|
|
||||||
|
static constexpr RenderInfo empty() {
|
||||||
|
return RenderInfo{.font_size = Make::SizeU8(), .kern_size = Make::SizeU8()};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
GPU::SizeU16 texture_size;
|
GPU::SizeU16 texture_size;
|
||||||
GPU::SizeU16 font_size;
|
RenderInfo render_info;
|
||||||
|
|
||||||
|
static constexpr FontInfo create(GPU::SizeU16 texture_size, GPU::SizeU8 font_size, GPU::SizeU8 kern_size) {
|
||||||
|
return FontInfo{.texture_size = texture_size, .render_info = {.font_size = font_size, .kern_size = kern_size}};
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr FontInfo create(GPU::SizeU16 texture_size, GPU::SizeU8 font_size) {
|
||||||
|
return FontInfo::create(texture_size, font_size, font_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr GPU::SizeU16 get_font_size() const {
|
||||||
|
return GPU::SizeU16::from(this->render_info.font_size);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace JabyEngine {
|
||||||
va_end(list)
|
va_end(list)
|
||||||
|
|
||||||
GPU::TexPage::Linked tex_page[2];
|
GPU::TexPage::Linked tex_page[2];
|
||||||
GPU::SizeI16 font_size;
|
FontInfo::RenderInfo render_info;
|
||||||
GPU::PageClut clut;
|
GPU::PageClut clut;
|
||||||
GPU::Link* last_primitive;
|
GPU::Link* last_primitive;
|
||||||
|
|
||||||
|
@ -22,16 +22,16 @@ namespace JabyEngine {
|
||||||
|
|
||||||
instance.tex_page[0] = {0};
|
instance.tex_page[0] = {0};
|
||||||
instance.tex_page[1] = {0};
|
instance.tex_page[1] = {0};
|
||||||
instance.font_size = Make::SizeI16();
|
instance.render_info = FontInfo::RenderInfo::empty();
|
||||||
instance.clut = Make::PageClut();
|
instance.clut = Make::PageClut();
|
||||||
instance.last_primitive = nullptr;
|
instance.last_primitive = nullptr;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(const SimpleTIM& vram_dst, const GPU::SizeI16& font_size);
|
void setup(const SimpleTIM& vram_dst, const FontInfo::RenderInfo& font_render_info);
|
||||||
|
|
||||||
void setup(const SimpleTIM& vram_dst, const FontInfo& font_info) {
|
void setup(const SimpleTIM& vram_dst, const FontInfo& font_info) {
|
||||||
FontWriter::setup(vram_dst, Make::SizeI16(font_info.font_size.width, font_info.font_size.height));
|
FontWriter::setup(vram_dst, font_info.render_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
|
@ -4,20 +4,13 @@
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
struct DefaultFont {
|
struct DefaultFont {
|
||||||
static constexpr auto Info = FontInfo {
|
static constexpr auto Info = FontInfo::create(Make::SizeU16(64, 80), Make::SizeU8(12, 16));
|
||||||
.texture_size = {64, 80},
|
|
||||||
.font_size = {12, 16}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void load(uint32_t* work_area, SimpleTIM vram_dst);
|
static void load(uint32_t* work_area, SimpleTIM vram_dst);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BIOSFont {
|
struct BIOSFont {
|
||||||
static constexpr auto Info = FontInfo {
|
static constexpr auto Info = FontInfo::create(Make::SizeU16(64, 96), Make::SizeU8(16, 16), Make::SizeU8(12, 16));
|
||||||
.texture_size = {64, 96},
|
static constexpr auto TIM = SimpleTIM(JabyEngine::GPU::BIOS_Font::TextureLoadPos.x, JabyEngine::GPU::BIOS_Font::TextureLoadPos.y, JabyEngine::GPU::BIOS_Font::CLUTLoadPos.x, JabyEngine::GPU::BIOS_Font::CLUTLoadPos.y);
|
||||||
.font_size = {16, 16}
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr auto TIM = SimpleTIM(JabyEngine::GPU::BIOS_Font::TextureLoadPos.x, JabyEngine::GPU::BIOS_Font::TextureLoadPos.y, JabyEngine::GPU::BIOS_Font::CLUTLoadPos.x, JabyEngine::GPU::BIOS_Font::CLUTLoadPos.y);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -54,11 +54,11 @@ namespace JabyEngine {
|
||||||
return &buffer[BufferStartID];
|
return &buffer[BufferStartID];
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontWriter :: setup(const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) {
|
void FontWriter :: setup(const SimpleTIM& vram_dst, const FontInfo::RenderInfo& font_render_info) {
|
||||||
for(auto& tex_page : this->tex_page) {
|
for(auto& tex_page : this->tex_page) {
|
||||||
tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked();
|
tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked();
|
||||||
}
|
}
|
||||||
this->font_size = font_size;
|
this->render_info = font_render_info;
|
||||||
this->clut = Make::PageClut(vram_dst.get_clut_position());
|
this->clut = Make::PageClut(vram_dst.get_clut_position());
|
||||||
this->last_primitive = nullptr;
|
this->last_primitive = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -76,23 +76,24 @@ namespace JabyEngine {
|
||||||
FontWriter::clear();
|
FontWriter::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto row_count = 256/font_size.width;
|
const auto sprt_size = GPU::SizeI16::from(this->render_info.font_size);
|
||||||
|
const auto row_count = 256/sprt_size.width;
|
||||||
const auto push_char = [&](State& state, char cur_char) -> bool {
|
const auto push_char = [&](State& state, char cur_char) -> bool {
|
||||||
auto& primitive = GlobalPrimitiveFactory.new_primitive();
|
auto& primitive = GlobalPrimitiveFactory.new_primitive();
|
||||||
|
|
||||||
primitive->position = state.pos;
|
primitive->position = state.pos;
|
||||||
primitive->size = this->font_size;
|
primitive->size = sprt_size;
|
||||||
if(wiggle) {
|
if(wiggle) {
|
||||||
const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7];
|
const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7];
|
||||||
primitive->position.move(off_x, off_y);
|
primitive->position.move(off_x, off_y);
|
||||||
}
|
}
|
||||||
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, font_size);
|
primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, sprt_size);
|
||||||
primitive->clut = this->clut;
|
primitive->clut = this->clut;
|
||||||
primitive->color = color;
|
primitive->color = color;
|
||||||
|
|
||||||
this->last_primitive->concat(primitive);
|
this->last_primitive->concat(primitive);
|
||||||
this->last_primitive = &primitive;
|
this->last_primitive = &primitive;
|
||||||
state.pos.move(this->font_size.width, 0);
|
state.pos.move(this->render_info.kern_size.width, 0);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
const auto old_x = state.pos.x;
|
const auto old_x = state.pos.x;
|
||||||
|
@ -112,11 +113,11 @@ namespace JabyEngine {
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
state.pos.x = old_x;
|
state.pos.x = old_x;
|
||||||
state.pos.y += font_size.height;
|
state.pos.y += this->render_info.kern_size.height;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case ' ':
|
case ' ':
|
||||||
state.pos.x += font_size.width;
|
state.pos.x += this->render_info.kern_size.width;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case '%':
|
case '%':
|
||||||
|
|
Loading…
Reference in New Issue