Skip to content

Commit

Permalink
Fix hypertext in the mainmenu (#13731)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Aug 13, 2023
1 parent 526c5f2 commit 137e4ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
2 changes: 0 additions & 2 deletions src/gui/guiFormSpecMenu.cpp
Expand Up @@ -1670,8 +1670,6 @@ void GUIFormSpecMenu::parseField(parserData* data, const std::string &element,

void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &element)
{
MY_CHECKCLIENT("hypertext");

std::vector<std::string> parts;
if (!precheckElement("hypertext", element, 4, 4, parts))
return;
Expand Down
31 changes: 15 additions & 16 deletions src/gui/guiHyperText.cpp
Expand Up @@ -600,8 +600,7 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor)

TextDrawer::TextDrawer(const wchar_t *text, Client *client,
gui::IGUIEnvironment *environment, ISimpleTextureSource *tsrc) :
m_text(text),
m_client(client), m_environment(environment)
m_text(text), m_client(client), m_tsrc(tsrc), m_guienv(environment)
{
// Size all elements
for (auto &p : m_text.m_paragraphs) {
Expand Down Expand Up @@ -632,7 +631,7 @@ TextDrawer::TextDrawer(const wchar_t *text, Client *client,

if (e.type == ParsedText::ELEMENT_IMAGE) {
video::ITexture *texture =
m_client->getTextureSource()->
m_tsrc->
getTexture(stringw_to_utf8(e.text));
if (texture)
dim = texture->getOriginalSize();
Expand Down Expand Up @@ -914,7 +913,7 @@ void TextDrawer::place(const core::rect<s32> &dest_rect)
void TextDrawer::draw(const core::rect<s32> &clip_rect,
const core::position2d<s32> &dest_offset)
{
irr::video::IVideoDriver *driver = m_environment->getVideoDriver();
irr::video::IVideoDriver *driver = m_guienv->getVideoDriver();
core::position2d<s32> offset = dest_offset;
offset.Y += m_voffset;

Expand Down Expand Up @@ -958,10 +957,10 @@ void TextDrawer::draw(const core::rect<s32> &clip_rect,

case ParsedText::ELEMENT_IMAGE: {
video::ITexture *texture =
m_client->getTextureSource()->getTexture(
m_tsrc->getTexture(
stringw_to_utf8(el.text));
if (texture != 0)
m_environment->getVideoDriver()->draw2DImage(
m_guienv->getVideoDriver()->draw2DImage(
texture, rect,
irr::core::rect<s32>(
core::position2d<s32>(0, 0),
Expand All @@ -970,15 +969,15 @@ void TextDrawer::draw(const core::rect<s32> &clip_rect,
} break;

case ParsedText::ELEMENT_ITEM: {
IItemDefManager *idef = m_client->idef();
ItemStack item;
item.deSerialize(stringw_to_utf8(el.text), idef);

drawItemStack(
m_environment->getVideoDriver(),
g_fontengine->getFont(), item, rect, &clip_rect,
m_client, IT_ROT_OTHER, el.angle, el.rotation
);
if (m_client) {
IItemDefManager *idef = m_client->idef();
ItemStack item;
item.deSerialize(stringw_to_utf8(el.text), idef);

drawItemStack(m_guienv->getVideoDriver(),
g_fontengine->getFont(), item, rect, &clip_rect, m_client,
IT_ROT_OTHER, el.angle, el.rotation);
}
} break;
}
}
Expand All @@ -993,7 +992,7 @@ GUIHyperText::GUIHyperText(const wchar_t *text, IGUIEnvironment *environment,
IGUIElement *parent, s32 id, const core::rect<s32> &rectangle,
Client *client, ISimpleTextureSource *tsrc) :
IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle),
m_client(client), m_vscrollbar(nullptr),
m_tsrc(tsrc), m_vscrollbar(nullptr),
m_drawer(text, client, environment, tsrc), m_text_scrollpos(0, 0)
{

Expand Down
7 changes: 4 additions & 3 deletions src/gui/guiHyperText.h
Expand Up @@ -188,8 +188,9 @@ class TextDrawer
};

ParsedText m_text;
Client *m_client;
gui::IGUIEnvironment *m_environment;
Client *m_client; ///< null in the mainmenu
ISimpleTextureSource *m_tsrc;
gui::IGUIEnvironment *m_guienv;
s32 m_height;
s32 m_voffset;
std::vector<RectWithMargin> m_floating;
Expand All @@ -216,7 +217,7 @@ class GUIHyperText : public gui::IGUIElement

protected:
// GUI members
Client *m_client;
ISimpleTextureSource *m_tsrc;
GUIScrollBar *m_vscrollbar;
TextDrawer m_drawer;

Expand Down

0 comments on commit 137e4ce

Please sign in to comment.