mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-06 19:01:21 +03:00
Added gui/ and ogre/ from OpenMW
This commit is contained in:
parent
5d73b47cc0
commit
fce290104e
10 changed files with 360 additions and 8 deletions
118
gui/layout.hpp
Normal file
118
gui/layout.hpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
#ifndef OENGINE_MYGUI_LAYOUT_H
|
||||
#define OENGINE_MYGUI_LAYOUT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <MyGUI.h>
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
/** The Layout class is an utility class used to load MyGUI layouts
|
||||
from xml files, and to manipulate member widgets.
|
||||
*/
|
||||
class Layout
|
||||
{
|
||||
public:
|
||||
Layout(const std::string & _layout, MyGUI::WidgetPtr _parent = nullptr)
|
||||
: mMainWidget(nullptr)
|
||||
{ initialise(_layout, _parent); }
|
||||
virtual ~Layout() { shutdown(); }
|
||||
|
||||
template <typename T>
|
||||
void getWidget(T * & _widget, const std::string & _name, bool _throw = true)
|
||||
{
|
||||
_widget = nullptr;
|
||||
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin();
|
||||
iter!=mListWindowRoot.end(); ++iter)
|
||||
{
|
||||
MyGUI::WidgetPtr find = (*iter)->findWidget(mPrefix + _name);
|
||||
if (nullptr != find)
|
||||
{
|
||||
T * cast = find->castType<T>(false);
|
||||
if (nullptr != cast)
|
||||
_widget = cast;
|
||||
else if (_throw)
|
||||
{
|
||||
MYGUI_EXCEPT("Error cast : dest type = '" << T::getClassTypeName()
|
||||
<< "' source name = '" << find->getName()
|
||||
<< "' source type = '" << find->getTypeName() << "' in layout '" << mLayoutName << "'");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
MYGUI_ASSERT( ! _throw, "widget name '" << _name << "' in layout '" << mLayoutName << "' not found.");
|
||||
}
|
||||
|
||||
void initialise(const std::string & _layout,
|
||||
MyGUI::WidgetPtr _parent = nullptr)
|
||||
{
|
||||
const std::string MAIN_WINDOW = "_Main";
|
||||
mLayoutName = _layout;
|
||||
|
||||
if (mLayoutName.empty())
|
||||
mMainWidget = _parent;
|
||||
else
|
||||
{
|
||||
mPrefix = MyGUI::utility::toString(this, "_");
|
||||
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
|
||||
|
||||
const std::string main_name = mPrefix + MAIN_WINDOW;
|
||||
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter)
|
||||
{
|
||||
if ((*iter)->getName() == main_name)
|
||||
{
|
||||
mMainWidget = (*iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
MYGUI_ASSERT(mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
|
||||
}
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
MyGUI::LayoutManager::getInstance().unloadLayout(mListWindowRoot);
|
||||
mListWindowRoot.clear();
|
||||
}
|
||||
|
||||
void setCoord(int x, int y, int w, int h)
|
||||
{
|
||||
mMainWidget->setCoord(x,y,w,h);
|
||||
}
|
||||
|
||||
void setVisible(bool b)
|
||||
{
|
||||
mMainWidget->setVisible(b);
|
||||
}
|
||||
|
||||
void setText(const std::string& name, const std::string& caption)
|
||||
{
|
||||
MyGUI::WidgetPtr pt;
|
||||
getWidget(pt, name);
|
||||
pt->setCaption(caption);
|
||||
}
|
||||
|
||||
void setTextColor(const std::string& name, float r, float g, float b)
|
||||
{
|
||||
MyGUI::WidgetPtr pt;
|
||||
getWidget(pt, name);
|
||||
MyGUI::StaticText *st = dynamic_cast<MyGUI::StaticText*>(pt);
|
||||
if(st != NULL)
|
||||
st->setTextColour(MyGUI::Colour(b,g,r));
|
||||
}
|
||||
|
||||
void setImage(const std::string& name, const std::string& imgName)
|
||||
{
|
||||
MyGUI::StaticImagePtr pt;
|
||||
getWidget(pt, name);
|
||||
pt->setImageTexture(imgName);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
MyGUI::WidgetPtr mMainWidget;
|
||||
std::string mPrefix;
|
||||
std::string mLayoutName;
|
||||
MyGUI::VectorWidgetPtr mListWindowRoot;
|
||||
};
|
||||
}
|
||||
#endif
|
43
gui/manager.cpp
Normal file
43
gui/manager.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <MyGUI.h>
|
||||
#include <MyGUI_OgrePlatform.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "manager.hpp"
|
||||
|
||||
using namespace GUI;
|
||||
|
||||
void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging)
|
||||
{
|
||||
assert(wnd);
|
||||
assert(mgr);
|
||||
|
||||
using namespace MyGUI;
|
||||
|
||||
// Enable/disable MyGUI logging to stdout. (Logging to MyGUI.log is
|
||||
// still enabled.) In order to do this we have to initialize the log
|
||||
// manager before the main gui system itself, otherwise the main
|
||||
// object will get the chance to spit out a few messages before we
|
||||
// can able to disable it.
|
||||
LogManager::initialise();
|
||||
LogManager::setSTDOutputEnabled(logging);
|
||||
|
||||
// Set up OGRE platform. We might make this more generic later.
|
||||
mPlatform = new OgrePlatform();
|
||||
mPlatform->initialise(wnd, mgr);
|
||||
|
||||
// Create GUI
|
||||
mGui = new Gui();
|
||||
mGui->initialise();
|
||||
}
|
||||
|
||||
void MyGUIManager::shutdown()
|
||||
{
|
||||
if(mGui) delete mGui;
|
||||
if(mPlatform)
|
||||
{
|
||||
mPlatform->shutdown();
|
||||
delete mPlatform;
|
||||
}
|
||||
mGui = NULL;
|
||||
mPlatform = NULL;
|
||||
}
|
33
gui/manager.hpp
Normal file
33
gui/manager.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef OENGINE_MYGUI_MANAGER_H
|
||||
#define OENGINE_MYGUI_MANAGER_H
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
class OgrePlatform;
|
||||
class Gui;
|
||||
}
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class RenderWindow;
|
||||
class SceneManager;
|
||||
}
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
class MyGUIManager
|
||||
{
|
||||
MyGUI::OgrePlatform *mPlatform;
|
||||
MyGUI::Gui *mGui;
|
||||
|
||||
public:
|
||||
MyGUIManager() : mPlatform(NULL), mGui(NULL) {}
|
||||
MyGUIManager(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false)
|
||||
{ setup(wnd,mgr,logging); }
|
||||
~MyGUIManager() { shutdown(); }
|
||||
|
||||
void setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false);
|
||||
void shutdown();
|
||||
};
|
||||
}
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue