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 "filters/tiled_mode.h"
17
18namespace app {
19
20class TiledModeCommand : public Command {
21public:
22 TiledModeCommand();
23
24protected:
25 void onLoadParams(const Params& params) override;
26 bool onEnabled(Context* context) override;
27 bool onChecked(Context* context) override;
28 void onExecute(Context* context) override;
29
30 filters::TiledMode m_mode;
31};
32
33TiledModeCommand::TiledModeCommand()
34 : Command(CommandId::TiledMode(), CmdUIOnlyFlag)
35 , m_mode(filters::TiledMode::NONE)
36{
37}
38
39void TiledModeCommand::onLoadParams(const Params& params)
40{
41 m_mode = filters::TiledMode::NONE;
42
43 std::string mode = params.get("axis");
44 if (mode == "both") m_mode = filters::TiledMode::BOTH;
45 else if (mode == "x") m_mode = filters::TiledMode::X_AXIS;
46 else if (mode == "y") m_mode = filters::TiledMode::Y_AXIS;
47}
48
49bool TiledModeCommand::onEnabled(Context* ctx)
50{
51 return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable |
52 ContextFlags::HasActiveSprite);
53}
54
55bool TiledModeCommand::onChecked(Context* ctx)
56{
57 const Doc* doc = ctx->activeDocument();
58 return (Preferences::instance().document(doc).tiled.mode() == m_mode);
59}
60
61void TiledModeCommand::onExecute(Context* ctx)
62{
63 const Doc* doc = ctx->activeDocument();
64 Preferences::instance().document(doc).tiled.mode(m_mode);
65}
66
67Command* CommandFactory::createTiledModeCommand()
68{
69 return new TiledModeCommand;
70}
71
72} // namespace app
73