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_opacity.h"
12
13#include "app/doc.h"
14#include "app/doc_event.h"
15#include "doc/cel.h"
16
17namespace app {
18namespace cmd {
19
20using namespace doc;
21
22SetCelOpacity::SetCelOpacity(Cel* cel, int opacity)
23 : WithCel(cel)
24 , m_oldOpacity(cel->opacity())
25 , m_newOpacity(opacity)
26{
27}
28
29void SetCelOpacity::onExecute()
30{
31 cel()->setOpacity(m_newOpacity);
32 cel()->data()->incrementVersion();
33}
34
35void SetCelOpacity::onUndo()
36{
37 cel()->setOpacity(m_oldOpacity);
38 cel()->data()->incrementVersion();
39}
40
41void SetCelOpacity::onFireNotifications()
42{
43 Cel* cel = this->cel();
44 Doc* doc = static_cast<Doc*>(cel->document());
45 DocEvent ev(doc);
46 ev.sprite(cel->sprite());
47 ev.cel(cel);
48 doc->notify_observers<DocEvent&>(&DocObserver::onCelOpacityChange, ev);
49}
50
51} // namespace cmd
52} // namespace app
53