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/params.h"
14#include "app/context.h"
15#include "app/pref/preferences.h"
16#include "app/tools/freehand_algorithm.h"
17#include "app/tools/tool.h"
18
19namespace app {
20
21class PixelPerfectModeCommand : public Command {
22public:
23 PixelPerfectModeCommand();
24
25protected:
26 bool onEnabled(Context* context) override;
27 bool onChecked(Context* context) override;
28 void onExecute(Context* context) override;
29};
30
31PixelPerfectModeCommand::PixelPerfectModeCommand()
32 : Command(CommandId::PixelPerfectMode(), CmdUIOnlyFlag)
33{
34}
35
36bool PixelPerfectModeCommand::onEnabled(Context* ctx)
37{
38 return true;
39}
40
41bool PixelPerfectModeCommand::onChecked(Context* ctx)
42{
43 tools::Tool* tool = App::instance()->activeTool();
44 if (!tool)
45 return false;
46
47 auto& toolPref = Preferences::instance().tool(tool);
48 return (toolPref.freehandAlgorithm() == tools::FreehandAlgorithm::PIXEL_PERFECT);
49}
50
51void PixelPerfectModeCommand::onExecute(Context* ctx)
52{
53 tools::Tool* tool = App::instance()->activeTool();
54 if (!tool)
55 return;
56
57 auto& toolPref = Preferences::instance().tool(tool);
58 toolPref.freehandAlgorithm(
59 toolPref.freehandAlgorithm() == tools::FreehandAlgorithm::DEFAULT ?
60 tools::FreehandAlgorithm::PIXEL_PERFECT:
61 tools::FreehandAlgorithm::DEFAULT);
62}
63
64Command* CommandFactory::createPixelPerfectModeCommand()
65{
66 return new PixelPerfectModeCommand;
67}
68
69} // namespace app
70