MyGUI  3.2.1
MyGUI_ResourceImageSetPointer.cpp
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #include "MyGUI_Precompiled.h"
00008 #include "MyGUI_ResourceImageSetPointer.h"
00009 #include "MyGUI_ImageBox.h"
00010 #include "MyGUI_ResourceManager.h"
00011 
00012 namespace MyGUI
00013 {
00014 
00015     ResourceImageSetPointer::ResourceImageSetPointer() :
00016         mImageSet(nullptr)
00017     {
00018     }
00019 
00020     ResourceImageSetPointer::~ResourceImageSetPointer()
00021     {
00022     }
00023 
00024     void ResourceImageSetPointer::deserialization(xml::ElementPtr _node, Version _version)
00025     {
00026         Base::deserialization(_node, _version);
00027 
00028         // берем детей и крутимся, основной цикл
00029         xml::ElementEnumerator info = _node->getElementEnumerator();
00030         while (info.next("Property"))
00031         {
00032             const std::string& key = info->findAttribute("key");
00033             const std::string& value = info->findAttribute("value");
00034 
00035             if (key == "Point")
00036                 mPoint = IntPoint::parse(value);
00037             else if (key == "Size")
00038                 mSize = IntSize::parse(value);
00039             else if (key == "Resource")
00040                 mImageSet = ResourceManager::getInstance().getByName(value)->castType<ResourceImageSet>();
00041         }
00042     }
00043 
00044     void ResourceImageSetPointer::setImage(ImageBox* _image)
00045     {
00046         if (mImageSet != nullptr)
00047             _image->setItemResourceInfo(mImageSet->getIndexInfo(0, 0));
00048     }
00049 
00050     void ResourceImageSetPointer::setPosition(ImageBox* _image, const IntPoint& _point)
00051     {
00052         _image->setCoord(_point.left - mPoint.left, _point.top - mPoint.top, mSize.width, mSize.height);
00053     }
00054 
00055 } // namespace MyGUI