From ac65b1291d1cc9b62ac9dc6c6c2a43c6f16a5149 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 29 Jun 2018 15:05:11 -0300 Subject: [PATCH] Add Shift+Enter (PlayPreviewAnimation command) to play/stop animation in preview window (fix #1774) --- data/gui.xml | 1 + data/strings/en.ini | 1 + src/app/commands/cmd_play_animation.cpp | 45 ++++++++++++++++++++++++- src/app/commands/commands_list.h | 1 + src/app/ui/preview_editor.cpp | 7 ++++ src/app/ui/preview_editor.h | 4 +-- 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/data/gui.xml b/data/gui.xml index 8af41d7f2..05ca46f4f 100644 --- a/data/gui.xml +++ b/data/gui.xml @@ -97,6 +97,7 @@ + diff --git a/data/strings/en.ini b/data/strings/en.ini index 86b11440c..f65ff7b9d 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -331,6 +331,7 @@ Paste = Paste PasteText = Insert Text PixelPerfectMode = Switch Pixel Perfect Mode PlayAnimation = Play Animation +PlayPreviewAnimation = Play Preview Animation Redo = Redo Refresh = Refresh RemoveFrame = Remove Frame diff --git a/src/app/commands/cmd_play_animation.cpp b/src/app/commands/cmd_play_animation.cpp index a1e03e73e..86640dea8 100644 --- a/src/app/commands/cmd_play_animation.cpp +++ b/src/app/commands/cmd_play_animation.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2017 David Capello +// Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -8,17 +8,22 @@ #include "config.h" #endif +#include "app/app.h" #include "app/commands/command.h" #include "app/context.h" #include "app/context_access.h" #include "app/modules/editors.h" #include "app/pref/preferences.h" #include "app/ui/editor/editor.h" +#include "app/ui/main_window.h" +#include "app/ui/preview_editor.h" namespace app { using namespace ui; +////////////////////////////////////////////////////////////////////// + class PlayAnimationCommand : public Command { public: PlayAnimationCommand(); @@ -61,9 +66,47 @@ void PlayAnimationCommand::onExecute(Context* context) Preferences::instance().editor.playAll()); } +////////////////////////////////////////////////////////////////////// + +class PlayPreviewAnimationCommand : public Command { +public: + PlayPreviewAnimationCommand(); + Command* clone() const override { return new PlayPreviewAnimationCommand(*this); } + +protected: + bool onEnabled(Context* context) override; + void onExecute(Context* context) override; +}; + +PlayPreviewAnimationCommand::PlayPreviewAnimationCommand() + : Command(CommandId::PlayPreviewAnimation(), CmdUIOnlyFlag) +{ +} + +bool PlayPreviewAnimationCommand::onEnabled(Context* context) +{ + return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | + ContextFlags::HasActiveSprite); +} + +void PlayPreviewAnimationCommand::onExecute(Context* context) +{ + PreviewEditorWindow* preview = App::instance()->mainWindow()->getPreviewEditor(); + if (!preview->isPreviewEnabled()) + preview->setPreviewEnabled(true); + preview->pressPlayButton(); +} + +////////////////////////////////////////////////////////////////////// + Command* CommandFactory::createPlayAnimationCommand() { return new PlayAnimationCommand; } +Command* CommandFactory::createPlayPreviewAnimationCommand() +{ + return new PlayPreviewAnimationCommand; +} + } // namespace app diff --git a/src/app/commands/commands_list.h b/src/app/commands/commands_list.h index a981ac9fe..678a52e10 100644 --- a/src/app/commands/commands_list.h +++ b/src/app/commands/commands_list.h @@ -105,6 +105,7 @@ FOR_EACH_COMMAND(Paste) FOR_EACH_COMMAND(PasteText) FOR_EACH_COMMAND(PixelPerfectMode) FOR_EACH_COMMAND(PlayAnimation) +FOR_EACH_COMMAND(PlayPreviewAnimation) FOR_EACH_COMMAND(Refresh) FOR_EACH_COMMAND(RemoveFrame) FOR_EACH_COMMAND(RemoveFrameTag) diff --git a/src/app/ui/preview_editor.cpp b/src/app/ui/preview_editor.cpp index 96c399697..f264ccfa2 100644 --- a/src/app/ui/preview_editor.cpp +++ b/src/app/ui/preview_editor.cpp @@ -206,6 +206,13 @@ void PreviewEditorWindow::setPreviewEnabled(bool state) updateUsingEditor(current_editor); } +void PreviewEditorWindow::pressPlayButton() +{ + m_playButton->setSelected( + !m_playButton->isSelected()); + onPlayClicked(); +} + bool PreviewEditorWindow::onProcessMessage(ui::Message* msg) { switch (msg->type()) { diff --git a/src/app/ui/preview_editor.h b/src/app/ui/preview_editor.h index 7575d5bc4..60f3f84d5 100644 --- a/src/app/ui/preview_editor.h +++ b/src/app/ui/preview_editor.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2017 David Capello +// Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -27,9 +27,9 @@ namespace app { bool isPreviewEnabled() const { return m_isEnabled; } void setPreviewEnabled(bool state); + void pressPlayButton(); void updateUsingEditor(Editor* editor); - Editor* relatedEditor() const { return m_relatedEditor; } // EditorObserver impl