MyGUI_SharedLayer.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_LayerItem.h"
#include "MyGUI_SharedLayer.h"
#include "MyGUI_LayerNode.h"
#include "MyGUI_RenderManager.h"
namespace MyGUI
{
SharedLayer::SharedLayer()
{
mViewSize = RenderManager::getInstance().getViewSize();
}
SharedLayer::~SharedLayer()
{
if (mChildItem != nullptr)
MYGUI_LOG(Critical, "Layer '" << getName() << "' must be empty before destroy");
}
void SharedLayer::deserialization(xml::ElementPtr _node, Version _version)
{
mName = _node->findAttribute("name");
if (_version >= Version(1, 2))
{
MyGUI::xml::ElementEnumerator propert = _node->getElementEnumerator();
while (propert.next("Property"))
{
std::string_view key = propert->findAttribute("key");
std::string_view value = propert->findAttribute("value");
if (key == "Pick")
setPick(utility::parseValue<bool>(value));
}
}
else if (_version >= Version(1, 0))
{
setPick(utility::parseBool(_node->findAttribute("pick")));
}
else
{
setPick(utility::parseBool(_node->findAttribute("peek")));
}
}
void SharedLayer::setPick(bool _pick)
{
mIsPick = _pick;
}
ILayerNode* SharedLayer::createChildItemNode()
{
if (mChildItem == nullptr)
mChildItem = new SharedLayerNode(this);
mChildItem->addUsing();
mOutOfDate = true;
return mChildItem;
}
void SharedLayer::destroyChildItemNode(ILayerNode* _item)
{
// айтем рутовый, мы удаляем
if (mChildItem == _item)
{
mChildItem->removeUsing();
if (0 == mChildItem->countUsing())
{
delete mChildItem;
mChildItem = nullptr;
}
mOutOfDate = true;
return;
}
//MYGUI_EXCEPT("item node not found");
}
void SharedLayer::upChildItemNode(ILayerNode* _item)
{
// если есть отец, то пусть сам рулит
ILayerNode* parent = _item->getParent();
if (parent != nullptr)
parent->upChildItemNode(_item);
mOutOfDate = true;
}
ILayerItem* SharedLayer::getLayerItemByPoint(int _left, int _top) const
{
if (!mIsPick)
return nullptr;
if (mChildItem != nullptr)
{
ILayerItem* item = mChildItem->getLayerItemByPoint(_left, _top);
if (item != nullptr)
return item;
}
return nullptr;
}
IntPoint SharedLayer::getPosition(int _left, int _top) const
{
return {_left, _top};
}
void SharedLayer::renderToTarget(IRenderTarget* _target, bool _update)
{
if (mChildItem != nullptr)
mChildItem->renderToTarget(_target, _update);
mOutOfDate = false;
}
void SharedLayer::resizeView(const IntSize& _viewSize)
{
if (mChildItem != nullptr)
mChildItem->resizeView(_viewSize);
mViewSize = _viewSize;
}
EnumeratorILayerNode SharedLayer::getEnumerator() const
{
static VectorILayerNode nodes;
if (mChildItem == nullptr)
{
nodes.clear();
}
else
{
if (nodes.empty())
nodes.push_back(mChildItem);
else
nodes[0] = mChildItem;
}
return EnumeratorILayerNode(nodes);
}
size_t SharedLayer::getLayerNodeCount() const
{
return mChildItem == nullptr ? 0 : 1;
}
ILayerNode* SharedLayer::getLayerNodeAt(size_t _index) const
{
size_t count = getLayerNodeCount();
MYGUI_ASSERT_RANGE(_index, count, "SharedLayer::getLayerNodeAt");
return mChildItem;
}
const IntSize& SharedLayer::getSize() const
{
return mViewSize;
}
bool SharedLayer::isOutOfDate() const
{
if (mChildItem->isOutOfDate())
return true;
return mOutOfDate;
}
} // namespace MyGUI
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_LayerItem.h
MyGUI_LayerNode.h
MyGUI_Precompiled.h
MyGUI_RenderManager.h
MyGUI_SharedLayer.h
MyGUI::ILayer::getName
const std::string & getName() const
Definition MyGUI_ILayer.h:28
MyGUI::ILayer::mName
std::string mName
Definition MyGUI_ILayer.h:66
MyGUI::ILayerItem
Definition MyGUI_ILayerItem.h:20
MyGUI::ILayerNode
Definition MyGUI_ILayerNode.h:29
MyGUI::ILayerNode::getParent
virtual ILayerNode * getParent() const =0
MyGUI::ILayerNode::upChildItemNode
virtual void upChildItemNode(ILayerNode *_item)=0
MyGUI::IRenderTarget
Definition MyGUI_IRenderTarget.h:21
MyGUI::RenderManager::getViewSize
virtual const IntSize & getViewSize() const =0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::SharedLayer::destroyChildItemNode
void destroyChildItemNode(ILayerNode *_item) override
Definition MyGUI_SharedLayer.cpp:68
MyGUI::SharedLayer::mViewSize
IntSize mViewSize
Definition MyGUI_SharedLayer.h:63
MyGUI::SharedLayer::mChildItem
SharedLayerNode * mChildItem
Definition MyGUI_SharedLayer.h:61
MyGUI::SharedLayer::getEnumerator
EnumeratorILayerNode getEnumerator() const override
Definition MyGUI_SharedLayer.cpp:132
MyGUI::SharedLayer::deserialization
void deserialization(xml::ElementPtr _node, Version _version) override
Definition MyGUI_SharedLayer.cpp:27
MyGUI::SharedLayer::setPick
void setPick(bool _pick)
Definition MyGUI_SharedLayer.cpp:51
MyGUI::SharedLayer::getLayerNodeAt
ILayerNode * getLayerNodeAt(size_t _index) const override
Definition MyGUI_SharedLayer.cpp:155
MyGUI::SharedLayer::renderToTarget
void renderToTarget(IRenderTarget *_target, bool _update) override
Definition MyGUI_SharedLayer.cpp:116
MyGUI::SharedLayer::isOutOfDate
bool isOutOfDate() const
Definition MyGUI_SharedLayer.cpp:168
MyGUI::SharedLayer::createChildItemNode
ILayerNode * createChildItemNode() override
Definition MyGUI_SharedLayer.cpp:56
MyGUI::SharedLayer::getPosition
IntPoint getPosition(int _left, int _top) const override
Definition MyGUI_SharedLayer.cpp:111
MyGUI::SharedLayer::~SharedLayer
~SharedLayer() override
Definition MyGUI_SharedLayer.cpp:21
MyGUI::SharedLayer::upChildItemNode
void upChildItemNode(ILayerNode *_item) override
Definition MyGUI_SharedLayer.cpp:87
MyGUI::SharedLayer::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_SharedLayer.cpp:97
MyGUI::SharedLayer::mOutOfDate
bool mOutOfDate
Definition MyGUI_SharedLayer.h:62
MyGUI::SharedLayer::mIsPick
bool mIsPick
Definition MyGUI_SharedLayer.h:60
MyGUI::SharedLayer::getLayerNodeCount
size_t getLayerNodeCount() const override
Definition MyGUI_SharedLayer.cpp:150
MyGUI::SharedLayer::getSize
const IntSize & getSize() const override
Definition MyGUI_SharedLayer.cpp:163
MyGUI::SharedLayer::SharedLayer
SharedLayer()
Definition MyGUI_SharedLayer.cpp:16
MyGUI::SharedLayer::resizeView
void resizeView(const IntSize &_viewSize) override
Definition MyGUI_SharedLayer.cpp:124
MyGUI::SharedLayerNode
Definition MyGUI_SharedLayerNode.h:17
MyGUI::Version
Definition MyGUI_Version.h:18
MyGUI::xml::ElementEnumerator
Definition MyGUI_XmlDocument.h:121
MyGUI::xml::ElementEnumerator::next
bool next()
Definition MyGUI_XmlDocument.cpp:107
MyGUI::xml::Element::findAttribute
bool findAttribute(std::string_view _name, std::string &_value)
Definition MyGUI_XmlDocument.cpp:242
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition MyGUI_XmlDocument.cpp:348
MyGUI::utility::parseBool
bool parseBool(std::string_view _value)
Definition MyGUI_StringUtility.h:127
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition MyGUI_XmlDocument.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::EnumeratorILayerNode
Enumerator< VectorILayerNode > EnumeratorILayerNode
Definition MyGUI_ILayerNode.h:26
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::VectorILayerNode
std::vector< ILayerNode * > VectorILayerNode
Definition MyGUI_ILayerNode.h:25
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30