| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2019 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2018 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include "config.h" |
| 10 | #endif |
| 11 | |
| 12 | #include "app/app.h" |
| 13 | #include "app/commands/command.h" |
| 14 | #include "app/context_access.h" |
| 15 | #include "app/doc_api.h" |
| 16 | #include "app/i18n/strings.h" |
| 17 | #include "app/modules/gui.h" |
| 18 | #include "app/tx.h" |
| 19 | #include "app/ui/status_bar.h" |
| 20 | #include "doc/cel.h" |
| 21 | #include "doc/layer.h" |
| 22 | #include "doc/sprite.h" |
| 23 | |
| 24 | namespace app { |
| 25 | |
| 26 | class ClearCelCommand : public Command { |
| 27 | public: |
| 28 | ClearCelCommand(); |
| 29 | |
| 30 | protected: |
| 31 | bool onEnabled(Context* context) override; |
| 32 | void onExecute(Context* context) override; |
| 33 | }; |
| 34 | |
| 35 | ClearCelCommand::ClearCelCommand() |
| 36 | : Command(CommandId::ClearCel(), CmdRecordableFlag) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | bool ClearCelCommand::onEnabled(Context* context) |
| 41 | { |
| 42 | return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); |
| 43 | } |
| 44 | |
| 45 | void ClearCelCommand::onExecute(Context* context) |
| 46 | { |
| 47 | ContextWriter writer(context); |
| 48 | Doc* document(writer.document()); |
| 49 | bool nonEditableLayers = false; |
| 50 | { |
| 51 | Tx tx(writer.context(), "Clear Cel"); |
| 52 | |
| 53 | const Site* site = writer.site(); |
| 54 | if (site->inTimeline() && |
| 55 | !site->selectedLayers().empty() && |
| 56 | !site->selectedFrames().empty()) { |
| 57 | for (Layer* layer : site->selectedLayers()) { |
| 58 | if (!layer->isImage()) |
| 59 | continue; |
| 60 | |
| 61 | if (!layer->isEditableHierarchy()) { |
| 62 | nonEditableLayers = true; |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | for (frame_t frame : site->selectedFrames().reversed()) { |
| 67 | if (Cel* cel = layer->cel(frame)) |
| 68 | document->getApi(tx).clearCel(cel); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | else if (writer.cel()) { |
| 73 | if (writer.layer()->isEditableHierarchy()) |
| 74 | document->getApi(tx).clearCel(writer.cel()); |
| 75 | else |
| 76 | nonEditableLayers = true; |
| 77 | } |
| 78 | |
| 79 | tx.commit(); |
| 80 | } |
| 81 | |
| 82 | if (nonEditableLayers) |
| 83 | StatusBar::instance()->showTip(1000, |
| 84 | Strings::statusbar_tips_locked_layers()); |
| 85 | |
| 86 | update_screen_for_document(document); |
| 87 | } |
| 88 | |
| 89 | Command* CommandFactory::createClearCelCommand() |
| 90 | { |
| 91 | return new ClearCelCommand; |
| 92 | } |
| 93 | |
| 94 | } // namespace app |
| 95 |