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.
22 #include "config.h" // for USE_FREETYPE
26 class ISimpleTextureSource;
30 #include "irrlicht_changes/CGUITTFont.h"
36 ParsedText(const wchar_t *text);
75 typedef std::unordered_map<std::string, std::string> StyleList;
76 typedef std::unordered_map<std::string, std::string> AttrsList;
87 std::list<Tag *> tags;
89 core::stringw text = "";
91 core::dimension2d<u32> dim;
92 core::position2d<s32> pos;
95 FloatType floating = FLOAT_NONE;
101 irr::video::SColor color;
102 irr::video::SColor hovercolor;
107 // img & item specific attributes
109 v3s16 angle{0, 0, 0};
110 v3s16 rotation{0, 0, 0};
114 void setStyle(StyleList &style);
119 std::vector<Element> elements;
123 void setStyle(StyleList &style);
126 std::vector<Paragraph> m_paragraphs;
130 ValignType valign = VALIGN_TOP;
131 BackgroundType background_type = BACKGROUND_NONE;
132 irr::video::SColor background_color;
138 void enterElement(ElementType type);
140 void enterParagraph();
142 void pushChar(wchar_t c);
143 ParsedText::Tag *newTag(const std::string &name, const AttrsList &attrs);
144 ParsedText::Tag *openTag(const std::string &name, const AttrsList &attrs);
145 bool closeTag(const std::string &name);
146 void parseGenericStyleAttr(const std::string &name, const std::string &value,
148 void parseStyles(const AttrsList &attrs, StyleList &style);
149 void globalTag(const ParsedText::AttrsList &attrs);
150 u32 parseTag(const wchar_t *text, u32 cursor);
151 void parse(const wchar_t *text);
153 std::unordered_map<std::string, StyleList> m_elementtags;
154 std::unordered_map<std::string, StyleList> m_paragraphtags;
156 std::vector<Tag *> m_tags;
157 std::list<Tag *> m_active_tags;
162 Paragraph *m_paragraph;
168 TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment,
169 ISimpleTextureSource *tsrc);
171 void place(const core::rect<s32> &dest_rect);
172 inline s32 getHeight() { return m_height; };
173 void draw(const core::rect<s32> &dest_rect,
174 const core::position2d<s32> &dest_offset);
175 ParsedText::Element *getElementAt(core::position2d<s32> pos);
176 ParsedText::Tag *m_hovertag;
179 struct RectWithMargin
181 core::rect<s32> rect;
187 gui::IGUIEnvironment *m_environment;
190 std::vector<RectWithMargin> m_floating;
193 class GUIHyperText : public gui::IGUIElement
197 GUIHyperText(const wchar_t *text, gui::IGUIEnvironment *environment,
198 gui::IGUIElement *parent, s32 id,
199 const core::rect<s32> &rectangle, Client *client,
200 ISimpleTextureSource *tsrc);
203 virtual ~GUIHyperText();
205 //! draws the element and its children
208 core::dimension2du getTextDimension();
210 bool OnEvent(const SEvent &event);
215 GUIScrollBar *m_vscrollbar;
219 u32 m_scrollbar_width;
220 core::rect<s32> m_display_text_rect;
221 core::position2d<s32> m_text_scrollpos;
223 ParsedText::Element *getElementAt(s32 X, s32 Y);
224 void checkHover(s32 X, s32 Y);