| 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_frame_duration.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 | SetFrameDuration::SetFrameDuration(Sprite* sprite, frame_t frame, int duration) |
| 21 | : WithSprite(sprite) |
| 22 | , m_frame(frame) |
| 23 | , m_oldDuration(sprite->frameDuration(frame)) |
| 24 | , m_newDuration(duration) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | void SetFrameDuration::onExecute() |
| 29 | { |
| 30 | sprite()->setFrameDuration(m_frame, m_newDuration); |
| 31 | sprite()->incrementVersion(); |
| 32 | } |
| 33 | |
| 34 | void SetFrameDuration::onUndo() |
| 35 | { |
| 36 | sprite()->setFrameDuration(m_frame, m_oldDuration); |
| 37 | sprite()->incrementVersion(); |
| 38 | } |
| 39 | |
| 40 | void SetFrameDuration::onFireNotifications() |
| 41 | { |
| 42 | Sprite* sprite = this->sprite(); |
| 43 | Doc* doc = static_cast<Doc*>(sprite->document()); |
| 44 | DocEvent ev(doc); |
| 45 | ev.sprite(sprite); |
| 46 | ev.frame(m_frame); |
| 47 | doc->notify_observers<DocEvent&>(&DocObserver::onFrameDurationChanged, ev); |
| 48 | } |
| 49 | |
| 50 | } // namespace cmd |
| 51 | } // namespace app |
| 52 |