Process tileset.

This commit is contained in:
2025-09-12 12:43:56 -05:00
parent 46a94ecacd
commit 9b98181d28
18 changed files with 205 additions and 47 deletions

View File

@@ -17,7 +17,7 @@ errorret_t uiTextInit(void) {
memoryZero(&UI_TEXT, sizeof(uitext_t));
errorChain(assetManagerLoadAsset(
"font_minogram.dai", &UI_TEXT.asset, &UI_TEXT.assetRef
TILESET_FONT_MINOGRAM.image, &UI_TEXT.asset, &UI_TEXT.assetRef
));
errorOk();
}
@@ -35,29 +35,25 @@ void uiTextDrawChar(
const color_t color
) {
int32_t tileIndex = (int32_t)(c) - UI_TEXT_CHAR_START;
if(tileIndex < 0 || tileIndex >= UI_TEXT_TILE_COUNT) {
if(tileIndex < 0 || tileIndex >= TILESET_FONT_MINOGRAM.tileCount) {
tileIndex = ((int32_t)'@') - UI_TEXT_CHAR_START;
}
assertTrue(
tileIndex >= 0 && tileIndex <= UI_TEXT_TILE_COUNT,
tileIndex >= 0 && tileIndex <= TILESET_FONT_MINOGRAM.tileCount,
"Character is out of bounds for font tiles"
);
const float_t w = (float)UI_TEXT.asset->alphaImage.texture.width;
const float_t h = (float)UI_TEXT.asset->alphaImage.texture.height;
const int32_t tileX = (tileIndex % UI_TEXT_COLUMN_COUNT);
const int32_t tileY = (tileIndex / UI_TEXT_COLUMN_COUNT);
vec4 uv;
tilesetTileGetUV(&TILESET_FONT_MINOGRAM, tileIndex, uv);
spriteBatchPush(
&UI_TEXT.asset->alphaImage.texture,
x, y,
x + UI_TEXT_TILE_WIDTH, y + UI_TEXT_TILE_HEIGHT,
x + TILESET_FONT_MINOGRAM.tileWidth,
y + TILESET_FONT_MINOGRAM.tileHeight,
color,
(tileX * UI_TEXT_TILE_WIDTH) / w,
(tileY * UI_TEXT_TILE_HEIGHT) / h,
((tileX + 1) * UI_TEXT_TILE_WIDTH) / w,
((tileY + 1) * UI_TEXT_TILE_HEIGHT) / h
uv[0], uv[1], uv[2], uv[3]
);
}
@@ -77,17 +73,17 @@ void uiTextDraw(
while((c = text[i++]) != '\0') {
if(c == '\n') {
posX = x;
posY += UI_TEXT_TILE_HEIGHT;
posY += TILESET_FONT_MINOGRAM.tileHeight;
continue;
}
if(c == ' ') {
posX += UI_TEXT_TILE_WIDTH;
posX += TILESET_FONT_MINOGRAM.tileWidth;
continue;
}
uiTextDrawChar(posX, posY, c, color);
posX += UI_TEXT_TILE_WIDTH;
posX += TILESET_FONT_MINOGRAM.tileWidth;
}
}
@@ -101,7 +97,7 @@ void uiTextMeasure(
assertNotNull(outHeight, "Output height pointer cannot be NULL");
int32_t width = 0;
int32_t height = UI_TEXT_TILE_HEIGHT;
int32_t height = TILESET_FONT_MINOGRAM.tileHeight;
int32_t lineWidth = 0;
char_t c;
@@ -112,11 +108,11 @@ void uiTextMeasure(
width = lineWidth;
}
lineWidth = 0;
height += UI_TEXT_TILE_HEIGHT;
height += TILESET_FONT_MINOGRAM.tileHeight;
continue;
}
lineWidth += UI_TEXT_TILE_WIDTH;
lineWidth += TILESET_FONT_MINOGRAM.tileWidth;
}
if(lineWidth > width) {