2015-01-10 01:50:43 +00:00
|
|
|
#include "layout.hpp"
|
|
|
|
|
|
|
|
#include <MyGUI_Gui.h>
|
|
|
|
#include <MyGUI_LayoutManager.h>
|
|
|
|
#include <MyGUI_TextBox.h>
|
|
|
|
#include <MyGUI_Widget.h>
|
|
|
|
#include <MyGUI_Window.h>
|
|
|
|
|
2022-08-24 20:16:03 +00:00
|
|
|
#include "ustring.hpp"
|
|
|
|
|
2015-05-01 00:09:57 +00:00
|
|
|
namespace MWGui
|
2015-01-10 01:50:43 +00:00
|
|
|
{
|
2022-06-27 17:13:17 +00:00
|
|
|
void Layout::initialise(std::string_view _layout)
|
2015-01-10 01:50:43 +00:00
|
|
|
{
|
2022-06-27 17:13:17 +00:00
|
|
|
const auto MAIN_WINDOW = "_Main";
|
2015-01-10 01:50:43 +00:00
|
|
|
mLayoutName = _layout;
|
|
|
|
|
2022-06-27 17:13:17 +00:00
|
|
|
mPrefix = MyGUI::utility::toString(this, "_");
|
|
|
|
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix);
|
2015-01-10 01:50:43 +00:00
|
|
|
|
2022-06-27 17:13:17 +00:00
|
|
|
const std::string main_name = mPrefix + MAIN_WINDOW;
|
|
|
|
for (MyGUI::Widget* widget : mListWindowRoot)
|
|
|
|
{
|
|
|
|
if (widget->getName() == main_name)
|
|
|
|
mMainWidget = widget;
|
2022-02-26 13:54:42 +00:00
|
|
|
|
2022-06-27 17:13:17 +00:00
|
|
|
// Force the alignment to update immediately
|
|
|
|
widget->_setAlign(widget->getSize(), widget->getParentSize());
|
2015-01-10 01:50:43 +00:00
|
|
|
}
|
2022-06-27 17:13:17 +00:00
|
|
|
MYGUI_ASSERT(
|
|
|
|
mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
|
2015-01-10 01:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layout::shutdown()
|
|
|
|
{
|
2021-03-13 23:43:46 +00:00
|
|
|
setVisible(false);
|
2015-01-10 01:50:43 +00:00
|
|
|
MyGUI::Gui::getInstance().destroyWidget(mMainWidget);
|
|
|
|
mListWindowRoot.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layout::setCoord(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
mMainWidget->setCoord(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layout::setVisible(bool b)
|
|
|
|
{
|
|
|
|
mMainWidget->setVisible(b);
|
|
|
|
}
|
|
|
|
|
2022-08-24 20:16:03 +00:00
|
|
|
void Layout::setText(std::string_view name, std::string_view caption)
|
2015-01-10 01:50:43 +00:00
|
|
|
{
|
|
|
|
MyGUI::Widget* pt;
|
|
|
|
getWidget(pt, name);
|
2022-08-24 20:16:03 +00:00
|
|
|
static_cast<MyGUI::TextBox*>(pt)->setCaption(toUString(caption));
|
2015-01-10 01:50:43 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 19:15:03 +00:00
|
|
|
void Layout::setTitle(std::string_view title)
|
2015-01-10 01:50:43 +00:00
|
|
|
{
|
2019-01-24 18:16:42 +00:00
|
|
|
MyGUI::Window* window = static_cast<MyGUI::Window*>(mMainWidget);
|
2022-08-24 20:16:03 +00:00
|
|
|
MyGUI::UString uTitle = toUString(title);
|
2019-01-24 18:16:42 +00:00
|
|
|
|
2022-08-16 19:15:03 +00:00
|
|
|
if (window->getCaption() != uTitle)
|
|
|
|
window->setCaptionWithReplacing(uTitle);
|
2015-01-10 01:50:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 17:13:17 +00:00
|
|
|
MyGUI::Widget* Layout::getWidget(std::string_view _name)
|
2015-01-10 01:50:43 +00:00
|
|
|
{
|
2022-06-27 17:13:17 +00:00
|
|
|
std::string target = mPrefix;
|
|
|
|
target += _name;
|
2019-03-02 09:27:59 +00:00
|
|
|
for (MyGUI::Widget* widget : mListWindowRoot)
|
2015-01-10 01:50:43 +00:00
|
|
|
{
|
2022-06-27 17:13:17 +00:00
|
|
|
MyGUI::Widget* find = widget->findWidget(target);
|
2015-01-10 01:50:43 +00:00
|
|
|
if (nullptr != find)
|
|
|
|
{
|
|
|
|
return find;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MYGUI_EXCEPT("widget name '" << _name << "' in layout '" << mLayoutName << "' not found.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|