From 18d3b074f9fdc046a67b2e3425685202c6b76c78 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 14 Jan 2023 23:34:15 -0800 Subject: [PATCH] Fixed more font stuff, works really really good now. --- src/dawn/display/font/TrueTypeFont.cpp | 28 ++++++++--------- .../components/scene/SubSceneCameraAlign.cpp | 1 - src/dawn/ui/UIComponent.cpp | 5 ++++ .../visualnovel/ui/VisualNovelTextbox.cpp | 4 +++ .../visualnovel/ui/VisualNovelTextbox.hpp | 7 +++++ src/dawnpokergame/CMakeLists.txt | 6 ++-- .../prefabs/ui/UIBorderPrefab.hpp | 2 +- .../prefabs/ui/VisualNovelTextboxPrefab.hpp | 13 ++++++-- src/dawnpokergame/scenes/PokerVNScene.cpp | 2 +- src/dawnpokergame/scenes/SubsceneTest.hpp | 1 - src/dawnpokergame/scenes/TestScene.hpp | 2 +- src/dawntools/locale/languagegen/main.c | 4 +++ src/dawntools/utils/csv.h | 1 + src/dawntools/utils/string.h | 30 +++++++++++++++++++ 14 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 src/dawntools/utils/string.h diff --git a/src/dawn/display/font/TrueTypeFont.cpp b/src/dawn/display/font/TrueTypeFont.cpp index 94c9df27..2dcf9f5d 100644 --- a/src/dawn/display/font/TrueTypeFont.cpp +++ b/src/dawn/display/font/TrueTypeFont.cpp @@ -37,12 +37,17 @@ float_t TrueTypeFont::getScale(float_t scale) { float_t TrueTypeFont::getSpaceSize(float_t fontSize) { assertTrue(fontSize > 0); - return mathRound(this->fontSize * 0.3f); + return mathRound(this->getScale(fontSize) * 18); } float_t TrueTypeFont::getInitialLineHeight(float_t fontSize) { assertTrue(fontSize > 0); - return 8.0f; + return mathRound(42.0f * this->getScale(fontSize)); +} + +float_t TrueTypeFont::getLineHeight(float_t fontSize) { + assertTrue(fontSize > 0); + return mathRound(58.0f * this->getScale(fontSize)); } void TrueTypeFont::buffer( @@ -100,7 +105,7 @@ void TrueTypeFont::buffer( // Setup the initial loop state, and X/Y coords for the quad. int32_t i = 0; float_t x = 0; - float_t y = this->getInitialLineHeight(fontSize); + float_t y = this->getInitialLineHeight(fontSize) / scale; float_t wordX = 0; char c; while(c = text[i++]) { @@ -108,12 +113,12 @@ void TrueTypeFont::buffer( // When space, start of new word about to begin if(c == FONT_SPACE) { - x += this->getSpaceSize(fontSize); + x += this->getSpaceSize(fontSize) / scale; // Did this space cause a newline? if(x > maxWidth) { info->addLine(info->realLength, 0); - y += this->getLineHeight(fontSize); + y += this->getLineHeight(fontSize) / scale; x = 0; } wordX = x; @@ -125,7 +130,7 @@ void TrueTypeFont::buffer( if(c == FONT_NEWLINE) { info->addLine(info->realLength, 0); wordStart = info->realLength; - y += this->getLineHeight(fontSize); + y += this->getLineHeight(fontSize) / scale; x = 0; continue; } @@ -142,15 +147,15 @@ void TrueTypeFont::buffer( quad = quads + j; quad->x0 -= wordX; quad->x1 -= wordX; - quad->y0 += this->getLineHeight(fontSize); - quad->y1 += this->getLineHeight(fontSize); + quad->y0 += this->getLineHeight(fontSize) / scale; + quad->y1 += this->getLineHeight(fontSize) / scale; } // Go back to the previous (still current) line and remove the chars info->lines[info->lines.size() - 1].length -= info->realLength - wordStart; // Next line begins with this word - y += this->getLineHeight(fontSize); + y += this->getLineHeight(fontSize) / scale; info->addLine(wordStart, info->realLength-wordStart); 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() { return (float_t)this->fontSize; } \ No newline at end of file diff --git a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp index bb444be4..8f811ea2 100644 --- a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp +++ b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp @@ -43,7 +43,6 @@ void SubSceneCameraAlign::realign() { this->camera->orthoLeft = diff; this->camera->orthoRight = this->renderTarget->getWidth() - diff; } - } void SubSceneCameraAlign::setRenderTarget(TextureRenderTarget *renderTarget) { diff --git a/src/dawn/ui/UIComponent.cpp b/src/dawn/ui/UIComponent.cpp index a5eeea5b..77848520 100644 --- a/src/dawn/ui/UIComponent.cpp +++ b/src/dawn/ui/UIComponent.cpp @@ -75,6 +75,11 @@ void UIComponent::updatePositions() { this->relativeY = (this->relativeY / 2.0f) - (this->height / 2.0f) + this->alignment[1]; } + this->relativeX = mathRound(this->relativeX); + this->relativeY = mathRound(this->relativeY); + this->width = mathRound(this->width); + this->height = mathRound(this->height); + // Update children auto it = this->children.begin(); while(it != this->children.end()) { diff --git a/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp b/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp index 14b50024..218dfb42 100644 --- a/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp +++ b/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp @@ -176,6 +176,10 @@ void VisualNovelTextbox::setLabelPadding(glm::vec2 padding) { this->updatePositions(); } +glm::vec2 VisualNovelTextbox::getLabelPadding() { + return this->labelPadding; +} + bool_t VisualNovelTextbox::hasRevealedAllCurrentCharacters() { int32_t quadsTotal = 0; for( diff --git a/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp b/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp index 78795f2d..068d689f 100644 --- a/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp +++ b/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp @@ -113,6 +113,13 @@ namespace Dawn { */ 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 * current textbox size have finished revealing, or false if not. diff --git a/src/dawnpokergame/CMakeLists.txt b/src/dawnpokergame/CMakeLists.txt index 22341131..2d2fc384 100644 --- a/src/dawnpokergame/CMakeLists.txt +++ b/src/dawnpokergame/CMakeLists.txt @@ -40,9 +40,9 @@ tool_tileset(tileset_cards texture_cards ${DIR_GAME_ASSETS}/cards.png 14 4) tool_truetype(truetype_ark ark-pixel.ttf truetype_ark - 96 - 96 - 10 + 2048 + 2048 + 60 ) add_dependencies(${DAWN_TARGET_NAME} diff --git a/src/dawnpokergame/prefabs/ui/UIBorderPrefab.hpp b/src/dawnpokergame/prefabs/ui/UIBorderPrefab.hpp index 31d337e7..39dfece2 100644 --- a/src/dawnpokergame/prefabs/ui/UIBorderPrefab.hpp +++ b/src/dawnpokergame/prefabs/ui/UIBorderPrefab.hpp @@ -19,7 +19,7 @@ namespace Dawn { static void prefabApply(AssetManager *man, UIBorder *border) { auto text = man->get("texture_test"); border->texture = &text->texture; - border->setBorderSize(glm::vec2(8, 8)); + border->setBorderSize(glm::vec2(4, 4)); } }; } \ No newline at end of file diff --git a/src/dawnpokergame/prefabs/ui/VisualNovelTextboxPrefab.hpp b/src/dawnpokergame/prefabs/ui/VisualNovelTextboxPrefab.hpp index f120dd0d..f6e01ac5 100644 --- a/src/dawnpokergame/prefabs/ui/VisualNovelTextboxPrefab.hpp +++ b/src/dawnpokergame/prefabs/ui/VisualNovelTextboxPrefab.hpp @@ -22,11 +22,18 @@ namespace Dawn { auto assetFont = man->get("truetype_ark"); UIBorderPrefab::apply(&textbox->border); textbox->setFont(&assetFont->font); - textbox->setFontSize(11); - textbox->setLabelPadding(glm::vec2(4, 4)); + textbox->setFontSize(10.0f); + textbox->setLabelPadding(glm::vec2(2, 2)); + textbox->setTransform( 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 ); } diff --git a/src/dawnpokergame/scenes/PokerVNScene.cpp b/src/dawnpokergame/scenes/PokerVNScene.cpp index acc5e2e6..82524755 100644 --- a/src/dawnpokergame/scenes/PokerVNScene.cpp +++ b/src/dawnpokergame/scenes/PokerVNScene.cpp @@ -23,7 +23,7 @@ std::vector PokerVNScene::getRequiredAssets() { } void PokerVNScene::vnStage() { - this->renderTarget.setClearColor(COLOR_RED); + this->renderTarget.setClearColor(COLOR_BLACK); this->camera->setRenderTarget(&this->renderTarget); auto pixelPerfectCamera = this->camera->item->addComponent(); diff --git a/src/dawnpokergame/scenes/SubsceneTest.hpp b/src/dawnpokergame/scenes/SubsceneTest.hpp index 4c659038..5b8a27aa 100644 --- a/src/dawnpokergame/scenes/SubsceneTest.hpp +++ b/src/dawnpokergame/scenes/SubsceneTest.hpp @@ -25,7 +25,6 @@ namespace Dawn { void stage() override { this->camera = Camera::create(this); - this->camera->transform->lookAt(glm::vec3(300, 300, 300), glm::vec3(0, 0, 0)); this->subScene.stage(); diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index 43d6e2df..77b7f746 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -40,7 +40,7 @@ namespace Dawn { vnManager, &texture->texture ); - start->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent(), "scene.1.1")); + start->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent(), "1234")); return start; } diff --git a/src/dawntools/locale/languagegen/main.c b/src/dawntools/locale/languagegen/main.c index a7d87547..a3d3c102 100644 --- a/src/dawntools/locale/languagegen/main.c +++ b/src/dawntools/locale/languagegen/main.c @@ -89,6 +89,10 @@ int main(int argc, char *argv[]) { char *key = csvGetCell(&csv, y, 0); 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) { printf("Failed to parse language. Line %i has an invalid string\n", y); fclose(file); diff --git a/src/dawntools/utils/csv.h b/src/dawntools/utils/csv.h index 3ab2582c..340e2cfe 100644 --- a/src/dawntools/utils/csv.h +++ b/src/dawntools/utils/csv.h @@ -7,6 +7,7 @@ #pragma once #include "common.h" +#include "string.h" #define CSV_ROW_COUNT_MAX 128 diff --git a/src/dawntools/utils/string.h b/src/dawntools/utils/string.h new file mode 100644 index 00000000..a6811ae7 --- /dev/null +++ b/src/dawntools/utils/string.h @@ -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--; + } +} \ No newline at end of file