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_total_frames.h"
12
13#include "app/doc.h"
14#include "app/doc_event.h"
15#include "doc/sprite.h"
16
17namespace app {
18namespace cmd {
19
20SetTotalFrames::SetTotalFrames(Sprite* sprite, frame_t frames)
21 : WithSprite(sprite)
22 , m_oldFrames(sprite->totalFrames())
23 , m_newFrames(frames)
24{
25}
26
27void SetTotalFrames::onExecute()
28{
29 Sprite* spr = sprite();
30 spr->setTotalFrames(m_newFrames);
31 spr->incrementVersion();
32}
33
34void SetTotalFrames::onUndo()
35{
36 Sprite* spr = sprite();
37 spr->setTotalFrames(m_oldFrames);
38 spr->incrementVersion();
39}
40
41void SetTotalFrames::onFireNotifications()
42{
43 Sprite* sprite = this->sprite();
44 Doc* doc = static_cast<Doc*>(sprite->document());
45 DocEvent ev(doc);
46 ev.sprite(sprite);
47 ev.frame(sprite->totalFrames());
48 doc->notify_observers<DocEvent&>(&DocObserver::onTotalFramesChanged, ev);
49}
50
51} // namespace cmd
52} // namespace app
53