aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/CMakeLists.txt1
-rw-r--r--src/gui/guiFormSpecMenu.cpp91
-rw-r--r--src/gui/guiFormSpecMenu.h2
-rw-r--r--src/gui/guiHyperText.cpp1137
-rw-r--r--src/gui/guiHyperText.h229
5 files changed, 1446 insertions, 14 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 2307856a4..c9f750b9a 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -11,6 +11,7 @@ set(gui_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiSkin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp
${CMAKE_CURRENT_SOURCE_DIR}/intlGUIEditBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modalMenu.cpp
diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp
index 5def4357e..44fdf7862 100644
--- a/src/gui/guiFormSpecMenu.cpp
+++ b/src/gui/guiFormSpecMenu.cpp
@@ -57,6 +57,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/guiscalingfilter.h"
#include "guiEditBoxWithScrollbar.h"
#include "intlGUIEditBox.h"
+#include "guiHyperText.h"
#define MY_CHECKPOS(a,b) \
if (v_pos.size() != 2) { \
@@ -155,16 +156,15 @@ void GUIFormSpecMenu::removeChildren()
{
const core::list<gui::IGUIElement*> &children = getChildren();
- while(!children.empty()) {
+ while (!children.empty()) {
(*children.getLast())->remove();
}
- if(m_tooltip_element) {
+ if (m_tooltip_element) {
m_tooltip_element->remove();
m_tooltip_element->drop();
- m_tooltip_element = NULL;
+ m_tooltip_element = nullptr;
}
-
}
void GUIFormSpecMenu::setInitialFocus()
@@ -1318,7 +1318,6 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>& parts,
const std::string &type)
{
-
std::vector<std::string> v_pos = split(parts[0],',');
std::vector<std::string> v_geom = split(parts[1],',');
std::string name = parts[2];
@@ -1402,6 +1401,59 @@ void GUIFormSpecMenu::parseField(parserData* data, const std::string &element,
errorstream<< "Invalid field element(" << parts.size() << "): '" << element << "'" << std::endl;
}
+void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &element)
+{
+ std::vector<std::string> parts = split(element, ';');
+
+ if (parts.size() != 4 && m_formspec_version < FORMSPEC_API_VERSION) {
+ errorstream << "Invalid text element(" << parts.size() << "): '" << element << "'" << std::endl;
+ return;
+ }
+
+ std::vector<std::string> v_pos = split(parts[0], ',');
+ std::vector<std::string> v_geom = split(parts[1], ',');
+ std::string name = parts[2];
+ std::string text = parts[3];
+
+ MY_CHECKPOS("hypertext", 0);
+ MY_CHECKGEOM("hypertext", 1);
+
+ v2s32 pos;
+ v2s32 geom;
+
+ if (data->real_coordinates) {
+ pos = getRealCoordinateBasePos(false, v_pos);
+ geom = getRealCoordinateGeometry(v_geom);
+ } else {
+ pos = getElementBasePos(false, &v_pos);
+ pos -= padding;
+
+ pos.X += stof(v_pos[0]) * spacing.X;
+ pos.Y += stof(v_pos[1]) * spacing.Y + (m_btn_height * 2);
+
+ geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
+ geom.Y = (stof(v_geom[1]) * imgsize.Y) - (spacing.Y - imgsize.Y);
+ }
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y);
+
+ if(m_form_src)
+ text = m_form_src->resolveText(text);
+
+ FieldSpec spec(
+ name,
+ utf8_to_wide(unescape_string(text)),
+ L"",
+ 258 + m_fields.size()
+ );
+
+ spec.ftype = f_Unknown;
+ new GUIHyperText(
+ spec.flabel.c_str(), Environment, this, spec.fid, rect, m_client, m_tsrc);
+
+ m_fields.push_back(spec);
+}
+
void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
{
std::vector<std::string> parts = split(element,';');
@@ -2293,6 +2345,11 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
return;
}
+ if (type == "hypertext") {
+ parseHyperText(data,description);
+ return;
+ }
+
if (type == "label") {
parseLabel(data,description);
return;
@@ -2879,8 +2936,8 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int layer,
if (!item.empty()) {
// Draw item stack
drawItemStack(driver, m_font, item,
- rect, &AbsoluteClippingRect, m_client,
- rotation_kind);
+ rect, &AbsoluteClippingRect, m_client, rotation_kind);
+
// Draw tooltip
if (hovering && !m_selected_item) {
std::string tooltip = item.getDescription(m_client->idef());
@@ -2900,8 +2957,8 @@ void GUIFormSpecMenu::drawSelectedItem()
if (!m_selected_item) {
drawItemStack(driver, m_font, ItemStack(),
- core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
- NULL, m_client, IT_ROT_DRAGGED);
+ core::rect<s32>(v2s32(0, 0), v2s32(0, 0)), NULL,
+ m_client, IT_ROT_DRAGGED);
return;
}
@@ -3482,9 +3539,10 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
}
}
}
- // Mouse wheel events: send to hovered element instead of focused
- if(event.EventType==EET_MOUSE_INPUT_EVENT
- && event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
+ // Mouse wheel and move events: send to hovered element instead of focused
+ if (event.EventType == EET_MOUSE_INPUT_EVENT &&
+ (event.MouseInput.Event == EMIE_MOUSE_WHEEL ||
+ event.MouseInput.Event == EMIE_MOUSE_MOVED)) {
s32 x = event.MouseInput.X;
s32 y = event.MouseInput.Y;
gui::IGUIElement *hovered =
@@ -3492,7 +3550,7 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
core::position2d<s32>(x, y));
if (hovered && isMyChild(hovered)) {
hovered->OnEvent(event);
- return true;
+ return event.MouseInput.Event == EMIE_MOUSE_WHEEL;
}
}
@@ -4041,8 +4099,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
}
m_old_pointer = m_pointer;
}
- if (event.EventType == EET_GUI_EVENT) {
+ if (event.EventType == EET_GUI_EVENT) {
if (event.GUIEvent.EventType == gui::EGET_TAB_CHANGED
&& isVisible()) {
// find the element that was clicked
@@ -4128,6 +4186,11 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
s.fdefault = L"Changed";
acceptInput(quit_mode_no);
s.fdefault = L"";
+ } else if ((s.ftype == f_Unknown) &&
+ (s.fid == event.GUIEvent.Caller->getID())) {
+ s.send = true;
+ acceptInput();
+ s.send = false;
}
}
}
diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h
index 46df0930c..39af1e7c2 100644
--- a/src/gui/guiFormSpecMenu.h
+++ b/src/gui/guiFormSpecMenu.h
@@ -469,6 +469,7 @@ protected:
video::SColor m_default_tooltip_bgcolor;
video::SColor m_default_tooltip_color;
+
private:
IFormSource *m_form_src;
TextDest *m_text_dst;
@@ -529,6 +530,7 @@ private:
void parseSimpleField(parserData* data,std::vector<std::string> &parts);
void parseTextArea(parserData* data,std::vector<std::string>& parts,
const std::string &type);
+ void parseHyperText(parserData *data, const std::string &element);
void parseLabel(parserData* data, const std::string &element);
void parseVertLabel(parserData* data, const std::string &element);
void parseImageButton(parserData* data, const std::string &element,
diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp
new file mode 100644
index 000000000..024e4de09
--- /dev/null
+++ b/src/gui/guiHyperText.cpp
@@ -0,0 +1,1137 @@
+/*
+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 "IGUIEnvironment.h"
+#include "IGUIElement.h"
+#include "guiScrollBar.h"
+#include "IGUIFont.h"
+#include <vector>
+#include <list>
+#include <unordered_map>
+using namespace irr::gui;
+#include "client/fontengine.h"
+#include <SColor.h>
+#include "client/tile.h"
+#include "IVideoDriver.h"
+#include "client/client.h"
+#include "client/renderingengine.h"
+#include "hud.h"
+#include "guiHyperText.h"
+#include "util/string.h"
+
+bool check_color(const std::string &str)
+{
+ irr::video::SColor color;
+ return parseColorString(str, color, false);
+}
+
+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;
+
+ // TODO: find a way to check font validity
+ // Build a new fontengine ?
+ this->font =
+#if USE_FREETYPE
+ (gui::CGUITTFont *)
+#endif
+ g_fontengine->getFont(font_size, font_mode,
+ is_yes(style["bold"]), is_yes(style["italic"]));
+
+ 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"] = m_root_tag.style["color"];
+
+ m_tags.push_back(&m_root_tag);
+ m_active_tags.push_front(&m_root_tag);
+ m_style = m_root_tag.style;
+
+ // Default simple tags definitions
+ StyleList style;
+
+ style["hovercolor"] = "#FF0000";
+ 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;
+ style.clear();
+
+ style["fontsize"] = m_root_tag.style["fontsize"];
+ m_elementtags["normal"] = style;
+ style.clear();
+
+ style["fontsize"] = "24";
+ m_elementtags["big"] = style;
+ style.clear();
+
+ style["fontsize"] = "36";
+ m_elementtags["bigger"] = style;
+ style.clear();
+
+ style["halign"] = "center";
+ m_paragraphtags["center"] = style;
+ style.clear();
+
+ style["halign"] = "justify";
+ m_paragraphtags["justify"] = style;
+ style.clear();
+
+ style["halign"] = "left";
+ m_paragraphtags["left"] = style;
+ style.clear();
+
+ style["halign"] = "right";
+ m_paragraphtags["right"] = style;
+ style.clear();
+
+ m_element = NULL;
+ m_paragraph = NULL;
+
+ parse(text);
+}
+
+ParsedText::~ParsedText()
+{
+ for (auto &tag : m_tags)
+ delete tag;
+}
+
+void ParsedText::parse(const wchar_t *text)
+{
+ wchar_t c;
+ u32 cursor = 0;
+ bool escape = false;
+
+ while ((c = text[cursor]) != L'\0') {
+ cursor++;
+
+ if (c == L'\r') { // Mac or Windows breaks
+ if (text[cursor] == L'\n')
+ cursor++;
+ // If text has begun, don't skip empty line
+ if (m_paragraph) {
+ endParagraph();
+ enterElement(ELEMENT_SEPARATOR);
+ }
+ escape = false;
+ continue;
+ }
+
+ if (c == L'\n') { // Unix breaks
+ // If text has begun, don't skip empty line
+ if (m_paragraph) {
+ endParagraph();
+ enterElement(ELEMENT_SEPARATOR);
+ }
+ escape = false;
+ continue;
+ }
+
+ if (escape) {
+ escape = false;
+ pushChar(c);
+ continue;
+ }
+
+ if (c == L'\\') {
+ escape = true;
+ continue;
+ }
+
+ // Tag check
+ if (c == L'<') {
+ u32 newcursor = parseTag(text, cursor);
+ if (newcursor > 0) {
+ cursor = newcursor;
+ continue;
+ }
+ }
+
+ // Default behavior
+ pushChar(c);
+ }
+
+ endParagraph();
+}
+
+void ParsedText::endElement()
+{
+ m_element = NULL;
+}
+
+void ParsedText::endParagraph()
+{
+ if (!m_paragraph)
+ return;
+
+ endElement();
+ m_paragraph = NULL;
+}
+
+void ParsedText::enterParagraph()
+{
+ if (!m_paragraph) {
+ m_paragraphs.emplace_back();
+ m_paragraph = &m_paragraphs.back();
+ m_paragraph->setStyle(m_style);
+ }
+}
+
+void ParsedText::enterElement(ElementType type)
+{
+ enterParagraph();
+
+ if (!m_element || m_element->type != type) {
+ m_paragraph->elements.emplace_back();
+ m_element = &m_paragraph->elements.back();
+ m_element->type = type;
+ m_element->tags = m_active_tags;
+ m_element->setStyle(m_style);
+ }
+}
+
+void ParsedText::pushChar(wchar_t c)
+{
+ // New word if needed
+ if (c == L' ' || c == L'\t')
+ enterElement(ELEMENT_SEPARATOR);
+ else
+ enterElement(ELEMENT_TEXT);
+
+ m_element->text += c;
+}
+
+ParsedText::Tag *ParsedText::newTag(const std::string &name, const AttrsList &attrs)
+{
+ endElement();
+ Tag *newtag = new Tag();
+ newtag->name = name;
+ newtag->attrs = attrs;
+ m_tags.push_back(newtag);
+ return newtag;
+}
+
+ParsedText::Tag *ParsedText::openTag(const std::string &name, const AttrsList &attrs)
+{
+ Tag *newtag = newTag(name, attrs);
+ m_active_tags.push_front(newtag);
+ return newtag;
+}
+
+bool ParsedText::closeTag(const std::string &name)
+{
+ bool found = false;
+ for (auto id = m_active_tags.begin(); id != m_active_tags.end(); ++id)
+ if ((*id)->name == name) {
+ m_active_tags.erase(id);
+ found = true;
+ break;
+ }
+ return found;
+}
+
+void ParsedText::parseGenericStyleAttr(
+ const std::string &name, const std::string &value, StyleList &style)
+{
+ // Color styles
+ if (name == "color" || name == "hovercolor") {
+ if (check_color(value))
+ style[name] = value;
+
+ // Boolean styles
+ } else if (name == "bold" || name == "italic" || name == "underline") {
+ style[name] = is_yes(value);
+
+ } else if (name == "size") {
+ if (check_integer(value))
+ style["fontsize"] = value;
+
+ } else if (name == "font") {
+ if (value == "mono" || value == "normal")
+ style["fontstyle"] = value;
+ }
+}
+
+void ParsedText::parseStyles(const AttrsList &attrs, StyleList &style)
+{
+ for (auto const &attr : attrs)
+ parseGenericStyleAttr(attr.first, attr.second, style);
+}
+
+void ParsedText::globalTag(const AttrsList &attrs)
+{
+ for (const auto &attr : attrs) {
+ // Only page level style
+ if (attr.first == "margin") {
+ if (check_integer(attr.second))
+ margin = stoi(attr.second.c_str());
+
+ } else if (attr.first == "valign") {
+ if (attr.second == "top")
+ valign = ParsedText::VALIGN_TOP;
+ else if (attr.second == "bottom")
+ valign = ParsedText::VALIGN_BOTTOM;
+ else if (attr.second == "middle")
+ valign = ParsedText::VALIGN_MIDDLE;
+ } else if (attr.first == "background") {
+ irr::video::SColor color;
+ if (attr.second == "none") {
+ background_type = BACKGROUND_NONE;
+ } else if (parseColorString(attr.second, color, false)) {
+ background_type = BACKGROUND_COLOR;
+ background_color = color;
+ }
+
+ // Inheriting styles
+
+ } else if (attr.first == "halign") {
+ if (attr.second == "left" || attr.second == "center" ||
+ attr.second == "right" ||
+ attr.second == "justify")
+ m_root_tag.style["halign"] = attr.second;
+
+ // Generic default styles
+
+ } else {
+ parseGenericStyleAttr(attr.first, attr.second, m_root_tag.style);
+ }
+ }
+}
+
+u32 ParsedText::parseTag(const wchar_t *text, u32 cursor)
+{
+ // Tag name
+ bool end = false;
+ std::string name = "";
+ wchar_t c = text[cursor];
+
+ if (c == L'/') {
+ end = true;
+ c = text[++cursor];
+ if (c == L'\0')
+ return 0;
+ }
+
+ while (c != ' ' && c != '>') {
+ name += c;
+ c = text[++cursor];
+ if (c == L'\0')
+ return 0;
+ }
+
+ // Tag attributes
+ AttrsList attrs;
+ while (c != L'>') {
+ std::string attr_name = "";
+ std::string attr_va inline void setLightingComplete(LightBank bank, u8 direction, bool is_complete) { assert(direction >= 0 && direction <= 5); if (bank == LIGHTBANK_NIGHT) { direction += 6; } u16 newflags = m_lighting_complete; if (is_complete) { newflags |= 1 << direction; } else { newflags &= ~(1 << direction); } setLightingComplete(newflags); } inline bool isLightingComplete(LightBank bank, u8 direction) { assert(direction >= 0 && direction <= 5); if (bank == LIGHTBANK_NIGHT) { direction += 6; } return (m_lighting_complete & (1 << direction)) != 0; } inline bool isGenerated() { return m_generated; } inline void setGenerated(bool b) { if (b != m_generated) { raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_GENERATED); m_generated = b; } } //// //// Position stuff //// inline v3s16 getPos() { return m_pos; } inline v3s16 getPosRelative() { return m_pos_relative; } inline core::aabbox3d<s16> getBox() { return core::aabbox3d<s16>(getPosRelative(), getPosRelative() + v3s16(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE) - v3s16(1,1,1)); } //// //// Regular MapNode get-setters //// inline bool isValidPosition(s16 x, s16 y, s16 z) { return data && x >= 0 && x < MAP_BLOCKSIZE && y >= 0 && y < MAP_BLOCKSIZE && z >= 0 && z < MAP_BLOCKSIZE; } inline bool isValidPosition(v3s16 p) { return isValidPosition(p.X, p.Y, p.Z); } inline MapNode getNode(s16 x, s16 y, s16 z, bool *valid_position) { *valid_position = isValidPosition(x, y, z); if (!*valid_position) return {CONTENT_IGNORE}; return data[z * zstride + y * ystride + x]; } inline MapNode getNode(v3s16 p, bool *valid_position) { return getNode(p.X, p.Y, p.Z, valid_position); } inline MapNode getNodeNoEx(v3s16 p) { bool is_valid; return getNode(p.X, p.Y, p.Z, &is_valid); } inline void setNode(s16 x, s16 y, s16 z, MapNode & n) { if (!isValidPosition(x, y, z)) throw InvalidPositionException(); data[z * zstride + y * ystride + x] = n; raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE); } inline void setNode(v3s16 p, MapNode & n) { setNode(p.X, p.Y, p.Z, n); } //// //// Non-checking variants of the above //// inline MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position) { *valid_position = data != nullptr; if (!*valid_position) return {CONTENT_IGNORE}; return data[z * zstride + y * ystride + x]; } inline MapNode getNodeNoCheck(v3s16 p, bool *valid_position) { return getNodeNoCheck(p.X, p.Y, p.Z, valid_position); } //// //// Non-checking, unsafe variants of the above //// MapBlock must be loaded by another function in the same scope/function //// Caller must ensure that this is not a dummy block (by calling isDummy()) //// inline const MapNode &getNodeUnsafe(s16 x, s16 y, s16 z) { return data[z * zstride + y * ystride + x]; } inline const MapNode &getNodeUnsafe(v3s16 &p) { return getNodeUnsafe(p.X, p.Y, p.Z); } inline void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n) { if (!data) throw InvalidPositionException(); data[z * zstride + y * ystride + x] = n; raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE_NO_CHECK); } inline void setNodeNoCheck(v3s16 p, MapNode & n) { setNodeNoCheck(p.X, p.Y, p.Z, n); } // These functions consult the parent container if the position // is not valid on this MapBlock. bool isValidPositionParent(v3s16 p); MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL); void setNodeParent(v3s16 p, MapNode & n); inline void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node) { for (u16 z = 0; z < d; z++) for (u16 y = 0; y < h; y++) for (u16 x = 0; x < w; x++) setNode(x0 + x, y0 + y, z0 + z, node); } // Copies data to VoxelManipulator to getPosRelative() void copyTo(VoxelManipulator &dst); // Copies data from VoxelManipulator getPosRelative() void copyFrom(VoxelManipulator &dst); // Update day-night lighting difference flag. // Sets m_day_night_differs to appropriate value. // These methods don't care about neighboring blocks. void actuallyUpdateDayNightDiff(); // Call this to schedule what the previous function does to be done // when the value is actually needed. void expireDayNightDiff(); inline bool getDayNightDiff() { if (m_day_night_differs_expired) actuallyUpdateDayNightDiff(); return m_day_night_differs; } //// //// Miscellaneous stuff //// /* Tries to measure ground level. Return value: -1 = only air -2 = only ground -3 = random fail 0...MAP_BLOCKSIZE-1 = ground level */ s16 getGroundLevel(v2s16 p2d); //// //// Timestamp (see m_timestamp) //// // NOTE: BLOCK_TIMESTAMP_UNDEFINED=0xffffffff means there is no timestamp. inline void setTimestamp(u32 time) { m_timestamp = time; raiseModified(MOD_STATE_WRITE_AT_UNLOAD, MOD_REASON_SET_TIMESTAMP); } inline void setTimestampNoChangedFlag(u32 time) { m_timestamp = time; } inline u32 getTimestamp() { return m_timestamp; } inline u32 getDiskTimestamp() { return m_disk_timestamp; } //// //// Usage timer (see m_usage_timer) //// inline void resetUsageTimer() { m_usage_timer = 0; } inline void incrementUsageTimer(float dtime) { m_usage_timer += dtime; } inline float getUsageTimer() { return m_usage_timer; } //// //// Reference counting (see m_refcount) //// inline void refGrab() { m_refcount++; } inline void refDrop() { m_refcount--; } inline int refGet() { return m_refcount; } //// //// Node Timers //// inline NodeTimer getNodeTimer(const v3s16 &p) { return m_node_timers.get(p); } inline void removeNodeTimer(const v3s16 &p) { m_node_timers.remove(p); } inline void setNodeTimer(const NodeTimer &t) { m_node_timers.set(t); } inline void clearNodeTimers() { m_node_timers.clear(); } //// //// Serialization /// // These don't write or read version by itself // Set disk to true for on-disk format, false for over-the-network format // Precondition: version >= SER_FMT_VER_LOWEST_WRITE void serialize(std::ostream &os, u8 version, bool disk); // If disk == true: In addition to doing other things, will add // unknown blocks from id-name mapping to wndef void deSerialize(std::istream &is, u8 version, bool disk); void serializeNetworkSpecific(std::ostream &os); void deSerializeNetworkSpecific(std::istream &is); private: /* Private methods */ void deSerialize_pre22(std::istream &is, u8 version, bool disk); /* Used only internally, because changes can't be tracked */ inline MapNode &getNodeRef(s16 x, s16 y, s16 z) { if (!isValidPosition(x, y, z)) throw InvalidPositionException(); return data[z * zstride + y * ystride + x]; } inline MapNode &getNodeRef(v3s16 &p) { return getNodeRef(p.X, p.Y, p.Z); } public: /* Public member variables */ #ifndef SERVER // Only on client MapBlockMesh *mesh = nullptr; #endif NodeMetadataList m_node_metadata; NodeTimerList m_node_timers; StaticObjectList m_static_objects; static const u32 ystride = MAP_BLOCKSIZE; static const u32 zstride = MAP_BLOCKSIZE * MAP_BLOCKSIZE; static const u32 nodecount = MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE; //// ABM optimizations //// // Cache of content types std::unordered_set<content_t> contents; // True if content types are cached bool contents_cached = false; // True if we never want to cache content types for this block bool do_not_cache_contents = false; private: /* Private member variables */ // NOTE: Lots of things rely on this being the Map Map *m_parent; // Position in blocks on parent v3s16 m_pos; /* This is the precalculated m_pos_relative value * This caches the value, improving performance by removing 3 s16 multiplications * at runtime on each getPosRelative call * For a 5 minutes runtime with valgrind this removes 3 * 19M s16 multiplications * The gain can be estimated in Release Build to 3 * 100M multiply operations for 5 mins */ v3s16 m_pos_relative; IGameDef *m_gamedef; /* If NULL, block is a dummy block. Dummy blocks are used for caching not-found-on-disk blocks. */ MapNode *data = nullptr; /* - On the server, this is used for telling whether the block has been modified from the one on disk. - On the client, this is used for nothing. */ u32 m_modified = MOD_STATE_WRITE_NEEDED; u32 m_modified_reason = MOD_REASON_INITIAL; /* When propagating sunlight and the above block doesn't exist, sunlight is assumed if this is false. In practice this is set to true if the block is completely undeground with nothing visible above the ground except caves. */ bool is_underground = false; /*! * Each bit indicates if light spreading was finished * in a direction. (Because the neighbor could also be unloaded.) * Bits (most significant first): * nothing, nothing, nothing, nothing, * night X-, night Y-, night Z-, night Z+, night Y+, night X+, * day X-, day Y-, day Z-, day Z+, day Y+, day X+. */ u16 m_lighting_complete = 0xFFFF; // Whether day and night lighting differs bool m_day_night_differs = false; bool m_day_night_differs_expired = true; bool m_generated = false; /* When block is removed from active blocks, this is set to gametime. Value BLOCK_TIMESTAMP_UNDEFINED=0xffffffff means there is no timestamp. */ u32 m_timestamp = BLOCK_TIMESTAMP_UNDEFINED; // The on-disk (or to-be on-disk) timestamp value u32 m_disk_timestamp = BLOCK_TIMESTAMP_UNDEFINED; /* When the block is accessed, this is set to 0. Map will unload the block when this reaches a timeout. */ float m_usage_timer = 0; /* Reference count; currently used for determining if this block is in the list of blocks to be drawn. */ int m_refcount = 0; }; typedef std::vector<MapBlock*> MapBlockVect; inline bool objectpos_over_limit(v3f p) { const float max_limit_bs = MAX_MAP_GENERATION_LIMIT * BS; return p.X < -max_limit_bs || p.X > max_limit_bs || p.Y < -max_limit_bs || p.Y > max_limit_bs || p.Z < -max_limit_bs || p.Z > max_limit_bs; } inline bool blockpos_over_max_limit(v3s16 p) { const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE; return p.X < -max_limit_bp || p.X > max_limit_bp || p.Y < -max_limit_bp || p.Y > max_limit_bp || p.Z < -max_limit_bp || p.Z > max_limit_bp; } /* Returns the position of the block where the node is located */ inline v3s16 getNodeBlockPos(const v3s16 &p) { return getContainerPos(p, MAP_BLOCKSIZE); } inline void getNodeBlockPosWithOffset(const v3s16 &p, v3s16 &block, v3s16 &offset) { getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset); } /* Get a quick string to describe what a block actually contains */ std::string analyze_block(MapBlock *block);
>
+ bool underline;
+
+ s32 baseline = 0;
+
+ // img & item specific attributes
+ std::string name;
+ v3s16 angle{0, 0, 0};
+ v3s16 rotation{0, 0, 0};
+
+ s32 margin = 10;
+
+ void setStyle(StyleList &style);
+ };
+
+ struct Paragraph
+ {
+ std::vector<Element> elements;
+ HalignType halign;
+ s32 margin = 10;
+
+ void setStyle(StyleList &style);
+ };
+
+ std::vector<Paragraph> m_paragraphs;
+
+ // Element style
+ s32 margin = 3;
+ ValignType valign = VALIGN_TOP;
+ BackgroundType background_type = BACKGROUND_NONE;
+ irr::video::SColor background_color;
+
+ Tag m_root_tag;
+
+protected:
+ // Parser functions
+ void enterElement(ElementType type);
+ void endElement();
+ void enterParagraph();
+ void endParagraph();
+ void pushChar(wchar_t c);
+ ParsedText::Tag *newTag(const std::string &name, const AttrsList &attrs);
+ ParsedText::Tag *openTag(const std::string &name, const AttrsList &attrs);
+ bool closeTag(const std::string &name);
+ void parseGenericStyleAttr(const std::string &name, const std::string &value,
+ StyleList &style);
+ void parseStyles(const AttrsList &attrs, StyleList &style);
+ void globalTag(const ParsedText::AttrsList &attrs);
+ u32 parseTag(const wchar_t *text, u32 cursor);
+ void parse(const wchar_t *text);
+
+ std::unordered_map<std::string, StyleList> m_elementtags;
+ std::unordered_map<std::string, StyleList> m_paragraphtags;
+
+ std::vector<Tag *> m_tags;
+ std::list<Tag *> m_active_tags;
+
+ // Current values
+ StyleList m_style;
+ Element *m_element;
+ Paragraph *m_paragraph;
+};
+
+class TextDrawer
+{
+public:
+ TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment,
+ ISimpleTextureSource *tsrc);
+
+ void place(const core::rect<s32> &dest_rect);
+ inline s32 getHeight() { return m_height; };
+ void draw(const core::rect<s32> &dest_rect,
+ const core::position2d<s32> &dest_offset);
+ ParsedText::Element *getElementAt(core::position2d<s32> pos);
+ ParsedText::Tag *m_hovertag;
+
+protected:
+ struct RectWithMargin
+ {
+ core::rect<s32> rect;
+ s32 margin;
+ };
+
+ ParsedText m_text;
+ Client *m_client;
+ gui::IGUIEnvironment *m_environment;
+ s32 m_height;
+ s32 m_voffset;
+ std::vector<RectWithMargin> m_floating;
+};
+
+class GUIHyperText : public gui::IGUIElement
+{
+public:
+ //! constructor
+ GUIHyperText(const wchar_t *text, gui::IGUIEnvironment *environment,
+ gui::IGUIElement *parent, s32 id,
+ const core::rect<s32> &rectangle, Client *client,
+ ISimpleTextureSource *tsrc);
+
+ //! destructor
+ virtual ~GUIHyperText();
+
+ //! draws the element and its children
+ virtual void draw();
+
+ core::dimension2du getTextDimension();
+
+ bool OnEvent(const SEvent &event);
+
+protected:
+ // GUI members
+ Client *m_client;
+ GUIScrollBar *m_vscrollbar;
+ TextDrawer m_drawer;
+
+ // Positioning
+ u32 m_scrollbar_width;
+ core::rect<s32> m_display_text_rect;
+ core::position2d<s32> m_text_scrollpos;
+
+ ParsedText::Element *getElementAt(s32 X, s32 Y);
+ void checkHover(s32 X, s32 Y);
+};