1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-31 18:31:04 +00:00

Add colored text (not only colored chat).

Add documentation, move files to a proper place and avoid memory leaks.
Make it work with most kind of texts, and allow backgrounds too.
This commit is contained in:
Ekdohibs 2016-05-31 17:30:11 +02:00
parent 1d40385d4a
commit 14ef2b445a
28 changed files with 689 additions and 318 deletions

View file

@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "fontengine.h"
#include "guiscalingfilter.h"
#include "irrlicht_changes/static_text.h"
#ifdef __ANDROID__
#include "client/tile.h"
@ -172,15 +173,16 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
m_sound_manager = &dummySoundManager;
//create topleft header
std::wstring t = utf8_to_wide(std::string(PROJECT_NAME_C " ") +
m_toplefttext = utf8_to_wide(std::string(PROJECT_NAME_C " ") +
g_version_hash);
core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()),
g_fontengine->getTextHeight());
rect += v2s32(4, 0);
m_irr_toplefttext =
m_device->getGUIEnvironment()->addStaticText(t.c_str(),
rect,false,true,0,-1);
addStaticText(m_device->getGUIEnvironment(), m_toplefttext,
rect, false, true, 0, -1);
//create formspecsource
m_formspecgui = new FormspecFormSource("");
@ -578,7 +580,7 @@ void GUIEngine::setTopleftText(std::string append)
toset += utf8_to_wide(append);
}
m_irr_toplefttext->setText(toset.c_str());
m_toplefttext = toset;
updateTopLeftTextSize();
}
@ -586,15 +588,14 @@ void GUIEngine::setTopleftText(std::string append)
/******************************************************************************/
void GUIEngine::updateTopLeftTextSize()
{
std::wstring text = m_irr_toplefttext->getText();
core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(text), g_fontengine->getTextHeight());
rect += v2s32(4, 0);
core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()),
g_fontengine->getTextHeight());
rect += v2s32(4, 0);
m_irr_toplefttext->remove();
m_irr_toplefttext =
m_device->getGUIEnvironment()->addStaticText(text.c_str(),
rect,false,true,0,-1);
addStaticText(m_device->getGUIEnvironment(), m_toplefttext,
rect, false, true, 0, -1);
}
/******************************************************************************/