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_opacity.h" |
12 | |
13 | #include "app/doc.h" |
14 | #include "app/doc_event.h" |
15 | #include "doc/layer.h" |
16 | #include "doc/sprite.h" |
17 | |
18 | namespace app { |
19 | namespace cmd { |
20 | |
21 | SetLayerOpacity::SetLayerOpacity(LayerImage* layer, int opacity) |
22 | : WithLayer(layer) |
23 | , m_oldOpacity(layer->opacity()) |
24 | , m_newOpacity(opacity) |
25 | { |
26 | } |
27 | |
28 | void SetLayerOpacity::onExecute() |
29 | { |
30 | static_cast<LayerImage*>(layer())->setOpacity(m_newOpacity); |
31 | layer()->incrementVersion(); |
32 | } |
33 | |
34 | void SetLayerOpacity::onUndo() |
35 | { |
36 | static_cast<LayerImage*>(layer())->setOpacity(m_oldOpacity); |
37 | layer()->incrementVersion(); |
38 | } |
39 | |
40 | void SetLayerOpacity::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::onLayerOpacityChange, ev); |
48 | } |
49 | |
50 | } // namespace cmd |
51 | } // namespace app |
52 |