Added some basic font rendering and texas holdem
This commit is contained in:
47
src/display/gui/font.c
Normal file
47
src/display/gui/font.c
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "font.h"
|
||||
|
||||
tilesetdiv_t * fontGetCharacterDivision(tileset_t *tileset, char character) {
|
||||
int32_t i = ((int32_t)character) - FONT_CHAR_START;
|
||||
return tileset->divisions + i;
|
||||
}
|
||||
|
||||
void fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
char *string, float x, float y, float z, float charWidth, float charHeight
|
||||
) {
|
||||
int32_t i;
|
||||
char c;
|
||||
tilesetdiv_t *div;
|
||||
float cx, cy;
|
||||
|
||||
i = 0;
|
||||
cx = x, cy = y;
|
||||
|
||||
while(true) {
|
||||
c = string[i];
|
||||
if(c == '\0') break;
|
||||
i++;
|
||||
|
||||
if(c == '\n') {
|
||||
cx = x;
|
||||
cy += charWidth;
|
||||
continue;
|
||||
} else if(c == ' ') {
|
||||
cx += charHeight;
|
||||
continue;
|
||||
}
|
||||
|
||||
div = fontGetCharacterDivision(tileset, c);
|
||||
spriteBatchQuad(batch, -1,
|
||||
cx, cy, z, charWidth, charHeight,
|
||||
div->x0, div->y0, div->x1, div->y1
|
||||
);
|
||||
cx += charWidth;
|
||||
}
|
||||
}
|
17
src/display/gui/font.h
Normal file
17
src/display/gui/font.h
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../spritebatch.h"
|
||||
|
||||
#define FONT_CHAR_START 33
|
||||
|
||||
tilesetdiv_t * fontGetCharacterDivision(tileset_t *tileset, char character);
|
||||
void fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
char *string, float x, float y, float z, float charWidth, float charHeight
|
||||
);
|
@ -14,7 +14,7 @@ tileset_t * tilesetCreate(
|
||||
int32_t borderX, int32_t borderY
|
||||
) {
|
||||
tileset_t *tileset;
|
||||
float divX, divY, tdivX;
|
||||
float tdivX, tdivY;
|
||||
int32_t x, y, i;
|
||||
|
||||
tileset = malloc(sizeof(tileset_t));
|
||||
@ -31,21 +31,30 @@ tileset_t * tilesetCreate(
|
||||
tileset->rows = rows;
|
||||
|
||||
// Calculate division sizes (pixels)
|
||||
divX = (width - (borderX * 2) - (gapX * (columns - 1))) / columns;
|
||||
divY = (height - (borderY * 2) - (gapY * (rows - 1))) / rows;
|
||||
tileset->divX = (width - (borderX * 2) - (gapX * (columns - 1))) / columns;
|
||||
tileset->divY = (height - (borderY * 2) - (gapY * (rows - 1))) / rows;
|
||||
|
||||
// Calculate the division sizes (units)
|
||||
divX = divX / width;
|
||||
divY = divY / height;
|
||||
tdivX = tileset->divX / width;
|
||||
tdivY = tileset->divY / height;
|
||||
|
||||
// Calculate the divisions
|
||||
// Calculate the divisions (in units)
|
||||
i = -1;
|
||||
for(y = 0; y < rows; y++) {
|
||||
for(x = 0; x < columns; x++) {
|
||||
tileset->divisions[++i].x0 = borderX + (divX * x) + (gapX * x);
|
||||
tileset->divisions[i].y0 = borderY + (divY * y) + (gapY * y);
|
||||
tileset->divisions[i].x1 = tileset->divisions[i].x0 + divX;
|
||||
tileset->divisions[i].y1 = tileset->divisions[i].y0 + divY;
|
||||
tileset->divisions[++i].x0 = (
|
||||
borderX + (tileset->divX * x) + (gapX * x)
|
||||
) / width;
|
||||
tileset->divisions[i].x1 = tileset->divisions[i].x0 + tdivX;
|
||||
|
||||
// tileset->divisions[i].y0 = (borderY + (divY * y) + (gapY * y)) / height;
|
||||
// tileset->divisions[i].y1 = tileset->divisions[i].y0 + tdivY;
|
||||
|
||||
// Vertically flipped for OpenGL
|
||||
tileset->divisions[i].y1 = (
|
||||
borderY + (tileset->divY * y) + (gapY * y)
|
||||
) / height;
|
||||
tileset->divisions[i].y0 = tileset->divisions[i].y1 + tdivY;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user