3 Copyright (C) 2019 EvicenceBKidscode / Pierre-Yves Rollo <dev@pyrollo.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <unordered_map>
26 #include "irrlichttypes_extrabloated.h"
30 class ISimpleTextureSource;
37 ParsedText(const wchar_t *text);
76 typedef std::unordered_map<std::string, std::string> StyleList;
77 typedef std::unordered_map<std::string, std::string> AttrsList;
88 std::list<Tag *> tags;
90 core::stringw text = "";
92 core::dimension2d<u32> dim;
93 core::position2d<s32> pos;
96 FloatType floating = FLOAT_NONE;
102 irr::video::SColor color;
103 irr::video::SColor hovercolor;
108 // img & item specific attributes
110 v3s16 angle{0, 0, 0};
111 v3s16 rotation{0, 0, 0};
115 void setStyle(StyleList &style);
120 std::vector<Element> elements;
124 void setStyle(StyleList &style);
127 std::vector<Paragraph> m_paragraphs;
131 ValignType valign = VALIGN_TOP;
132 BackgroundType background_type = BACKGROUND_NONE;
133 irr::video::SColor background_color;
138 typedef enum { ER_NONE, ER_TAG, ER_NEWLINE } EndReason;
141 void enterElement(ElementType type);
143 void enterParagraph();
144 void endParagraph(EndReason reason);
145 void pushChar(wchar_t c);
146 ParsedText::Tag *newTag(const std::string &name, const AttrsList &attrs);
147 ParsedText::Tag *openTag(const std::string &name, const AttrsList &attrs);
148 bool closeTag(const std::string &name);
149 void parseGenericStyleAttr(const std::string &name, const std::string &value,
151 void parseStyles(const AttrsList &attrs, StyleList &style);
152 void globalTag(const ParsedText::AttrsList &attrs);
153 u32 parseTag(const wchar_t *text, u32 cursor);
154 void parse(const wchar_t *text);
156 std::unordered_map<std::string, StyleList> m_elementtags;
157 std::unordered_map<std::string, StyleList> m_paragraphtags;
159 std::vector<Tag *> m_not_root_tags;
160 std::list<Tag *> m_active_tags;
165 Paragraph *m_paragraph;
166 bool m_empty_paragraph;
167 EndReason m_end_paragraph_reason;
173 TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment,
174 ISimpleTextureSource *tsrc);
176 void place(const core::rect<s32> &dest_rect);
177 inline s32 getHeight() { return m_height; };
178 void draw(const core::rect<s32> &clip_rect,
179 const core::position2d<s32> &dest_offset);
180 ParsedText::Element *getElementAt(core::position2d<s32> pos);
181 ParsedText::Tag *m_hovertag;
184 struct RectWithMargin
186 core::rect<s32> rect;
192 gui::IGUIEnvironment *m_environment;
195 std::vector<RectWithMargin> m_floating;
198 class GUIHyperText : public gui::IGUIElement
202 GUIHyperText(const wchar_t *text, gui::IGUIEnvironment *environment,
203 gui::IGUIElement *parent, s32 id,
204 const core::rect<s32> &rectangle, Client *client,
205 ISimpleTextureSource *tsrc);
208 virtual ~GUIHyperText();
210 //! draws the element and its children
213 core::dimension2du getTextDimension();
215 bool OnEvent(const SEvent &event);
220 GUIScrollBar *m_vscrollbar;
224 u32 m_scrollbar_width;
225 core::rect<s32> m_display_text_rect;
226 core::position2d<s32> m_text_scrollpos;
228 ParsedText::Element *getElementAt(s32 X, s32 Y);
229 void checkHover(s32 X, s32 Y);