From 7dcc0072f14f498c9e2875d269f4eb3fd1b5c67d Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 6 Dec 2017 14:44:40 -0300 Subject: [PATCH] Add SwitchNonactiveLayersOpacity command (fix #1515) This is a temporal solution but it's good enough for an experimental feature. --- data/strings/en.ini | 1 + src/app/ui/editor/editor.cpp | 28 ++++++++++++++++++++++++++++ src/app/ui/editor/editor.h | 2 ++ src/app/ui/main_window.cpp | 2 ++ 4 files changed, 33 insertions(+) diff --git a/data/strings/en.ini b/data/strings/en.ini index 19cda74a7..6d56f3e72 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -370,6 +370,7 @@ SnapToGrid = Snap to Grid SpriteProperties = Sprite Properties SpriteSize = Sprite Size SwitchColors = Switch Colors +SwitchNonactiveLayersOpacity = Switch Nonactive Layers Opacity SymmetryMode = Symmetry Mode TiledMode = Tiled Mode Timeline = Switch Timeline diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index b0ace85e8..22187a022 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -16,7 +16,9 @@ #include "app/color_utils.h" #include "app/commands/commands.h" #include "app/commands/params.h" +#include "app/commands/quick_command.h" #include "app/console.h" +#include "app/i18n/strings.h" #include "app/ini_file.h" #include "app/modules/editors.h" #include "app/modules/gfx.h" @@ -2485,4 +2487,30 @@ void Editor::updateAutoCelGuides(ui::Message* msg) invalidate(); } +// static +void Editor::registerCommands() +{ + Commands::instance() + ->add( + new QuickCommand( + CommandId::SwitchNonactiveLayersOpacity(), + []{ + static int oldValue = -1; + auto& option = Preferences::instance().experimental.nonactiveLayersOpacity; + if (oldValue == -1) { + oldValue = option(); + if (option() == 255) + option(128); + else + option(255); + } + else { + const int newValue = oldValue; + oldValue = option(); + option(newValue); + } + app_refresh_screen(); + })); +} + } // namespace app diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index a69b46be6..a9b9222c6 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -269,6 +269,8 @@ namespace app { // freehand tool is pressed. bool startStraightLineWithFreehandTool(const ui::MouseMessage* msg); + static void registerCommands(); + protected: bool onProcessMessage(ui::Message* msg) override; void onSizeHint(ui::SizeHintEvent& ev) override; diff --git a/src/app/ui/main_window.cpp b/src/app/ui/main_window.cpp index b91033880..51e026236 100644 --- a/src/app/ui/main_window.cpp +++ b/src/app/ui/main_window.cpp @@ -101,6 +101,8 @@ MainWindow::MainWindow() m_previewEditor = new PreviewEditorWindow(); m_timeline = new Timeline(); + Editor::registerCommands(); + m_workspace->setTabsBar(m_tabsBar); m_workspace->ActiveViewChanged.connect(&MainWindow::onActiveViewChange, this);