Fixed more font stuff, works really really good now.

This commit is contained in:
2023-01-14 23:34:15 -08:00
parent 0558b3bb25
commit 18d3b074f9
14 changed files with 81 additions and 25 deletions

View File

@ -37,12 +37,17 @@ float_t TrueTypeFont::getScale(float_t scale) {
float_t TrueTypeFont::getSpaceSize(float_t fontSize) {
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) {
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(
@ -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;
}

View File

@ -43,7 +43,6 @@ void SubSceneCameraAlign::realign() {
this->camera->orthoLeft = diff;
this->camera->orthoRight = this->renderTarget->getWidth() - diff;
}
}
void SubSceneCameraAlign::setRenderTarget(TextureRenderTarget *renderTarget) {

View File

@ -75,6 +75,11 @@ void UIComponent::updatePositions() {
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
auto it = this->children.begin();
while(it != this->children.end()) {

View File

@ -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(

View File

@ -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.