1 | // Aseprite |
2 | // Copyright (C) 2019-2022 Igara Studio S.A. |
3 | // Copyright (C) 2001-2018 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_STANDBY_STATE_H_INCLUDED |
9 | #define APP_UI_EDITOR_STANDBY_STATE_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "app/transformation.h" |
13 | #include "app/ui/editor/editor_decorator.h" |
14 | #include "app/ui/editor/handle_type.h" |
15 | #include "app/ui/editor/state_with_wheel_behavior.h" |
16 | #include "doc/algorithm/flip_type.h" |
17 | #include "obs/connection.h" |
18 | |
19 | namespace app { |
20 | namespace tools { |
21 | class Ink; |
22 | class Pointer; |
23 | } |
24 | |
25 | class DrawingState; |
26 | class TransformHandles; |
27 | |
28 | class StandbyState : public StateWithWheelBehavior { |
29 | public: |
30 | enum class DrawingType { Regular, LineFreehand, SelectTiles }; |
31 | |
32 | StandbyState(); |
33 | virtual ~StandbyState(); |
34 | virtual void onEnterState(Editor* editor) override; |
35 | virtual void onActiveToolChange(Editor* editor, tools::Tool* tool) override; |
36 | virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override; |
37 | virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override; |
38 | virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override; |
39 | virtual bool onDoubleClick(Editor* editor, ui::MouseMessage* msg) override; |
40 | virtual bool onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) override; |
41 | virtual bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override; |
42 | virtual bool onKeyUp(Editor* editor, ui::KeyMessage* msg) override; |
43 | virtual bool onUpdateStatusBar(Editor* editor) override; |
44 | |
45 | // Returns true as the standby state is the only one which shows |
46 | // the brush-preview. |
47 | virtual bool requireBrushPreview() override { return true; } |
48 | |
49 | // Layer edges and cel guides are allowed to be drawn. |
50 | virtual bool allowLayerEdges() override { return true; } |
51 | |
52 | virtual Transformation getTransformation(Editor* editor); |
53 | |
54 | void startSelectionTransformation(Editor* editor, const gfx::Point& move, double angle); |
55 | |
56 | void startFlipTransformation(Editor* editor, doc::algorithm::FlipType flipType); |
57 | |
58 | protected: |
59 | void callEyedropper(Editor* editor, const ui::MouseMessage* msg); |
60 | bool checkStartDrawingStraightLine(Editor* editor, |
61 | const ui::MouseMessage* msg, |
62 | const tools::Pointer* pointer); |
63 | virtual bool canCheckStartDrawingStraightLine() { return true; } |
64 | |
65 | class Decorator : public EditorDecorator { |
66 | public: |
67 | struct Handle { |
68 | int align; |
69 | gfx::Rect bounds; |
70 | Handle(int align, const gfx::Rect& bounds) |
71 | : align(align), bounds(bounds) { } |
72 | }; |
73 | typedef std::vector<Handle> Handles; |
74 | |
75 | Decorator(StandbyState* standbyState); |
76 | virtual ~Decorator(); |
77 | |
78 | TransformHandles* getTransformHandles(Editor* editor); |
79 | bool getSymmetryHandles(Editor* editor, Handles& handles); |
80 | |
81 | bool onSetCursor(tools::Ink* ink, Editor* editor, const gfx::Point& mouseScreenPos); |
82 | |
83 | // EditorDecorator overrides |
84 | void postRenderDecorator(EditorPostRender* render) override; |
85 | void getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) override; |
86 | |
87 | private: |
88 | TransformHandles* m_transfHandles; |
89 | StandbyState* m_standbyState; |
90 | }; |
91 | |
92 | private: |
93 | DrawingState* startDrawingState(Editor* editor, |
94 | const ui::MouseMessage* msg, |
95 | const DrawingType drawingType, |
96 | const tools::Pointer& pointer); |
97 | void transformSelection(Editor* editor, ui::MouseMessage* msg, HandleType handle); |
98 | void onPivotChange(Editor* editor); |
99 | gfx::Rect resizeCelBounds(Editor* editor) const; |
100 | bool overSelectionEdges(Editor* editor, const gfx::Point& mouseScreenPos) const; |
101 | void selectTile(Editor* editor); |
102 | |
103 | Decorator* m_decorator; |
104 | obs::scoped_connection m_pivotVisConn; |
105 | obs::scoped_connection m_pivotPosConn; |
106 | bool m_transformSelectionHandlesAreVisible; |
107 | }; |
108 | |
109 | } // namespace app |
110 | |
111 | #endif // APP_UI_EDITOR_STANDBY_STATE_H_INCLUDED |
112 | |