summaryrefslogtreecommitdiff
path: root/src/irrlicht_changes
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2018-01-03 17:28:57 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-01-05 20:59:30 +0100
commit3a772e7ed6c02f91de57320b1694c7d11e1c7618 (patch)
tree8662cc6a9ac690713d74abdf01406b30c86c8e3b /src/irrlicht_changes
parent0ebaed430ad5cd2523d78d2e2c051576e948fe13 (diff)
downloadminetest-3a772e7ed6c02f91de57320b1694c7d11e1c7618.tar.gz
minetest-3a772e7ed6c02f91de57320b1694c7d11e1c7618.tar.bz2
minetest-3a772e7ed6c02f91de57320b1694c7d11e1c7618.zip
GameUI refactor (part 2/X): Move Game::guitext to GameUI + enhancements on StaticText
Other enhancements: * C++ friendlyness for addStaticText() -> move to static StaticText::add()
Diffstat (limited to 'src/irrlicht_changes')
-rw-r--r--src/irrlicht_changes/static_text.h105
1 files changed, 53 insertions, 52 deletions
diff --git a/src/irrlicht_changes/static_text.h b/src/irrlicht_changes/static_text.h
index de7b47e76..6bb85bd6b 100644
--- a/src/irrlicht_changes/static_text.h
+++ b/src/irrlicht_changes/static_text.h
@@ -42,6 +42,59 @@ namespace gui
//! destructor
virtual ~StaticText();
+ static irr::gui::IGUIStaticText *add(
+ irr::gui::IGUIEnvironment *guienv,
+ const EnrichedString &text,
+ const core::rect< s32 > &rectangle,
+ bool border = false,
+ bool wordWrap = true,
+ irr::gui::IGUIElement *parent = NULL,
+ s32 id = -1,
+ bool fillBackground = false)
+ {
+ if (parent == NULL) {
+ // parent is NULL, so we must find one, or we need not to drop
+ // result, but then there will be a memory leak.
+ //
+ // What Irrlicht does is to use guienv as a parent, but the problem
+ // is that guienv is here only an IGUIEnvironment, while it is a
+ // CGUIEnvironment in Irrlicht, which inherits from both IGUIElement
+ // and IGUIEnvironment.
+ //
+ // A solution would be to dynamic_cast guienv to a
+ // IGUIElement*, but Irrlicht is shipped without rtti support
+ // in some distributions, causing the dymanic_cast to segfault.
+ //
+ // Thus, to find the parent, we create a dummy StaticText and ask
+ // for its parent, and then remove it.
+ irr::gui::IGUIStaticText *dummy_text =
+ guienv->addStaticText(L"", rectangle, border, wordWrap,
+ parent, id, fillBackground);
+ parent = dummy_text->getParent();
+ dummy_text->remove();
+ }
+ irr::gui::IGUIStaticText *result = new irr::gui::StaticText(
+ text, border, guienv, parent,
+ id, rectangle, fillBackground);
+
+ result->setWordWrap(wordWrap);
+ result->drop();
+ return result;
+ }
+
+ static irr::gui::IGUIStaticText *add(
+ irr::gui::IGUIEnvironment *guienv,
+ const wchar_t *text,
+ const core::rect< s32 > &rectangle,
+ bool border = false,
+ bool wordWrap = true,
+ irr::gui::IGUIElement *parent = NULL,
+ s32 id = -1,
+ bool fillBackground = false)
+ {
+ return add(guienv, EnrichedString(text), rectangle, border, wordWrap, parent, id, fillBackground);
+ }
+
//! draws the element and its children
virtual void draw();
@@ -171,46 +224,6 @@ namespace gui
} // end namespace irr
-inline irr::gui::IGUIStaticText *addStaticText(
- irr::gui::IGUIEnvironment *guienv,
- const EnrichedString &text,
- const core::rect< s32 > &rectangle,
- bool border = false,
- bool wordWrap = true,
- irr::gui::IGUIElement *parent = NULL,
- s32 id = -1,
- bool fillBackground = false)
-{
- if (parent == NULL) {
- // parent is NULL, so we must find one, or we need not to drop
- // result, but then there will be a memory leak.
- //
- // What Irrlicht does is to use guienv as a parent, but the problem
- // is that guienv is here only an IGUIEnvironment, while it is a
- // CGUIEnvironment in Irrlicht, which inherits from both IGUIElement
- // and IGUIEnvironment.
- //
- // A solution would be to dynamic_cast guienv to a
- // IGUIElement*, but Irrlicht is shipped without rtti support
- // in some distributions, causing the dymanic_cast to segfault.
- //
- // Thus, to find the parent, we create a dummy StaticText and ask
- // for its parent, and then remove it.
- irr::gui::IGUIStaticText *dummy_text =
- guienv->addStaticText(L"", rectangle, border, wordWrap,
- parent, id, fillBackground);
- parent = dummy_text->getParent();
- dummy_text->remove();
- }
- irr::gui::IGUIStaticText *result = new irr::gui::StaticText(
- text, border, guienv, parent,
- id, rectangle, fillBackground);
-
- result->setWordWrap(wordWrap);
- result->drop();
- return result;
-}
-
inline void setStaticText(irr::gui::IGUIStaticText *static_text, const EnrichedString &text)
{
// dynamic_cast not possible due to some distributions shipped
@@ -245,18 +258,6 @@ inline void setStaticText(irr::gui::IGUIStaticText *static_text, const EnrichedS
#endif
-inline irr::gui::IGUIStaticText *addStaticText(
- irr::gui::IGUIEnvironment *guienv,
- const wchar_t *text,
- const core::rect< s32 > &rectangle,
- bool border = false,
- bool wordWrap = true,
- irr::gui::IGUIElement *parent = NULL,
- s32 id = -1,
- bool fillBackground = false) {
- return addStaticText(guienv, EnrichedString(text), rectangle, border, wordWrap, parent, id, fillBackground);
-}
-
inline void setStaticText(irr::gui::IGUIStaticText *static_text, const wchar_t *text)
{
setStaticText(static_text, EnrichedString(text));