diff --git a/data/gui.xml b/data/gui.xml
index 08066ea71..a213b7e6e 100644
--- a/data/gui.xml
+++ b/data/gui.xml
@@ -303,6 +303,12 @@
+
+
+
+
+
+
@@ -1017,7 +1023,14 @@
-
-
+
diff --git a/data/pref.xml b/data/pref.xml
index 16f1110f7..9b92ebea5 100644
--- a/data/pref.xml
+++ b/data/pref.xml
@@ -234,6 +234,7 @@
+
diff --git a/data/strings/en.ini b/data/strings/en.ini
index 78bcb0594..81c8bf733 100644
--- a/data/strings/en.ini
+++ b/data/strings/en.ini
@@ -601,6 +601,8 @@ SwitchNonactiveLayersOpacity = Switch Nonactive Layers Opacity
SymmetryMode = Symmetry Mode
TiledMode = Tiled Mode
Timeline = Switch Timeline
+ToggleOtherLayersOpacity = Toggle Other Layers Opacity
+ToggleOtherLayersOpacity_PreviewEditor = Toggle Other Layers Opacity in Preview
TogglePlayAll = Play All Frames (Ignore Tags)
TogglePlayOnce = Play Once
TogglePlaySubtags = Play Subtags & Repetitions
@@ -1350,6 +1352,7 @@ view_set_loop_section = Set &Loop Section
view_show_onion_skin = Show &Onion Skin
view_timeline = &Timeline
view_preview = Previe&w
+view_preview_hide_other_layers = &Hide Other Layers
view_advanced_mode = &Advanced Mode
view_full_screen_mode = &Full Screen Mode
view_full_screen_preview = F&ull Screen Preview
diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
index 4d56d765f..12aac8278 100644
--- a/src/app/CMakeLists.txt
+++ b/src/app/CMakeLists.txt
@@ -330,6 +330,7 @@ if(ENABLE_UI)
commands/set_playback_speed.cpp
commands/show_menu.cpp
commands/tileset_mode.cpp
+ commands/toggle_other_layers_opacity.cpp
commands/toggle_play_option.cpp
file_selector.cpp
modules/gfx.cpp
diff --git a/src/app/commands/commands_list.h b/src/app/commands/commands_list.h
index cd1cb78d4..4b732b903 100644
--- a/src/app/commands/commands_list.h
+++ b/src/app/commands/commands_list.h
@@ -168,6 +168,7 @@ FOR_EACH_COMMAND(SymmetryMode)
FOR_EACH_COMMAND(TiledMode)
FOR_EACH_COMMAND(TilesetMode)
FOR_EACH_COMMAND(Timeline)
+FOR_EACH_COMMAND(ToggleOtherLayersOpacity)
FOR_EACH_COMMAND(TogglePlayAll)
FOR_EACH_COMMAND(TogglePlayOnce)
FOR_EACH_COMMAND(TogglePlaySubtags)
diff --git a/src/app/commands/toggle_other_layers_opacity.cpp b/src/app/commands/toggle_other_layers_opacity.cpp
new file mode 100644
index 000000000..ea670c939
--- /dev/null
+++ b/src/app/commands/toggle_other_layers_opacity.cpp
@@ -0,0 +1,114 @@
+// Aseprite
+// Copyright (C) 2023 Igara Studio S.A.
+//
+// This program is distributed under the terms of
+// the End-User License Agreement for Aseprite.
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "app/app.h"
+#include "app/commands/new_params.h"
+#include "app/i18n/strings.h"
+#include "app/ui/editor/editor.h"
+#include "app/ui/main_window.h"
+#include "app/ui/preview_editor.h"
+#include "fmt/format.h"
+#include "ui/system.h"
+
+namespace app {
+
+struct ToggleOtherLayersOpacityParams : public NewParams {
+ Param preview { this, false, "preview" };
+ Param opacity { this, 255, "opacity" };
+ // Can be used if the option is presend as "Hide Others", so it's
+ // checked when the configured opacity == 0
+ Param checkedIfZero { this, false, "checkedIfZero" };
+};
+
+class ToggleOtherLayersOpacityCommand : public CommandWithNewParams {
+public:
+ ToggleOtherLayersOpacityCommand();
+private:
+ bool onChecked(Context* ctx) override;
+ void onExecute(Context* ctx) override;
+ std::string onGetFriendlyName() const override;
+};
+
+ToggleOtherLayersOpacityCommand::ToggleOtherLayersOpacityCommand()
+ : CommandWithNewParams(
+ CommandId::ToggleOtherLayersOpacity(), CmdUIOnlyFlag)
+{
+}
+
+bool ToggleOtherLayersOpacityCommand::onChecked(Context* ctx)
+{
+ if (params().checkedIfZero.isSet()) {
+ auto& pref = Preferences::instance();
+ auto& option =
+ (params().preview() ?
+ pref.experimental.nonactiveLayersOpacityPreview:
+ pref.experimental.nonactiveLayersOpacity);
+ return (option() == 0);
+ }
+ return false;
+}
+
+void ToggleOtherLayersOpacityCommand::onExecute(Context* ctx)
+{
+ auto& pref = Preferences::instance();
+ auto& option =
+ (params().preview() ?
+ pref.experimental.nonactiveLayersOpacityPreview:
+ pref.experimental.nonactiveLayersOpacity);
+
+ // If we want to toggle the other layers in the preview window, and
+ // the preview window is hidden, we just show it with the "other
+ // layers" hidden.
+ if (params().preview()) {
+ PreviewEditorWindow* previewWin =
+ App::instance()->mainWindow()->getPreviewEditor();
+ if (!previewWin->isPreviewEnabled()) {
+ option(0);
+ previewWin->setPreviewEnabled(true);
+ return;
+ }
+ }
+
+ if (params().opacity.isSet()) {
+ option(params().opacity());
+ }
+ else {
+ option(option() == 0 ? 255: 0);
+ }
+
+ // TODO make the editors listen the opacity change
+ if (params().preview()) {
+ PreviewEditorWindow* previewWin =
+ App::instance()->mainWindow()->getPreviewEditor();
+ previewWin->previewEditor()->invalidate();
+ }
+ else {
+ app_refresh_screen();
+ }
+}
+
+std::string ToggleOtherLayersOpacityCommand::onGetFriendlyName() const
+{
+ std::string text;
+ if (params().preview())
+ text = Strings::commands_ToggleOtherLayersOpacity_PreviewEditor();
+ else
+ text = Strings::commands_ToggleOtherLayersOpacity();
+ if (params().opacity.isSet())
+ text = fmt::format("{} ({})", text, params().opacity());
+ return text;
+}
+
+Command* CommandFactory::createToggleOtherLayersOpacityCommand()
+{
+ return new ToggleOtherLayersOpacityCommand;
+}
+
+} // namespace app
diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp
index 616e2954e..63478f6c1 100644
--- a/src/app/ui/editor/editor.cpp
+++ b/src/app/ui/editor/editor.cpp
@@ -383,7 +383,7 @@ void Editor::setLayer(const Layer* layer)
// If the user want to see the active layer edges...
m_docPref.show.layerEdges() ||
// If there is a different opacity for nonactive-layers
- Preferences::instance().experimental.nonactiveLayersOpacity() < 255 ||
+ otherLayersOpacity() < 255 ||
// If the automatic cel guides are visible...
m_showGuidesThisCel ||
// If grid settings changed
@@ -672,10 +672,7 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite
m_renderEngine->setNewBlendMethod(pref.experimental.newBlend());
m_renderEngine->setRefLayersVisiblity(true);
m_renderEngine->setSelectedLayer(m_layer);
- if (m_flags & Editor::kUseNonactiveLayersOpacityWhenEnabled)
- m_renderEngine->setNonactiveLayersOpacity(pref.experimental.nonactiveLayersOpacity());
- else
- m_renderEngine->setNonactiveLayersOpacity(255);
+ m_renderEngine->setNonactiveLayersOpacity(otherLayersOpacity());
m_renderEngine->setupBackground(m_document, IMAGE_RGB);
m_renderEngine->disableOnionskin();
@@ -2978,9 +2975,18 @@ void Editor::updateAutoCelGuides(ui::Message* msg)
}
}
+int Editor::otherLayersOpacity() const
+{
+ if (m_docView && m_docView->isPreview())
+ return Preferences::instance().experimental.nonactiveLayersOpacityPreview();
+ else
+ return Preferences::instance().experimental.nonactiveLayersOpacity();
+}
+
// static
void Editor::registerCommands()
{
+ // TODO merge with ToggleOtherLayersOpacity
Commands::instance()
->add(
new QuickCommand(
diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h
index be23fb28e..e6830c6a7 100644
--- a/src/app/ui/editor/editor.h
+++ b/src/app/ui/editor/editor.h
@@ -90,15 +90,13 @@ namespace app {
kShowDecorators = 16,
kShowSymmetryLine = 32,
kShowSlices = 64,
- kUseNonactiveLayersOpacityWhenEnabled = 128,
kDefaultEditorFlags = (kShowGrid |
kShowMask |
kShowOnionskin |
kShowOutside |
kShowDecorators |
kShowSymmetryLine |
- kShowSlices |
- kUseNonactiveLayersOpacityWhenEnabled)
+ kShowSlices)
};
enum class ZoomBehavior {
@@ -398,6 +396,8 @@ namespace app {
void invalidateIfActive();
void updateAutoCelGuides(ui::Message* msg);
+ int otherLayersOpacity() const;
+
// Stack of states. The top element in the stack is the current state (m_state).
EditorStatesHistory m_statesHistory;
EditorStatesHistory m_deletedStates;