MyGUI  3.0.1
MyGUI_ResourceImageSetPointer.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 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_ResourceImageSetPointer.h"
00025 #include "MyGUI_StaticImage.h"
00026 #include "MyGUI_ResourceManager.h"
00027 
00028 namespace MyGUI
00029 {
00030 
00031     ResourceImageSetPointer::ResourceImageSetPointer() :
00032         mImageSet(nullptr)
00033     {
00034     }
00035 
00036     void ResourceImageSetPointer::deserialization(xml::ElementPtr _node, Version _version)
00037     {
00038         Base::deserialization(_node, _version);
00039 
00040         // берем детей и крутимся, основной цикл
00041         xml::ElementEnumerator info = _node->getElementEnumerator();
00042         while (info.next("Property"))
00043         {
00044             const std::string& key = info->findAttribute("key");
00045             const std::string& value = info->findAttribute("value");
00046 
00047             if (key == "Point") mPoint = IntPoint::parse(value);
00048             else if (key == "Size") mSize = IntSize::parse(value);
00049             else if (key == "Resource") mImageSet = ResourceManager::getInstance().getByName(value)->castType<ResourceImageSet>();
00050         }
00051     }
00052 
00053     void ResourceImageSetPointer::setImage(StaticImage* _image)
00054     {
00055         if (mImageSet != nullptr)
00056             _image->setItemResourceInfo(mImageSet->getIndexInfo(0, 0));
00057     }
00058 
00059     void ResourceImageSetPointer::setPosition(StaticImage* _image, const IntPoint& _point)
00060     {
00061         _image->setCoord(_point.left - mPoint.left, _point.top - mPoint.top, mSize.width, mSize.height);
00062     }
00063 
00064 } // namespace MyGUI