Skip to content

Commit

Permalink
Select the valid tag for animation playback depending on the active t…
Browse files Browse the repository at this point in the history
…imeline frame tag (related to aseprite#920)
  • Loading branch information
dacap committed Mar 30, 2017
1 parent 6f750b1 commit 01979f0
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/app/commands/cmd_goto_frame.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand Down
8 changes: 7 additions & 1 deletion src/app/loop_tag.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Expand Down
28 changes: 26 additions & 2 deletions src/app/ui/document_view.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
}
};

Expand Down
6 changes: 5 additions & 1 deletion src/app/ui/editor/editor_customization_delegate.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,6 +16,7 @@ namespace tools {

namespace app {
class Editor;
class FrameTagProvider;

class EditorCustomizationDelegate {
public:
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/app/ui/editor/play_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions src/app/ui/preview_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 17 additions & 0 deletions src/app/ui/timeline/timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
10 changes: 9 additions & 1 deletion src/app/ui/timeline/timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 01979f0

Please sign in to comment.