1// Aseprite
2// Copyright (C) 2001-2017 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/commands/commands.h"
14#include "app/commands/params.h"
15#include "app/pref/preferences.h"
16#include "app/tools/tool.h"
17#include "app/tools/tool_box.h"
18
19namespace app {
20
21class SetSameInkCommand : public Command {
22public:
23 SetSameInkCommand();
24
25protected:
26 bool onChecked(Context* context) override;
27 void onExecute(Context* context) override;
28};
29
30SetSameInkCommand::SetSameInkCommand()
31 : Command(CommandId::SetSameInk(), CmdUIOnlyFlag)
32{
33}
34
35bool SetSameInkCommand::onChecked(Context* context)
36{
37 return Preferences::instance().shared.shareInk();
38}
39
40void SetSameInkCommand::onExecute(Context* context)
41{
42 Preferences& pref = Preferences::instance();
43 bool newState = !pref.shared.shareInk();
44 pref.shared.shareInk(newState);
45
46 if (newState) {
47 tools::Tool* activeTool = App::instance()->activeTool();
48 tools::InkType inkType = pref.tool(activeTool).ink();
49 int opacity = pref.tool(activeTool).opacity();
50
51 for (tools::Tool* tool : *App::instance()->toolBox()) {
52 if (tool != activeTool) {
53 pref.tool(tool).ink(inkType);
54 pref.tool(tool).opacity(opacity);
55 }
56 }
57 }
58}
59
60Command* CommandFactory::createSetSameInkCommand()
61{
62 return new SetSameInkCommand;
63}
64
65} // namespace app
66