Fixed more font stuff, works really really good now.
This commit is contained in:
src
dawn
display/font
scene/components/scene
ui
visualnovel/ui
dawnpokergame
dawntools
@ -37,12 +37,17 @@ float_t TrueTypeFont::getScale(float_t scale) {
|
|||||||
|
|
||||||
float_t TrueTypeFont::getSpaceSize(float_t fontSize) {
|
float_t TrueTypeFont::getSpaceSize(float_t fontSize) {
|
||||||
assertTrue(fontSize > 0);
|
assertTrue(fontSize > 0);
|
||||||
return mathRound<float_t>(this->fontSize * 0.3f);
|
return mathRound<float_t>(this->getScale(fontSize) * 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t TrueTypeFont::getInitialLineHeight(float_t fontSize) {
|
float_t TrueTypeFont::getInitialLineHeight(float_t fontSize) {
|
||||||
assertTrue(fontSize > 0);
|
assertTrue(fontSize > 0);
|
||||||
return 8.0f;
|
return mathRound<float_t>(42.0f * this->getScale(fontSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
float_t TrueTypeFont::getLineHeight(float_t fontSize) {
|
||||||
|
assertTrue(fontSize > 0);
|
||||||
|
return mathRound<float_t>(58.0f * this->getScale(fontSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrueTypeFont::buffer(
|
void TrueTypeFont::buffer(
|
||||||
@ -100,7 +105,7 @@ void TrueTypeFont::buffer(
|
|||||||
// Setup the initial loop state, and X/Y coords for the quad.
|
// Setup the initial loop state, and X/Y coords for the quad.
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
float_t x = 0;
|
float_t x = 0;
|
||||||
float_t y = this->getInitialLineHeight(fontSize);
|
float_t y = this->getInitialLineHeight(fontSize) / scale;
|
||||||
float_t wordX = 0;
|
float_t wordX = 0;
|
||||||
char c;
|
char c;
|
||||||
while(c = text[i++]) {
|
while(c = text[i++]) {
|
||||||
@ -108,12 +113,12 @@ void TrueTypeFont::buffer(
|
|||||||
|
|
||||||
// When space, start of new word about to begin
|
// When space, start of new word about to begin
|
||||||
if(c == FONT_SPACE) {
|
if(c == FONT_SPACE) {
|
||||||
x += this->getSpaceSize(fontSize);
|
x += this->getSpaceSize(fontSize) / scale;
|
||||||
|
|
||||||
// Did this space cause a newline?
|
// Did this space cause a newline?
|
||||||
if(x > maxWidth) {
|
if(x > maxWidth) {
|
||||||
info->addLine(info->realLength, 0);
|
info->addLine(info->realLength, 0);
|
||||||
y += this->getLineHeight(fontSize);
|
y += this->getLineHeight(fontSize) / scale;
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
wordX = x;
|
wordX = x;
|
||||||
@ -125,7 +130,7 @@ void TrueTypeFont::buffer(
|
|||||||
if(c == FONT_NEWLINE) {
|
if(c == FONT_NEWLINE) {
|
||||||
info->addLine(info->realLength, 0);
|
info->addLine(info->realLength, 0);
|
||||||
wordStart = info->realLength;
|
wordStart = info->realLength;
|
||||||
y += this->getLineHeight(fontSize);
|
y += this->getLineHeight(fontSize) / scale;
|
||||||
x = 0;
|
x = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -142,15 +147,15 @@ void TrueTypeFont::buffer(
|
|||||||
quad = quads + j;
|
quad = quads + j;
|
||||||
quad->x0 -= wordX;
|
quad->x0 -= wordX;
|
||||||
quad->x1 -= wordX;
|
quad->x1 -= wordX;
|
||||||
quad->y0 += this->getLineHeight(fontSize);
|
quad->y0 += this->getLineHeight(fontSize) / scale;
|
||||||
quad->y1 += this->getLineHeight(fontSize);
|
quad->y1 += this->getLineHeight(fontSize) / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go back to the previous (still current) line and remove the chars
|
// Go back to the previous (still current) line and remove the chars
|
||||||
info->lines[info->lines.size() - 1].length -= info->realLength - wordStart;
|
info->lines[info->lines.size() - 1].length -= info->realLength - wordStart;
|
||||||
|
|
||||||
// Next line begins with this word
|
// Next line begins with this word
|
||||||
y += this->getLineHeight(fontSize);
|
y += this->getLineHeight(fontSize) / scale;
|
||||||
info->addLine(wordStart, info->realLength-wordStart);
|
info->addLine(wordStart, info->realLength-wordStart);
|
||||||
wordX = 0;
|
wordX = 0;
|
||||||
}
|
}
|
||||||
@ -208,11 +213,6 @@ void TrueTypeFont::draw(Mesh *mesh, int32_t startchar, int32_t length) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t TrueTypeFont::getLineHeight(float_t fontSize) {
|
|
||||||
assertTrue(fontSize > 0);
|
|
||||||
return 13.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t TrueTypeFont::getDefaultFontSize() {
|
float_t TrueTypeFont::getDefaultFontSize() {
|
||||||
return (float_t)this->fontSize;
|
return (float_t)this->fontSize;
|
||||||
}
|
}
|
@ -43,7 +43,6 @@ void SubSceneCameraAlign::realign() {
|
|||||||
this->camera->orthoLeft = diff;
|
this->camera->orthoLeft = diff;
|
||||||
this->camera->orthoRight = this->renderTarget->getWidth() - diff;
|
this->camera->orthoRight = this->renderTarget->getWidth() - diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubSceneCameraAlign::setRenderTarget(TextureRenderTarget *renderTarget) {
|
void SubSceneCameraAlign::setRenderTarget(TextureRenderTarget *renderTarget) {
|
||||||
|
@ -75,6 +75,11 @@ void UIComponent::updatePositions() {
|
|||||||
this->relativeY = (this->relativeY / 2.0f) - (this->height / 2.0f) + this->alignment[1];
|
this->relativeY = (this->relativeY / 2.0f) - (this->height / 2.0f) + this->alignment[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->relativeX = mathRound<float_t>(this->relativeX);
|
||||||
|
this->relativeY = mathRound<float_t>(this->relativeY);
|
||||||
|
this->width = mathRound<float_t>(this->width);
|
||||||
|
this->height = mathRound<float_t>(this->height);
|
||||||
|
|
||||||
// Update children
|
// Update children
|
||||||
auto it = this->children.begin();
|
auto it = this->children.begin();
|
||||||
while(it != this->children.end()) {
|
while(it != this->children.end()) {
|
||||||
|
@ -176,6 +176,10 @@ void VisualNovelTextbox::setLabelPadding(glm::vec2 padding) {
|
|||||||
this->updatePositions();
|
this->updatePositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec2 VisualNovelTextbox::getLabelPadding() {
|
||||||
|
return this->labelPadding;
|
||||||
|
}
|
||||||
|
|
||||||
bool_t VisualNovelTextbox::hasRevealedAllCurrentCharacters() {
|
bool_t VisualNovelTextbox::hasRevealedAllCurrentCharacters() {
|
||||||
int32_t quadsTotal = 0;
|
int32_t quadsTotal = 0;
|
||||||
for(
|
for(
|
||||||
|
@ -113,6 +113,13 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
void setLabelPadding(glm::vec2 padding);
|
void setLabelPadding(glm::vec2 padding);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current label padding.
|
||||||
|
*
|
||||||
|
* @return The current label padding.
|
||||||
|
*/
|
||||||
|
glm::vec2 getLabelPadding();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if all of the characters that can be made visible for the
|
* Returns true if all of the characters that can be made visible for the
|
||||||
* current textbox size have finished revealing, or false if not.
|
* current textbox size have finished revealing, or false if not.
|
||||||
|
@ -40,9 +40,9 @@ tool_tileset(tileset_cards texture_cards ${DIR_GAME_ASSETS}/cards.png 14 4)
|
|||||||
tool_truetype(truetype_ark
|
tool_truetype(truetype_ark
|
||||||
ark-pixel.ttf
|
ark-pixel.ttf
|
||||||
truetype_ark
|
truetype_ark
|
||||||
96
|
2048
|
||||||
96
|
2048
|
||||||
10
|
60
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(${DAWN_TARGET_NAME}
|
add_dependencies(${DAWN_TARGET_NAME}
|
||||||
|
@ -19,7 +19,7 @@ namespace Dawn {
|
|||||||
static void prefabApply(AssetManager *man, UIBorder *border) {
|
static void prefabApply(AssetManager *man, UIBorder *border) {
|
||||||
auto text = man->get<TextureAsset>("texture_test");
|
auto text = man->get<TextureAsset>("texture_test");
|
||||||
border->texture = &text->texture;
|
border->texture = &text->texture;
|
||||||
border->setBorderSize(glm::vec2(8, 8));
|
border->setBorderSize(glm::vec2(4, 4));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -22,11 +22,18 @@ namespace Dawn {
|
|||||||
auto assetFont = man->get<TrueTypeAsset>("truetype_ark");
|
auto assetFont = man->get<TrueTypeAsset>("truetype_ark");
|
||||||
UIBorderPrefab::apply(&textbox->border);
|
UIBorderPrefab::apply(&textbox->border);
|
||||||
textbox->setFont(&assetFont->font);
|
textbox->setFont(&assetFont->font);
|
||||||
textbox->setFontSize(11);
|
textbox->setFontSize(10.0f);
|
||||||
textbox->setLabelPadding(glm::vec2(4, 4));
|
textbox->setLabelPadding(glm::vec2(2, 2));
|
||||||
|
|
||||||
textbox->setTransform(
|
textbox->setTransform(
|
||||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
|
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
|
||||||
glm::vec4(0, assetFont->font.getLineHeight(textbox->getFontSize()) * 4, 0, 0),
|
glm::vec4(
|
||||||
|
0,
|
||||||
|
(assetFont->font.getLineHeight(textbox->getFontSize()) * 4) +
|
||||||
|
(textbox->border.getBorderSize().y * 2.0f) +
|
||||||
|
(textbox->getLabelPadding().y * 2.0f),
|
||||||
|
0, 0
|
||||||
|
),
|
||||||
0.0f
|
0.0f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ std::vector<Asset*> PokerVNScene::getRequiredAssets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PokerVNScene::vnStage() {
|
void PokerVNScene::vnStage() {
|
||||||
this->renderTarget.setClearColor(COLOR_RED);
|
this->renderTarget.setClearColor(COLOR_BLACK);
|
||||||
this->camera->setRenderTarget(&this->renderTarget);
|
this->camera->setRenderTarget(&this->renderTarget);
|
||||||
|
|
||||||
auto pixelPerfectCamera = this->camera->item->addComponent<PixelPerfectCamera>();
|
auto pixelPerfectCamera = this->camera->item->addComponent<PixelPerfectCamera>();
|
||||||
|
@ -25,7 +25,6 @@ namespace Dawn {
|
|||||||
|
|
||||||
void stage() override {
|
void stage() override {
|
||||||
this->camera = Camera::create(this);
|
this->camera = Camera::create(this);
|
||||||
this->camera->transform->lookAt(glm::vec3(300, 300, 300), glm::vec3(0, 0, 0));
|
|
||||||
|
|
||||||
this->subScene.stage();
|
this->subScene.stage();
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace Dawn {
|
|||||||
vnManager, &texture->texture
|
vnManager, &texture->texture
|
||||||
);
|
);
|
||||||
|
|
||||||
start->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "scene.1.1"));
|
start->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "1234"));
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,10 @@ int main(int argc, char *argv[]) {
|
|||||||
char *key = csvGetCell(&csv, y, 0);
|
char *key = csvGetCell(&csv, y, 0);
|
||||||
char *value = csvGetCell(&csv, y, 1);
|
char *value = csvGetCell(&csv, y, 1);
|
||||||
|
|
||||||
|
// 23/01/14 - Replace \r in CSV.
|
||||||
|
stringRemoveAll(key, '\r');
|
||||||
|
stringRemoveAll(value, '\r');
|
||||||
|
|
||||||
if(strlen(key) <= 0 || strlen(value) <= 0) {
|
if(strlen(key) <= 0 || strlen(value) <= 0) {
|
||||||
printf("Failed to parse language. Line %i has an invalid string\n", y);
|
printf("Failed to parse language. Line %i has an invalid string\n", y);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
#define CSV_ROW_COUNT_MAX 128
|
#define CSV_ROW_COUNT_MAX 128
|
||||||
|
|
||||||
|
30
src/dawntools/utils/string.h
Normal file
30
src/dawntools/utils/string.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2023 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
static inline void stringRemoveAll(char *string, char remove) {
|
||||||
|
size_t len = strlen(string);
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while(i < len) {
|
||||||
|
char c = string[i];
|
||||||
|
if(c != remove) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
j = i + 1;
|
||||||
|
while(j < len) {
|
||||||
|
string[j-1] = string[j];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user