Add shortcut to switch pixel-perfect mode (fix #858)

This commit is contained in:
David Capello 2015-11-18 16:15:25 -03:00
parent c29fd79796
commit 6cbb1882d4
8 changed files with 95 additions and 4 deletions

View File

@ -365,6 +365,9 @@
<key command="NewBrush" shortcut="Ctrl+B" mac="Cmd+B" />
<key command="NewSpriteFromSelection" shortcut="Ctrl+Alt+N" mac="Cmd+Alt+N" />
<!-- Commands not associated to menu items and without shortcuts by default -->
<key command="PixelPerfectMode" />
</commands>
<!-- Keyboard shortcuts to select tools -->

View File

@ -227,6 +227,7 @@ add_library(app-lib
commands/cmd_palette_size.cpp
commands/cmd_paste.cpp
commands/cmd_paste_text.cpp
commands/cmd_pixel_perfect_mode.cpp
commands/cmd_play_animation.cpp
commands/cmd_refresh.cpp
commands/cmd_remove_frame.cpp

View File

@ -0,0 +1,73 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/app.h"
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/context.h"
#include "app/pref/preferences.h"
#include "app/tools/freehand_algorithm.h"
#include "app/tools/tool.h"
namespace app {
class PixelPerfectModeCommand : public Command {
public:
PixelPerfectModeCommand();
Command* clone() const override { return new PixelPerfectModeCommand(*this); }
protected:
bool onEnabled(Context* context) override;
bool onChecked(Context* context) override;
void onExecute(Context* context) override;
};
PixelPerfectModeCommand::PixelPerfectModeCommand()
: Command("PixelPerfectMode",
"Switch Pixel Perfect Mode",
CmdUIOnlyFlag)
{
}
bool PixelPerfectModeCommand::onEnabled(Context* ctx)
{
return true;
}
bool PixelPerfectModeCommand::onChecked(Context* ctx)
{
tools::Tool* tool = App::instance()->activeTool();
if (!tool)
return false;
auto& toolPref = Preferences::instance().tool(tool);
return (toolPref.freehandAlgorithm() == tools::FreehandAlgorithm::PIXEL_PERFECT);
}
void PixelPerfectModeCommand::onExecute(Context* ctx)
{
tools::Tool* tool = App::instance()->activeTool();
if (!tool)
return;
auto& toolPref = Preferences::instance().tool(tool);
toolPref.freehandAlgorithm(
toolPref.freehandAlgorithm() == tools::FreehandAlgorithm::DEFAULT ?
tools::FreehandAlgorithm::PIXEL_PERFECT:
tools::FreehandAlgorithm::DEFAULT);
}
Command* CommandFactory::createPixelPerfectModeCommand()
{
return new PixelPerfectModeCommand;
}
} // namespace app

View File

@ -37,6 +37,9 @@ namespace app {
static CommandsModule* instance();
Command* getCommandByName(const char* name);
CommandsList::iterator begin() { return m_commands.begin(); }
CommandsList::iterator end() { return m_commands.end(); }
};
} // namespace app

View File

@ -84,6 +84,7 @@ FOR_EACH_COMMAND(PaletteEditor)
FOR_EACH_COMMAND(PaletteSize)
FOR_EACH_COMMAND(Paste)
FOR_EACH_COMMAND(PasteText)
FOR_EACH_COMMAND(PixelPerfectMode)
FOR_EACH_COMMAND(PlayAnimation)
FOR_EACH_COMMAND(Redo)
FOR_EACH_COMMAND(Refresh)

View File

@ -1125,6 +1125,15 @@ void ContextBar::onToolSetOpacity(const int& newOpacity)
m_inkOpacity->setTextf("%d", newOpacity);
}
void ContextBar::onToolSetFreehandAlgorithm()
{
Tool* tool = App::instance()->activeTool();
if (tool) {
m_freehandAlgo->setFreehandAlgorithm(
Preferences::instance().tool(tool).freehandAlgorithm());
}
}
void ContextBar::onBrushSizeChange()
{
if (m_activeBrush->type() != kImageBrushType)
@ -1188,6 +1197,7 @@ void ContextBar::updateForTool(tools::Tool* tool)
m_sizeConn = brushPref->size.AfterChange.connect(Bind<void>(&ContextBar::onBrushSizeChange, this));
m_angleConn = brushPref->angle.AfterChange.connect(Bind<void>(&ContextBar::onBrushAngleChange, this));
m_opacityConn = toolPref->opacity.AfterChange.connect(&ContextBar::onToolSetOpacity, this);
m_freehandAlgoConn = toolPref->freehandAlgorithm.AfterChange.connect(Bind<void>(&ContextBar::onToolSetFreehandAlgorithm, this));
}
if (tool)

View File

@ -78,6 +78,7 @@ namespace app {
protected:
void onPreferredSize(ui::PreferredSizeEvent& ev) override;
void onToolSetOpacity(const int& newOpacity);
void onToolSetFreehandAlgorithm();
private:
void onBrushSizeChange();
@ -156,6 +157,7 @@ namespace app {
ScopedConnection m_sizeConn;
ScopedConnection m_angleConn;
ScopedConnection m_opacityConn;
ScopedConnection m_freehandAlgoConn;
};
} // namespace app

View File

@ -312,7 +312,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
const char* command_key = get_shortcut(xmlKey);
bool removed = bool_attr_is_true(xmlKey, "removed");
if (command_name && command_key) {
if (command_name) {
Command* command = CommandsModule::instance()->getCommandByName(command_name);
if (command) {
// Read context
@ -339,11 +339,9 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
xmlParam = xmlParam->NextSiblingElement();
}
LOG(" - Shortcut for command `%s' <%s>\n", command_name, command_key);
// add the keyboard shortcut to the command
Key* key = this->command(command_name, params, keycontext);
if (key) {
if (key && command_key) {
Accelerator accel(command_key);
if (!removed) {