1 #pragma once
2 
3 #ifndef FILLTOOL_H
4 #define FILLTOOL_H
5 
6 // TnzCore includes
7 #include "tproperty.h"
8 #include "toonz/txshlevelhandle.h"
9 #include "toonz/txshsimplelevel.h"
10 #include "toonz/strokegenerator.h"
11 // TnzTools includes
12 #include "tools/tool.h"
13 #include "tools/toolutils.h"
14 #include "autofill.h"
15 #include "toonz/fill.h"
16 
17 #include <QObject>
18 
19 #define LINES L"Lines"
20 #define AREAS L"Areas"
21 #define ALL L"Lines & Areas"
22 
23 class NormalLineFillTool;
24 namespace {
25 class AreaFillTool {
26 public:
27   enum Type { RECT, FREEHAND, POLYLINE };
28 
29 private:
30   bool m_frameRange;
31   bool m_onlyUnfilled;
32   Type m_type;
33 
34   bool m_selecting;
35   TRectD m_selectingRect;
36 
37   TRectD m_firstRect;
38   bool m_firstFrameSelected;
39   TXshSimpleLevelP m_level;
40   TFrameId m_firstFrameId, m_veryFirstFrameId;
41   TTool *m_parent;
42   std::wstring m_colorType;
43   std::pair<int, int> m_currCell;
44   StrokeGenerator m_track;
45   std::vector<TPointD> m_polyline;
46   bool m_isPath;
47   bool m_active;
48   bool m_enabled;
49   double m_thick;
50   TPointD m_firstPos;
51   TStroke *m_firstStroke;
52   TPointD m_mousePosition;
53   bool m_onion;
54   bool m_isLeftButtonPressed;
55   bool m_autopaintLines;
56 
57 public:
58   AreaFillTool(TTool *Parent);
59   void draw();
60   void resetMulti();
61   void leftButtonDown(const TPointD &pos, const TMouseEvent &, TImage *img);
62   void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e);
63   void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
64   void mouseMove(const TPointD &pos, const TMouseEvent &e);
65   void leftButtonUp(const TPointD &pos, const TMouseEvent &e);
66   void onImageChanged();
67   bool onPropertyChanged(bool multi, bool onlyUnfilled, bool onion, Type type,
68                          std::wstring colorType, bool autopaintLines);
69   void onActivate();
70   void onEnter();
71 };
72 }  // namespace
73 class FillTool final : public QObject, public TTool {
74   // Q_DECLARE_TR_FUNCTIONS(FillTool)
75   Q_OBJECT
76   bool m_firstTime;
77   TPointD m_firstPoint, m_clickPoint;
78   bool m_firstClick;
79   bool m_frameSwitched             = false;
80   double m_changedGapOriginalValue = -1.0;
81   TXshSimpleLevelP m_level;
82   TFrameId m_firstFrameId, m_veryFirstFrameId;
83   int m_onionStyleId;
84   TEnumProperty m_colorType;  // Line, Area
85   TEnumProperty m_fillType;   // Rect, Polyline etc.
86   TBoolProperty m_onion;
87   TBoolProperty m_frameRange;
88   TBoolProperty m_selective;
89   TDoublePairProperty m_fillDepth;
90   TBoolProperty m_segment;
91   TDoubleProperty m_maxGapDistance;
92   AreaFillTool *m_rectFill;
93   NormalLineFillTool *m_normalLineFillTool;
94 
95   TPropertyGroup m_prop;
96   std::pair<int, int> m_currCell;
97   std::vector<TFilledRegionInf> m_oldFillInformation;
98 #ifdef _DEBUG
99   std::vector<TRect> m_rects;
100 #endif
101 
102   // For the raster fill tool, autopaint lines is optional and can be temporary
103   // disabled
104   TBoolProperty m_autopaintLines;
105 
106 public:
107   FillTool(int targetType);
108 
getToolType()109   ToolType getToolType() const override { return TTool::LevelWriteTool; }
110 
111   void updateTranslation() override;
112 
getProperties(int targetType)113   TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
114 
115   FillParameters getFillParameters() const;
116 
117   void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
118   void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
119   void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
120   void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
121   void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e) override;
122   void resetMulti();
123 
124   bool onPropertyChanged(std::string propertyName) override;
125   void onImageChanged() override;
126   void draw() override;
127 
128   // if frame = -1 it uses current frame
129   int pick(const TImageP &image, const TPointD &pos, const int frame = -1);
130   int pickOnionColor(const TPointD &pos);
131 
132   void onEnter() override;
133 
134   void onActivate() override;
135   void onDeactivate() override;
136 
137   int getCursorId() const override;
138 
getColorClass()139   int getColorClass() const { return 2; }
140 public slots:
141   void onFrameSwitched() override;
142 };
143 
144 #endif  // FILLTOOL_H
145