From c76d41c903f231eb8db2405e77030dd43e04f32d Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 3 Sep 2021 18:25:47 +0800 Subject: [PATCH] Add callback to IGUIStaticText to allow text handling --- lib/irrlicht/include/IGUIStaticText.h | 2 ++ .../source/Irrlicht/CGUIStaticText.cpp | 18 ++++++++++++++++++ lib/irrlicht/source/Irrlicht/CGUIStaticText.h | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/irrlicht/include/IGUIStaticText.h b/lib/irrlicht/include/IGUIStaticText.h index 77c5a5842..5c9e10386 100644 --- a/lib/irrlicht/include/IGUIStaticText.h +++ b/lib/irrlicht/include/IGUIStaticText.h @@ -8,6 +8,7 @@ #include "IGUIElement.h" #include "SColor.h" +#include #include namespace irr @@ -123,6 +124,7 @@ namespace gui virtual void clearGlyphLayouts() = 0; virtual void setUseGlyphLayoutsOnly(bool gls_only) = 0; virtual bool useGlyphLayoutsOnly() const = 0; + virtual void setMouseCallback(std::function cb) {} }; diff --git a/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp b/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp index b8b566f92..ade17cf19 100644 --- a/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp +++ b/lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp @@ -375,6 +375,24 @@ void CGUIStaticText::deserializeAttributes(io::IAttributes* in, io::SAttributeRe } +bool CGUIStaticText::OnEvent(const SEvent& event) +{ + if (IsEnabled) + { + switch(event.EventType) + { + case EET_MOUSE_INPUT_EVENT: + { + if (m_callback && m_callback(this, event.MouseInput)) + return true; + } + default: + break; + } + } + return IGUIElement::OnEvent(event); +} + } // end namespace gui } // end namespace irr diff --git a/lib/irrlicht/source/Irrlicht/CGUIStaticText.h b/lib/irrlicht/source/Irrlicht/CGUIStaticText.h index bbdb66cd7..c1d3ee837 100644 --- a/lib/irrlicht/source/Irrlicht/CGUIStaticText.h +++ b/lib/irrlicht/source/Irrlicht/CGUIStaticText.h @@ -110,7 +110,9 @@ namespace gui virtual void clearGlyphLayouts() { m_glyph_layouts.clear(); } virtual void setUseGlyphLayoutsOnly(bool gls_only) { m_use_glyph_layouts_only = gls_only; } virtual bool useGlyphLayoutsOnly() const { return m_use_glyph_layouts_only; } - + //! called if an event happened. + virtual bool OnEvent(const SEvent& event); + virtual void setMouseCallback(std::function cb) { m_callback = cb; } private: //! Breaks the single text line. @@ -131,6 +133,7 @@ namespace gui //! If true, setText / updating this element will not reshape with Text object bool m_use_glyph_layouts_only; std::vector m_glyph_layouts; + std::function m_callback; }; } // end namespace gui