1// Aseprite
2// Copyright (C) 2019-2020 Igara Studio S.A.
3// Copyright (C) 2001-2015 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "app/cmd/set_tag_range.h"
13
14#include "app/doc.h"
15#include "app/doc_event.h"
16#include "doc/sprite.h"
17#include "doc/tag.h"
18#include "doc/tags.h"
19
20namespace app {
21namespace cmd {
22
23SetTagRange::SetTagRange(Tag* tag, frame_t from, frame_t to)
24 : WithTag(tag)
25 , m_oldFrom(tag->fromFrame())
26 , m_oldTo(tag->toFrame())
27 , m_newFrom(from)
28 , m_newTo(to)
29{
30}
31
32void SetTagRange::onExecute()
33{
34 tag()->setFrameRange(m_newFrom, m_newTo);
35 tag()->incrementVersion();
36}
37
38void SetTagRange::onUndo()
39{
40 tag()->setFrameRange(m_oldFrom, m_oldTo);
41 tag()->incrementVersion();
42}
43
44void SetTagRange::onFireNotifications()
45{
46 Tag* tag = this->tag();
47 Sprite* sprite = tag->owner()->sprite();
48 Doc* doc = static_cast<Doc*>(sprite->document());
49 DocEvent ev(doc);
50 ev.sprite(sprite);
51 ev.tag(tag);
52 doc->notify_observers<DocEvent&>(&DocObserver::onTagChange, ev);
53}
54
55} // namespace cmd
56} // namespace app
57