| 1 | // Aseprite |
| 2 | // Copyright (C) 2019-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_PIXELS_STATE_H_INCLUDED |
| 9 | #define APP_UI_EDITOR_MOVING_PIXELS_STATE_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/ui/context_bar_observer.h" |
| 13 | #include "app/ui/editor/delayed_mouse_move.h" |
| 14 | #include "app/ui/editor/editor_observer.h" |
| 15 | #include "app/ui/editor/handle_type.h" |
| 16 | #include "app/ui/editor/pixels_movement.h" |
| 17 | #include "app/ui/editor/standby_state.h" |
| 18 | #include "app/ui/status_bar.h" |
| 19 | #include "app/ui/timeline/timeline_observer.h" |
| 20 | #include "obs/connection.h" |
| 21 | #include "ui/timer.h" |
| 22 | |
| 23 | namespace doc { |
| 24 | class Image; |
| 25 | } |
| 26 | |
| 27 | namespace app { |
| 28 | class CommandExecutionEvent; |
| 29 | class Editor; |
| 30 | |
| 31 | class MovingPixelsState |
| 32 | : public StandbyState |
| 33 | , EditorObserver |
| 34 | , TimelineObserver |
| 35 | , ContextBarObserver |
| 36 | , PixelsMovementDelegate |
| 37 | , DelayedMouseMoveDelegate { |
| 38 | public: |
| 39 | MovingPixelsState(Editor* editor, |
| 40 | ui::MouseMessage* msg, |
| 41 | PixelsMovementPtr pixelsMovement, |
| 42 | HandleType handle); |
| 43 | virtual ~MovingPixelsState(); |
| 44 | |
| 45 | bool canHandleFrameChange() const { |
| 46 | return m_pixelsMovement->canHandleFrameChange(); |
| 47 | } |
| 48 | |
| 49 | void translate(const gfx::PointF& delta); |
| 50 | void rotate(double angle); |
| 51 | void flip(doc::algorithm::FlipType flipType); |
| 52 | void shift(int dx, int dy); |
| 53 | |
| 54 | void updateTransformation(const Transformation& t); |
| 55 | |
| 56 | // EditorState |
| 57 | virtual void onEnterState(Editor* editor) override; |
| 58 | virtual void onEditorGotFocus(Editor* editor) override; |
| 59 | virtual LeaveAction onLeaveState(Editor* editor, EditorState* newState) override; |
| 60 | virtual void onActiveToolChange(Editor* editor, tools::Tool* tool) override; |
| 61 | virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override; |
| 62 | virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override; |
| 63 | virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override; |
| 64 | virtual bool onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) override; |
| 65 | virtual bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override; |
| 66 | virtual bool onKeyUp(Editor* editor, ui::KeyMessage* msg) override; |
| 67 | virtual bool onUpdateStatusBar(Editor* editor) override; |
| 68 | virtual bool acceptQuickTool(tools::Tool* tool) override; |
| 69 | virtual bool requireBrushPreview() override { return false; } |
| 70 | |
| 71 | // EditorObserver |
| 72 | virtual void onDestroyEditor(Editor* editor) override; |
| 73 | virtual void onBeforeFrameChanged(Editor* editor) override; |
| 74 | virtual void onBeforeLayerChanged(Editor* editor) override; |
| 75 | |
| 76 | // TimelineObserver |
| 77 | virtual void onBeforeRangeChanged(Timeline* timeline) override; |
| 78 | |
| 79 | // ContextBarObserver |
| 80 | virtual void onDropPixels(ContextBarObserver::DropAction action) override; |
| 81 | |
| 82 | // PixelsMovementDelegate |
| 83 | virtual void onPivotChange() override; |
| 84 | |
| 85 | virtual Transformation getTransformation(Editor* editor) override; |
| 86 | |
| 87 | private: |
| 88 | // DelayedMouseMoveDelegate impl |
| 89 | void onCommitMouseMove(Editor* editor, |
| 90 | const gfx::PointF& spritePos) override; |
| 91 | |
| 92 | void onTransparentColorChange(); |
| 93 | void onRenderTimer(); |
| 94 | |
| 95 | // ContextObserver |
| 96 | void onBeforeCommandExecution(CommandExecutionEvent& ev); |
| 97 | |
| 98 | void setTransparentColor(bool opaque, const app::Color& color); |
| 99 | void dropPixels(); |
| 100 | |
| 101 | bool isActiveDocument() const; |
| 102 | bool isActiveEditor() const; |
| 103 | |
| 104 | void removeAsEditorObserver(); |
| 105 | void removePixelsMovement(); |
| 106 | |
| 107 | // Helper member to move/translate selection and pixels. |
| 108 | PixelsMovementPtr m_pixelsMovement; |
| 109 | DelayedMouseMove m_delayedMouseMove; |
| 110 | Editor* m_editor; |
| 111 | bool m_observingEditor; |
| 112 | |
| 113 | // True if the image was discarded (e.g. when a "Cut" command was |
| 114 | // used to remove the dragged image). |
| 115 | bool m_discarded; |
| 116 | |
| 117 | ui::Timer m_renderTimer; |
| 118 | |
| 119 | obs::connection m_ctxConn; |
| 120 | obs::connection m_opaqueConn; |
| 121 | obs::connection m_transparentConn; |
| 122 | }; |
| 123 | |
| 124 | } // namespace app |
| 125 | |
| 126 | #endif // APP_UI_EDITOR_MOVING_PIXELS_STATE_H_INCLUDED |
| 127 | |