axmol/extensions/DragonBones/model/TextureAtlasData.cpp

104 lines
2.0 KiB
C++
Raw Normal View History

2021-12-24 21:11:44 +08:00
#include "TextureAtlasData.h"
DRAGONBONES_NAMESPACE_BEGIN
void TextureAtlasData::_onClear()
{
for (const auto& pair : textures)
{
pair.second->returnToPool();
}
autoSearch = false;
2021-12-25 10:04:45 +08:00
format = TextureFormat::DEFAULT;
width = 0;
height = 0;
scale = 1.0f;
name = "";
imagePath.clear();
textures.clear();
}
void TextureAtlasData::copyFrom(const TextureAtlasData& value)
{
autoSearch = value.autoSearch;
2021-12-25 10:04:45 +08:00
format = value.format;
width = value.width;
height = value.height;
scale = value.scale;
name = value.name;
imagePath = value.imagePath;
for (const auto& pair : textures)
{
pair.second->returnToPool();
}
textures.clear();
2021-12-25 10:04:45 +08:00
for (const auto& pair : value.textures)
{
const auto texture = createTexture();
texture->copyFrom(*(pair.second));
textures[pair.first] = texture;
}
}
void TextureAtlasData::addTexture(TextureData* value)
{
2021-12-25 10:04:45 +08:00
if (textures.find(value->name) != textures.cend())
{
DRAGONBONES_ASSERT(false, "Same texture: " + value->name);
return;
}
textures[value->name] = value;
2021-12-25 10:04:45 +08:00
value->parent = this;
}
Rectangle* TextureData::createRectangle()
{
return new Rectangle();
}
2021-12-25 10:04:45 +08:00
TextureData::~TextureData() {}
void TextureData::_onClear()
{
if (frame != nullptr)
{
delete frame;
}
rotated = false;
2021-12-25 10:04:45 +08:00
name = "";
region.clear();
parent = nullptr;
2021-12-25 10:04:45 +08:00
frame = nullptr;
}
2021-12-25 10:04:45 +08:00
void TextureData::copyFrom(const TextureData& value)
{
rotated = value.rotated;
2021-12-25 10:04:45 +08:00
name = value.name;
region = value.region; // Copy.
parent = value.parent;
if (frame == nullptr && value.frame != nullptr)
{
frame = TextureData::createRectangle();
}
else if (frame != nullptr && value.frame == nullptr)
{
delete frame;
frame = nullptr;
}
if (frame != nullptr && value.frame != nullptr)
{
2021-12-25 10:04:45 +08:00
*frame = *(value.frame); // Copy.
}
}
DRAGONBONES_NAMESPACE_END