Use a std::unique_ptr for m_boundsF in doc::CelData

This commit is contained in:
David Capello 2022-07-11 10:21:38 -03:00
parent d46724329f
commit 62c052dd40
2 changed files with 14 additions and 8 deletions

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -33,14 +34,13 @@ CelData::CelData(const CelData& celData)
, m_image(celData.m_image)
, m_opacity(celData.m_opacity)
, m_bounds(celData.m_bounds)
, m_boundsF(celData.m_boundsF ? new gfx::RectF(*celData.m_boundsF):
, m_boundsF(celData.m_boundsF ? std::make_unique<gfx::RectF>(*celData.m_boundsF):
nullptr)
{
}
CelData::~CelData()
{
delete m_boundsF;
}
void CelData::setImage(const ImageRef& image)

View File

@ -1,6 +1,6 @@
// Aseprite Document Library
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -31,8 +31,14 @@ namespace doc {
ImageRef imageRef() const { return m_image; }
void setImage(const ImageRef& image);
void setPosition(const gfx::Point& pos) { m_bounds.setOrigin(pos); }
void setOpacity(int opacity) { m_opacity = opacity; }
void setPosition(const gfx::Point& pos) {
m_bounds.setOrigin(pos);
}
void setOpacity(int opacity) {
m_opacity = opacity;
}
void setBounds(const gfx::Rect& bounds) {
m_bounds = bounds;
@ -44,14 +50,14 @@ namespace doc {
if (m_boundsF)
*m_boundsF = boundsF;
else
m_boundsF = new gfx::RectF(boundsF);
m_boundsF = std::make_unique<gfx::RectF>(boundsF);
m_bounds = gfx::Rect(boundsF);
}
const gfx::RectF& boundsF() const {
if (!m_boundsF)
m_boundsF = new gfx::RectF(m_bounds);
m_boundsF = std::make_unique<gfx::RectF>(m_bounds);
return *m_boundsF;
}
@ -71,7 +77,7 @@ namespace doc {
// Special bounds for reference layers that can have subpixel
// position.
mutable gfx::RectF* m_boundsF;
mutable std::unique_ptr<gfx::RectF> m_boundsF;
};
typedef std::shared_ptr<CelData> CelDataRef;