21 template <> LayerManager* Singleton<LayerManager>::msInstance =
nullptr;
22 template <>
const char* Singleton<LayerManager>::mClassTypeName =
"LayerManager";
26 mCategoryName(
"Layer")
60 mIsInitialise =
false;
63 void LayerManager::clear()
65 for (VectorLayer::iterator iter = mLayerNodes.begin(); iter != mLayerNodes.end(); ++iter)
72 void LayerManager::_load(
xml::ElementPtr _node,
const std::string& _file, Version _version)
76 xml::ElementEnumerator layer = _node->getElementEnumerator();
77 while (layer.next(mCategoryName))
82 if ( !layer->findAttribute(
"name", name))
84 MYGUI_LOG(Warning,
"Attribute 'name' not found (file : " << _file <<
")");
88 for (VectorLayer::iterator iter = layers.begin(); iter != layers.end(); ++iter)
90 MYGUI_ASSERT((*iter)->getName() != name,
"Layer '" << name <<
"' already exist (file : " << _file <<
")");
93 std::string type = layer->findAttribute(
"type");
94 if (type.empty() && _version <= Version(1, 0))
97 type = overlapped ?
"OverlappedLayer" :
"SharedLayer";
101 MYGUI_ASSERT(
object !=
nullptr,
"factory '" << type <<
"' is not found");
103 ILayer* item =
object->castType<ILayer>();
104 item->deserialization(layer.current(), _version);
106 layers.push_back(item);
113 void LayerManager::_unlinkWidget(Widget* _widget)
121 MYGUI_ASSERT(
nullptr != _item,
"pointer must be valid");
128 for (VectorLayer::iterator iter = mLayerNodes.begin(); iter != mLayerNodes.end(); ++iter)
130 if (_name == (*iter)->getName())
138 MYGUI_LOG(Error,
"Layer '" << _name <<
"' is not found");
144 MYGUI_ASSERT(
nullptr != _item,
"pointer must be valid");
150 MYGUI_ASSERT(
nullptr != _item,
"pointer must be valid");
156 return getByName(_name,
false) !=
nullptr;
159 void LayerManager::merge(VectorLayer& _layers)
161 for (VectorLayer::iterator iter = mLayerNodes.begin(); iter != mLayerNodes.end(); ++iter)
163 if ((*iter) ==
nullptr)
continue;
165 std::string name = (*iter)->
getName();
166 for (VectorLayer::iterator iter2 = _layers.begin(); iter2 != _layers.end(); ++iter2)
168 if (name == (*iter2)->getName())
186 mLayerNodes = _layers;
189 void LayerManager::destroy(ILayer* _layer)
191 MYGUI_LOG(Info,
"destroy layer '" << _layer->getName() <<
"'");
197 VectorLayer::reverse_iterator iter = mLayerNodes.rbegin();
198 while (iter != mLayerNodes.rend())
201 if (item !=
nullptr)
return static_cast<Widget*
>(item);
209 for (VectorLayer::iterator iter = mLayerNodes.begin(); iter != mLayerNodes.end(); ++iter)
211 (*iter)->renderToTarget(_target, _update);
217 for (VectorLayer::const_iterator iter = mLayerNodes.begin(); iter != mLayerNodes.end(); ++iter)
219 if (_name == (*iter)->getName())
222 MYGUI_ASSERT(!_throw,
"Layer '" << _name <<
"' not found");
233 for (VectorLayer::const_iterator iter = mLayerNodes.begin(); iter != mLayerNodes.end(); ++iter)
234 (*iter)->resizeView(_viewSize);
239 return mLayerNodes.size();
245 return mLayerNodes[_index];
250 return mCategoryName;