diff --git a/src/app/commands/cmd_goto_frame.cpp b/src/app/commands/cmd_goto_frame.cpp index bd1611392c..9de34ced45 100644 --- a/src/app/commands/cmd_goto_frame.cpp +++ b/src/app/commands/cmd_goto_frame.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -14,6 +14,7 @@ #include "app/modules/editors.h" #include "app/modules/gui.h" #include "app/ui/editor/editor.h" +#include "app/ui/editor/editor_customization_delegate.h" #include "doc/frame_tag.h" #include "doc/sprite.h" #include "ui/window.h" @@ -96,7 +97,10 @@ class GotoNextFrameWithSameTagCommand : public GotoCommand { protected: frame_t onGetFrame(Editor* editor) override { frame_t frame = editor->frame(); - FrameTag* tag = get_animation_tag(editor->sprite(), frame); + FrameTag* tag = editor + ->getCustomizationDelegate() + ->getFrameTagProvider() + ->getFrameTagByFrame(frame); frame_t first = (tag ? tag->fromFrame(): 0); frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame()); @@ -113,7 +117,10 @@ class GotoPreviousFrameWithSameTagCommand : public GotoCommand { protected: frame_t onGetFrame(Editor* editor) override { frame_t frame = editor->frame(); - FrameTag* tag = get_animation_tag(editor->sprite(), frame); + FrameTag* tag = editor + ->getCustomizationDelegate() + ->getFrameTagProvider() + ->getFrameTagByFrame(frame); frame_t first = (tag ? tag->fromFrame(): 0); frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame()); diff --git a/src/app/loop_tag.h b/src/app/loop_tag.h index 0efab5d159..65eae3f0bc 100644 --- a/src/app/loop_tag.h +++ b/src/app/loop_tag.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -17,6 +17,12 @@ namespace doc { namespace app { + class FrameTagProvider { + public: + virtual ~FrameTagProvider() { } + virtual doc::FrameTag* getFrameTagByFrame(const doc::frame_t frame) = 0; + }; + doc::FrameTag* get_animation_tag(const doc::Sprite* sprite, doc::frame_t frame); doc::FrameTag* get_loop_tag(const doc::Sprite* sprite); doc::FrameTag* create_loop_tag(doc::frame_t from, doc::frame_t to); diff --git a/src/app/ui/document_view.cpp b/src/app/ui/document_view.cpp index 8c8bfb4889..13d22dfd3f 100644 --- a/src/app/ui/document_view.cpp +++ b/src/app/ui/document_view.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -29,6 +29,7 @@ #include "app/ui/keyboard_shortcuts.h" #include "app/ui/main_window.h" #include "app/ui/status_bar.h" +#include "app/ui/timeline/timeline.h" #include "app/ui/workspace.h" #include "app/ui_context.h" #include "app/util/clipboard.h" @@ -99,6 +100,10 @@ class AppEditor : public Editor, return KeyboardShortcuts::instance()->getCurrentActionModifiers(context); } + FrameTagProvider* getFrameTagProvider() override { + return App::instance()->mainWindow()->getTimeline(); + } + protected: bool onProcessMessage(Message* msg) override { switch (msg->type()) { @@ -146,11 +151,30 @@ class AppEditor : public Editor, DocumentViewPreviewDelegate* m_previewDelegate; }; -class PreviewEditor : public Editor { +class PreviewEditor : public Editor, + public EditorCustomizationDelegate { public: PreviewEditor(Document* document) : Editor(document, Editor::kShowOutside) // Don't show grid/mask in preview preview { + setCustomizationDelegate(this); + } + + // EditorCustomizationDelegate implementation + void dispose() override { + // Do nothing + } + + tools::Tool* getQuickTool(tools::Tool* currentTool) override { + return nullptr; + } + + KeyAction getPressedKeyAction(KeyContext context) override { + return KeyAction::None; + } + + FrameTagProvider* getFrameTagProvider() override { + return App::instance()->mainWindow()->getTimeline(); } }; diff --git a/src/app/ui/editor/editor_customization_delegate.h b/src/app/ui/editor/editor_customization_delegate.h index 93096c8329..d0ad4c41bd 100644 --- a/src/app/ui/editor/editor_customization_delegate.h +++ b/src/app/ui/editor/editor_customization_delegate.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -16,6 +16,7 @@ namespace tools { namespace app { class Editor; + class FrameTagProvider; class EditorCustomizationDelegate { public: @@ -29,6 +30,9 @@ namespace app { // Returns what action is pressed at this moment. virtual KeyAction getPressedKeyAction(KeyContext context) = 0; + + // Returns the provider of active frame tag (it's the timeline). + virtual FrameTagProvider* getFrameTagProvider() = 0; }; } // namespace app diff --git a/src/app/ui/editor/play_state.cpp b/src/app/ui/editor/play_state.cpp index 636d93395d..0e6f51990d 100644 --- a/src/app/ui/editor/play_state.cpp +++ b/src/app/ui/editor/play_state.cpp @@ -16,6 +16,7 @@ #include "app/pref/preferences.h" #include "app/tools/ink.h" #include "app/ui/editor/editor.h" +#include "app/ui/editor/editor_customization_delegate.h" #include "app/ui/editor/scrolling_state.h" #include "app/ui_context.h" #include "doc/frame_tag.h" @@ -59,7 +60,10 @@ void PlayState::onEnterState(Editor* editor) // Get the tag if (!m_playAll) - m_tag = get_animation_tag(m_editor->sprite(), m_refFrame); + m_tag = m_editor + ->getCustomizationDelegate() + ->getFrameTagProvider() + ->getFrameTagByFrame(m_refFrame); // Go to the first frame of the animation or active frame tag if (m_playOnce) { diff --git a/src/app/ui/preview_editor.cpp b/src/app/ui/preview_editor.cpp index 658e9dff22..51ce655cb6 100644 --- a/src/app/ui/preview_editor.cpp +++ b/src/app/ui/preview_editor.cpp @@ -18,6 +18,7 @@ #include "app/modules/gui.h" #include "app/pref/preferences.h" #include "app/ui/editor/editor.h" +#include "app/ui/editor/editor_customization_delegate.h" #include "app/ui/editor/editor_view.h" #include "app/ui/editor/navigate_state.h" #include "app/ui/skin/skin_button.h" @@ -375,8 +376,16 @@ void PreviewEditorWindow::updateUsingEditor(Editor* editor) } else { if (miniEditor->isPlaying()) { - doc::FrameTag* tag = get_animation_tag(editor->sprite(), editor->frame()); - doc::FrameTag* playingTag = get_animation_tag(editor->sprite(), m_refFrame); + doc::FrameTag* tag = editor + ->getCustomizationDelegate() + ->getFrameTagProvider() + ->getFrameTagByFrame(editor->frame()); + + doc::FrameTag* playingTag = editor + ->getCustomizationDelegate() + ->getFrameTagProvider() + ->getFrameTagByFrame(m_refFrame); + if (tag == playingTag) return; diff --git a/src/app/ui/timeline/timeline.cpp b/src/app/ui/timeline/timeline.cpp index 06abb290da..5d4ee1f06e 100644 --- a/src/app/ui/timeline/timeline.cpp +++ b/src/app/ui/timeline/timeline.cpp @@ -415,6 +415,23 @@ void Timeline::activateClipboardRange() invalidate(); } +FrameTag* Timeline::getFrameTagByFrame(const frame_t frame) +{ + if (m_tagFocusBand < 0) { + return get_animation_tag(m_sprite, frame); + } + else { + for (FrameTag* frameTag : m_sprite->frameTags()) { + if (frame >= frameTag->fromFrame() && + frame <= frameTag->toFrame() && + m_tagBand[frameTag] == m_tagFocusBand) { + return frameTag; + } + } + return nullptr; + } +} + bool Timeline::onProcessMessage(Message* msg) { switch (msg->type()) { diff --git a/src/app/ui/timeline/timeline.h b/src/app/ui/timeline/timeline.h index 016a341d64..6cd0dba0b1 100644 --- a/src/app/ui/timeline/timeline.h +++ b/src/app/ui/timeline/timeline.h @@ -9,6 +9,7 @@ #pragma once #include "app/document_range.h" +#include "app/loop_tag.h" #include "app/pref/preferences.h" #include "app/ui/editor/editor_observer.h" #include "app/ui/input_chain_element.h" @@ -56,7 +57,8 @@ namespace app { , public doc::DocumentsObserver , public doc::DocumentObserver , public app::EditorObserver - , public app::InputChainElement { + , public app::InputChainElement + , public app::FrameTagProvider { public: typedef DocumentRange Range; @@ -99,6 +101,12 @@ namespace app { // called from popup menus. void dropRange(DropOp op); + // FrameTagProvider impl + // Returns the active frame tag depending on the timeline status + // E.g. if other frame tags are collapsed, the focused band has + // priority and tags in other bands are ignored. + FrameTag* getFrameTagByFrame(const frame_t frame) override; + // ScrollableViewDelegate impl gfx::Size visibleSize() const override; gfx::Point viewScroll() const override;