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
;
137 typedef enum { ER_NONE
, ER_TAG
, ER_NEWLINE
} EndReason
;
140 void enterElement(ElementType type
);
142 void enterParagraph();
143 void endParagraph(EndReason reason
);
144 void pushChar(wchar_t c
);
145 ParsedText::Tag
*newTag(const std::string
&name
, const AttrsList
&attrs
);
146 ParsedText::Tag
*openTag(const std::string
&name
, const AttrsList
&attrs
);
147 bool closeTag(const std::string
&name
);
148 void parseGenericStyleAttr(const std::string
&name
, const std::string
&value
,
150 void parseStyles(const AttrsList
&attrs
, StyleList
&style
);
151 void globalTag(const ParsedText::AttrsList
&attrs
);
152 u32
parseTag(const wchar_t *text
, u32 cursor
);
153 void parse(const wchar_t *text
);
155 std::unordered_map
<std::string
, StyleList
> m_elementtags
;
156 std::unordered_map
<std::string
, StyleList
> m_paragraphtags
;
158 std::vector
<Tag
*> m_not_root_tags
;
159 std::list
<Tag
*> m_active_tags
;
164 Paragraph
*m_paragraph
;
165 bool m_empty_paragraph
;
166 EndReason m_end_paragraph_reason
;
172 TextDrawer(const wchar_t *text
, Client
*client
, gui::IGUIEnvironment
*environment
,
173 ISimpleTextureSource
*tsrc
);
175 void place(const core::rect
<s32
> &dest_rect
);
176 inline s32
getHeight() { return m_height
; };
177 void draw(const core::rect
<s32
> &clip_rect
,
178 const core::position2d
<s32
> &dest_offset
);
179 ParsedText::Element
*getElementAt(core::position2d
<s32
> pos
);
180 ParsedText::Tag
*m_hovertag
;
183 struct RectWithMargin
185 core::rect
<s32
> rect
;
191 gui::IGUIEnvironment
*m_environment
;
194 std::vector
<RectWithMargin
> m_floating
;
197 class GUIHyperText
: public gui::IGUIElement
201 GUIHyperText(const wchar_t *text
, gui::IGUIEnvironment
*environment
,
202 gui::IGUIElement
*parent
, s32 id
,
203 const core::rect
<s32
> &rectangle
, Client
*client
,
204 ISimpleTextureSource
*tsrc
);
207 virtual ~GUIHyperText();
209 //! draws the element and its children
212 core::dimension2du
getTextDimension();
214 bool OnEvent(const SEvent
&event
);
219 GUIScrollBar
*m_vscrollbar
;
223 u32 m_scrollbar_width
;
224 core::rect
<s32
> m_display_text_rect
;
225 core::position2d
<s32
> m_text_scrollpos
;
227 ParsedText::Element
*getElementAt(s32 X
, s32 Y
);
228 void checkHover(s32 X
, s32 Y
);