1 | // Aseprite |
---|---|
2 | // Copyright (C) 2001-2018 David Capello |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "app/cmd/set_cel_position.h" |
12 | |
13 | #include "app/doc.h" |
14 | #include "app/doc_event.h" |
15 | #include "doc/cel.h" |
16 | |
17 | namespace app { |
18 | namespace cmd { |
19 | |
20 | using namespace doc; |
21 | |
22 | SetCelPosition::SetCelPosition(Cel* cel, int x, int y) |
23 | : WithCel(cel) |
24 | , m_oldX(cel->x()) |
25 | , m_oldY(cel->y()) |
26 | , m_newX(x) |
27 | , m_newY(y) |
28 | { |
29 | } |
30 | |
31 | void SetCelPosition::onExecute() |
32 | { |
33 | cel()->data()->setPosition(gfx::Point(m_newX, m_newY)); |
34 | cel()->data()->incrementVersion(); |
35 | } |
36 | |
37 | void SetCelPosition::onUndo() |
38 | { |
39 | cel()->data()->setPosition(gfx::Point(m_oldX, m_oldY)); |
40 | cel()->data()->incrementVersion(); |
41 | } |
42 | |
43 | void SetCelPosition::onFireNotifications() |
44 | { |
45 | Cel* cel = this->cel(); |
46 | Doc* doc = static_cast<Doc*>(cel->document()); |
47 | DocEvent ev(doc); |
48 | ev.sprite(cel->sprite()); |
49 | ev.cel(cel); |
50 | doc->notify_observers<DocEvent&>(&DocObserver::onCelPositionChanged, ev); |
51 | } |
52 | |
53 | } // namespace cmd |
54 | } // namespace app |
55 |