1 | // Aseprite |
---|---|
2 | // Copyright (C) 2016 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/restore_visible_layers.h" |
12 | |
13 | #include "doc/layer.h" |
14 | #include "doc/selected_layers.h" |
15 | #include "doc/sprite.h" |
16 | |
17 | namespace app { |
18 | |
19 | using namespace doc; |
20 | |
21 | RestoreVisibleLayers::~RestoreVisibleLayers() |
22 | { |
23 | for (auto item : m_restore) |
24 | item.first->setVisible(item.second); |
25 | } |
26 | |
27 | void RestoreVisibleLayers::showLayer(Layer* layer) |
28 | { |
29 | SelectedLayers selLayers; |
30 | selLayers.insert(layer); |
31 | selLayers.propagateSelection(); |
32 | showSelectedLayers(layer->sprite(), selLayers); |
33 | } |
34 | |
35 | void RestoreVisibleLayers::showSelectedLayers(Sprite* sprite, const SelectedLayers& inSelLayers) |
36 | { |
37 | SelectedLayers selLayers = inSelLayers; |
38 | selLayers.propagateSelection(); |
39 | setLayerVisiblity(sprite->root(), selLayers); |
40 | } |
41 | |
42 | void RestoreVisibleLayers::setLayerVisiblity(LayerGroup* group, const SelectedLayers& selLayers) |
43 | { |
44 | for (Layer* layer : group->layers()) { |
45 | bool selected = (selLayers.contains(layer)); |
46 | if (selected != layer->isVisible()) { |
47 | m_restore.push_back(std::make_pair(layer, layer->isVisible())); |
48 | layer->setVisible(selected); |
49 | } |
50 | if (selected && layer->isGroup()) |
51 | setLayerVisiblity(static_cast<LayerGroup*>(layer), selLayers); |
52 | } |
53 | } |
54 | |
55 | } // namespace app |
56 |