Luanti 5.15.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>
11#include <IGUIElement.h>
12#include <IGUIEnvironment.h>
13#include "irr_v3d.h"
14
15
17class Client;
18class GUIScrollBar;
19
21{
22public:
23 ParsedText(const wchar_t *text);
25
33
39
46
54
61
62 typedef std::unordered_map<std::string, std::string> StyleList;
63 typedef std::unordered_map<std::string, std::string> AttrsList;
64
65 struct Tag
66 {
67 std::string name;
70 };
71
72 struct Element
73 {
74 std::list<Tag *> tags;
76 core::stringw text = "";
77
78 core::dimension2d<u32> dim;
79 core::position2d<s32> pos;
81
83
85
86 gui::IGUIFont *font;
87
88 video::SColor color;
89 video::SColor hovercolor;
91
92 s32 baseline = 0;
93
94 // img & item specific attributes
95 std::string name;
96 v3s16 angle{0, 0, 0};
97 v3s16 rotation{0, 0, 0};
98
99 s32 margin = 10;
100
101 void setStyle(StyleList &style);
102 };
103
105 {
106 std::vector<Element> elements;
108 s32 margin = 10;
109
110 void setStyle(StyleList &style);
111 };
112
113 std::vector<Paragraph> m_paragraphs;
114
115 // Element style
116 s32 margin = 3;
119 video::SColor background_color;
120
122
123protected:
124 typedef enum { ER_NONE, ER_TAG, ER_NEWLINE } EndReason;
125
126 // Parser functions
127 void enterElement(ElementType type);
128 void endElement();
129 void enterParagraph();
130 void endParagraph(EndReason reason);
131 void pushChar(wchar_t c);
132 ParsedText::Tag *newTag(const std::string &name, const AttrsList &attrs);
133 ParsedText::Tag *openTag(const std::string &name, const AttrsList &attrs);
134 bool closeTag(const std::string &name);
135 void parseGenericStyleAttr(const std::string &name, const std::string &value,
136 StyleList &style);
137 void parseStyles(const AttrsList &attrs, StyleList &style);
138 void globalTag(const ParsedText::AttrsList &attrs);
139 u32 parseTag(const wchar_t *text, u32 cursor);
140 void parse(const wchar_t *text);
141
142 std::unordered_map<std::string, StyleList> m_elementtags;
143 std::unordered_map<std::string, StyleList> m_paragraphtags;
144
145 std::vector<Tag *> m_not_root_tags;
146 std::list<Tag *> m_active_tags;
147
148 // Current values
154};
155
157{
158public:
159 TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment,
161
162 void place(const core::rect<s32> &dest_rect);
163 inline s32 getHeight() { return m_height; };
164 void draw(const core::rect<s32> &clip_rect,
165 const core::position2d<s32> &dest_offset);
166 ParsedText::Element *getElementAt(core::position2d<s32> pos);
168
169protected:
171 {
172 core::rect<s32> rect;
174 };
175
179 gui::IGUIEnvironment *m_guienv;
182 std::vector<RectWithMargin> m_floating;
183};
184
185class GUIHyperText : public gui::IGUIElement
186{
187public:
189 GUIHyperText(const wchar_t *text, gui::IGUIEnvironment *environment,
190 gui::IGUIElement *parent, s32 id,
191 const core::rect<s32> &rectangle, Client *client,
193
195 virtual ~GUIHyperText();
196
198 virtual void draw();
199
200 core::dimension2du getTextDimension();
201
202 bool OnEvent(const SEvent &event);
203
204protected:
205 // GUI members
209
210 // Positioning
212 core::rect<s32> m_display_text_rect;
213 core::position2d<s32> m_text_scrollpos;
214
215 ParsedText::Element *getElementAt(s32 X, s32 Y);
216 void checkHover(s32 X, s32 Y);
217};
Definition client.h:106
Definition guiHyperText.h:186
ISimpleTextureSource * m_tsrc
Definition guiHyperText.h:206
core::position2d< s32 > m_text_scrollpos
Definition guiHyperText.h:213
virtual void draw()
draws the element and its children
Definition guiHyperText.cpp:1142
u32 m_scrollbar_width
Definition guiHyperText.h:211
void checkHover(s32 X, s32 Y)
Definition guiHyperText.cpp:1047
core::dimension2du getTextDimension()
ParsedText::Element * getElementAt(s32 X, s32 Y)
Definition guiHyperText.cpp:1039
bool OnEvent(const SEvent &event)
Definition guiHyperText.cpp:1070
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:207
core::rect< s32 > m_display_text_rect
Definition guiHyperText.h:212
virtual ~GUIHyperText()
destructor
Definition guiHyperText.cpp:1033
TextDrawer m_drawer
Definition guiHyperText.h:208
Definition guiScrollBar.h:25
Definition texturesource.h:34
Definition guiHyperText.h:21
void enterParagraph()
Definition guiHyperText.cpp:250
void enterElement(ElementType type)
Definition guiHyperText.cpp:260
void endElement()
Definition guiHyperText.cpp:227
EndReason
Definition guiHyperText.h:124
@ ER_NONE
Definition guiHyperText.h:124
@ ER_TAG
Definition guiHyperText.h:124
@ ER_NEWLINE
Definition guiHyperText.h:124
std::unordered_map< std::string, std::string > AttrsList
Definition guiHyperText.h:63
video::SColor background_color
Definition guiHyperText.h:119
bool closeTag(const std::string &name)
Definition guiHyperText.cpp:305
ParsedText::Tag * openTag(const std::string &name, const AttrsList &attrs)
Definition guiHyperText.cpp:298
std::vector< Tag * > m_not_root_tags
Definition guiHyperText.h:145
void globalTag(const ParsedText::AttrsList &attrs)
Definition guiHyperText.cpp:345
BackgroundType
Definition guiHyperText.h:35
@ BACKGROUND_NONE
Definition guiHyperText.h:36
@ BACKGROUND_COLOR
Definition guiHyperText.h:37
void endParagraph(EndReason reason)
Definition guiHyperText.cpp:232
std::unordered_map< std::string, std::string > StyleList
Definition guiHyperText.h:62
ValignType
Definition guiHyperText.h:56
@ VALIGN_MIDDLE
Definition guiHyperText.h:57
@ VALIGN_BOTTOM
Definition guiHyperText.h:59
@ VALIGN_TOP
Definition guiHyperText.h:58
void parse(const wchar_t *text)
Definition guiHyperText.cpp:169
Paragraph * m_paragraph
Definition guiHyperText.h:151
u32 parseTag(const wchar_t *text, u32 cursor)
Definition guiHyperText.cpp:385
StyleList m_style
Definition guiHyperText.h:149
~ParsedText()
Definition guiHyperText.cpp:163
Tag m_root_tag
Definition guiHyperText.h:121
void parseGenericStyleAttr(const std::string &name, const std::string &value, StyleList &style)
Definition guiHyperText.cpp:317
void pushChar(wchar_t c)
Definition guiHyperText.cpp:273
FloatType
Definition guiHyperText.h:41
@ FLOAT_NONE
Definition guiHyperText.h:42
@ FLOAT_LEFT
Definition guiHyperText.h:44
@ FLOAT_RIGHT
Definition guiHyperText.h:43
std::list< Tag * > m_active_tags
Definition guiHyperText.h:146
EndReason m_end_paragraph_reason
Definition guiHyperText.h:153
HalignType
Definition guiHyperText.h:48
@ HALIGN_RIGHT
Definition guiHyperText.h:51
@ HALIGN_LEFT
Definition guiHyperText.h:50
@ HALIGN_JUSTIFY
Definition guiHyperText.h:52
@ HALIGN_CENTER
Definition guiHyperText.h:49
ValignType valign
Definition guiHyperText.h:117
std::unordered_map< std::string, StyleList > m_paragraphtags
Definition guiHyperText.h:143
void parseStyles(const AttrsList &attrs, StyleList &style)
Definition guiHyperText.cpp:339
std::unordered_map< std::string, StyleList > m_elementtags
Definition guiHyperText.h:142
ParsedText(const wchar_t *text)
Definition guiHyperText.cpp:88
s32 margin
Definition guiHyperText.h:116
ElementType
Definition guiHyperText.h:27
@ ELEMENT_SEPARATOR
Definition guiHyperText.h:29
@ ELEMENT_TEXT
Definition guiHyperText.h:28
@ ELEMENT_IMAGE
Definition guiHyperText.h:30
@ ELEMENT_ITEM
Definition guiHyperText.h:31
bool m_empty_paragraph
Definition guiHyperText.h:152
Element * m_element
Definition guiHyperText.h:150
std::vector< Paragraph > m_paragraphs
Definition guiHyperText.h:113
BackgroundType background_type
Definition guiHyperText.h:118
ParsedText::Tag * newTag(const std::string &name, const AttrsList &attrs)
Definition guiHyperText.cpp:288
Definition guiHyperText.h:157
s32 getHeight()
Definition guiHyperText.h:163
std::vector< RectWithMargin > m_floating
Definition guiHyperText.h:182
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:167
Client * m_client
null in the mainmenu
Definition guiHyperText.h:177
s32 m_voffset
Definition guiHyperText.h:181
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:178
s32 m_height
Definition guiHyperText.h:180
gui::IGUIEnvironment * m_guienv
Definition guiHyperText.h:179
ParsedText m_text
Definition guiHyperText.h:176
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
Definition activeobjectmgr.cpp:11
Definition guiHyperText.h:73
video::SColor hovercolor
Definition guiHyperText.h:89
s32 baseline
Definition guiHyperText.h:92
std::string name
Definition guiHyperText.h:95
s32 margin
Definition guiHyperText.h:99
video::SColor color
Definition guiHyperText.h:88
bool underline
Definition guiHyperText.h:90
v3s16 rotation
Definition guiHyperText.h:97
v3s16 angle
Definition guiHyperText.h:96
core::position2d< s32 > pos
Definition guiHyperText.h:79
void setStyle(StyleList &style)
Definition guiHyperText.cpp:41
std::list< Tag * > tags
Definition guiHyperText.h:74
s32 drawwidth
Definition guiHyperText.h:80
gui::IGUIFont * font
Definition guiHyperText.h:86
ElementType type
Definition guiHyperText.h:75
ValignType valign
Definition guiHyperText.h:84
FloatType floating
Definition guiHyperText.h:82
core::dimension2d< u32 > dim
Definition guiHyperText.h:78
core::stringw text
Definition guiHyperText.h:76
Definition guiHyperText.h:105
void setStyle(StyleList &style)
Definition guiHyperText.cpp:76
std::vector< Element > elements
Definition guiHyperText.h:106
HalignType halign
Definition guiHyperText.h:107
s32 margin
Definition guiHyperText.h:108
Definition guiHyperText.h:66
AttrsList attrs
Definition guiHyperText.h:68
std::string name
Definition guiHyperText.h:67
StyleList style
Definition guiHyperText.h:69
Definition guiHyperText.h:171
s32 margin
Definition guiHyperText.h:173
core::rect< s32 > rect
Definition guiHyperText.h:172