shun-iwasawa 98926d
#pragma once
shun-iwasawa 98926d
shun-iwasawa 98926d
#ifndef TOONZVECTORBRUSHTOOL_H
shun-iwasawa 98926d
#define TOONZVECTORBRUSHTOOL_H
shun-iwasawa 98926d
02850b
#include <tgeometry.h></tgeometry.h>
02850b
#include <tproperty.h></tproperty.h>
02850b
#include <trasterimage.h></trasterimage.h>
02850b
#include <ttoonzimage.h></ttoonzimage.h>
02850b
#include <tstroke.h></tstroke.h>
02850b
#include <toonz strokegenerator.h=""></toonz>
shun-iwasawa 98926d
02850b
#include <tools tool.h=""></tools>
02850b
#include <tools cursors.h=""></tools>
shun-iwasawa 98926d
ebedef
#include <tools inputmanager.h=""></tools>
ebedef
#include <tools modifierline.h="" modifiers=""></tools>
ebedef
#include <tools modifiers="" modifiertangents.h=""></tools>
ebedef
#include <tools modifierassistants.h="" modifiers=""></tools>
ebedef
#include <tools modifiers="" modifiersegmentation.h=""></tools>
ebedef
#include <tools modifiers="" modifiersimplify.h=""></tools>
ebedef
#include <tools modifiers="" modifiersmooth.h=""></tools>
ebedef
#ifndef NDEBUG
ebedef
#include <tools modifiers="" modifiertest.h=""></tools>
ebedef
#endif
ebedef
shun-iwasawa 98926d
#include <qcoreapplication></qcoreapplication>
shun-iwasawa 98926d
#include <qradialgradient></qradialgradient>
shun-iwasawa 98926d
shun-iwasawa 98926d
//--------------------------------------------------------------
shun-iwasawa 98926d
shun-iwasawa 98926d
//  Forward declarations
shun-iwasawa 98926d
shun-iwasawa 98926d
class TTileSetCM32;
shun-iwasawa 98926d
class TTileSaverCM32;
shun-iwasawa 98926d
class RasterStrokeGenerator;
shun-iwasawa 98926d
class BluredBrush;
shun-iwasawa 98926d
shun-iwasawa 98926d
//--------------------------------------------------------------
shun-iwasawa 98926d
shun-iwasawa 98926d
//************************************************************************
shun-iwasawa 98926d
//    Brush Data declaration
shun-iwasawa 98926d
//************************************************************************
shun-iwasawa 98926d
shun-iwasawa 98926d
struct VectorBrushData final : public TPersist {
shun-iwasawa 98926d
  PERSIST_DECLARATION(VectorBrushData)
shun-iwasawa 98926d
  // frameRange, snapSensitivity and snap are not included
shun-iwasawa 98926d
  // Those options are not really a part of the brush settings,
shun-iwasawa 98926d
  // just the overall tool.
shun-iwasawa 98926d
shun-iwasawa 98926d
  std::wstring m_name;
shun-iwasawa 98926d
  double m_min, m_max, m_acc, m_smooth;
shun-iwasawa 98926d
  bool m_breakAngles, m_pressure;
shun-iwasawa 98926d
  int m_cap, m_join, m_miter;
shun-iwasawa 98926d
shun-iwasawa 98926d
  VectorBrushData();
shun-iwasawa 98926d
  VectorBrushData(const std::wstring &name);
shun-iwasawa 98926d
shun-iwasawa 98926d
  bool operator<(const VectorBrushData &other) const {
shun-iwasawa 98926d
    return m_name < other.m_name;
shun-iwasawa 98926d
  }
shun-iwasawa 98926d
shun-iwasawa 98926d
  void saveData(TOStream &os) override;
shun-iwasawa 98926d
  void loadData(TIStream &is) override;
shun-iwasawa 98926d
};
shun-iwasawa 98926d
shun-iwasawa 98926d
//************************************************************************
shun-iwasawa 98926d
//    Brush Preset Manager declaration
shun-iwasawa 98926d
//************************************************************************
shun-iwasawa 98926d
shun-iwasawa 98926d
class VectorBrushPresetManager {
shun-iwasawa 98926d
  TFilePath m_fp;                       //!< Presets file path
shun-iwasawa 98926d
  std::set<vectorbrushdata> m_presets;  //!< Current presets container</vectorbrushdata>
shun-iwasawa 98926d
shun-iwasawa 98926d
public:
shun-iwasawa 98926d
  VectorBrushPresetManager() {}
shun-iwasawa 98926d
shun-iwasawa 98926d
  void load(const TFilePath &fp);
shun-iwasawa 98926d
  void save();
shun-iwasawa 98926d
shun-iwasawa 98926d
  const TFilePath &path() { return m_fp; };
shun-iwasawa 98926d
  const std::set<vectorbrushdata> &presets() const { return m_presets; }</vectorbrushdata>
shun-iwasawa 98926d
shun-iwasawa 98926d
  void addPreset(const VectorBrushData &data);
shun-iwasawa 98926d
  void removePreset(const std::wstring &name);
shun-iwasawa 98926d
};
shun-iwasawa 98926d
shun-iwasawa 98926d
//************************************************************************
shun-iwasawa 98926d
//    Brush Tool declaration
shun-iwasawa 98926d
//************************************************************************
shun-iwasawa 98926d
ebedef
class ToonzVectorBrushTool final : public TTool,
ebedef
                                   public TInputHandler
ebedef
{
shun-iwasawa 085210
  Q_DECLARE_TR_FUNCTIONS(ToonzVectorBrushTool)
shun-iwasawa 98926d
shun-iwasawa 98926d
public:
shun-iwasawa 98926d
  ToonzVectorBrushTool(std::string name, int targetType);
shun-iwasawa 98926d
shun-iwasawa 98926d
  ToolType getToolType() const override { return TTool::LevelWriteTool; }
shun-iwasawa 98926d
shun-iwasawa 98926d
  ToolOptionsBox *createOptionsBox() override;
shun-iwasawa 98926d
shun-iwasawa 98926d
  void updateTranslation() override;
shun-iwasawa 98926d
shun-iwasawa 98926d
  void onActivate() override;
shun-iwasawa 98926d
  void onDeactivate() override;
shun-iwasawa 98926d
shun-iwasawa 98926d
  bool preLeftButtonDown() override;
shun-iwasawa 98926d
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
shun-iwasawa 98926d
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
shun-iwasawa 98926d
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
shun-iwasawa 98926d
  void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
shun-iwasawa 98926d
  bool keyDown(QKeyEvent *event) override;
shun-iwasawa 98926d
ebedef
  void inputMouseMove(const TPointD &position,
ebedef
                      const TInputState &state) override;
ebedef
  void inputSetBusy(bool busy) override;
ebedef
  void inputPaintTracks(const TTrackList &tracks) override;
ebedef
  void inputInvalidateRect(const TRectD &bounds) override { invalidate(bounds); }
ebedef
  TTool *inputGetTool() override { return this; };
ebedef
shun-iwasawa 98926d
  void draw() override;
shun-iwasawa 98926d
shun-iwasawa 98926d
  void onEnter() override;
shun-iwasawa 98926d
  void onLeave() override;
shun-iwasawa 98926d
manongjohn 40a40e
  int getCursorId() const override {
manongjohn 40a40e
    if (m_viewer && m_viewer->getGuidedStrokePickerMode())
manongjohn 40a40e
      return m_viewer->getGuidedStrokePickerCursor();
manongjohn 40a40e
    return ToolCursor::PenCursor;
manongjohn 40a40e
  }
shun-iwasawa 98926d
shun-iwasawa 98926d
  TPropertyGroup *getProperties(int targetType) override;
shun-iwasawa 98926d
  bool onPropertyChanged(std::string propertyName) override;
shun-iwasawa 98926d
  void resetFrameRange();
shun-iwasawa 98926d
shun-iwasawa 98926d
  void initPresets();
shun-iwasawa 98926d
  void loadPreset();
shun-iwasawa 98926d
  void addPreset(QString name);
shun-iwasawa 98926d
  void removePreset();
shun-iwasawa 98926d
manongjohn df5842
  void loadLastBrush();
manongjohn df5842
shun-iwasawa 98926d
  // return true if the pencil mode is active in the Brush / PaintBrush / Eraser
shun-iwasawa 98926d
  // Tools.
shun-iwasawa 98926d
  bool isPencilModeActive() override;
shun-iwasawa 98926d
shun-iwasawa 98926d
  bool doFrameRangeStrokes(TFrameId firstFrameId, TStroke *firstStroke,
shun-iwasawa 98926d
                           TFrameId lastFrameId, TStroke *lastStroke,
manongjohn 40a40e
                           int interpolationType, bool breakAngles,
manongjohn 40a40e
                           bool autoGroup = false, bool autoFill = false,
manongjohn 40a40e
                           bool drawFirstStroke = true,
manongjohn 40a40e
                           bool drawLastStroke = true, bool withUndo = true);
manongjohn 40a40e
  bool doGuidedAutoInbetween(TFrameId cFid, const TVectorImageP &cvi,
manongjohn 40a40e
                             TStroke *cStroke, bool breakAngles,
manongjohn 40a40e
                             bool autoGroup = false, bool autoFill = false,
manongjohn 40a40e
                             bool drawStroke = true);
shun-iwasawa 98926d
398cd8
protected:
398cd8
  void snap(const TPointD &pos, bool snapEnabled, bool withSelfSnap = false);
398cd8
ebedef
  enum MouseEventType { ME_DOWN, ME_DRAG, ME_UP, ME_MOVE };
ebedef
  void handleMouseEvent(MouseEventType type, const TPointD &pos,
ebedef
                        const TMouseEvent &e);
ebedef
shun-iwasawa 98926d
protected:
shun-iwasawa 98926d
  TPropertyGroup m_prop[2];
shun-iwasawa 98926d
shun-iwasawa 98926d
  TDoublePairProperty m_thickness;
shun-iwasawa 98926d
  TDoubleProperty m_accuracy;
shun-iwasawa 98926d
  TDoubleProperty m_smooth;
shun-iwasawa 98926d
  TEnumProperty m_preset;
shun-iwasawa 98926d
  TBoolProperty m_breakAngles;
shun-iwasawa 98926d
  TBoolProperty m_pressure;
shun-iwasawa 98926d
  TBoolProperty m_snap;
shun-iwasawa 98926d
  TEnumProperty m_frameRange;
shun-iwasawa 98926d
  TEnumProperty m_snapSensitivity;
shun-iwasawa 98926d
  TEnumProperty m_capStyle;
shun-iwasawa 98926d
  TEnumProperty m_joinStyle;
shun-iwasawa 98926d
  TIntProperty m_miterJoinLimit;
0d5555
  TBoolProperty m_assistants;
shun-iwasawa 98926d
ebedef
  TInputManager m_inputmanager;
ebedef
  TSmartPointerT<tmodifierline> m_modifierLine;</tmodifierline>
ebedef
  TSmartPointerT<tmodifiertangents> m_modifierTangents;</tmodifiertangents>
ebedef
  TSmartPointerT<tmodifierassistants> m_modifierAssistants;</tmodifierassistants>
ebedef
  TSmartPointerT<tmodifiersegmentation> m_modifierSegmentation;</tmodifiersegmentation>
ebedef
  TSmartPointerT<tmodifiersegmentation> m_modifierSmoothSegmentation;</tmodifiersegmentation>
ebedef
  TSmartPointerT<tmodifiersmooth> m_modifierSmooth[3];</tmodifiersmooth>
ebedef
  TSmartPointerT<tmodifiersimplify> m_modifierSimplify;</tmodifiersimplify>
ebedef
#ifndef NDEBUG
ebedef
  TSmartPointerT<tmodifiertest> m_modifierTest;</tmodifiertest>
ebedef
#endif
ebedef
shun-iwasawa 98926d
  StrokeGenerator m_track;
shun-iwasawa 98926d
  StrokeGenerator m_rangeTrack;
shun-iwasawa 98926d
  TStroke *m_firstStroke;
shun-iwasawa 98926d
  TFrameId m_firstFrameId, m_veryFirstFrameId;
shun-iwasawa 98926d
  TPixel32 m_currentColor;
ebedef
  int m_styleId; // bwtodo: remove
shun-iwasawa 98926d
  double m_minThick, m_maxThick;
shun-iwasawa 98926d
shun-iwasawa 98926d
  // for snapping and framerange
f8139f
  int m_col, m_firstFrame, m_veryFirstFrame,
shun-iwasawa 98926d
      m_veryFirstCol, m_targetType;
b8dbde
  double m_pixelSize, m_minDistance2;
398cd8
  
b8dbde
  bool m_snapped;
398cd8
  bool m_snappedSelf;
398cd8
  TPointD m_snapPoint;
398cd8
  TPointD m_snapPointSelf;
398cd8
  
b8dbde
  TPointD m_mousePos;  //!< Current mouse position, in world coordinates.
b8dbde
  TPointD m_brushPos;  //!< World position the brush will be painted at.
shun-iwasawa 98926d
shun-iwasawa 98926d
  VectorBrushPresetManager
shun-iwasawa 98926d
      m_presetsManager;  //!< Manager for presets of this tool instance
shun-iwasawa 98926d
c9521d
  bool m_active,
shun-iwasawa 98926d
      m_isPrompting,  //!< Whether the tool is prompting for spline
shun-iwasawa 98926d
                      //! substitution.
shun-iwasawa 98926d
      m_firstTime, m_isPath, m_presetsLoaded, m_firstFrameRange;
shun-iwasawa 98926d
b8dbde
  bool m_propertyUpdating;
shun-iwasawa 98926d
};
shun-iwasawa 98926d
shun-iwasawa 98926d
#endif  // TOONZVECTORBRUSHTOOL_H