1// Aseprite
2// Copyright (C) 2020 Igara Studio S.A.
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/i18n/strings.h"
15#include "app/ui/color_bar.h"
16#include "fmt/format.h"
17
18namespace app {
19
20using namespace gfx;
21
22class TilesetModeCommand : public Command {
23public:
24 TilesetModeCommand()
25 : Command(CommandId::TilesetMode(), CmdUIOnlyFlag) {
26 m_mode = TilesetMode::Auto;
27 }
28
29protected:
30
31 void onLoadParams(const Params& params) override {
32 std::string mode = params.get("mode");
33 if (mode == "manual") m_mode = TilesetMode::Manual;
34 else if (mode == "stack") m_mode = TilesetMode::Stack;
35 else m_mode = TilesetMode::Auto;
36 }
37
38 bool onChecked(Context* context) override {
39 auto colorBar = ColorBar::instance();
40 return (colorBar->tilesetMode() == m_mode);
41 }
42
43 void onExecute(Context* context) override {
44 auto colorBar = ColorBar::instance();
45 colorBar->setTilesetMode(m_mode);
46 }
47
48 std::string onGetFriendlyName() const override {
49 std::string mode;
50 switch (m_mode) {
51 case TilesetMode::Manual: mode = Strings::commands_TilesetMode_Manual(); break;
52 case TilesetMode::Auto: mode = Strings::commands_TilesetMode_Auto(); break;
53 case TilesetMode::Stack: mode = Strings::commands_TilesetMode_Stack(); break;
54 }
55 return fmt::format(getBaseFriendlyName(), mode);
56 }
57
58private:
59 TilesetMode m_mode;
60};
61
62Command* CommandFactory::createTilesetModeCommand()
63{
64 return new TilesetModeCommand;
65}
66
67} // namespace app
68