Select the valid tag for animation playback depending on the active timeline frame tag (related to #920)

This commit is contained in:
David Capello 2017-03-29 21:18:29 -03:00
parent 6f750b1b50
commit 01979f0cac
8 changed files with 90 additions and 11 deletions

View File

@ -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 @@ public:
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 @@ public:
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());

View File

@ -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);

View File

@ -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 @@ public:
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 @@ private:
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();
}
};

View File

@ -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

View File

@ -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) {

View File

@ -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;

View File

@ -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()) {

View File

@ -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;