1 | // Aseprite |
---|---|
2 | // Copyright (C) 2020 Igara Studio S.A. |
3 | // Copyright (C) 2001-2017 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/commands/move_thing.h" |
15 | #include "app/commands/params.h" |
16 | #include "app/context_access.h" |
17 | #include "app/i18n/strings.h" |
18 | #include "app/modules/editors.h" |
19 | #include "app/ui/editor/editor.h" |
20 | #include "base/convert_to.h" |
21 | #include "fmt/format.h" |
22 | #include "ui/view.h" |
23 | |
24 | namespace app { |
25 | |
26 | class ScrollCommand : public Command { |
27 | public: |
28 | ScrollCommand(); |
29 | |
30 | protected: |
31 | bool onNeedsParams() const override { return true; } |
32 | void onLoadParams(const Params& params) override; |
33 | bool onEnabled(Context* context) override; |
34 | void onExecute(Context* context) override; |
35 | std::string onGetFriendlyName() const override; |
36 | |
37 | private: |
38 | MoveThing m_moveThing; |
39 | }; |
40 | |
41 | ScrollCommand::ScrollCommand() |
42 | : Command(CommandId::Scroll(), CmdUIOnlyFlag) |
43 | { |
44 | } |
45 | |
46 | void ScrollCommand::onLoadParams(const Params& params) |
47 | { |
48 | m_moveThing.onLoadParams(params); |
49 | } |
50 | |
51 | bool ScrollCommand::onEnabled(Context* context) |
52 | { |
53 | return context->checkFlags(ContextFlags::HasActiveDocument); |
54 | } |
55 | |
56 | void ScrollCommand::onExecute(Context* context) |
57 | { |
58 | ui::View* view = ui::View::getView(current_editor); |
59 | gfx::Point scroll = view->viewScroll(); |
60 | gfx::Point delta = m_moveThing.getDelta(context); |
61 | |
62 | current_editor->setEditorScroll(scroll+delta); |
63 | } |
64 | |
65 | std::string ScrollCommand::onGetFriendlyName() const |
66 | { |
67 | return fmt::format(getBaseFriendlyName(), |
68 | m_moveThing.getFriendlyString()); |
69 | } |
70 | |
71 | Command* CommandFactory::createScrollCommand() |
72 | { |
73 | return new ScrollCommand; |
74 | } |
75 | |
76 | } // namespace app |
77 |