1// Aseprite Document Library
2// Copyright (C) 2019-2020 Igara Studio S.A.
3// Copyright (C) 2001-2016 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "doc/tag.h"
13
14#include "base/debug.h"
15#include "doc/tags.h"
16
17namespace doc {
18
19Tag::Tag(frame_t from, frame_t to)
20 : WithUserData(ObjectType::Tag)
21 , m_owner(nullptr)
22 , m_from(from)
23 , m_to(to)
24 , m_name("Tag")
25 , m_aniDir(AniDir::FORWARD)
26{
27 color_t defaultColor = rgba_a_mask;// black color with full opacity.
28 userData().setColor(defaultColor);
29}
30
31Tag::Tag(const Tag& other)
32 : WithUserData(ObjectType::Tag)
33 , m_owner(nullptr)
34 , m_from(other.m_from)
35 , m_to(other.m_to)
36 , m_name(other.m_name)
37 , m_aniDir(other.m_aniDir)
38{
39}
40
41Tag::~Tag()
42{
43 ASSERT(!m_owner);
44}
45
46Sprite* Tag::sprite() const
47{
48 if (m_owner)
49 return m_owner->sprite();
50 else
51 return nullptr;
52}
53
54void Tag::setOwner(Tags* owner)
55{
56 m_owner = owner;
57}
58
59void Tag::setFrameRange(frame_t from, frame_t to)
60{
61 Tags* owner = m_owner;
62 if (owner)
63 owner->remove(this);
64
65 m_from = from;
66 m_to = to;
67
68 if (owner)
69 owner->add(this); // Re-add the tag, so it's added in the correct place
70}
71
72void Tag::setName(const std::string& name)
73{
74 m_name = name;
75}
76
77void Tag::setColor(color_t color)
78{
79 userData().setColor(color);
80}
81
82void Tag::setAniDir(AniDir aniDir)
83{
84 ASSERT(m_aniDir == AniDir::FORWARD ||
85 m_aniDir == AniDir::REVERSE ||
86 m_aniDir == AniDir::PING_PONG);
87
88 m_aniDir = aniDir;
89}
90
91} // namespace doc
92