somewhat functional text rendering
This commit is contained in:
parent
dbe70eb4f4
commit
2356d165fe
6 changed files with 368 additions and 16 deletions
34
src/main.c3
34
src/main.c3
|
|
@ -27,6 +27,7 @@ fn int main(String[] args)
|
|||
{
|
||||
ugui::Ctx ui;
|
||||
ui.init()!!;
|
||||
ui.font.load("/usr/share/fonts/TTF/FreeSans.ttf", 16)!!;
|
||||
|
||||
short width = 800;
|
||||
short height = 450;
|
||||
|
|
@ -92,6 +93,8 @@ fn int main(String[] args)
|
|||
ugui::Elem* e = ui.get_elem_by_label("slider")!!;
|
||||
io::printfn("slider: %f", e.slider.value);
|
||||
}
|
||||
|
||||
ui.text_unbounded("text1", "Ciao Mamma")!!;
|
||||
|};
|
||||
ui.div_end()!!;
|
||||
|
||||
|
|
@ -125,6 +128,8 @@ fn int main(String[] args)
|
|||
// ClearBackground(BLACK);
|
||||
|
||||
rl::Color c;
|
||||
static rl::Image font_atlas;
|
||||
static rl::Texture2D font_texture;
|
||||
for (Cmd* cmd; (cmd = ui.cmd_queue.dequeue() ?? null) != null;) {
|
||||
switch (cmd.type) {
|
||||
case ugui::CmdType.CMD_RECT:
|
||||
|
|
@ -141,8 +146,34 @@ fn int main(String[] args)
|
|||
cmd.rect.rect.h,
|
||||
c
|
||||
);
|
||||
case ugui::CmdType.CMD_UPDATE_ATLAS:
|
||||
rl::unload_image(font_atlas);
|
||||
font_atlas.data = cmd.update_atlas.raw_buffer;
|
||||
font_atlas.width = cmd.update_atlas.width;
|
||||
font_atlas.height = cmd.update_atlas.height;
|
||||
font_atlas.mipmaps = 1;
|
||||
//font_atlas.format = rl::PixelFormat.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
|
||||
font_atlas.format = 1;
|
||||
if (rl::is_texture_ready(font_texture)) {
|
||||
rl::unload_texture(font_texture);
|
||||
}
|
||||
font_texture = rl::load_texture_from_image(font_atlas);
|
||||
//rl::draw_texture(font_texture, 0, 0, rl::WHITE);
|
||||
case ugui::CmdType.CMD_SPRITE:
|
||||
rl::Rectangle source = {
|
||||
.x = cmd.sprite.texture_rect.x,
|
||||
.y = cmd.sprite.texture_rect.y,
|
||||
.width = cmd.sprite.texture_rect.w,
|
||||
.height = cmd.sprite.texture_rect.h,
|
||||
};
|
||||
rl::Vector2 position = {
|
||||
.x = cmd.sprite.rect.x,
|
||||
.y = (float)cmd.sprite.rect.y - cmd.sprite.rect.h,
|
||||
};
|
||||
|
||||
rl::draw_texture_rec(font_texture, source, position, rl::WHITE);
|
||||
default:
|
||||
io::printfn("Unknown cmd type: %d", cmd.type);
|
||||
io::printfn("Unknown cmd type: %s", cmd.type);
|
||||
}
|
||||
}
|
||||
draw_times.push(clock.mark());
|
||||
|
|
@ -154,6 +185,7 @@ fn int main(String[] args)
|
|||
|
||||
rl::close_window();
|
||||
|
||||
ui.font.free();
|
||||
ui.free();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue