/*
Minetest
Copyright (C) 2019 EvicenceBKidscode / Pierre-Yves Rollo <dev@pyrollo.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "guiHyperText.h"
#include "guiScrollBar.h"
#include "client/fontengine.h"
#include "client/tile.h"
#include "IVideoDriver.h"
#include "client/client.h"
#include "client/renderingengine.h"
#include "hud.h"
#include "util/string.h"
#include "irrlicht_changes/CGUITTFont.h"
using namespace irr::gui;
static bool check_color(const std::string &str)
{
irr::video::SColor color;
return parseColorString(str, color, false);
}
static bool check_integer(const std::string &str)
{
if (str.empty())
return false;
char *endptr = nullptr;
strtol(str.c_str(), &endptr, 10);
return *endptr == '\0';
}
// -----------------------------------------------------------------------------
// ParsedText - A text parser
void ParsedText::Element::setStyle(StyleList &style)
{
this->underline = is_yes(style["underline"]);
video::SColor color;
if (parseColorString(style["color"], color, false))
this->color = color;
if (parseColorString(style["hovercolor"], color, false))
this->hovercolor = color;
unsigned int font_size = std::atoi(style["fontsize"].c_str());
FontMode font_mode = FM_Standard;
if (style["fontstyle"] == "mono")
font_mode = FM_Mono;
FontSpec spec(font_size, font_mode,
is_yes(style["bold"]), is_yes(style["italic"]));
// TODO: find a way to check font validity
// Build a new fontengine ?
this->font = g_fontengine->getFont(spec);
if (!this->font)
printf("No font found ! Size=%d, mode=%d, bold=%s, italic=%s\n",
font_size, font_mode, style["bold"].c_str(),
style["italic"].c_str());
}
void ParsedText::Paragraph::setStyle(StyleList &style)
{
if (style["halign"] == "center")
this->halign = HALIGN_CENTER;
else if (style["halign"] == "right")
this->halign = HALIGN_RIGHT;
else if (style["halign"] == "justify")
this->halign = HALIGN_JUSTIFY;
else
this->halign = HALIGN_LEFT;
}
ParsedText::ParsedText(const wchar_t *text)
{
// Default style
m_root_tag.name = "root";
m_root_tag.style["fontsize"] = "16";
m_root_tag.style["fontstyle"] = "normal";
m_root_tag.style["bold"] = "false";
m_root_tag.style["italic"] = "false";
m_root_tag.style["underline"] = "false";
m_root_tag.style["halign"] = "left";
m_root_tag.style["color"] = "#EEEEEE";
m_root_tag.style["hovercolor"] = "#FF0000";
m_active_tags.push_front(&m_root_tag);
m_style = m_root_tag.style;
// Default simple tags definitions
StyleList style;
style["color"] = "#0000FF";
style["underline"] = "true";
m_elementtags["action"] = style;
style.clear();
style["bold"] = "true";
m_elementtags["b"] = style;
style.clear();
style["italic"] = "true";
m_elementtags["i"] = style;
style.clear();
style["underline"] = "true";
m_elementtags["u"] = style;
style.clear();
style["fontstyle"] = "mono";
m_elementtags["mono"] = style;
sty
|