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