diff --git a/include/gui/GuiText.h b/include/gui/GuiText.h index 1f8720f..0fc3a85 100644 --- a/include/gui/GuiText.h +++ b/include/gui/GuiText.h @@ -142,6 +142,24 @@ public: //!Constantly called to draw the text void draw(CVideo *pVideo); + virtual float getWidth() { + return getTextWidth(); + } + + virtual float getHeight() { + return getTextHeight(); + } + + virtual void setSize(float w, float h) { + //! We calculate the size based on the text. + this->width = 0; + this->height = 0; + } + + virtual float getCenterY(void); + + virtual float getCenterX(void); + //! text enums enum { WRAP, diff --git a/source/gui/GuiText.cpp b/source/gui/GuiText.cpp index a51bb3e..9a3603b 100644 --- a/source/gui/GuiText.cpp +++ b/source/gui/GuiText.cpp @@ -53,6 +53,8 @@ GuiText::GuiText() { blurGlowIntensity = 0.0f; blurAlpha = 0.0f; blurGlowColor = glm::vec4(0.0f); + width = 0; + height = 0; } GuiText::GuiText(const char *t, int32_t s, const glm::vec4 &c) { @@ -73,6 +75,8 @@ GuiText::GuiText(const char *t, int32_t s, const glm::vec4 &c) { blurGlowIntensity = 0.0f; blurAlpha = 0.0f; blurGlowColor = glm::vec4(0.0f); + width = 0; + height = 0; if (t) { textMutex.lock(); @@ -99,6 +103,8 @@ GuiText::GuiText(const wchar_t *t, int32_t s, const glm::vec4 &c) { blurGlowIntensity = 0.0f; blurAlpha = 0.0f; blurGlowColor = glm::vec4(0.0f); + width = 0; + height = 0; if (t) { textMutex.lock(); @@ -134,6 +140,8 @@ GuiText::GuiText(const char *t) { blurGlowIntensity = 0.0f; blurAlpha = 0.0f; blurGlowColor = glm::vec4(0.0f); + width = 0; + height = 0; if (t) { textMutex.lock(); @@ -531,6 +539,78 @@ void GuiText::wrapText() { textMutex.unlock(); } +/** + * We need to redefine this, because we don't want to use our width. + */ +float GuiText::getCenterX(void) { + float pCenterX = 0.0f; + + if (parentElement) { + pCenterX = parentElement->getCenterX(); + } + + pCenterX += xoffset + xoffsetDyn; + + if (alignment & ALIGN_LEFT) { + float pWidth = 0.0f; + float pScale = 0.0f; + + if (parentElement) { + pWidth = parentElement->getWidth(); + pScale = parentElement->getScaleX(); + } + + pCenterX -= pWidth * 0.5f * pScale; + } else if (alignment & ALIGN_RIGHT) { + float pWidth = 0.0f; + float pScale = 0.0f; + + if (parentElement) { + pWidth = parentElement->getWidth(); + pScale = parentElement->getScaleX(); + } + + pCenterX += pWidth * 0.5f * pScale; + } + return pCenterX; +} + +/** + * We need to redefine this, because we don't want to use our height. + */ +float GuiText::getCenterY(void) { + float pCenterY = 0.0f; + + if (parentElement) { + pCenterY = parentElement->getCenterY(); + } + + pCenterY += yoffset + yoffsetDyn; + + if (alignment & ALIGN_TOP) { + float pHeight = 0.0f; + float pScale = 0.0f; + + if (parentElement) { + pHeight = parentElement->getHeight(); + pScale = parentElement->getScaleY(); + } + + pCenterY += pHeight * 0.5f * pScale; + } else if (alignment & ALIGN_BOTTOM) { + float pHeight = 0.0f; + float pScale = 0.0f; + + if (parentElement) { + pHeight = parentElement->getHeight(); + pScale = parentElement->getScaleY(); + } + + pCenterY -= pHeight * 0.5f * pScale; + } + return pCenterY; +} + /** * Draw the text on screen */