Jeremy Bullock e122a9
#pragma once
Jeremy Bullock e122a9
Jeremy Bullock e122a9
#ifndef FILLTOOL_H
Jeremy Bullock e122a9
#define FILLTOOL_H
Jeremy Bullock e122a9
Jeremy Bullock e122a9
// TnzCore includes
Jeremy Bullock e122a9
#include "tproperty.h"
Jeremy Bullock e122a9
#include "toonz/txshlevelhandle.h"
Jeremy Bullock e122a9
#include "toonz/txshsimplelevel.h"
Jeremy Bullock e122a9
#include "toonz/strokegenerator.h"
Jeremy Bullock e122a9
// TnzTools includes
Jeremy Bullock e122a9
#include "tools/tool.h"
Jeremy Bullock e122a9
#include "tools/toolutils.h"
Jeremy Bullock e122a9
#include "autofill.h"
Jeremy Bullock e122a9
#include "toonz/fill.h"
Jeremy Bullock e122a9
Jeremy Bullock e122a9
#include <qobject></qobject>
Jeremy Bullock e122a9
Jeremy Bullock e122a9
#define LINES L"Lines"
Jeremy Bullock e122a9
#define AREAS L"Areas"
Jeremy Bullock e122a9
#define ALL L"Lines & Areas"
Jeremy Bullock e122a9
Jeremy Bullock e122a9
class NormalLineFillTool;
Jeremy Bullock e122a9
namespace {
Jeremy Bullock e122a9
class AreaFillTool {
Jeremy Bullock e122a9
public:
justburner 8221ad
  enum Type { RECT, FREEHAND, POLYLINE, FREEPICK };
Jeremy Bullock e122a9
Jeremy Bullock e122a9
private:
Jeremy Bullock e122a9
  bool m_frameRange;
Jeremy Bullock e122a9
  bool m_onlyUnfilled;
Jeremy Bullock e122a9
  Type m_type;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  bool m_selecting;
Jeremy Bullock e122a9
  TRectD m_selectingRect;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  TRectD m_firstRect;
Jeremy Bullock e122a9
  bool m_firstFrameSelected;
Jeremy Bullock e122a9
  TXshSimpleLevelP m_level;
Jeremy Bullock e122a9
  TFrameId m_firstFrameId, m_veryFirstFrameId;
Jeremy Bullock e122a9
  TTool *m_parent;
Jeremy Bullock e122a9
  std::wstring m_colorType;
Jeremy Bullock e122a9
  std::pair<int, int=""> m_currCell;</int,>
Jeremy Bullock e122a9
  StrokeGenerator m_track;
Jeremy Bullock e122a9
  std::vector<tpointd> m_polyline;</tpointd>
Jeremy Bullock e122a9
  bool m_isPath;
Jeremy Bullock e122a9
  bool m_active;
Jeremy Bullock e122a9
  bool m_enabled;
Jeremy Bullock e122a9
  double m_thick;
Jeremy Bullock e122a9
  TPointD m_firstPos;
Jeremy Bullock e122a9
  TStroke *m_firstStroke;
Jeremy Bullock e122a9
  TPointD m_mousePosition;
Jeremy Bullock e122a9
  bool m_onion;
Jeremy Bullock e122a9
  bool m_isLeftButtonPressed;
Jeremy Bullock e122a9
  bool m_autopaintLines;
Jeremy Bullock e122a9
justburner 8221ad
  int m_bckStyleId;
justburner 8221ad
Jeremy Bullock e122a9
public:
Jeremy Bullock e122a9
  AreaFillTool(TTool *Parent);
Jeremy Bullock e122a9
  void draw();
justburner 8221ad
  int pick(const TImageP &image, const TPointD &pos, const int frame, int mode);
Jeremy Bullock e122a9
  void resetMulti();
Jeremy Bullock e122a9
  void leftButtonDown(const TPointD &pos, const TMouseEvent &, TImage *img);
Jeremy Bullock e122a9
  void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e);
Jeremy Bullock e122a9
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
Jeremy Bullock e122a9
  void mouseMove(const TPointD &pos, const TMouseEvent &e);
Jeremy Bullock e122a9
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e);
Jeremy Bullock e122a9
  void onImageChanged();
Jeremy Bullock e122a9
  bool onPropertyChanged(bool multi, bool onlyUnfilled, bool onion, Type type,
Jeremy Bullock e122a9
                         std::wstring colorType, bool autopaintLines);
Jeremy Bullock e122a9
  void onActivate();
Jeremy Bullock e122a9
  void onEnter();
Jeremy Bullock e122a9
};
shun-iwasawa 2d0135
}  // namespace
Jeremy Bullock e122a9
class FillTool final : public QObject, public TTool {
Jeremy Bullock e122a9
  // Q_DECLARE_TR_FUNCTIONS(FillTool)
Jeremy Bullock e122a9
  Q_OBJECT
Jeremy Bullock e122a9
  bool m_firstTime;
Jeremy Bullock e122a9
  TPointD m_firstPoint, m_clickPoint;
Jeremy Bullock e122a9
  bool m_firstClick;
Jeremy Bullock e122a9
  bool m_frameSwitched             = false;
Jeremy Bullock e122a9
  double m_changedGapOriginalValue = -1.0;
Jeremy Bullock e122a9
  TXshSimpleLevelP m_level;
Jeremy Bullock e122a9
  TFrameId m_firstFrameId, m_veryFirstFrameId;
Jeremy Bullock e122a9
  int m_onionStyleId;
Jeremy Bullock e122a9
  TEnumProperty m_colorType;  // Line, Area
Jeremy Bullock e122a9
  TEnumProperty m_fillType;   // Rect, Polyline etc.
Jeremy Bullock e122a9
  TBoolProperty m_onion;
Jeremy Bullock e122a9
  TBoolProperty m_frameRange;
Jeremy Bullock e122a9
  TBoolProperty m_selective;
Jeremy Bullock e122a9
  TDoublePairProperty m_fillDepth;
Jeremy Bullock e122a9
  TBoolProperty m_segment;
Jeremy Bullock e122a9
  TDoubleProperty m_maxGapDistance;
Jeremy Bullock e122a9
  AreaFillTool *m_rectFill;
Jeremy Bullock e122a9
  NormalLineFillTool *m_normalLineFillTool;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  TPropertyGroup m_prop;
Jeremy Bullock e122a9
  std::pair<int, int=""> m_currCell;</int,>
Jeremy Bullock e122a9
  std::vector<tfilledregioninf> m_oldFillInformation;</tfilledregioninf>
Jeremy Bullock e122a9
#ifdef _DEBUG
Jeremy Bullock e122a9
  std::vector<trect> m_rects;</trect>
Jeremy Bullock e122a9
#endif
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  // For the raster fill tool, autopaint lines is optional and can be temporary
Jeremy Bullock e122a9
  // disabled
Jeremy Bullock e122a9
  TBoolProperty m_autopaintLines;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
public:
Jeremy Bullock e122a9
  FillTool(int targetType);
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  ToolType getToolType() const override { return TTool::LevelWriteTool; }
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  void updateTranslation() override;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  FillParameters getFillParameters() const;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
Jeremy Bullock e122a9
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
Jeremy Bullock e122a9
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
Jeremy Bullock e122a9
  void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
Jeremy Bullock e122a9
  void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e) override;
Jeremy Bullock e122a9
  void resetMulti();
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  bool onPropertyChanged(std::string propertyName) override;
Jeremy Bullock e122a9
  void onImageChanged() override;
Jeremy Bullock e122a9
  void draw() override;
Jeremy Bullock e122a9
shun-iwasawa 2d0135
  // if frame = -1 it uses current frame
shun-iwasawa 2d0135
  int pick(const TImageP &image, const TPointD &pos, const int frame = -1);
Jeremy Bullock e122a9
  int pickOnionColor(const TPointD &pos);
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  void onEnter() override;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  void onActivate() override;
Jeremy Bullock e122a9
  void onDeactivate() override;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  int getCursorId() const override;
Jeremy Bullock e122a9
Jeremy Bullock e122a9
  int getColorClass() const { return 2; }
Jeremy Bullock e122a9
public slots:
Jeremy Bullock e122a9
  void onFrameSwitched() override;
Jeremy Bullock e122a9
};
Jeremy Bullock e122a9
Jeremy Bullock e122a9
#endif  // FILLTOOL_H