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_layer_blend_mode.h"
12
13#include "app/doc.h"
14#include "app/doc_event.h"
15#include "doc/layer.h"
16#include "doc/sprite.h"
17
18namespace app {
19namespace cmd {
20
21SetLayerBlendMode::SetLayerBlendMode(LayerImage* layer, BlendMode blendMode)
22 : WithLayer(layer)
23 , m_oldBlendMode(layer->blendMode())
24 , m_newBlendMode(blendMode)
25{
26}
27
28void SetLayerBlendMode::onExecute()
29{
30 static_cast<LayerImage*>(layer())->setBlendMode(m_newBlendMode);
31 layer()->incrementVersion();
32}
33
34void SetLayerBlendMode::onUndo()
35{
36 static_cast<LayerImage*>(layer())->setBlendMode(m_oldBlendMode);
37 layer()->incrementVersion();
38}
39
40void SetLayerBlendMode::onFireNotifications()
41{
42 Layer* layer = this->layer();
43 Doc* doc = static_cast<Doc*>(layer->sprite()->document());
44 DocEvent ev(doc);
45 ev.sprite(layer->sprite());
46 ev.layer(layer);
47 doc->notify_observers<DocEvent&>(&DocObserver::onLayerBlendModeChange, ev);
48}
49
50} // namespace cmd
51} // namespace app
52