MyGUI_Gui.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_Gui.h"
#include "MyGUI_Widget.h"
#include "MyGUI_InputManager.h"
#include "MyGUI_SubWidgetManager.h"
#include "MyGUI_LogManager.h"
#include "MyGUI_SkinManager.h"
#include "MyGUI_WidgetManager.h"
#include "MyGUI_LayerManager.h"
#include "MyGUI_FontManager.h"
#include "MyGUI_ControllerManager.h"
#include "MyGUI_PointerManager.h"
#include "MyGUI_ClipboardManager.h"
#include "MyGUI_LayoutManager.h"
#include "MyGUI_PluginManager.h"
#include "MyGUI_DynLibManager.h"
#include "MyGUI_LanguageManager.h"
#include "MyGUI_ResourceManager.h"
#include "MyGUI_RenderManager.h"
#include "MyGUI_FactoryManager.h"
#include "MyGUI_ToolTipManager.h"
#include "MyGUI_TextureUtility.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(Gui);
Gui::Gui() :
mSingletonHolder(this)
{
}
void Gui::initialise(const std::string& _core)
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
MYGUI_LOG(
Info,
"* MyGUI version " << MYGUI_VERSION_MAJOR << "." << MYGUI_VERSION_MINOR << "." << MYGUI_VERSION_PATCH);
// создаем и инициализируем синглтоны
mResourceManager = new ResourceManager();
mLayerManager = new LayerManager();
mWidgetManager = new WidgetManager();
mInputManager = new InputManager();
mSubWidgetManager = new SubWidgetManager();
mSkinManager = new SkinManager();
mFontManager = new FontManager();
mControllerManager = new ControllerManager();
mPointerManager = new PointerManager();
mClipboardManager = new ClipboardManager();
mLayoutManager = new LayoutManager();
mDynLibManager = new DynLibManager();
mPluginManager = new PluginManager();
mLanguageManager = new LanguageManager();
mFactoryManager = new FactoryManager();
mToolTipManager = new ToolTipManager();
mResourceManager->initialise();
mLayerManager->initialise();
mWidgetManager->initialise();
mInputManager->initialise();
mSubWidgetManager->initialise();
mSkinManager->initialise();
mFontManager->initialise();
mControllerManager->initialise();
mPointerManager->initialise();
mClipboardManager->initialise();
mLayoutManager->initialise();
mDynLibManager->initialise();
mPluginManager->initialise();
mLanguageManager->initialise();
mFactoryManager->initialise();
mToolTipManager->initialise();
WidgetManager::getInstance().registerUnlinker(this);
// загружаем дефолтные настройки если надо
if (!_core.empty())
mResourceManager->load(_core);
BackwardCompatibility::initialise();
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
#ifndef MYGUI_DONT_USE_OBSOLETE
void Gui::initialise(const std::string& _core, std::string_view _logFileName)
{
initialise(_core);
}
#endif // MYGUI_DONT_USE_OBSOLETE
void Gui::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
BackwardCompatibility::shutdown();
_destroyAllChildWidget();
// деинициализируем и удаляем синглтоны
mPointerManager->shutdown();
mInputManager->shutdown();
mSkinManager->shutdown();
mSubWidgetManager->shutdown();
mLayerManager->shutdown();
mFontManager->shutdown();
mControllerManager->shutdown();
mClipboardManager->shutdown();
mLayoutManager->shutdown();
mPluginManager->shutdown();
mDynLibManager->shutdown();
mLanguageManager->shutdown();
mResourceManager->shutdown();
mFactoryManager->shutdown();
mToolTipManager->shutdown();
WidgetManager::getInstance().unregisterUnlinker(this);
mWidgetManager->shutdown();
delete mPointerManager;
delete mWidgetManager;
delete mInputManager;
delete mSkinManager;
delete mSubWidgetManager;
delete mLayerManager;
delete mFontManager;
delete mControllerManager;
delete mClipboardManager;
delete mLayoutManager;
delete mDynLibManager;
delete mPluginManager;
delete mLanguageManager;
delete mResourceManager;
delete mFactoryManager;
delete mToolTipManager;
// сбрасываем кеш
texture_utility::getTextureSize(std::string{}, false);
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
Widget* Gui::baseCreateWidget(
WidgetStyle _style,
std::string_view _type,
std::string_view _skin,
const IntCoord& _coord,
Align _align,
std::string_view _layer,
std::string_view _name)
{
Widget* widget = WidgetManager::getInstance()
.createWidget(_style, _type, _skin, _coord, /*_align, */ nullptr, nullptr, _name);
mWidgetChild.push_back(widget);
widget->setAlign(_align);
// присоединяем виджет с уровню
if (!_layer.empty())
LayerManager::getInstance().attachToLayerNode(_layer, widget);
return widget;
}
Widget* Gui::findWidgetT(std::string_view _name, bool _throw) const
{
for (const auto& iter : mWidgetChild)
{
Widget* widget = iter->findWidget(_name);
if (widget != nullptr)
return widget;
}
MYGUI_ASSERT(!_throw, "Widget '" << _name << "' not found");
return nullptr;
}
// удяляет неудачника
void Gui::_destroyChildWidget(Widget* _widget)
{
MYGUI_ASSERT(nullptr != _widget, "invalid widget pointer");
VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
if (iter != mWidgetChild.end())
{
// сохраняем указатель
MyGUI::Widget* widget = *iter;
// удаляем из списка
mWidgetChild.erase(iter);
// отписываем от всех
mWidgetManager->unlinkFromUnlinkers(_widget);
// непосредственное удаление
WidgetManager::getInstance()._deleteWidget(widget);
}
else
{
MYGUI_EXCEPT("Widget '" << _widget->getName() << "' not found");
}
}
// удаляет всех детей
void Gui::_destroyAllChildWidget()
{
while (!mWidgetChild.empty())
{
// сразу себя отписывем, иначе вложенной удаление убивает все
Widget* widget = mWidgetChild.back();
mWidgetChild.pop_back();
// отписываем от всех
mWidgetManager->unlinkFromUnlinkers(widget);
// и сами удалим, так как его больше в списке нет
WidgetManager::getInstance()._deleteWidget(widget);
}
}
void Gui::destroyWidget(Widget* _widget)
{
Widget* parent = _widget->getParent();
if (parent != nullptr)
parent->_destroyChildWidget(_widget);
else
_destroyChildWidget(_widget);
}
void Gui::destroyWidgets(const VectorWidgetPtr& _widgets)
{
for (auto* widget : _widgets)
destroyWidget(widget);
}
void Gui::destroyWidgets(EnumeratorWidgetPtr& _widgets)
{
VectorWidgetPtr widgets;
while (_widgets.next())
widgets.push_back(_widgets.current());
destroyWidgets(widgets);
}
void Gui::_unlinkWidget(Widget* _widget)
{
eventFrameStart.clear(_widget);
}
void Gui::_linkChildWidget(Widget* _widget)
{
VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
MYGUI_ASSERT(iter == mWidgetChild.end(), "widget already exist");
mWidgetChild.push_back(_widget);
}
void Gui::_unlinkChildWidget(Widget* _widget)
{
VectorWidgetPtr::iterator iter = std::remove(mWidgetChild.begin(), mWidgetChild.end(), _widget);
MYGUI_ASSERT(iter != mWidgetChild.end(), "widget not found");
mWidgetChild.erase(iter);
}
Widget* Gui::createWidgetT(
std::string_view _type,
std::string_view _skin,
const IntCoord& _coord,
Align _align,
std::string_view _layer,
std::string_view _name)
{
return baseCreateWidget(WidgetStyle::Overlapped, _type, _skin, _coord, _align, _layer, _name);
}
Widget* Gui::createWidgetT(
std::string_view _type,
std::string_view _skin,
int _left,
int _top,
int _width,
int _height,
Align _align,
std::string_view _layer,
std::string_view _name)
{
return createWidgetT(_type, _skin, IntCoord(_left, _top, _width, _height), _align, _layer, _name);
}
Widget* Gui::createWidgetRealT(
std::string_view _type,
std::string_view _skin,
const FloatCoord& _coord,
Align _align,
std::string_view _layer,
std::string_view _name)
{
IntSize size = RenderManager::getInstance().getViewSize();
return createWidgetT(
_type,
_skin,
IntCoord(
static_cast<int>(_coord.left * size.width),
static_cast<int>(_coord.top * size.height),
static_cast<int>(_coord.width * size.width),
static_cast<int>(_coord.height * size.height)),
_align,
_layer,
_name);
}
Widget* Gui::createWidgetRealT(
std::string_view _type,
std::string_view _skin,
float _left,
float _top,
float _width,
float _height,
Align _align,
std::string_view _layer,
std::string_view _name)
{
IntSize size = RenderManager::getInstance().getViewSize();
return createWidgetT(
_type,
_skin,
IntCoord(
static_cast<int>(_left * size.width),
static_cast<int>(_top * size.height),
static_cast<int>(_width * size.width),
static_cast<int>(_height * size.height)),
_align,
_layer,
_name);
}
Widget* Gui::findWidgetT(std::string_view _name, std::string_view _prefix, bool _throw) const
{
std::string name{_prefix};
name += _name;
return findWidgetT(name, _throw);
}
void Gui::destroyChildWidget(Widget* _widget)
{
_destroyChildWidget(_widget);
}
void Gui::destroyAllChildWidget()
{
_destroyAllChildWidget();
}
EnumeratorWidgetPtr Gui::getEnumerator() const
{
return EnumeratorWidgetPtr(mWidgetChild);
}
void Gui::frameEvent(float _time) const
{
eventFrameStart(_time);
}
} // namespace MyGUI
MyGUI_ClipboardManager.h
MyGUI_ControllerManager.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition MyGUI_Diagnostic.h:21
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_DynLibManager.h
MyGUI_FactoryManager.h
MyGUI_FontManager.h
MyGUI_Gui.h
MyGUI_InputManager.h
MyGUI_LanguageManager.h
MyGUI_LayerManager.h
MyGUI_LayoutManager.h
MyGUI_LogManager.h
MyGUI_PluginManager.h
MyGUI_PointerManager.h
MyGUI_Precompiled.h
MYGUI_VERSION_PATCH
#define MYGUI_VERSION_PATCH
Definition MyGUI_Prerequest.h:62
MYGUI_VERSION_MAJOR
#define MYGUI_VERSION_MAJOR
Definition MyGUI_Prerequest.h:60
MYGUI_VERSION_MINOR
#define MYGUI_VERSION_MINOR
Definition MyGUI_Prerequest.h:61
MyGUI_RenderManager.h
MyGUI_ResourceManager.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI_SkinManager.h
MyGUI_SubWidgetManager.h
MyGUI_TextureUtility.h
MyGUI_ToolTipManager.h
MyGUI_Widget.h
MyGUI_WidgetManager.h
MyGUI::BackwardCompatibility::initialise
static void initialise()
Definition MyGUI_BackwardCompatibility.cpp:1201
MyGUI::BackwardCompatibility::shutdown
static void shutdown()
Definition MyGUI_BackwardCompatibility.cpp:1433
MyGUI::ClipboardManager
Definition MyGUI_ClipboardManager.h:22
MyGUI::ControllerManager
Definition MyGUI_ControllerManager.h:21
MyGUI::DynLibManager
Manager of dynamic libraries.
Definition MyGUI_DynLibManager.h:21
MyGUI::Enumerator::current
T::const_reference current()
Definition MyGUI_Enumerator.h:84
MyGUI::Enumerator::next
bool next()
Definition MyGUI_Enumerator.h:65
MyGUI::FactoryManager
Definition MyGUI_FactoryManager.h:19
MyGUI::FontManager
Definition MyGUI_FontManager.h:22
MyGUI::Gui::_unlinkChildWidget
void _unlinkChildWidget(Widget *_widget)
Definition MyGUI_Gui.cpp:268
MyGUI::Gui::destroyWidget
void destroyWidget(Widget *_widget)
Definition MyGUI_Gui.cpp:233
MyGUI::Gui::shutdown
void shutdown()
Definition MyGUI_Gui.cpp:104
MyGUI::Gui::Gui
Gui()
Definition MyGUI_Gui.cpp:36
MyGUI::Gui::createWidgetRealT
Widget * createWidgetRealT(std::string_view _type, std::string_view _skin, const FloatCoord &_coord, Align _align, std::string_view _layer, std::string_view _name={})
Definition MyGUI_Gui.cpp:300
MyGUI::Gui::getClassTypeName
static std::string_view getClassTypeName()
Definition MyGUI_Gui.cpp:34
MyGUI::Gui::frameEvent
void frameEvent(float _time) const
Definition MyGUI_Gui.cpp:369
MyGUI::Gui::initialise
void initialise(const std::string &_core="MyGUI_Core.xml")
Definition MyGUI_Gui.cpp:41
MyGUI::Gui::destroyAllChildWidget
void destroyAllChildWidget()
Definition MyGUI_Gui.cpp:359
MyGUI::Gui::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition MyGUI_Gui.cpp:242
MyGUI::Gui::_linkChildWidget
void _linkChildWidget(Widget *_widget)
Definition MyGUI_Gui.cpp:261
MyGUI::Gui::WidgetManager
friend class WidgetManager
Definition MyGUI_Gui.h:26
MyGUI::Gui::findWidgetT
Widget * findWidgetT(std::string_view _name, bool _throw=true) const
Definition MyGUI_Gui.cpp:178
MyGUI::Gui::Gui
Gui(const Gui &)=delete
MyGUI::Gui::createWidgetT
Widget * createWidgetT(std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer, std::string_view _name={})
Definition MyGUI_Gui.cpp:275
MyGUI::Gui::destroyChildWidget
void destroyChildWidget(Widget *_widget)
Definition MyGUI_Gui.cpp:354
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
MyGUI::Gui::getEnumerator
EnumeratorWidgetPtr getEnumerator() const
Definition MyGUI_Gui.cpp:364
MyGUI::InputManager
Definition MyGUI_InputManager.h:27
MyGUI::LanguageManager
Definition MyGUI_LanguageManager.h:21
MyGUI::LayerManager
Definition MyGUI_LayerManager.h:23
MyGUI::LayerManager::getInstance
static LayerManager & getInstance()
MyGUI::LayerManager::attachToLayerNode
void attachToLayerNode(std::string_view _name, Widget *_item)
Definition MyGUI_LayerManager.cpp:122
MyGUI::LayoutManager
Definition MyGUI_LayoutManager.h:27
MyGUI::PluginManager
Plugin manager. Load/unload and register plugins.
Definition MyGUI_PluginManager.h:25
MyGUI::PointerManager
Definition MyGUI_PointerManager.h:22
MyGUI::RenderManager::getViewSize
virtual const IntSize & getViewSize() const =0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::ResourceManager
Definition MyGUI_ResourceManager.h:23
MyGUI::SkinManager
Definition MyGUI_SkinManager.h:22
MyGUI::SubWidgetManager
Definition MyGUI_SubWidgetManager.h:17
MyGUI::ToolTipManager
Definition MyGUI_ToolTipManager.h:18
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::getParent
Widget * getParent() const
Definition MyGUI_Widget.cpp:1352
MyGUI::Widget::_destroyChildWidget
void _destroyChildWidget(Widget *_widget)
Definition MyGUI_Widget.cpp:411
MyGUI::Widget::getName
const std::string & getName() const
Get name of widget.
Definition MyGUI_Widget.cpp:1322
MyGUI::Widget::findWidget
Widget * findWidget(std::string_view _name)
Definition MyGUI_Widget.cpp:575
MyGUI::Widget::setAlign
virtual void setAlign(Align _value)
Definition MyGUI_Widget.cpp:775
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:144
MyGUI::WidgetManager::createWidget
Widget * createWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Widget *_parent, ICroppedRectangle *_cropeedParent, std::string_view _name)
Definition MyGUI_WidgetManager.cpp:102
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::WidgetManager::_deleteWidget
void _deleteWidget(Widget *_widget)
Definition MyGUI_WidgetManager.cpp:170
MyGUI::WidgetManager::unlinkFromUnlinkers
void unlinkFromUnlinkers(Widget *_widget)
Definition MyGUI_WidgetManager.cpp:152
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:138
MyGUI::delegates::MultiDelegate::clear
void clear()
Definition MyGUI_Delegate.h:209
MyGUI::texture_utility::getTextureSize
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
Definition MyGUI_TextureUtility.cpp:17
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::FloatCoord
types::TCoord< float > FloatCoord
Definition MyGUI_Types.h:37
MyGUI::EnumeratorWidgetPtr
Enumerator< VectorWidgetPtr > EnumeratorWidgetPtr
Definition MyGUI_WidgetDefines.h:22
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::WidgetStyle
Definition MyGUI_WidgetStyle.h:19
MyGUI::WidgetStyle::Overlapped
@ Overlapped
Definition MyGUI_WidgetStyle.h:24
MyGUI::types::TCoord::height
T height
Definition MyGUI_TCoord.h:23
MyGUI::types::TCoord::width
T width
Definition MyGUI_TCoord.h:22
MyGUI::types::TCoord::top
T top
Definition MyGUI_TCoord.h:21
MyGUI::types::TCoord::left
T left
Definition MyGUI_TCoord.h:20
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:19
MyGUI::types::TSize::height
T height
Definition MyGUI_TSize.h:20