mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 03:39:51 +00:00
Continue playing animation when we scroll
This commit is contained in:
parent
91c2872908
commit
fed03e7d7b
@ -26,10 +26,14 @@ namespace app {
|
|||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
|
||||||
PlayState::PlayState()
|
PlayState::PlayState()
|
||||||
: m_playTimer(10)
|
: m_editor(nullptr)
|
||||||
|
, m_toScroll(false)
|
||||||
|
, m_playTimer(10)
|
||||||
, m_nextFrameTime(-1)
|
, m_nextFrameTime(-1)
|
||||||
, m_pingPongForward(true)
|
, m_pingPongForward(true)
|
||||||
{
|
{
|
||||||
|
m_playTimer.Tick.connect(&PlayState::onPlaybackTick, this);
|
||||||
|
|
||||||
// Hook BeforeCommandExecution signal so we know if the user wants
|
// Hook BeforeCommandExecution signal so we know if the user wants
|
||||||
// to execute other command, so we can stop the animation.
|
// to execute other command, so we can stop the animation.
|
||||||
m_ctxConn = UIContext::instance()->BeforeCommandExecution.connect(
|
m_ctxConn = UIContext::instance()->BeforeCommandExecution.connect(
|
||||||
@ -40,20 +44,31 @@ void PlayState::onAfterChangeState(Editor* editor)
|
|||||||
{
|
{
|
||||||
StateWithWheelBehavior::onAfterChangeState(editor);
|
StateWithWheelBehavior::onAfterChangeState(editor);
|
||||||
|
|
||||||
|
if (!m_editor) {
|
||||||
m_editor = editor;
|
m_editor = editor;
|
||||||
|
m_refFrame = editor->frame();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_toScroll = false;
|
||||||
m_nextFrameTime = editor->sprite()->frameDuration(editor->frame());
|
m_nextFrameTime = editor->sprite()->frameDuration(editor->frame());
|
||||||
m_curFrameTick = ui::clock();
|
m_curFrameTick = ui::clock();
|
||||||
m_pingPongForward = true;
|
m_pingPongForward = true;
|
||||||
m_refFrame = editor->frame();
|
|
||||||
|
|
||||||
m_playTimer.Tick.connect(&PlayState::onPlaybackTick, this);
|
// Maybe we came from ScrollingState and the timer is already
|
||||||
|
// running.
|
||||||
|
if (!m_playTimer.isRunning())
|
||||||
m_playTimer.start();
|
m_playTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorState::BeforeChangeAction PlayState::onBeforeChangeState(Editor* editor, EditorState* newState)
|
EditorState::BeforeChangeAction PlayState::onBeforeChangeState(Editor* editor, EditorState* newState)
|
||||||
{
|
{
|
||||||
|
if (!m_toScroll) {
|
||||||
m_editor->setFrame(m_refFrame);
|
m_editor->setFrame(m_refFrame);
|
||||||
|
|
||||||
|
// We don't stop the timer if we are going to the ScrollingState
|
||||||
|
// (we keep playing the animation).
|
||||||
m_playTimer.stop();
|
m_playTimer.stop();
|
||||||
|
}
|
||||||
return KeepState;
|
return KeepState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +87,10 @@ bool PlayState::onMouseDown(Editor* editor, MouseMessage* msg)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set this flag to indicate that we are going to ScrollingState for
|
||||||
|
// some time, so we don't change the current frame.
|
||||||
|
m_toScroll = true;
|
||||||
|
|
||||||
// Start scroll loop
|
// Start scroll loop
|
||||||
EditorStatePtr newState(new ScrollingState());
|
EditorStatePtr newState(new ScrollingState());
|
||||||
editor->setState(newState);
|
editor->setState(newState);
|
||||||
|
@ -36,6 +36,7 @@ namespace app {
|
|||||||
void onBeforeCommandExecution(Command* command);
|
void onBeforeCommandExecution(Command* command);
|
||||||
|
|
||||||
Editor* m_editor;
|
Editor* m_editor;
|
||||||
|
bool m_toScroll;
|
||||||
ui::Timer m_playTimer;
|
ui::Timer m_playTimer;
|
||||||
|
|
||||||
// Number of milliseconds to go to the next frame if m_playTimer
|
// Number of milliseconds to go to the next frame if m_playTimer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user