MyGUI_ResourceImageSet.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_ResourceImageSet.h"
#include "MyGUI_ResourceManager.h"
#include "MyGUI_LanguageManager.h"
#include "MyGUI_Constants.h"
namespace MyGUI
{
void ResourceImageSet::deserialization(xml::ElementPtr _node, Version _version)
{
Base::deserialization(_node, _version);
// берем детей и крутимся, основной цикл
xml::ElementEnumerator group_node = _node->getElementEnumerator();
while (group_node.next("Group"))
{
GroupImage group;
group.name = group_node->findAttribute("name");
group.texture = group_node->findAttribute("texture");
// tags replacement support for Skins
if (_version >= Version(1, 1))
{
group.texture = LanguageManager::getInstance().replaceTags(group.texture);
}
group.size = IntSize::parse(group_node->findAttribute("size"));
xml::ElementEnumerator index_node = group_node->getElementEnumerator();
while (index_node.next("Index"))
{
IndexImage index;
index.name = index_node->findAttribute("name");
index.rate = utility::parseFloat(index_node->findAttribute("rate"));
xml::ElementEnumerator frame_node = index_node->getElementEnumerator();
while (frame_node.next("Frame"))
{
size_t count = utility::parseSizeT(frame_node->findAttribute("count"));
const IntPoint& point = IntPoint::parse(frame_node->findAttribute("point"));
if ((count < 1) || (count > 256))
count = 1;
while (count > 0)
{
index.frames.push_back(point);
--count;
}
}
group.indexes.push_back(index);
}
AddGroupImage(group);
}
}
ImageIndexInfo ResourceImageSet::getIndexInfo(std::string_view _group, std::string_view _index) const
{
size_t index_group = getGroupIndex(_group);
if (index_group != ITEM_NONE)
{
const GroupImage& group = mGroups[index_group];
size_t index_image = getImageIndex(group, _index);
if (index_image != ITEM_NONE)
{
const IndexImage& index = group.indexes[index_image];
return {group.texture, group.size, index.rate, index.frames};
}
}
return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
}
ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, std::string_view _index) const
{
if (_group < mGroups.size())
{
const GroupImage& group = mGroups[_group];
size_t index_image = getImageIndex(group, _index);
if (index_image != ITEM_NONE)
{
const IndexImage& index = group.indexes[index_image];
return {group.texture, group.size, index.rate, index.frames};
}
}
return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
}
ImageIndexInfo ResourceImageSet::getIndexInfo(std::string_view _group, size_t _index) const
{
size_t index_group = getGroupIndex(_group);
if (index_group != ITEM_NONE)
{
const GroupImage& group = mGroups[index_group];
if (_index < group.indexes.size())
{
const IndexImage& index = group.indexes[_index];
return {group.texture, group.size, index.rate, index.frames};
}
}
return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
}
ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, size_t _index) const
{
if (_group < mGroups.size())
{
const GroupImage& group = mGroups[_group];
if (_index < group.indexes.size())
{
const IndexImage& index = group.indexes[_index];
return {group.texture, group.size, index.rate, index.frames};
}
}
return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
}
ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, size_t _index) const
{
size_t index_group = getGroupIndex(_group);
if (index_group != ITEM_NONE)
{
const GroupImage& group = mGroups[index_group];
if (_index < group.indexes.size())
{
const IndexImage& index = group.indexes[_index];
return {group.texture, group.size, index.rate, index.frames};
}
}
return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
}
ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, std::string_view _index) const
{
size_t index_group = getGroupIndex(_group);
if (index_group != ITEM_NONE)
{
const GroupImage& group = mGroups[index_group];
size_t index_image = getImageIndex(group, _index);
if (index_image != ITEM_NONE)
{
const IndexImage& index = group.indexes[index_image];
return {group.texture, group.size, index.rate, index.frames};
}
}
return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
}
size_t ResourceImageSet::getGroupIndex(std::string_view _name) const
{
for (size_t index = 0; index < mGroups.size(); ++index)
{
if (mGroups[index].name == _name)
return index;
}
return ITEM_NONE;
}
size_t ResourceImageSet::getGroupIndex(const IntSize& _size) const
{
for (size_t index = 0; index < mGroups.size(); ++index)
{
if (mGroups[index].size == _size)
return index;
}
return ITEM_NONE;
}
size_t ResourceImageSet::getImageIndex(const GroupImage& _group, std::string_view _name) const
{
const VectorIndexImage& indices = _group.indexes;
for (size_t index = 0; index < indices.size(); ++index)
{
if (indices[index].name == _name)
return index;
}
return ITEM_NONE;
}
EnumeratorGroupImage ResourceImageSet::getEnumerator() const
{
return EnumeratorGroupImage(mGroups);
}
void ResourceImageSet::AddGroupImage(const GroupImage& _group)
{
mGroups.push_back(_group);
}
} // namespace MyGUI
MyGUI_Constants.h
MyGUI_LanguageManager.h
MyGUI_Precompiled.h
MyGUI_ResourceImageSet.h
MyGUI_ResourceManager.h
MyGUI::Constants::getZeroIntSize
static const IntSize & getZeroIntSize()
Definition MyGUI_Constants.h:28
MyGUI::LanguageManager::getInstance
static LanguageManager & getInstance()
Definition MyGUI_LanguageManager.cpp:18
MyGUI::LanguageManager::replaceTags
UString replaceTags(const UString &_line) const
Definition MyGUI_LanguageManager.cpp:199
MyGUI::ResourceImageSet::getIndexInfo
ImageIndexInfo getIndexInfo(std::string_view _group, std::string_view _index) const
Definition MyGUI_ResourceImageSet.cpp:64
MyGUI::ResourceImageSet::getEnumerator
EnumeratorGroupImage getEnumerator() const
Definition MyGUI_ResourceImageSet.cpp:186
MyGUI::ResourceImageSet::AddGroupImage
void AddGroupImage(const GroupImage &_group)
Definition MyGUI_ResourceImageSet.cpp:191
MyGUI::Version
Definition MyGUI_Version.h:18
MyGUI::utility::parseFloat
float parseFloat(std::string_view _value)
Definition MyGUI_StringUtility.h:117
MyGUI::utility::parseSizeT
size_t parseSizeT(std::string_view _value)
Definition MyGUI_StringUtility.h:112
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition MyGUI_XmlDocument.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::VectorIndexImage
std::vector< IndexImage > VectorIndexImage
Definition MyGUI_ResourceImageSetData.h:21
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::EnumeratorGroupImage
Enumerator< VectorGroupImage > EnumeratorGroupImage
Definition MyGUI_ResourceImageSetData.h:31
MyGUI::GroupImage
Definition MyGUI_ResourceImageSetData.h:24
MyGUI::GroupImage::indexes
VectorIndexImage indexes
Definition MyGUI_ResourceImageSetData.h:28
MyGUI::GroupImage::texture
std::string texture
Definition MyGUI_ResourceImageSetData.h:26
MyGUI::GroupImage::size
IntSize size
Definition MyGUI_ResourceImageSetData.h:27
MyGUI::ImageIndexInfo
Definition MyGUI_ImageInfo.h:25
MyGUI::IndexImage
Definition MyGUI_ResourceImageSetData.h:16
MyGUI::IndexImage::rate
float rate
Definition MyGUI_ResourceImageSetData.h:18
MyGUI::IndexImage::frames
std::vector< IntPoint > frames
Definition MyGUI_ResourceImageSetData.h:19
MyGUI::types::TPoint< int >::parse
static TPoint< int > parse(std::string_view _value)
Definition MyGUI_TPoint.h:102
MyGUI::types::TSize< int >::parse
static TSize< int > parse(std::string_view _value)
Definition MyGUI_TSize.h:102