Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
guiHyperText.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2019 EvicenceBKidscode / Pierre-Yves Rollo <dev@pyrollo.com>
4
5#pragma once
6
7#include <vector>
8#include <list>
9#include <unordered_map>
10#include <string>
12
13using namespace irr;
14
16class Client;
17class GUIScrollBar;
18
20{
21public:
22 ParsedText(const wchar_t *text);
24
32
38
45
53
60
61 typedef std::unordered_map<std::string, std::string> StyleList;
62 typedef std::unordered_map<std::string, std::string> AttrsList;
63
64 struct Tag
65 {
66 std::string name;
69 };
70
71 struct Element
72 {
73 std::list<Tag *> tags;
75 core::stringw text = "";
76
77 core::dimension2d<u32> dim;
78 core::position2d<s32> pos;
80
82
84
85 gui::IGUIFont *font;
86
87 irr::video::SColor color;
88 irr::video::SColor hovercolor;
90
91 s32 baseline = 0;
92
93 // img & item specific attributes
94 std::string name;
95 v3s16 angle{0, 0, 0};
96 v3s16 rotation{0, 0, 0};
97
98 s32 margin = 10;
99
100 void setStyle(StyleList &style);
101 };
102
104 {
105 std::vector<Element> elements;
107 s32 margin = 10;
108
109 void setStyle(StyleList &style);
110 };
111
112 std::vector<Paragraph> m_paragraphs;
113
114 // Element style
115 s32 margin = 3;
118 irr::video::SColor background_color;
119
121
122protected:
123 typedef enum { ER_NONE, ER_TAG, ER_NEWLINE } EndReason;
124
125 // Parser functions
126 void enterElement(ElementType type);
127 void endElement();
128 void enterParagraph();
129 void endParagraph(EndReason reason);
130 void pushChar(wchar_t c);
131 ParsedText::Tag *newTag(const std::string &name, const AttrsList &attrs);
132 ParsedText::Tag *openTag(const std::string &name, const AttrsList &attrs);
133 bool closeTag(const std::string &name);
134 void parseGenericStyleAttr(const std::string &name, const std::string &value,
135 StyleList &style);
136 void parseStyles(const AttrsList &attrs, StyleList &style);
137 void globalTag(const ParsedText::AttrsList &attrs);
138 u32 parseTag(const wchar_t *text, u32 cursor);
139 void parse(const wchar_t *text);
140
141 std::unordered_map<std::string, StyleList> m_elementtags;
142 std::unordered_map<std::string, StyleList> m_paragraphtags;
143
144 std::vector<Tag *> m_not_root_tags;
145 std::list<Tag *> m_active_tags;
146
147 // Current values
153};
154
156{
157public:
158 TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment,
160
161 void place(const core::rect<s32> &dest_rect);
162 inline s32 getHeight() { return m_height; };
163 void draw(const core::rect<s32> &clip_rect,
164 const core::position2d<s32> &dest_offset);
165 ParsedText::Element *getElementAt(core::position2d<s32> pos);
167
168protected:
170 {
171 core::rect<s32> rect;
173 };
174
178 gui::IGUIEnvironment *m_guienv;
181 std::vector<RectWithMargin> m_floating;
182};
183
184class GUIHyperText : public gui::IGUIElement
185{
186public:
188 GUIHyperText(const wchar_t *text, gui::IGUIEnvironment *environment,
189 gui::IGUIElement *parent, s32 id,
190 const core::rect<s32> &rectangle, Client *client,
192
194 virtual ~GUIHyperText();
195
197 virtual void draw();
198
199 core::dimension2du getTextDimension();
200
201 bool OnEvent(const SEvent &event);
202
203protected:
204 // GUI members
208
209 // Positioning
211 core::rect<s32> m_display_text_rect;
212 core::position2d<s32> m_text_scrollpos;
213
214 ParsedText::Element *getElementAt(s32 X, s32 Y);
215 void checkHover(s32 X, s32 Y);
216};
Definition client.h:105
Definition guiHyperText.h:185
ISimpleTextureSource * m_tsrc
Definition guiHyperText.h:205
core::position2d< s32 > m_text_scrollpos
Definition guiHyperText.h:212
virtual void draw()
draws the element and its children
Definition guiHyperText.cpp:1146
u32 m_scrollbar_width
Definition guiHyperText.h:210
void checkHover(s32 X, s32 Y)
Definition guiHyperText.cpp:1051
core::dimension2du getTextDimension()
ParsedText::Element * getElementAt(s32 X, s32 Y)
Definition guiHyperText.cpp:1043
bool OnEvent(const SEvent &event)
Definition guiHyperText.cpp:1074
GUIHyperText(const wchar_t *text, gui::IGUIEnvironment *environment, gui::IGUIElement *parent, s32 id, const core::rect< s32 > &rectangle, Client *client, ISimpleTextureSource *tsrc)
constructor
Definition guiHyperText.cpp:1010
GUIScrollBar * m_vscrollbar
Definition guiHyperText.h:206
core::rect< s32 > m_display_text_rect
Definition guiHyperText.h:211
virtual ~GUIHyperText()
destructor
Definition guiHyperText.cpp:1037
TextDrawer m_drawer
Definition guiHyperText.h:207
Definition guiScrollBar.h:24
Definition texturesource.h:25
Definition guiHyperText.h:20
void enterParagraph()
Definition guiHyperText.cpp:251
void enterElement(ElementType type)
Definition guiHyperText.cpp:261
void endElement()
Definition guiHyperText.cpp:228
EndReason
Definition guiHyperText.h:123
@ ER_NONE
Definition guiHyperText.h:123
@ ER_TAG
Definition guiHyperText.h:123
@ ER_NEWLINE
Definition guiHyperText.h:123
std::unordered_map< std::string, std::string > AttrsList
Definition guiHyperText.h:62
bool closeTag(const std::string &name)
Definition guiHyperText.cpp:306
ParsedText::Tag * openTag(const std::string &name, const AttrsList &attrs)
Definition guiHyperText.cpp:299
std::vector< Tag * > m_not_root_tags
Definition guiHyperText.h:144
void globalTag(const ParsedText::AttrsList &attrs)
Definition guiHyperText.cpp:346
BackgroundType
Definition guiHyperText.h:34
@ BACKGROUND_NONE
Definition guiHyperText.h:35
@ BACKGROUND_COLOR
Definition guiHyperText.h:36
void endParagraph(EndReason reason)
Definition guiHyperText.cpp:233
std::unordered_map< std::string, std::string > StyleList
Definition guiHyperText.h:61
ValignType
Definition guiHyperText.h:55
@ VALIGN_MIDDLE
Definition guiHyperText.h:56
@ VALIGN_BOTTOM
Definition guiHyperText.h:58
@ VALIGN_TOP
Definition guiHyperText.h:57
void parse(const wchar_t *text)
Definition guiHyperText.cpp:170
Paragraph * m_paragraph
Definition guiHyperText.h:150
u32 parseTag(const wchar_t *text, u32 cursor)
Definition guiHyperText.cpp:386
StyleList m_style
Definition guiHyperText.h:148
irr::video::SColor background_color
Definition guiHyperText.h:118
~ParsedText()
Definition guiHyperText.cpp:164
Tag m_root_tag
Definition guiHyperText.h:120
void parseGenericStyleAttr(const std::string &name, const std::string &value, StyleList &style)
Definition guiHyperText.cpp:318
void pushChar(wchar_t c)
Definition guiHyperText.cpp:274
FloatType
Definition guiHyperText.h:40
@ FLOAT_NONE
Definition guiHyperText.h:41
@ FLOAT_LEFT
Definition guiHyperText.h:43
@ FLOAT_RIGHT
Definition guiHyperText.h:42
std::list< Tag * > m_active_tags
Definition guiHyperText.h:145
EndReason m_end_paragraph_reason
Definition guiHyperText.h:152
HalignType
Definition guiHyperText.h:47
@ HALIGN_RIGHT
Definition guiHyperText.h:50
@ HALIGN_LEFT
Definition guiHyperText.h:49
@ HALIGN_JUSTIFY
Definition guiHyperText.h:51
@ HALIGN_CENTER
Definition guiHyperText.h:48
ValignType valign
Definition guiHyperText.h:116
std::unordered_map< std::string, StyleList > m_paragraphtags
Definition guiHyperText.h:142
void parseStyles(const AttrsList &attrs, StyleList &style)
Definition guiHyperText.cpp:340
std::unordered_map< std::string, StyleList > m_elementtags
Definition guiHyperText.h:141
ParsedText(const wchar_t *text)
Definition guiHyperText.cpp:89
s32 margin
Definition guiHyperText.h:115
ElementType
Definition guiHyperText.h:26
@ ELEMENT_SEPARATOR
Definition guiHyperText.h:28
@ ELEMENT_TEXT
Definition guiHyperText.h:27
@ ELEMENT_IMAGE
Definition guiHyperText.h:29
@ ELEMENT_ITEM
Definition guiHyperText.h:30
bool m_empty_paragraph
Definition guiHyperText.h:151
Element * m_element
Definition guiHyperText.h:149
std::vector< Paragraph > m_paragraphs
Definition guiHyperText.h:112
BackgroundType background_type
Definition guiHyperText.h:117
ParsedText::Tag * newTag(const std::string &name, const AttrsList &attrs)
Definition guiHyperText.cpp:289
Definition guiHyperText.h:156
s32 getHeight()
Definition guiHyperText.h:162
std::vector< RectWithMargin > m_floating
Definition guiHyperText.h:181
void draw(const core::rect< s32 > &clip_rect, const core::position2d< s32 > &dest_offset)
Definition guiHyperText.cpp:932
ParsedText::Element * getElementAt(core::position2d< s32 > pos)
Definition guiHyperText.cpp:676
ParsedText::Tag * m_hovertag
Definition guiHyperText.h:166
Client * m_client
null in the mainmenu
Definition guiHyperText.h:176
s32 m_voffset
Definition guiHyperText.h:180
void place(const core::rect< s32 > &dest_rect)
Definition guiHyperText.cpp:697
TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment, ISimpleTextureSource *tsrc)
Definition guiHyperText.cpp:620
ISimpleTextureSource * m_tsrc
Definition guiHyperText.h:177
s32 m_height
Definition guiHyperText.h:179
gui::IGUIEnvironment * m_guienv
Definition guiHyperText.h:178
ParsedText m_text
Definition guiHyperText.h:175
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
Definition activeobjectmgr.cpp:11
Definition clientmap.h:30
Definition guiHyperText.h:72
s32 baseline
Definition guiHyperText.h:91
irr::video::SColor hovercolor
Definition guiHyperText.h:88
std::string name
Definition guiHyperText.h:94
s32 margin
Definition guiHyperText.h:98
bool underline
Definition guiHyperText.h:89
v3s16 rotation
Definition guiHyperText.h:96
v3s16 angle
Definition guiHyperText.h:95
core::position2d< s32 > pos
Definition guiHyperText.h:78
void setStyle(StyleList &style)
Definition guiHyperText.cpp:42
std::list< Tag * > tags
Definition guiHyperText.h:73
irr::video::SColor color
Definition guiHyperText.h:87
s32 drawwidth
Definition guiHyperText.h:79
gui::IGUIFont * font
Definition guiHyperText.h:85
ElementType type
Definition guiHyperText.h:74
ValignType valign
Definition guiHyperText.h:83
FloatType floating
Definition guiHyperText.h:81
core::dimension2d< u32 > dim
Definition guiHyperText.h:77
core::stringw text
Definition guiHyperText.h:75
Definition guiHyperText.h:104
void setStyle(StyleList &style)
Definition guiHyperText.cpp:77
std::vector< Element > elements
Definition guiHyperText.h:105
HalignType halign
Definition guiHyperText.h:106
s32 margin
Definition guiHyperText.h:107
Definition guiHyperText.h:65
AttrsList attrs
Definition guiHyperText.h:67
std::string name
Definition guiHyperText.h:66
StyleList style
Definition guiHyperText.h:68
Definition guiHyperText.h:170
s32 margin
Definition guiHyperText.h:172
core::rect< s32 > rect
Definition guiHyperText.h:171