From ea7cfcf210a077ac90619617be67025241587e12 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Thu, 22 May 2025 11:55:14 +1200 Subject: [PATCH] Rename a few things and replace floor with int truncate --- examples/terminal-example/main.c | 2 +- renderers/terminal/clay_renderer_terminal_ansi.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/terminal-example/main.c b/examples/terminal-example/main.c index b77e7bf..de666e9 100644 --- a/examples/terminal-example/main.c +++ b/examples/terminal-example/main.c @@ -31,7 +31,7 @@ int main() { while (true) { Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(&demoData); - Clay_Console_Render(renderCommands, width, height, columnWidth); + Clay_Terminal_Render(renderCommands, width, height, columnWidth); fflush(stdout); sleep(1); diff --git a/renderers/terminal/clay_renderer_terminal_ansi.c b/renderers/terminal/clay_renderer_terminal_ansi.c index 66e676e..d73f735 100644 --- a/renderers/terminal/clay_renderer_terminal_ansi.c +++ b/renderers/terminal/clay_renderer_terminal_ansi.c @@ -2,7 +2,6 @@ #include "string.h" #include "stdio.h" #include "stdlib.h" -#include "math.h" #ifdef CLAY_OVERFLOW_TRAP #include "signal.h" @@ -29,7 +28,7 @@ static inline void Console_DrawRectangle(int x0, int y0, int width, int height, } Console_MoveCursor(x, y); - // TODO there are only two colors actually drawn, the background and white + // TODO this should be replaced by a better logarithmic scale if we're doing black and white if (average > 0.75) { printf("█"); } else if (average > 0.5) { @@ -73,7 +72,7 @@ Console_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void return textSize; } -void Clay_Console_Render(Clay_RenderCommandArray renderCommands, int width, int height, int columnWidth) { +void Clay_Terminal_Render(Clay_RenderCommandArray renderCommands, int width, int height, int columnWidth) { printf("\033[H\033[J"); // Clear const Clay_BoundingBox fullWindow = { @@ -88,10 +87,10 @@ void Clay_Console_Render(Clay_RenderCommandArray renderCommands, int width, int for (int j = 0; j < renderCommands.length; j++) { Clay_RenderCommand *renderCommand = Clay_RenderCommandArray_Get(&renderCommands, j); Clay_BoundingBox boundingBox = (Clay_BoundingBox) { - .x = floorf((renderCommand->boundingBox.x / columnWidth) + 0.5), - .y = floorf((renderCommand->boundingBox.y / columnWidth) + 0.5), - .width = floorf((renderCommand->boundingBox.width / columnWidth) + 0.5), - .height = floorf((renderCommand->boundingBox.height / columnWidth) + 0.5), + .x = (int)((renderCommand->boundingBox.x / columnWidth) + 0.5), + .y = (int)((renderCommand->boundingBox.y / columnWidth) + 0.5), + .width = (int)((renderCommand->boundingBox.width / columnWidth) + 0.5), + .height = (int)((renderCommand->boundingBox.height / columnWidth) + 0.5), }; switch (renderCommand->commandType) { case CLAY_RENDER_COMMAND_TYPE_TEXT: {