axmol/extensions/DragonBones/CCTextureAtlasData.cpp

76 lines
2.0 KiB
C++
Raw Normal View History

2021-12-24 21:11:44 +08:00
#include "CCTextureAtlasData.h"
DRAGONBONES_NAMESPACE_BEGIN
void CCTextureAtlasData::_onClear()
{
TextureAtlasData::_onClear();
if (_renderTexture != nullptr)
{
_renderTexture->release();
_renderTexture = nullptr;
}
}
TextureData* CCTextureAtlasData::createTexture() const
{
return BaseObject::borrowObject<CCTextureData>();
}
2022-08-08 18:02:17 +08:00
void CCTextureAtlasData::setRenderTexture(ax::Texture2D* value)
{
2021-12-25 10:04:45 +08:00
if (_renderTexture == value)
{
return;
}
_renderTexture = value;
2021-12-25 10:04:45 +08:00
if (_renderTexture != nullptr)
{
_renderTexture->retain();
2021-12-25 10:04:45 +08:00
for (const auto& pair : textures)
{
const auto textureData = static_cast<CCTextureData*>(pair.second);
if (textureData->spriteFrame == nullptr)
{
2022-08-08 18:02:17 +08:00
ax::Rect rect(textureData->region.x, textureData->region.y,
2021-12-25 10:04:45 +08:00
textureData->rotated ? textureData->region.height : textureData->region.width,
textureData->rotated ? textureData->region.width : textureData->region.height);
2022-08-08 18:02:17 +08:00
ax::Vec2 offset(0.0f, 0.0f);
ax::Size originSize(rect.size.width, rect.size.height);
textureData->spriteFrame = ax::SpriteFrame::createWithTexture(
2021-12-25 10:04:45 +08:00
_renderTexture, rect, textureData->rotated, offset, originSize); // TODO multiply textureAtlas
textureData->spriteFrame->retain();
}
}
}
2021-12-25 10:04:45 +08:00
else
{
for (const auto& pair : textures)
{
const auto textureData = static_cast<CCTextureData*>(pair.second);
if (textureData->spriteFrame != nullptr)
{
textureData->spriteFrame->release();
textureData->spriteFrame = nullptr;
}
}
}
}
void CCTextureData::_onClear()
{
TextureData::_onClear();
if (spriteFrame != nullptr)
{
spriteFrame->release();
spriteFrame = nullptr;
}
}
DRAGONBONES_NAMESPACE_END