ui text rendering ordering working + console report view

This commit is contained in:
Tuomas Katajisto 2025-05-03 11:42:14 +03:00
parent f7882ae500
commit 5f0af59c18
5 changed files with 48 additions and 73 deletions

View File

@ -24,10 +24,7 @@ Arb_Draw_Command :: struct {
texture : *Ui_Texture; texture : *Ui_Texture;
// for text // for text
font : *Ui_Font; layer: s32 = 0;
text : string;
text_color : Vector4;
x,y : s64;
} }
@ -102,8 +99,7 @@ arb_tri_flush :: () {
flush_arb_commands(); flush_arb_commands();
} }
debug_arb_flush : bool : true; debug_arb_flush : bool : false;
is_in_pass : bool = false;
layer : s32 = 0; layer : s32 = 0;
@ -119,62 +115,12 @@ flush_arb_commands :: () {
case .REMOVE_TEXTURE; case .REMOVE_TEXTURE;
gCurrentTexture = null; gCurrentTexture = null;
case .FLUSH_TRI; case .FLUSH_TRI;
// if !is_in_pass {
// sg_begin_pass(*(sg_pass.{ action = state.pass_action, swapchain = cast,force(sg_swapchain) sglue_swapchain() }));
// is_in_pass = true;
// }
sg_apply_pipeline(gPipelines.arbtri.pipeline); sg_apply_pipeline(gPipelines.arbtri.pipeline);
sg_apply_bindings(*gPipelines.arbtri.bind); sg_apply_bindings(*gPipelines.arbtri.bind);
sg_draw(xx (it.tri_offset * 3), xx (it.tri_count * 3), 1); sg_draw(xx (it.tri_offset * 3), xx (it.tri_count * 3), 1);
case .PREPARE_TEXT; case .PREPARE_TEXT;
// if is_in_pass {
// sg_end_pass();
// is_in_pass = false;
// }
font := it.font;
text := it.text;
if text.count < 1 then continue;
print("prep at size: %\n", font.character_height);
fonsSetFont(state.fons, state.font_default.fons_font);
fonsSetSize(state.fons, xx font.character_height);
w := fonsTextBounds(state.fons, 0.0, 0.0, text.data, text.data + text.count, null);
gPreppedText = text;
gPreppedTextWidth = cast(s32) w;
array_reset(*font.temporary_glyphs);
array_reset(*font.temporary_glyphs_byte_offsets);
for 0..(text.count-1) {
glyph : Ui_Font_Glyph;
glyph.advance = cast(u32) fonsTextBounds(state.fons, 0.0, 0.0, text.data + it, text.data + it + 1, null);
array_add(*font.temporary_glyphs, glyph);
array_add(*font.temporary_glyphs_byte_offsets, cast(u32) it);
}
case .DRAW_TEXT; case .DRAW_TEXT;
if gPreppedText.count < 1 then continue; sgl_draw_layer(it.layer);
text_color := it.text_color;
x := it.x;
y := it.y;
font := it.font;
color := sfons_rgba(xx (255.0 * text_color.x), xx (255.0 * text_color.y), xx (255.0 * text_color.z), xx (255.0 * text_color.w));
fonsSetColor(state.fons, color);
result := cast(*u8) temporary_alloc(gPreppedText.count + 1); // Add 1 for the zero.
memcpy(result, gPreppedText.data, gPreppedText.count);
result[gPreppedText.count] = 0;
sgl_layer(layer);
fonsDrawText(state.fons, xx x, xx y, result, null);
// sg_begin_pass(*(sg_pass.{ action = state.pass_action, swapchain = cast,force(sg_swapchain) sglue_swapchain() }));
sfons_flush(state.fons);
sgl_draw_layer(layer);
// sg_end_pass();
layer += 1;
fonsPushState(state.fons);
} }
} }
// if is_in_pass {
// sg_end_pass();
// }
} }

View File

@ -4,8 +4,12 @@ Console_State :: enum {
OPEN_FULL; OPEN_FULL;
} }
MAX_REPORT_ROWS :: 100;
console_state : Console_State = .CLOSED; console_state : Console_State = .CLOSED;
console_report : [..]string;
console_h : float = 0.0; console_h : float = 0.0;
console_move_speed : float = 400.0; console_move_speed : float = 400.0;
@ -53,9 +57,13 @@ tick_console :: () {
console_h = t; console_h = t;
} }
} }
while console_report.count > MAX_REPORT_ROWS {
array_ordered_remove_by_index(*console_report, 0);
}
} }
console_input : string = "HELLO??dasdasdasd"; console_input_start : string = "";
draw_console :: (theme: *GR.Overall_Theme) { draw_console :: (theme: *GR.Overall_Theme) {
if console_h < 1 then return; if console_h < 1 then return;
@ -65,7 +73,17 @@ draw_console :: (theme: *GR.Overall_Theme) {
r.x -= 1*vw; r.x -= 1*vw;
r.y = r.h - ui_h(5, 4); r.y = r.h - ui_h(5, 4);
r.h = ui_h(5, 4); r.h = ui_h(5, 4);
// GR.label(r, "HELLO?!! wTF=", *theme.label_theme);
a, new, state := GR.text_input(r, console_input, *theme.text_input_theme); a, new, state := GR.text_input(r, console_input_start, *theme.text_input_theme);
if a & .ENTERED {
array_add(*console_report, copy_string(tprint("> %", new)));
state.text = console_input_start;
}
for < console_report {
r.y -= r.h;
GR.label(r, it, *t_label_left(theme));
}
if !state.active then GR.activate(state); if !state.active then GR.activate(state);
} }

View File

@ -6,7 +6,7 @@ draw_editor_ui :: (theme: *GR.Overall_Theme) {
r.y = 0; r.h = ui_h(5, 0); r.y = 0; r.h = ui_h(5, 0);
draw_bg_rectangle(r, theme); draw_bg_rectangle(r, theme);
r.w = 15*vw; r.w = 15*vw;
GR.label(r, "Trueno!", *t_label_left(theme)); GR.label(r, tprint("Trueno v%.%", V_MAJOR, V_MINOR), *t_label_left(theme));
r = GR.get_rect(0, ui_h(5,0), ui_w(20, 20), ui_h(95, 0)); r = GR.get_rect(0, ui_h(5,0), ui_w(20, 20), ui_h(95, 0));
draw_bg_rectangle(r, theme); draw_bg_rectangle(r, theme);

View File

@ -15,6 +15,10 @@ stbi :: #import "stb_image";
last_frame_time : float64; last_frame_time : float64;
delta\ _time : float64; delta\ _time : float64;
V_MAJOR :: 0;
V_MINOR :: 2;
state: struct { state: struct {
pass_action_clear : sg_pass_action; pass_action_clear : sg_pass_action;
pass_action : sg_pass_action; pass_action : sg_pass_action;
@ -104,7 +108,8 @@ frame :: () {
tick_ui(); tick_ui();
render_ui(); render_ui();
is_in_pass = true;
// UI Pass:
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, swapchain = cast,force(sg_swapchain) sglue_swapchain() })); sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, swapchain = cast,force(sg_swapchain) sglue_swapchain() }));
arb_tri_flush(); arb_tri_flush();
sg_end_pass(); sg_end_pass();

View File

@ -153,13 +153,11 @@ gPreppedText: string;
gPreppedTextWidth : s32; gPreppedTextWidth : s32;
prepare_text :: (font: *Ui_Type_Indicator.Font, text: string, effects: Ui_Type_Indicator.Font_Effects = 0) -> s64 { prepare_text :: (font: *Ui_Type_Indicator.Font, text: string, effects: Ui_Type_Indicator.Font_Effects = 0) -> s64 {
if text.count < 1 then return 0; if text.count < 1 {
gPreppedText = "";
arb_tri_command_add(.{ gPreppedTextWidth = 0;
type = .PREPARE_TEXT, return 0;
font = font, }
text = text
});
fonsSetFont(state.fons, state.font_default.fons_font); fonsSetFont(state.fons, state.font_default.fons_font);
fonsSetSize(state.fons, xx font.character_height); fonsSetSize(state.fons, xx font.character_height);
w := fonsTextBounds(state.fons, 0.0, 0.0, text.data, text.data + text.count, null); w := fonsTextBounds(state.fons, 0.0, 0.0, text.data, text.data + text.count, null);
@ -181,13 +179,21 @@ prepare_text :: (font: *Ui_Type_Indicator.Font, text: string, effects: Ui_Type_I
return cast(s64) w; return cast(s64) w;
} }
draw_prepared_text :: (font: *Ui_Type_Indicator.Font, x: s64, y: s64, text_color: Vector4, effects: Ui_Type_Indicator.Font_Effects = 0) { draw_prepared_text :: (font: *Ui_Type_Indicator.Font, x: s64, y: s64, text_color: Vector4, effects: Ui_Type_Indicator.Font_Effects = 0) {
if gPreppedText.count < 1 then return;
color := sfons_rgba(xx (255.0 * text_color.x), xx (255.0 * text_color.y), xx (255.0 * text_color.z), xx (255.0 * text_color.w));
fonsSetColor(state.fons, color);
result := cast(*u8) temporary_alloc(gPreppedText.count + 1); // Add 1 for the zero.
memcpy(result, gPreppedText.data, gPreppedText.count);
result[gPreppedText.count] = 0;
sgl_layer(layer);
fonsDrawText(state.fons, xx x, xx y, result, null);
sfons_flush(state.fons);
fonsPushState(state.fons);
arb_tri_command_add(.{ arb_tri_command_add(.{
type = .DRAW_TEXT, type = .DRAW_TEXT,
text_color = text_color, layer = layer
font = font,
x = x,
y = y
}); });
layer += 1;
} }
get_mouse_pointer_position :: (window: Ui_Type_Indicator.Window_Type, right_handed: bool) -> (x: int, y: int, success: bool) { get_mouse_pointer_position :: (window: Ui_Type_Indicator.Window_Type, right_handed: bool) -> (x: int, y: int, success: bool) {
return xx input_mouse_x, xx input_mouse_y, true; return xx input_mouse_x, xx input_mouse_y, true;