From 39a2045a438e963af2e2d5b65762890c621e172b Mon Sep 17 00:00:00 2001 From: MorganDavid Date: Thu, 28 May 2020 23:11:26 +0100 Subject: [PATCH] Added swap checkerboard colors command --- data/strings/en.ini | 1 + src/app/CMakeLists.txt | 1 + .../commands/cmd_swap_checkerboard_colors.cpp | 53 +++++++++++++++++++ src/app/commands/commands_list.h | 1 + 4 files changed, 56 insertions(+) create mode 100644 src/app/commands/cmd_swap_checkerboard_colors.cpp diff --git a/data/strings/en.ini b/data/strings/en.ini index 616b09d9e..ec3439c6d 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -439,6 +439,7 @@ SpriteProperties = Sprite Properties SpriteSize = Sprite Size Stroke = Stroke Selection Borders with Foreground Color SwitchColors = Switch Colors +SwapCheckerboardColors = Swap Checkerboard Background Colors SwitchNonactiveLayersOpacity = Switch Nonactive Layers Opacity SymmetryMode = Symmetry Mode TiledMode = Tiled Mode diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 13f30a70b..4b6bb5eda 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -283,6 +283,7 @@ if(ENABLE_UI) commands/cmd_show.cpp commands/cmd_slice_properties.cpp commands/cmd_sprite_properties.cpp + commands/cmd_swap_checkerboard_colors.cpp commands/cmd_switch_colors.cpp commands/cmd_symmetry_mode.cpp commands/cmd_tiled_mode.cpp diff --git a/src/app/commands/cmd_swap_checkerboard_colors.cpp b/src/app/commands/cmd_swap_checkerboard_colors.cpp new file mode 100644 index 000000000..2022581cf --- /dev/null +++ b/src/app/commands/cmd_swap_checkerboard_colors.cpp @@ -0,0 +1,53 @@ +// Aseprite +// Copyright (C) 2001-2015 David Capello +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "app/app.h" +#include "app/commands/command.h" +#include "app/modules/editors.h" +#include "app/ui/editor/editor.h" +#include "ui/base.h" +#include "app/context.h" + +namespace app { + + class SwapCheckerboardColorsCommand : public Command { + public: + SwapCheckerboardColorsCommand(); + + protected: + bool onEnabled(Context* context) override; + void onExecute(Context* context) override; + }; + + SwapCheckerboardColorsCommand::SwapCheckerboardColorsCommand() + : Command(CommandId::SwapCheckerboardColors(), CmdUIOnlyFlag) + { + } + + bool SwapCheckerboardColorsCommand::onEnabled(Context* context) + { + return true; + } + + void SwapCheckerboardColorsCommand::onExecute(Context* context) + { + DocumentPreferences& docPref = Preferences::instance().document(context->activeDocument()); + app::Color c1 = docPref.bg.color1(); + app::Color c2 = docPref.bg.color2(); + + docPref.bg.color1(c2); + docPref.bg.color2(c1); + } + Command* CommandFactory::createSwapCheckerboardColorsCommand() + { + return new SwapCheckerboardColorsCommand; + } + +} // namespace app diff --git a/src/app/commands/commands_list.h b/src/app/commands/commands_list.h index 9ae1c9648..03b5ea124 100644 --- a/src/app/commands/commands_list.h +++ b/src/app/commands/commands_list.h @@ -151,6 +151,7 @@ FOR_EACH_COMMAND(SliceProperties) FOR_EACH_COMMAND(SnapToGrid) FOR_EACH_COMMAND(SpriteProperties) FOR_EACH_COMMAND(Stroke) +FOR_EACH_COMMAND(SwapCheckerboardColors) FOR_EACH_COMMAND(SwitchColors) FOR_EACH_COMMAND(SymmetryMode) FOR_EACH_COMMAND(TiledMode)