diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 5446038b0..5d66db217 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -617,9 +617,9 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor) // ----------------------------------------------------------------------------- // Text Drawer -TextDrawer::TextDrawer(const wchar_t *text, Client *client, - gui::IGUIEnvironment *environment, ISimpleTextureSource *tsrc) : - m_text(text), m_client(client), m_tsrc(tsrc), m_guienv(environment) +TextDrawer::TextDrawer(const wchar_t *text, + const std::function& texture_getter) : + m_text(text), m_texture_getter(texture_getter) { // Size all elements for (auto &p : m_text.m_paragraphs) { @@ -649,9 +649,7 @@ TextDrawer::TextDrawer(const wchar_t *text, Client *client, core::dimension2d dim(80, 80); if (e.type == ParsedText::ELEMENT_IMAGE) { - video::ITexture *texture = - m_tsrc-> - getTexture(stringw_to_utf8(e.text)); + video::ITexture* texture = m_texture_getter(stringw_to_utf8(e.text)); if (texture) dim = texture->getOriginalSize(); } @@ -930,9 +928,8 @@ void TextDrawer::place(const core::rect &dest_rect) // Draw text in a rectangle with a given offset. Items are actually placed in // relative (to upper left corner) coordinates. void TextDrawer::draw(const core::rect &clip_rect, - const core::position2d &dest_offset) + const core::position2d dest_offset, irr::video::IVideoDriver *driver, Client *client) { - irr::video::IVideoDriver *driver = m_guienv->getVideoDriver(); core::position2d offset = dest_offset; offset.Y += m_voffset; @@ -976,10 +973,10 @@ void TextDrawer::draw(const core::rect &clip_rect, case ParsedText::ELEMENT_IMAGE: { video::ITexture *texture = - m_tsrc->getTexture( + m_texture_getter( stringw_to_utf8(el.text)); if (texture != 0) - m_guienv->getVideoDriver()->draw2DImage( + driver->draw2DImage( texture, rect, irr::core::rect( core::position2d(0, 0), @@ -988,13 +985,13 @@ void TextDrawer::draw(const core::rect &clip_rect, } break; case ParsedText::ELEMENT_ITEM: { - if (m_client) { - IItemDefManager *idef = m_client->idef(); + if (client) { + IItemDefManager *idef = 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, + drawItemStack(driver, + g_fontengine->getFont(), item, rect, &clip_rect, client, IT_ROT_OTHER, el.angle, el.rotation); } } break; @@ -1011,8 +1008,10 @@ GUIHyperText::GUIHyperText(const wchar_t *text, IGUIEnvironment *environment, IGUIElement *parent, s32 id, const core::rect &rectangle, Client *client, ISimpleTextureSource *tsrc) : IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle), - m_tsrc(tsrc), m_vscrollbar(nullptr), - m_drawer(text, client, environment, tsrc), m_text_scrollpos(0, 0) + m_vscrollbar(nullptr), m_client(client), + m_drawer(text, [=](const std::string& s){ + return tsrc->getTexture(s); + }), m_text_scrollpos(0, 0) { IGUISkin *skin = 0; @@ -1095,7 +1094,7 @@ bool GUIHyperText::OnEvent(const SEvent &event) m_vscrollbar->setPosInterpolated(m_vscrollbar->getTargetPos() - event.MouseInput.Wheel * m_vscrollbar->getSmallStep()); m_text_scrollpos.Y = -m_vscrollbar->getPos(); - m_drawer.draw(m_display_text_rect, m_text_scrollpos); + m_drawer.draw(m_display_text_rect, m_text_scrollpos, Environment->getVideoDriver(), m_client); checkHover(event.MouseInput.X, event.MouseInput.Y); return true; @@ -1171,7 +1170,7 @@ void GUIHyperText::draw() m_vscrollbar->setVisible(false); } m_drawer.draw(AbsoluteClippingRect, - m_display_text_rect.UpperLeftCorner + m_text_scrollpos); + m_display_text_rect.UpperLeftCorner + m_text_scrollpos, Environment->getVideoDriver(), m_client); // draw children IGUIElement::draw(); diff --git a/src/gui/guiHyperText.h b/src/gui/guiHyperText.h index d11e80dd7..59cc87ac0 100644 --- a/src/gui/guiHyperText.h +++ b/src/gui/guiHyperText.h @@ -155,13 +155,13 @@ protected: class TextDrawer { public: - TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment, - ISimpleTextureSource *tsrc); + TextDrawer(const wchar_t *text, + const std::function& texture_getter); void place(const core::rect &dest_rect); inline s32 getHeight() { return m_height; }; void draw(const core::rect &clip_rect, - const core::position2d &dest_offset); + const core::position2d dest_offset, video::IVideoDriver* driver, Client *client); ParsedText::Element *getElementAt(core::position2d pos); ParsedText::Tag *m_hovertag; @@ -173,9 +173,7 @@ protected: }; ParsedText m_text; - Client *m_client; ///< null in the mainmenu - ISimpleTextureSource *m_tsrc; - gui::IGUIEnvironment *m_guienv; + std::function m_texture_getter; s32 m_height; s32 m_voffset; std::vector m_floating; @@ -202,7 +200,7 @@ public: protected: // GUI members - ISimpleTextureSource *m_tsrc; + Client *m_client; GUIScrollBar *m_vscrollbar; TextDrawer m_drawer;