MyGUI 3.0.1

MyGUI_SharedLayer.cpp

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 
00024 #include "MyGUI_Precompiled.h"
00025 #include "MyGUI_LayerItem.h"
00026 #include "MyGUI_SharedLayer.h"
00027 #include "MyGUI_LayerNode.h"
00028 #include "MyGUI_RenderManager.h"
00029 
00030 namespace MyGUI
00031 {
00032 
00033     SharedLayer::SharedLayer() :
00034         mIsPick(false),
00035         mChildItem(nullptr)
00036     {
00037     }
00038 
00039     SharedLayer::~SharedLayer()
00040     {
00041         MYGUI_ASSERT(mChildItem == nullptr, "Layer '" << getName() << "' must be empty before destroy");
00042     }
00043 
00044     void SharedLayer::deserialization(xml::ElementPtr _node, Version _version)
00045     {
00046         mName = _node->findAttribute("name");
00047         if (_version >= Version(1, 2))
00048         {
00049             MyGUI::xml::ElementEnumerator propert = _node->getElementEnumerator();
00050             while (propert.next("Property"))
00051             {
00052                 const std::string& key = propert->findAttribute("key");
00053                 const std::string& value = propert->findAttribute("value");
00054                 if (key == "Pick") mIsPick = utility::parseValue<bool>(value);
00055             }
00056         }
00057         else
00058         {
00059             mIsPick = utility::parseBool(_version < Version(1, 0) ? _node->findAttribute("peek") : _node->findAttribute("pick"));
00060         }
00061     }
00062 
00063     ILayerNode* SharedLayer::createChildItemNode()
00064     {
00065         if (mChildItem == nullptr)
00066         {
00067             mChildItem = new SharedLayerNode(this);
00068         }
00069 
00070         mChildItem->addUsing();
00071         return mChildItem;
00072     }
00073 
00074     void SharedLayer::destroyChildItemNode(ILayerNode* _item)
00075     {
00076         // айтем рутовый, мы удаляем
00077         if (mChildItem == _item)
00078         {
00079             mChildItem->removeUsing();
00080             if (0 == mChildItem->countUsing())
00081             {
00082                 delete mChildItem;
00083                 mChildItem = nullptr;
00084             }
00085             return;
00086         }
00087         //MYGUI_EXCEPT("item node not found");
00088     }
00089 
00090     void SharedLayer::upChildItemNode(ILayerNode* _item)
00091     {
00092         // если есть отец, то пусть сам рулит
00093         ILayerNode * parent = _item->getParent();
00094         if (parent != nullptr)
00095         {
00096             parent->upChildItemNode(_item);
00097         }
00098     }
00099 
00100     ILayerItem * SharedLayer::getLayerItemByPoint(int _left, int _top)
00101     {
00102         if (!mIsPick) return nullptr;
00103         if (mChildItem != nullptr)
00104         {
00105             ILayerItem * item = mChildItem->getLayerItemByPoint(_left, _top);
00106             if (item != nullptr) return item;
00107         }
00108         return nullptr;
00109     }
00110 
00111     IntPoint SharedLayer::getPosition(int _left, int _top) const
00112     {
00113         return IntPoint(_left, _top);
00114     }
00115 
00116     void SharedLayer::renderToTarget(IRenderTarget* _target, bool _update)
00117     {
00118         if (mChildItem != nullptr) mChildItem->renderToTarget(_target, _update);
00119     }
00120 
00121     EnumeratorILayerNode SharedLayer::getEnumerator()
00122     {
00123         static VectorILayerNode nodes;
00124         if (mChildItem == nullptr)
00125         {
00126             nodes.clear();
00127         }
00128         else
00129         {
00130             if (nodes.empty()) nodes.push_back(mChildItem);
00131             else nodes[0] = mChildItem;
00132         }
00133 
00134         return EnumeratorILayerNode(nodes);
00135     }
00136 
00137     void SharedLayer::dumpStatisticToLog()
00138     {
00139         static const char* spacer = "                                                                                                                        ";
00140         MYGUI_LOG(Info, spacer);
00141         MYGUI_LOG(Info, "Layer name='" << getName() << "'" << " type='" << getTypeName() << "'" << spacer);
00142         MYGUI_LOG(Info, "Count root nodes : " << (mChildItem == nullptr ? 0 : 1) << spacer);
00143 
00144         if (mChildItem != nullptr)
00145         {
00146             mChildItem->dumpStatisticToLog(0);
00147         }
00148     }
00149 
00150     const IntSize& SharedLayer::getSize() const
00151     {
00152         return RenderManager::getInstance().getViewSize();
00153     }
00154 
00155 } // namespace MyGUI
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines