Render is color not uint8_t

This commit is contained in:
2025-09-11 22:20:21 -05:00
parent c8f8170ec2
commit 268e9ffefd
12 changed files with 64 additions and 53 deletions

View File

@@ -8,5 +8,6 @@ target_sources(${DUSK_TARGET_NAME}
PRIVATE
uitext.c
ui.c
uifps.c
uiconsole.c
)

View File

@@ -10,6 +10,7 @@
#include "display/framebuffer/framebuffer.h"
#include "display/spritebatch/spritebatch.h"
#include "uiconsole.h"
#include "uifps.h"
#include "util/memory.h"
ui_t UI;
@@ -51,6 +52,7 @@ void uiRender(void) {
cameraPushMatrix(&UI.camera);
uiConsoleRender();
uiFPSRender();
spriteBatchFlush();
cameraPopMatrix();

View File

@@ -20,10 +20,7 @@ void uiConsoleRender(void) {
i++;
continue;
}
uiTextDraw(
0, i * UI_TEXT_TILE_HEIGHT, line,
0xFF, 0xFF, 0xFF
);
uiTextDraw(0, i * UI_TEXT_TILE_HEIGHT, line, COLOR_WHITE);
i++;
} while(i < CONSOLE_HISTORY_MAX);
}

27
src/display/ui/uifps.c Normal file
View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "uifps.h"
#include "display/ui/uitext.h"
#include "time/time.h"
void uiFPSRender(void) {
float_t fps = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f;
char_t buffer[64];
snprintf(
buffer,
sizeof(buffer),
"FPS: %d",
(int32_t)fps
);
color_t color = fps >= 50.0f ? COLOR_GREEN :
(fps >= 30.0f ? COLOR_YELLOW : COLOR_RED);
uiTextDraw(0, 0, buffer, color);
}

11
src/display/ui/uifps.h Normal file
View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
void uiFPSRender(void);

View File

@@ -32,9 +32,7 @@ void uiTextDrawChar(
const float_t x,
const float_t y,
const char_t c,
const uint8_t r,
const uint8_t g,
const uint8_t b
const color_t color
) {
int32_t tileIndex = (int32_t)(c) - UI_TEXT_CHAR_START;
if(tileIndex < 0 || tileIndex >= UI_TEXT_TILE_COUNT) {
@@ -55,7 +53,7 @@ void uiTextDrawChar(
&UI_TEXT.asset->alphaImage.texture,
x, y,
x + UI_TEXT_TILE_WIDTH, y + UI_TEXT_TILE_HEIGHT,
r, g, b, 0xFF,
color,
(tileX * UI_TEXT_TILE_WIDTH) / w,
(tileY * UI_TEXT_TILE_HEIGHT) / h,
((tileX + 1) * UI_TEXT_TILE_WIDTH) / w,
@@ -67,9 +65,7 @@ void uiTextDraw(
const float_t x,
const float_t y,
const char_t *text,
const uint8_t r,
const uint8_t g,
const uint8_t b
const color_t color
) {
assertNotNull(text, "Text cannot be NULL");
@@ -90,7 +86,7 @@ void uiTextDraw(
continue;
}
uiTextDrawChar(posX, posY, c, r, g, b);
uiTextDrawChar(posX, posY, c, color);
posX += UI_TEXT_TILE_WIDTH;
}
}

View File

@@ -35,17 +35,13 @@ errorret_t uiTextInit(void);
* @param x The x-coordinate to draw the character at.
* @param y The y-coordinate to draw the character at.
* @param c The character to draw.
* @param r The red component of the color (0-255).
* @param g The green component of the color (0-255).
* @param b The blue component of the color (0-255).
* @param color The color to draw the character in.
*/
void uiTextDrawChar(
const float_t x,
const float_t y,
const char_t c,
const uint8_t r,
const uint8_t g,
const uint8_t b
const color_t color
);
/**
@@ -54,17 +50,13 @@ void uiTextDrawChar(
* @param x The x-coordinate to draw the text at.
* @param y The y-coordinate to draw the text at.
* @param text The null-terminated string of text to draw.
* @param r The red component of the color (0-255).
* @param g The green component of the color (0-255).
* @param b The blue component of the color (0-255).
* @param color The color to draw the text in.
*/
void uiTextDraw(
const float_t x,
const float_t y,
const char_t *text,
const uint8_t r,
const uint8_t g,
const uint8_t b
const color_t color
);
/**