From 427b511cb01f0a87f13846da7c93efb813897750 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 13 Aug 2020 13:39:17 +0200 Subject: [PATCH] Do not cache the textWidth in GuiText --- include/gui/GuiText.h | 6 +----- source/gui/GuiText.cpp | 23 +++++++---------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/include/gui/GuiText.h b/include/gui/GuiText.h index f3f58e9..2e5abb8 100644 --- a/include/gui/GuiText.h +++ b/include/gui/GuiText.h @@ -94,9 +94,7 @@ public: virtual std::string toUTF8(void) const; //!Get the Horizontal Size of Text - int32_t getTextWidth() { - return textWidth; - } + int32_t getTextWidth(); int32_t getTextWidth(int32_t ind); @@ -173,10 +171,8 @@ protected: int32_t textScrollPos; //!< Current starting index of text string for scrolling int32_t textScrollInitialDelay; //!< Delay to wait before starting to scroll int32_t textScrollDelay; //!< Scrolling speed - int32_t size; //!< Font size int32_t maxWidth; //!< Maximum width of the generated text object (for text wrapping) FreeTypeGX *font; - int32_t textWidth; int32_t currentSize; int32_t linestodraw; glm::vec4 color; diff --git a/source/gui/GuiText.cpp b/source/gui/GuiText.cpp index c523bef..9a2e439 100644 --- a/source/gui/GuiText.cpp +++ b/source/gui/GuiText.cpp @@ -45,7 +45,6 @@ GuiText::GuiText() { maxWidth = presetMaxWidth; internalSSAA = presetSSAA; wrapMode = 0; - textWidth = 0; font = presentFont; linestodraw = MAX_LINES_TO_DRAW; textScrollPos = 0; @@ -67,7 +66,6 @@ GuiText::GuiText(const char *t, int32_t s, const glm::vec4 &c) { maxWidth = presetMaxWidth; internalSSAA = presetSSAA; wrapMode = 0; - textWidth = 0; font = presentFont; linestodraw = MAX_LINES_TO_DRAW; textScrollPos = 0; @@ -83,8 +81,6 @@ GuiText::GuiText(const char *t, int32_t s, const glm::vec4 &c) { if (!text) { return; } - - textWidth = font->getWidth(text, currentSize); } } @@ -98,7 +94,6 @@ GuiText::GuiText(const wchar_t *t, int32_t s, const glm::vec4 &c) { maxWidth = presetMaxWidth; internalSSAA = presetSSAA; wrapMode = 0; - textWidth = 0; font = presentFont; linestodraw = MAX_LINES_TO_DRAW; textScrollPos = 0; @@ -116,8 +111,6 @@ GuiText::GuiText(const wchar_t *t, int32_t s, const glm::vec4 &c) { } wcscpy(text, t); - - textWidth = font->getWidth(text, currentSize); } } @@ -134,7 +127,6 @@ GuiText::GuiText(const char *t) { maxWidth = presetMaxWidth; internalSSAA = presetSSAA; wrapMode = 0; - textWidth = 0; font = presentFont; linestodraw = MAX_LINES_TO_DRAW; textScrollPos = 0; @@ -150,8 +142,6 @@ GuiText::GuiText(const char *t) { if (!text) { return; } - - textWidth = font->getWidth(text, currentSize); } } @@ -184,8 +174,6 @@ void GuiText::setText(const char *t) { if (!text) { return; } - - textWidth = font->getWidth(text, currentSize); } } @@ -228,8 +216,6 @@ void GuiText::setText(const wchar_t *t) { } wcscpy(text, t); - - textWidth = font->getWidth(text, currentSize); } } @@ -288,10 +274,16 @@ int32_t GuiText::getTextWidth(int32_t ind) { if (ind < 0 || ind >= (int32_t) textDyn.size()) { return this->getTextWidth(); } - return font->getWidth(textDyn[ind], currentSize); } +//!Get the Horizontal Size of Text +int32_t GuiText::getTextWidth() { + auto res = font->getWidth(text, currentSize); + res = res > maxWidth && maxWidth > 0 ? maxWidth : res; + return res; +} + const wchar_t *GuiText::getDynText(int32_t ind) { if (ind < 0 || ind >= (int32_t) textDyn.size()) { return text; @@ -309,7 +301,6 @@ bool GuiText::setFont(FreeTypeGX *f) { } font = f; - textWidth = font->getWidth(text, currentSize); return true; }