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_sprite_size.h" |
12 | |
13 | #include "app/doc.h" |
14 | #include "app/doc_event.h" |
15 | #include "doc/sprite.h" |
16 | |
17 | namespace app { |
18 | namespace cmd { |
19 | |
20 | SetSpriteSize::SetSpriteSize(Sprite* sprite, int newWidth, int newHeight) |
21 | : WithSprite(sprite) |
22 | , m_oldWidth(sprite->width()) |
23 | , m_oldHeight(sprite->height()) |
24 | , m_newWidth(newWidth) |
25 | , m_newHeight(newHeight) |
26 | { |
27 | ASSERT(m_newWidth > 0); |
28 | ASSERT(m_newHeight > 0); |
29 | } |
30 | |
31 | void SetSpriteSize::onExecute() |
32 | { |
33 | Sprite* spr = sprite(); |
34 | spr->setSize(m_newWidth, m_newHeight); |
35 | spr->incrementVersion(); |
36 | } |
37 | |
38 | void SetSpriteSize::onUndo() |
39 | { |
40 | Sprite* spr = sprite(); |
41 | spr->setSize(m_oldWidth, m_oldHeight); |
42 | spr->incrementVersion(); |
43 | } |
44 | |
45 | void SetSpriteSize::onFireNotifications() |
46 | { |
47 | Sprite* sprite = this->sprite(); |
48 | Doc* doc = static_cast<Doc*>(sprite->document()); |
49 | DocEvent ev(doc); |
50 | ev.sprite(sprite); |
51 | doc->notify_observers<DocEvent&>(&DocObserver::onSpriteSizeChanged, ev); |
52 | } |
53 | |
54 | } // namespace cmd |
55 | } // namespace app |
56 |