Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hypertext in the mainmenu #13731

Merged
merged 2 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
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
27 changes: 13 additions & 14 deletions src/gui/guiHyperText.cpp
Original file line number Diff line number Diff line change
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_environment(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 @@ -958,7 +957,7 @@ 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(
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_environment->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
5 changes: 3 additions & 2 deletions src/gui/guiHyperText.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ class TextDrawer
};

ParsedText m_text;
Client *m_client;
Client *m_client; //< may be null
rubenwardy marked this conversation as resolved.
Show resolved Hide resolved
ISimpleTextureSource *m_tsrc;
gui::IGUIEnvironment *m_environment;
rubenwardy marked this conversation as resolved.
Show resolved Hide resolved
s32 m_height;
s32 m_voffset;
Expand Down Expand Up @@ -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