From ed477006298ab1d2de4aab45ab19c61e45ec58fb Mon Sep 17 00:00:00 2001 From: Jonathan Hoffstadt Date: Mon, 21 Oct 2024 22:50:44 -0500 Subject: [PATCH] feat: pl_draw.h v1.0.0 --- examples/example_2.c | 46 +- examples/example_3.c | 6 +- examples/example_8.c | 19 +- extensions/pl_debug_ext.c | 50 +- extensions/pl_draw_backend_ext.c | 91 +-- extensions/pl_draw_ext.c | 1226 +++++++++++++++--------------- extensions/pl_draw_ext.h | 404 +++++----- extensions/pl_renderer_ext.c | 24 +- extensions/pl_ui_core.c | 87 ++- extensions/pl_ui_demo.c | 8 +- extensions/pl_ui_ext.c | 2 +- extensions/pl_ui_ext.h | 2 +- extensions/pl_ui_internal.h | 4 +- extensions/pl_ui_widgets.c | 462 +++++++---- sandbox/app.c | 17 +- sandbox/pl_ecs_tools.c | 22 +- sandbox/pl_gizmo.c | 106 +-- 17 files changed, 1378 insertions(+), 1198 deletions(-) diff --git a/examples/example_2.c b/examples/example_2.c index 70913814..46167e83 100644 --- a/examples/example_2.c +++ b/examples/example_2.c @@ -210,7 +210,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // adding another font plFontConfig tFontConfig0 = { .bSdf = false, - .fFontSize = 18.0f, + .fSize = 18.0f, .uHOverSampling = 1, .uVOverSampling = 1, .uRangeCount = 1, @@ -221,7 +221,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // adding previous font but as a signed distance field plFontConfig tFontConfig1 = { .bSdf = true, // only works with ttf - .fFontSize = 18.0f, + .fSize = 18.0f, .uHOverSampling = 1, .uVOverSampling = 1, .ucOnEdgeValue = 180, @@ -305,51 +305,49 @@ pl_app_update(plAppData* ptAppData) // lines float fXCursor = 0.0f; - gptDraw->add_line(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f); + gptDraw->add_line(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_triangle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f); + gptDraw->add_triangle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_circle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 50.0f}, 50.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 0, 1.0f); + gptDraw->add_circle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 50.0f}, 50.0f, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_rect(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f, 0, 0); + gptDraw->add_rect_rounded(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 0, 0, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_rect(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 2.0f, 25.0f, 0); + gptDraw->add_rect_rounded(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 25.0f, 0, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_rect_ex(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 2.0f, 25.0f, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT); + gptDraw->add_rect_rounded(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 25.0f, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_quad(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 5.0f}, (plVec2){fXCursor + 5.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 5.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f); + gptDraw->add_quad(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 5.0f}, (plVec2){fXCursor + 5.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 5.0f}, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_bezier_quad(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f, 0); + gptDraw->add_bezier_quad(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_bezier_cubic(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f, 0); + gptDraw->add_bezier_cubic(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; // solids fXCursor = 100.0f; - gptDraw->add_triangle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 100.0f}, (plVec2){fXCursor, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}); + gptDraw->add_triangle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 100.0f}, (plVec2){fXCursor, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_circle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 150.0f}, 50.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 0); + gptDraw->add_circle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 150.0f}, 50.0f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_rect_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 0, 0); + gptDraw->add_rect_rounded_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, 0, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_rect_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 25.0f, 0); + gptDraw->add_rect_rounded_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, 25.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA}); fXCursor += 100.0f; - gptDraw->add_rect_filled_ex(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 25.0f, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT); - fXCursor += 100.0f; - gptDraw->add_quad_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 105.0f}, (plVec2){fXCursor + 5.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 105.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}); + gptDraw->add_quad_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 105.0f}, (plVec2){fXCursor + 5.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 105.0f}, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA}); // gptDraw->add_circle_filled(ptAppData->ptBGLayer, (plVec2){100.0f, 100.0f}, 25.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 24); // default text - gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptDefaultFont, 13.0f, (plVec2){25.0f, 300.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Proggy @ 13 (loaded at 13)", 0.0f); - gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptDefaultFont, 45.0f, (plVec2){25.0f, 315.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Proggy @ 45 (loaded at 13)", 0.0f); + gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 300.0f}, "Proggy @ 13 (loaded at 13)", (plDrawTextOptions){.ptFont = ptAppData->ptDefaultFont, .uColor = PL_COLOR_32_WHITE}); + gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 315.0f}, "Proggy @ 45 (loaded at 13)", (plDrawTextOptions){.ptFont = ptAppData->ptDefaultFont, .uColor = PL_COLOR_32_WHITE, .fSize = 45.0f}); // bitmap text - gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineBitmapFont, 18.0f, (plVec2){25.0f, 400.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 18, bitmap (loaded at 18)", 0.0f); - gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineBitmapFont, 100.0f, (plVec2){25.0f, 420.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 100, bitmap (loaded at 18)", 0.0f); + gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 400.0f}, "Cousine @ 18, bitmap (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineBitmapFont, .uColor = PL_COLOR_32_WHITE}); + gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 420.0f}, "Cousine @ 100, bitmap (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineBitmapFont, .uColor = PL_COLOR_32_WHITE, .fSize = 100.0f}); // sdf text - gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineSDFFont, 18.0f, (plVec2){25.0f, 520.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 18, sdf (loaded at 18)", 0.0f); - gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineSDFFont, 100.0f, (plVec2){25.0f, 540.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 100, sdf (loaded at 18)", 0.0f); + gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 520.0f}, "Cousine @ 18, sdf (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineSDFFont, .uColor = PL_COLOR_32_WHITE, .fSize = 100.0f}); + gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 540.0f}, "Cousine @ 100, sdf (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineSDFFont, .uColor = PL_COLOR_32_WHITE, .fSize = 100.0f}); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~drawing prep~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/examples/example_3.c b/examples/example_3.c index e2232fda..d4f99b29 100644 --- a/examples/example_3.c +++ b/examples/example_3.c @@ -36,7 +36,7 @@ Index of this file: // extensions #include "pl_shader_ext.h" -#include "pl_draw_ext.h" // not yet stable +#include "pl_draw_ext.h" #include "pl_ui_ext.h" // not yet stable #include "pl_graphics_ext.h" // not yet stable #include "pl_draw_backend_ext.h" // not yet stable @@ -275,7 +275,7 @@ pl_app_update(plAppData* ptAppData) const float pfRatios[] = {1.0f}; gptUi->layout_row(PL_UI_LAYOUT_ROW_TYPE_DYNAMIC, 0.0f, 1, pfRatios); - if(gptUi->collapsing_header("Information")) + if(gptUi->begin_collapsing_header("Information")) { gptUi->text("Pilot Light %s", PILOT_LIGHT_VERSION); @@ -289,7 +289,7 @@ pl_app_update(plAppData* ptAppData) gptUi->end_collapsing_header(); } - if(gptUi->collapsing_header("User Interface")) + if(gptUi->begin_collapsing_header("User Interface")) { gptUi->checkbox("UI Debug", &ptAppData->bShowUiDebug); gptUi->checkbox("UI Demo", &ptAppData->bShowUiDemo); diff --git a/examples/example_8.c b/examples/example_8.c index 2662789e..42a9600b 100644 --- a/examples/example_8.c +++ b/examples/example_8.c @@ -42,7 +42,7 @@ Index of this file: // extensions #include "pl_graphics_ext.h" // not yet stable -#include "pl_draw_ext.h" // not yet stable +#include "pl_draw_ext.h" #include "pl_shader_ext.h" #include "pl_draw_backend_ext.h" // not yet stable @@ -483,32 +483,31 @@ pl_app_update(plAppData* ptAppData) // 3d drawing API usage const plMat4 tOrigin = pl_identity_mat4(); - gptDraw->add_3d_transform(ptAppData->pt3dDrawlist, &tOrigin, 10.0f, 0.2f); + gptDraw->add_3d_transform(ptAppData->pt3dDrawlist, &tOrigin, 10.0f, (plDrawLineOptions){.fThickness = 0.2f}); plDrawCylinderDesc tCylinderDesc = { .fRadius = 1.5f, .tBasePos = {-2.5f, 1.0f, 0.0f}, .tTipPos = {-2.5f, 4.0f, 0.0f}, - .tColor = (plVec4){1.0f, 1.0f, 0.0f, 0.75f}, .uSegments = 12 }; - gptDraw->add_3d_cylinder_filled_ex(ptAppData->pt3dDrawlist, &tCylinderDesc); + gptDraw->add_3d_cylinder_filled(ptAppData->pt3dDrawlist, tCylinderDesc, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)}); gptDraw->add_3d_triangle_filled(ptAppData->pt3dDrawlist, (plVec3){1.0f, 1.0f, 0.0f}, (plVec3){4.0f, 1.0f, 0.0f}, (plVec3){1.0f, 4.0f, 0.0f}, - (plVec4){1.0f, 1.0f, 0.0f, 0.75f}); + (plDrawSolidOptions){.uColor = PL_COLOR_32_YELLOW}); gptDraw->add_3d_sphere_filled(ptAppData->pt3dDrawlist, - (plVec3){5.5f, 2.5f, 0.0f}, 1.5f, (plVec4){1.0f, 1.0f, 0.0f, 0.75f}); + (plDrawSphereDesc){.fRadius = 1.0F, .tCenter = {5.5f, 2.5f, 0.0f}}, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)}); gptDraw->add_3d_circle_xz_filled(ptAppData->pt3dDrawlist, - (plVec3){8.5f, 2.5f, 0.0f}, 1.5f, (plVec4){1.0f, 1.0f, 0.0f, 0.75f}, 0); + (plVec3){8.5f, 2.5f, 0.0f}, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)}); - gptDraw->add_3d_band_xz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, (plVec4){1.0f, 1.0f, 0.0f, 0.75f}, 0); - gptDraw->add_3d_band_xy_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, (plVec4){1.0f, 0.0f, 0.0f, 0.75f}, 0); - gptDraw->add_3d_band_yz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, (plVec4){1.0f, 0.0f, 1.0f, 0.75f}, 0); + gptDraw->add_3d_band_xz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)}); + gptDraw->add_3d_band_xy_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 0.0f, 0.75f)}); + gptDraw->add_3d_band_yz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 1.0f, 0.75f)}); // gptDraw->add_3d_triangle_filled(ptAppData->pt3dDrawlist, // (plVec3){1.0f, 1.0f, 3.0f}, diff --git a/extensions/pl_debug_ext.c b/extensions/pl_debug_ext.c index 6bfbc238..cc6b48d4 100644 --- a/extensions/pl_debug_ext.c +++ b/extensions/pl_debug_ext.c @@ -410,7 +410,7 @@ pl__show_profiling(bool* bValue) } } - gptDraw->add_rect_filled(ptFgLayer, tCursorPos, pl_add_vec2(tCursorPos, tTimelineBarSize), (plVec4){0.5f, 0.0f, 0.0f, 0.7f}, 0.0f, 0); + gptDraw->add_rect_rounded_filled(ptFgLayer, tCursorPos, pl_add_vec2(tCursorPos, tTimelineBarSize), 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(0.5f, 0.0f, 0.0f, 0.7f)}); const double dUnitMultiplier = 1000.0; uint32_t uDecimalPlaces = 0; @@ -447,12 +447,12 @@ pl__show_profiling(bool* bValue) const double dLineX0 = (double)(dTime0 * dConvertToPixel) + tCursorPos.x; char* pcDecimals = pl_temp_allocator_sprintf(&gptDebugCtx->tTempAllocator, " %%0.%uf ms ", uDecimalPlaces); char* pcText0 = pl_temp_allocator_sprintf(&gptDebugCtx->tTempAllocator, pcDecimals, (double)dTime0 * dUnitMultiplier); - const plRect tBB0 = gptDraw->calculate_text_bb(gptUI->get_default_font(), gptUI->get_default_font()->fSize, (plVec2){roundf((float)dLineX0), tCursorPos.y + 20.0f}, pcText0, 0.0f); + const plRect tBB0 = gptDraw->calculate_text_bb((plVec2){roundf((float)dLineX0), tCursorPos.y + 20.0f}, pcText0, (plDrawTextOptions){.ptFont = gptUI->get_default_font()}); const double dTime1 = dTime0 + dIncrement; const float dLineX1 = (float)(dTime1 * dConvertToPixel) + tCursorPos.x; char* pcText1 = pl_temp_allocator_sprintf(&gptDebugCtx->tTempAllocator, pcDecimals, (double)dTime1 * dUnitMultiplier); - const plRect tBB1 = gptDraw->calculate_text_bb(gptUI->get_default_font(), gptUI->get_default_font()->fSize, (plVec2){roundf((float)dLineX1), tCursorPos.y + 20.0f}, pcText1, 0.0f); + const plRect tBB1 = gptDraw->calculate_text_bb((plVec2){roundf((float)dLineX1), tCursorPos.y + 20.0f}, pcText1, (plDrawTextOptions){.ptFont = gptUI->get_default_font()}); pl_temp_allocator_reset(&gptDebugCtx->tTempAllocator); if(!pl_rect_overlaps_rect(&tBB0, &tBB1)) @@ -471,7 +471,7 @@ pl__show_profiling(bool* bValue) while(dCurrentTime < dEndTime) { const float fLineX = (float)((dCurrentTime * dConvertToPixel)) + tCursorPos.x; - gptDraw->add_line(ptFgLayer, (plVec2){fLineX, tCursorPos.y}, (plVec2){fLineX, tCursorPos.y + 10.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, 1.0f); + gptDraw->add_line(ptFgLayer, (plVec2){fLineX, tCursorPos.y}, (plVec2){fLineX, tCursorPos.y + 10.0f}, (plDrawLineOptions){.uColor = PL_COLOR_32_WHITE, .fThickness = 1.0f}); dCurrentTime += dIncrement * 0.5f; } @@ -480,7 +480,7 @@ pl__show_profiling(bool* bValue) while(dCurrentTime < dEndTime) { const float fLineX = (float)((dCurrentTime * dConvertToPixel)) + tCursorPos.x; - gptDraw->add_line(ptFgLayer, (plVec2){fLineX, tCursorPos.y}, (plVec2){fLineX, tCursorPos.y + 5.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, 1.0f); + gptDraw->add_line(ptFgLayer, (plVec2){fLineX, tCursorPos.y}, (plVec2){fLineX, tCursorPos.y + 5.0f}, (plDrawLineOptions){.uColor = PL_COLOR_32_WHITE, .fThickness = 1.0f}); dCurrentTime += dIncrement * 0.1f; } @@ -491,9 +491,9 @@ pl__show_profiling(bool* bValue) const float fLineX = (float)((dCurrentTime * dConvertToPixel)) + tCursorPos.x; char* pcDecimals = pl_temp_allocator_sprintf(&gptDebugCtx->tTempAllocator, "%%0.%uf ms", uDecimalPlaces); char* pcText = pl_temp_allocator_sprintf(&gptDebugCtx->tTempAllocator, pcDecimals, (double)dCurrentTime * dUnitMultiplier); - const float fTextWidth = gptDraw->calculate_text_size(gptUI->get_default_font(), gptUI->get_default_font()->fSize, pcText, 0.0f).x; - gptDraw->add_line(ptFgLayer, (plVec2){fLineX, tCursorPos.y}, (plVec2){fLineX, tCursorPos.y + 20.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, 1.0f); - gptDraw->add_text(ptFgLayer, gptUI->get_default_font(), gptUI->get_default_font()->fSize, (plVec2){roundf(fLineX - fTextWidth / 2.0f), tCursorPos.y + 20.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, pcText, 0.0f); + const float fTextWidth = gptDraw->calculate_text_size(pcText, (plDrawTextOptions){.ptFont = gptUI->get_default_font()}).x; + gptDraw->add_line(ptFgLayer, (plVec2){fLineX, tCursorPos.y}, (plVec2){fLineX, tCursorPos.y + 20.0f}, (plDrawLineOptions){.uColor = PL_COLOR_32_WHITE, .fThickness = 1.0f}); + gptDraw->add_text(ptFgLayer, (plVec2){roundf(fLineX - fTextWidth / 2.0f), tCursorPos.y + 20.0f}, pcText, (plDrawTextOptions){.uColor = PL_COLOR_32_WHITE, .ptFont = gptUI->get_default_font()}); pl_temp_allocator_reset(&gptDebugCtx->tTempAllocator); dCurrentTime += dIncrement; } @@ -529,9 +529,9 @@ pl__show_profiling(bool* bValue) if(bHovered) { - gptDraw->add_line(ptFgLayer, (plVec2){tMousePos.x, tCursorPos.y}, (plVec2){tMousePos.x, tWindowEnd.y}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, 1.0f); + gptDraw->add_line(ptFgLayer, (plVec2){tMousePos.x, tCursorPos.y}, (plVec2){tMousePos.x, tWindowEnd.y}, (plDrawLineOptions){.uColor = PL_COLOR_32_WHITE, .fThickness = 1.0f}); char* pcText = pl_temp_allocator_sprintf(&gptDebugCtx->tTempAllocator, "%0.6f", (double)dConvertToTime * (double)(tMousePos.x - tParentCursorPos.x + gptUI->get_window_scroll().x)); - gptDraw->add_text(ptFgLayer, gptUI->get_default_font(), gptUI->get_default_font()->fSize, tMousePos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, pcText, 0.0f); + gptDraw->add_text(ptFgLayer, tMousePos, pcText, (plDrawTextOptions){.uColor = PL_COLOR_32_WHITE, .ptFont = gptUI->get_default_font()}); pl_temp_allocator_reset(&gptDebugCtx->tTempAllocator); } @@ -571,7 +571,7 @@ pl__show_statistics(bool* bValue) for(uint32_t i = 0; i < uNameCount; i++) { gptDebugCtx->sbppdFrameValues[i] = gptStats->get_counter_data(gptDebugCtx->ppcNames[i]); - float fCurrentWidth = gptDraw->calculate_text_size(gptUI->get_default_font(), gptUI->get_default_font()->fSize, gptDebugCtx->ppcNames[i], 0.0f).x; + float fCurrentWidth = gptDraw->calculate_text_size(gptDebugCtx->ppcNames[i], (plDrawTextOptions){.ptFont = gptUI->get_default_font()}).x; if(fCurrentWidth > gptDebugCtx->fLegendWidth) gptDebugCtx->fLegendWidth = fCurrentWidth; } @@ -663,10 +663,10 @@ pl__show_statistics(bool* bValue) const plVec2 tCursor1 = gptUI->get_cursor_pos(); gptUI->invisible_button("legend", tLegendSize); - gptDraw->add_rect_filled(ptFgLayer, + gptDraw->add_rect_rounded_filled(ptFgLayer, tCursor0, pl_add_vec2(tCursor0, tPlotSize), - (plVec4){0.2f, 0.0f, 0.0f, 0.5f}, 0.0f, 0); + 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(0.2f, 0.0f, 0.0f, 0.5f)}); static const plVec4 atColors[6] = { {0.0f, 1.0f, 1.0f, 0.75f}, @@ -684,8 +684,8 @@ pl__show_statistics(bool* bValue) if(bAllowNegative) { - gptDraw->add_text(ptFgLayer, gptUI->get_default_font(), gptUI->get_default_font()->fSize, (plVec2){roundf(tCursor0.x), roundf((float)dYCenter)}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "0", 0.0f); - gptDraw->add_line(ptFgLayer, (plVec2){tCursor0.x, (float)dYCenter}, (plVec2){tCursor0.x + tPlotSize.x, (float)dYCenter}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, 1.0f); + gptDraw->add_text(ptFgLayer, (plVec2){roundf(tCursor0.x), roundf((float)dYCenter)}, "0", (plDrawTextOptions){.uColor = PL_COLOR_32_WHITE, .ptFont = gptUI->get_default_font()}); + gptDraw->add_line(ptFgLayer, (plVec2){tCursor0.x, (float)dYCenter}, (plVec2){tCursor0.x + tPlotSize.x, (float)dYCenter}, (plDrawLineOptions){.uColor = PL_COLOR_32_WHITE, .fThickness = 1.0f}); } bAllowNegative = false; @@ -712,8 +712,8 @@ pl__show_statistics(bool* bValue) uint32_t uIndexStart = (uint32_t)gptIO->ulFrameCount; const plVec2 tTextPoint = {tCursor1.x + 5.0f, tCursor1.y + i * 20.0f}; - gptDraw->add_rect_filled(ptFgLayer, tTextPoint, (plVec2){tTextPoint.x + gptUI->get_default_font()->fSize, tTextPoint.y + gptUI->get_default_font()->fSize}, *ptColor, 0.0f, 0); - gptDraw->add_text(ptFgLayer, gptUI->get_default_font(), gptUI->get_default_font()->fSize, (plVec2){roundf(tTextPoint.x + 20.0f), roundf(tTextPoint.y)}, *ptColor, apcTempNames[i], 0.0f); + gptDraw->add_rect_rounded_filled(ptFgLayer, tTextPoint, (plVec2){tTextPoint.x + gptUI->get_default_font()->fSize, tTextPoint.y + gptUI->get_default_font()->fSize}, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(*ptColor)}); + gptDraw->add_text(ptFgLayer, (plVec2){roundf(tTextPoint.x + 20.0f), roundf(tTextPoint.y)}, apcTempNames[i], (plDrawTextOptions){.uColor = PL_COLOR_32_VEC4(*ptColor), .ptFont = gptUI->get_default_font()}); for(uint32_t j = 0; j < uStatsMaxFrames - 1; j++) { @@ -721,13 +721,13 @@ pl__show_statistics(bool* bValue) uint32_t uActualIndex1 = (uIndexStart + j + 1) % uStatsMaxFrames; const plVec2 tLineStart = {tCursor0.x + (float)(j * dXIncrement), (float)(dYCenter - dValues[uActualIndex0] * dConversion)}; const plVec2 tLineEnd = {tCursor0.x + (float)((j + 1) * dXIncrement), (float)(dYCenter - dValues[uActualIndex1] * dConversion)}; - gptDraw->add_line(ptFgLayer, tLineStart, tLineEnd, *ptColor, 1.0f); + gptDraw->add_line(ptFgLayer, tLineStart, tLineEnd, (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(*ptColor), .fThickness = 1.0f}); if(j == uStatsMaxFrames - 2) { char acTextBuffer[32] = {0}; pl_sprintf(acTextBuffer, "%0.0f", dValues[uActualIndex1]); - gptDraw->add_text(ptFgLayer, gptUI->get_default_font(), gptUI->get_default_font()->fSize, (plVec2){roundf(tLineEnd.x), roundf(tLineEnd.y) - 6.0f}, *ptColor, acTextBuffer, 0.0f); + gptDraw->add_text(ptFgLayer, (plVec2){roundf(tLineEnd.x), roundf(tLineEnd.y) - 6.0f}, acTextBuffer, (plDrawTextOptions){.uColor = PL_COLOR_32_VEC4(*ptColor), .ptFont = gptUI->get_default_font()}); } } @@ -748,7 +748,7 @@ pl__show_statistics(bool* bValue) { const float fXPos = gptUI->get_cursor_pos().x - 5.0f; const float fYPos = gptUI->get_cursor_pos().y; - gptDraw->add_line(ptFgLayer, (plVec2){fXPos, fYPos}, (plVec2){fXPos, 3000.0f}, (plVec4){0.7f, 0.0f, 0.0f, 1.0f}, 1.0f); + gptDraw->add_line(ptFgLayer, (plVec2){fXPos, fYPos}, (plVec2){fXPos, 3000.0f}, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.7f, 0.0f, 0.0f), .fThickness = 1.0f}); gptUI->button(apcTempNames[i]); } @@ -893,9 +893,9 @@ pl__show_device_memory(bool* bValue) const float fTotalWidth = fWidthAvailable * ((float)ptBlock->ulSize) / (float)ulMaxBlockSize; if(ptBlock->uHandle == 0) - gptDraw->add_rect(ptFgLayer, tCursor0, (plVec2){tCursor0.x + fTotalWidth - 6.0f, 30.0f + tCursor0.y}, tAvailableColor, 1.0f, 0.0f, 0); + gptDraw->add_rect(ptFgLayer, tCursor0, (plVec2){tCursor0.x + fTotalWidth - 6.0f, 30.0f + tCursor0.y}, (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(tAvailableColor), .fThickness = 1.0f}); else - gptDraw->add_rect_filled(ptFgLayer, tCursor0, (plVec2){tCursor0.x + fTotalWidth, 30.0f + tCursor0.y}, tAvailableColor, 0.0f, 0); + gptDraw->add_rect_filled(ptFgLayer, tCursor0, (plVec2){tCursor0.x + fTotalWidth, 30.0f + tCursor0.y}, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tAvailableColor)}); gptUI->invisible_button(pcTempBuffer1, (plVec2){fTotalWidth, 30.0f}); if(gptUI->was_last_item_hovered()) { @@ -922,15 +922,15 @@ pl__show_device_memory(bool* bValue) const float fAvailableWidth = fWidthAvailable * ((float)ptRange->ulTotalSize) / (float)ulMaxBlockSize; const float fYPos = fHeight0 + 34.0f * (float)ptBlock->uCurrentIndex; - gptDraw->add_rect_filled(ptFgLayer, (plVec2){fStartPos, fYPos}, (plVec2){fStartPos + fAvailableWidth, 30.0f + fYPos}, tWastedColor, 0.0f, 0); - gptDraw->add_rect_filled(ptFgLayer, (plVec2){fStartPos, fYPos}, (plVec2){fStartPos + fUsedWidth, 30.0f + fYPos}, tUsedColor, 0.0f, 0); + gptDraw->add_rect_rounded_filled(ptFgLayer, (plVec2){fStartPos, fYPos}, (plVec2){fStartPos + fAvailableWidth, 30.0f + fYPos}, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tWastedColor)}); + gptDraw->add_rect_rounded_filled(ptFgLayer, (plVec2){fStartPos, fYPos}, (plVec2){fStartPos + fUsedWidth, 30.0f + fYPos}, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tUsedColor)}); if(ptRange->ulBlockIndex == ulHoveredBlock) { const plRect tHitBox = pl_calculate_rect((plVec2){fStartPos, fYPos}, (plVec2){fAvailableWidth, 30}); if(pl_rect_contains_point(&tHitBox, tMousePos)) { - gptDraw->add_rect(ptFgLayer, tHitBox.tMin, tHitBox.tMax, tWhiteColor, 1.0f, 0.0f, 0); + gptDraw->add_rect(ptFgLayer, tHitBox.tMin, tHitBox.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(tWhiteColor), .fThickness = 1.0f}); gptUI->begin_tooltip(); gptUI->text(ptRange->acName); gptUI->text("Offset: %lu", ptRange->ulOffset); diff --git a/extensions/pl_draw_backend_ext.c b/extensions/pl_draw_backend_ext.c index e935cc32..e7295a5d 100644 --- a/extensions/pl_draw_backend_ext.c +++ b/extensions/pl_draw_backend_ext.c @@ -8,6 +8,7 @@ #include "pl_shader_ext.h" #include "pl_draw_backend_ext.h" #include "pl_draw_ext.h" +#include "pl_stats_ext.h" #include "pl_ext.inc" @@ -155,6 +156,19 @@ pl_cleanup_draw_backend(void) static void pl_new_draw_frame(void) { + + static double* pd2dPipelineCount = NULL; + static double* pd3dPipelineCount = NULL; + + if(!pd2dPipelineCount) + pd2dPipelineCount = gptStats->get_counter("Draw 2D Pipelines"); + + if(!pd3dPipelineCount) + pd3dPipelineCount = gptStats->get_counter("Draw 3D Pipelines"); + + *pd2dPipelineCount = pl_sb_size(gptDrawBackendCtx->sbt2dPipelineEntries); + *pd3dPipelineCount = pl_sb_size(gptDrawBackendCtx->sbt3dPipelineEntries); + gptDraw->new_frame(); // reset buffer offsets @@ -175,7 +189,7 @@ pl_build_font_atlas_backend(plFontAtlas* ptAtlas) // create texture const plTextureDesc tFontTextureDesc = { - .tDimensions = {(float)ptAtlas->auAtlasSize[0], (float)ptAtlas->auAtlasSize[1], 1}, + .tDimensions = {ptAtlas->tAtlasSize.x, ptAtlas->tAtlasSize.y, 1}, .tFormat = PL_FORMAT_R8G8B8A8_UNORM, .uLayers = 1, .uMips = 1, @@ -201,7 +215,7 @@ pl_build_font_atlas_backend(plFontAtlas* ptAtlas) const plBufferDescription tBufferDesc = { .tUsage = PL_BUFFER_USAGE_STAGING, - .uByteSize = ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1] * 4 + .uByteSize = (uint32_t)(ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y * 4) }; plBufferHandle tStagingBuffer = pl__create_staging_buffer(&tBufferDesc, "font staging buffer", 0); plBuffer* ptStagingBuffer = gptGfx->get_buffer(ptDevice, tStagingBuffer); @@ -214,7 +228,7 @@ pl_build_font_atlas_backend(plFontAtlas* ptAtlas) plBlitEncoderHandle tEncoder = gptGfx->begin_blit_pass(tCommandBuffer); const plBufferImageCopy tBufferImageCopy = { - .tImageExtent = {(uint32_t)ptAtlas->auAtlasSize[0], (uint32_t)ptAtlas->auAtlasSize[1], 1}, + .tImageExtent = {(uint32_t)ptAtlas->tAtlasSize.x, (uint32_t)ptAtlas->tAtlasSize.y, 1}, .uLayerCount = 1 }; @@ -533,6 +547,9 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u static void pl_submit_2d_drawlist(plDrawList2D* ptDrawlist, plRenderEncoderHandle tEncoder, float fWidth, float fHeight, uint32_t uMSAASampleCount) { + + gptDraw->prepare_2d_drawlist(ptDrawlist); + if(pl_sb_size(ptDrawlist->sbtVertexBuffer) == 0u) return; @@ -573,7 +590,7 @@ pl_submit_2d_drawlist(plDrawList2D* ptDrawlist, plRenderEncoderHandle tEncoder, //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~index buffer prep~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ensure gpu index buffer size is adequate - const uint32_t uIdxBufSzNeeded = sizeof(uint32_t) * ptDrawlist->uIndexBufferByteSize; + const uint32_t uIdxBufSzNeeded = ptDrawlist->uIndexBufferByteSize; // space left in index buffer const uint32_t uAvailableIndexBufferSpace = gptDrawBackendCtx->auIndexBufferSize[uFrameIdx] - gptDrawBackendCtx->auIndexBufferOffset[uFrameIdx]; @@ -592,65 +609,17 @@ pl_submit_2d_drawlist(plDrawList2D* ptDrawlist, plRenderEncoderHandle tEncoder, gptDrawBackendCtx->auIndexBufferOffset[uFrameIdx] = 0; } + // index GPU data transfer plBuffer* ptIndexBuffer = gptGfx->get_buffer(ptDevice, gptDrawBackendCtx->atIndexBuffer[uFrameIdx]); char* pucMappedIndexBufferLocation = ptIndexBuffer->tMemoryAllocation.pHostMapped; - - char* pucDestination = &pucMappedIndexBufferLocation[gptDrawBackendCtx->auIndexBufferOffset[uFrameIdx]]; - - // index GPU data transfer - uint32_t uTempIndexBufferOffset = 0u; - uint32_t globalIdxBufferIndexOffset = 0u; - - for(uint32_t i = 0u; i < pl_sb_size(ptDrawlist->sbtSubmittedLayers); i++) - { - plDrawCommand* ptLastCommand = NULL; - plDrawLayer2D* ptLayer = ptDrawlist->sbtSubmittedLayers[i]; - - memcpy(&pucDestination[uTempIndexBufferOffset], ptLayer->sbuIndexBuffer, sizeof(uint32_t) * pl_sb_size(ptLayer->sbuIndexBuffer)); - - uTempIndexBufferOffset += pl_sb_size(ptLayer->sbuIndexBuffer)*sizeof(uint32_t); - - // attempt to merge commands - for(uint32_t j = 0u; j < pl_sb_size(ptLayer->sbtCommandBuffer); j++) - { - plDrawCommand* ptLayerCommand = &ptLayer->sbtCommandBuffer[j]; - bool bCreateNewCommand = true; - - if(ptLastCommand) - { - // check for same texture (allows merging draw calls) - if(ptLastCommand->tTextureId == ptLayerCommand->tTextureId && ptLastCommand->bSdf == ptLayerCommand->bSdf) - { - ptLastCommand->uElementCount += ptLayerCommand->uElementCount; - bCreateNewCommand = false; - } - - // check for same clipping (allows merging draw calls) - if(ptLayerCommand->tClip.tMax.x != ptLastCommand->tClip.tMax.x || ptLayerCommand->tClip.tMax.y != ptLastCommand->tClip.tMax.y || - ptLayerCommand->tClip.tMin.x != ptLastCommand->tClip.tMin.x || ptLayerCommand->tClip.tMin.y != ptLastCommand->tClip.tMin.y) - { - bCreateNewCommand = true; - } - - } - - if(bCreateNewCommand) - { - ptLayerCommand->uIndexOffset = globalIdxBufferIndexOffset + ptLayerCommand->uIndexOffset; - pl_sb_push(ptDrawlist->sbtDrawCommands, *ptLayerCommand); - ptLastCommand = ptLayerCommand; - } - - } - globalIdxBufferIndexOffset += pl_sb_size(ptLayer->sbuIndexBuffer); - } + memcpy(&pucMappedIndexBufferLocation[gptDrawBackendCtx->auIndexBufferOffset[uFrameIdx]], ptDrawlist->sbuIndexBuffer, uIdxBufSzNeeded); const int32_t iVertexOffset = ptBufferInfo->uVertexBufferOffset / sizeof(plDrawVertex); const int32_t iIndexOffset = gptDrawBackendCtx->auIndexBufferOffset[uFrameIdx] / sizeof(uint32_t); const plPipelineEntry* ptEntry = pl__get_2d_pipeline(gptGfx->get_encoder_render_pass(tEncoder), uMSAASampleCount, gptGfx->get_render_encoder_subpass(tEncoder)); -// const plVec2 tClipScale = gptIOI->get_io()->tMainFramebufferScale; + // const plVec2 tClipScale = gptIOI->get_io()->tMainFramebufferScale; // const plVec2 tClipScale = {1.0f, 1.0f}; // const plVec2 tClipScale = ptCtx->tFrameBufferScale; @@ -684,7 +653,8 @@ pl_submit_2d_drawlist(plDrawList2D* ptDrawlist, plRenderEncoderHandle tEncoder, gptGfx->bind_vertex_buffer(tEncoder, ptBufferInfo->tVertexBuffer); gptGfx->bind_shader(tEncoder, tCurrentShader); - for(uint32_t i = 0u; i < pl_sb_size(ptDrawlist->sbtDrawCommands); i++) + const uint32_t uCmdCount = pl_sb_size(ptDrawlist->sbtDrawCommands); + for(uint32_t i = 0u; i < uCmdCount; i++) { plDrawCommand cmd = ptDrawlist->sbtDrawCommands[i]; @@ -960,7 +930,14 @@ pl_submit_3d_drawlist(plDrawList3D* ptDrawlist, plRenderEncoderHandle tEncoder, { tPos.x = fWidth * 0.5f * (1.0f + tPos.x); tPos.y = fHeight * 0.5f * (1.0f + tPos.y); - pl_add_text(ptDrawlist->ptLayer, ptText->tFontHandle, ptText->fSize, (plVec2){roundf(tPos.x + 0.5f), roundf(tPos.y + 0.5f)}, ptText->tColor, ptText->acText, ptText->fWrap); + pl_add_text_ex(ptDrawlist->ptLayer, + (plVec2){roundf(tPos.x + 0.5f), roundf(tPos.y + 0.5f)}, + ptText->acText, + (plDrawTextOptions){ + .fSize = ptText->fSize, + .ptFont = ptText->ptFont, + .fWrap = ptText->fWrap, + .uColor = ptText->uColor}); } } diff --git a/extensions/pl_draw_ext.c b/extensions/pl_draw_ext.c index 34d35d58..7a2f9525 100644 --- a/extensions/pl_draw_ext.c +++ b/extensions/pl_draw_ext.c @@ -45,6 +45,52 @@ Index of this file: // [SECTION] internal structs //----------------------------------------------------------------------------- +typedef struct _plFontCustomRect +{ + uint32_t uWidth; + uint32_t uHeight; + uint32_t uX; + uint32_t uY; + unsigned char* pucBytes; +} plFontCustomRect; + +typedef struct _plFontChar +{ + uint16_t x0; + uint16_t y0; + uint16_t x1; + uint16_t y1; + float xOff; + float yOff; + float xAdv; + float xOff2; + float yOff2; +} plFontChar; + +typedef struct _plFontGlyph +{ + float x0; + float y0; + float u0; + float v0; + float x1; + float y1; + float u1; + float v1; + float xAdvance; + float leftBearing; +} plFontGlyph; + +typedef struct _plDrawLayer2D +{ + plDrawList2D* ptDrawlist; + plDrawCommand* sbtCommandBuffer; + uint32_t* sbuIndexBuffer; + plVec2* sbtPath; + uint32_t uVertexCount; + plDrawCommand* _ptLastCommand; +} plDrawLayer2D; + typedef struct _plFontPrepData { stbtt_fontinfo fontInfo; @@ -89,7 +135,7 @@ static plDrawContext* gptDrawCtx = NULL; static void pl__prepare_draw_command(plDrawLayer2D*, plTextureID, bool sdf); static void pl__reserve_triangles(plDrawLayer2D*, uint32_t indexCount, uint32_t uVertexCount); -static void pl__add_vertex(plDrawLayer2D*, plVec2 pos, plVec4 color, plVec2 uv); +static void pl__add_vertex(plDrawLayer2D*, plVec2 pos, uint32_t color, plVec2 uv); static void pl__add_index(plDrawLayer2D*, uint32_t vertexStart, uint32_t i0, uint32_t i1, uint32_t i2); static inline float pl__get_max(float v1, float v2) { return v1 > v2 ? v1 : v2;} static inline int pl__get_min(int v1, int v2) { return v1 < v2 ? v1 : v2;} @@ -102,8 +148,8 @@ static char* plu__read_file(const char* file); #define pl__mul_f_vec2(left, right) (plVec2){(left) * (right).x, (left) * (right).y} // stateful drawing -#define pl__submit_path(ptLayer, color, thickness)\ - pl_add_lines((ptLayer), (ptLayer)->sbtPath, pl_sb_size((ptLayer)->sbtPath) - 1, (color), (thickness));\ +#define pl__submit_path(ptLayer, tOptions)\ + pl_add_lines((ptLayer), (ptLayer)->sbtPath, pl_sb_size((ptLayer)->sbtPath) - 1, (tOptions));\ pl_sb_reset((ptLayer)->sbtPath); #define PL_NORMALIZE2F_OVER_ZERO(VX,VY) \ @@ -112,13 +158,8 @@ static char* plu__read_file(const char* file); static inline void -pl__add_3d_indexed_lines(plDrawList3D* ptDrawlist, uint32_t uIndexCount, const plVec3* atPoints, const uint32_t* auIndices, plVec4 tColor, float fThickness) +pl__add_3d_indexed_lines(plDrawList3D* ptDrawlist, uint32_t uIndexCount, const plVec3* atPoints, const uint32_t* auIndices, plDrawLineOptions tOptions) { - uint32_t tU32Color = 0; - tU32Color = (uint32_t) (255.0f * tColor.r + 0.5f); - tU32Color |= (uint32_t) (255.0f * tColor.g + 0.5f) << 8; - tU32Color |= (uint32_t) (255.0f * tColor.b + 0.5f) << 16; - tU32Color |= (uint32_t) (255.0f * tColor.a + 0.5f) << 24; const uint32_t uVertexStart = pl_sb_size(ptDrawlist->sbtLineVertexBuffer); const uint32_t uIndexStart = pl_sb_size(ptDrawlist->sbtLineIndexBuffer); @@ -140,19 +181,19 @@ pl__add_3d_indexed_lines(plDrawList3D* ptDrawlist, uint32_t uIndexCount, const p plDrawVertex3DLine tNewVertex0 = { {tP0.x, tP0.y, tP0.z}, -1.0f, - fThickness, + tOptions.fThickness, 1.0f, {tP1.x, tP1.y, tP1.z}, - tU32Color + tOptions.uColor }; plDrawVertex3DLine tNewVertex1 = { {tP1.x, tP1.y, tP1.z}, -1.0f, - fThickness, + tOptions.fThickness, -1.0f, {tP0.x, tP0.y, tP0.z}, - tU32Color + tOptions.uColor }; ptDrawlist->sbtLineVertexBuffer[uCurrentVertex] = tNewVertex0; @@ -176,14 +217,8 @@ pl__add_3d_indexed_lines(plDrawList3D* ptDrawlist, uint32_t uIndexCount, const p } static inline void -pl__add_3d_lines(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoints, plVec4 tColor, float fThickness) +pl__add_3d_lines(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoints, plDrawLineOptions tOptions) { - uint32_t tU32Color = 0; - tU32Color = (uint32_t) (255.0f * tColor.r + 0.5f); - tU32Color |= (uint32_t) (255.0f * tColor.g + 0.5f) << 8; - tU32Color |= (uint32_t) (255.0f * tColor.b + 0.5f) << 16; - tU32Color |= (uint32_t) (255.0f * tColor.a + 0.5f) << 24; - const uint32_t uVertexStart = pl_sb_size(ptDrawlist->sbtLineVertexBuffer); const uint32_t uIndexStart = pl_sb_size(ptDrawlist->sbtLineIndexBuffer); @@ -200,19 +235,19 @@ pl__add_3d_lines(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoin plDrawVertex3DLine tNewVertex0 = { {tP0.x, tP0.y, tP0.z}, -1.0f, - fThickness, + tOptions.fThickness, 1.0f, {tP1.x, tP1.y, tP1.z}, - tU32Color + tOptions.uColor }; plDrawVertex3DLine tNewVertex1 = { {tP1.x, tP1.y, tP1.z}, -1.0f, - fThickness, + tOptions.fThickness, -1.0f, {tP0.x, tP0.y, tP0.z}, - tU32Color + tOptions.uColor }; ptDrawlist->sbtLineVertexBuffer[uCurrentVertex] = tNewVertex0; @@ -236,14 +271,8 @@ pl__add_3d_lines(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoin } static inline void -pl__add_3d_path(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoints, plVec4 tColor, float fThickness) +pl__add_3d_path(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoints, plDrawLineOptions tOptions) { - uint32_t tU32Color = 0; - tU32Color = (uint32_t) (255.0f * tColor.r + 0.5f); - tU32Color |= (uint32_t) (255.0f * tColor.g + 0.5f) << 8; - tU32Color |= (uint32_t) (255.0f * tColor.b + 0.5f) << 16; - tU32Color |= (uint32_t) (255.0f * tColor.a + 0.5f) << 24; - const uint32_t uVertexStart = pl_sb_size(ptDrawlist->sbtLineVertexBuffer); const uint32_t uIndexStart = pl_sb_size(ptDrawlist->sbtLineIndexBuffer); @@ -260,19 +289,19 @@ pl__add_3d_path(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoint plDrawVertex3DLine tNewVertex0 = { {tP0.x, tP0.y, tP0.z}, -1.0f, - fThickness, + tOptions.fThickness, 1.0f, {tP1.x, tP1.y, tP1.z}, - tU32Color + tOptions.uColor }; plDrawVertex3DLine tNewVertex1 = { {tP1.x, tP1.y, tP1.z}, -1.0f, - fThickness, + tOptions.fThickness, -1.0f, {tP0.x, tP0.y, tP0.z}, - tU32Color + tOptions.uColor }; ptDrawlist->sbtLineVertexBuffer[uCurrentVertex] = tNewVertex0; @@ -327,21 +356,21 @@ pl_cleanup(void) for(uint32_t i = 0; i < gptDrawCtx->uDrawlistCount2D; i++) { plDrawList2D* ptDrawlist = gptDrawCtx->aptDrawlists2D[i]; - pl_sb_free(ptDrawlist->sbtClipStack); + pl_sb_free(ptDrawlist->_sbtClipStack); pl_sb_free(ptDrawlist->sbtDrawCommands); - pl_sb_free(ptDrawlist->sbtLayerCache); - - pl_sb_free(ptDrawlist->sbtSubmittedLayers); + pl_sb_free(ptDrawlist->_sbtLayerCache); + pl_sb_free(ptDrawlist->_sbtSubmittedLayers); pl_sb_free(ptDrawlist->sbtVertexBuffer); + pl_sb_free(ptDrawlist->sbuIndexBuffer); - for(uint32_t j = 0; j < pl_sb_size(ptDrawlist->sbtLayersCreated); j++) + for(uint32_t j = 0; j < pl_sb_size(ptDrawlist->_sbtLayersCreated); j++) { - pl_sb_free(ptDrawlist->sbtLayersCreated[j]->sbtCommandBuffer); - pl_sb_free(ptDrawlist->sbtLayersCreated[j]->sbtPath); - pl_sb_free(ptDrawlist->sbtLayersCreated[j]->sbuIndexBuffer); - PL_FREE(ptDrawlist->sbtLayersCreated[j]); + pl_sb_free(ptDrawlist->_sbtLayersCreated[j]->sbtCommandBuffer); + pl_sb_free(ptDrawlist->_sbtLayersCreated[j]->sbtPath); + pl_sb_free(ptDrawlist->_sbtLayersCreated[j]->sbuIndexBuffer); + PL_FREE(ptDrawlist->_sbtLayersCreated[j]); } - pl_sb_free(ptDrawlist->sbtLayersCreated); + pl_sb_free(ptDrawlist->_sbtLayersCreated); } pl_temp_allocator_free(&gptDrawCtx->tTempAllocator); } @@ -367,18 +396,17 @@ pl_request_2d_layer(plDrawList2D* ptDrawlist) // check if ptDrawlist has any cached layers // which reduces allocations necessary since // cached layers' buffers are only reset - if(pl_sb_size(ptDrawlist->sbtLayerCache) > 0) + if(pl_sb_size(ptDrawlist->_sbtLayerCache) > 0) { - ptLayer = pl_sb_pop(ptDrawlist->sbtLayerCache); + ptLayer = pl_sb_pop(ptDrawlist->_sbtLayerCache); } else // create new ptLayer { - ptDrawlist->uLayersCreated++; ptLayer = PL_ALLOC(sizeof(plDrawLayer2D)); memset(ptLayer, 0, sizeof(plDrawLayer2D)); ptLayer->ptDrawlist = ptDrawlist; - pl_sb_push(ptDrawlist->sbtLayersCreated, ptLayer); + pl_sb_push(ptDrawlist->_sbtLayersCreated, ptLayer); } pl_sb_reserve(ptLayer->sbuIndexBuffer, 1024); @@ -450,6 +478,53 @@ pl_return_2d_drawlist(plDrawList2D* ptDrawlist) gptDrawCtx->uDrawlistCount2D--; } +static void +pl_prepare_2d_drawlist(plDrawList2D* ptDrawlist) +{ + uint32_t globalIdxBufferIndexOffset = 0u; + const uint32_t uLayerCount = pl_sb_size(ptDrawlist->_sbtSubmittedLayers); + for(uint32_t i = 0u; i < uLayerCount; i++) + { + plDrawLayer2D* ptLayer = ptDrawlist->_sbtSubmittedLayers[i]; + plDrawCommand* ptLastCommand = NULL; + + // attempt to merge commands + const uint32_t uCmdCount = pl_sb_size(ptLayer->sbtCommandBuffer); + for(uint32_t j = 0u; j < uCmdCount; j++) + { + plDrawCommand* ptLayerCommand = &ptLayer->sbtCommandBuffer[j]; + bool bCreateNewCommand = true; + + if(ptLastCommand) + { + // check for same texture (allows merging draw calls) + if(ptLastCommand->tTextureId == ptLayerCommand->tTextureId && ptLastCommand->bSdf == ptLayerCommand->bSdf) + { + ptLastCommand->uElementCount += ptLayerCommand->uElementCount; + bCreateNewCommand = false; + } + + // check for same clipping (allows merging draw calls) + if(ptLayerCommand->tClip.tMax.x != ptLastCommand->tClip.tMax.x || ptLayerCommand->tClip.tMax.y != ptLastCommand->tClip.tMax.y || + ptLayerCommand->tClip.tMin.x != ptLastCommand->tClip.tMin.x || ptLayerCommand->tClip.tMin.y != ptLastCommand->tClip.tMin.y) + { + bCreateNewCommand = true; + } + + } + + if(bCreateNewCommand) + { + ptLayerCommand->uIndexOffset = globalIdxBufferIndexOffset + ptLayerCommand->uIndexOffset; + pl_sb_push(ptDrawlist->sbtDrawCommands, *ptLayerCommand); + ptLastCommand = ptLayerCommand; + } + + } + globalIdxBufferIndexOffset += pl_sb_size(ptLayer->sbuIndexBuffer); + } +} + static void pl_return_2d_layer(plDrawLayer2D* ptLayer) { @@ -458,18 +533,24 @@ pl_return_2d_layer(plDrawLayer2D* ptLayer) pl_sb_reset(ptLayer->sbtCommandBuffer); pl_sb_reset(ptLayer->sbuIndexBuffer); pl_sb_reset(ptLayer->sbtPath); - pl_sb_push(ptLayer->ptDrawlist->sbtLayerCache, ptLayer); + pl_sb_push(ptLayer->ptDrawlist->_sbtLayerCache, ptLayer); } static void pl_submit_2d_layer(plDrawLayer2D* ptLayer) { - pl_sb_push(ptLayer->ptDrawlist->sbtSubmittedLayers, ptLayer); - ptLayer->ptDrawlist->uIndexBufferByteSize += pl_sb_size(ptLayer->sbuIndexBuffer) * sizeof(uint32_t); + pl_sb_push(ptLayer->ptDrawlist->_sbtSubmittedLayers, ptLayer); + const uint32_t uCurrentIndexCount = pl_sb_size(ptLayer->ptDrawlist->sbuIndexBuffer); + const uint32_t uAdditionalIndexCount = pl_sb_size(ptLayer->sbuIndexBuffer); + if(uAdditionalIndexCount == 0) + return; + ptLayer->ptDrawlist->uIndexBufferByteSize += uAdditionalIndexCount * sizeof(uint32_t); + pl_sb_add_n(ptLayer->ptDrawlist->sbuIndexBuffer, uAdditionalIndexCount); + memcpy(&ptLayer->ptDrawlist->sbuIndexBuffer[uCurrentIndexCount], ptLayer->sbuIndexBuffer, uAdditionalIndexCount * sizeof(uint32_t)); } static void -pl_add_lines(plDrawLayer2D* ptLayer, plVec2* atPoints, uint32_t count, plVec4 color, float thickness) +pl_add_lines(plDrawLayer2D* ptLayer, plVec2* atPoints, uint32_t count, plDrawLineOptions tOptions) { pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, false); pl__reserve_triangles(ptLayer, 6 * count, 4 * count); @@ -488,17 +569,17 @@ pl_add_lines(plDrawLayer2D* ptLayer, plVec2* atPoints, uint32_t count, plVec4 co plVec2 cornerPoints[4] = { - pl__subtract_vec2(atPoints[i], pl__mul_vec2_f(normalVector, thickness / 2.0f)), - pl__subtract_vec2(atPoints[i + 1], pl__mul_vec2_f(normalVector, thickness / 2.0f)), - pl__add_vec2( atPoints[i + 1], pl__mul_vec2_f(normalVector, thickness / 2.0f)), - pl__add_vec2( atPoints[i], pl__mul_vec2_f(normalVector, thickness / 2.0f)) + pl__subtract_vec2(atPoints[i], pl__mul_vec2_f(normalVector, tOptions.fThickness / 2.0f)), + pl__subtract_vec2(atPoints[i + 1], pl__mul_vec2_f(normalVector, tOptions.fThickness / 2.0f)), + pl__add_vec2( atPoints[i + 1], pl__mul_vec2_f(normalVector, tOptions.fThickness / 2.0f)), + pl__add_vec2( atPoints[i], pl__mul_vec2_f(normalVector, tOptions.fThickness / 2.0f)) }; uint32_t vertexStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, cornerPoints[0], color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, cornerPoints[1], color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, cornerPoints[2], color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, cornerPoints[3], color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); + pl__add_vertex(ptLayer, cornerPoints[0], tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, cornerPoints[1], tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, cornerPoints[2], tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, cornerPoints[3], tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); pl__add_index(ptLayer, vertexStart, 0, 1, 2); pl__add_index(ptLayer, vertexStart, 0, 2, 3); @@ -506,20 +587,32 @@ pl_add_lines(plDrawLayer2D* ptLayer, plVec2* atPoints, uint32_t count, plVec4 co } static void -pl_add_line(plDrawLayer2D* ptLayer, plVec2 p0, plVec2 p1, plVec4 tColor, float fThickness) +pl_add_line(plDrawLayer2D* ptLayer, plVec2 p0, plVec2 p1, plDrawLineOptions tOptions) { pl_sb_push(ptLayer->sbtPath, p0); pl_sb_push(ptLayer->sbtPath, p1); - pl__submit_path(ptLayer, tColor, fThickness); + pl__submit_path(ptLayer, tOptions); } + static void -pl_add_text_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 p, plVec4 color, const char* text, const char* pcTextEnd, float wrap) +pl_add_text_ex(plDrawLayer2D* ptLayer, plVec2 p, const char* text, plDrawTextOptions tOptions) { + if(tOptions.pcTextEnd == NULL) + { + tOptions.pcTextEnd = text; + while(*tOptions.pcTextEnd != '\0') + tOptions.pcTextEnd++; + } + + plFont* font = tOptions.ptFont; + float size = tOptions.fSize; + const char* pcTextEnd = tOptions.pcTextEnd; + float scale = size > 0.0f ? size / font->fSize : 1.0f; - float fLineSpacing = scale * font->fLineSpacing; + float fLineSpacing = scale * font->_fLineSpacing; const plVec2 originalPosition = p; bool firstCharacter = true; @@ -548,10 +641,10 @@ pl_add_text_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 p, plVec { bool glyphFound = false; - const uint32_t uRangeCount = pl_sb_size(font->sbtRanges); + const uint32_t uRangeCount = pl_sb_size(font->_sbtRanges); for(uint32_t i = 0u; i < uRangeCount; i++) { - const plFontRange* ptRange = &font->sbtRanges[i]; + const plFontRange* ptRange = &font->_sbtRanges[i]; if (c >= (uint32_t)ptRange->iFirstCodePoint && c < (uint32_t)ptRange->iFirstCodePoint + (uint32_t)ptRange->uCharCount) { @@ -559,7 +652,7 @@ pl_add_text_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 p, plVec float x0,y0,s0,t0; // top-left float x1,y1,s1,t1; // bottom-right - const plFontGlyph* glyph = &font->sbtGlyphs[font->_auCodePoints[c]]; + const plFontGlyph* glyph = &font->_sbtGlyphs[font->_auCodePoints[c]]; // adjust for left side bearing if first char if(firstCharacter) @@ -573,7 +666,7 @@ pl_add_text_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 p, plVec y0 = p.y + glyph->y0 * scale; y1 = p.y + glyph->y1 * scale; - if(wrap > 0.0f && x1 > originalPosition.x + wrap) + if(tOptions.fWrap > 0.0f && x1 > originalPosition.x + tOptions.fWrap) { x0 = originalPosition.x + glyph->x0 * scale; y0 = y0 + fLineSpacing; @@ -594,10 +687,10 @@ pl_add_text_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 p, plVec pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, font->_sbtConfigs[ptRange->_uConfigIndex].bSdf); pl__reserve_triangles(ptLayer, 6, 4); uint32_t uVtxStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, (plVec2){x0, y0}, color, (plVec2){s0, t0}); - pl__add_vertex(ptLayer, (plVec2){x1, y0}, color, (plVec2){s1, t0}); - pl__add_vertex(ptLayer, (plVec2){x1, y1}, color, (plVec2){s1, t1}); - pl__add_vertex(ptLayer, (plVec2){x0, y1}, color, (plVec2){s0, t1}); + pl__add_vertex(ptLayer, (plVec2){x0, y0}, tOptions.uColor, (plVec2){s0, t0}); + pl__add_vertex(ptLayer, (plVec2){x1, y0}, tOptions.uColor, (plVec2){s1, t0}); + pl__add_vertex(ptLayer, (plVec2){x1, y1}, tOptions.uColor, (plVec2){s1, t1}); + pl__add_vertex(ptLayer, (plVec2){x0, y1}, tOptions.uColor, (plVec2){s0, t1}); pl__add_index(ptLayer, uVtxStart, 1, 0, 2); pl__add_index(ptLayer, uVtxStart, 2, 0, 3); @@ -614,21 +707,26 @@ pl_add_text_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 p, plVec } static void -pl_add_text(plDrawLayer2D* ptLayer, plFont* ptFont, float size, plVec2 p, plVec4 color, const char* text, float wrap) +pl_add_text_clipped_ex(plDrawLayer2D* ptLayer, plVec2 p, const char* text, plVec2 tMin, plVec2 tMax, plDrawTextOptions tOptions) { - const char* pcTextEnd = text + strlen(text); - pl_add_text_ex(ptLayer, ptFont, size, p, color, text, pcTextEnd, wrap); -} -static void -pl_add_text_clipped_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 p, plVec2 tMin, plVec2 tMax, plVec4 color, const char* text, const char* pcTextEnd, float wrap) -{ + if(tOptions.pcTextEnd == NULL) + { + tOptions.pcTextEnd = text; + while (*tOptions.pcTextEnd != '\0') + tOptions.pcTextEnd++; + } + // const plVec2 tTextSize = pl_calculate_text_size_ex(font, size, text, pcTextEnd, wrap); const plRect tClipRect = {tMin, tMax}; + plFont* font = tOptions.ptFont; + float size = tOptions.fSize; + const char* pcTextEnd = tOptions.pcTextEnd; + float scale = size > 0.0f ? size / font->fSize : 1.0f; - float fLineSpacing = scale * font->fLineSpacing; + float fLineSpacing = scale * font->_fLineSpacing; const plVec2 originalPosition = p; bool firstCharacter = true; @@ -657,10 +755,10 @@ pl_add_text_clipped_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 { bool glyphFound = false; - const uint32_t uRangeCount = pl_sb_size(font->sbtRanges); + const uint32_t uRangeCount = pl_sb_size(font->_sbtRanges); for(uint32_t i = 0u; i < uRangeCount; i++) { - const plFontRange* ptRange = &font->sbtRanges[i]; + const plFontRange* ptRange = &font->_sbtRanges[i]; if (c >= (uint32_t)ptRange->iFirstCodePoint && c < (uint32_t)ptRange->iFirstCodePoint + (uint32_t)ptRange->uCharCount) { @@ -668,7 +766,7 @@ pl_add_text_clipped_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 float x0,y0,s0,t0; // top-left float x1,y1,s1,t1; // bottom-right - const plFontGlyph* glyph = &font->sbtGlyphs[font->_auCodePoints[c]]; + const plFontGlyph* glyph = &font->_sbtGlyphs[font->_auCodePoints[c]]; // adjust for left side bearing if first char if(firstCharacter) @@ -682,7 +780,7 @@ pl_add_text_clipped_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 y0 = p.y + glyph->y0 * scale; y1 = p.y + glyph->y1 * scale; - if(wrap > 0.0f && x1 > originalPosition.x + wrap) + if(tOptions.fWrap > 0.0f && x1 > originalPosition.x + tOptions.fWrap) { x0 = originalPosition.x + glyph->x0 * scale; y0 = y0 + fLineSpacing; @@ -703,10 +801,10 @@ pl_add_text_clipped_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, font->_sbtConfigs[ptRange->_uConfigIndex].bSdf); pl__reserve_triangles(ptLayer, 6, 4); uint32_t uVtxStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, (plVec2){x0, y0}, color, (plVec2){s0, t0}); - pl__add_vertex(ptLayer, (plVec2){x1, y0}, color, (plVec2){s1, t0}); - pl__add_vertex(ptLayer, (plVec2){x1, y1}, color, (plVec2){s1, t1}); - pl__add_vertex(ptLayer, (plVec2){x0, y1}, color, (plVec2){s0, t1}); + pl__add_vertex(ptLayer, (plVec2){x0, y0}, tOptions.uColor, (plVec2){s0, t0}); + pl__add_vertex(ptLayer, (plVec2){x1, y0}, tOptions.uColor, (plVec2){s1, t0}); + pl__add_vertex(ptLayer, (plVec2){x1, y1}, tOptions.uColor, (plVec2){s1, t1}); + pl__add_vertex(ptLayer, (plVec2){x0, y1}, tOptions.uColor, (plVec2){s0, t1}); pl__add_index(ptLayer, uVtxStart, 1, 0, 2); pl__add_index(ptLayer, uVtxStart, 2, 0, 3); @@ -723,38 +821,47 @@ pl_add_text_clipped_ex(plDrawLayer2D* ptLayer, plFont* font, float size, plVec2 } static void -pl_add_text_clipped(plDrawLayer2D* ptLayer, plFont* ptFont, float fSize, plVec2 tP, plVec2 tMin, plVec2 tMax, plVec4 tColor, const char* pcText, float fWrap) -{ - const char* pcTextEnd = pcText + strlen(pcText); - pl_add_text_clipped_ex(ptLayer, ptFont, fSize, tP, tMin, tMax, tColor, pcText, pcTextEnd, fWrap); -} - -static void -pl_add_triangle(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec4 tColor, float fThickness) +pl_add_triangle(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plDrawLineOptions tOptions) { pl_sb_push(ptLayer->sbtPath, tP0); pl_sb_push(ptLayer->sbtPath, tP1); pl_sb_push(ptLayer->sbtPath, tP2); pl_sb_push(ptLayer->sbtPath, tP0); - pl__submit_path(ptLayer, tColor, fThickness); + pl__submit_path(ptLayer, tOptions); } static void -pl_add_triangle_filled(plDrawLayer2D* ptLayer, plVec2 p0, plVec2 p1, plVec2 p2, plVec4 color) +pl_add_triangle_filled(plDrawLayer2D* ptLayer, plVec2 p0, plVec2 p1, plVec2 p2, plDrawSolidOptions tOptions) { pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, false); pl__reserve_triangles(ptLayer, 3, 3); uint32_t vertexStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, p0, color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, p1, color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, p2, color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); + pl__add_vertex(ptLayer, p0, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, p1, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, p2, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); pl__add_index(ptLayer, vertexStart, 0, 1, 2); } static void -pl_add_rect(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fThickness) +pl_add_triangles_filled(plDrawLayer2D* ptLayer, plVec2* atPoints, uint32_t uCount, plDrawSolidOptions tOptions) +{ + pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, false); + pl__reserve_triangles(ptLayer, 3 * uCount, 3 * uCount); + + for(uint32_t i = 0; i < uCount; i++) + { + uint32_t vertexStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); + pl__add_vertex(ptLayer, atPoints[i * 3 + 0], tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, atPoints[i * 3 + 1], tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, atPoints[i * 3 + 2], tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_index(ptLayer, vertexStart, 0, 1, 2); + } +} + +static void +pl_add_rect(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plDrawLineOptions tOptions) { const plVec2 fBotLeftVec = {tMinP.x, tMaxP.y}; const plVec2 fTopRightVec = {tMaxP.x, tMinP.y}; @@ -764,11 +871,11 @@ pl_add_rect(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, f pl_sb_push(ptLayer->sbtPath, tMaxP); pl_sb_push(ptLayer->sbtPath, fTopRightVec); pl_sb_push(ptLayer->sbtPath, tMinP); - pl__submit_path(ptLayer, tColor, fThickness); + pl__submit_path(ptLayer, tOptions); } static void -pl_add_rect_filled(plDrawLayer2D* ptLayer, plVec2 minP, plVec2 maxP, plVec4 color) +pl_add_rect_filled(plDrawLayer2D* ptLayer, plVec2 minP, plVec2 maxP, plDrawSolidOptions tOptions) { pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, false); pl__reserve_triangles(ptLayer, 6, 4); @@ -777,25 +884,32 @@ pl_add_rect_filled(plDrawLayer2D* ptLayer, plVec2 minP, plVec2 maxP, plVec4 colo const plVec2 topRight = { maxP.x, minP.y }; const uint32_t vertexStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, minP, color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, bottomLeft, color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, maxP, color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, topRight, color, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); + pl__add_vertex(ptLayer, minP, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, bottomLeft, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, maxP, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, topRight, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); pl__add_index(ptLayer, vertexStart, 0, 1, 2); pl__add_index(ptLayer, vertexStart, 0, 2, 3); } static void -pl_add_rect_rounded_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fThickness, float fRadius, uint32_t uSegments, plDrawRectFlags tFlags) +pl_add_rect_rounded_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, float fRadius, uint32_t uSegments, plDrawRectFlags tFlags, plDrawLineOptions tOptions) { // segments is the number of segments used to approximate one corner if(fRadius <= 0.0f) { - pl_add_rect(ptLayer, tMinP, tMaxP, tColor, fThickness); + pl_add_rect(ptLayer, tMinP, tMaxP, tOptions); return; } + else + { + if(tFlags == PL_DRAW_RECT_FLAG_NONE) + { + tFlags = PL_DRAW_RECT_FLAG_ROUND_CORNERS_All; + } + } if(uSegments == 0){ uSegments = 4; } const float fIncrement = PL_PI_2 / uSegments; @@ -856,23 +970,24 @@ pl_add_rect_rounded_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plVec pl_sb_push(ptLayer->sbtPath, bottomRightStart); - pl__submit_path(ptLayer, tColor, fThickness); -} - -static void -pl_add_rect_rounded(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fThickness, float fRadius, uint32_t uSegments) -{ - pl_add_rect_rounded_ex(ptLayer, tMinP, tMaxP, tColor, fThickness, fRadius, uSegments, PL_DRAW_RECT_FLAG_ROUND_CORNERS_All); + pl__submit_path(ptLayer, tOptions); } static void -pl_add_rect_rounded_filled_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fRadius, uint32_t uSegments, plDrawRectFlags tFlags) +pl_add_rect_rounded_filled_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, float fRadius, uint32_t uSegments, plDrawRectFlags tFlags, plDrawSolidOptions tOptions) { if(fRadius <= 0.0f) { - pl_add_rect_filled(ptLayer, tMinP, tMaxP, tColor); + pl_add_rect_filled(ptLayer, tMinP, tMaxP, tOptions); return; } + else + { + if(tFlags == PL_DRAW_RECT_FLAG_NONE) + { + tFlags = PL_DRAW_RECT_FLAG_ROUND_CORNERS_All; + } + } if(tMaxP.x - tMinP.x < fRadius * 2.0f) { @@ -904,19 +1019,19 @@ pl_add_rect_rounded_filled_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP const plVec2 tOuterTopRight1 = {tMaxP.x - fRadius, tMinP.y}; const uint32_t uVertexStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, tInnerTopLeft, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tInnerBottomLeft, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tInnerBottomRight, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tInnerTopRight, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - - pl__add_vertex(ptLayer, tOuterTopLeft1, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tOuterBottomLeft0, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tOuterBottomLeft1, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tOuterBottomRight0, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tOuterBottomRight1, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tOuterTopRight0, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tOuterTopRight1, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); - pl__add_vertex(ptLayer, tOuterTopLeft0, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); + pl__add_vertex(ptLayer, tInnerTopLeft, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tInnerBottomLeft, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tInnerBottomRight, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tInnerTopRight, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + + pl__add_vertex(ptLayer, tOuterTopLeft1, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tOuterBottomLeft0, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tOuterBottomLeft1, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tOuterBottomRight0, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tOuterBottomRight1, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tOuterTopRight0, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tOuterTopRight1, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); + pl__add_vertex(ptLayer, tOuterTopLeft0, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); // center pl__add_index(ptLayer, uVertexStart, 0, 1, 2); @@ -947,16 +1062,16 @@ pl_add_rect_rounded_filled_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP for(uint32_t i = 0; i < uSegments - 1; i++) { plVec2 tPoint = {tInnerTopLeft.x + fRadius * cosf(fTheta), tInnerTopLeft.y - fRadius * sinf(fTheta)}; - pl_add_triangle_filled(ptLayer, tInnerTopLeft, tLastPoint, tPoint, tColor); + pl_add_triangle_filled(ptLayer, tInnerTopLeft, tLastPoint, tPoint, tOptions); tLastPoint = tPoint; fTheta += fIncrement; } - pl_add_triangle_filled(ptLayer, tInnerTopLeft, tLastPoint, tOuterTopLeft1, tColor); + pl_add_triangle_filled(ptLayer, tInnerTopLeft, tLastPoint, tOuterTopLeft1, tOptions); } else { - pl_add_triangle_filled(ptLayer, tInnerTopLeft, tOuterTopLeft0, tMinP, tColor); - pl_add_triangle_filled(ptLayer, tInnerTopLeft, tMinP, tOuterTopLeft1, tColor); + pl_add_triangle_filled(ptLayer, tInnerTopLeft, tOuterTopLeft0, tMinP, tOptions); + pl_add_triangle_filled(ptLayer, tInnerTopLeft, tMinP, tOuterTopLeft1, tOptions); } if(tFlags & PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT) @@ -966,16 +1081,16 @@ pl_add_rect_rounded_filled_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP for(uint32_t i = 0; i < uSegments - 1; i++) { plVec2 tPoint = {tInnerBottomLeft.x + fRadius * cosf(fTheta), tInnerBottomLeft.y - fRadius * sinf(fTheta)}; - pl_add_triangle_filled(ptLayer, tInnerBottomLeft, tLastPoint, tPoint, tColor); + pl_add_triangle_filled(ptLayer, tInnerBottomLeft, tLastPoint, tPoint, tOptions); tLastPoint = tPoint; fTheta += fIncrement; } - pl_add_triangle_filled(ptLayer, tInnerBottomLeft, tLastPoint, tOuterBottomLeft1, tColor); + pl_add_triangle_filled(ptLayer, tInnerBottomLeft, tLastPoint, tOuterBottomLeft1, tOptions); } else { - pl_add_triangle_filled(ptLayer, tInnerBottomLeft, tOuterBottomLeft0, (plVec2){tMinP.x, tMaxP.y}, tColor); - pl_add_triangle_filled(ptLayer, tInnerBottomLeft, (plVec2){tMinP.x, tMaxP.y}, tOuterBottomLeft1, tColor); + pl_add_triangle_filled(ptLayer, tInnerBottomLeft, tOuterBottomLeft0, (plVec2){tMinP.x, tMaxP.y}, tOptions); + pl_add_triangle_filled(ptLayer, tInnerBottomLeft, (plVec2){tMinP.x, tMaxP.y}, tOuterBottomLeft1, tOptions); } if(tFlags & PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT) @@ -985,16 +1100,16 @@ pl_add_rect_rounded_filled_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP for(uint32_t i = 0; i < uSegments - 1; i++) { plVec2 tPoint = {tInnerBottomRight.x + fRadius * cosf(fTheta), tInnerBottomRight.y - fRadius * sinf(fTheta)}; - pl_add_triangle_filled(ptLayer, tInnerBottomRight, tLastPoint, tPoint, tColor); + pl_add_triangle_filled(ptLayer, tInnerBottomRight, tLastPoint, tPoint, tOptions); tLastPoint = tPoint; fTheta += fIncrement; } - pl_add_triangle_filled(ptLayer, tInnerBottomRight, tLastPoint, tOuterBottomRight1, tColor); + pl_add_triangle_filled(ptLayer, tInnerBottomRight, tLastPoint, tOuterBottomRight1, tOptions); } else { - pl_add_triangle_filled(ptLayer, tInnerBottomRight, tOuterBottomRight0, tMaxP, tColor); - pl_add_triangle_filled(ptLayer, tInnerBottomRight, tMaxP, tOuterBottomRight1, tColor); + pl_add_triangle_filled(ptLayer, tInnerBottomRight, tOuterBottomRight0, tMaxP, tOptions); + pl_add_triangle_filled(ptLayer, tInnerBottomRight, tMaxP, tOuterBottomRight1, tOptions); } if(tFlags & PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT) @@ -1004,54 +1119,48 @@ pl_add_rect_rounded_filled_ex(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP for(uint32_t i = 0; i < uSegments - 1; i++) { plVec2 tPoint = {tInnerTopRight.x + fRadius * cosf(fTheta), tInnerTopRight.y - fRadius * sinf(fTheta)}; - pl_add_triangle_filled(ptLayer, tInnerTopRight, tLastPoint, tPoint, tColor); + pl_add_triangle_filled(ptLayer, tInnerTopRight, tLastPoint, tPoint, tOptions); tLastPoint = tPoint; fTheta += fIncrement; } - pl_add_triangle_filled(ptLayer, tInnerTopRight, tLastPoint, tOuterTopRight1, tColor); + pl_add_triangle_filled(ptLayer, tInnerTopRight, tLastPoint, tOuterTopRight1, tOptions); } else { - pl_add_triangle_filled(ptLayer, tInnerTopRight, tOuterTopRight0, (plVec2){tMaxP.x, tMinP.y}, tColor); - pl_add_triangle_filled(ptLayer, tInnerTopRight, (plVec2){tMaxP.x, tMinP.y}, tOuterTopRight1, tColor); + pl_add_triangle_filled(ptLayer, tInnerTopRight, tOuterTopRight0, (plVec2){tMaxP.x, tMinP.y}, tOptions); + pl_add_triangle_filled(ptLayer, tInnerTopRight, (plVec2){tMaxP.x, tMinP.y}, tOuterTopRight1, tOptions); } } -static void -pl_add_rect_rounded_filled(plDrawLayer2D* ptLayer, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fRadius, uint32_t uSegments) -{ - pl_add_rect_rounded_filled_ex(ptLayer, tMinP, tMaxP, tColor, fRadius, uSegments, PL_DRAW_RECT_FLAG_ROUND_CORNERS_All); -} - static void -pl_add_quad(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plVec4 tColor, float fThickness) +pl_add_quad(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plDrawLineOptions tOptions) { pl_sb_push(ptLayer->sbtPath, tP0); pl_sb_push(ptLayer->sbtPath, tP1); pl_sb_push(ptLayer->sbtPath, tP2); pl_sb_push(ptLayer->sbtPath, tP3); pl_sb_push(ptLayer->sbtPath, tP0); - pl__submit_path(ptLayer, tColor, fThickness); + pl__submit_path(ptLayer, tOptions); } static void -pl_add_quad_filled(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plVec4 tColor) +pl_add_quad_filled(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plDrawSolidOptions tOptions) { pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, false); pl__reserve_triangles(ptLayer, 6, 4); const uint32_t uVtxStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, tP0, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); // top left - pl__add_vertex(ptLayer, tP1, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); // bot left - pl__add_vertex(ptLayer, tP2, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); // bot right - pl__add_vertex(ptLayer, tP3, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); // top right + pl__add_vertex(ptLayer, tP0, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); // top left + pl__add_vertex(ptLayer, tP1, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); // bot left + pl__add_vertex(ptLayer, tP2, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); // bot right + pl__add_vertex(ptLayer, tP3, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); // top right pl__add_index(ptLayer, uVtxStart, 0, 1, 2); pl__add_index(ptLayer, uVtxStart, 0, 2, 3); } static void -pl_add_circle(plDrawLayer2D* ptLayer, plVec2 tP, float fRadius, plVec4 tColor, uint32_t uSegments, float fThickness) +pl_add_circle(plDrawLayer2D* ptLayer, plVec2 tP, float fRadius, uint32_t uSegments, plDrawLineOptions tOptions) { if(uSegments == 0){ uSegments = 12; } const float fIncrement = PL_2PI / uSegments; @@ -1062,24 +1171,24 @@ pl_add_circle(plDrawLayer2D* ptLayer, plVec2 tP, float fRadius, plVec4 tColor, u fTheta += fIncrement; } pl_sb_push(ptLayer->sbtPath, ((plVec2){tP.x + fRadius, tP.y})); - pl__submit_path(ptLayer, tColor, fThickness); + pl__submit_path(ptLayer, tOptions); } static void -pl_add_circle_filled(plDrawLayer2D* ptLayer, plVec2 tP, float fRadius, plVec4 tColor, uint32_t uSegments) +pl_add_circle_filled(plDrawLayer2D* ptLayer, plVec2 tP, float fRadius, uint32_t uSegments, plDrawSolidOptions tOptions) { if(uSegments == 0){ uSegments = 12; } pl__prepare_draw_command(ptLayer, gptDrawCtx->ptAtlas->tTexture, false); pl__reserve_triangles(ptLayer, 3 * uSegments, uSegments + 1); const uint32_t uVertexStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, tP, tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); + pl__add_vertex(ptLayer, tP, tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); const float fIncrement = PL_2PI / uSegments; float fTheta = 0.0f; for(uint32_t i = 0; i < uSegments; i++) { - pl__add_vertex(ptLayer, ((plVec2){tP.x + (fRadius * sinf(fTheta + PL_PI_2)), tP.y + (fRadius * sinf(fTheta))}), tColor, (plVec2){gptDrawCtx->ptAtlas->afWhiteUv[0], gptDrawCtx->ptAtlas->afWhiteUv[1]}); + pl__add_vertex(ptLayer, ((plVec2){tP.x + (fRadius * sinf(fTheta + PL_PI_2)), tP.y + (fRadius * sinf(fTheta))}), tOptions.uColor, gptDrawCtx->ptAtlas->_tWhiteUv); fTheta += fIncrement; } @@ -1089,7 +1198,7 @@ pl_add_circle_filled(plDrawLayer2D* ptLayer, plVec2 tP, float fRadius, plVec4 tC } static void -pl_add_image_ex(plDrawLayer2D* ptLayer, plTextureID tTexture, plVec2 tPMin, plVec2 tPMax, plVec2 tUvMin, plVec2 tUvMax, plVec4 tColor) +pl_add_image_ex(plDrawLayer2D* ptLayer, plTextureID tTexture, plVec2 tPMin, plVec2 tPMax, plVec2 tUvMin, plVec2 tUvMax, uint32_t uColor) { pl__prepare_draw_command(ptLayer, tTexture, false); pl__reserve_triangles(ptLayer, 6, 4); @@ -1098,10 +1207,10 @@ pl_add_image_ex(plDrawLayer2D* ptLayer, plTextureID tTexture, plVec2 tPMin, plVe const plVec2 topRight = { tPMax.x, tPMin.y }; const uint32_t vertexStart = pl_sb_size(ptLayer->ptDrawlist->sbtVertexBuffer); - pl__add_vertex(ptLayer, tPMin, tColor, tUvMin); - pl__add_vertex(ptLayer, bottomLeft, tColor, (plVec2){tUvMin.x, tUvMax.y}); - pl__add_vertex(ptLayer, tPMax, tColor, tUvMax); - pl__add_vertex(ptLayer, topRight, tColor, (plVec2){tUvMax.x, tUvMin.y}); + pl__add_vertex(ptLayer, tPMin, uColor, tUvMin); + pl__add_vertex(ptLayer, bottomLeft, uColor, (plVec2){tUvMin.x, tUvMax.y}); + pl__add_vertex(ptLayer, tPMax, uColor, tUvMax); + pl__add_vertex(ptLayer, topRight, uColor, (plVec2){tUvMax.x, tUvMin.y}); pl__add_index(ptLayer, vertexStart, 0, 1, 2); pl__add_index(ptLayer, vertexStart, 0, 2, 3); @@ -1110,11 +1219,11 @@ pl_add_image_ex(plDrawLayer2D* ptLayer, plTextureID tTexture, plVec2 tPMin, plVe static void pl_add_image(plDrawLayer2D* ptLayer, plTextureID tTexture, plVec2 tPMin, plVec2 tPMax) { - pl_add_image_ex(ptLayer, tTexture, tPMin, tPMax, (plVec2){0}, (plVec2){1.0f, 1.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + pl_add_image_ex(ptLayer, tTexture, tPMin, tPMax, (plVec2){0}, (plVec2){1.0f, 1.0f}, PL_COLOR_32_WHITE); } static void -pl_add_bezier_quad(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec4 tColor, float fThickness, uint32_t uSegments) +pl_add_bezier_quad(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, uint32_t uSegments, plDrawLineOptions tOptions) { // order of the bezier curve inputs are 0=start, 1=control, 2=ending @@ -1144,11 +1253,11 @@ pl_add_bezier_quad(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, p // push last point pl_sb_push(ptLayer->sbtPath, tP2); - pl__submit_path(ptLayer, tColor, fThickness); + pl__submit_path(ptLayer, tOptions); } static void -pl_add_bezier_cubic(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plVec4 tColor, float fThickness, uint32_t uSegments) +pl_add_bezier_cubic(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, uint32_t uSegments, plDrawLineOptions tOptions) { // order of the bezier curve inputs are 0=start, 1=control 1, 2=control 2, 3=ending @@ -1183,7 +1292,7 @@ pl_add_bezier_cubic(plDrawLayer2D* ptLayer, plVec2 tP0, plVec2 tP1, plVec2 tP2, // push last point pl_sb_push(ptLayer->sbtPath, tP3); - pl__submit_path(ptLayer, tColor, fThickness); + pl__submit_path(ptLayer, tOptions); } static char* @@ -1227,20 +1336,19 @@ plu__read_file(const char* file) static plFont* pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* data) { - ptAtlas->bDirty = true; - ptAtlas->iGlyphPadding = 1; + ptAtlas->_iGlyphPadding = 1; plFont* ptFont = NULL; - if(config.bMergeFont) + if(config.ptMergeFont) { - ptFont = config.tMergeFont; + ptFont = config.ptMergeFont; } else { ptFont = PL_ALLOC(sizeof(plFont)); memset(ptFont, 0, sizeof(plFont)); - ptFont->fLineSpacing = 0.0f; - ptFont->fSize = config.fFontSize; + ptFont->_fLineSpacing = 0.0f; + ptFont->fSize = config.fSize; ptFont->_ptNextFont = ptAtlas->_ptFontListHead; ptAtlas->_ptFontListHead = ptFont; } @@ -1270,7 +1378,7 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat // calculate base line spacing ptPrep->fAscent = ceilf(ascent * ptPrep->scale); ptPrep->fDescent = floorf(descent * ptPrep->scale); - ptFont->fLineSpacing = pl_max(ptFont->fLineSpacing, (ptPrep->fAscent - ptPrep->fDescent + ptPrep->scale * (float)lineGap)); + ptFont->_fLineSpacing = pl_max(ptFont->_fLineSpacing, (ptPrep->fAscent - ptPrep->fDescent + ptPrep->scale * (float)lineGap)); // convert individual chars to ranges for(uint32_t i = 0; i < config.uRangeCount; i++) @@ -1290,7 +1398,7 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat } // find total number of glyphs/chars required - // const uint32_t uGlyphOffset = pl_sb_size(ptFont->sbtGlyphs); + // const uint32_t uGlyphOffset = pl_sb_size(ptFont->_sbtGlyphs); uint32_t totalCharCount = 0u; for(uint32_t i = 0; i < pl_sb_size(config._sbtRanges); i++) { @@ -1298,12 +1406,12 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat totalCharCount += config._sbtRanges[i]._uConfigIndex = uConfigIndex; } - pl_sb_reserve(ptFont->sbtGlyphs, pl_sb_size(ptFont->sbtGlyphs) + totalCharCount); + pl_sb_reserve(ptFont->_sbtGlyphs, pl_sb_size(ptFont->_sbtGlyphs) + totalCharCount); pl_sb_resize(config._sbtCharData, totalCharCount); if(config.bSdf) { - pl_sb_reserve(ptAtlas->sbtCustomRects, pl_sb_size(ptAtlas->sbtCustomRects) + totalCharCount); // is this correct + pl_sb_reserve(ptAtlas->_sbtCustomRects, pl_sb_size(ptAtlas->_sbtCustomRects) + totalCharCount); // is this correct } ptPrep->ranges = PL_ALLOC(sizeof(stbtt_pack_range) * pl_sb_size(config._sbtRanges)); @@ -1320,7 +1428,7 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat plFontRange* range = &config._sbtRanges[i]; range->_uConfigIndex = uConfigIndex; ptPrep->uTotalCharCount += range->uCharCount; - pl_sb_push(ptFont->sbtRanges, *range); + pl_sb_push(ptFont->_sbtRanges, *range); } if(!config.bSdf) @@ -1336,7 +1444,7 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat maxCodePoint = range->iFirstCodePoint + (int)range->uCharCount; // prepare stb stuff - ptPrep->ranges[i].font_size = config.fFontSize; + ptPrep->ranges[i].font_size = config.fSize; ptPrep->ranges[i].first_unicode_codepoint_in_range = range->iFirstCodePoint; ptPrep->ranges[i].chardata_for_range = (stbtt_packedchar*)&config._sbtCharData[totalCharCount]; ptPrep->ranges[i].num_chars = range->uCharCount; @@ -1360,7 +1468,7 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat int xOff = 0u; int yOff = 0u; unsigned char* bytes = stbtt_GetCodepointSDF(&ptPrep->fontInfo, - stbtt_ScaleForPixelHeight(&ptPrep->fontInfo, config.fFontSize), + stbtt_ScaleForPixelHeight(&ptPrep->fontInfo, config.fSize), codePoint, config.iSdfPadding, config.ucOnEdgeValue, @@ -1381,8 +1489,8 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat .uHeight = (uint32_t)height, .pucBytes = bytes }; - pl_sb_push(ptAtlas->sbtCustomRects, customRect); - ptAtlas->fTotalArea += width * height; + pl_sb_push(ptAtlas->_sbtCustomRects, customRect); + ptAtlas->_fTotalArea += width * height; } k += ptPrep->ranges[i].num_chars; @@ -1409,9 +1517,9 @@ pl_add_font_from_memory_ttf(plFontAtlas* ptAtlas, plFontConfig config, void* dat ptPrep->scale * config.uHOverSampling, ptPrep->scale * config.uVOverSampling, 0, 0, &x0, &y0, &x1, &y1); - ptPrep->rects[k].w = (stbrp_coord)(x1 - x0 + ptAtlas->iGlyphPadding + config.uHOverSampling - 1); - ptPrep->rects[k].h = (stbrp_coord)(y1 - y0 + ptAtlas->iGlyphPadding + config.uVOverSampling - 1); - ptAtlas->fTotalArea += ptPrep->rects[k].w * ptPrep->rects[k].h; + ptPrep->rects[k].w = (stbrp_coord)(x1 - x0 + ptAtlas->_iGlyphPadding + config.uHOverSampling - 1); + ptPrep->rects[k].h = (stbrp_coord)(y1 - y0 + ptAtlas->_iGlyphPadding + config.uVOverSampling - 1); + ptAtlas->_fTotalArea += ptPrep->rects[k].w * ptPrep->rects[k].h; if (glyphIndex == 0) missingGlyphAdded = true; } k++; @@ -1444,14 +1552,26 @@ pl_add_font_from_file_ttf(plFontAtlas* ptAtlas, plFontConfig config, const char* } static plVec2 -pl_calculate_text_size_ex(plFont* font, float size, const char* text, const char* pcTextEnd, float wrap) +pl_calculate_text_size(const char* text, plDrawTextOptions tOptions) { + + if(tOptions.pcTextEnd == NULL) + { + tOptions.pcTextEnd = text; + while(*tOptions.pcTextEnd != '\0') + tOptions.pcTextEnd++; + } + plVec2 result = {0}; plVec2 cursor = {0}; + plFont* font = tOptions.ptFont; + float size = tOptions.fSize == 0.0f ? font->fSize : tOptions.fSize; + const char* pcTextEnd = tOptions.pcTextEnd; + float scale = size > 0.0f ? size / font->fSize : 1.0f; - float fLineSpacing = scale * font->fLineSpacing; + float fLineSpacing = scale * font->_fLineSpacing; plVec2 originalPosition = {FLT_MAX, FLT_MAX}; bool firstCharacter = true; @@ -1480,9 +1600,10 @@ pl_calculate_text_size_ex(plFont* font, float size, const char* text, const char { bool glyphFound = false; - for(uint32_t i = 0u; i < pl_sb_size(font->sbtRanges); i++) + const uint32_t uRangeCount = pl_sb_size(font->_sbtRanges); + for(uint32_t i = 0; i < uRangeCount; i++) { - plFontRange* ptRange = &font->sbtRanges[i]; + plFontRange* ptRange = &font->_sbtRanges[i]; if (c >= (uint32_t)ptRange->iFirstCodePoint && c < (uint32_t)ptRange->iFirstCodePoint + (uint32_t)ptRange->uCharCount) { @@ -1490,7 +1611,7 @@ pl_calculate_text_size_ex(plFont* font, float size, const char* text, const char float x0,y0,s0,t0; // top-left float x1,y1,s1,t1; // bottom-right - const plFontGlyph* glyph = &font->sbtGlyphs[font->_auCodePoints[c]]; + const plFontGlyph* glyph = &font->_sbtGlyphs[font->_auCodePoints[c]]; // adjust for left side bearing if first char if(firstCharacter) @@ -1506,7 +1627,7 @@ pl_calculate_text_size_ex(plFont* font, float size, const char* text, const char y0 = cursor.y + glyph->y0 * scale; y1 = cursor.y + glyph->y1 * scale; - if(wrap > 0.0f && x1 > originalPosition.x + wrap) + if(tOptions.fWrap > 0.0f && x1 > originalPosition.x + tOptions.fWrap) { x0 = originalPosition.x + glyph->x0 * scale; y0 = y0 + fLineSpacing; @@ -1541,22 +1662,26 @@ pl_calculate_text_size_ex(plFont* font, float size, const char* text, const char return pl_sub_vec2(result, originalPosition); } -static plVec2 -pl_calculate_text_size(plFont* font, float size, const char* text, float wrap) -{ - const char* pcTextEnd = text + strlen(text); - return pl_calculate_text_size_ex(font, size, text, pcTextEnd, wrap); -} - static plRect -pl_calculate_text_bb_ex(plFont* font, float size, plVec2 tP, const char* text, const char* pcTextEnd, float wrap) +pl_calculate_text_bb(plVec2 tP, const char* text, plDrawTextOptions tOptions) { + if(tOptions.pcTextEnd == NULL) + { + tOptions.pcTextEnd = text; + while(*tOptions.pcTextEnd != '\0') + tOptions.pcTextEnd++; + } + plVec2 tTextSize = {0}; plVec2 cursor = {0}; + plFont* font = tOptions.ptFont; + float size = tOptions.fSize == 0.0f ? font->fSize : tOptions.fSize; + const char* pcTextEnd = tOptions.pcTextEnd; + float scale = size > 0.0f ? size / font->fSize : 1.0f; - float fLineSpacing = scale * font->fLineSpacing; + float fLineSpacing = scale * font->_fLineSpacing; plVec2 originalPosition = {FLT_MAX, FLT_MAX}; bool firstCharacter = true; @@ -1585,16 +1710,17 @@ pl_calculate_text_bb_ex(plFont* font, float size, plVec2 tP, const char* text, c { bool glyphFound = false; - for(uint32_t i = 0u; i < pl_sb_size(font->sbtRanges); i++) + const uint32_t uRangeCount = pl_sb_size(font->_sbtRanges); + for(uint32_t i = 0u; i < uRangeCount; i++) { - plFontRange* ptRange = &font->sbtRanges[i]; + plFontRange* ptRange = &font->_sbtRanges[i]; if (c >= (uint32_t)ptRange->iFirstCodePoint && c < (uint32_t)ptRange->iFirstCodePoint + (uint32_t)ptRange->uCharCount) { float x0,y0,s0,t0; // top-left float x1,y1,s1,t1; // bottom-right - const plFontGlyph* glyph = &font->sbtGlyphs[font->_auCodePoints[c]]; + const plFontGlyph* glyph = &font->_sbtGlyphs[font->_auCodePoints[c]]; // adjust for left side bearing if first char if(firstCharacter) @@ -1610,7 +1736,7 @@ pl_calculate_text_bb_ex(plFont* font, float size, plVec2 tP, const char* text, c y0 = cursor.y + glyph->y0 * scale; y1 = cursor.y + glyph->y1 * scale; - if(wrap > 0.0f && x1 > originalPosition.x + wrap) + if(tOptions.fWrap > 0.0f && x1 > originalPosition.x + tOptions.fWrap) { x0 = originalPosition.x + glyph->x0 * scale; y0 = y0 + fLineSpacing; @@ -1653,38 +1779,34 @@ pl_calculate_text_bb_ex(plFont* font, float size, plVec2 tP, const char* text, c return tResult; } -static plRect -pl_calculate_text_bb(plFont* ptFont, float fSize, plVec2 tP, const char* pcText, float fWrap) -{ - const char* pcTextEnd = pcText + strlen(pcText); - return pl_calculate_text_bb_ex(ptFont, fSize, tP, pcText, pcTextEnd, fWrap); -} - static void -pl_push_clip_rect_pt(plDrawList2D* ptDrawlist, const plRect* ptRect) +pl_push_clip_rect_pt(plDrawList2D* ptDrawlist, const plRect* ptRect, bool bAccumulate) { - pl_sb_push(ptDrawlist->sbtClipStack, *ptRect); + plRect tRect = *ptRect; + if(bAccumulate && pl_sb_size(ptDrawlist->_sbtClipStack) > 0) + tRect = pl_rect_clip_full(&tRect, &pl_sb_back(ptDrawlist->_sbtClipStack)); + pl_sb_push(ptDrawlist->_sbtClipStack, tRect); } static void pl_push_clip_rect(plDrawList2D* ptDrawlist, plRect tRect, bool bAccumulate) { - if(bAccumulate && pl_sb_size(ptDrawlist->sbtClipStack) > 0) - tRect = pl_rect_clip_full(&tRect, &pl_sb_back(ptDrawlist->sbtClipStack)); - pl_sb_push(ptDrawlist->sbtClipStack, tRect); + if(bAccumulate && pl_sb_size(ptDrawlist->_sbtClipStack) > 0) + tRect = pl_rect_clip_full(&tRect, &pl_sb_back(ptDrawlist->_sbtClipStack)); + pl_sb_push(ptDrawlist->_sbtClipStack, tRect); } static void pl_pop_clip_rect(plDrawList2D* ptDrawlist) { - pl_sb_pop(ptDrawlist->sbtClipStack); + pl_sb_pop(ptDrawlist->_sbtClipStack); } static const plRect* pl_get_clip_rect(plDrawList2D* ptDrawlist) { - if(pl_sb_size(ptDrawlist->sbtClipStack) > 0) - return &pl_sb_back(ptDrawlist->sbtClipStack); + if(pl_sb_size(ptDrawlist->_sbtClipStack) > 0) + return &pl_sb_back(ptDrawlist->_sbtClipStack); return NULL; } @@ -1714,48 +1836,48 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) { // create our white location - plFontCustomRect ptWhiteRect = { + plFontCustomRect _ptWhiteRect = { .uWidth = 8u, .uHeight = 8u, .uX = 0u, .uY = 0u, .pucBytes = malloc(64) }; - memset(ptWhiteRect.pucBytes, 255, 64); - pl_sb_push(ptAtlas->sbtCustomRects, ptWhiteRect); - ptAtlas->ptWhiteRect = &pl_sb_back(ptAtlas->sbtCustomRects); - ptAtlas->fTotalArea += 64; + memset(_ptWhiteRect.pucBytes, 255, 64); + pl_sb_push(ptAtlas->_sbtCustomRects, _ptWhiteRect); + ptAtlas->_ptWhiteRect = &pl_sb_back(ptAtlas->_sbtCustomRects); + ptAtlas->_fTotalArea += 64; // calculate final texture area required - const float totalAtlasAreaSqrt = (float)sqrt((float)ptAtlas->fTotalArea) + 1.0f; - ptAtlas->auAtlasSize[0] = 512; - ptAtlas->auAtlasSize[1] = 0; - if (totalAtlasAreaSqrt >= 4096 * 0.7f) ptAtlas->auAtlasSize[0] = 4096; - else if(totalAtlasAreaSqrt >= 2048 * 0.7f) ptAtlas->auAtlasSize[0] = 2048; - else if(totalAtlasAreaSqrt >= 1024 * 0.7f) ptAtlas->auAtlasSize[0] = 1024; + const float totalAtlasAreaSqrt = (float)sqrt((float)ptAtlas->_fTotalArea) + 1.0f; + ptAtlas->tAtlasSize.x = 512; + ptAtlas->tAtlasSize.y = 0; + if (totalAtlasAreaSqrt >= 4096 * 0.7f) ptAtlas->tAtlasSize.x = 4096; + else if(totalAtlasAreaSqrt >= 2048 * 0.7f) ptAtlas->tAtlasSize.x = 2048; + else if(totalAtlasAreaSqrt >= 1024 * 0.7f) ptAtlas->tAtlasSize.x = 1024; // begin packing stbtt_pack_context spc = {0}; - stbtt_PackBegin(&spc, NULL, ptAtlas->auAtlasSize[0], 1024 * 32, 0, ptAtlas->iGlyphPadding, NULL); + stbtt_PackBegin(&spc, NULL, (uint32_t)ptAtlas->tAtlasSize.x, 1024 * 32, 0, ptAtlas->_iGlyphPadding, NULL); // allocate SDF rects - stbrp_rect* rects = PL_ALLOC(pl_sb_size(ptAtlas->sbtCustomRects) * sizeof(stbrp_rect)); - memset(rects, 0, sizeof(stbrp_rect) * pl_sb_size(ptAtlas->sbtCustomRects)); + stbrp_rect* rects = PL_ALLOC(pl_sb_size(ptAtlas->_sbtCustomRects) * sizeof(stbrp_rect)); + memset(rects, 0, sizeof(stbrp_rect) * pl_sb_size(ptAtlas->_sbtCustomRects)); // transfer our data to stb data - for(uint32_t i = 0u; i < pl_sb_size(ptAtlas->sbtCustomRects); i++) + for(uint32_t i = 0u; i < pl_sb_size(ptAtlas->_sbtCustomRects); i++) { - rects[i].w = (int)ptAtlas->sbtCustomRects[i].uWidth; - rects[i].h = (int)ptAtlas->sbtCustomRects[i].uHeight; + rects[i].w = (int)ptAtlas->_sbtCustomRects[i].uWidth; + rects[i].h = (int)ptAtlas->_sbtCustomRects[i].uHeight; } // pack bitmap fonts plFont* font = ptAtlas->_ptFontListHead; while(font) { - for(uint32_t j = 0; j < pl_sb_size(font->sbtRanges); j++) + for(uint32_t j = 0; j < pl_sb_size(font->_sbtRanges); j++) { - plFontRange* ptRange = &font->sbtRanges[j]; + plFontRange* ptRange = &font->_sbtRanges[j]; if(!font->_sbtConfigs[ptRange->_uConfigIndex].bSdf) { plFontPrepData* prep = &font->_sbtPreps[ptRange->_uConfigIndex]; @@ -1766,7 +1888,7 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) for(uint32_t k = 0u; k < prep->uTotalCharCount; k++) { if(prep->rects[k].was_packed) - ptAtlas->auAtlasSize[1] = (uint32_t)pl__get_max((float)ptAtlas->auAtlasSize[1], (float)(prep->rects[k].y + prep->rects[k].h)); + ptAtlas->tAtlasSize.y = pl__get_max((float)ptAtlas->tAtlasSize.y, (float)(prep->rects[k].y + prep->rects[k].h)); } prep->bPrepped = true; } @@ -1777,28 +1899,28 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) // pack SDF fonts stbtt_PackSetOversampling(&spc, 1, 1); - stbrp_pack_rects((stbrp_context*)spc.pack_info, rects, pl_sb_size(ptAtlas->sbtCustomRects)); + stbrp_pack_rects((stbrp_context*)spc.pack_info, rects, pl_sb_size(ptAtlas->_sbtCustomRects)); - for(uint32_t i = 0u; i < pl_sb_size(ptAtlas->sbtCustomRects); i++) + for(uint32_t i = 0u; i < pl_sb_size(ptAtlas->_sbtCustomRects); i++) { if(rects[i].was_packed) - ptAtlas->auAtlasSize[1] = (uint32_t)pl__get_max((float)ptAtlas->auAtlasSize[1], (float)(rects[i].y + rects[i].h)); + ptAtlas->tAtlasSize.y = pl__get_max((float)ptAtlas->tAtlasSize.y, (float)(rects[i].y + rects[i].h)); } // grow cpu side buffers if needed - if(ptAtlas->szPixelDataSize < ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1]) + if(ptAtlas->_szPixelDataSize < ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y) { - if(ptAtlas->pucPixelsAsAlpha8) PL_FREE(ptAtlas->pucPixelsAsAlpha8); + if(ptAtlas->_pucPixelsAsAlpha8) PL_FREE(ptAtlas->_pucPixelsAsAlpha8); if(ptAtlas->pucPixelsAsRGBA32) PL_FREE(ptAtlas->pucPixelsAsRGBA32); - ptAtlas->pucPixelsAsAlpha8 = PL_ALLOC(ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1]); - ptAtlas->pucPixelsAsRGBA32 = PL_ALLOC(ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1] * 4); + ptAtlas->_pucPixelsAsAlpha8 = PL_ALLOC((uint32_t)(ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y)); + ptAtlas->pucPixelsAsRGBA32 = PL_ALLOC((uint32_t)(ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y * 4)); - memset(ptAtlas->pucPixelsAsAlpha8, 0, ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1]); - memset(ptAtlas->pucPixelsAsRGBA32, 0, ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1] * 4); + memset(ptAtlas->_pucPixelsAsAlpha8, 0, (uint32_t)(ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y)); + memset(ptAtlas->pucPixelsAsRGBA32, 0, (uint32_t)(ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y * 4)); } - spc.pixels = ptAtlas->pucPixelsAsAlpha8; - ptAtlas->szPixelDataSize = ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1]; + spc.pixels = ptAtlas->_pucPixelsAsAlpha8; + ptAtlas->_szPixelDataSize = (size_t)(ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y); // rasterize bitmap fonts font = ptAtlas->_ptFontListHead; @@ -1814,10 +1936,10 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) } // update SDF/custom data - for(uint32_t i = 0u; i < pl_sb_size(ptAtlas->sbtCustomRects); i++) + for(uint32_t i = 0u; i < pl_sb_size(ptAtlas->_sbtCustomRects); i++) { - ptAtlas->sbtCustomRects[i].uX = (uint32_t)rects[i].x; - ptAtlas->sbtCustomRects[i].uY = (uint32_t)rects[i].y; + ptAtlas->_sbtCustomRects[i].uX = (uint32_t)rects[i].x; + ptAtlas->_sbtCustomRects[i].uY = (uint32_t)rects[i].y; } font = ptAtlas->_ptFontListHead; @@ -1833,8 +1955,8 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) { ptConfig->_sbtCharData[i].x0 = (uint16_t)rects[charDataOffset + i].x; ptConfig->_sbtCharData[i].y0 = (uint16_t)rects[charDataOffset + i].y; - ptConfig->_sbtCharData[i].x1 = (uint16_t)(rects[charDataOffset + i].x + ptAtlas->sbtCustomRects[charDataOffset + i].uWidth); - ptConfig->_sbtCharData[i].y1 = (uint16_t)(rects[charDataOffset + i].y + ptAtlas->sbtCustomRects[charDataOffset + i].uHeight); + ptConfig->_sbtCharData[i].x1 = (uint16_t)(rects[charDataOffset + i].x + ptAtlas->_sbtCustomRects[charDataOffset + i].uWidth); + ptConfig->_sbtCharData[i].y1 = (uint16_t)(rects[charDataOffset + i].y + ptAtlas->_sbtCustomRects[charDataOffset + i].uHeight); } charDataOffset += pl_sb_size(ptConfig->_sbtCharData); } @@ -1846,21 +1968,21 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) stbtt_PackEnd(&spc); // rasterize SDF/custom rects - for(uint32_t r = 0u; r < pl_sb_size(ptAtlas->sbtCustomRects); r++) + for(uint32_t r = 0u; r < pl_sb_size(ptAtlas->_sbtCustomRects); r++) { - plFontCustomRect* customRect = &ptAtlas->sbtCustomRects[r]; + plFontCustomRect* customRect = &ptAtlas->_sbtCustomRects[r]; for(uint32_t i = 0u; i < customRect->uHeight; i++) { for(uint32_t j = 0u; j < customRect->uWidth; j++) - ptAtlas->pucPixelsAsAlpha8[(customRect->uY + i) * ptAtlas->auAtlasSize[0] + (customRect->uX + j)] = customRect->pucBytes[i * customRect->uWidth + j]; + ptAtlas->_pucPixelsAsAlpha8[(customRect->uY + i) * (uint32_t)ptAtlas->tAtlasSize.x + (customRect->uX + j)] = customRect->pucBytes[i * customRect->uWidth + j]; } stbtt_FreeSDF(customRect->pucBytes, NULL); customRect->pucBytes = NULL; } // update white point uvs - ptAtlas->afWhiteUv[0] = (float)(ptAtlas->ptWhiteRect->uX + ptAtlas->ptWhiteRect->uWidth / 2) / (float)ptAtlas->auAtlasSize[0]; - ptAtlas->afWhiteUv[1] = (float)(ptAtlas->ptWhiteRect->uY + ptAtlas->ptWhiteRect->uHeight / 2) / (float)ptAtlas->auAtlasSize[1]; + ptAtlas->_tWhiteUv.x = (float)(ptAtlas->_ptWhiteRect->uX + ptAtlas->_ptWhiteRect->uWidth / 2) / (float)ptAtlas->tAtlasSize.x; + ptAtlas->_tWhiteUv.y = (float)(ptAtlas->_ptWhiteRect->uY + ptAtlas->_ptWhiteRect->uHeight / 2) / (float)ptAtlas->tAtlasSize.y; // add glyphs font = ptAtlas->_ptFontListHead; @@ -1871,16 +1993,16 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) uint32_t charIndex = 0u; float pixelHeight = 0.0f; - for(uint32_t i = 0u; i < pl_sb_size(font->sbtRanges); i++) + for(uint32_t i = 0u; i < pl_sb_size(font->_sbtRanges); i++) { - plFontRange* range = &font->sbtRanges[i]; + plFontRange* range = &font->_sbtRanges[i]; if(uConfigIndex != range->_uConfigIndex) { charIndex = 0; uConfigIndex = range->_uConfigIndex; } if(font->_sbtConfigs[range->_uConfigIndex].bSdf) - pixelHeight = 0.5f * 1.0f / (float)ptAtlas->auAtlasSize[1]; // is this correct? + pixelHeight = 0.5f * 1.0f / (float)ptAtlas->tAtlasSize.y; // is this correct? else pixelHeight = 0.0f; for(uint32_t j = 0u; j < range->uCharCount; j++) @@ -1889,7 +2011,7 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) const int codePoint = range->iFirstCodePoint + j; stbtt_aligned_quad q; float unused_x = 0.0f, unused_y = 0.0f; - stbtt_GetPackedQuad((stbtt_packedchar*)font->_sbtConfigs[range->_uConfigIndex]._sbtCharData, ptAtlas->auAtlasSize[0], ptAtlas->auAtlasSize[1], charIndex, &unused_x, &unused_y, &q, 0); + stbtt_GetPackedQuad((stbtt_packedchar*)font->_sbtConfigs[range->_uConfigIndex]._sbtCharData, (int)ptAtlas->tAtlasSize.x, (int)ptAtlas->tAtlasSize.y, charIndex, &unused_x, &unused_y, &q, 0); int unusedAdvanced, leftSideBearing; stbtt_GetCodepointHMetrics(&font->_sbtPreps[range->_uConfigIndex].fontInfo, codePoint, &unusedAdvanced, &leftSideBearing); @@ -1906,8 +2028,8 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) .xAdvance = font->_sbtConfigs[range->_uConfigIndex]._sbtCharData[charIndex].xAdv, .leftBearing = (float)leftSideBearing * font->_sbtPreps[range->_uConfigIndex].scale }; - pl_sb_push(font->sbtGlyphs, glyph); - font->_auCodePoints[codePoint] = pl_sb_size(font->sbtGlyphs) - 1; + pl_sb_push(font->_sbtGlyphs, glyph); + font->_auCodePoints[codePoint] = pl_sb_size(font->_sbtGlyphs) - 1; charIndex++; } } @@ -1929,12 +2051,12 @@ pl_prepare_font_atlas(plFontAtlas* ptAtlas) } // convert to 4 color channels - for(uint32_t i = 0u; i < ptAtlas->auAtlasSize[0] * ptAtlas->auAtlasSize[1]; i++) + for(uint32_t i = 0u; i < ptAtlas->tAtlasSize.x * ptAtlas->tAtlasSize.y; i++) { ptAtlas->pucPixelsAsRGBA32[i * 4] = 255; ptAtlas->pucPixelsAsRGBA32[i * 4 + 1] = 255; ptAtlas->pucPixelsAsRGBA32[i * 4 + 2] = 255; - ptAtlas->pucPixelsAsRGBA32[i * 4 + 3] = ptAtlas->pucPixelsAsAlpha8[i]; + ptAtlas->pucPixelsAsRGBA32[i * 4 + 3] = ptAtlas->_pucPixelsAsAlpha8[i]; } PL_FREE(rects); @@ -1952,8 +2074,8 @@ pl_cleanup_font_atlas(plFontAtlas* ptAtlas) { PL_FREE(font->_auCodePoints); - pl_sb_free(font->sbtGlyphs); - pl_sb_free(font->sbtRanges); + pl_sb_free(font->_sbtGlyphs); + pl_sb_free(font->_sbtRanges); for(uint32_t j = 0; j < pl_sb_size(font->_sbtConfigs); j++) { pl_sb_free(font->_sbtConfigs[j]._sbtRanges); @@ -1964,12 +2086,12 @@ pl_cleanup_font_atlas(plFontAtlas* ptAtlas) PL_FREE(ptOldFont); } - for(uint32_t i = 0; i < pl_sb_size(ptAtlas->sbtCustomRects); i++) + for(uint32_t i = 0; i < pl_sb_size(ptAtlas->_sbtCustomRects); i++) { - PL_FREE(ptAtlas->sbtCustomRects[i].pucBytes); + PL_FREE(ptAtlas->_sbtCustomRects[i].pucBytes); } - pl_sb_free(ptAtlas->sbtCustomRects); - PL_FREE(ptAtlas->pucPixelsAsAlpha8); + pl_sb_free(ptAtlas->_sbtCustomRects); + PL_FREE(ptAtlas->_pucPixelsAsAlpha8); PL_FREE(ptAtlas->pucPixelsAsRGBA32); } @@ -1978,9 +2100,8 @@ pl__prepare_draw_command(plDrawLayer2D* ptLayer, plTextureID textureID, bool sdf { bool createNewCommand = true; - const plRect tCurrentClip = pl_sb_size(ptLayer->ptDrawlist->sbtClipStack) > 0 ? pl_sb_top(ptLayer->ptDrawlist->sbtClipStack) : (plRect){0}; + const plRect tCurrentClip = pl_sb_size(ptLayer->ptDrawlist->_sbtClipStack) > 0 ? pl_sb_top(ptLayer->ptDrawlist->_sbtClipStack) : (plRect){0}; - if(ptLayer->_ptLastCommand) { // check if last command has same texture @@ -2026,22 +2147,16 @@ pl__reserve_triangles(plDrawLayer2D* ptLayer, uint32_t indexCount, uint32_t uVer } static void -pl__add_vertex(plDrawLayer2D* ptLayer, plVec2 pos, plVec4 color, plVec2 uv) +pl__add_vertex(plDrawLayer2D* ptLayer, plVec2 pos, uint32_t uColor, plVec2 uv) { - uint32_t tcolor = 0; - tcolor = (uint32_t) (255.0f * color.r + 0.5f); - tcolor |= (uint32_t) (255.0f * color.g + 0.5f) << 8; - tcolor |= (uint32_t) (255.0f * color.b + 0.5f) << 16; - tcolor |= (uint32_t) (255.0f * color.a + 0.5f) << 24; - pl_sb_push(ptLayer->ptDrawlist->sbtVertexBuffer, ((plDrawVertex){ .afPos[0] = pos.x, .afPos[1] = pos.y, .afUv[0] = uv.u, .afUv[1] = uv.v, - .uColor = tcolor + .uColor = uColor }) ); } @@ -2078,20 +2193,21 @@ pl_new_draw_3d_frame(void) pl_sb_reset(ptDrawlist->sbtDrawCommands); pl_sb_reset(ptDrawlist->sbtVertexBuffer); - for(uint32_t j = 0; j < pl_sb_size(ptDrawlist->sbtLayersCreated); j++) + pl_sb_reset(ptDrawlist->sbuIndexBuffer); + for(uint32_t j = 0; j < pl_sb_size(ptDrawlist->_sbtLayersCreated); j++) { - pl_sb_reset(ptDrawlist->sbtLayersCreated[j]->sbtCommandBuffer); - pl_sb_reset(ptDrawlist->sbtLayersCreated[j]->sbuIndexBuffer); - pl_sb_reset(ptDrawlist->sbtLayersCreated[j]->sbtPath); - ptDrawlist->sbtLayersCreated[j]->uVertexCount = 0u; - ptDrawlist->sbtLayersCreated[j]->_ptLastCommand = NULL; + pl_sb_reset(ptDrawlist->_sbtLayersCreated[j]->sbtCommandBuffer); + pl_sb_reset(ptDrawlist->_sbtLayersCreated[j]->sbuIndexBuffer); + pl_sb_reset(ptDrawlist->_sbtLayersCreated[j]->sbtPath); + ptDrawlist->_sbtLayersCreated[j]->uVertexCount = 0u; + ptDrawlist->_sbtLayersCreated[j]->_ptLastCommand = NULL; } - pl_sb_reset(ptDrawlist->sbtSubmittedLayers); + pl_sb_reset(ptDrawlist->_sbtSubmittedLayers); } } static inline void -pl__add_3d_triangles(plDrawList3D* ptDrawlist, uint32_t uVertexCount, const plVec3* atPoints, uint32_t uTriangleCount, const uint32_t* auIndices, plVec4 tColor) +pl__add_3d_triangles(plDrawList3D* ptDrawlist, uint32_t uVertexCount, const plVec3* atPoints, uint32_t uTriangleCount, const uint32_t* auIndices, uint32_t uColor) { const uint32_t uVertexStart = pl_sb_size(ptDrawlist->sbtSolidVertexBuffer); @@ -2100,15 +2216,9 @@ pl__add_3d_triangles(plDrawList3D* ptDrawlist, uint32_t uVertexCount, const plVe pl_sb_resize(ptDrawlist->sbtSolidVertexBuffer, pl_sb_size(ptDrawlist->sbtSolidVertexBuffer) + uVertexCount); pl_sb_resize(ptDrawlist->sbtSolidIndexBuffer, pl_sb_size(ptDrawlist->sbtSolidIndexBuffer) + 3 * uTriangleCount); - uint32_t tU32Color = 0; - tU32Color = (uint32_t) (255.0f * tColor.r + 0.5f); - tU32Color |= (uint32_t) (255.0f * tColor.g + 0.5f) << 8; - tU32Color |= (uint32_t) (255.0f * tColor.b + 0.5f) << 16; - tU32Color |= (uint32_t) (255.0f * tColor.a + 0.5f) << 24; - for(uint32_t i = 0; i < uVertexCount; i++) { - ptDrawlist->sbtSolidVertexBuffer[uVertexStart + i] = ((plDrawVertex3DSolid){ {atPoints[i].x, atPoints[i].y, atPoints[i].z}, tU32Color}); + ptDrawlist->sbtSolidVertexBuffer[uVertexStart + i] = ((plDrawVertex3DSolid){ {atPoints[i].x, atPoints[i].y, atPoints[i].z}, uColor}); } for(uint32_t i = 0; i < uTriangleCount; i++) @@ -2120,7 +2230,7 @@ pl__add_3d_triangles(plDrawList3D* ptDrawlist, uint32_t uVertexCount, const plVe } static void -pl__add_3d_triangle_filled(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 tP2, plVec4 tColor) +pl__add_3d_triangle_filled(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 tP2, plDrawSolidOptions tOptions) { pl_sb_reserve(ptDrawlist->sbtSolidVertexBuffer, pl_sb_size(ptDrawlist->sbtSolidVertexBuffer) + 3); @@ -2128,15 +2238,9 @@ pl__add_3d_triangle_filled(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plV const uint32_t uVertexStart = pl_sb_size(ptDrawlist->sbtSolidVertexBuffer); - uint32_t tU32Color = 0; - tU32Color = (uint32_t) (255.0f * tColor.r + 0.5f); - tU32Color |= (uint32_t) (255.0f * tColor.g + 0.5f) << 8; - tU32Color |= (uint32_t) (255.0f * tColor.b + 0.5f) << 16; - tU32Color |= (uint32_t) (255.0f * tColor.a + 0.5f) << 24; - - pl_sb_push(ptDrawlist->sbtSolidVertexBuffer, ((plDrawVertex3DSolid){ {tP0.x, tP0.y, tP0.z}, tU32Color})); - pl_sb_push(ptDrawlist->sbtSolidVertexBuffer, ((plDrawVertex3DSolid){ {tP1.x, tP1.y, tP1.z}, tU32Color})); - pl_sb_push(ptDrawlist->sbtSolidVertexBuffer, ((plDrawVertex3DSolid){ {tP2.x, tP2.y, tP2.z}, tU32Color})); + pl_sb_push(ptDrawlist->sbtSolidVertexBuffer, ((plDrawVertex3DSolid){ {tP0.x, tP0.y, tP0.z}, tOptions.uColor})); + pl_sb_push(ptDrawlist->sbtSolidVertexBuffer, ((plDrawVertex3DSolid){ {tP1.x, tP1.y, tP1.z}, tOptions.uColor})); + pl_sb_push(ptDrawlist->sbtSolidVertexBuffer, ((plDrawVertex3DSolid){ {tP2.x, tP2.y, tP2.z}, tOptions.uColor})); pl_sb_push(ptDrawlist->sbtSolidIndexBuffer, uVertexStart + 0); pl_sb_push(ptDrawlist->sbtSolidIndexBuffer, uVertexStart + 1); @@ -2144,51 +2248,50 @@ pl__add_3d_triangle_filled(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plV } static void -pl__add_3d_sphere_filled_ex(plDrawList3D* ptDrawlist, const plDrawSphereDesc* ptDesc) +pl__add_3d_sphere_filled(plDrawList3D* ptDrawlist, plDrawSphereDesc tDesc, plDrawSolidOptions tOptions) { const uint32_t uVertexStart = pl_sb_size(ptDrawlist->sbtSolidVertexBuffer); const uint32_t uIndexStart = pl_sb_size(ptDrawlist->sbtSolidIndexBuffer); - pl_sb_resize(ptDrawlist->sbtSolidVertexBuffer, pl_sb_size(ptDrawlist->sbtSolidVertexBuffer) + (ptDesc->uLatBands + 1) * (ptDesc->uLongBands + 1)); - pl_sb_resize(ptDrawlist->sbtSolidIndexBuffer, pl_sb_size(ptDrawlist->sbtSolidIndexBuffer) + ptDesc->uLatBands * ptDesc->uLongBands * 6); + if(tDesc.uLatBands == 0) + tDesc.uLatBands = 16; + if(tDesc.uLongBands == 0) + tDesc.uLongBands = 16; - uint32_t tU32Color = 0; - tU32Color = (uint32_t) (255.0f * ptDesc->tColor.r + 0.5f); - tU32Color |= (uint32_t) (255.0f * ptDesc->tColor.g + 0.5f) << 8; - tU32Color |= (uint32_t) (255.0f * ptDesc->tColor.b + 0.5f) << 16; - tU32Color |= (uint32_t) (255.0f * ptDesc->tColor.a + 0.5f) << 24; + pl_sb_resize(ptDrawlist->sbtSolidVertexBuffer, pl_sb_size(ptDrawlist->sbtSolidVertexBuffer) + (tDesc.uLatBands + 1) * (tDesc.uLongBands + 1)); + pl_sb_resize(ptDrawlist->sbtSolidIndexBuffer, pl_sb_size(ptDrawlist->sbtSolidIndexBuffer) + tDesc.uLatBands * tDesc.uLongBands * 6); uint32_t uCurrentPoint = 0; - for(uint32_t uLatNumber = 0; uLatNumber <= ptDesc->uLatBands; uLatNumber++) + for(uint32_t uLatNumber = 0; uLatNumber <= tDesc.uLatBands; uLatNumber++) { - const float fTheta = (float)uLatNumber * PL_PI / (float)ptDesc->uLatBands; + const float fTheta = (float)uLatNumber * PL_PI / (float)tDesc.uLatBands; const float fSinTheta = sinf(fTheta); const float fCosTheta = cosf(fTheta); - for(uint32_t uLongNumber = 0; uLongNumber <= ptDesc->uLongBands; uLongNumber++) + for(uint32_t uLongNumber = 0; uLongNumber <= tDesc.uLongBands; uLongNumber++) { - const float fPhi = (float)uLongNumber * 2 * PL_PI / (float)ptDesc->uLongBands; + const float fPhi = (float)uLongNumber * 2 * PL_PI / (float)tDesc.uLongBands; const float fSinPhi = sinf(fPhi); const float fCosPhi = cosf(fPhi); ptDrawlist->sbtSolidVertexBuffer[uVertexStart + uCurrentPoint] = (plDrawVertex3DSolid){ { - fCosPhi * fSinTheta * ptDesc->fRadius + ptDesc->tCenter.x, - fCosTheta * ptDesc->fRadius + ptDesc->tCenter.y, - fSinPhi * fSinTheta * ptDesc->fRadius + ptDesc->tCenter.z}, - tU32Color}; + fCosPhi * fSinTheta * tDesc.fRadius + tDesc.tCenter.x, + fCosTheta * tDesc.fRadius + tDesc.tCenter.y, + fSinPhi * fSinTheta * tDesc.fRadius + tDesc.tCenter.z}, + tOptions.uColor}; uCurrentPoint++; } } uCurrentPoint = 0; - for(uint32_t uLatNumber = 0; uLatNumber < ptDesc->uLatBands; uLatNumber++) + for(uint32_t uLatNumber = 0; uLatNumber < tDesc.uLatBands; uLatNumber++) { - for(uint32_t uLongNumber = 0; uLongNumber < ptDesc->uLongBands; uLongNumber++) + for(uint32_t uLongNumber = 0; uLongNumber < tDesc.uLongBands; uLongNumber++) { - const uint32_t uFirst = (uLatNumber * (ptDesc->uLongBands + 1)) + uLongNumber; - const uint32_t uSecond = uFirst + ptDesc->uLongBands + 1; + const uint32_t uFirst = (uLatNumber * (tDesc.uLongBands + 1)) + uLongNumber; + const uint32_t uSecond = uFirst + tDesc.uLongBands + 1; ptDrawlist->sbtSolidIndexBuffer[uIndexStart + uCurrentPoint + 0] = uVertexStart + uFirst; ptDrawlist->sbtSolidIndexBuffer[uIndexStart + uCurrentPoint + 1] = uVertexStart + uSecond; @@ -2204,7 +2307,7 @@ pl__add_3d_sphere_filled_ex(plDrawList3D* ptDrawlist, const plDrawSphereDesc* pt } static void -pl__add_3d_circle_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRadius, plVec4 tColor, uint32_t uSegments) +pl__add_3d_circle_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRadius, uint32_t uSegments, plDrawSolidOptions tOptions) { if(uSegments == 0){ uSegments = 12; } const float fIncrement = PL_2PI / uSegments; @@ -2229,13 +2332,13 @@ pl__add_3d_circle_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRad auIndices[uSegments * 3 + 1] = 1; auIndices[uSegments * 3 + 2] = uSegments; - pl__add_3d_triangles(ptDrawlist, uSegments + 2, atPoints, uSegments + 1, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, uSegments + 2, atPoints, uSegments + 1, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_centered_box_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, float fDepth, plVec4 tColor) +pl__add_3d_centered_box_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, float fDepth, plDrawSolidOptions tOptions) { const plVec3 tWidthVec = {fWidth / 2.0f, 0.0f, 0.0f}; @@ -2268,13 +2371,13 @@ pl__add_3d_centered_box_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float f 5, 2, 6 }; - pl__add_3d_triangles(ptDrawlist, 8, atVerticies, 12, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, 8, atVerticies, 12, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_plane_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, plVec4 tColor) +pl__add_3d_plane_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, plDrawSolidOptions tOptions) { const plVec3 tWidthVec = {fWidth / 2.0f, 0.0f, 0.0f}; @@ -2292,12 +2395,12 @@ pl__add_3d_plane_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidt 0, 2, 3 }; - pl__add_3d_triangles(ptDrawlist, 4, atVerticies, 2, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, 4, atVerticies, 2, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_plane_xy_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, plVec4 tColor) +pl__add_3d_plane_xy_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, plDrawSolidOptions tOptions) { const plVec3 tWidthVec = {fWidth / 2.0f, 0.0f, 0.0f}; @@ -2315,12 +2418,12 @@ pl__add_3d_plane_xy_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidt 0, 2, 3 }; - pl__add_3d_triangles(ptDrawlist, 4, atVerticies, 2, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, 4, atVerticies, 2, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_plane_yz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, plVec4 tColor) +pl__add_3d_plane_yz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, plDrawSolidOptions tOptions) { const plVec3 tWidthVec = {fWidth / 2.0f, 0.0f, 0.0f}; @@ -2338,12 +2441,12 @@ pl__add_3d_plane_yz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidt 0, 2, 3 }; - pl__add_3d_triangles(ptDrawlist, 4, atVerticies, 2, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, 4, atVerticies, 2, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_band_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInnerRadius, float fOuterRadius, plVec4 tColor, uint32_t uSegments) +pl__add_3d_band_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInnerRadius, float fOuterRadius, uint32_t uSegments, plDrawSolidOptions tOptions) { if(uSegments == 0){ uSegments = 12; } const float fIncrement = PL_2PI / uSegments; @@ -2371,13 +2474,13 @@ pl__add_3d_band_xz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInner auIndices[(uSegments - 1) * 6 + 4] = uSegments; auIndices[(uSegments - 1) * 6 + 5] = 0; - pl__add_3d_triangles(ptDrawlist, uSegments * 2, atPoints, uSegments * 2, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, uSegments * 2, atPoints, uSegments * 2, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_band_xy_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInnerRadius, float fOuterRadius, plVec4 tColor, uint32_t uSegments) +pl__add_3d_band_xy_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInnerRadius, float fOuterRadius, uint32_t uSegments, plDrawSolidOptions tOptions) { if(uSegments == 0){ uSegments = 12; } const float fIncrement = PL_2PI / uSegments; @@ -2405,13 +2508,13 @@ pl__add_3d_band_xy_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInner auIndices[(uSegments - 1) * 6 + 4] = uSegments; auIndices[(uSegments - 1) * 6 + 5] = 0; - pl__add_3d_triangles(ptDrawlist, uSegments * 2, atPoints, uSegments * 2, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, uSegments * 2, atPoints, uSegments * 2, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_band_yz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInnerRadius, float fOuterRadius, plVec4 tColor, uint32_t uSegments) +pl__add_3d_band_yz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInnerRadius, float fOuterRadius, uint32_t uSegments, plDrawSolidOptions tOptions) { if(uSegments == 0){ uSegments = 12; } const float fIncrement = PL_2PI / uSegments; @@ -2439,106 +2542,112 @@ pl__add_3d_band_yz_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fInner auIndices[(uSegments - 1) * 6 + 4] = uSegments; auIndices[(uSegments - 1) * 6 + 5] = 0; - pl__add_3d_triangles(ptDrawlist, uSegments * 2, atPoints, uSegments * 2, auIndices, tColor); + pl__add_3d_triangles(ptDrawlist, uSegments * 2, atPoints, uSegments * 2, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_cylinder_filled_ex(plDrawList3D* ptDrawlist, const plDrawCylinderDesc* ptDesc) +pl__add_3d_cylinder_filled(plDrawList3D* ptDrawlist, plDrawCylinderDesc tDesc, plDrawSolidOptions tOptions) { - plVec3 tDirection = pl_sub_vec3(ptDesc->tTipPos, ptDesc->tBasePos); + if(tDesc.uSegments == 0) + tDesc.uSegments = 12; + + plVec3 tDirection = pl_sub_vec3(tDesc.tTipPos, tDesc.tBasePos); const float fDistance = pl_length_vec3(tDirection); tDirection = pl_norm_vec3(tDirection); const float fAngleBetweenVecs = acosf(pl_dot_vec3(tDirection, (plVec3){0.0f, 1.0f, 0.0f})); const plVec3 tRotAxis = pl_cross_vec3((plVec3){0.0f, 1.0f, 0.0f}, tDirection); const plMat4 tRot = pl_mat4_rotate_vec3(fAngleBetweenVecs, tRotAxis); - const uint32_t uPointCount = ptDesc->uSegments * 2 + 2; - const uint32_t uIndexCount = (ptDesc->uSegments * 2 * 3) + (2 * 3 * ptDesc->uSegments); + const uint32_t uPointCount = tDesc.uSegments * 2 + 2; + const uint32_t uIndexCount = (tDesc.uSegments * 2 * 3) + (2 * 3 * tDesc.uSegments); plVec3* atPoints = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(plVec3) * uPointCount); uint32_t* auIndices = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(uint32_t) * uIndexCount); - const float fIncrement = PL_2PI / ptDesc->uSegments; + const float fIncrement = PL_2PI / tDesc.uSegments; float fTheta = 0.0f; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { - atPoints[i] = (plVec3){ptDesc->fRadius * sinf(fTheta + PL_PI_2), 0.0f, ptDesc->fRadius * sinf(fTheta)}; - atPoints[i + ptDesc->uSegments] = (plVec3){atPoints[i].x, atPoints[i].y + fDistance, atPoints[i].z}; + atPoints[i] = (plVec3){tDesc.fRadius * sinf(fTheta + PL_PI_2), 0.0f, tDesc.fRadius * sinf(fTheta)}; + atPoints[i + tDesc.uSegments] = (plVec3){atPoints[i].x, atPoints[i].y + fDistance, atPoints[i].z}; atPoints[i] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i]}).xyz; - atPoints[i + ptDesc->uSegments] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i + ptDesc->uSegments]}).xyz; - atPoints[i] = pl_add_vec3(atPoints[i], ptDesc->tBasePos); - atPoints[i + ptDesc->uSegments] = pl_add_vec3(atPoints[i + ptDesc->uSegments], ptDesc->tBasePos); + atPoints[i + tDesc.uSegments] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i + tDesc.uSegments]}).xyz; + atPoints[i] = pl_add_vec3(atPoints[i], tDesc.tBasePos); + atPoints[i + tDesc.uSegments] = pl_add_vec3(atPoints[i + tDesc.uSegments], tDesc.tBasePos); fTheta += fIncrement; } - atPoints[uPointCount - 2] = ptDesc->tBasePos; - atPoints[uPointCount - 1] = ptDesc->tTipPos; + atPoints[uPointCount - 2] = tDesc.tBasePos; + atPoints[uPointCount - 1] = tDesc.tTipPos; uint32_t uCurrentIndex = 0; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { auIndices[i * 6] = i; - auIndices[i * 6 + 1] = i + ptDesc->uSegments; - auIndices[i * 6 + 2] = i + ptDesc->uSegments + 1; + auIndices[i * 6 + 1] = i + tDesc.uSegments; + auIndices[i * 6 + 2] = i + tDesc.uSegments + 1; auIndices[i * 6 + 3] = i; - auIndices[i * 6 + 4] = i + ptDesc->uSegments + 1; + auIndices[i * 6 + 4] = i + tDesc.uSegments + 1; auIndices[i * 6 + 5] = i + 1; uCurrentIndex += 6; } - auIndices[(ptDesc->uSegments - 1) * 6 + 2] = ptDesc->uSegments; - auIndices[(ptDesc->uSegments - 1) * 6 + 4] = ptDesc->uSegments; - auIndices[(ptDesc->uSegments - 1) * 6 + 5] = 0; + auIndices[(tDesc.uSegments - 1) * 6 + 2] = tDesc.uSegments; + auIndices[(tDesc.uSegments - 1) * 6 + 4] = tDesc.uSegments; + auIndices[(tDesc.uSegments - 1) * 6 + 5] = 0; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { auIndices[uCurrentIndex + i * 6] = uPointCount - 2; auIndices[uCurrentIndex + i * 6 + 1] = i + 1; auIndices[uCurrentIndex + i * 6 + 2] = i; auIndices[uCurrentIndex + i * 6 + 3] = uPointCount - 1; - auIndices[uCurrentIndex + i * 6 + 4] = i + 1 + ptDesc->uSegments; - auIndices[uCurrentIndex + i * 6 + 5] = i + ptDesc->uSegments; + auIndices[uCurrentIndex + i * 6 + 4] = i + 1 + tDesc.uSegments; + auIndices[uCurrentIndex + i * 6 + 5] = i + tDesc.uSegments; } - auIndices[uCurrentIndex + (ptDesc->uSegments - 1) * 6 + 1] = 0; - auIndices[uCurrentIndex + (ptDesc->uSegments - 1) * 6 + 4] = ptDesc->uSegments; + auIndices[uCurrentIndex + (tDesc.uSegments - 1) * 6 + 1] = 0; + auIndices[uCurrentIndex + (tDesc.uSegments - 1) * 6 + 4] = tDesc.uSegments; - pl__add_3d_triangles(ptDrawlist, uPointCount, atPoints, uIndexCount / 3, auIndices, ptDesc->tColor); + pl__add_3d_triangles(ptDrawlist, uPointCount, atPoints, uIndexCount / 3, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_cone_filled_ex(plDrawList3D* ptDrawlist, const plDrawConeDesc* ptDesc) +pl__add_3d_cone_filled(plDrawList3D* ptDrawlist, plDrawConeDesc tDesc, plDrawSolidOptions tOptions) { - plVec3 tDirection = pl_sub_vec3(ptDesc->tTipPos, ptDesc->tBasePos); + if(tDesc.uSegments == 0) + tDesc.uSegments = 12; + + plVec3 tDirection = pl_sub_vec3(tDesc.tTipPos, tDesc.tBasePos); const float fDistance = pl_length_vec3(tDirection); tDirection = pl_norm_vec3(tDirection); const float fAngleBetweenVecs = acosf(pl_dot_vec3(tDirection, (plVec3){0.0f, 1.0f, 0.0f})); const plVec3 tRotAxis = pl_cross_vec3((plVec3){0.0f, 1.0f, 0.0f}, tDirection); const plMat4 tRot = pl_mat4_rotate_vec3(fAngleBetweenVecs, tRotAxis); - const uint32_t uPointCount = ptDesc->uSegments + 2; - const uint32_t uIndexCount = ptDesc->uSegments * 2 * 3; + const uint32_t uPointCount = tDesc.uSegments + 2; + const uint32_t uIndexCount = tDesc.uSegments * 2 * 3; plVec3* atPoints = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(plVec3) * uPointCount); uint32_t* auIndices = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(uint32_t) * uIndexCount); - const float fIncrement = PL_2PI / ptDesc->uSegments; + const float fIncrement = PL_2PI / tDesc.uSegments; float fTheta = 0.0f; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { - atPoints[i] = (plVec3){ptDesc->fRadius * sinf(fTheta + PL_PI_2), 0.0f, ptDesc->fRadius * sinf(fTheta)}; + atPoints[i] = (plVec3){tDesc.fRadius * sinf(fTheta + PL_PI_2), 0.0f, tDesc.fRadius * sinf(fTheta)}; atPoints[i] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i]}).xyz; - atPoints[i] = pl_add_vec3(atPoints[i], ptDesc->tBasePos); + atPoints[i] = pl_add_vec3(atPoints[i], tDesc.tBasePos); fTheta += fIncrement; } - atPoints[uPointCount - 2] = ptDesc->tBasePos; - atPoints[uPointCount - 1] = ptDesc->tTipPos; + atPoints[uPointCount - 2] = tDesc.tBasePos; + atPoints[uPointCount - 1] = tDesc.tTipPos; uint32_t uCurrentIndex = 0; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { auIndices[i * 6] = i; auIndices[i * 6 + 1] = i + 1; @@ -2554,19 +2663,14 @@ pl__add_3d_cone_filled_ex(plDrawList3D* ptDrawlist, const plDrawConeDesc* ptDesc auIndices[uCurrentIndex + 1] = 0; auIndices[uCurrentIndex + 5] = 0; - pl__add_3d_triangles(ptDrawlist, uPointCount, atPoints, uIndexCount / 3, auIndices, ptDesc->tColor); + pl__add_3d_triangles(ptDrawlist, uPointCount, atPoints, uIndexCount / 3, auIndices, tOptions.uColor); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_line(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec4 tColor, float fThickness) +pl__add_3d_line(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plDrawLineOptions tOptions) { - uint32_t tU32Color = 0; - tU32Color = (uint32_t) (255.0f * tColor.r + 0.5f); - tU32Color |= (uint32_t) (255.0f * tColor.g + 0.5f) << 8; - tU32Color |= (uint32_t) (255.0f * tColor.b + 0.5f) << 16; - tU32Color |= (uint32_t) (255.0f * tColor.a + 0.5f) << 24; pl_sb_reserve(ptDrawlist->sbtLineVertexBuffer, pl_sb_size(ptDrawlist->sbtLineVertexBuffer) + 4); pl_sb_reserve(ptDrawlist->sbtLineIndexBuffer, pl_sb_size(ptDrawlist->sbtLineIndexBuffer) + 6); @@ -2574,19 +2678,19 @@ pl__add_3d_line(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec4 tColor, plDrawVertex3DLine tNewVertex0 = { {tP0.x, tP0.y, tP0.z}, -1.0f, - fThickness, + tOptions.fThickness, 1.0f, {tP1.x, tP1.y, tP1.z}, - tU32Color + tOptions.uColor }; plDrawVertex3DLine tNewVertex1 = { {tP1.x, tP1.y, tP1.z}, -1.0f, - fThickness, + tOptions.fThickness, -1.0f, {tP0.x, tP0.y, tP0.z}, - tU32Color + tOptions.uColor }; const uint32_t uVertexStart = pl_sb_size(ptDrawlist->sbtLineVertexBuffer); @@ -2609,14 +2713,14 @@ pl__add_3d_line(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec4 tColor, static void -pl__add_3d_text(plDrawList3D* ptDrawlist, plFont* ptFont, float fSize, plVec3 tP, plVec4 tColor, const char* pcText, float fWrap) +pl__add_3d_text(plDrawList3D* ptDrawlist, plVec3 tP, const char* pcText, plDrawTextOptions tOptions) { plDraw3DText tText = { - .fSize = fSize, - .fWrap = fWrap, - .tColor = tColor, - .tFontHandle = ptFont, - .tP = tP + .fSize = tOptions.fSize == 0.0f ? tOptions.ptFont->fSize : tOptions.fSize, + .fWrap = tOptions.fWrap, + .uColor = tOptions.uColor, + .ptFont = tOptions.ptFont, + .tP = tP }; strncpy(tText.acText, pcText, PL_MAX_NAME_LENGTH); pl_sb_push(ptDrawlist->sbtTextEntries, tText); @@ -2624,7 +2728,7 @@ pl__add_3d_text(plDrawList3D* ptDrawlist, plFont* ptFont, float fSize, plVec3 tP static void -pl__add_3d_cross(plDrawList3D* ptDrawlist, plVec3 tP, plVec4 tColor, float fLength, float fThickness) +pl__add_3d_cross(plDrawList3D* ptDrawlist, plVec3 tP, float fLength, plDrawLineOptions tOptions) { const plVec3 aatVerticies[6] = { { tP.x - fLength / 2.0f, tP.y, tP.z}, @@ -2634,11 +2738,11 @@ pl__add_3d_cross(plDrawList3D* ptDrawlist, plVec3 tP, plVec4 tColor, float fLeng { tP.x, tP.y, tP.z - fLength / 2.0f}, { tP.x, tP.y, tP.z + fLength / 2.0f} }; - pl__add_3d_lines(ptDrawlist, 3, aatVerticies, tColor, fThickness); + pl__add_3d_lines(ptDrawlist, 3, aatVerticies, tOptions); } static void -pl__add_3d_transform(plDrawList3D* ptDrawlist, const plMat4* ptTransform, float fLength, float fThickness) +pl__add_3d_transform(plDrawList3D* ptDrawlist, const plMat4* ptTransform, float fLength, plDrawLineOptions tOptions) { const plVec3 tOrigin = pl_mul_mat4_vec3(ptTransform, (plVec3){0.0f, 0.0f, 0.0f}); @@ -2646,28 +2750,31 @@ pl__add_3d_transform(plDrawList3D* ptDrawlist, const plMat4* ptTransform, float const plVec3 tYAxis = pl_mul_mat4_vec3(ptTransform, (plVec3){0.0f, fLength, 0.0f}); const plVec3 tZAxis = pl_mul_mat4_vec3(ptTransform, (plVec3){0.0f, 0.0f, fLength}); - pl__add_3d_line(ptDrawlist, tOrigin, tXAxis, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, fThickness); - pl__add_3d_line(ptDrawlist, tOrigin, tYAxis, (plVec4){0.0f, 1.0f, 0.0f, 1.0f}, fThickness); - pl__add_3d_line(ptDrawlist, tOrigin, tZAxis, (plVec4){0.0f, 0.0f, 1.0f, 1.0f}, fThickness); + tOptions.uColor = PL_COLOR_32_RGB(1.0f, 0.0f, 0.0f); + pl__add_3d_line(ptDrawlist, tOrigin, tXAxis, tOptions); + tOptions.uColor = PL_COLOR_32_RGB(0.0f, 1.0f, 0.0f); + pl__add_3d_line(ptDrawlist, tOrigin, tYAxis, tOptions); + tOptions.uColor = PL_COLOR_32_RGB(0.0f, 0.0f, 1.0f); + pl__add_3d_line(ptDrawlist, tOrigin, tZAxis, tOptions); } static void -pl__add_3d_frustum(plDrawList3D* ptDrawlist, const plMat4* ptTransform, float fYFov, float fAspect, float fNearZ, float fFarZ, plVec4 tColor, float fThickness) +pl__add_3d_frustum(plDrawList3D* ptDrawlist, const plMat4* ptTransform, plDrawFrustumDesc tDesc, plDrawLineOptions tOptions) { - const float fSmallHeight = tanf(fYFov / 2.0f) * fNearZ; - const float fSmallWidth = fSmallHeight * fAspect; - const float fBigHeight = tanf(fYFov / 2.0f) * fFarZ; - const float fBigWidth = fBigHeight * fAspect; + const float fSmallHeight = tanf(tDesc.fYFov / 2.0f) * tDesc.fNearZ; + const float fSmallWidth = fSmallHeight * tDesc.fAspectRatio; + const float fBigHeight = tanf(tDesc.fYFov / 2.0f) * tDesc.fFarZ; + const float fBigWidth = fBigHeight * tDesc.fAspectRatio; const plVec3 atVerticies[8] = { - pl_mul_mat4_vec3(ptTransform, (plVec3){ fSmallWidth, fSmallHeight, fNearZ}), - pl_mul_mat4_vec3(ptTransform, (plVec3){ fSmallWidth, -fSmallHeight, fNearZ}), - pl_mul_mat4_vec3(ptTransform, (plVec3){ -fSmallWidth, -fSmallHeight, fNearZ}), - pl_mul_mat4_vec3(ptTransform, (plVec3){ -fSmallWidth, fSmallHeight, fNearZ}), - pl_mul_mat4_vec3(ptTransform, (plVec3){ fBigWidth, fBigHeight, fFarZ}), - pl_mul_mat4_vec3(ptTransform, (plVec3){ fBigWidth, -fBigHeight, fFarZ}), - pl_mul_mat4_vec3(ptTransform, (plVec3){ -fBigWidth, -fBigHeight, fFarZ}), - pl_mul_mat4_vec3(ptTransform, (plVec3){ -fBigWidth, fBigHeight, fFarZ}) + pl_mul_mat4_vec3(ptTransform, (plVec3){ fSmallWidth, fSmallHeight, tDesc.fNearZ}), + pl_mul_mat4_vec3(ptTransform, (plVec3){ fSmallWidth, -fSmallHeight, tDesc.fNearZ}), + pl_mul_mat4_vec3(ptTransform, (plVec3){ -fSmallWidth, -fSmallHeight, tDesc.fNearZ}), + pl_mul_mat4_vec3(ptTransform, (plVec3){ -fSmallWidth, fSmallHeight, tDesc.fNearZ}), + pl_mul_mat4_vec3(ptTransform, (plVec3){ fBigWidth, fBigHeight, tDesc.fFarZ}), + pl_mul_mat4_vec3(ptTransform, (plVec3){ fBigWidth, -fBigHeight, tDesc.fFarZ}), + pl_mul_mat4_vec3(ptTransform, (plVec3){ -fBigWidth, -fBigHeight, tDesc.fFarZ}), + pl_mul_mat4_vec3(ptTransform, (plVec3){ -fBigWidth, fBigHeight, tDesc.fFarZ}) }; const uint32_t auIndices[] = { @@ -2684,41 +2791,45 @@ pl__add_3d_frustum(plDrawList3D* ptDrawlist, const plMat4* ptTransform, float fY 6, 7, 7, 4 }; - pl__add_3d_indexed_lines(ptDrawlist, 24, atVerticies, auIndices, tColor, fThickness); + pl__add_3d_indexed_lines(ptDrawlist, 24, atVerticies, auIndices, tOptions); } static void -pl__add_3d_sphere_ex(plDrawList3D* ptDrawlist, const plDrawSphereDesc* ptDesc) +pl__add_3d_sphere_ex(plDrawList3D* ptDrawlist, plDrawSphereDesc tDesc, plDrawLineOptions tOptions) { + if(tDesc.uLatBands == 0) + tDesc.uLatBands = 16; + if(tDesc.uLongBands == 0) + tDesc.uLongBands = 16; - plVec3* atPoints = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(plVec3) * (ptDesc->uLatBands + 1) * (ptDesc->uLongBands + 1)); - uint32_t* auIndices = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(uint32_t) * ptDesc->uLatBands * ptDesc->uLongBands * 8); + plVec3* atPoints = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(plVec3) * (tDesc.uLatBands + 1) * (tDesc.uLongBands + 1)); + uint32_t* auIndices = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(uint32_t) * tDesc.uLatBands * tDesc.uLongBands * 8); uint32_t uCurrentPoint = 0; - for(uint32_t uLatNumber = 0; uLatNumber <= ptDesc->uLatBands; uLatNumber++) + for(uint32_t uLatNumber = 0; uLatNumber <= tDesc.uLatBands; uLatNumber++) { - const float fTheta = (float)uLatNumber * PL_PI / (float)ptDesc->uLatBands; + const float fTheta = (float)uLatNumber * PL_PI / (float)tDesc.uLatBands; const float fSinTheta = sinf(fTheta); const float fCosTheta = cosf(fTheta); - for(uint32_t uLongNumber = 0; uLongNumber <= ptDesc->uLongBands; uLongNumber++) + for(uint32_t uLongNumber = 0; uLongNumber <= tDesc.uLongBands; uLongNumber++) { - const float fPhi = (float)uLongNumber * 2 * PL_PI / (float)ptDesc->uLongBands; + const float fPhi = (float)uLongNumber * 2 * PL_PI / (float)tDesc.uLongBands; const float fSinPhi = sinf(fPhi); const float fCosPhi = cosf(fPhi); - atPoints[uCurrentPoint] = (plVec3){fCosPhi * fSinTheta * ptDesc->fRadius + ptDesc->tCenter.x, fCosTheta * ptDesc->fRadius + ptDesc->tCenter.y, fSinPhi * fSinTheta * ptDesc->fRadius + ptDesc->tCenter.z}; + atPoints[uCurrentPoint] = (plVec3){fCosPhi * fSinTheta * tDesc.fRadius + tDesc.tCenter.x, fCosTheta * tDesc.fRadius + tDesc.tCenter.y, fSinPhi * fSinTheta * tDesc.fRadius + tDesc.tCenter.z}; uCurrentPoint++; } } uCurrentPoint = 0; - for(uint32_t uLatNumber = 0; uLatNumber < ptDesc->uLatBands; uLatNumber++) + for(uint32_t uLatNumber = 0; uLatNumber < tDesc.uLatBands; uLatNumber++) { - for(uint32_t uLongNumber = 0; uLongNumber < ptDesc->uLongBands; uLongNumber++) + for(uint32_t uLongNumber = 0; uLongNumber < tDesc.uLongBands; uLongNumber++) { - const uint32_t uFirst = (uLatNumber * (ptDesc->uLongBands + 1)) + uLongNumber; - const uint32_t uSecond = uFirst + ptDesc->uLongBands + 1; + const uint32_t uFirst = (uLatNumber * (tDesc.uLongBands + 1)) + uLongNumber; + const uint32_t uSecond = uFirst + tDesc.uLongBands + 1; auIndices[uCurrentPoint] = uFirst; auIndices[uCurrentPoint + 1] = uSecond; @@ -2734,18 +2845,21 @@ pl__add_3d_sphere_ex(plDrawList3D* ptDrawlist, const plDrawSphereDesc* ptDesc) uCurrentPoint += 8; } } - pl__add_3d_indexed_lines(ptDrawlist, ptDesc->uLatBands * ptDesc->uLongBands * 8, atPoints, auIndices, ptDesc->tColor, ptDesc->fThickness); + pl__add_3d_indexed_lines(ptDrawlist, tDesc.uLatBands * tDesc.uLongBands * 8, atPoints, auIndices, tOptions); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_capsule_ex(plDrawList3D* ptDrawlist, const plDrawCapsuleDesc* ptDesc) +pl__add_3d_capsule_ex(plDrawList3D* ptDrawlist, plDrawCapsuleDesc tDesc, plDrawLineOptions tOptions) { - plDrawCapsuleDesc tDesc = *ptDesc; + if(tDesc.uLatBands == 0) + tDesc.uLatBands = 16; + if(tDesc.uLongBands == 0) + tDesc.uLongBands = 16; - const float fTipRadius = ptDesc->fTipRadius < 0.0f ? ptDesc->fBaseRadius : ptDesc->fTipRadius; + const float fTipRadius = tDesc.fTipRadius < 0.0f ? tDesc.fBaseRadius : tDesc.fTipRadius; plVec3 tDirection = pl_sub_vec3(tDesc.tTipPos, tDesc.tBasePos); const float fDistance = pl_length_vec3(tDirection); @@ -2821,184 +2935,98 @@ pl__add_3d_capsule_ex(plDrawList3D* ptDrawlist, const plDrawCapsuleDesc* ptDesc) uCurrentPoint += 8; } } - pl__add_3d_indexed_lines(ptDrawlist, uIndexCount, atPoints, auIndices, tDesc.tColor, tDesc.fThickness); + pl__add_3d_indexed_lines(ptDrawlist, uIndexCount, atPoints, auIndices, tOptions); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__fill_capsule_desc_default(plDrawCapsuleDesc* ptDesc) -{ - if(ptDesc == NULL) - return; - - ptDesc->fThickness = 0.02f; - ptDesc->fBaseRadius = 0.5f; - ptDesc->fTipRadius = 0.5f; - ptDesc->fEndOffsetRatio = 0.0f; - ptDesc->uLatBands = 16; - ptDesc->uLongBands = 16; - ptDesc->tColor = (plVec4){1.0f, 1.0f, 1.0f, 1.0f}; - ptDesc->tBasePos = (plVec3){0}; - ptDesc->tTipPos = (plVec3){0.0f, 1.0f, 0.0f}; -} - -static void -pl__fill_sphere_desc_default(plDrawSphereDesc* ptDesc) +pl__add_3d_cylinder(plDrawList3D* ptDrawlist, plDrawCylinderDesc tDesc, plDrawLineOptions tOptions) { - if(ptDesc == NULL) - return; - - ptDesc->fThickness = 0.02f; - ptDesc->fRadius = 0.5f; - ptDesc->uLatBands = 16; - ptDesc->uLongBands = 16; - ptDesc->tColor = (plVec4){1.0f, 1.0f, 1.0f, 1.0f}; -} -static void -pl__fill_cylinder_desc_default(plDrawCylinderDesc* ptDesc) -{ - if(ptDesc == NULL) - return; - - ptDesc->fThickness = 0.02f; - ptDesc->fRadius = 0.5f; - ptDesc->uSegments = 12; - ptDesc->tColor = (plVec4){1.0f, 1.0f, 1.0f, 1.0f}; -} + if(tDesc.uSegments == 0) + tDesc.uSegments = 12; -static void -pl__fill_cone_desc_default(plDrawConeDesc* ptDesc) -{ - if(ptDesc == NULL) - return; - - ptDesc->fThickness = 0.02f; - ptDesc->fRadius = 0.5f; - ptDesc->uSegments = 12; - ptDesc->tColor = (plVec4){1.0f, 1.0f, 1.0f, 1.0f}; -} - -static void -pl__add_3d_sphere(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRadius, plVec4 tColor, float fThickness) -{ - plDrawSphereDesc tDesc = {0}; - pl__fill_sphere_desc_default(&tDesc); - tDesc.tCenter = tCenter; - tDesc.fRadius = fRadius; - tDesc.tColor = tColor; - tDesc.fThickness = fThickness; - pl__add_3d_sphere_ex(ptDrawlist, &tDesc); -} - -static void -pl__add_3d_sphere_filled(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRadius, plVec4 tColor) -{ - plDrawSphereDesc tDesc = {0}; - pl__fill_sphere_desc_default(&tDesc); - tDesc.tCenter = tCenter; - tDesc.fRadius = fRadius; - tDesc.tColor = tColor; - pl__add_3d_sphere_filled_ex(ptDrawlist, &tDesc); -} - -static void -pl__add_3d_capsule(plDrawList3D* ptDrawlist, plVec3 tBasePos, plVec3 tTipPos, float fRadius, plVec4 tColor, float fThickness) -{ - plDrawCapsuleDesc tDesc = {0}; - pl__fill_capsule_desc_default(&tDesc); - tDesc.tBasePos = tBasePos; - tDesc.tTipPos = tTipPos; - tDesc.fBaseRadius = fRadius; - tDesc.fTipRadius = fRadius; - tDesc.tColor = tColor; - tDesc.fThickness = fThickness; - pl__add_3d_capsule_ex(ptDrawlist, &tDesc); -} - -static void -pl__add_3d_cylinder_ex(plDrawList3D* ptDrawlist, const plDrawCylinderDesc* ptDesc) -{ - - plVec3 tDirection = pl_sub_vec3(ptDesc->tTipPos, ptDesc->tBasePos); + plVec3 tDirection = pl_sub_vec3(tDesc.tTipPos, tDesc.tBasePos); const float fDistance = pl_length_vec3(tDirection); tDirection = pl_norm_vec3(tDirection); const float fAngleBetweenVecs = acosf(pl_dot_vec3(tDirection, (plVec3){0.0f, 1.0f, 0.0f})); const plVec3 tRotAxis = pl_cross_vec3((plVec3){0.0f, 1.0f, 0.0f}, tDirection); const plMat4 tRot = pl_mat4_rotate_vec3(fAngleBetweenVecs, tRotAxis); - const uint32_t uPointCount = ptDesc->uSegments * 2; - const uint32_t uIndexCount = ptDesc->uSegments * 8 - 2; + const uint32_t uPointCount = tDesc.uSegments * 2; + const uint32_t uIndexCount = tDesc.uSegments * 8 - 2; plVec3* atPoints = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(plVec3) * uPointCount); uint32_t* auIndices = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(uint32_t) * uIndexCount); - const float fIncrement = PL_2PI / ptDesc->uSegments; + const float fIncrement = PL_2PI / tDesc.uSegments; float fTheta = 0.0f; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { - atPoints[i] = (plVec3){ptDesc->fRadius * sinf(fTheta + PL_PI_2), 0.0f, ptDesc->fRadius * sinf(fTheta)}; - atPoints[i + ptDesc->uSegments] = (plVec3){atPoints[i].x, atPoints[i].y + fDistance, atPoints[i].z}; + atPoints[i] = (plVec3){tDesc.fRadius * sinf(fTheta + PL_PI_2), 0.0f, tDesc.fRadius * sinf(fTheta)}; + atPoints[i + tDesc.uSegments] = (plVec3){atPoints[i].x, atPoints[i].y + fDistance, atPoints[i].z}; atPoints[i] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i]}).xyz; - atPoints[i + ptDesc->uSegments] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i + ptDesc->uSegments]}).xyz; - atPoints[i] = pl_add_vec3(atPoints[i], ptDesc->tBasePos); - atPoints[i + ptDesc->uSegments] = pl_add_vec3(atPoints[i + ptDesc->uSegments], ptDesc->tBasePos); + atPoints[i + tDesc.uSegments] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i + tDesc.uSegments]}).xyz; + atPoints[i] = pl_add_vec3(atPoints[i], tDesc.tBasePos); + atPoints[i + tDesc.uSegments] = pl_add_vec3(atPoints[i + tDesc.uSegments], tDesc.tBasePos); fTheta += fIncrement; } uint32_t uCurrentIndex = 0; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { auIndices[uCurrentIndex] = i; auIndices[uCurrentIndex + 1] = i + 1; - auIndices[uCurrentIndex + 2] = i + ptDesc->uSegments; - auIndices[uCurrentIndex + 3] = i + ptDesc->uSegments + 1; + auIndices[uCurrentIndex + 2] = i + tDesc.uSegments; + auIndices[uCurrentIndex + 3] = i + tDesc.uSegments + 1; auIndices[uCurrentIndex + 4] = i; - auIndices[uCurrentIndex + 5] = i + ptDesc->uSegments; + auIndices[uCurrentIndex + 5] = i + tDesc.uSegments; auIndices[uCurrentIndex + 6] = i + 1; - auIndices[uCurrentIndex + 7] = i + 1 + ptDesc->uSegments; + auIndices[uCurrentIndex + 7] = i + 1 + tDesc.uSegments; uCurrentIndex += 8; } uCurrentIndex -= 8; auIndices[uCurrentIndex + 1] = 0; - auIndices[uCurrentIndex + 3] = ptDesc->uSegments; - - pl__add_3d_indexed_lines(ptDrawlist, uIndexCount, atPoints, auIndices, ptDesc->tColor, ptDesc->fThickness); + auIndices[uCurrentIndex + 3] = tDesc.uSegments; + pl__add_3d_indexed_lines(ptDrawlist, uIndexCount, atPoints, auIndices, tOptions); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_cone_ex(plDrawList3D* ptDrawlist, const plDrawConeDesc* ptDesc) +pl__add_3d_cone_ex(plDrawList3D* ptDrawlist, plDrawConeDesc tDesc, plDrawLineOptions tOptions) { - plVec3 tDirection = pl_sub_vec3(ptDesc->tTipPos, ptDesc->tBasePos); + if(tDesc.uSegments == 0) + tDesc.uSegments = 12; + + plVec3 tDirection = pl_sub_vec3(tDesc.tTipPos, tDesc.tBasePos); const float fDistance = pl_length_vec3(tDirection); tDirection = pl_norm_vec3(tDirection); const float fAngleBetweenVecs = acosf(pl_dot_vec3(tDirection, (plVec3){0.0f, 1.0f, 0.0f})); const plVec3 tRotAxis = pl_cross_vec3((plVec3){0.0f, 1.0f, 0.0f}, tDirection); const plMat4 tRot = pl_mat4_rotate_vec3(fAngleBetweenVecs, tRotAxis); - const uint32_t uPointCount = ptDesc->uSegments + 1; - const uint32_t uIndexCount = ptDesc->uSegments * 2 * 2; + const uint32_t uPointCount = tDesc.uSegments + 1; + const uint32_t uIndexCount = tDesc.uSegments * 2 * 2; plVec3* atPoints = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(plVec3) * uPointCount); uint32_t* auIndices = pl_temp_allocator_alloc(&gptDrawCtx->tTempAllocator, sizeof(uint32_t) * uIndexCount); - const float fIncrement = PL_2PI / ptDesc->uSegments; + const float fIncrement = PL_2PI / tDesc.uSegments; float fTheta = 0.0f; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { - atPoints[i] = (plVec3){ptDesc->fRadius * sinf(fTheta + PL_PI_2), 0.0f, ptDesc->fRadius * sinf(fTheta)}; + atPoints[i] = (plVec3){tDesc.fRadius * sinf(fTheta + PL_PI_2), 0.0f, tDesc.fRadius * sinf(fTheta)}; atPoints[i] = pl_mul_mat4_vec4(&tRot, (plVec4){.xyz = atPoints[i]}).xyz; - atPoints[i] = pl_add_vec3(atPoints[i], ptDesc->tBasePos); + atPoints[i] = pl_add_vec3(atPoints[i], tDesc.tBasePos); fTheta += fIncrement; } - atPoints[uPointCount - 1] = ptDesc->tTipPos; + atPoints[uPointCount - 1] = tDesc.tTipPos; uint32_t uCurrentIndex = 0; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { auIndices[i * 2] = i; auIndices[i * 2 + 1] = i + 1; @@ -3008,19 +3036,18 @@ pl__add_3d_cone_ex(plDrawList3D* ptDrawlist, const plDrawConeDesc* ptDesc) auIndices[uCurrentIndex + 1] = 0; uCurrentIndex+=2; - for(uint32_t i = 0; i < ptDesc->uSegments; i++) + for(uint32_t i = 0; i < tDesc.uSegments; i++) { auIndices[uCurrentIndex + i * 2] = i; auIndices[uCurrentIndex + i * 2 + 1] = uPointCount - 1; } - pl__add_3d_indexed_lines(ptDrawlist, uIndexCount, atPoints, auIndices, ptDesc->tColor, ptDesc->fThickness); - + pl__add_3d_indexed_lines(ptDrawlist, uIndexCount, atPoints, auIndices, tOptions); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_circle_xz(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRadius, plVec4 tColor, uint32_t uSegments, float fThickness) +pl__add_3d_circle_xz(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRadius, uint32_t uSegments, plDrawLineOptions tOptions) { if(uSegments == 0){ uSegments = 12; } const float fIncrement = PL_2PI / uSegments; @@ -3032,12 +3059,12 @@ pl__add_3d_circle_xz(plDrawList3D* ptDrawlist, plVec3 tCenter, float fRadius, pl fTheta += fIncrement; } atPoints[uSegments] = atPoints[0]; - pl__add_3d_path(ptDrawlist, uSegments + 1, atPoints, tColor, fThickness); + pl__add_3d_path(ptDrawlist, uSegments + 1, atPoints, tOptions); pl_temp_allocator_reset(&gptDrawCtx->tTempAllocator); } static void -pl__add_3d_centered_box(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, float fDepth, plVec4 tColor, float fThickness) +pl__add_3d_centered_box(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, float fHeight, float fDepth, plDrawLineOptions tOptions) { const plVec3 tWidthVec = {fWidth / 2.0f, 0.0f, 0.0f}; const plVec3 tHeightVec = {0.0f, fHeight / 2.0f, 0.0f}; @@ -3068,11 +3095,11 @@ pl__add_3d_centered_box(plDrawList3D* ptDrawlist, plVec3 tCenter, float fWidth, 6, 7, 7, 4 }; - pl__add_3d_indexed_lines(ptDrawlist, 24, atVerticies, auIndices, tColor, fThickness); + pl__add_3d_indexed_lines(ptDrawlist, 24, atVerticies, auIndices, tOptions); } static void -pl__add_3d_aabb(plDrawList3D* ptDrawlist, plVec3 tMin, plVec3 tMax, plVec4 tColor, float fThickness) +pl__add_3d_aabb(plDrawList3D* ptDrawlist, plVec3 tMin, plVec3 tMax, plDrawLineOptions tOptions) { const plVec3 atVerticies[] = { @@ -3100,11 +3127,11 @@ pl__add_3d_aabb(plDrawList3D* ptDrawlist, plVec3 tMin, plVec3 tMax, plVec4 tColo 6, 7, 7, 4 }; - pl__add_3d_indexed_lines(ptDrawlist, 24, atVerticies, auIndices, tColor, fThickness); + pl__add_3d_indexed_lines(ptDrawlist, 24, atVerticies, auIndices, tOptions); } static void -pl__add_3d_bezier_quad(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 tP2, plVec4 tColor, float fThickness, uint32_t uSegments) +pl__add_3d_bezier_quad(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 tP2, uint32_t uSegments, plDrawLineOptions tOptions) { // order of the bezier curve inputs are 0=start, 1=control, 2=ending @@ -3132,17 +3159,17 @@ pl__add_3d_bezier_quad(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 atVerticies[0] = atVerticies[1]; atVerticies[1] = p4; - pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tColor, fThickness); + pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tOptions); } // set up last point atVerticies[0] = atVerticies[1]; atVerticies[1] = tP2; - pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tColor, fThickness); + pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tOptions); } static void -pl__add_3d_bezier_cubic(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 tP2, plVec3 tP3, plVec4 tColor, float fThickness, uint32_t uSegments) +pl__add_3d_bezier_cubic(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 tP2, plVec3 tP3, uint32_t uSegments, plDrawLineOptions tOptions) { // order of the bezier curve inputs are 0=start, 1=control 1, 2=control 2, 3=ending @@ -3173,13 +3200,13 @@ pl__add_3d_bezier_cubic(plDrawList3D* ptDrawlist, plVec3 tP0, plVec3 tP1, plVec3 atVerticies[0] = atVerticies[1]; atVerticies[1] = p7; - pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tColor, fThickness); + pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tOptions); } // set up last point atVerticies[0] = atVerticies[1]; atVerticies[1] = tP3; - pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tColor, fThickness); + pl__add_3d_line(ptDrawlist, atVerticies[0], atVerticies[1], tOptions); } //----------------------------------------------------------------------------- @@ -3446,7 +3473,7 @@ pl_add_default_font(plFontAtlas* ptAtlas) plFontConfig fontConfig = { .bSdf = false, - .fFontSize = 13.0f, + .fSize = 13.0f, .uHOverSampling = 1, .uVOverSampling = 1, .ucOnEdgeValue = 255, @@ -3473,13 +3500,12 @@ pl_load_draw_3d_api(void) .new_frame = pl_new_draw_3d_frame, .add_3d_triangle_filled = pl__add_3d_triangle_filled, .add_3d_circle_xz_filled = pl__add_3d_circle_xz_filled, - .add_3d_sphere_filled_ex = pl__add_3d_sphere_filled_ex, .add_3d_band_xz_filled = pl__add_3d_band_xz_filled, .add_3d_band_xy_filled = pl__add_3d_band_xy_filled, .add_3d_band_yz_filled = pl__add_3d_band_yz_filled, .add_3d_sphere_filled = pl__add_3d_sphere_filled, - .add_3d_cylinder_filled_ex = pl__add_3d_cylinder_filled_ex, - .add_3d_cone_filled_ex = pl__add_3d_cone_filled_ex, + .add_3d_cylinder_filled = pl__add_3d_cylinder_filled, + .add_3d_cone_filled = pl__add_3d_cone_filled, .add_3d_centered_box_filled = pl__add_3d_centered_box_filled, .add_3d_plane_xz_filled = pl__add_3d_plane_xz_filled, .add_3d_plane_xy_filled = pl__add_3d_plane_xy_filled, @@ -3488,24 +3514,19 @@ pl_load_draw_3d_api(void) .add_3d_cross = pl__add_3d_cross, .add_3d_transform = pl__add_3d_transform, .add_3d_frustum = pl__add_3d_frustum, - .add_3d_sphere = pl__add_3d_sphere, - .add_3d_sphere_ex = pl__add_3d_sphere_ex, - .add_3d_capsule = pl__add_3d_capsule, - .add_3d_capsule_ex = pl__add_3d_capsule_ex, - .add_3d_cylinder_ex = pl__add_3d_cylinder_ex, - .add_3d_cone_ex = pl__add_3d_cone_ex, + .add_3d_sphere = pl__add_3d_sphere_ex, + .add_3d_capsule = pl__add_3d_capsule_ex, + .add_3d_cylinder = pl__add_3d_cylinder, + .add_3d_cone = pl__add_3d_cone_ex, .add_3d_centered_box = pl__add_3d_centered_box, .add_3d_bezier_quad = pl__add_3d_bezier_quad, .add_3d_bezier_cubic = pl__add_3d_bezier_cubic, .add_3d_aabb = pl__add_3d_aabb, .add_3d_circle_xz = pl__add_3d_circle_xz, .add_3d_text = pl__add_3d_text, - .fill_capsule_desc_default = pl__fill_capsule_desc_default, - .fill_sphere_desc_default = pl__fill_sphere_desc_default, - .fill_cylinder_desc_default = pl__fill_cylinder_desc_default, - .fill_cone_desc_default = pl__fill_cone_desc_default, .request_2d_drawlist = pl_request_2d_drawlist, .return_2d_drawlist = pl_return_2d_drawlist, + .prepare_2d_drawlist = pl_prepare_2d_drawlist, .request_2d_layer = pl_request_2d_layer, .return_2d_layer = pl_return_2d_layer, .submit_2d_layer = pl_submit_2d_layer, @@ -3518,25 +3539,22 @@ pl_load_draw_3d_api(void) .add_font_from_file_ttf = pl_add_font_from_file_ttf, .add_font_from_memory_ttf = pl_add_font_from_memory_ttf, .calculate_text_size = pl_calculate_text_size, - .calculate_text_size_ex = pl_calculate_text_size_ex, .calculate_text_bb = pl_calculate_text_bb, - .calculate_text_bb_ex = pl_calculate_text_bb_ex, .push_clip_rect_pt = pl_push_clip_rect_pt, .push_clip_rect = pl_push_clip_rect, .pop_clip_rect = pl_pop_clip_rect, .get_clip_rect = pl_get_clip_rect, .add_line = pl_add_line, .add_lines = pl_add_lines, - .add_text = pl_add_text, - .add_text_ex = pl_add_text_ex, - .add_text_clipped = pl_add_text_clipped, - .add_text_clipped_ex = pl_add_text_clipped_ex, + .add_text = pl_add_text_ex, + .add_text_clipped = pl_add_text_clipped_ex, .add_triangle = pl_add_triangle, .add_triangle_filled = pl_add_triangle_filled, - .add_rect = pl_add_rect_rounded, - .add_rect_filled = pl_add_rect_rounded_filled, - .add_rect_ex = pl_add_rect_rounded_ex, - .add_rect_filled_ex = pl_add_rect_rounded_filled_ex, + .add_triangles_filled = pl_add_triangles_filled, + .add_rect_rounded = pl_add_rect_rounded_ex, + .add_rect_rounded_filled = pl_add_rect_rounded_filled_ex, + .add_rect = pl_add_rect, + .add_rect_filled = pl_add_rect_filled, .add_quad = pl_add_quad, .add_quad_filled = pl_add_quad_filled, .add_circle = pl_add_circle, diff --git a/extensions/pl_draw_ext.h b/extensions/pl_draw_ext.h index 637c92e1..e5747a8c 100644 --- a/extensions/pl_draw_ext.h +++ b/extensions/pl_draw_ext.h @@ -5,6 +5,7 @@ /* Index of this file: // [SECTION] header mess +// [SECTION] defines // [SECTION] apis // [SECTION] includes // [SECTION] forward declarations & basic types @@ -22,8 +23,16 @@ Index of this file: #define PL_DRAW_EXT_H // extension version (format XYYZZ) -// #define PL_DRAW_EXT_VERSION "1.0.0" -// #define PL_DRAW_EXT_VERSION_NUM 10000 +#define PL_DRAW_EXT_VERSION "1.0.0" +#define PL_DRAW_EXT_VERSION_NUM 10000 + +//----------------------------------------------------------------------------- +// [SECTION] defines +//----------------------------------------------------------------------------- + +#ifndef PL_MAX_NAME_LENGTH + #define PL_MAX_NAME_LENGTH 1024 +#endif //----------------------------------------------------------------------------- // [SECTION] apis @@ -44,30 +53,41 @@ typedef struct _plDrawI plDrawI; //----------------------------------------------------------------------------- // basic types -typedef struct _plDrawInit plDrawInit; -typedef struct _plFontAtlas plFontAtlas; -typedef struct _plDrawList2D plDrawList2D; -typedef struct _plDrawList3D plDrawList3D; -typedef struct _plDrawLayer2D plDrawLayer2D; +typedef struct _plDrawInit plDrawInit; // initialization options (reserved for future use) +typedef struct _plFontAtlas plFontAtlas; // font atlas data +typedef struct _plDrawList2D plDrawList2D; // drawlist data for 2D +typedef struct _plDrawList3D plDrawList3D; // drawlist data for 3D +typedef struct _plDrawLayer2D plDrawLayer2D; // opaque type for 2D draw layers + +// vertex buffer types +typedef struct _plDrawVertex plDrawVertex; // vertex type (LAYOUT & PADDING MATTERS) +typedef struct _plDrawVertex3DSolid plDrawVertex3DSolid; // vertex type (LAYOUT & PADDING MATTERS) +typedef struct _plDrawVertex3DLine plDrawVertex3DLine; // vertex type (LAYOUT & PADDING MATTERS) +typedef struct _plDraw3DText plDraw3DText; // primitive options -typedef struct _plDrawCapsuleDesc plDrawCapsuleDesc; -typedef struct _plDrawSphereDesc plDrawSphereDesc; -typedef struct _plDrawCylinderDesc plDrawCylinderDesc; -typedef struct _plDrawConeDesc plDrawConeDesc; +typedef struct _plDrawLineOptions plDrawLineOptions; // options for lines +typedef struct _plDrawSolidOptions plDrawSolidOptions; // options for solids +typedef struct _plDrawTextOptions plDrawTextOptions; // options for text +typedef struct _plDrawCapsuleDesc plDrawCapsuleDesc; // description for drawing capsules +typedef struct _plDrawSphereDesc plDrawSphereDesc; // description for drawing spheres +typedef struct _plDrawCylinderDesc plDrawCylinderDesc; // description for drawing cylinders +typedef struct _plDrawConeDesc plDrawConeDesc; // description for drawing cones +typedef struct _plDrawFrustumDesc plDrawFrustumDesc; // description for drawing frustums // font types -typedef struct _plFontChar plFontChar; -typedef struct _plFontGlyph plFontGlyph; -typedef struct _plFontCustomRect plFontCustomRect; typedef struct _plFontRange plFontRange; // a range of characters typedef struct _plFont plFont; // a single font with a specific size and config typedef struct _plFontConfig plFontConfig; // configuration for loading a single font +typedef struct _plFontChar plFontChar; // internal type +typedef struct _plFontGlyph plFontGlyph; // internal type +typedef struct _plFontCustomRect plFontCustomRect; // internal type // enums typedef int plDrawFlags; // -> enum _plDrawFlags // Flags: typedef int plDrawRectFlags; // -> enum _plDrawRectFlags // Flags: +// backend texture type #ifndef plTextureID typedef uint64_t plTextureID; #endif @@ -80,63 +100,65 @@ typedef struct _plDrawI { // init/cleanup void (*initialize)(const plDrawInit*); - void (*cleanup) (void); // usually called by backend + void (*cleanup) (void); // usually called by backend "cleanup" func. // per frame - void (*new_frame)(void); // usually called by backend + void (*new_frame)(void); // usually called by backend "new_frame" func. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~fonts~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // font atlas plFontAtlas* (*create_font_atlas) (void); - bool (*prepare_font_atlas) (plFontAtlas*); // usually called by backend - void (*cleanup_font_atlas) (plFontAtlas*); // usually called by backend + bool (*prepare_font_atlas) (plFontAtlas*); // usually called by backend "build_font_atlas" func. + void (*cleanup_font_atlas) (plFontAtlas*); // usually called by backend "cleanup_font_atlas" func. void (*set_font_atlas) (plFontAtlas*); plFontAtlas* (*get_current_font_atlas)(void); plFont* (*add_default_font) (plFontAtlas*); - plFont* (*add_font_from_file_ttf) (plFontAtlas*, plFontConfig, const char* pcFile); - plFont* (*add_font_from_memory_ttf)(plFontAtlas*, plFontConfig, void* pData); - plVec2 (*calculate_text_size) (plFont*, float fSize, const char* pcText, float fWrap); - plVec2 (*calculate_text_size_ex) (plFont*, float fSize, const char* pcText, const char* pcTextEnd, float fWrap); - plRect (*calculate_text_bb) (plFont*, float fSize, plVec2 tP, const char* pcText, float fWrap); - plRect (*calculate_text_bb_ex) (plFont*, float fSize, plVec2 tP, const char* pcText, const char* pcTextEnd, float fWrap); + plFont* (*add_font_from_file_ttf) (plFontAtlas*, plFontConfig, const char* file); + plFont* (*add_font_from_memory_ttf)(plFontAtlas*, plFontConfig, void* data); + plVec2 (*calculate_text_size) (const char* text, plDrawTextOptions); + plRect (*calculate_text_bb) (plVec2 p, const char* text, plDrawTextOptions); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~2D~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // drawlists plDrawList2D* (*request_2d_drawlist)(void); void (*return_2d_drawlist) (plDrawList2D*); + void (*prepare_2d_drawlist)(plDrawList2D*); // usually called by backend "submit_2d_drawlist" func. // layers plDrawLayer2D* (*request_2d_layer)(plDrawList2D*); void (*return_2d_layer) (plDrawLayer2D*); void (*submit_2d_layer) (plDrawLayer2D*); - // drawing - void (*add_line) (plDrawLayer2D*, plVec2 tP0, plVec2 tP1, plVec4 tColor, float fThickness); - void (*add_lines) (plDrawLayer2D*, plVec2* atPoints, uint32_t uCount, plVec4 tColor, float fThickness); - void (*add_text) (plDrawLayer2D*, plFont*, float fSize, plVec2 tP, plVec4 tColor, const char* pcText, float fWrap); - void (*add_text_ex) (plDrawLayer2D*, plFont*, float fSize, plVec2 tP, plVec4 tColor, const char* pcText, const char* pcTextEnd, float fWrap); - void (*add_text_clipped) (plDrawLayer2D*, plFont*, float fSize, plVec2 tP, plVec2 tMin, plVec2 tMax, plVec4 tColor, const char* pcText, float fWrap); - void (*add_text_clipped_ex)(plDrawLayer2D*, plFont*, float fSize, plVec2 tP, plVec2 tMin, plVec2 tMax, plVec4 tColor, const char* pcText, const char* pcTextEnd, float fWrap); - void (*add_triangle) (plDrawLayer2D*, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec4 tColor, float fThickness); - void (*add_triangle_filled)(plDrawLayer2D*, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec4 tColor); - void (*add_rect) (plDrawLayer2D*, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fThickness, float fRadius, uint32_t uSegments); - void (*add_rect_filled) (plDrawLayer2D*, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fRadius, uint32_t uSegments); - void (*add_rect_ex) (plDrawLayer2D*, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fThickness, float fRadius, uint32_t uSegments, plDrawRectFlags); - void (*add_rect_filled_ex) (plDrawLayer2D*, plVec2 tMinP, plVec2 tMaxP, plVec4 tColor, float fRadius, uint32_t uSegments, plDrawRectFlags); - void (*add_quad) (plDrawLayer2D*, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plVec4 tColor, float fThickness); - void (*add_quad_filled) (plDrawLayer2D*, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plVec4 tColor); - void (*add_circle) (plDrawLayer2D*, plVec2 tP, float fRadius, plVec4 tColor, uint32_t uSegments, float fThickness); - void (*add_circle_filled) (plDrawLayer2D*, plVec2 tP, float fRadius, plVec4 tColor, uint32_t uSegments); - void (*add_image) (plDrawLayer2D*, plTextureID, plVec2 tPMin, plVec2 tPMax); - void (*add_image_ex) (plDrawLayer2D*, plTextureID, plVec2 tPMin, plVec2 tPMax, plVec2 tUvMin, plVec2 tUvMax, plVec4 tColor); - void (*add_bezier_quad) (plDrawLayer2D*, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec4 tColor, float fThickness, uint32_t uSegments); - void (*add_bezier_cubic) (plDrawLayer2D*, plVec2 tP0, plVec2 tP1, plVec2 tP2, plVec2 tP3, plVec4 tColor, float fThickness, uint32_t uSegments); + // drawing (lines) + void (*add_line) (plDrawLayer2D*, plVec2 p0, plVec2 p1, plDrawLineOptions); + void (*add_lines) (plDrawLayer2D*, plVec2* points, uint32_t count, plDrawLineOptions); + void (*add_triangle) (plDrawLayer2D*, plVec2 p0, plVec2 p1, plVec2 p2, plDrawLineOptions); + void (*add_rect) (plDrawLayer2D*, plVec2 pMin, plVec2 pMax, plDrawLineOptions); + void (*add_rect_rounded)(plDrawLayer2D*, plVec2 pMin, plVec2 pMax, float radius, uint32_t segments, plDrawRectFlags, plDrawLineOptions); + void (*add_quad) (plDrawLayer2D*, plVec2 p0, plVec2 p1, plVec2 p2, plVec2 p3, plDrawLineOptions); + void (*add_circle) (plDrawLayer2D*, plVec2 p, float radius, uint32_t segments, plDrawLineOptions); + void (*add_bezier_quad) (plDrawLayer2D*, plVec2 p0, plVec2 p1, plVec2 p2, uint32_t segments, plDrawLineOptions); + void (*add_bezier_cubic)(plDrawLayer2D*, plVec2 p0, plVec2 p1, plVec2 p2, plVec2 p3, uint32_t segments, plDrawLineOptions); + + // drawing (solids) + void (*add_triangle_filled) (plDrawLayer2D*, plVec2 p0, plVec2 p1, plVec2 p2, plDrawSolidOptions); + void (*add_triangles_filled) (plDrawLayer2D*, plVec2* points, uint32_t count, plDrawSolidOptions); + void (*add_rect_filled) (plDrawLayer2D*, plVec2 minP, plVec2 maxP, plDrawSolidOptions); + void (*add_rect_rounded_filled)(plDrawLayer2D*, plVec2 minP, plVec2 maxP, float radius, uint32_t segments, plDrawRectFlags, plDrawSolidOptions); + void (*add_quad_filled) (plDrawLayer2D*, plVec2 p0, plVec2 p1, plVec2 p2, plVec2 p3, plDrawSolidOptions); + void (*add_circle_filled) (plDrawLayer2D*, plVec2 p, float radius, uint32_t segments, plDrawSolidOptions); + void (*add_image) (plDrawLayer2D*, plTextureID, plVec2 minP, plVec2 maxP); + void (*add_image_ex) (plDrawLayer2D*, plTextureID, plVec2 minP, plVec2 maxP, plVec2 minUV, plVec2 maxUV, uint32_t color); + + // drawing (text) + void (*add_text) (plDrawLayer2D*, plVec2 p, const char* text, plDrawTextOptions); + void (*add_text_clipped)(plDrawLayer2D*, plVec2 p, const char* text, plVec2 clipMin, plVec2 clipMax, plDrawTextOptions); // clipping - void (*push_clip_rect_pt)(plDrawList2D*, const plRect*); + void (*push_clip_rect_pt)(plDrawList2D*, const plRect*, bool bAccumulate); void (*push_clip_rect) (plDrawList2D*, plRect, bool bAccumulate); void (*pop_clip_rect) (plDrawList2D*); const plRect* (*get_clip_rect) (plDrawList2D*); @@ -147,46 +169,37 @@ typedef struct _plDrawI plDrawList3D* (*request_3d_drawlist)(void); void (*return_3d_drawlist)(plDrawList3D*); + // text + void (*add_3d_text)(plDrawList3D*, plVec3 p, const char* text, plDrawTextOptions); + // solid - void (*add_3d_triangle_filled) (plDrawList3D*, plVec3 tP0, plVec3 tP1, plVec3 tP2, plVec4 tColor); - void (*add_3d_sphere_filled) (plDrawList3D*, plVec3 tCenter, float fRadius, plVec4 tColor); - void (*add_3d_sphere_filled_ex) (plDrawList3D*, const plDrawSphereDesc*); - void (*add_3d_circle_xz_filled) (plDrawList3D*, plVec3 tCenter, float fRadius, plVec4 tColor, uint32_t uSegments); - void (*add_3d_band_xz_filled) (plDrawList3D*, plVec3 tCenter, float fInnerRadius, float fOuterRadius, plVec4 tColor, uint32_t uSegments); - void (*add_3d_band_xy_filled) (plDrawList3D*, plVec3 tCenter, float fInnerRadius, float fOuterRadius, plVec4 tColor, uint32_t uSegments); - void (*add_3d_band_yz_filled) (plDrawList3D*, plVec3 tCenter, float fInnerRadius, float fOuterRadius, plVec4 tColor, uint32_t uSegments); - void (*add_3d_cylinder_filled_ex) (plDrawList3D*, const plDrawCylinderDesc*); - void (*add_3d_cone_filled_ex) (plDrawList3D*, const plDrawConeDesc*); - void (*add_3d_centered_box_filled)(plDrawList3D*, plVec3 tCenter, float fWidth, float fHeight, float fDepth, plVec4 tColor); - void (*add_3d_plane_xz_filled) (plDrawList3D*, plVec3 tCenter, float fWidth, float fHeight, plVec4 tColor); - void (*add_3d_plane_xy_filled) (plDrawList3D*, plVec3 tCenter, float fWidth, float fHeight, plVec4 tColor); - void (*add_3d_plane_yz_filled) (plDrawList3D*, plVec3 tCenter, float fWidth, float fHeight, plVec4 tColor); + void (*add_3d_triangle_filled) (plDrawList3D*, plVec3 p0, plVec3 p1, plVec3 p2, plDrawSolidOptions); + void (*add_3d_circle_xz_filled) (plDrawList3D*, plVec3 center, float radius, uint32_t segments, plDrawSolidOptions); + void (*add_3d_band_xz_filled) (plDrawList3D*, plVec3 center, float innerRadius, float outerRadius, uint32_t segments, plDrawSolidOptions); + void (*add_3d_band_xy_filled) (plDrawList3D*, plVec3 center, float innerRadius, float outerRadius, uint32_t segments, plDrawSolidOptions); + void (*add_3d_band_yz_filled) (plDrawList3D*, plVec3 center, float innerRadius, float outerRadius, uint32_t segments, plDrawSolidOptions); + void (*add_3d_centered_box_filled)(plDrawList3D*, plVec3 center, float width, float height, float depth, plDrawSolidOptions); + void (*add_3d_plane_xz_filled) (plDrawList3D*, plVec3 center, float width, float height, plDrawSolidOptions); + void (*add_3d_plane_xy_filled) (plDrawList3D*, plVec3 center, float width, float height, plDrawSolidOptions); + void (*add_3d_plane_yz_filled) (plDrawList3D*, plVec3 center, float width, float height, plDrawSolidOptions); + void (*add_3d_sphere_filled) (plDrawList3D*, plDrawSphereDesc, plDrawSolidOptions); + void (*add_3d_cylinder_filled) (plDrawList3D*, plDrawCylinderDesc, plDrawSolidOptions); + void (*add_3d_cone_filled) (plDrawList3D*, plDrawConeDesc, plDrawSolidOptions); // wireframe - void (*add_3d_line) (plDrawList3D*, plVec3 tP0, plVec3 tP1, plVec4 tColor, float fThickness); - void (*add_3d_cross) (plDrawList3D*, plVec3 tP0, plVec4 tColor, float fLength, float fThickness); - void (*add_3d_transform) (plDrawList3D*, const plMat4* ptTransform, float fLength, float fThickness); - void (*add_3d_frustum) (plDrawList3D*, const plMat4* ptTransform, float fYFov, float fAspect, float fNearZ, float fFarZ, plVec4 tColor, float fThickness); - void (*add_3d_centered_box)(plDrawList3D*, plVec3 tCenter, float fWidth, float fHeight, float fDepth, plVec4 tColor, float fThickness); - void (*add_3d_aabb) (plDrawList3D*, plVec3 tMin, plVec3 tMax, plVec4 tColor, float fThickness); - void (*add_3d_bezier_quad) (plDrawList3D*, plVec3 tP0, plVec3 tP1, plVec3 tP2, plVec4 tColor, float fThickness, uint32_t uSegments); - void (*add_3d_bezier_cubic)(plDrawList3D*, plVec3 tP0, plVec3 tP1, plVec3 tP2, plVec3 tP3, plVec4 tColor, float fThickness, uint32_t uSegments); - void (*add_3d_circle_xz) (plDrawList3D*, plVec3 tCenter, float fRadius, plVec4 tColor, uint32_t uSegments, float fThickness); - void (*add_3d_capsule) (plDrawList3D*, plVec3 tBasePos, plVec3 tTipPos, float fRadius, plVec4 tColor, float fThickness); - void (*add_3d_sphere) (plDrawList3D*, plVec3 tCenter, float fRadius, plVec4 tColor, float fThickness); - void (*add_3d_sphere_ex) (plDrawList3D*, const plDrawSphereDesc*); - void (*add_3d_capsule_ex) (plDrawList3D*, const plDrawCapsuleDesc*); - void (*add_3d_cylinder_ex) (plDrawList3D*, const plDrawCylinderDesc*); - void (*add_3d_cone_ex) (plDrawList3D*, const plDrawConeDesc*); - - // text - void (*add_3d_text)(plDrawList3D*, plFont*, float fSize, plVec3 tP, plVec4 tColor, const char* pcText, float fWrap); - - // primitive option helpers (fills defaults) - void (*fill_capsule_desc_default) (plDrawCapsuleDesc*); - void (*fill_sphere_desc_default) (plDrawSphereDesc*); - void (*fill_cylinder_desc_default)(plDrawCylinderDesc*); - void (*fill_cone_desc_default) (plDrawConeDesc*); + void (*add_3d_line) (plDrawList3D*, plVec3 p0, plVec3 p1, plDrawLineOptions); + void (*add_3d_cross) (plDrawList3D*, plVec3 p, float length, plDrawLineOptions); + void (*add_3d_transform) (plDrawList3D*, const plMat4* transform, float length, plDrawLineOptions); + void (*add_3d_frustum) (plDrawList3D*, const plMat4* transform, plDrawFrustumDesc, plDrawLineOptions); + void (*add_3d_centered_box)(plDrawList3D*, plVec3 center, float width, float height, float depth, plDrawLineOptions); + void (*add_3d_aabb) (plDrawList3D*, plVec3 minP, plVec3 maxP, plDrawLineOptions); + void (*add_3d_bezier_quad) (plDrawList3D*, plVec3 p0, plVec3 p1, plVec3 p2, uint32_t segments, plDrawLineOptions); + void (*add_3d_bezier_cubic)(plDrawList3D*, plVec3 p0, plVec3 p1, plVec3 p2, plVec3 tP3, uint32_t segments, plDrawLineOptions); + void (*add_3d_circle_xz) (plDrawList3D*, plVec3 center, float radius, uint32_t segments, plDrawLineOptions); + void (*add_3d_sphere) (plDrawList3D*, plDrawSphereDesc, plDrawLineOptions); + void (*add_3d_capsule) (plDrawList3D*, plDrawCapsuleDesc, plDrawLineOptions); + void (*add_3d_cylinder) (plDrawList3D*, plDrawCylinderDesc, plDrawLineOptions); + void (*add_3d_cone) (plDrawList3D*, plDrawConeDesc, plDrawLineOptions); } plDrawI; @@ -206,17 +219,17 @@ enum _plDrawFlags enum _plDrawRectFlags { - PL_DRAW_RECT_FLAG_NONE = 0, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT = 1 << 0, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT = 1 << 1, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT = 1 << 2, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT = 1 << 4, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_NONE = 1 << 5, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM = PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_LEFT = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_RIGHT = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT, - PL_DRAW_RECT_FLAG_ROUND_CORNERS_All = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT, + PL_DRAW_RECT_FLAG_NONE = 0, // default: PL_DRAW_RECT_FLAG_ROUND_CORNERS_All + PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT = 1 << 0, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT = 1 << 1, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT = 1 << 2, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT = 1 << 4, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_NONE = 1 << 5, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM = PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_LEFT = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_RIGHT = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT, + PL_DRAW_RECT_FLAG_ROUND_CORNERS_All = PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_RIGHT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_LEFT | PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM_RIGHT, }; //----------------------------------------------------------------------------- @@ -234,10 +247,8 @@ typedef struct _plDrawCapsuleDesc float fBaseRadius; plVec3 tTipPos; float fTipRadius; - plVec4 tColor; - float fThickness; - uint32_t uLatBands; - uint32_t uLongBands; + uint32_t uLatBands; // default: 16 + uint32_t uLongBands; // default: 16 float fEndOffsetRatio; } plDrawCapsuleDesc; @@ -245,10 +256,8 @@ typedef struct _plDrawSphereDesc { plVec3 tCenter; float fRadius; - plVec4 tColor; - uint32_t uLatBands; - uint32_t uLongBands; - float fThickness; + uint32_t uLatBands; // default: 16 + uint32_t uLongBands; // default: 16 } plDrawSphereDesc; typedef struct _plDrawCylinderDesc @@ -256,9 +265,7 @@ typedef struct _plDrawCylinderDesc plVec3 tBasePos; plVec3 tTipPos; float fRadius; - plVec4 tColor; - float fThickness; - uint32_t uSegments; + uint32_t uSegments; // default: 12 } plDrawCylinderDesc; typedef struct _plDrawConeDesc @@ -266,11 +273,37 @@ typedef struct _plDrawConeDesc plVec3 tBasePos; plVec3 tTipPos; float fRadius; - plVec4 tColor; - float fThickness; - uint32_t uSegments; + uint32_t uSegments; // default: 12 } plDrawConeDesc; +typedef struct _plDrawFrustumDesc +{ + float fYFov; + float fAspectRatio; + float fNearZ; + float fFarZ; +} plDrawFrustumDesc; + +typedef struct _plDrawLineOptions +{ + uint32_t uColor; + float fThickness; +} plDrawLineOptions; + +typedef struct _plDrawSolidOptions +{ + uint32_t uColor; +} plDrawSolidOptions; + +typedef struct _plDrawTextOptions +{ + plFont* ptFont; + float fSize; // if zero, will use loaded size + uint32_t uColor; + float fWrap; // 0.0f, no wrap + const char* pcTextEnd; // if null terminated, set to NULL +} plDrawTextOptions; + typedef struct _plFontRange { int iFirstCodePoint; @@ -282,24 +315,23 @@ typedef struct _plFontRange typedef struct _plFontConfig { - float fFontSize; + float fSize; const plFontRange* ptRanges; uint32_t uRangeCount; const int* piIndividualChars; uint32_t uIndividualCharCount; - bool bMergeFont; - plFont* tMergeFont; + plFont* ptMergeFont; - // BITMAP + // BITMAP ONLY uint32_t uVOverSampling; uint32_t uHOverSampling; - // SDF (ttf only) + // SDF ONLY (ttf only) bool bSdf; int iSdfPadding; unsigned char ucOnEdgeValue; - // internal + // [INTERNAL] plFontRange* _sbtRanges; plFontChar* _sbtCharData; float _fSdfPixelDistScale; @@ -307,60 +339,30 @@ typedef struct _plFontConfig typedef struct _plFont { - float fSize; - float fLineSpacing; - - // internal - plFontRange* sbtRanges; - uint32_t _uCodePointCount; - uint32_t* _auCodePoints; // glyph index lookup based on codepoint - plFontGlyph* sbtGlyphs; // glyphs - plFontConfig* _sbtConfigs; + float fSize; // loaded size + + // [INTERNAL] + float _fLineSpacing; + plFontRange* _sbtRanges; + uint32_t _uCodePointCount; + uint32_t* _auCodePoints; // glyph index lookup based on codepoint + plFontGlyph* _sbtGlyphs; // glyphs + plFontConfig* _sbtConfigs; struct _plFontPrepData* _sbtPreps; - - plFont* _ptNextFont; + plFont* _ptNextFont; } plFont; -typedef struct _plFontCustomRect -{ - uint32_t uWidth; - uint32_t uHeight; - uint32_t uX; - uint32_t uY; - unsigned char* pucBytes; -} plFontCustomRect; - -typedef struct _plFontChar -{ - uint16_t x0; - uint16_t y0; - uint16_t x1; - uint16_t y1; - float xOff; - float yOff; - float xAdv; - float xOff2; - float yOff2; -} plFontChar; - -typedef struct _plFontGlyph -{ - float x0; - float y0; - float u0; - float v0; - float x1; - float y1; - float u1; - float v1; - float xAdvance; - float leftBearing; -} plFontGlyph; - //----------------------------------------------------------------------------- // [SECTION] structs for backends //----------------------------------------------------------------------------- +typedef struct _plDrawVertex +{ + float afPos[2]; + float afUv[2]; + uint32_t uColor; +} plDrawVertex; + typedef struct _plDrawVertex3DSolid { float afPos[3]; @@ -379,18 +381,21 @@ typedef struct _plDrawVertex3DLine typedef struct _plDraw3DText { - plFont* tFontHandle; - float fSize; - plVec3 tP; - plVec4 tColor; - char acText[PL_MAX_NAME_LENGTH]; - float fWrap; + plFont* ptFont; + float fSize; + plVec3 tP; + uint32_t uColor; + char acText[PL_MAX_NAME_LENGTH]; + float fWrap; } plDraw3DText; typedef struct _plDrawList3D { + // solid plDrawVertex3DSolid* sbtSolidVertexBuffer; uint32_t* sbtSolidIndexBuffer; + + // lines plDrawVertex3DLine* sbtLineVertexBuffer; uint32_t* sbtLineIndexBuffer; @@ -400,13 +405,6 @@ typedef struct _plDrawList3D plDrawLayer2D* ptLayer; } plDrawList3D; -typedef struct _plDrawVertex -{ - float afPos[2]; - float afUv[2]; - uint32_t uColor; -} plDrawVertex; - typedef struct _plDrawCommand { uint32_t uVertexOffset; @@ -417,46 +415,36 @@ typedef struct _plDrawCommand bool bSdf; } plDrawCommand; -typedef struct _plDrawLayer2D -{ - plDrawList2D* ptDrawlist; - plDrawCommand* sbtCommandBuffer; - uint32_t* sbuIndexBuffer; - plVec2* sbtPath; - uint32_t uVertexCount; - plDrawCommand* _ptLastCommand; -} plDrawLayer2D; - typedef struct _plDrawList2D { - plDrawLayer2D** sbtSubmittedLayers; - plDrawLayer2D** sbtLayerCache; - plDrawLayer2D** sbtLayersCreated; - plDrawCommand* sbtDrawCommands; - plDrawVertex* sbtVertexBuffer; - uint32_t uIndexBufferByteSize; - uint32_t uLayersCreated; - plRect* sbtClipStack; - int _padding; + plDrawVertex* sbtVertexBuffer; + uint32_t* sbuIndexBuffer; + uint32_t uIndexBufferByteSize; + plDrawCommand* sbtDrawCommands; + + // [INTERNAL] + plDrawLayer2D** _sbtSubmittedLayers; + plDrawLayer2D** _sbtLayerCache; + plDrawLayer2D** _sbtLayersCreated; + plRect* _sbtClipStack; } plDrawList2D; typedef struct _plFontAtlas { - // fonts - plFont* _ptFontListHead; - - plFontCustomRect* sbtCustomRects; - unsigned char* pucPixelsAsAlpha8; - unsigned char* pucPixelsAsRGBA32; - uint32_t auAtlasSize[2]; - float afWhiteUv[2]; - bool bDirty; - int iGlyphPadding; - size_t szPixelDataSize; - plFontCustomRect* ptWhiteRect; - plTextureID tTexture; - float fTotalArea; - + + plVec2 tAtlasSize; + plTextureID tTexture; + unsigned char* pucPixelsAsRGBA32; + + // [INTERNAL] + plFont* _ptFontListHead; + plFontCustomRect* _sbtCustomRects; + unsigned char* _pucPixelsAsAlpha8; + plVec2 _tWhiteUv; + int _iGlyphPadding; + size_t _szPixelDataSize; + plFontCustomRect* _ptWhiteRect; + float _fTotalArea; } plFontAtlas; #endif // PL_DRAW_EXT_H \ No newline at end of file diff --git a/extensions/pl_renderer_ext.c b/extensions/pl_renderer_ext.c index 3bb1488f..a7554e2f 100644 --- a/extensions/pl_renderer_ext.c +++ b/extensions/pl_renderer_ext.c @@ -4135,7 +4135,7 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions const plDrawable tDrawable = ptScene->sbtOutlineDrawables[i]; plObjectComponent* ptObject = gptECS->get_component(&ptScene->tComponentLibrary, PL_COMPONENT_TYPE_OBJECT, tDrawable.tEntity); plMeshComponent* ptMesh = gptECS->get_component(&ptScene->tComponentLibrary, PL_COMPONENT_TYPE_MESH, ptObject->tMesh); - gptDraw->add_3d_aabb(ptView->pt3DSelectionDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, tOutlineColor, 0.01f); + gptDraw->add_3d_aabb(ptView->pt3DSelectionDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(tOutlineColor), .fThickness = 0.01f}); } } @@ -4146,7 +4146,7 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions if(ptScene->sbtLightData[i].iType == PL_LIGHT_TYPE_POINT) { const plVec4 tColor = {.rgb = ptScene->sbtLightData[i].tColor, .a = 1.0f}; - gptDraw->add_3d_cross(ptView->pt3DDrawList, ptScene->sbtLightData[i].tPosition, tColor, 0.25f, 0.02f); + gptDraw->add_3d_cross(ptView->pt3DDrawList, ptScene->sbtLightData[i].tPosition, 0.02f, (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(tColor), .fThickness = 0.25f}); } } @@ -4157,13 +4157,13 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions { plMeshComponent* ptMesh = gptECS->get_component(&ptScene->tComponentLibrary, PL_COMPONENT_TYPE_MESH, ptScene->sbtOpaqueDrawables[i].tEntity); - gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, 0.02f); + gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 0.0f, 0.0f), .fThickness = 0.02f}); } for(uint32_t i = 0; i < uTransparentDrawableCount; i++) { plMeshComponent* ptMesh = gptECS->get_component(&ptScene->tComponentLibrary, PL_COMPONENT_TYPE_MESH, ptScene->sbtTransparentDrawables[i].tEntity); - gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, 0.02f); + gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 0.0f, 0.0f), .fThickness = 0.02f}); } } else if(gptData->bDrawVisibleBoundingBoxes) @@ -4172,25 +4172,31 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions { plMeshComponent* ptMesh = gptECS->get_component(&ptScene->tComponentLibrary, PL_COMPONENT_TYPE_MESH, ptView->sbtVisibleOpaqueDrawables[i].tEntity); - gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, 0.02f); + gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 0.0f, 0.0f), .fThickness = 0.02f}); } for(uint32_t i = 0; i < uVisibleTransparentDrawCount; i++) { plMeshComponent* ptMesh = gptECS->get_component(&ptScene->tComponentLibrary, PL_COMPONENT_TYPE_MESH, ptView->sbtVisibleTransparentDrawables[i].tEntity); - gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, 0.02f); + gptDraw->add_3d_aabb(ptView->pt3DDrawList, ptMesh->tAABBFinal.tMin, ptMesh->tAABBFinal.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 0.0f, 0.0f), .fThickness = 0.02f}); } } if(gptData->bShowOrigin) { const plMat4 tTransform = pl_identity_mat4(); - gptDraw->add_3d_transform(ptView->pt3DDrawList, &tTransform, 10.0f, 0.02f); + gptDraw->add_3d_transform(ptView->pt3DDrawList, &tTransform, 10.0f, (plDrawLineOptions){.fThickness = 0.02f}); } if(ptCullCamera && ptCullCamera != ptCamera) { - gptDraw->add_3d_frustum(ptView->pt3DSelectionDrawList, &ptCullCamera->tTransformMat, ptCullCamera->fFieldOfView, ptCullCamera->fAspectRatio, ptCullCamera->fNearZ, ptCullCamera->fFarZ, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 0.02f); + plDrawFrustumDesc tFrustumDesc = { + .fAspectRatio = ptCullCamera->fAspectRatio, + .fFarZ = ptCullCamera->fFarZ, + .fNearZ = ptCullCamera->fNearZ, + .fYFov = ptCullCamera->fFieldOfView + }; + gptDraw->add_3d_frustum(ptView->pt3DSelectionDrawList, &ptCullCamera->tTransformMat, tFrustumDesc, (plDrawLineOptions){.uColor = PL_COLOR_32_YELLOW, .fThickness = 0.02f}); } gptDrawBackend->submit_3d_drawlist(ptView->pt3DDrawList, tEncoder, tDimensions.x, tDimensions.y, &tMVP, PL_DRAW_FLAG_DEPTH_TEST | PL_DRAW_FLAG_DEPTH_WRITE, 1); @@ -4688,7 +4694,7 @@ pl_add_drawable_objects_to_scene(uint32_t uSceneHandle, uint32_t uOpaqueCount, c static void pl_show_graphics_options(const char* pcTitle) { - if(gptUI->collapsing_header(pcTitle)) + if(gptUI->begin_collapsing_header(pcTitle)) { // if(gptUI->checkbox("VSync", &gptData->ptSwap->bVSync)) // gptData->bReloadSwapchain = true; diff --git a/extensions/pl_ui_core.c b/extensions/pl_ui_core.c index 5ca8c7c2..986a9df8 100644 --- a/extensions/pl_ui_core.c +++ b/extensions/pl_ui_core.c @@ -640,9 +640,9 @@ pl_end_tooltip(void) ptWindow->tSize.x = ptWindow->tContentSize.x + gptCtx->tStyle.fWindowHorizontalPadding; ptWindow->tSize.y = ptWindow->tContentSize.y; - gptDraw->add_rect_filled(ptWindow->ptBgLayer, + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, ptWindow->tPos, - pl_add_vec2(ptWindow->tPos, ptWindow->tSize), gptCtx->tColorScheme.tWindowBgColor, 0.0f, 0); + pl_add_vec2(ptWindow->tPos, ptWindow->tSize), 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tWindowBgColor)}); gptDraw->pop_clip_rect(gptCtx->ptDrawlist); gptCtx->ptCurrentWindow = ptWindow->ptParentWindow; @@ -1275,24 +1275,37 @@ pl_is_item_hoverable_circle(plVec2 tP, float fRadius, uint32_t uHash) } static void -pl__add_text(plDrawLayer2D* ptLayer, plFont* ptFont, float fSize, plVec2 tP, plVec4 tColor, const char* pcText, float fWrap) +pl__add_text(plDrawLayer2D* ptLayer, plFont* ptFont, float fSize, plVec2 tP, uint32_t uColor, const char* pcText, float fWrap) { const char* pcTextEnd = pcText + strlen(pcText); - gptDraw->add_text_ex(ptLayer, ptFont, fSize, (plVec2){roundf(tP.x), roundf(tP.y)}, tColor, pcText, pl__find_renderered_text_end(pcText, pcTextEnd), fWrap); + gptDraw->add_text(ptLayer, (plVec2){roundf(tP.x), roundf(tP.y)}, pcText, (plDrawTextOptions){ + .fSize = fSize, + .fWrap = fWrap, + .pcTextEnd = pl__find_renderered_text_end(pcText, pcTextEnd), + .ptFont = ptFont, + .uColor = uColor + }); } static void -pl__add_clipped_text(plDrawLayer2D* ptLayer, plFont* ptFont, float fSize, plVec2 tP, plVec2 tMin, plVec2 tMax, plVec4 tColor, const char* pcText, float fWrap) +pl__add_clipped_text(plDrawLayer2D* ptLayer, plFont* ptFont, float fSize, plVec2 tP, plVec2 tMin, plVec2 tMax, uint32_t uColor, const char* pcText, float fWrap) { const char* pcTextEnd = pcText + strlen(pcText); - gptDraw->add_text_clipped_ex(ptLayer, ptFont, fSize, (plVec2){roundf(tP.x + 0.5f), roundf(tP.y + 0.5f)}, tMin, tMax, tColor, pcText, pl__find_renderered_text_end(pcText, pcTextEnd), fWrap); + gptDraw->add_text_clipped(ptLayer, (plVec2){roundf(tP.x + 0.5f), roundf(tP.y + 0.5f)}, pcText, tMin, tMax, + (plDrawTextOptions){ + .fSize = fSize, + .fWrap = fWrap, + .pcTextEnd = pl__find_renderered_text_end(pcText, pcTextEnd), + .ptFont = ptFont, + .uColor = uColor + }); } static plVec2 pl__calculate_text_size(plFont* ptFont, float size, const char* text, float wrap) { const char* pcTextEnd = text + strlen(text); - return gptDraw->calculate_text_size_ex(ptFont, size, text, pl__find_renderered_text_end(text, pcTextEnd), wrap); + return gptDraw->calculate_text_size(text, (plDrawTextOptions){.ptFont = ptFont, .fSize = size, .pcTextEnd = pl__find_renderered_text_end(text, pcTextEnd), .fWrap = wrap}); } static plUiStorageEntry* @@ -1536,11 +1549,11 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) tTitleColor = gptCtx->tColorScheme.tTitleBgCollapsedCol; else tTitleColor = gptCtx->tColorScheme.tTitleBgCol; - gptDraw->add_rect_filled_ex(ptWindow->ptFgLayer, tStartPos, pl_add_vec2(tStartPos, (plVec2){ptWindow->tSize.x, fTitleBarHeight}), tTitleColor, gptCtx->tStyle.fWindowRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, pl_add_vec2(tStartPos, (plVec2){ptWindow->tSize.x, fTitleBarHeight}), gptCtx->tStyle.fWindowRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tTitleColor)}); // draw title text const plVec2 titlePos = pl_add_vec2(tStartPos, (plVec2){ptWindow->tSize.x / 2.0f - tTextSize.x / 2.0f, gptCtx->tStyle.fTitlePadding}); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, titlePos, gptCtx->tColorScheme.tTextCol, pcName, 0.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, titlePos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcName, 0.0f); // draw close button const float fTitleBarButtonRadius = 8.0f; @@ -1557,9 +1570,9 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) bool bHeld = false; bool bPressed = pl__button_behavior(&tBoundingBox, uCloseHash, &bHovered, &bHeld); - if(gptCtx->uActiveId == uCloseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, 12); - else if(gptCtx->uHoveredId == uCloseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, 12); - else gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, (plVec4){0.5f, 0.0f, 0.0f, 1.0f}, 12); + if(gptCtx->uActiveId == uCloseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 0.0f, 1.0f)}); + else if(gptCtx->uHoveredId == uCloseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 0.0f, 1.0f)}); + else gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(0.5f, 0.0f, 0.0f, 1.0f)}); if(bPressed) *pbOpen = false; @@ -1577,9 +1590,9 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) bool bHeld = false; bool bPressed = pl__button_behavior(&tBoundingBox, uCollapseHash, &bHovered, &bHeld); - if(gptCtx->uActiveId == uCollapseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 12); - else if(gptCtx->uHoveredId == uCollapseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 12); - else gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, (plVec4){0.5f, 0.5f, 0.0f, 1.0f}, 12); + if(gptCtx->uActiveId == uCollapseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 1.0f)}); + else if(gptCtx->uHoveredId == uCollapseHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 1.0f)}); + else gptDraw->add_circle_filled(ptWindow->ptFgLayer, tCloseCenterPos, fTitleBarButtonRadius, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(0.5f, 0.5f, 0.0f, 1.0f)}); if(bPressed) { @@ -1636,7 +1649,7 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) ptWindow->tOuterRectClipped = ptWindow->tOuterRect; // draw background - gptDraw->add_rect_filled_ex(ptWindow->ptBgLayer, tBgRect.tMin, tBgRect.tMax, gptCtx->tColorScheme.tWindowBgColor, gptCtx->tStyle.fWindowRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tBgRect.tMin, tBgRect.tMax, gptCtx->tStyle.fWindowRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tWindowBgColor)}); ptWindow->tFullSize = ptWindow->tSize; } @@ -1668,8 +1681,8 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) // draw border if(!(tFlags & PL_UI_WINDOW_FLAGS_NO_BACKGROUND)) { - gptDraw->add_rect(ptWindow->ptFgLayer, ptWindow->tOuterRect.tMin, ptWindow->tOuterRect.tMax, gptCtx->tColorScheme.tWindowBorderColor, 1.0f, gptCtx->tStyle.fWindowRounding, 0); - gptDraw->add_rect_filled_ex(ptWindow->ptBgLayer, tBgRect.tMin, tBgRect.tMax, gptCtx->tColorScheme.tWindowBgColor, gptCtx->tStyle.fWindowRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM); + gptDraw->add_rect_rounded(ptWindow->ptFgLayer, ptWindow->tOuterRect.tMin, ptWindow->tOuterRect.tMax, gptCtx->tStyle.fWindowRounding, 0, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tWindowBorderColor)}); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tBgRect.tMin, tBgRect.tMax, gptCtx->tStyle.fWindowRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_BOTTOM, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tWindowBgColor)}); } // vertical scroll bar @@ -1699,17 +1712,17 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) if(gptCtx->uActiveId == uResizeHash) { - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, tBottomRight, tCornerTopPos, tCornerLeftPos, (plVec4){0.99f, 0.02f, 0.10f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, tBottomRight, tCornerTopPos, tCornerLeftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGB(0.99f, 0.02f, 0.10f)}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_NWSE); } else if(gptCtx->uHoveredId == uResizeHash) { - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, tBottomRight, tCornerTopPos, tCornerLeftPos, (plVec4){0.66f, 0.02f, 0.10f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, tBottomRight, tCornerTopPos, tCornerLeftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGB(0.66f, 0.02f, 0.10f)}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_NWSE); } else { - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, tBottomRight, tCornerTopPos, tCornerLeftPos, (plVec4){0.33f, 0.02f, 0.10f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, tBottomRight, tCornerTopPos, tCornerLeftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGB(0.33f, 0.02f, 0.10f)}); } } @@ -1725,12 +1738,12 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) if(gptCtx->uActiveId == uEastResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopRight.x, tTopRight.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomRight.x, tBottomRight.y - gptCtx->tStyle.fWindowRounding}, (plVec4){0.99f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopRight.x, tTopRight.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomRight.x, tBottomRight.y - gptCtx->tStyle.fWindowRounding}, (plDrawLineOptions){.fThickness = 2.0f, .uColor = PL_COLOR_32_RGB(0.99f, 0.02f, 0.10f)}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_EW); } else if(gptCtx->uHoveredId == uEastResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopRight.x, tTopRight.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomRight.x, tBottomRight.y - gptCtx->tStyle.fWindowRounding}, (plVec4){0.66f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopRight.x, tTopRight.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomRight.x, tBottomRight.y - gptCtx->tStyle.fWindowRounding}, (plDrawLineOptions){.fThickness = 2.0f, .uColor = PL_COLOR_32_RGB(0.66f, 0.02f, 0.10f)}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_EW); } } @@ -1746,12 +1759,12 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) if(gptCtx->uActiveId == uWestResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x, tTopLeft.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomLeft.x, tBottomLeft.y - gptCtx->tStyle.fWindowRounding}, (plVec4){0.99f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x, tTopLeft.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomLeft.x, tBottomLeft.y - gptCtx->tStyle.fWindowRounding}, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.99f, 0.02f, 0.10f), .fThickness = 2.0f}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_EW); } else if(gptCtx->uHoveredId == uWestResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x, tTopLeft.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomLeft.x, tBottomLeft.y - gptCtx->tStyle.fWindowRounding}, (plVec4){0.66f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x, tTopLeft.y + gptCtx->tStyle.fWindowRounding}, (plVec2){tBottomLeft.x, tBottomLeft.y - gptCtx->tStyle.fWindowRounding}, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.66f, 0.02f, 0.10f), .fThickness = 2.0f}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_EW); } } @@ -1767,12 +1780,12 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) if(gptCtx->uActiveId == uNorthResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x + gptCtx->tStyle.fWindowRounding, tTopLeft.y}, (plVec2){tTopRight.x - gptCtx->tStyle.fWindowRounding, tTopRight.y}, (plVec4){0.99f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x + gptCtx->tStyle.fWindowRounding, tTopLeft.y}, (plVec2){tTopRight.x - gptCtx->tStyle.fWindowRounding, tTopRight.y}, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.99f, 0.02f, 0.10f), .fThickness = 2.0f}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_NS); } else if(gptCtx->uHoveredId == uNorthResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x + gptCtx->tStyle.fWindowRounding, tTopLeft.y}, (plVec2){tTopRight.x - gptCtx->tStyle.fWindowRounding, tTopRight.y}, (plVec4){0.66f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTopLeft.x + gptCtx->tStyle.fWindowRounding, tTopLeft.y}, (plVec2){tTopRight.x - gptCtx->tStyle.fWindowRounding, tTopRight.y}, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.66f, 0.02f, 0.10f), .fThickness = 2.0f}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_NS); } } @@ -1788,12 +1801,12 @@ pl__begin_window_ex(const char* pcName, bool* pbOpen, plUiWindowFlags tFlags) if(gptCtx->uActiveId == uSouthResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tBottomLeft.x + gptCtx->tStyle.fWindowRounding, tBottomLeft.y}, (plVec2){tBottomRight.x - gptCtx->tStyle.fWindowRounding, tBottomRight.y}, (plVec4){0.99f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tBottomLeft.x + gptCtx->tStyle.fWindowRounding, tBottomLeft.y}, (plVec2){tBottomRight.x - gptCtx->tStyle.fWindowRounding, tBottomRight.y}, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.99f, 0.02f, 0.10f), .fThickness = 2.0f}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_NS); } else if(gptCtx->uHoveredId == uSouthResizeHash) { - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tBottomLeft.x + gptCtx->tStyle.fWindowRounding, tBottomLeft.y}, (plVec2){tBottomRight.x - gptCtx->tStyle.fWindowRounding, tBottomRight.y}, (plVec4){0.66f, 0.02f, 0.10f, 1.0f}, 2.0f); + gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tBottomLeft.x + gptCtx->tStyle.fWindowRounding, tBottomLeft.y}, (plVec2){tBottomRight.x - gptCtx->tStyle.fWindowRounding, tBottomRight.y}, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.66f, 0.02f, 0.10f), .fThickness = 2.0f}); gptIOI->set_mouse_cursor(PL_MOUSE_CURSOR_RESIZE_NS); } } @@ -1940,17 +1953,17 @@ pl__render_scrollbar(plUiWindow* ptWindow, uint32_t uHash, plUiAxis tAxis) tScrollBackground = pl_rect_clip(&tScrollBackground, &ptWindow->tOuterRectClipped); tHandleBox = pl_rect_clip(&tHandleBox, &ptWindow->tOuterRectClipped); - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tScrollBackground.tMin, tScrollBackground.tMax, gptCtx->tColorScheme.tScrollbarBgCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tScrollBackground.tMin, tScrollBackground.tMax, gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarBgCol)}); bool bHovered = false; bool bHeld = false; const bool bPressed = pl__button_behavior(&tHandleBox, uHash, &bHovered, &bHeld); if(gptCtx->uActiveId == uHash) - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tStartPos, pl_add_vec2(tStartPos, tFinalSize), gptCtx->tColorScheme.tScrollbarActiveCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tStartPos, pl_add_vec2(tStartPos, tFinalSize), gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarActiveCol)}); else if(gptCtx->uHoveredId == uHash) - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tStartPos, pl_add_vec2(tStartPos, tFinalSize), gptCtx->tColorScheme.tScrollbarHoveredCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tStartPos, pl_add_vec2(tStartPos, tFinalSize), gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarHoveredCol)}); else - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tStartPos, pl_add_vec2(tStartPos, tFinalSize), gptCtx->tColorScheme.tScrollbarHandleCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tStartPos, pl_add_vec2(tStartPos, tFinalSize), gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarHandleCol)}); } } else if(tAxis == PL_UI_AXIS_Y) @@ -1980,7 +1993,7 @@ pl__render_scrollbar(plUiWindow* ptWindow, uint32_t uHash, plUiAxis tAxis) tHandleBox = pl_rect_clip(&tHandleBox, &ptWindow->tOuterRectClipped); // scrollbar background - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tScrollBackground.tMin, tScrollBackground.tMax, gptCtx->tColorScheme.tScrollbarBgCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tScrollBackground.tMin, tScrollBackground.tMax, gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarBgCol)}); bool bHovered = false; bool bHeld = false; @@ -1988,11 +2001,11 @@ pl__render_scrollbar(plUiWindow* ptWindow, uint32_t uHash, plUiAxis tAxis) // scrollbar handle if(gptCtx->uActiveId == uHash) - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tHandleBox.tMin, tHandleBox.tMax, gptCtx->tColorScheme.tScrollbarActiveCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tHandleBox.tMin, tHandleBox.tMax, gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarActiveCol)}); else if(gptCtx->uHoveredId == uHash) - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tHandleBox.tMin, tHandleBox.tMax, gptCtx->tColorScheme.tScrollbarHoveredCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tHandleBox.tMin, tHandleBox.tMax, gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarHoveredCol)}); else - gptDraw->add_rect_filled(ptWindow->ptBgLayer, tHandleBox.tMin, tHandleBox.tMax, gptCtx->tColorScheme.tScrollbarHandleCol, gptCtx->tStyle.fScrollbarRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptBgLayer, tHandleBox.tMin, tHandleBox.tMax, gptCtx->tStyle.fScrollbarRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tScrollbarHandleCol)}); } } diff --git a/extensions/pl_ui_demo.c b/extensions/pl_ui_demo.c index f0c0b2d4..96bb0331 100644 --- a/extensions/pl_ui_demo.c +++ b/extensions/pl_ui_demo.c @@ -29,16 +29,16 @@ pl_show_debug_window(bool* pbOpen) if(ptWindow->bActive) { if(bShowWindowInnerRect) - gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tInnerRect.tMin, ptWindow->tInnerRect.tMax, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 1.0f, 0.0f, 0); + gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tInnerRect.tMin, ptWindow->tInnerRect.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 1.0f, 0.0f), .fThickness = 1.0f}); if(bShowWindowInnerClipRect) - gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tInnerClipRect.tMin, ptWindow->tInnerClipRect.tMax, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 1.0f, 0.0f, 0); + gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tInnerClipRect.tMin, ptWindow->tInnerClipRect.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 1.0f, 0.0f), .fThickness = 1.0f}); if(bShowWindowOuterRect) - gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tOuterRect.tMin, ptWindow->tOuterRect.tMax, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 1.0f, 0.0f, 0); + gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tOuterRect.tMin, ptWindow->tOuterRect.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 1.0f, 0.0f), .fThickness = 1.0f}); if(bShowWindowOuterClippedRect) - gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tOuterRectClipped.tMin, ptWindow->tOuterRectClipped.tMax, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 1.0f, 0.0f, 0); + gptDraw->add_rect(gptCtx->ptDebugLayer, ptWindow->tOuterRectClipped.tMin, ptWindow->tOuterRectClipped.tMax, (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 1.0f, 0.0f), .fThickness = 1.0f}); } } diff --git a/extensions/pl_ui_ext.c b/extensions/pl_ui_ext.c index 26dd3919..c3e35c46 100644 --- a/extensions/pl_ui_ext.c +++ b/extensions/pl_ui_ext.c @@ -87,7 +87,7 @@ pl_load_ui_api(void) .slider_int_f = pl_slider_int_f, .drag_float = pl_drag_float, .drag_float_f = pl_drag_float_f, - .collapsing_header = pl_collapsing_header, + .begin_collapsing_header = pl_collapsing_header, .end_collapsing_header = pl_end_collapsing_header, .tree_node = pl_tree_node, .tree_node_f = pl_tree_node_f, diff --git a/extensions/pl_ui_ext.h b/extensions/pl_ui_ext.h index 595c57fa..089ce88c 100644 --- a/extensions/pl_ui_ext.h +++ b/extensions/pl_ui_ext.h @@ -204,7 +204,7 @@ typedef struct _plUiI // trees // - only call "pl_tree_pop()" if "pl_tree_node()" returns true (its call automatically if false) // - only call "pl_end_collapsing_header()" if "pl_collapsing_header()" returns true (its call automatically if false) - bool (*collapsing_header) (const char* pcText); + bool (*begin_collapsing_header) (const char* pcText); void (*end_collapsing_header)(void); bool (*tree_node) (const char* pcText); bool (*tree_node_f) (const char* pcFmt, ...); diff --git a/extensions/pl_ui_internal.h b/extensions/pl_ui_internal.h index 6fd07c2b..0e821f26 100644 --- a/extensions/pl_ui_internal.h +++ b/extensions/pl_ui_internal.h @@ -497,8 +497,8 @@ typedef struct _plUiContext //----------------------------------------------------------------------------- static const char* pl__find_renderered_text_end(const char* pcText, const char* pcTextEnd); -static void pl__add_text (plDrawLayer2D*, plFont*, float fSize, plVec2 tP, plVec4 tColor, const char* pcText, float fWrap); -static void pl__add_clipped_text (plDrawLayer2D*, plFont*, float fSize, plVec2 tP, plVec2 tMin, plVec2 tMax, plVec4 tColor, const char* pcText, float fWrap); +static void pl__add_text (plDrawLayer2D*, plFont*, float fSize, plVec2 tP, uint32_t uColor, const char* pcText, float fWrap); +static void pl__add_clipped_text (plDrawLayer2D*, plFont*, float fSize, plVec2 tP, plVec2 tMin, plVec2 tMax, uint32_t uColor, const char* pcText, float fWrap); static plVec2 pl__calculate_text_size (plFont*, float size, const char* text, float wrap); static inline float pl__get_frame_height (void) { return gptCtx->tStyle.fFontSize + gptCtx->tStyle.tFramePadding.y * 2.0f; } diff --git a/extensions/pl_ui_widgets.c b/extensions/pl_ui_widgets.c index 3b5778eb..1becea1e 100644 --- a/extensions/pl_ui_widgets.c +++ b/extensions/pl_ui_widgets.c @@ -33,7 +33,7 @@ pl__input_text_calc_text_size_w(const plUiWChar* text_begin, const plUiWChar* te if (c == '\r') continue; - const float char_width = font->sbtGlyphs[font->_auCodePoints[(plUiWChar)c]].xAdvance * scale; + const float char_width = font->_sbtGlyphs[font->_auCodePoints[(plUiWChar)c]].xAdvance * scale; line_width += char_width; } @@ -72,7 +72,7 @@ STB_TEXTEDIT_GETWIDTH(plUiInputTextState* obj, int line_start_idx, int char_idx) if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; plFont* font = gptCtx->tFont; - return font->sbtGlyphs[font->_auCodePoints[c]].xAdvance * (gptCtx->tStyle.fFontSize / font->fSize); + return font->_sbtGlyphs[font->_auCodePoints[c]].xAdvance * (gptCtx->tStyle.fFontSize / font->fSize); } static int @@ -515,12 +515,18 @@ pl_button(const char* pcText) bool bHeld = false; bPressed = pl__button_behavior(&tBoundingBox, uHash, &bHovered, &bHeld); - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonActiveCol, gptCtx->tStyle.fFrameRounding, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonHoveredCol, gptCtx->tStyle.fFrameRounding, 0); - else gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonCol, gptCtx->tStyle.fFrameRounding, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonHoveredCol)}); + else gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonCol)}); const plVec2 tTextSize = pl__calculate_text_size(gptCtx->tFont, gptCtx->tStyle.fFontSize, pcText, -1.0f); - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + const plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f + }); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); plVec2 tTextStartPos = { @@ -533,7 +539,7 @@ pl_button(const char* pcText) else // not clipping, so center on widget tTextStartPos.x += tStartPos.x + tWidgetSize.x / 2.0f - tTextActualCenter.x; - pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, tBoundingBox.tMin, tBoundingBox.tMax, gptCtx->tColorScheme.tTextCol, pcText, 0.0f); + pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, tBoundingBox.tMin, tBoundingBox.tMax, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, 0.0f); pl__add_widget(uHash); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); @@ -558,7 +564,12 @@ pl_selectable(const char* pcText, bool* bpValue) { const uint32_t uHash = pl_str_hash(pcText, 0, pl_sb_top(gptCtx->sbuIdStack)); - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tTextStartPos = { @@ -579,13 +590,13 @@ pl_selectable(const char* pcText, bool* bpValue) if(bPressed) *bpValue = !*bpValue; - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderActiveCol, 0.0f, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderHoveredCol, 0.0f, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderHoveredCol)}); if(*bpValue) - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderCol, 0.0f, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderCol)}); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcText, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, -1.0f); pl__add_widget(uHash); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); @@ -605,8 +616,12 @@ pl_menu_item(const char* pcLabel, const char* pcShortcut, bool bSelected, bool b if(pl__ui_should_render(&tStartPos, &tWidgetSize)) { const uint32_t uHash = pl_str_hash(pcLabel, 0, pl_sb_top(gptCtx->sbuIdStack)); - - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tTextStartPos = { @@ -630,31 +645,31 @@ pl_menu_item(const char* pcLabel, const char* pcShortcut, bool bSelected, bool b pl_sb_reset(gptCtx->sbtOpenPopupStack); } - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderActiveCol, 0.0f, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderHoveredCol, 0.0f, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderHoveredCol)}); if(bSelected) { gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tEndPos.x - 0.333f * tWidgetSize.y, tStartPos.y + 0.25f * tWidgetSize.y}, (plVec2){tEndPos.x - 0.5f * tWidgetSize.y, tStartPos.y + 0.75f * tWidgetSize.y}, - gptCtx->tColorScheme.tCheckmarkCol, 3.0f); + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tCheckmarkCol), .fThickness = 3.0f}); gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tEndPos.x - 0.5f * tWidgetSize.y, tStartPos.y + 0.75f * tWidgetSize.y}, (plVec2){tEndPos.x - 0.666f * tWidgetSize.y, tStartPos.y + 0.5f * tWidgetSize.y}, - gptCtx->tColorScheme.tCheckmarkCol, 3.0f); + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tCheckmarkCol), .fThickness = 3.0f}); } - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); if(pcShortcut) { - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tTextStartPos.x + 0.666f * tWidgetSize.x, tTextStartPos.y}, gptCtx->tColorScheme.tTextDisabledCol, pcShortcut, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tTextStartPos.x + 0.666f * tWidgetSize.x, tTextStartPos.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextDisabledCol), pcShortcut, -1.0f); } } else { - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextDisabledCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextDisabledCol), pcLabel, -1.0f); } pl__add_widget(uHash); } @@ -680,7 +695,12 @@ pl_menu_item_toggle(const char* pcLabel, const char* pcShortcut, bool* pbSelecte { const uint32_t uHash = pl_str_hash(pcLabel, 0, pl_sb_top(gptCtx->sbuIdStack)); - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tTextStartPos = { @@ -704,31 +724,31 @@ pl_menu_item_toggle(const char* pcLabel, const char* pcShortcut, bool* pbSelecte *pbSelected = !*pbSelected; } - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderActiveCol, 0.0f, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderHoveredCol, 0.0f, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderHoveredCol)}); if(*pbSelected) { gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tEndPos.x - 0.333f * tWidgetSize.y, tStartPos.y + 0.25f * tWidgetSize.y}, (plVec2){tEndPos.x - 0.5f * tWidgetSize.y, tStartPos.y + 0.75f * tWidgetSize.y}, - gptCtx->tColorScheme.tCheckmarkCol, 3.0f); + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tCheckmarkCol), .fThickness = 3.0f}); gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tEndPos.x - 0.5f * tWidgetSize.y, tStartPos.y + 0.75f * tWidgetSize.y}, (plVec2){tEndPos.x - 0.666f * tWidgetSize.y, tStartPos.y + 0.5f * tWidgetSize.y}, - gptCtx->tColorScheme.tCheckmarkCol, 3.0f); + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tCheckmarkCol), .fThickness = 3.0f}); } - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); if(pcShortcut) { - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tTextStartPos.x + 0.666f * tWidgetSize.x, tTextStartPos.y}, gptCtx->tColorScheme.tTextDisabledCol, pcShortcut, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tTextStartPos.x + 0.666f * tWidgetSize.x, tTextStartPos.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextDisabledCol), pcShortcut, -1.0f); } } else { - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextDisabledCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextDisabledCol), pcLabel, -1.0f); } pl__add_widget(uHash); } @@ -753,7 +773,12 @@ pl_checkbox(const char* pcText, bool* bpValue) { const bool bOriginalValue = *bpValue; const uint32_t uHash = pl_str_hash(pcText, 0, pl_sb_top(gptCtx->sbuIdStack)); - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); @@ -772,18 +797,18 @@ pl_checkbox(const char* pcText, bool* bpValue) if(bPressed) *bpValue = !bOriginalValue; - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgActiveCol, gptCtx->tStyle.fFrameRounding, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgHoveredCol, gptCtx->tStyle.fFrameRounding, 0); - else gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgCol, gptCtx->tStyle.fFrameRounding, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgHoveredCol)}); + else gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgCol)}); if(*bpValue) { tBoundingBox = pl_rect_expand_vec2(&tBoundingBox, (plVec2){-5.0f, -5.0f}); - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tBoundingBox.tMin, tBoundingBox.tMax, gptCtx->tColorScheme.tCheckmarkCol, gptCtx->tStyle.fFrameRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tBoundingBox.tMin, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tCheckmarkCol)}); } // add label - pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, tStartPos, pl_add_vec2(tStartPos, tWidgetSize), gptCtx->tColorScheme.tTextCol, pcText, -1.0f); + pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, tStartPos, pl_add_vec2(tStartPos, tWidgetSize), PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, -1.0f); pl__add_widget(uHash); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); @@ -803,7 +828,12 @@ pl_radio_button(const char* pcText, int* piValue, int iButtonValue) { const uint32_t uHash = pl_str_hash(pcText, 0, pl_sb_top(gptCtx->sbuIdStack)); const plVec2 tTextSize = pl__calculate_text_size(gptCtx->tFont, gptCtx->tStyle.fFontSize, pcText, -1.0f); - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tSize = {tTextSize.x + 2.0f * gptCtx->tStyle.tFramePadding.x + gptCtx->tStyle.tInnerSpacing.x + tWidgetSize.y, tWidgetSize.y}; @@ -825,14 +855,14 @@ pl_radio_button(const char* pcText, int* piValue, int iButtonValue) if(bPressed) *piValue = iButtonValue; - if(gptCtx->uActiveId == uHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 1.5f, gptCtx->tColorScheme.tFrameBgActiveCol, 12); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 1.5f, gptCtx->tColorScheme.tFrameBgHoveredCol, 12); - else gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 1.5f, gptCtx->tColorScheme.tFrameBgCol, 12); + if(gptCtx->uActiveId == uHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 1.5f, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 1.5f, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgHoveredCol)}); + else gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 1.5f, 12, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgCol)}); if(*piValue == iButtonValue) - gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 2.5f, gptCtx->tColorScheme.tCheckmarkCol, 12); + gptDraw->add_circle_filled(ptWindow->ptFgLayer, (plVec2){tStartPos.x + tWidgetSize.y / 2.0f, tStartPos.y + tWidgetSize.y / 2.0f}, gptCtx->tStyle.fFontSize / 2.5f,12, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tCheckmarkCol)}); - pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, tStartPos, pl_add_vec2(tStartPos, tWidgetSize), gptCtx->tColorScheme.tTextCol, pcText, -1.0f); + pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, tStartPos, pl_add_vec2(tStartPos, tWidgetSize), PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, -1.0f); pl__add_widget(uHash); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); @@ -856,8 +886,19 @@ pl_begin_combo(const char* pcLabel, const char* pcPreview, plUiComboFlags tFlags { const plVec2 tFrameStartPos = {tStartPos.x, tStartPos.y }; - const plRect tPreviewTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, pcPreview, pl__find_renderered_text_end(pcPreview, NULL), -1.0f); - const plRect tLabelTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + plRect tPreviewTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, pcPreview, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcPreview, NULL), + .fWrap = -1.0f}); + + plRect tLabelTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tPreviewTextBounding); const plVec2 tLabelTextActualCenter = pl_rect_center(&tLabelTextBounding); @@ -907,24 +948,24 @@ pl_begin_combo(const char* pcLabel, const char* pcPreview, plUiComboFlags tFlags tButtonColor = gptCtx->tColorScheme.tButtonHoveredCol; } - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, tFrameColor, gptCtx->tStyle.fFrameRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tFrameColor)}); if(!(tFlags & PL_UI_COMBO_FLAGS_NO_ARROW_BUTTON)) { - gptDraw->add_rect_filled(ptWindow->ptFgLayer, (plVec2){tBoundingBox.tMax.x - 8.0f * 3.0f, tBoundingBox.tMin.y}, tBoundingBox.tMax, tButtonColor, gptCtx->tStyle.fFrameRounding, 0); - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, (plVec2){tBoundingBox.tMax.x - 8.0f * 3.0f, tBoundingBox.tMin.y}, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tButtonColor)}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_WHITE}); } - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcPreview, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcPreview, -1.0f); pl__add_widget(uHash); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); if(bPopupOpen) { - gptDraw->add_rect_filled(ptWindow->ptFgLayer, (plVec2){tBoundingBox.tMax.x - 8.0f * 3.0f, tBoundingBox.tMin.y}, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonActiveCol, gptCtx->tStyle.fFrameRounding, 0); - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, (plVec2){tBoundingBox.tMax.x - 8.0f * 3.0f, tBoundingBox.tMin.y}, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonActiveCol)}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_WHITE}); const plUiWindowFlags tWindowFlags = PL_UI_WINDOW_FLAGS_NO_TITLE_BAR | PL_UI_WINDOW_FLAGS_NO_RESIZE | @@ -978,7 +1019,12 @@ pl_begin_menu(const char* pcLabel, bool bEnabled) { const uint32_t uHash = pl_str_hash(pcLabel, 0, pl_sb_top(gptCtx->sbuIdStack)); - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tTextStartPos = { @@ -1005,25 +1051,25 @@ pl_begin_menu(const char* pcLabel, bool bEnabled) const bool bPopupOpen = pl_is_popup_open(gptCtx->sbcTempBuffer); - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderActiveCol, 0.0f, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderHoveredCol, 0.0f, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderHoveredCol)}); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); const plVec2 centerPoint = {tBoundingBox.tMax.x - 8.0f * 1.5f, tStartPos.y + tWidgetSize.y / 2.0f}; const plVec2 pointPos = pl_add_vec2(centerPoint, (plVec2){ 4.0f, 0.0f}); const plVec2 rightPos = pl_add_vec2(centerPoint, (plVec2){ -4.0f, -4.0f}); const plVec2 leftPos = pl_add_vec2(centerPoint, (plVec2){-4.0f, 4.0f}); - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_WHITE}); pl__add_widget(uHash); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); if(bPopupOpen) { - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, gptCtx->tColorScheme.tHeaderHoveredCol, 0.0f, 0); - // gptDraw->add_rect_filled(ptWindow->ptFgLayer, (plVec2){tBoundingBox.tMax.x - 8.0f * 3.0f, tBoundingBox.tMin.y}, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonActiveCol, gptCtx->tStyle.fFrameRounding, 0); - // gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tEndPos, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderHoveredCol)}); + // gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, (plVec2){tBoundingBox.tMax.x - 8.0f * 3.0f, tBoundingBox.tMin.y}, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonActiveCol, gptCtx->tStyle.fFrameRounding, 0); + // gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, PL_COLOR_32_WHITE); const plUiWindowFlags tWindowFlags = PL_UI_WINDOW_FLAGS_NO_TITLE_BAR | PL_UI_WINDOW_FLAGS_NO_RESIZE | @@ -1065,7 +1111,12 @@ pl_collapsing_header(const char* pcText) bool* pbOpenState = pl__get_bool_ptr(&ptWindow->tStorage, uHash, false); if(pl__ui_should_render(&tStartPos, &tWidgetSize)) { - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tTextStartPos = { @@ -1083,9 +1134,9 @@ pl_collapsing_header(const char* pcText) if(bPressed) *pbOpenState = !*pbOpenState; - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tHeaderActiveCol, gptCtx->tStyle.fFrameRounding, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tHeaderHoveredCol, gptCtx->tStyle.fFrameRounding, 0); - else gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tHeaderCol, gptCtx->tStyle.fFrameRounding, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderHoveredCol)}); + else gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderCol)}); if(*pbOpenState) { @@ -1093,7 +1144,7 @@ pl_collapsing_header(const char* pcText) const plVec2 pointPos = pl_add_vec2(centerPoint, (plVec2){ 0.0f, 4.0f}); const plVec2 rightPos = pl_add_vec2(centerPoint, (plVec2){ 4.0f, -4.0f}); const plVec2 leftPos = pl_add_vec2(centerPoint, (plVec2){-4.0f, -4.0f}); - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_WHITE}); } else { @@ -1101,10 +1152,10 @@ pl_collapsing_header(const char* pcText) const plVec2 pointPos = pl_add_vec2(centerPoint, (plVec2){ 4.0f, 0.0f}); const plVec2 rightPos = pl_add_vec2(centerPoint, (plVec2){ -4.0f, -4.0f}); const plVec2 leftPos = pl_add_vec2(centerPoint, (plVec2){ -4.0f, 4.0f}); - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_WHITE}); } - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcText, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, -1.0f); } if(*pbOpenState) pl_sb_push(ptWindow->sbtRowStack, ptWindow->tTempData.tCurrentLayoutRow); @@ -1136,7 +1187,12 @@ pl_tree_node(const char* pcText) if(pl__ui_should_render(&tStartPos, &tWidgetSize)) { - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); plRect tBoundingBox = pl_calculate_rect(tStartPos, tWidgetSize); @@ -1149,8 +1205,8 @@ pl_tree_node(const char* pcText) if(bPressed) *pbOpenState = !*pbOpenState; - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tHeaderActiveCol, 0.0f, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tHeaderHoveredCol, 0.0f, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tHeaderHoveredCol)}); if(*pbOpenState) { @@ -1158,7 +1214,7 @@ pl_tree_node(const char* pcText) const plVec2 pointPos = pl_add_vec2(centerPoint, (plVec2){ 0.0f, 4.0f}); const plVec2 rightPos = pl_add_vec2(centerPoint, (plVec2){ 4.0f, -4.0f}); const plVec2 leftPos = pl_add_vec2(centerPoint, (plVec2){-4.0f, -4.0f}); - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_WHITE}); } else { @@ -1166,14 +1222,14 @@ pl_tree_node(const char* pcText) const plVec2 pointPos = pl_add_vec2(centerPoint, (plVec2){ 4.0f, 0.0f}); const plVec2 rightPos = pl_add_vec2(centerPoint, (plVec2){ -4.0f, -4.0f}); const plVec2 leftPos = pl_add_vec2(centerPoint, (plVec2){ -4.0f, 4.0f}); - gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}); + gptDraw->add_triangle_filled(ptWindow->ptFgLayer, pointPos, rightPos, leftPos, (plDrawSolidOptions){.uColor = PL_COLOR_32_WHITE}); } const plVec2 tTextStartPos = { .x = tStartPos.x + tWidgetSize.y * 1.5f, .y = tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y }; - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcText, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, -1.0f); } pl__add_widget(uHash); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); @@ -1281,7 +1337,7 @@ pl_begin_tab_bar(const char* pcText) gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){gptCtx->ptCurrentTabBar->tStartPos.x, gptCtx->ptCurrentTabBar->tStartPos.y + fFrameHeight}, (plVec2){gptCtx->ptCurrentTabBar->tStartPos.x + tWidgetSize.x, gptCtx->ptCurrentTabBar->tStartPos.y + fFrameHeight}, - gptCtx->tColorScheme.tButtonActiveCol, 1.0f); + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonActiveCol), .fThickness = 1.0f}); pl__add_widget(uHash); pl__advance_cursor(tWidgetSize.x, fFrameHeight); @@ -1358,7 +1414,12 @@ pl_begin_tab(const char* pcText) const plVec2 tTextSize = pl__calculate_text_size(gptCtx->tFont, gptCtx->tStyle.fFontSize, pcText, -1.0f); const plVec2 tStartPos = ptTabBar->tCursorPos; - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tFinalSize = {tTextSize.x + 2.0f * gptCtx->tStyle.tFramePadding.x, fFrameHeight}; @@ -1378,12 +1439,12 @@ pl_begin_tab(const char* pcText) ptTabBar->uNextValue = uHash; } - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled_ex(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonActiveCol, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled_ex(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonHoveredCol, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP); - else if(ptTabBar->uValue == uHash) gptDraw->add_rect_filled_ex(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonActiveCol, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP); - else gptDraw->add_rect_filled_ex(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tButtonCol, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonHoveredCol)}); + else if(ptTabBar->uValue == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonActiveCol)}); + else gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, tBoundingBox.tMax, gptCtx->tStyle.fTabRounding, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonCol)}); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcText, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, -1.0f); ptTabBar->tCursorPos.x += gptCtx->tStyle.tInnerSpacing.x + tFinalSize.x; ptTabBar->uCurrentIndex++; @@ -1403,7 +1464,12 @@ pl_separator(void) const plVec2 tStartPos = pl__get_cursor_pos(); const plVec2 tWidgetSize = pl__calculate_item_size(gptCtx->tStyle.tItemSpacing.y * 2.0f); if(pl__ui_should_render(&tStartPos, &tWidgetSize)) - gptDraw->add_line(ptWindow->ptFgLayer, tStartPos, (plVec2){tStartPos.x + tWidgetSize.x, tStartPos.y}, gptCtx->tColorScheme.tSeparatorCol, 1.0f); + { + gptDraw->add_line(ptWindow->ptFgLayer, + tStartPos, + (plVec2){tStartPos.x + tWidgetSize.x, tStartPos.y}, + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tSeparatorCol), .fThickness = 1.0f}); + } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); } @@ -1418,7 +1484,12 @@ pl_separator_text(const char* pcText) const plVec2 tWidgetSize = pl__calculate_item_size(gptCtx->tStyle.fFontSize + gptCtx->tStyle.tSeparatorTextPadding.y * 2.0f); if(pl__ui_should_render(&tStartPos, &tWidgetSize)) { - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcText, pl__find_renderered_text_end(pcText, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcText, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcText, NULL), + .fWrap = -1.0f}); const float fTextWidth = pl_rect_width(&tTextBounding); const float fTextHeight = pl_rect_height(&tTextBounding); // const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); @@ -1432,9 +1503,15 @@ pl_separator_text(const char* pcText) const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tTextBounding.tMin.x, tTextBounding.tMin.y}, gptCtx->tColorScheme.tTextCol, pcText, -1.0f); - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tStartPos.x, tTextActualCenter.y}, (plVec2){tTextBounding.tMin.x - gptCtx->tStyle.tItemSpacing.x + 1.0f, tTextActualCenter.y}, gptCtx->tColorScheme.tSeparatorCol, gptCtx->tStyle.fSeparatorTextLineSize); - gptDraw->add_line(ptWindow->ptFgLayer, (plVec2){tTextBounding.tMax.x + gptCtx->tStyle.tItemSpacing.x, tTextActualCenter.y}, (plVec2){tStartPos.x + tWidgetSize.x, tTextActualCenter.y}, gptCtx->tColorScheme.tSeparatorCol, gptCtx->tStyle.fSeparatorTextLineSize); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tTextBounding.tMin.x, tTextBounding.tMin.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcText, -1.0f); + gptDraw->add_line(ptWindow->ptFgLayer, + (plVec2){tStartPos.x, tTextActualCenter.y}, + (plVec2){tTextBounding.tMin.x - gptCtx->tStyle.tItemSpacing.x + 1.0f, tTextActualCenter.y}, + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tSeparatorCol), .fThickness = gptCtx->tStyle.fSeparatorTextLineSize}); + gptDraw->add_line(ptWindow->ptFgLayer, + (plVec2){tTextBounding.tMax.x + gptCtx->tStyle.tItemSpacing.x, tTextActualCenter.y}, + (plVec2){tStartPos.x + tWidgetSize.x, tTextActualCenter.y}, + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tSeparatorCol), .fThickness = gptCtx->tStyle.fSeparatorTextLineSize}); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); @@ -1478,9 +1555,14 @@ pl_text_v(const char* pcFmt, va_list args) if(pl__ui_should_render(&tStartPos, &tWidgetSize)) { pl_vsprintf(acTempBuffer, pcFmt, args); - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, acTempBuffer, pl__find_renderered_text_end(acTempBuffer, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, acTempBuffer, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(acTempBuffer, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, acTempBuffer, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), acTempBuffer, -1.0f); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); } @@ -1505,9 +1587,14 @@ pl_color_text_v(plVec4 tColor, const char* pcFmt, va_list args) if(pl__ui_should_render(&tStartPos, &tWidgetSize)) { pl_vsprintf(acTempBuffer, pcFmt, args); - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, acTempBuffer, pl__find_renderered_text_end(acTempBuffer, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, acTempBuffer, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(acTempBuffer, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, tColor, acTempBuffer, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(tColor), acTempBuffer, -1.0f); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); } @@ -1531,12 +1618,17 @@ pl_labeled_text_v(const char* pcLabel, const char* pcFmt, va_list args) if(pl__ui_should_render(&tStartPos, &tWidgetSize)) { pl_vsprintf(acTempBuffer, pcFmt, args); - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, acTempBuffer, pl__find_renderered_text_end(acTempBuffer, NULL), -1.0f); + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, acTempBuffer, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(acTempBuffer, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tStartLocation = {tStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}; - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartLocation, gptCtx->tColorScheme.tTextCol, acTempBuffer, -1.0f); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, pl_add_vec2(tStartLocation, (plVec2){(2.0f * tWidgetSize.x / 3.0f), 0.0f}), gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartLocation, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), acTempBuffer, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, pl_add_vec2(tStartLocation, (plVec2){(2.0f * tWidgetSize.x / 3.0f), 0.0f}), PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); } pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); } @@ -1615,9 +1707,14 @@ pl_input_float2(const char* pcLabel, float* afValue, const char* pcFormat) tSubStartPos.x += fActualSubWidth; } - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tSubStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + const plRect tTextBounding = gptDraw->calculate_text_bb(tSubStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); pl_pop_id(); return bChanged; @@ -1649,9 +1746,14 @@ pl_input_float3(const char* pcLabel, float* afValue, const char* pcFormat) tSubStartPos.x += fActualSubWidth; } - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tSubStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + const plRect tTextBounding = gptDraw->calculate_text_bb(tSubStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); pl_pop_id(); return bChanged; @@ -1683,9 +1785,14 @@ pl_input_float4(const char* pcLabel, float* afValue, const char* pcFormat) tSubStartPos.x += fActualSubWidth; } - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tSubStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + const plRect tTextBounding = gptDraw->calculate_text_bb(tSubStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); pl_pop_id(); return bChanged; @@ -1735,9 +1842,14 @@ pl_input_int2(const char* pcLabel, int* aiValue) tSubStartPos.x += fActualSubWidth; } - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tSubStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + const plRect tTextBounding = gptDraw->calculate_text_bb(tSubStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); pl_pop_id(); return bChanged; @@ -1769,9 +1881,14 @@ pl_input_int3(const char* pcLabel, int* aiValue) tSubStartPos.x += fActualSubWidth; } - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tSubStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + const plRect tTextBounding = gptDraw->calculate_text_bb(tSubStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); pl_pop_id(); return bChanged; @@ -1803,9 +1920,14 @@ pl_input_int4(const char* pcLabel, int* aiValue) tSubStartPos.x += fActualSubWidth; } - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tSubStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + const plRect tTextBounding = gptDraw->calculate_text_bb(tSubStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tSubStartPos.x, tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); pl__advance_cursor(tWidgetSize.x, tWidgetSize.y); pl_pop_id(); return bChanged; @@ -1828,7 +1950,12 @@ pl__input_text_ex(const char* pcLabel, const char* pcHint, char* pcBuffer, size_ const plVec2 tFrameStartPos = *ptStartPos; const uint32_t uHash = pl_str_hash(pcLabel, 0, pl_sb_top(gptCtx->sbuIdStack)); - const plRect tLabelTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + const plRect tLabelTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); const plVec2 tLabelTextActualCenter = pl_rect_center(&tLabelTextBounding); const plVec2 tFrameSize = { 2.0f * (ptWidgetSize->x / 3.0f), ptWidgetSize->y}; @@ -2442,7 +2569,7 @@ pl__input_text_ex(const char* pcLabel, const char* pcHint, char* pcBuffer, size_ if (!bIsMultiLine) { // RenderNavHighlight(frame_bb, id); - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgCol, gptCtx->tStyle.fFrameRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgCol)}); } @@ -2599,14 +2726,14 @@ pl__input_text_ex(const char* pcLabel, const char* pcHint, char* pcBuffer, size_ else { plVec2 rect_size = pl__input_text_calc_text_size_w(p, text_selected_end, &p, NULL, true); - if (rect_size.x <= 0.0f) rect_size.x = floorf(font->sbtGlyphs[font->_auCodePoints[(plUiWChar)' ']].xAdvance * 0.50f); // So we can see selected empty lines + if (rect_size.x <= 0.0f) rect_size.x = floorf(font->_sbtGlyphs[font->_auCodePoints[(plUiWChar)' ']].xAdvance * 0.50f); // So we can see selected empty lines plRect rect = { pl_add_vec2(rect_pos, (plVec2){0.0f, bg_offy_up - gptCtx->tStyle.fFontSize}), pl_add_vec2(rect_pos, (plVec2){rect_size.x, bg_offy_dn}) }; rect = pl_rect_clip(&rect, &clip_rect); if (pl_rect_overlaps_rect(&rect, &clip_rect)) - gptDraw->add_rect_filled(ptWindow->ptFgLayer, rect.tMin, rect.tMax, (plVec4){1.0f, 0.0f, 0.0f, 1.0f}, 0.0f, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, rect.tMin, rect.tMax, 0.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGB(1.0f, 0.0f, 0.0f)}); } rect_pos.x = draw_pos.x - draw_scroll.x; rect_pos.y += gptCtx->tStyle.fFontSize; @@ -2617,7 +2744,7 @@ pl__input_text_ex(const char* pcLabel, const char* pcHint, char* pcBuffer, size_ if (bIsMultiLine || (pcBufferDisplayEnd - pcBufferDisplay) < iBufferDisplayMaxLength) { // ImU32 col = GetColorU32(bIsDisplayingHint ? ImGuiCol_TextDisabled : ImGuiCol_Text); - pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, pl_sub_vec2(draw_pos, draw_scroll), tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tTextCol, + pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, pl_sub_vec2(draw_pos, draw_scroll), tFrameStartPos, tBoundingBox.tMax, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcBufferDisplay, 0.0f); // gptDraw->add_text_ex(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, pl_sub_vec2(draw_pos, draw_scroll), gptCtx->tColorScheme.tTextCol, // pcBufferDisplay, pcBufferDisplayEnd, 0.0f); @@ -2636,7 +2763,12 @@ pl__input_text_ex(const char* pcLabel, const char* pcHint, char* pcBuffer, size_ {cursor_screen_pos.x + 1.0f, cursor_screen_pos.y - 1.5f} }; if (bCursorIsVisible && pl_rect_overlaps_rect(&cursor_screen_rect, &clip_rect)) - gptDraw->add_line(ptWindow->ptFgLayer, cursor_screen_rect.tMin, pl_rect_bottom_left(&cursor_screen_rect), gptCtx->tColorScheme.tTextCol, 1.0f); + { + gptDraw->add_line(ptWindow->ptFgLayer, + cursor_screen_rect.tMin, + pl_rect_bottom_left(&cursor_screen_rect), + (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), .fThickness = 1.0f}); + } // Notify OS of text input position for advanced IME (-1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.) // if (!bIsReadOnly) @@ -2659,7 +2791,7 @@ pl__input_text_ex(const char* pcLabel, const char* pcHint, char* pcBuffer, size_ if (bIsMultiLine || (pcBufferDisplayEnd - pcBufferDisplay) < iBufferDisplayMaxLength) { - pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, draw_pos, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tTextCol, + pl__add_clipped_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, draw_pos, tFrameStartPos, tBoundingBox.tMax, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcBufferDisplay, 0.0f); // gptDraw->add_text_ex(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, draw_pos, gptCtx->tColorScheme.tTextCol, // pcBufferDisplay, pcBufferDisplayEnd, 0.0f); @@ -2693,7 +2825,7 @@ pl__input_text_ex(const char* pcLabel, const char* pcHint, char* pcBuffer, size_ // if (pcLabel.x > 0) { // RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){ptStartPos->x + (2.0f * ptWidgetSize->x / 3.0f), ptStartPos->y + ptStartPos->y + ptWidgetSize->y / 2.0f - tLabelTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){ptStartPos->x + (2.0f * ptWidgetSize->x / 3.0f), ptStartPos->y + ptStartPos->y + ptWidgetSize->y / 2.0f - tLabelTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); } // if (value_changed && !(flags & ImGuiInputTextFlags_NoMarkEdited)) @@ -2721,8 +2853,21 @@ pl_slider_float_f(const char* pcLabel, float* pfValue, float fMin, float fMax, c char acTextBuffer[64] = {0}; pl_sprintf(acTextBuffer, pcFormat, *pfValue); - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, acTextBuffer, pl__find_renderered_text_end(acTextBuffer, NULL), -1.0f); - const plRect tLabelTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + + const plRect tTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(acTextBuffer, NULL), + .fWrap = -1.0f}); + + const plRect tLabelTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); + const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tLabelTextActualCenter = pl_rect_center(&tLabelTextBounding); @@ -2749,13 +2894,13 @@ pl_slider_float_f(const char* pcLabel, float* pfValue, float fMin, float fMax, c const bool bPressed = pl__button_behavior(&tGrabBox, uHash, &bHovered, &bHeld); const plRect tBoundingBox = pl_calculate_rect(tFrameStartPos, tSize); - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgActiveCol, gptCtx->tStyle.fFrameRounding, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgHoveredCol, gptCtx->tStyle.fFrameRounding, 0); - else gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgCol, gptCtx->tStyle.fFrameRounding, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgHoveredCol)}); + else gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgCol)}); - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tGrabStartPos, tGrabBox.tMax, gptCtx->tColorScheme.tButtonCol, gptCtx->tStyle.fGrabRounding, 0); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, acTextBuffer, -1.0f); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tGrabStartPos, tGrabBox.tMax, gptCtx->tStyle.fGrabRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonCol)}); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), acTextBuffer, -1.0f); bool bDragged = false; if(gptCtx->uActiveId == uHash && gptIOI->is_mouse_dragging(PL_MOUSE_BUTTON_LEFT, 1.0f)) @@ -2803,8 +2948,21 @@ pl_slider_int_f(const char* pcLabel, int* piValue, int iMin, int iMax, const cha char acTextBuffer[64] = {0}; pl_sprintf(acTextBuffer, pcFormat, *piValue); - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, acTextBuffer, pl__find_renderered_text_end(acTextBuffer, NULL), -1.0f); - const plRect tLabelTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + + const plRect tTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(acTextBuffer, NULL), + .fWrap = -1.0f}); + + const plRect tLabelTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); + const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tLabelTextActualCenter = pl_rect_center(&tLabelTextBounding); @@ -2829,13 +2987,13 @@ pl_slider_int_f(const char* pcLabel, int* piValue, int iMin, int iMax, const cha const bool bPressed = pl__button_behavior(&tGrabBox, uHash, &bHovered, &bHeld); const plRect tBoundingBox = pl_calculate_rect(tFrameStartPos, tSize); - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgActiveCol, gptCtx->tStyle.fFrameRounding, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgHoveredCol, gptCtx->tStyle.fFrameRounding, 0); - else gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgCol, gptCtx->tStyle.fFrameRounding, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgHoveredCol)}); + else gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgCol)}); - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tGrabStartPos, tGrabBox.tMax, gptCtx->tColorScheme.tButtonCol, gptCtx->tStyle.fGrabRounding, 0); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, acTextBuffer, -1.0f); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tGrabStartPos, tGrabBox.tMax, gptCtx->tStyle.fGrabRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tButtonCol)}); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), acTextBuffer, -1.0f); bool bDragged = false; if(gptCtx->uActiveId == uHash && gptIOI->is_mouse_dragging(PL_MOUSE_BUTTON_LEFT, 1.0f)) @@ -2884,8 +3042,21 @@ pl_drag_float_f(const char* pcLabel, float* pfValue, float fSpeed, float fMin, f char acTextBuffer[64] = {0}; pl_sprintf(acTextBuffer, pcFormat, *pfValue); - const plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, acTextBuffer, pl__find_renderered_text_end(acTextBuffer, NULL), -1.0f); - const plRect tLabelTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tFrameStartPos, pcLabel, pl__find_renderered_text_end(pcLabel, NULL), -1.0f); + + const plRect tTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(acTextBuffer, NULL), + .fWrap = -1.0f}); + + const plRect tLabelTextBounding = gptDraw->calculate_text_bb(tFrameStartPos, pcLabel, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcLabel, NULL), + .fWrap = -1.0f}); + const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); const plVec2 tLabelTextActualCenter = pl_rect_center(&tLabelTextBounding); @@ -2902,12 +3073,12 @@ pl_drag_float_f(const char* pcLabel, float* pfValue, float fSpeed, float fMin, f bool bHeld = false; const bool bPressed = pl__button_behavior(&tBoundingBox, uHash, &bHovered, &bHeld); - if(gptCtx->uActiveId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgActiveCol, gptCtx->tStyle.fFrameRounding, 0); - else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgHoveredCol, gptCtx->tStyle.fFrameRounding, 0); - else gptDraw->add_rect_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tColorScheme.tFrameBgCol, gptCtx->tStyle.fFrameRounding, 0); + if(gptCtx->uActiveId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgActiveCol)}); + else if(gptCtx->uHoveredId == uHash) gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgHoveredCol)}); + else gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tFrameStartPos, tBoundingBox.tMax, gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgCol)}); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, gptCtx->tColorScheme.tTextCol, pcLabel, -1.0f); - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, acTextBuffer, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, (plVec2){tStartPos.x + (2.0f * tWidgetSize.x / 3.0f), tStartPos.y + tStartPos.y + tWidgetSize.y / 2.0f - tLabelTextActualCenter.y}, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcLabel, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), acTextBuffer, -1.0f); bool bDragged = false; if(gptCtx->uActiveId == uHash && gptIOI->is_mouse_dragging(PL_MOUSE_BUTTON_LEFT, 1.0f)) @@ -2944,10 +3115,12 @@ pl_image_ex(plTextureID tTexture, plVec2 tSize, plVec2 tUv0, plVec2 tUv1, plVec4 if(!(tFinalPos.y < ptWindow->tPos.y || tStartPos.y > ptWindow->tPos.y + ptWindow->tFullSize.y)) { - gptDraw->add_image_ex(ptWindow->ptFgLayer, tTexture, tStartPos, tFinalPos, tUv0, tUv1, tTintColor); + gptDraw->add_image_ex(ptWindow->ptFgLayer, tTexture, tStartPos, tFinalPos, tUv0, tUv1, PL_COLOR_32_VEC4(tTintColor)); if(tBorderColor.a > 0.0f) - gptDraw->add_rect(ptWindow->ptFgLayer, tStartPos, tFinalPos, tBorderColor, 1.0f, 0.0f, 0); + { + gptDraw->add_rect(ptWindow->ptFgLayer, tStartPos, tFinalPos, (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(tBorderColor), .fThickness = 1.0f}); + } } pl__advance_cursor(tSize.x, tSize.y); @@ -2980,10 +3153,10 @@ pl_image_button_ex(const char* pcId, plTextureID tTexture, plVec2 tSize, plVec2 bool bHeld = false; bPressed = pl__button_behavior(&tBoundingBox, uHash, &bHovered, &bHeld); - gptDraw->add_image_ex(ptWindow->ptFgLayer, tTexture, tStartPos, tFinalPos, tUv0, tUv1, tTintColor); + gptDraw->add_image_ex(ptWindow->ptFgLayer, tTexture, tStartPos, tFinalPos, tUv0, tUv1, PL_COLOR_32_VEC4(tTintColor)); if(tBorderColor.a > 0.0f) - gptDraw->add_rect(ptWindow->ptFgLayer, tStartPos, tFinalPos, tBorderColor, 1.0f, 0.0f, 0); + gptDraw->add_rect(ptWindow->ptFgLayer, tStartPos, tFinalPos, (plDrawLineOptions){.uColor = PL_COLOR_32_VEC4(tBorderColor), .fThickness = 1.0f}); pl__add_widget(uHash); } @@ -3043,8 +3216,8 @@ pl_progress_bar(float fFraction, plVec2 tSize, const char* pcOverlay) if(!(tStartPos.y + tSize.y < ptWindow->tPos.y || tStartPos.y > ptWindow->tPos.y + ptWindow->tFullSize.y)) { - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, pl_add_vec2(tStartPos, tSize), gptCtx->tColorScheme.tFrameBgCol, gptCtx->tStyle.fFrameRounding, 0); - gptDraw->add_rect_filled(ptWindow->ptFgLayer, tStartPos, pl_add_vec2(tStartPos, (plVec2){tSize.x * fFraction, tSize.y}), gptCtx->tColorScheme.tProgressBarCol, gptCtx->tStyle.fFrameRounding, 0); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, pl_add_vec2(tStartPos, tSize), gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tFrameBgCol)}); + gptDraw->add_rect_rounded_filled(ptWindow->ptFgLayer, tStartPos, pl_add_vec2(tStartPos, (plVec2){tSize.x * fFraction, tSize.y}), gptCtx->tStyle.fFrameRounding, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(gptCtx->tColorScheme.tProgressBarCol)}); const char* pcTextPtr = pcOverlay; @@ -3056,7 +3229,14 @@ pl_progress_bar(float fFraction, plVec2 tSize, const char* pcOverlay) } const plVec2 tTextSize = pl__calculate_text_size(gptCtx->tFont, gptCtx->tStyle.fFontSize, pcTextPtr, -1.0f); - plRect tTextBounding = gptDraw->calculate_text_bb_ex(gptCtx->tFont, gptCtx->tStyle.fFontSize, tStartPos, pcTextPtr, pl__find_renderered_text_end(pcTextPtr, NULL), -1.0f); + + plRect tTextBounding = gptDraw->calculate_text_bb(tStartPos, pcTextPtr, + (plDrawTextOptions){ + .ptFont = gptCtx->tFont, + .fSize = gptCtx->tStyle.fFontSize, + .pcTextEnd = pl__find_renderered_text_end(pcTextPtr, NULL), + .fWrap = -1.0f}); + const plVec2 tTextActualCenter = pl_rect_center(&tTextBounding); plVec2 tTextStartPos = { @@ -3067,7 +3247,7 @@ pl_progress_bar(float fFraction, plVec2 tSize, const char* pcOverlay) if(tTextStartPos.x + tTextSize.x > tStartPos.x + tSize.x) tTextStartPos.x = tStartPos.x + tSize.x - tTextSize.x - gptCtx->tStyle.tInnerSpacing.x; - pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, gptCtx->tColorScheme.tTextCol, pcTextPtr, -1.0f); + pl__add_text(ptWindow->ptFgLayer, gptCtx->tFont, gptCtx->tStyle.fFontSize, tTextStartPos, PL_COLOR_32_VEC4(gptCtx->tColorScheme.tTextCol), pcTextPtr, -1.0f); const bool bHovered = gptIOI->is_mouse_hovering_rect(tStartPos, pl_add_vec2(tStartPos, tWidgetSize)) && ptWindow == gptCtx->ptHoveredWindow; gptCtx->tPrevItemData.bHovered = bHovered; diff --git a/sandbox/app.c b/sandbox/app.c index c4849b36..ef4dfb6a 100644 --- a/sandbox/app.c +++ b/sandbox/app.c @@ -131,7 +131,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData) plFontConfig tFontConfig0 = { .bSdf = false, - .fFontSize = 16.0f, + .fSize = 16.0f, .uHOverSampling = 1, .uVOverSampling = 1, .ptRanges = &tFontRange, @@ -147,11 +147,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData) plFontConfig tFontConfig1 = { .bSdf = false, - .fFontSize = 16.0f, + .fSize = 16.0f, .uHOverSampling = 1, .uVOverSampling = 1, - .bMergeFont = true, - .tMergeFont = ptEditorData->tDefaultFont, + .ptMergeFont = ptEditorData->tDefaultFont, .ptRanges = &tIconRange, .uRangeCount = 1 }; @@ -376,7 +375,7 @@ pl_app_update(plEditorData* ptEditorData) const float pfRatios[] = {1.0f}; gptUi->layout_row(PL_UI_LAYOUT_ROW_TYPE_DYNAMIC, 0.0f, 1, pfRatios); - if(gptUi->collapsing_header(ICON_FA_CIRCLE_INFO " Information")) + if(gptUi->begin_collapsing_header(ICON_FA_CIRCLE_INFO " Information")) { gptUi->text("Pilot Light %s", PILOT_LIGHT_VERSION); @@ -390,7 +389,7 @@ pl_app_update(plEditorData* ptEditorData) gptUi->end_collapsing_header(); } - if(gptUi->collapsing_header(ICON_FA_SLIDERS " App Options")) + if(gptUi->begin_collapsing_header(ICON_FA_SLIDERS " App Options")) { if(gptUi->checkbox("Freeze Culling Camera", &ptEditorData->bFreezeCullCamera)) { @@ -409,7 +408,7 @@ pl_app_update(plEditorData* ptEditorData) gptRenderer->show_graphics_options(ICON_FA_DICE_D6 " Graphics"); - if(gptUi->collapsing_header(ICON_FA_SCREWDRIVER_WRENCH " Tools")) + if(gptUi->begin_collapsing_header(ICON_FA_SCREWDRIVER_WRENCH " Tools")) { gptUi->checkbox("Device Memory Analyzer", &ptEditorData->tDebugInfo.bShowDeviceMemoryAnalyzer); gptUi->checkbox("Memory Allocations", &ptEditorData->tDebugInfo.bShowMemoryAllocations); @@ -420,7 +419,7 @@ pl_app_update(plEditorData* ptEditorData) gptUi->end_collapsing_header(); } - if(gptUi->collapsing_header(ICON_FA_BUG " Debug")) + if(gptUi->begin_collapsing_header(ICON_FA_BUG " Debug")) { if(gptUi->button("resize")) ptEditorData->bResize = true; @@ -434,7 +433,7 @@ pl_app_update(plEditorData* ptEditorData) gptUi->end_collapsing_header(); } - if(gptUi->collapsing_header(ICON_FA_USER_GEAR " User Interface")) + if(gptUi->begin_collapsing_header(ICON_FA_USER_GEAR " User Interface")) { gptUi->checkbox("UI Debug", &ptEditorData->bShowUiDebug); gptUi->checkbox("UI Demo", &ptEditorData->bShowUiDemo); diff --git a/sandbox/pl_ecs_tools.c b/sandbox/pl_ecs_tools.c index 93fc8d0d..cf624e50 100644 --- a/sandbox/pl_ecs_tools.c +++ b/sandbox/pl_ecs_tools.c @@ -100,13 +100,13 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->text("Entity: %u, %u", ptSelectedEntity->uIndex, ptSelectedEntity->uGeneration); - if(ptTagComp && gptUi->collapsing_header("Tag")) + if(ptTagComp && gptUi->begin_collapsing_header("Tag")) { gptUi->text("Name: %s", ptTagComp->acName); gptUi->end_collapsing_header(); } - if(ptTransformComp && gptUi->collapsing_header("Transform")) + if(ptTransformComp && gptUi->begin_collapsing_header("Transform")) { gptUi->text("Scale: (%+0.3f, %+0.3f, %+0.3f)", ptTransformComp->tScale.x, ptTransformComp->tScale.y, ptTransformComp->tScale.z); gptUi->text("Translation: (%+0.3f, %+0.3f, %+0.3f)", ptTransformComp->tTranslation.x, ptTransformComp->tTranslation.y, ptTransformComp->tTranslation.z); @@ -119,7 +119,7 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->end_collapsing_header(); } - if(ptMeshComp && gptUi->collapsing_header("Mesh")) + if(ptMeshComp && gptUi->begin_collapsing_header("Mesh")) { plTagComponent* ptMaterialTagComp = gptEcs->get_component(ptLibrary, PL_COMPONENT_TYPE_TAG, ptMeshComp->tMaterial); @@ -145,7 +145,7 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->end_collapsing_header(); } - if(ptObjectComp && gptUi->collapsing_header("Object")) + if(ptObjectComp && gptUi->begin_collapsing_header("Object")) { plTagComponent* ptMeshTagComp = gptEcs->get_component(ptLibrary, PL_COMPONENT_TYPE_TAG, ptObjectComp->tMesh); plTagComponent* ptTransformTagComp = gptEcs->get_component(ptLibrary, PL_COMPONENT_TYPE_TAG, ptObjectComp->tTransform); @@ -154,14 +154,14 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->end_collapsing_header(); } - if(ptHierarchyComp && gptUi->collapsing_header("Hierarchy")) + if(ptHierarchyComp && gptUi->begin_collapsing_header("Hierarchy")) { plTagComponent* ptParentTagComp = gptEcs->get_component(ptLibrary, PL_COMPONENT_TYPE_TAG, ptHierarchyComp->tParent); gptUi->text("Parent Entity: %s , %u", ptParentTagComp->acName, ptHierarchyComp->tParent.uIndex); gptUi->end_collapsing_header(); } - if(ptLightComp && gptUi->collapsing_header("Light")) + if(ptLightComp && gptUi->begin_collapsing_header("Light")) { static const char* apcLightTypes[] = { "PL_LIGHT_TYPE_DIRECTIONAL", @@ -175,7 +175,7 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->text("Cast Shadow: %s", ptLightComp->tFlags & PL_LIGHT_FLAG_CAST_SHADOW ? "true" : "false"); } - if(ptMaterialComp && gptUi->collapsing_header("Material")) + if(ptMaterialComp && gptUi->begin_collapsing_header("Material")) { gptUi->text("Base Color: (%0.3f, %0.3f, %0.3f, %0.3f)", ptMaterialComp->tBaseColor.r, ptMaterialComp->tBaseColor.g, ptMaterialComp->tBaseColor.b, ptMaterialComp->tBaseColor.a); gptUi->text("Alpha Cutoff: %0.3f", ptMaterialComp->fAlphaCutoff); @@ -232,7 +232,7 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->end_collapsing_header(); } - if(ptSkinComp && gptUi->collapsing_header("Skin")) + if(ptSkinComp && gptUi->begin_collapsing_header("Skin")) { if(gptUi->tree_node("Joints")) { @@ -246,7 +246,7 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->end_collapsing_header(); } - if(ptCameraComp && gptUi->collapsing_header("Camera")) + if(ptCameraComp && gptUi->begin_collapsing_header("Camera")) { gptUi->text("Near Z: %+0.3f", ptCameraComp->fNearZ); gptUi->text("Far Z: %+0.3f", ptCameraComp->fFarZ); @@ -263,7 +263,7 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->end_collapsing_header(); } - if(ptAnimationComp && gptUi->collapsing_header("Animation")) + if(ptAnimationComp && gptUi->begin_collapsing_header("Animation")) { bool bPlaying = ptAnimationComp->tFlags & PL_ANIMATION_FLAG_PLAYING; bool bLooped = ptAnimationComp->tFlags & PL_ANIMATION_FLAG_LOOPED; @@ -296,7 +296,7 @@ pl_show_ecs_window(plEntity* ptSelectedEntity, plComponentLibrary* ptLibrary, bo gptUi->end_collapsing_header(); } - if(ptIKComp && gptUi->collapsing_header("Inverse Kinematics")) + if(ptIKComp && gptUi->begin_collapsing_header("Inverse Kinematics")) { plTagComponent* ptTargetComp = gptEcs->get_component(ptLibrary, PL_COMPONENT_TYPE_TAG, ptIKComp->tTarget); gptUi->text("Target Entity: %s , %u", ptTargetComp->acName, ptIKComp->tTarget.uIndex); diff --git a/sandbox/pl_gizmo.c b/sandbox/pl_gizmo.c index b819de49..cc7d232a 100644 --- a/sandbox/pl_gizmo.c +++ b/sandbox/pl_gizmo.c @@ -237,12 +237,16 @@ pl__gizmo_translation(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, p if(ptGizmoData->tState != PL_GIZMO_STATE_DEFAULT) { - gptDraw->add_3d_sphere_filled(ptGizmoDrawlist, ptGizmoData->tBeginPos, fAxisRadius * 2, (plVec4){0.5f, 0.5f, 0.5f, 0.5f}); - gptDraw->add_3d_line(ptGizmoDrawlist, ptGizmoData->tBeginPos, *ptCenter, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, fAxisRadius); + gptDraw->add_3d_sphere_filled(ptGizmoDrawlist, (plDrawSphereDesc){.tCenter = ptGizmoData->tBeginPos, .fRadius = fAxisRadius * 2}, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(0.5f, 0.5f, 0.5f, 0.5f)}); + gptDraw->add_3d_line(ptGizmoDrawlist, ptGizmoData->tBeginPos, *ptCenter, (plDrawLineOptions){.uColor = PL_COLOR_32_YELLOW, .fThickness = fAxisRadius}); char acTextBuffer[256] = {0}; pl_sprintf(acTextBuffer, "offset: %0.3f, %0.3f, %0.3f", ptCenter->x - ptGizmoData->tBeginPos.x, ptCenter->y - ptGizmoData->tBeginPos.y, ptCenter->z - ptGizmoData->tBeginPos.z); - gptDraw->add_3d_text(ptGizmoDrawlist, gptUi->get_default_font(), 0.0f, (plVec3){ptCenter->x, ptCenter->y + fLength * 1.1f, ptCenter->z}, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, acTextBuffer, 0.0f); - } + gptDraw->add_3d_text(ptGizmoDrawlist, (plVec3){ptCenter->x, ptCenter->y + fLength * 1.1f, ptCenter->z}, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptUi->get_default_font(), + .uColor = PL_COLOR_32_YELLOW + }); + }; float fXDistanceAlong = 0.0f; float fYDistanceAlong = 0.0f; @@ -561,57 +565,45 @@ pl__gizmo_translation(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, p // x arrow head plDrawConeDesc tDrawDesc0 = {0}; - gptDraw->fill_cone_desc_default(&tDrawDesc0); - tDrawDesc0.tColor = tXColor; tDrawDesc0.tBasePos = (plVec3){ptCenter->x + fLength - fArrowLength, ptCenter->y, ptCenter->z}; tDrawDesc0.tTipPos = (plVec3){ptCenter->x + fLength, ptCenter->y, ptCenter->z}; tDrawDesc0.fRadius = fArrowRadius; - gptDraw->add_3d_cone_filled_ex(ptGizmoDrawlist, &tDrawDesc0); + gptDraw->add_3d_cone_filled(ptGizmoDrawlist, tDrawDesc0, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXColor)}); // y arrow head plDrawConeDesc tDrawDesc1 = {0}; - gptDraw->fill_cone_desc_default(&tDrawDesc1); - tDrawDesc1.tColor = tYColor; tDrawDesc1.tBasePos = (plVec3){ptCenter->x, ptCenter->y + fLength - fArrowLength, ptCenter->z}; tDrawDesc1.tTipPos = (plVec3){ptCenter->x, ptCenter->y + fLength, ptCenter->z}; tDrawDesc1.fRadius = fArrowRadius; - gptDraw->add_3d_cone_filled_ex(ptGizmoDrawlist, &tDrawDesc1); + gptDraw->add_3d_cone_filled(ptGizmoDrawlist, tDrawDesc1, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tYColor)}); // z arrow head plDrawConeDesc tDrawDesc2 = {0}; - gptDraw->fill_cone_desc_default(&tDrawDesc2); - tDrawDesc2.tColor = tZColor; tDrawDesc2.tBasePos = (plVec3){ptCenter->x, ptCenter->y, ptCenter->z + fLength - fArrowLength}; tDrawDesc2.tTipPos = (plVec3){ptCenter->x, ptCenter->y, ptCenter->z + fLength}; tDrawDesc2.fRadius = fArrowRadius; - gptDraw->add_3d_cone_filled_ex(ptGizmoDrawlist, &tDrawDesc2); + gptDraw->add_3d_cone_filled(ptGizmoDrawlist, tDrawDesc2, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tZColor)}); // x axis plDrawCylinderDesc tDrawDesc3 = {0}; - gptDraw->fill_cylinder_desc_default(&tDrawDesc3); - tDrawDesc3.tColor = tXColor; tDrawDesc3.tBasePos = *ptCenter; tDrawDesc3.tTipPos = (plVec3){ptCenter->x + fLength - fArrowLength, ptCenter->y, ptCenter->z}; tDrawDesc3.fRadius = fAxisRadius; - gptDraw->add_3d_cylinder_filled_ex(ptGizmoDrawlist, &tDrawDesc3); + gptDraw->add_3d_cylinder_filled(ptGizmoDrawlist, tDrawDesc3, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXColor)}); // y axis plDrawCylinderDesc tDrawDesc4 = {0}; - gptDraw->fill_cylinder_desc_default(&tDrawDesc4); - tDrawDesc4.tColor = tYColor; tDrawDesc4.tBasePos = *ptCenter; tDrawDesc4.tTipPos = (plVec3){ptCenter->x, ptCenter->y + fLength - fArrowLength, ptCenter->z}; tDrawDesc4.fRadius = fAxisRadius; - gptDraw->add_3d_cylinder_filled_ex(ptGizmoDrawlist, &tDrawDesc4); + gptDraw->add_3d_cylinder_filled(ptGizmoDrawlist, tDrawDesc4, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tYColor)}); // z axis plDrawCylinderDesc tDrawDesc5 = {0}; - gptDraw->fill_cylinder_desc_default(&tDrawDesc5); - tDrawDesc5.tColor = tZColor; tDrawDesc5.tBasePos = *ptCenter; tDrawDesc5.tTipPos = (plVec3){ptCenter->x, ptCenter->y, ptCenter->z + fLength - fArrowLength}; tDrawDesc5.fRadius = fAxisRadius; - gptDraw->add_3d_cylinder_filled_ex(ptGizmoDrawlist, &tDrawDesc5); + gptDraw->add_3d_cylinder_filled(ptGizmoDrawlist, tDrawDesc5, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tZColor)}); // origin gptDraw->add_3d_centered_box_filled(ptGizmoDrawlist, @@ -619,12 +611,12 @@ pl__gizmo_translation(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, p fAxisRadius * 4, fAxisRadius * 4, fAxisRadius * 4, - (plVec4){0.5f, 0.5f, 0.5f, 1.0f}); + (plDrawSolidOptions){.uColor = PL_COLOR_32_RGB(0.5f, 0.5f, 0.5f)}); // PLANES - gptDraw->add_3d_plane_xy_filled(ptGizmoDrawlist, (plVec3){ptCenter->x + fLength * 0.25f, ptCenter->y + fLength * 0.25f, ptCenter->z}, fLength * 0.25f, fLength * 0.25f, tXYColor); - gptDraw->add_3d_plane_yz_filled(ptGizmoDrawlist, (plVec3){ptCenter->x, ptCenter->y + fLength * 0.25f, ptCenter->z + fLength * 0.25f}, fLength * 0.25f, fLength * 0.25f, tYZColor); - gptDraw->add_3d_plane_xz_filled(ptGizmoDrawlist, (plVec3){ptCenter->x + fLength * 0.25f, ptCenter->y, ptCenter->z + fLength * 0.25f}, fLength * 0.25f, fLength * 0.25f, tXZColor); + gptDraw->add_3d_plane_xy_filled(ptGizmoDrawlist, (plVec3){ptCenter->x + fLength * 0.25f, ptCenter->y + fLength * 0.25f, ptCenter->z}, fLength * 0.25f, fLength * 0.25f, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXYColor)}); + gptDraw->add_3d_plane_yz_filled(ptGizmoDrawlist, (plVec3){ptCenter->x, ptCenter->y + fLength * 0.25f, ptCenter->z + fLength * 0.25f}, fLength * 0.25f, fLength * 0.25f, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tYZColor)}); + gptDraw->add_3d_plane_xz_filled(ptGizmoDrawlist, (plVec3){ptCenter->x + fLength * 0.25f, ptCenter->y, ptCenter->z + fLength * 0.25f}, fLength * 0.25f, fLength * 0.25f, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXZColor)}); } static void @@ -735,9 +727,13 @@ pl__gizmo_rotation(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCa char acTextBuffer[256] = {0}; pl_sprintf(acTextBuffer, "x-axis rotation: %0.0f degrees", fAngleBetweenVecs * 180.0f / PL_PI); - gptDraw->add_3d_text(ptGizmoDrawlist, gptUi->get_default_font(), 0.0f, (plVec3){ptCenter->x, ptCenter->y + fOuterRadius * 1.1f, ptCenter->z}, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, acTextBuffer, 0.0f); - gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir0, fInnerRadius)), (plVec4){0.7f, 0.7f, 0.7f, 1.0f}, 0.0035f * ptGizmoData->fCaptureScale); - gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir1, fInnerRadius)), (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 0.0035f * ptGizmoData->fCaptureScale); + gptDraw->add_3d_text(ptGizmoDrawlist, (plVec3){ptCenter->x, ptCenter->y + fOuterRadius * 1.1f, ptCenter->z}, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptUi->get_default_font(), + .uColor = PL_COLOR_32_YELLOW + }); + gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir0, fInnerRadius)), (plDrawLineOptions){.uColor = PL_COLOR_32_RGBA(0.7f, 0.7f, 0.7f, 1.0f), .fThickness = 0.0035f * ptGizmoData->fCaptureScale}); + gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir1, fInnerRadius)), (plDrawLineOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 1.0f), .fThickness = 0.0035f * ptGizmoData->fCaptureScale}); if(fAngleBetweenVecs != 0.0f) { @@ -779,9 +775,13 @@ pl__gizmo_rotation(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCa char acTextBuffer[256] = {0}; pl_sprintf(acTextBuffer, "y-axis rotation: %0.0f degrees", fAngleBetweenVecs * 180.0f / PL_PI); - gptDraw->add_3d_text(ptGizmoDrawlist, gptUi->get_default_font(), 0.0f, (plVec3){ptCenter->x, ptCenter->y + fOuterRadius * 1.1f, ptCenter->z}, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, acTextBuffer, 0.0f); - gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir0, fInnerRadius)), (plVec4){0.7f, 0.7f, 0.7f, 1.0f}, 0.0035f * ptGizmoData->fCaptureScale); - gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir1, fInnerRadius)), (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 0.0035f * ptGizmoData->fCaptureScale); + gptDraw->add_3d_text(ptGizmoDrawlist, (plVec3){ptCenter->x, ptCenter->y + fOuterRadius * 1.1f, ptCenter->z}, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptUi->get_default_font(), + .uColor = PL_COLOR_32_YELLOW + }); + gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir0, fInnerRadius)), (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.7f, 0.7f, 0.7f), .fThickness = 0.0035f * ptGizmoData->fCaptureScale}); + gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir1, fInnerRadius)), (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 1.0f, 0.0f), .fThickness = 0.0035f * ptGizmoData->fCaptureScale}); if(fAngleBetweenVecs != 0.0f) { @@ -823,9 +823,13 @@ pl__gizmo_rotation(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCa char acTextBuffer[256] = {0}; pl_sprintf(acTextBuffer, "z-axis rotation: %0.0f degrees", fAngleBetweenVecs * 180.0f / PL_PI); - gptDraw->add_3d_text(ptGizmoDrawlist, gptUi->get_default_font(), 0.0f, (plVec3){ptCenter->x, ptCenter->y + fOuterRadius * 1.1f, ptCenter->z}, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, acTextBuffer, 0.0f); - gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir0, fInnerRadius)), (plVec4){0.7f, 0.7f, 0.7f, 1.0f}, 0.0035f * ptGizmoData->fCaptureScale); - gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir1, fInnerRadius)), (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, 0.0035f * ptGizmoData->fCaptureScale); + gptDraw->add_3d_text(ptGizmoDrawlist, (plVec3){ptCenter->x, ptCenter->y + fOuterRadius * 1.1f, ptCenter->z}, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptUi->get_default_font(), + .uColor = PL_COLOR_32_YELLOW + }); + gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir0, fInnerRadius)), (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(0.7f, 0.7f, 0.7f), .fThickness = 0.0035f * ptGizmoData->fCaptureScale}); + gptDraw->add_3d_line(ptGizmoDrawlist, *ptCenter, pl_add_vec3(*ptCenter, pl_mul_vec3_scalarf(tDir1, fInnerRadius)), (plDrawLineOptions){.uColor = PL_COLOR_32_RGB(1.0f, 1.0f, 0.0f), .fThickness = 0.0035f * ptGizmoData->fCaptureScale}); if(fAngleBetweenVecs != 0.0f) { @@ -899,9 +903,9 @@ pl__gizmo_rotation(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCa ptGizmoData->tState = PL_GIZMO_STATE_DEFAULT; } - gptDraw->add_3d_band_yz_filled(ptGizmoDrawlist, *ptCenter, fInnerRadius, fOuterRadius, tXColor, 36); - gptDraw->add_3d_band_xz_filled(ptGizmoDrawlist, *ptCenter, fInnerRadius, fOuterRadius, tYColor, 36); - gptDraw->add_3d_band_xy_filled(ptGizmoDrawlist, *ptCenter, fInnerRadius, fOuterRadius, tZColor, 36); + gptDraw->add_3d_band_yz_filled(ptGizmoDrawlist, *ptCenter, fInnerRadius, fOuterRadius, 36, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXColor)}); + gptDraw->add_3d_band_xz_filled(ptGizmoDrawlist, *ptCenter, fInnerRadius, fOuterRadius, 36, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tYColor)}); + gptDraw->add_3d_band_xy_filled(ptGizmoDrawlist, *ptCenter, fInnerRadius, fOuterRadius, 36, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tZColor)}); } static void @@ -938,7 +942,11 @@ pl__gizmo_scale(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCamer { char acTextBuffer[256] = {0}; pl_sprintf(acTextBuffer, "scaling: %0.3f, %0.3f, %0.3f", tCurrentScale.x, tCurrentScale.y, tCurrentScale.z); - gptDraw->add_3d_text(ptGizmoDrawlist, gptUi->get_default_font(), 0.0f, (plVec3){ptCenter->x, ptCenter->y + fLength * 1.2f, ptCenter->z}, (plVec4){1.0f, 1.0f, 0.0f, 1.0f}, acTextBuffer, 0.0f); + gptDraw->add_3d_text(ptGizmoDrawlist, (plVec3){ptCenter->x, ptCenter->y + fLength * 1.2f, ptCenter->z}, acTextBuffer, + (plDrawTextOptions){ + .ptFont = gptUi->get_default_font(), + .uColor = PL_COLOR_32_YELLOW + }); } float fXDistanceAlong = 0.0f; @@ -1143,30 +1151,24 @@ pl__gizmo_scale(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCamer // x axis plDrawCylinderDesc tDrawDesc3 = {0}; - gptDraw->fill_cylinder_desc_default(&tDrawDesc3); - tDrawDesc3.tColor = tXColor; tDrawDesc3.tBasePos = *ptCenter; tDrawDesc3.tTipPos = (plVec3){ptCenter->x + fLength, ptCenter->y, ptCenter->z}; tDrawDesc3.fRadius = fAxisRadius; - gptDraw->add_3d_cylinder_filled_ex(ptGizmoDrawlist, &tDrawDesc3); + gptDraw->add_3d_cylinder_filled(ptGizmoDrawlist, tDrawDesc3, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXColor)}); // y axis plDrawCylinderDesc tDrawDesc4 = {0}; - gptDraw->fill_cylinder_desc_default(&tDrawDesc4); - tDrawDesc4.tColor = tYColor; tDrawDesc4.tBasePos = *ptCenter; tDrawDesc4.tTipPos = (plVec3){ptCenter->x, ptCenter->y + fLength, ptCenter->z}; tDrawDesc4.fRadius = fAxisRadius; - gptDraw->add_3d_cylinder_filled_ex(ptGizmoDrawlist, &tDrawDesc4); + gptDraw->add_3d_cylinder_filled(ptGizmoDrawlist, tDrawDesc4, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tYColor)}); // z axis plDrawCylinderDesc tDrawDesc5 = {0}; - gptDraw->fill_cylinder_desc_default(&tDrawDesc5); - tDrawDesc5.tColor = tZColor; tDrawDesc5.tBasePos = *ptCenter; tDrawDesc5.tTipPos = (plVec3){ptCenter->x, ptCenter->y, ptCenter->z + fLength}; tDrawDesc5.fRadius = fAxisRadius; - gptDraw->add_3d_cylinder_filled_ex(ptGizmoDrawlist, &tDrawDesc5); + gptDraw->add_3d_cylinder_filled(ptGizmoDrawlist, tDrawDesc5, (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tZColor)}); // x end gptDraw->add_3d_centered_box_filled(ptGizmoDrawlist, @@ -1174,7 +1176,7 @@ pl__gizmo_scale(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCamer fAxisRadius * 4, fAxisRadius * 4, fAxisRadius * 4, - tXColor); + (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXColor)}); // y end gptDraw->add_3d_centered_box_filled(ptGizmoDrawlist, @@ -1182,7 +1184,7 @@ pl__gizmo_scale(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCamer fAxisRadius * 4, fAxisRadius * 4, fAxisRadius * 4, - tYColor); + (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tYColor)}); // z end gptDraw->add_3d_centered_box_filled(ptGizmoDrawlist, @@ -1190,7 +1192,7 @@ pl__gizmo_scale(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCamer fAxisRadius * 4, fAxisRadius * 4, fAxisRadius * 4, - tZColor); + (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tZColor)}); // origin gptDraw->add_3d_centered_box_filled(ptGizmoDrawlist, @@ -1198,5 +1200,5 @@ pl__gizmo_scale(plGizmoData* ptGizmoData, plDrawList3D* ptGizmoDrawlist, plCamer fAxisRadius * 4, fAxisRadius * 4, fAxisRadius * 4, - tXYZColor); + (plDrawSolidOptions){.uColor = PL_COLOR_32_VEC4(tXYZColor)}); } \ No newline at end of file