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/app.h" |
12 | #include "app/commands/command.h" |
13 | #include "app/context_access.h" |
14 | #include "app/doc_range_ops.h" |
15 | #include "app/modules/gui.h" |
16 | #include "app/ui/timeline/timeline.h" |
17 | |
18 | namespace app { |
19 | |
20 | class ReverseFramesCommand : public Command { |
21 | public: |
22 | ReverseFramesCommand(); |
23 | |
24 | protected: |
25 | bool onEnabled(Context* context) override; |
26 | void onExecute(Context* context) override; |
27 | }; |
28 | |
29 | ReverseFramesCommand::ReverseFramesCommand() |
30 | : Command(CommandId::ReverseFrames(), CmdUIOnlyFlag) |
31 | { |
32 | } |
33 | |
34 | bool ReverseFramesCommand::onEnabled(Context* context) |
35 | { |
36 | auto range = App::instance()->timeline()->range(); |
37 | return |
38 | context->checkFlags(ContextFlags::ActiveDocumentIsWritable) && |
39 | range.enabled() && |
40 | range.frames() >= 2; // We need at least 2 frames to reverse |
41 | } |
42 | |
43 | void ReverseFramesCommand::onExecute(Context* context) |
44 | { |
45 | auto range = App::instance()->timeline()->range(); |
46 | if (!range.enabled()) |
47 | return; // Nothing to do |
48 | |
49 | Doc* doc = context->activeDocument(); |
50 | |
51 | reverse_frames(doc, range); |
52 | |
53 | update_screen_for_document(doc); |
54 | } |
55 | |
56 | Command* CommandFactory::createReverseFramesCommand() |
57 | { |
58 | return new ReverseFramesCommand; |
59 | } |
60 | |
61 | } // namespace app |
62 |