Working on model loading and added poker table
This commit is contained in:
@ -12,14 +12,74 @@ tilesetdiv_t * fontGetCharacterDivision(tileset_t *tileset, char character) {
|
||||
return tileset->divisions + i;
|
||||
}
|
||||
|
||||
void fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
fontmeasure_t fontMeasure(char *string, float charWidth, float charHeight) {
|
||||
int32_t i;
|
||||
float x, y;
|
||||
char c;
|
||||
fontmeasure_t measure = {
|
||||
.height = 0, .lines = 1, .width = 0
|
||||
};
|
||||
|
||||
i = 0;
|
||||
y = 0;
|
||||
x = 0;
|
||||
|
||||
while(true) {
|
||||
c = string[i];
|
||||
if(c == '\0') break;
|
||||
i++;
|
||||
|
||||
if(c == '\n') {
|
||||
measure.width = mathMax(x, measure.width);
|
||||
x = 0;
|
||||
y += charHeight;
|
||||
measure.lines++;
|
||||
continue;
|
||||
} else if(c == ' ') {
|
||||
x += charWidth;
|
||||
continue;
|
||||
}
|
||||
|
||||
x += charWidth;
|
||||
}
|
||||
|
||||
measure.width = mathMax(x, measure.width);
|
||||
measure.height = y + charHeight;
|
||||
|
||||
return measure;
|
||||
}
|
||||
|
||||
fontmeasure_t 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;
|
||||
fontmeasure_t measure;
|
||||
|
||||
// Detect char dimensions
|
||||
if(charWidth == -1) charWidth = tileset->divX * (charHeight / tileset->divY);
|
||||
if(charHeight == -1) charHeight = tileset->divY * (charWidth / tileset->divX);
|
||||
|
||||
// Position the text.
|
||||
if(x == FONT_CENTER_X ||
|
||||
y == FONT_CENTER_Y ||
|
||||
x == FONT_RIGHT_X
|
||||
) {
|
||||
measure = fontMeasure(string, charWidth, charHeight);
|
||||
if(x == FONT_CENTER_X) {
|
||||
x = -(measure.width/2);
|
||||
} else if(x == FONT_RIGHT_X) {
|
||||
x = -measure.width;
|
||||
}
|
||||
if(y == FONT_CENTER_Y) y = -(measure.height/2);
|
||||
}
|
||||
|
||||
// Begin buffering the sprite batch
|
||||
measure.width = 0;
|
||||
measure.height = 0;
|
||||
measure.lines = 1;
|
||||
i = 0;
|
||||
cx = x, cy = y;
|
||||
|
||||
@ -28,20 +88,28 @@ void fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
if(c == '\0') break;
|
||||
i++;
|
||||
|
||||
// Special chars
|
||||
if(c == '\n') {
|
||||
measure.width = mathMax(cx-x, measure.width);
|
||||
cx = x;
|
||||
cy += charWidth;
|
||||
cy += charHeight;
|
||||
measure.lines++;
|
||||
continue;
|
||||
} else if(c == ' ') {
|
||||
cx += charHeight;
|
||||
cx += charWidth;
|
||||
continue;
|
||||
}
|
||||
|
||||
div = fontGetCharacterDivision(tileset, c);
|
||||
spriteBatchQuad(batch, -1,
|
||||
cx, cy, z, charWidth, charHeight,
|
||||
div->x0, div->y0, div->x1, div->y1
|
||||
div->x0, div->y1, div->x1, div->y0
|
||||
);
|
||||
cx += charWidth;
|
||||
}
|
||||
|
||||
measure.width = mathMax(cx-x, measure.width);
|
||||
measure.height = cy-y + charHeight;
|
||||
|
||||
return measure;
|
||||
}
|
@ -8,8 +8,7 @@
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../spritebatch.h"
|
||||
|
||||
#define FONT_CHAR_START 33
|
||||
#include "../../util/math.h"
|
||||
|
||||
/**
|
||||
* Get the division for a given character.
|
||||
@ -20,6 +19,16 @@
|
||||
*/
|
||||
tilesetdiv_t * fontGetCharacterDivision(tileset_t *tileset, char character);
|
||||
|
||||
/**
|
||||
* Measures a string's fully rendered size.
|
||||
*
|
||||
* @param string The string to measure
|
||||
* @param charWidth The width of each character.
|
||||
* @param charHeight The height of each character.
|
||||
* @return The measured string.
|
||||
*/
|
||||
fontmeasure_t fontMeasure(char *string, float charWidth, float charHeight);
|
||||
|
||||
/**
|
||||
* Renders a set of font characters to the sprite. Coordinates are anchored to
|
||||
* the top left (0,0) origin.
|
||||
@ -30,9 +39,10 @@ tilesetdiv_t * fontGetCharacterDivision(tileset_t *tileset, char character);
|
||||
* @param x Position in X space.
|
||||
* @param y Position in Y space.
|
||||
* @param z Position in Z space.
|
||||
* @param charWidth Width of each character.
|
||||
* @param charHeight Height of each character.
|
||||
* @param charWidth Width of each character. Set to -1 to use the height ratio.
|
||||
* @param charHeight Height of each character. Set to -1 to be the width ratio.
|
||||
* @returns The string measurement.
|
||||
*/
|
||||
void fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
fontmeasure_t fontSpriteBatchBuffer(spritebatch_t *batch, tileset_t *tileset,
|
||||
char *string, float x, float y, float z, float charWidth, float charHeight
|
||||
);
|
Reference in New Issue
Block a user