mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
GameUI refactor (part 2/X): Move Game::guitext to GameUI + enhancements on StaticText
Other enhancements: * C++ friendlyness for addStaticText() -> move to static StaticText::add()
This commit is contained in:
parent
0ebaed430a
commit
3a772e7ed6
8 changed files with 159 additions and 134 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue