1// Aseprite
2// Copyright (C) 2020-2021 Igara Studio S.A.
3// Copyright (C) 2001-2017 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_UI_EDITOR_PLAY_STATE_H_INCLUDED
9#define APP_UI_EDITOR_PLAY_STATE_H_INCLUDED
10#pragma once
11
12#include "app/ui/editor/state_with_wheel_behavior.h"
13#include "base/time.h"
14#include "doc/frame.h"
15#include "obs/connection.h"
16#include "ui/timer.h"
17
18namespace doc {
19 class Tag;
20}
21
22namespace app {
23
24 class CommandExecutionEvent;
25
26 class PlayState : public StateWithWheelBehavior {
27 public:
28 PlayState(const bool playOnce,
29 const bool playAll);
30
31 doc::Tag* playingTag() const;
32
33 void onEnterState(Editor* editor) override;
34 LeaveAction onLeaveState(Editor* editor, EditorState* newState) override;
35 void onBeforePopState(Editor* editor) override;
36 bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
37 bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
38 bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
39 bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override;
40 bool onKeyUp(Editor* editor, ui::KeyMessage* msg) override;
41 bool onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) override;
42 void onRemoveTag(Editor* editor, doc::Tag* tag) override;
43
44 private:
45 void onPlaybackTick();
46
47 // ContextObserver
48 void onBeforeCommandExecution(CommandExecutionEvent& ev);
49
50 double getNextFrameTime();
51
52 Editor* m_editor;
53 bool m_playOnce;
54 bool m_playAll;
55 bool m_toScroll;
56 ui::Timer m_playTimer;
57
58 // Number of milliseconds to go to the next frame if m_playTimer
59 // is activated.
60 double m_nextFrameTime;
61 base::tick_t m_curFrameTick;
62
63 bool m_pingPongForward;
64 doc::frame_t m_refFrame;
65 doc::Tag* m_tag;
66
67 obs::scoped_connection m_ctxConn;
68 };
69
70} // namespace app
71
72#endif
73