1 | // Aseprite |
---|---|
2 | // Copyright (C) 2020 Igara Studio S.A. |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #include "app/util/layer_utils.h" |
8 | |
9 | #include "app/i18n/strings.h" |
10 | #include "app/ui/editor/editor.h" |
11 | #include "app/ui/status_bar.h" |
12 | #include "doc/layer.h" |
13 | #include "doc/sprite.h" |
14 | #include "fmt/format.h" |
15 | |
16 | namespace app { |
17 | |
18 | using namespace doc; |
19 | |
20 | Layer* candidate_if_layer_is_deleted( |
21 | const Layer* selectedLayer, |
22 | const Layer* layerToDelete) |
23 | { |
24 | const Layer* layerToSelect = selectedLayer; |
25 | |
26 | if ((selectedLayer == layerToDelete) || |
27 | (selectedLayer && |
28 | selectedLayer->hasAncestor(layerToDelete))) { |
29 | Sprite* sprite = selectedLayer->sprite(); |
30 | LayerGroup* parent = layerToDelete->parent(); |
31 | |
32 | // Select previous layer, or next layer, or the parent (if it is |
33 | // not the main layer of sprite set). |
34 | if (layerToDelete->getPrevious()) |
35 | layerToSelect = layerToDelete->getPrevious(); |
36 | else if (layerToDelete->getNext()) |
37 | layerToSelect = layerToDelete->getNext(); |
38 | else if (parent != sprite->root()) |
39 | layerToSelect = parent; |
40 | } |
41 | |
42 | return const_cast<Layer*>(layerToSelect); |
43 | } |
44 | |
45 | bool layer_is_locked(Editor* editor) |
46 | { |
47 | Layer* layer = editor->layer(); |
48 | if (layer && !layer->isEditableHierarchy()) { |
49 | #ifdef ENABLE_UI |
50 | if (auto statusBar = StatusBar::instance()) |
51 | statusBar->showTip( |
52 | 1000, fmt::format(Strings::statusbar_tips_layer_locked(), layer->name())); |
53 | #endif |
54 | return true; |
55 | } |
56 | return false; |
57 | } |
58 | |
59 | } // namespace app |
60 |