summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-08-19 15:31:43 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-08-19 15:31:43 -0400
commit86505b7176718f397c3be62ccf28d6a742676382 (patch)
tree84fedf61c710491cac4ad48e99c285b9c45281d3
parent154436ab88925540f86f43c0ac885c080949aa9b (diff)
pke: add ui-text test scene
-rw-r--r--editor/editor.cpp4
-rw-r--r--src/font.cpp8
-rw-r--r--src/font.hpp6
-rw-r--r--src/game.cpp41
-rw-r--r--tests-proj/ui-text.pstf36
5 files changed, 49 insertions, 46 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 42b1c75..4aa2c0c 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -1303,6 +1303,10 @@ void RecordImGuiUITree() {
box->flags |= PKE_UI_BOX_FLAG_CENTER_BOTH;
box->max_size = glm::vec2(.6, .6);
selected_ui_box = box;
+ if (type == PKE_UI_BOX_TYPE_TEXT) {
+ FontRenderSettings frs{};
+ box->type_data->text.font_render_handle = FontType_AddStringRender(FontTypeIndex(0), std::move(cstring_to_pk_cstr("")), &frs, box);
+ }
is_creating_new_box = false;
is_child = false;
type = PKE_UI_BOX_TYPE(-1);
diff --git a/src/font.cpp b/src/font.cpp
index 6d47fa9..b24ea8f 100644
--- a/src/font.cpp
+++ b/src/font.cpp
@@ -890,9 +890,13 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_cstr &&
}
FontRender *FontType_GetFontRender(FontRenderHandle frh) {
- assert(frh.index_ft < ftd.h_ft);
+ if (frh.index_ft >= ftd.h_ft) {
+ return nullptr;
+ }
FontType *ft = &ftd.arr_ft[static_cast<FontTypeIndex_T>(frh.index_ft)];
- assert(frh.index_fr < ft->h_render);
+ if (frh.index_fr >= ft->h_render) {
+ return nullptr;
+ }
return &ft->renders[static_cast<FontRenderIndex_T>(frh.index_fr)];
}
diff --git a/src/font.hpp b/src/font.hpp
index 127feec..912327e 100644
--- a/src/font.hpp
+++ b/src/font.hpp
@@ -57,9 +57,9 @@ struct FontGlyphChar {
struct FontRenderSettings {
glm::vec4 color_foreground = glm::vec4(0.4, 0.9, 0.5, 0.8);
glm::vec4 color_background = glm::vec4(0.0, 0.0, 0.0, 0.0);
- float char_scale;
- float line_height_scale;
- float char_spacing_scale;
+ float char_scale = 1.f;
+ float line_height_scale = 1.f;
+ float char_spacing_scale = 1.f;
glm::ivec2 surface_area_size;
glm::ivec2 surface_area_pos;
FONT_RENDER_SURFACE_AREA_TYPE_FLAG surface_area_type_flags; // TODO
diff --git a/src/game.cpp b/src/game.cpp
index 5dc149f..0784ce9 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -167,47 +167,6 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
pk_arr_append_t(&lvl->scene_instances, si);
}
- // TODO remove me: temp stuff for testing
- /*
- FontTypeIndex font_type_count;
- FontRenderSettings fr_set;
- FontRenderHandle fr_1;
- FontRenderHandle fr_2;
- fr_set.char_scale = 9 * 7.0;
- fr_set.line_height_scale = 1.0;
- fr_set.char_spacing_scale = 1.0;
- fr_set.surface_area_size.x = 1920 - (1920 / 4.0);
- fr_set.surface_area_size.y = 1080 - (1080 / 3.0);
- fr_set.surface_area_pos.x = 1920 / 4.0;
- fr_set.surface_area_pos.y = 1080 / 3.0;
- fr_set.surface_area_type_flags = FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_NONE;
- if ((FontType_GetFonts(font_type_count)); font_type_count != FontTypeIndex{0}) {
- fr_1 = FontType_AddStringRender(FontTypeIndex{0}, std::move(cstring_to_pk_cstr("012\n3456789\tThe quick\r\nbrown fox jumped over the lazy dog.")), &fr_set);
- }
- if ((FontType_GetFonts(font_type_count)); font_type_count > FontTypeIndex{1}) {
- fr_set.surface_area_pos.y *= 2;
- fr_set.surface_area_size.y = 1080 - fr_set.surface_area_pos.y;
- fr_2 = FontType_AddStringRender(FontTypeIndex{1}, std::move(cstring_to_pk_cstr("+0123456\n789\tThe quick brown fox jumped over the lazy dog.")), &fr_set);
- }
-
- // TODO remove me: temp stuff for testing
- pke_ui_box *ui_box = pke_ui_box_new_root();
- ui_box->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
- ui_box->pos_top_left.x = 0.1;
- ui_box->pos_top_left.y = 0.1;
- ui_box->max_size.x = 0.8;
- ui_box->max_size.y = 0.8;
-
- // TODO remove me: temp stuff for testing
- pke_ui_box *c_ui_box = pke_ui_box_new_child(ui_box, PKE_UI_BOX_TYPE_TEXT);
- c_ui_box->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC;
- c_ui_box->pos_top_left.x = 20;
- c_ui_box->pos_top_left.y = 20;
- c_ui_box->max_size.x = 3000;
- c_ui_box->max_size.y = 3000;
- c_ui_box->type_data->text.font_render_handle = fr_1;
- */
-
GameTimePoint lastTimePoint = pkeSettings.steadyClock.now();
double deltaTillNextRender = pkeSettings.deltaPerFrame;
GameTimePoint lastLogTimePoint = pkeSettings.steadyClock.now();
diff --git a/tests-proj/ui-text.pstf b/tests-proj/ui-text.pstf
new file mode 100644
index 0000000..90b2675
--- /dev/null
+++ b/tests-proj/ui-text.pstf
@@ -0,0 +1,36 @@
+:PKFB:
+:0:
+
+FontRenderSettings:00000000!00000000
+CharScale:32.000000
+LineHeightScale:1.000000
+CharSpacingScale:1.000000
+SurfaceAreaSize:619;615
+SurfaceAreaPos:206;205
+SurfaceAreaFlags:0x00
+ColorForeground:0.400000;0.900000;0.500000;0.800000
+ColorBackground:0.000000;0.000000;0.000000;0.000000
+
+FontRender:00000000!00000001
+ChildId:00000000!00000000
+UUID:68a4c9a7-16d2-7e41-a443-a8582d1d5ae9
+FontTypeTitle:fnt_mquin_7y
+TextBegin::
+this is a test
+:MULTILINE_END:
+
+UIBoxTypeData:00000000!00000002
+FontRenderUUID:68a4c9a7-16d2-7e41-a443-a8582d1d5ae9
+
+UIBox:00000000!00000003
+ChildId:00000000!00000002
+UUID:68a4c9a7-0cd2-78a6-b33a-b105721da317
+Flags:0x64
+PosTopLeft:0.000000;0.000000
+MaxSize:0.600000;0.600000
+Type:0x32
+Layer:0x00
+ColorBorder:1.000000;0.000000;0.000000;1.000000
+ColorBackground:0.200000;0.300000;0.200000;0.500000
+
+:PKFE: