| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2021-2022 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_MOVING_CEL_STATE_H_INCLUDED |
| 9 | #define APP_UI_EDITOR_MOVING_CEL_STATE_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/ui/editor/standby_state.h" |
| 13 | |
| 14 | #include "app/context_access.h" |
| 15 | #include "app/ui/editor/delayed_mouse_move.h" |
| 16 | #include "app/ui/editor/handle_type.h" |
| 17 | #include "doc/cel_list.h" |
| 18 | |
| 19 | #include <vector> |
| 20 | |
| 21 | namespace doc { |
| 22 | class Cel; |
| 23 | } |
| 24 | |
| 25 | namespace app { |
| 26 | class Editor; |
| 27 | |
| 28 | class MovingCelCollect { |
| 29 | public: |
| 30 | MovingCelCollect(Editor* editor, Layer* layer); |
| 31 | |
| 32 | bool empty() const { return m_celList.empty(); } |
| 33 | |
| 34 | Cel* mainCel() const { return m_mainCel; } |
| 35 | const CelList& celList() const { return m_celList; } |
| 36 | |
| 37 | private: |
| 38 | Cel* m_mainCel; |
| 39 | CelList m_celList; |
| 40 | }; |
| 41 | |
| 42 | class MovingCelState : public StandbyState |
| 43 | , DelayedMouseMoveDelegate { |
| 44 | public: |
| 45 | MovingCelState(Editor* editor, |
| 46 | const ui::MouseMessage* msg, |
| 47 | const HandleType handle, |
| 48 | const MovingCelCollect& collect); |
| 49 | |
| 50 | virtual void onBeforePopState(Editor* editor) override; |
| 51 | virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override; |
| 52 | virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override; |
| 53 | virtual bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override; |
| 54 | virtual bool onUpdateStatusBar(Editor* editor) override; |
| 55 | |
| 56 | virtual bool requireBrushPreview() override { return false; } |
| 57 | |
| 58 | private: |
| 59 | gfx::Point intCelOffset() const; |
| 60 | gfx::RectF calcFullBounds() const; |
| 61 | bool restoreCelStartPosition() const; |
| 62 | // ContextObserver |
| 63 | void onBeforeCommandExecution(CommandExecutionEvent& ev); |
| 64 | |
| 65 | // DelayedMouseMoveDelegate impl |
| 66 | void onCommitMouseMove(Editor* editor, |
| 67 | const gfx::PointF& spritePos) override; |
| 68 | |
| 69 | ContextReader m_reader; |
| 70 | DelayedMouseMove m_delayedMouseMove; |
| 71 | Cel* m_cel; |
| 72 | CelList m_celList; |
| 73 | std::vector<gfx::RectF> m_celStarts; |
| 74 | gfx::PointF m_cursorStart; |
| 75 | gfx::PointF m_celOffset; |
| 76 | gfx::SizeF m_celMainSize; |
| 77 | gfx::SizeF m_celScale; |
| 78 | bool m_maskVisible; |
| 79 | bool m_hasReference = false; |
| 80 | bool m_moved = false; |
| 81 | bool m_scaled = false; |
| 82 | HandleType m_handle; |
| 83 | Editor* m_editor; |
| 84 | |
| 85 | obs::scoped_connection m_ctxConn; |
| 86 | }; |
| 87 | |
| 88 | } // namespace app |
| 89 | |
| 90 | #endif // APP_UI_EDITOR_MOVING_CEL_STATE_H_INCLUDED |
| 91 |