1// Aseprite
2// Copyright (C) 2022 Igara Studio S.A.
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifndef APP_UI_EDITOR_DRAGGING_VALUE_STATE_H_INCLUDED
8#define APP_UI_EDITOR_DRAGGING_VALUE_STATE_H_INCLUDED
9#pragma once
10
11#include "app/ui/editor/state_with_wheel_behavior.h"
12#include "app/ui/key.h"
13#include "gfx/point.h"
14#include "obs/connection.h"
15#include "render/zoom.h"
16
17namespace app {
18 class CommandExecutionEvent;
19
20 class DraggingValueState : public StateWithWheelBehavior {
21 public:
22 DraggingValueState(Editor* editor, const Keys& keys);
23
24 bool isTemporalState() const override { return true; }
25 void onBeforePopState(Editor* editor) override;
26 bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
27 bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
28 bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
29 bool onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) override;
30 bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override;
31 bool onKeyUp(Editor* editor, ui::KeyMessage* msg) override;
32 bool onUpdateStatusBar(Editor* editor) override;
33
34 bool requireBrushPreview() override { return true; }
35
36 private:
37 void onBeforeCommandExecution(CommandExecutionEvent& ev);
38 Color initialFgColor() const override { return m_fgColor; }
39 Color initialBgColor() const override { return m_initialBgColor; }
40 int initialFgTileIndex() const override { return m_initialFgTileIndex; }
41 int initialBgTileIndex() const override { return m_initialBgTileIndex; }
42 int initialBrushSize() override { return m_initialBrushSize; }
43 int initialBrushAngle() override { return m_initialBrushAngle; }
44 gfx::Point initialScroll(Editor* editor) const override { return m_initialScroll; }
45 render::Zoom initialZoom(Editor* editor) const override { return m_initialZoom; }
46 doc::frame_t initialFrame(Editor* editor) const override { return m_initialFrame; }
47 doc::layer_t initialLayer(Editor* editor) const override { return m_initialLayer; }
48 tools::InkType initialInkType(Editor* editor) const override { return m_initialInkType; }
49 int initialInkOpacity(Editor* editor) const override { return m_initialInkOpacity; }
50 int initialCelOpacity(Editor* editor) const override { return m_initialCelOpacity; }
51 int initialLayerOpacity(Editor* editor) const override { return m_initialLayerOpacity; }
52 tools::Tool* initialTool() const override { return m_initialTool; }
53 void changeFgColor(Color c) override;
54
55 tools::Tool* getInitialToolInActiveGroup() override;
56 void onToolChange(tools::Tool* tool) override;
57 void onToolGroupChange(Editor* editor,
58 tools::ToolGroup* group) override;
59
60 Editor* m_editor;
61 Keys m_keys;
62 gfx::Point m_initialPos;
63 gfx::Point m_initialPosSameGroup;
64
65 Color m_initialFgColor;
66 Color m_initialBgColor;
67 int m_initialFgTileIndex;
68 int m_initialBgTileIndex;
69 int m_initialBrushSize;
70 int m_initialBrushAngle;
71 gfx::Point m_initialScroll;
72 render::Zoom m_initialZoom;
73 doc::frame_t m_initialFrame;
74 doc::layer_t m_initialLayer;
75 tools::InkType m_initialInkType;
76 int m_initialInkOpacity;
77 int m_initialCelOpacity;
78 int m_initialLayerOpacity;
79 tools::Tool* m_initialTool;
80
81 // Used to allow multiple modifications to the same initial FG
82 // color (m_initialFgColor), e.g. when multiples Key will change
83 // different elements of the color (e.g. Value and Saturation) at
84 // the same time with different DragVectors/axes.
85 Color m_fgColor;
86
87 obs::scoped_connection m_beforeCmdConn;
88 };
89
90} // namespace app
91
92#endif // APP_UI_EDITOR_ZOOMING_STATE_H_INCLUDED
93