MyGUI_OverlappedLayer.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_OverlappedLayer.h"
#include "MyGUI_LayerNode.h"
#include "MyGUI_RenderManager.h"
namespace MyGUI
{
OverlappedLayer::OverlappedLayer()
{
mViewSize = RenderManager::getInstance().getViewSize();
}
OverlappedLayer::~OverlappedLayer()
{
if (!mChildItems.empty())
MYGUI_LOG(Critical, "Layer '" << getName() << "' must be empty before destroy");
}
void OverlappedLayer::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 OverlappedLayer::setPick(bool _pick)
{
mIsPick = _pick;
}
ILayerNode* OverlappedLayer::createChildItemNode()
{
// создаем рутовый айтем
ILayerNode* node = new LayerNode(this);
mChildItems.push_back(node);
mOutOfDate = true;
return node;
}
void OverlappedLayer::destroyChildItemNode(ILayerNode* _item)
{
// если есть отец, то русть сам и удаляет
ILayerNode* parent = _item->getParent();
if (parent)
{
parent->destroyChildItemNode(_item);
mOutOfDate = true;
return;
}
// айтем рутовый, мы удаляем
for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
{
if ((*iter) == _item)
{
delete _item;
mChildItems.erase(iter);
mOutOfDate = true;
return;
}
}
MYGUI_EXCEPT("item node not found");
}
void OverlappedLayer::upChildItemNode(ILayerNode* _item)
{
// если есть отец, то пусть сам рулит
ILayerNode* parent = _item->getParent();
if (parent != nullptr)
{
parent->upChildItemNode(_item);
mOutOfDate = true;
return;
}
if ((2 > mChildItems.size()) || (mChildItems.back() == _item))
return;
for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
{
if ((*iter) == _item)
{
mChildItems.erase(iter);
mChildItems.push_back(_item);
mOutOfDate = true;
return;
}
}
MYGUI_EXCEPT("item node not found");
}
ILayerItem* OverlappedLayer::getLayerItemByPoint(int _left, int _top) const
{
if (!mIsPick)
return nullptr;
VectorILayerNode::const_reverse_iterator iter = mChildItems.rbegin();
while (iter != mChildItems.rend())
{
ILayerItem* item = (*iter)->getLayerItemByPoint(_left, _top);
if (item != nullptr)
return item;
++iter;
}
return nullptr;
}
IntPoint OverlappedLayer::getPosition(int _left, int _top) const
{
return {_left, _top};
}
void OverlappedLayer::renderToTarget(IRenderTarget* _target, bool _update)
{
for (auto& childItem : mChildItems)
childItem->renderToTarget(_target, _update);
mOutOfDate = false;
}
void OverlappedLayer::resizeView(const IntSize& _viewSize)
{
for (auto& childItem : mChildItems)
childItem->resizeView(_viewSize);
mViewSize = _viewSize;
}
EnumeratorILayerNode OverlappedLayer::getEnumerator() const
{
return EnumeratorILayerNode(mChildItems);
}
size_t OverlappedLayer::getLayerNodeCount() const
{
return mChildItems.size();
}
ILayerNode* OverlappedLayer::getLayerNodeAt(size_t _index) const
{
MYGUI_ASSERT_RANGE(_index, mChildItems.size(), "OverlappedLayer::getLayerNodeAt");
return mChildItems[_index];
}
const IntSize& OverlappedLayer::getSize() const
{
return mViewSize;
}
bool OverlappedLayer::isOutOfDate() const
{
for (const auto& childItem : mChildItems)
{
if (static_cast<const LayerNode*>(childItem)->isOutOfDate())
return true;
}
return mOutOfDate;
}
} // namespace MyGUI
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition MyGUI_Diagnostic.h:21
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_OverlappedLayer.h
MyGUI_Precompiled.h
MyGUI_RenderManager.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::ILayerItem::getLayerItemByPoint
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const =0
MyGUI::ILayerNode
Definition MyGUI_ILayerNode.h:29
MyGUI::ILayerNode::getParent
virtual ILayerNode * getParent() const =0
MyGUI::ILayerNode::destroyChildItemNode
virtual void destroyChildItemNode(ILayerNode *_node)=0
MyGUI::ILayerNode::upChildItemNode
virtual void upChildItemNode(ILayerNode *_item)=0
MyGUI::IRenderTarget
Definition MyGUI_IRenderTarget.h:21
MyGUI::LayerNode
Definition MyGUI_LayerNode.h:23
MyGUI::OverlappedLayer::getSize
const IntSize & getSize() const override
Definition MyGUI_OverlappedLayer.cpp:183
MyGUI::OverlappedLayer::deserialization
void deserialization(xml::ElementPtr _node, Version _version) override
Definition MyGUI_OverlappedLayer.cpp:27
MyGUI::OverlappedLayer::getEnumerator
EnumeratorILayerNode getEnumerator() const override
Definition MyGUI_OverlappedLayer.cpp:166
MyGUI::OverlappedLayer::setPick
void setPick(bool _pick)
Definition MyGUI_OverlappedLayer.cpp:51
MyGUI::OverlappedLayer::getLayerNodeAt
ILayerNode * getLayerNodeAt(size_t _index) const override
Definition MyGUI_OverlappedLayer.cpp:176
MyGUI::OverlappedLayer::mIsPick
bool mIsPick
Definition MyGUI_OverlappedLayer.h:59
MyGUI::OverlappedLayer::mChildItems
VectorILayerNode mChildItems
Definition MyGUI_OverlappedLayer.h:60
MyGUI::OverlappedLayer::~OverlappedLayer
~OverlappedLayer() override
Definition MyGUI_OverlappedLayer.cpp:21
MyGUI::OverlappedLayer::resizeView
void resizeView(const IntSize &_viewSize) override
Definition MyGUI_OverlappedLayer.cpp:158
MyGUI::OverlappedLayer::getPosition
IntPoint getPosition(int _left, int _top) const override
Definition MyGUI_OverlappedLayer.cpp:145
MyGUI::OverlappedLayer::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_OverlappedLayer.cpp:129
MyGUI::OverlappedLayer::OverlappedLayer
OverlappedLayer()
Definition MyGUI_OverlappedLayer.cpp:16
MyGUI::OverlappedLayer::destroyChildItemNode
void destroyChildItemNode(ILayerNode *_item) override
Definition MyGUI_OverlappedLayer.cpp:67
MyGUI::OverlappedLayer::mOutOfDate
bool mOutOfDate
Definition MyGUI_OverlappedLayer.h:61
MyGUI::OverlappedLayer::createChildItemNode
ILayerNode * createChildItemNode() override
Definition MyGUI_OverlappedLayer.cpp:56
MyGUI::OverlappedLayer::renderToTarget
void renderToTarget(IRenderTarget *_target, bool _update) override
Definition MyGUI_OverlappedLayer.cpp:150
MyGUI::OverlappedLayer::upChildItemNode
void upChildItemNode(ILayerNode *_item) override
Definition MyGUI_OverlappedLayer.cpp:97
MyGUI::OverlappedLayer::getLayerNodeCount
size_t getLayerNodeCount() const override
Definition MyGUI_OverlappedLayer.cpp:171
MyGUI::OverlappedLayer::mViewSize
IntSize mViewSize
Definition MyGUI_OverlappedLayer.h:62
MyGUI::OverlappedLayer::isOutOfDate
bool isOutOfDate() const
Definition MyGUI_OverlappedLayer.cpp:188
MyGUI::RenderManager::getViewSize
virtual const IntSize & getViewSize() const =0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
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::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30