1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 09:32:45 +00:00
OpenMW/apps/openmw/mwgui/layout.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.0 KiB
C++
Raw Normal View History

2015-05-01 02:09:57 +02:00
#ifndef OPENMW_MWGUI_LAYOUT_H
#define OPENMW_MWGUI_LAYOUT_H
2010-07-09 21:21:04 +02:00
2015-01-10 02:50:43 +01:00
#include <string>
#include <string_view>
2015-01-10 02:50:43 +01:00
#include <MyGUI_Widget.h>
2010-07-09 21:21:04 +02:00
#include <components/debug/debuglog.hpp>
2015-05-01 02:09:57 +02:00
namespace MWGui
2010-07-09 21:21:04 +02:00
{
/** The Layout class is an utility class used to load MyGUI layouts
from xml files, and to manipulate member widgets.
*/
class Layout
{
public:
Layout(std::string_view layout)
: mMainWidget(nullptr)
{
initialise(layout);
2015-01-10 02:50:43 +01:00
assert(mMainWidget);
}
2022-09-22 21:26:05 +03:00
virtual ~Layout()
{
2022-09-22 21:26:05 +03:00
try
{
2015-01-10 02:50:43 +01:00
shutdown();
2022-09-22 21:26:05 +03:00
}
catch (const MyGUI::Exception& e)
2022-09-22 21:26:05 +03:00
{
Log(Debug::Error) << "Error in the destructor: " << e.what();
2022-09-22 21:26:05 +03:00
}
}
2010-07-09 21:21:04 +02:00
MyGUI::Widget* getWidget(std::string_view name);
2015-01-10 02:50:43 +01:00
2010-07-09 21:21:04 +02:00
template <typename T>
void getWidget(T*& _widget, std::string_view _name)
2010-07-09 21:21:04 +02:00
{
2015-01-10 02:50:43 +01:00
MyGUI::Widget* w = getWidget(_name);
T* cast = w->castType<T>(false);
if (!cast)
2022-09-22 21:26:05 +03:00
{
2015-01-10 02:50:43 +01:00
MYGUI_EXCEPT("Error cast : dest type = '" << T::getClassTypeName() << "' source name = '"
<< w->getName() << "' source type = '" << w->getTypeName()
<< "' in layout '" << mLayoutName << "'");
2022-09-22 21:26:05 +03:00
}
else
2015-01-10 02:50:43 +01:00
_widget = cast;
2010-07-09 21:21:04 +02:00
}
2022-09-22 21:26:05 +03:00
private:
2015-01-10 02:50:43 +01:00
void initialise(std::string_view layout);
2010-07-09 21:21:04 +02:00
2015-01-10 02:50:43 +01:00
void shutdown();
2010-07-09 21:21:04 +02:00
2015-01-10 02:50:43 +01:00
public:
void setCoord(int x, int y, int w, int h);
virtual void setVisible(bool b);
2010-07-09 21:21:04 +02:00
2022-08-16 21:15:03 +02:00
void setText(std::string_view name, std::string_view caption);
2010-07-09 21:21:04 +02:00
2013-12-03 18:42:35 +01:00
// NOTE: this assume that mMainWidget is of type Window.
void setTitle(std::string_view title);
2012-04-16 15:48:01 +02:00
2015-01-10 02:50:43 +01:00
MyGUI::Widget* mMainWidget;
2010-07-09 21:21:04 +02:00
protected:
std::string mPrefix;
std::string mLayoutName;
MyGUI::VectorWidgetPtr mListWindowRoot;
};
2015-05-01 02:09:57 +02:00
}
2010-07-09 21:21:04 +02:00
#endif