Switch shading colors with X key

Related to #85 and #854
This commit is contained in:
David Capello 2015-11-20 18:44:08 -03:00
parent c96691c681
commit e683b8fb1a
3 changed files with 35 additions and 2 deletions

View File

@ -11,7 +11,11 @@
#include "app/app.h"
#include "app/commands/command.h"
#include "app/modules/editors.h"
#include "app/ui/color_bar.h"
#include "app/ui/context_bar.h"
#include "app/ui/editor/editor.h"
#include "app/ui/main_window.h"
#include "ui/base.h"
namespace app {
@ -21,7 +25,8 @@ public:
SwitchColorsCommand();
protected:
void onExecute(Context* context);
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
};
SwitchColorsCommand::SwitchColorsCommand()
@ -31,12 +36,29 @@ SwitchColorsCommand::SwitchColorsCommand()
{
}
bool SwitchColorsCommand::onEnabled(Context* context)
{
return (current_editor ? true: false);
}
void SwitchColorsCommand::onExecute(Context* context)
{
ASSERT(current_editor);
if (!current_editor)
return;
tools::Tool* tool = current_editor->getCurrentEditorTool();
if (tool) {
const auto& toolPref(Preferences::instance().tool(tool));
if (toolPref.ink() == tools::InkType::SHADING) {
App::instance()->getMainWindow()->
getContextBar()->reverseShadesColors();
}
}
ColorBar* colorbar = ColorBar::instance();
app::Color fg = colorbar->getFgColor();
app::Color bg = colorbar->getBgColor();
colorbar->setFgColor(bg);
colorbar->setBgColor(fg);
}

View File

@ -437,6 +437,11 @@ public:
setText("Select colors in the palette");
}
void reverseColors() {
std::reverse(m_colors.begin(), m_colors.end());
invalidate();
}
doc::Remap* createShadesRemap(bool left) {
base::UniquePtr<doc::Remap> remap;
Colors colors = getColors();
@ -1503,4 +1508,9 @@ doc::Remap* ContextBar::createShadesRemap(bool left)
return m_inkShades->createShadesRemap(left);
}
void ContextBar::reverseShadesColors()
{
m_inkShades->reverseColors();
}
} // namespace app

View File

@ -71,6 +71,7 @@ namespace app {
ToolPreferences::Brush* brushPref = nullptr);
doc::Remap* createShadesRemap(bool left);
void reverseShadesColors();
// Signals
Signal0<void> BrushChange;