Added font sizing, needs full testing
This commit is contained in:
@ -42,6 +42,7 @@
|
||||
#include "game/poker/pokergame.h"
|
||||
#include "game/poker/pokerdiscussion.h"
|
||||
#include "game/poker/pokergameassets.h"
|
||||
#include "game/poker/pokerui.h"
|
||||
|
||||
// Player Input
|
||||
#include "input/input.h"
|
||||
@ -57,6 +58,9 @@
|
||||
#include "poker/poker.h"
|
||||
#include "poker/winner.h"
|
||||
|
||||
// User Interface Objects
|
||||
#include "ui/label.h"
|
||||
|
||||
// Utility Objects
|
||||
#include "util/array.h"
|
||||
#include "util/list.h"
|
||||
|
@ -24,8 +24,11 @@
|
||||
/** Refer to STBTT docs for OpenGL Fill Mode v d3d Fill Modes */
|
||||
#define FONT_FILL_MODE 1
|
||||
|
||||
/** Passed to STBTT for scaling the font nicely, essentially the font size. */
|
||||
#define FONT_TEXTURE_SIZE 32
|
||||
/** Passed to STBTT for scaling the font, essentially the font resolution */
|
||||
#define FONT_TEXTURE_SIZE 64
|
||||
|
||||
/** Default Font Size (on which all font scales are based) */
|
||||
#define FONT_SIZE_DEFAULT (FONT_TEXTURE_SIZE / 2)
|
||||
|
||||
// Chars
|
||||
#define FONT_NEWLINE '\n'
|
||||
|
@ -9,5 +9,5 @@
|
||||
#include "../../libs.h"
|
||||
|
||||
typedef struct {
|
||||
|
||||
int32_t INeedSomePropertyToStopCompilerComplaining;
|
||||
} dawngame_t;
|
14
include/dawn/game/poker/pokerui.h
Normal file
14
include/dawn/game/poker/pokerui.h
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../ui/label.h"
|
||||
|
||||
typedef struct {
|
||||
label_t labelTest;
|
||||
} pokerui_t;
|
@ -11,4 +11,4 @@
|
||||
#define SETTING_GAME_DAWN 2
|
||||
|
||||
// Settings
|
||||
#define SETTING_GAME SETTING_GAME_DAWN
|
||||
#define SETTING_GAME SETTING_GAME_POKER
|
20
include/dawn/ui/label.h
Normal file
20
include/dawn/ui/label.h
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../display/primitive.h"
|
||||
#include "../display/gui/font.h"
|
||||
|
||||
/** Representation of a Label UI Element */
|
||||
typedef struct {
|
||||
font_t *font;
|
||||
float x, y, z;
|
||||
float fontSize;
|
||||
fonttextinfo_t info;
|
||||
primitive_t primitive;
|
||||
} label_t;
|
@ -13,6 +13,8 @@
|
||||
/** Amount of characters scrolled, per second */
|
||||
#define VN_TEXTBOX_SCROLL_SPEED 60
|
||||
|
||||
#define VN_TEXTBOX_FONT_SIZE 16.0
|
||||
|
||||
#define VN_TEXTBOX_STATE_CLOSED 0x01
|
||||
|
||||
typedef struct {
|
||||
|
@ -44,6 +44,10 @@ void fontDispose(font_t *font) {
|
||||
textureDispose(&font->texture);
|
||||
}
|
||||
|
||||
float fontGetScale(float fontSize) {
|
||||
return fontSize / FONT_SIZE_DEFAULT;
|
||||
}
|
||||
|
||||
void fontTextBuffer(font_t *font, primitive_t *primitive, fonttextinfo_t *info){
|
||||
stbtt_aligned_quad *quad;
|
||||
int32_t i;
|
||||
@ -66,13 +70,19 @@ void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info) {
|
||||
}
|
||||
|
||||
void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
float maxWidth
|
||||
float maxWidth, float fontSize
|
||||
) {
|
||||
int32_t i, j, wordIndex;
|
||||
char c;
|
||||
float x, y, wordX;
|
||||
float x, y, wordX, scale;
|
||||
stbtt_aligned_quad *quad;
|
||||
|
||||
// Get the font scale
|
||||
scale = fontGetScale(fontSize);
|
||||
|
||||
// Adjust the max width to match the scale, and allow "no max width".
|
||||
maxWidth = maxWidth == -1 ? 999999 : maxWidth * (1 / scale);
|
||||
|
||||
/** Which index in the original text var is the current word from */
|
||||
int32_t wordStart = 0;
|
||||
|
||||
@ -98,7 +108,7 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
|
||||
// When space, start of new word about to begin
|
||||
if(c == FONT_SPACE) {
|
||||
x += FONT_SPACE_SIZE;
|
||||
x += FONT_SPACE_SIZE * scale;
|
||||
|
||||
// Did this space cause a newline?
|
||||
if(x > maxWidth) {
|
||||
@ -106,7 +116,7 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
info->lines[info->lineCount].start = info->realLength;
|
||||
info->lines[info->lineCount].length = 0;
|
||||
|
||||
y += FONT_LINE_HEIGHT;
|
||||
y += FONT_LINE_HEIGHT * scale;
|
||||
x = 0;
|
||||
}
|
||||
wordX = x;
|
||||
@ -121,7 +131,7 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
info->lines[info->lineCount].length = 0;
|
||||
|
||||
wordStart = info->realLength;
|
||||
y += FONT_LINE_HEIGHT;
|
||||
y += FONT_LINE_HEIGHT * scale;
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
@ -139,8 +149,10 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
x = quad->x1 - wordX;
|
||||
for(j = wordStart; j <= info->realLength; j++) {
|
||||
quad = info->quads + j;
|
||||
quad->x0 -= wordX, quad->x1 -= wordX;
|
||||
quad->y0 += FONT_LINE_HEIGHT, quad->y1 += FONT_LINE_HEIGHT;
|
||||
quad->x0 -= wordX;
|
||||
quad->x1 -= wordX;
|
||||
quad->y0 += FONT_LINE_HEIGHT;
|
||||
quad->y1 += FONT_LINE_HEIGHT;
|
||||
}
|
||||
|
||||
// Go back to the previous (still current) line and remove the chars
|
||||
@ -163,6 +175,16 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
|
||||
for(j = 0; j < info->realLength; j++) {
|
||||
quad = info->quads + j;
|
||||
|
||||
// Scale the Quad
|
||||
if(scale != 1.0) {
|
||||
quad->x0 *= scale;
|
||||
quad->x1 *= scale;
|
||||
quad->y0 *= scale;
|
||||
quad->y1 *= scale;
|
||||
}
|
||||
|
||||
// Update the dimensions.
|
||||
info->width = mathMax(info->width, quad->x1);
|
||||
info->height = mathMax(info->height, quad->y1);
|
||||
}
|
||||
|
@ -45,6 +45,14 @@ void fontTextBuffer(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
|
||||
*/
|
||||
void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
|
||||
|
||||
/**
|
||||
* Convert a Font's Size into a Font Scale. The scale is based on the font's
|
||||
* default size for the given texture size (Refer to FONT_SIZE_DEFAULT).
|
||||
*
|
||||
* @param fontSize Font size to convert.
|
||||
* @return The times scale that the font size is to the textured default.
|
||||
*/
|
||||
float fontGetScale(float fontSize);
|
||||
|
||||
/**
|
||||
* Clamps text to a max width, inserting newlines where possible.
|
||||
@ -52,10 +60,11 @@ void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
|
||||
* @param font Font to use
|
||||
* @param info Font text info to clamp into.
|
||||
* @param text Text to clamp.
|
||||
* @param maxWidth Max width (in pixels) to clamp the text to.
|
||||
* @param maxWidth Max width (pixels) to clamp the text to, -1 for no max width.
|
||||
* @param fontSize Font Size of the text.
|
||||
*/
|
||||
void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
float maxWidth
|
||||
float maxWidth, float fontSize
|
||||
);
|
||||
|
||||
/**
|
||||
|
20
src/game/dawn/dawngame.c
Normal file
20
src/game/dawn/dawngame.c
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dawngame.h"
|
||||
|
||||
bool dawnGameInit(game_t *game) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void dawnGameUpdate(game_t *game) {
|
||||
|
||||
}
|
||||
|
||||
void dawnGameDispose(game_t *game) {
|
||||
|
||||
}
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "pokergame.h"
|
||||
|
||||
label_t label;
|
||||
|
||||
bool pokerGameInit(game_t *game) {
|
||||
pokergame_t *pokerGame = &game->pokerGame;
|
||||
|
||||
@ -20,6 +22,11 @@ bool pokerGameInit(game_t *game) {
|
||||
vnSceneInit(&pokerGame->scene, &pokerGame->assets.font);
|
||||
pokerGameActionStartAdd(pokerGame);
|
||||
|
||||
labelInit(&label);
|
||||
label.y = 32;
|
||||
label.fontSize = 8.0;
|
||||
labelSetText(&label, &pokerGame->assets.font, "Hello World");
|
||||
|
||||
// pokerActionMatchAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
// pokerActionMatchAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
// pokerActionRoundAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
@ -48,6 +55,7 @@ void pokerGameUpdate(game_t *game) {
|
||||
// Render the visual novel scene
|
||||
vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
|
||||
vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
|
||||
labelRender(&label, &pokerGame->assets.shader);
|
||||
}
|
||||
|
||||
void pokerGameDispose(game_t *game) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "../../vn/vnscene.h"
|
||||
#include "actions/start.h"
|
||||
|
||||
#include "../../ui/label.h"
|
||||
|
||||
/**
|
||||
* Initializes the game state for the poker game.
|
||||
*
|
||||
|
12
src/game/poker/pokerui.c
Normal file
12
src/game/poker/pokerui.c
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "pokerui.h"
|
||||
|
||||
void pokerUiInit(pokerui_t *ui) {
|
||||
|
||||
}
|
12
src/game/poker/pokerui.h
Normal file
12
src/game/poker/pokerui.h
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 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 "../../ui/label.h"
|
||||
|
||||
void pokerUiInit(pokerui_t *ui);
|
39
src/ui/label.c
Normal file
39
src/ui/label.c
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "label.h"
|
||||
|
||||
void labelInit(label_t *label) {
|
||||
label->x = 0;
|
||||
label->y = 0;
|
||||
label->z = 0;
|
||||
label->fontSize = FONT_SIZE_DEFAULT;
|
||||
label->font = NULL;
|
||||
label->primitive.verticeCount = 0;
|
||||
}
|
||||
|
||||
void labelSetText(label_t *label, font_t *font, char *text) {
|
||||
if(label->primitive.verticeCount != 0) {
|
||||
primitiveDispose(&label->primitive);
|
||||
label->primitive.verticeCount = 0;
|
||||
}
|
||||
|
||||
label->font = font;
|
||||
fontTextClamp(font, &label->info, text, -1, 16.0);
|
||||
fontTextInit(font, &label->primitive, &label->info);
|
||||
}
|
||||
|
||||
void labelRender(label_t *label, shader_t *shader) {
|
||||
if(label->primitive.verticeCount == 0) return;
|
||||
shaderUsePosition(shader, label->x, label->y, label->z, 0, 0, 0);
|
||||
shaderUseTexture(shader, &label->font->texture);
|
||||
primitiveDraw(&label->primitive, 0, -1);
|
||||
}
|
||||
|
||||
void labelDispose(label_t *label) {
|
||||
primitiveDispose(&label->primitive);
|
||||
}
|
18
src/ui/label.h
Normal file
18
src/ui/label.h
Normal file
@ -0,0 +1,18 @@
|
||||
// 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 "../display/shader.h"
|
||||
#include "../display/primitive.h"
|
||||
#include "../display/gui/font.h"
|
||||
|
||||
void labelInit(label_t *label);
|
||||
|
||||
void labelSetText(label_t *label, font_t *font, char *text);
|
||||
|
||||
void labelRender(label_t *label, shader_t *shader);
|
||||
|
||||
void labelDispose(label_t *label);
|
@ -33,7 +33,9 @@ void vnTextBoxRebuffer(vntextbox_t *box) {
|
||||
if(box->text == NULL) return;
|
||||
|
||||
// Rebuffer the text.
|
||||
fontTextClamp(box->font, &box->textInfo, box->text, box->widthMax);
|
||||
fontTextClamp(
|
||||
box->font, &box->textInfo, box->text, box->widthMax, VN_TEXTBOX_FONT_SIZE
|
||||
);
|
||||
fontTextInit(box->font, &box->primitive, &box->textInfo);
|
||||
|
||||
// Test "Background"
|
||||
|
Reference in New Issue
Block a user