forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcel_data.cpp
84 lines (72 loc) · 1.86 KB
/
cel_data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Aseprite Document Library
// Copyright (c) 2019-2022 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/cel_data.h"
#include "doc/image.h"
#include "doc/layer.h"
#include "doc/layer_tilemap.h"
#include "doc/sprite.h"
#include "doc/tileset.h"
#include "gfx/rect.h"
namespace doc {
CelData::CelData(const ImageRef& image)
: WithUserData(ObjectType::CelData)
, m_image(image)
, m_opacity(255)
, m_bounds(0, 0,
image ? image->width(): 0,
image ? image->height(): 0)
, m_boundsF(nullptr)
{
}
CelData::CelData(const CelData& celData)
: WithUserData(ObjectType::CelData)
, m_image(celData.m_image)
, m_opacity(celData.m_opacity)
, m_bounds(celData.m_bounds)
, m_boundsF(celData.m_boundsF ? std::make_unique<gfx::RectF>(*celData.m_boundsF):
nullptr)
{
}
CelData::~CelData()
{
}
void CelData::setImage(const ImageRef& image, Layer* layer)
{
ASSERT(image.get());
m_image = image;
adjustBounds(layer);
}
void CelData::setPosition(const gfx::Point& pos)
{
m_bounds.setOrigin(pos);
if (m_boundsF)
m_boundsF->setOrigin(gfx::PointF(pos));
}
void CelData::adjustBounds(Layer* layer)
{
ASSERT(m_image);
if (m_image->pixelFormat() == IMAGE_TILEMAP) {
Tileset* tileset = nullptr;
if (layer && layer->isTilemap())
tileset = static_cast<LayerTilemap*>(layer)->tileset();
if (tileset) {
gfx::Size canvasSize =
tileset->grid().tilemapSizeToCanvas(
gfx::Size(m_image->width(),
m_image->height()));
m_bounds.w = canvasSize.w;
m_bounds.h = canvasSize.h;
return;
}
}
m_bounds.w = m_image->width();
m_bounds.h = m_image->height();
}
} // namespace doc