• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

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_Common.h"
00026 #include "MyGUI_LayerItem.h"
00027 #include "MyGUI_SharedLayer.h"
00028 #include "MyGUI_LayerNode.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 (false == 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     void SharedLayer::renderToTarget(IRenderTarget* _target, bool _update)
00112     {
00113         if (mChildItem != nullptr) mChildItem->renderToTarget(_target, _update);
00114     }
00115 
00116     EnumeratorILayerNode SharedLayer::getEnumerator()
00117     {
00118         static VectorILayerNode nodes;
00119         if (mChildItem == nullptr)
00120         {
00121             nodes.clear();
00122         }
00123         else
00124         {
00125             if (nodes.empty()) nodes.push_back(mChildItem);
00126             else nodes[0] = mChildItem;
00127         }
00128 
00129         return EnumeratorILayerNode(nodes);
00130     }
00131 
00132 
00133 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1