mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-05 18:41:05 +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:
parent
1d40385d4a
commit
14ef2b445a
28 changed files with 689 additions and 318 deletions
|
@ -50,6 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/hex.h"
|
||||
#include "util/numeric.h"
|
||||
#include "util/string.h" // for parseColorString()
|
||||
#include "irrlicht_changes/static_text.h"
|
||||
#include "guiscalingfilter.h"
|
||||
|
||||
#if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
|
||||
|
@ -249,37 +250,6 @@ std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static std::vector<std::string> split(const std::string &s, char delim)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
|
||||
std::string current = "";
|
||||
bool last_was_escape = false;
|
||||
for (unsigned int i = 0; i < s.size(); i++) {
|
||||
char si = s.c_str()[i];
|
||||
if (last_was_escape) {
|
||||
current += '\\';
|
||||
current += si;
|
||||
last_was_escape = false;
|
||||
} else {
|
||||
if (si == delim) {
|
||||
tokens.push_back(current);
|
||||
current = "";
|
||||
last_was_escape = false;
|
||||
} else if (si == '\\') {
|
||||
last_was_escape = true;
|
||||
} else {
|
||||
current += si;
|
||||
last_was_escape = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//push last element
|
||||
tokens.push_back(current);
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
void GUIFormSpecMenu::parseSize(parserData* data,std::string element)
|
||||
{
|
||||
std::vector<std::string> parts = split(element,',');
|
||||
|
@ -966,7 +936,7 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
|
|||
int font_height = g_fontengine->getTextHeight();
|
||||
rect.UpperLeftCorner.Y -= font_height;
|
||||
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
|
||||
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
|
||||
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
|
||||
}
|
||||
|
||||
e->setPasswordBox(true,L'*');
|
||||
|
@ -1021,7 +991,7 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
|
|||
if (name == "")
|
||||
{
|
||||
// spec field id to 0, this stops submit searching for a value that isn't there
|
||||
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
|
||||
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, spec.fid);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1056,7 +1026,7 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
|
|||
int font_height = g_fontengine->getTextHeight();
|
||||
rect.UpperLeftCorner.Y -= font_height;
|
||||
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
|
||||
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
|
||||
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1117,7 +1087,7 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,
|
|||
if (name == "")
|
||||
{
|
||||
// spec field id to 0, this stops submit searching for a value that isn't there
|
||||
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
|
||||
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, spec.fid);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1161,7 +1131,7 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,
|
|||
int font_height = g_fontengine->getTextHeight();
|
||||
rect.UpperLeftCorner.Y -= font_height;
|
||||
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
|
||||
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
|
||||
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
|
||||
}
|
||||
}
|
||||
m_fields.push_back(spec);
|
||||
|
@ -1230,7 +1200,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
|
|||
258+m_fields.size()
|
||||
);
|
||||
gui::IGUIStaticText *e =
|
||||
Environment->addStaticText(spec.flabel.c_str(),
|
||||
addStaticText(Environment, spec.flabel.c_str(),
|
||||
rect, false, false, this, spec.fid);
|
||||
e->setTextAlignment(gui::EGUIA_UPPERLEFT,
|
||||
gui::EGUIA_CENTER);
|
||||
|
@ -1284,7 +1254,7 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element)
|
|||
258+m_fields.size()
|
||||
);
|
||||
gui::IGUIStaticText *t =
|
||||
Environment->addStaticText(spec.flabel.c_str(), rect, false, false, this, spec.fid);
|
||||
addStaticText(Environment, spec.flabel.c_str(), rect, false, false, this, spec.fid);
|
||||
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
|
||||
m_fields.push_back(spec);
|
||||
return;
|
||||
|
@ -1910,7 +1880,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
{
|
||||
assert(m_tooltip_element == NULL);
|
||||
// Note: parent != this so that the tooltip isn't clipped by the menu rectangle
|
||||
m_tooltip_element = Environment->addStaticText(L"",core::rect<s32>(0,0,110,18));
|
||||
m_tooltip_element = addStaticText(Environment, L"",core::rect<s32>(0,0,110,18));
|
||||
m_tooltip_element->enableOverrideColor(true);
|
||||
m_tooltip_element->setBackgroundColor(m_default_tooltip_bgcolor);
|
||||
m_tooltip_element->setDrawBackground(true);
|
||||
|
@ -2255,7 +2225,6 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase,
|
|||
std::wstring tooltip_text = L"";
|
||||
if (hovering && !m_selected_item) {
|
||||
tooltip_text = utf8_to_wide(item.getDefinition(m_gamedef->idef()).description);
|
||||
tooltip_text = unescape_enriched(tooltip_text);
|
||||
}
|
||||
if (tooltip_text != L"") {
|
||||
std::vector<std::wstring> tt_rows = str_split(tooltip_text, L'\n');
|
||||
|
@ -2263,7 +2232,7 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase,
|
|||
m_tooltip_element->setOverrideColor(m_default_tooltip_color);
|
||||
m_tooltip_element->setVisible(true);
|
||||
this->bringToFront(m_tooltip_element);
|
||||
m_tooltip_element->setText(tooltip_text.c_str());
|
||||
setStaticText(m_tooltip_element, tooltip_text.c_str());
|
||||
s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
|
||||
#if IRRLICHT_VERSION_MAJOR <= 1 && IRRLICHT_VERSION_MINOR <= 8 && IRRLICHT_VERSION_REVISION < 2
|
||||
s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
|
||||
|
@ -2535,8 +2504,10 @@ void GUIFormSpecMenu::drawMenu()
|
|||
iter != m_fields.end(); ++iter) {
|
||||
if (iter->fid == id && m_tooltips[iter->fname].tooltip != L"") {
|
||||
if (m_old_tooltip != m_tooltips[iter->fname].tooltip) {
|
||||
m_tooltip_element->setBackgroundColor(m_tooltips[iter->fname].bgcolor);
|
||||
m_tooltip_element->setOverrideColor(m_tooltips[iter->fname].color);
|
||||
m_old_tooltip = m_tooltips[iter->fname].tooltip;
|
||||
m_tooltip_element->setText(m_tooltips[iter->fname].tooltip.c_str());
|
||||
setStaticText(m_tooltip_element, m_tooltips[iter->fname].tooltip.c_str());
|
||||
std::vector<std::wstring> tt_rows = str_split(m_tooltips[iter->fname].tooltip, L'\n');
|
||||
s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
|
||||
s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
|
||||
|
@ -2558,8 +2529,6 @@ void GUIFormSpecMenu::drawMenu()
|
|||
core::position2d<s32>(tooltip_x, tooltip_y),
|
||||
core::dimension2d<s32>(tooltip_width, tooltip_height)));
|
||||
}
|
||||
m_tooltip_element->setBackgroundColor(m_tooltips[iter->fname].bgcolor);
|
||||
m_tooltip_element->setOverrideColor(m_tooltips[iter->fname].color);
|
||||
m_tooltip_element->setVisible(true);
|
||||
this->bringToFront(m_tooltip_element);
|
||||
break;
|
||||
|
@ -2568,6 +2537,8 @@ void GUIFormSpecMenu::drawMenu()
|
|||
}
|
||||
}
|
||||
|
||||
m_tooltip_element->draw();
|
||||
|
||||
/*
|
||||
Draw dragged item stack
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue