| 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/cmd/set_mask.h" |
| 13 | #include "app/commands/command.h" |
| 14 | #include "app/context_access.h" |
| 15 | #include "app/modules/gui.h" |
| 16 | #include "app/tx.h" |
| 17 | #include "doc/mask.h" |
| 18 | #include "doc/sprite.h" |
| 19 | #include "app/pref/preferences.h" |
| 20 | |
| 21 | namespace app { |
| 22 | |
| 23 | class MaskAllCommand : public Command { |
| 24 | public: |
| 25 | MaskAllCommand(); |
| 26 | |
| 27 | protected: |
| 28 | bool onEnabled(Context* context) override; |
| 29 | void onExecute(Context* context) override; |
| 30 | }; |
| 31 | |
| 32 | MaskAllCommand::MaskAllCommand() |
| 33 | : Command(CommandId::MaskAll(), CmdRecordableFlag) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | bool MaskAllCommand::onEnabled(Context* context) |
| 38 | { |
| 39 | return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | |
| 40 | ContextFlags::HasActiveSprite); |
| 41 | } |
| 42 | |
| 43 | void MaskAllCommand::onExecute(Context* context) |
| 44 | { |
| 45 | ContextWriter writer(context); |
| 46 | Doc* document(writer.document()); |
| 47 | Sprite* sprite(writer.sprite()); |
| 48 | |
| 49 | Mask newMask; |
| 50 | newMask.replace(sprite->bounds()); |
| 51 | |
| 52 | Tx tx(writer.context(), "Select All", DoesntModifyDocument); |
| 53 | tx(new cmd::SetMask(document, &newMask)); |
| 54 | document->resetTransformation(); |
| 55 | tx.commit(); |
| 56 | |
| 57 | if (Preferences::instance().selection.autoShowSelectionEdges()) { |
| 58 | DocumentPreferences& docPref = Preferences::instance().document(document); |
| 59 | docPref.show.selectionEdges(true); |
| 60 | } |
| 61 | |
| 62 | update_screen_for_document(document); |
| 63 | } |
| 64 | |
| 65 | Command* CommandFactory::createMaskAllCommand() |
| 66 | { |
| 67 | return new MaskAllCommand; |
| 68 | } |
| 69 | |
| 70 | } // namespace app |
| 71 |