1 | // Aseprite |
---|---|
2 | // Copyright (C) 2016-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_pixel_ratio.h" |
12 | |
13 | #include "app/doc.h" |
14 | #include "app/doc_event.h" |
15 | #include "app/doc_observer.h" |
16 | #include "doc/sprite.h" |
17 | |
18 | namespace app { |
19 | namespace cmd { |
20 | |
21 | using namespace doc; |
22 | |
23 | SetPixelRatio::SetPixelRatio(Sprite* sprite, PixelRatio pixelRatio) |
24 | : WithSprite(sprite) |
25 | , m_oldRatio(sprite->pixelRatio()) |
26 | , m_newRatio(pixelRatio) |
27 | { |
28 | } |
29 | |
30 | void SetPixelRatio::onExecute() |
31 | { |
32 | Sprite* spr = sprite(); |
33 | spr->setPixelRatio(m_newRatio); |
34 | spr->incrementVersion(); |
35 | } |
36 | |
37 | void SetPixelRatio::onUndo() |
38 | { |
39 | Sprite* spr = sprite(); |
40 | spr->setPixelRatio(m_oldRatio); |
41 | spr->incrementVersion(); |
42 | } |
43 | |
44 | void SetPixelRatio::onFireNotifications() |
45 | { |
46 | Sprite* sprite = this->sprite(); |
47 | Doc* doc = static_cast<Doc*>(sprite->document()); |
48 | DocEvent ev(doc); |
49 | ev.sprite(sprite); |
50 | doc->notify_observers<DocEvent&>(&DocObserver::onSpritePixelRatioChanged, ev); |
51 | } |
52 | |
53 | } // namespace cmd |
54 | } // namespace app |
55 |