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/modules/editors.h" 14 #include "app/ui/color_bar.h" 15 #include "app/ui/context_bar.h" 16 #include "app/ui/editor/editor.h" 17 #include "ui/base.h" 18 19 namespace app { 20 21 class SwitchColorsCommand : public Command { 22 public: 23 SwitchColorsCommand(); 24 25 protected: 26 bool onEnabled(Context* context) override; 27 void onExecute(Context* context) override; 28 }; 29 SwitchColorsCommand()30SwitchColorsCommand::SwitchColorsCommand() 31 : Command(CommandId::SwitchColors(), CmdUIOnlyFlag) 32 { 33 } 34 onEnabled(Context * context)35bool SwitchColorsCommand::onEnabled(Context* context) 36 { 37 return (current_editor ? true: false); 38 } 39 onExecute(Context * context)40void SwitchColorsCommand::onExecute(Context* context) 41 { 42 ASSERT(current_editor); 43 if (!current_editor) 44 return; 45 46 tools::Tool* tool = current_editor->getCurrentEditorTool(); 47 if (tool) { 48 const auto& toolPref(Preferences::instance().tool(tool)); 49 if (toolPref.ink() == tools::InkType::SHADING) { 50 App::instance()->contextBar()->reverseShadeColors(); 51 } 52 } 53 54 DisableColorBarEditMode disable; 55 ColorBar* colorbar = ColorBar::instance(); 56 app::Color fg = colorbar->getFgColor(); 57 app::Color bg = colorbar->getBgColor(); 58 59 // Change the background and then the foreground color so the color 60 // spectrum and color wheel shows the foreground color as the 61 // selected one. 62 colorbar->setBgColor(fg); 63 colorbar->setFgColor(bg); 64 } 65 createSwitchColorsCommand()66Command* CommandFactory::createSwitchColorsCommand() 67 { 68 return new SwitchColorsCommand; 69 } 70 71 } // namespace app 72