[aseprite] 07/308: Add shortcut to switch pixel-perfect mode (fix #858)
Tobias Hansen
thansen at moszumanska.debian.org
Tue Mar 8 02:44:46 UTC 2016
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit 6cbb1882d4188c581a7a77bdf51b2b5540aeb043
Author: David Capello <davidcapello at gmail.com>
Date: Wed Nov 18 16:15:25 2015 -0300
Add shortcut to switch pixel-perfect mode (fix #858)
---
data/gui.xml | 3 ++
src/app/CMakeLists.txt | 1 +
src/app/commands/cmd_pixel_perfect_mode.cpp | 73 +++++++++++++++++++++++++++++
src/app/commands/commands.h | 3 ++
src/app/commands/commands_list.h | 1 +
src/app/ui/context_bar.cpp | 10 ++++
src/app/ui/context_bar.h | 2 +
src/app/ui/keyboard_shortcuts.cpp | 6 +--
8 files changed, 95 insertions(+), 4 deletions(-)
diff --git a/data/gui.xml b/data/gui.xml
index d7246a0..e1738d0 100644
--- a/data/gui.xml
+++ b/data/gui.xml
@@ -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 -->
diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
index 8f11db8..a857b87 100644
--- a/src/app/CMakeLists.txt
+++ b/src/app/CMakeLists.txt
@@ -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
diff --git a/src/app/commands/cmd_pixel_perfect_mode.cpp b/src/app/commands/cmd_pixel_perfect_mode.cpp
new file mode 100644
index 0000000..1314f9f
--- /dev/null
+++ b/src/app/commands/cmd_pixel_perfect_mode.cpp
@@ -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
diff --git a/src/app/commands/commands.h b/src/app/commands/commands.h
index 2041637..4444030 100644
--- a/src/app/commands/commands.h
+++ b/src/app/commands/commands.h
@@ -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
diff --git a/src/app/commands/commands_list.h b/src/app/commands/commands_list.h
index 00c3edb..0d488ce 100644
--- a/src/app/commands/commands_list.h
+++ b/src/app/commands/commands_list.h
@@ -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)
diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp
index 1916bda..ef1de84 100644
--- a/src/app/ui/context_bar.cpp
+++ b/src/app/ui/context_bar.cpp
@@ -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)
diff --git a/src/app/ui/context_bar.h b/src/app/ui/context_bar.h
index 1fa8cfa..52ca071 100644
--- a/src/app/ui/context_bar.h
+++ b/src/app/ui/context_bar.h
@@ -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
diff --git a/src/app/ui/keyboard_shortcuts.cpp b/src/app/ui/keyboard_shortcuts.cpp
index b4024ec..2e295e9 100644
--- a/src/app/ui/keyboard_shortcuts.cpp
+++ b/src/app/ui/keyboard_shortcuts.cpp
@@ -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) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list