Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef BRUSHTOOL_H
Toshihiro Shimizu 890ddd
#define BRUSHTOOL_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Jeremy Bullock cd00fd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "toonz/strokegenerator.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
#include <qradialgradient></qradialgradient>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//  Forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TTileSetCM32;
Toshihiro Shimizu 890ddd
class TTileSaverCM32;
Toshihiro Shimizu 890ddd
class RasterStrokeGenerator;
Toshihiro Shimizu 890ddd
class BluredBrush;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    Brush Data declaration
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
struct BrushData final : public TPersist {
Shinya Kitaoka 120a6e
  PERSIST_DECLARATION(BrushData)
Jeremy Bullock e84aac
  // frameRange, snapSensitivity and snap are not included
Jeremy Bullock e84aac
  // Those options are not really a part of the brush settings, 
Jeremy Bullock e84aac
  //just the overall tool.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::wstring m_name;
walkerka 22f456
  double m_min, m_max, m_acc, m_smooth, m_hardness, m_opacityMin, m_opacityMax;
Jeremy Bullock e84aac
  bool m_selective, m_pencil, m_breakAngles, m_pressure; 
Jeremy Bullock e84aac
  int m_cap, m_join, m_miter; 
bf1d82
  double m_modifierSize, m_modifierOpacity;
572ed1
  bool m_modifierEraser, m_modifierLockAlpha;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  BrushData();
Shinya Kitaoka 120a6e
  BrushData(const std::wstring &name);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool operator<(const BrushData &other) const { return m_name < other.m_name; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void saveData(TOStream &os) override;
Shinya Kitaoka 473e70
  void loadData(TIStream &is) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    Brush Preset Manager declaration
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class BrushPresetManager {
Shinya Kitaoka 120a6e
  TFilePath m_fp;                 //!< Presets file path
Shinya Kitaoka 120a6e
  std::set<brushdata> m_presets;  //!< Current presets container</brushdata>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  BrushPresetManager() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void load(const TFilePath &fp);
Shinya Kitaoka 120a6e
  void save();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const TFilePath &path() { return m_fp; };
Shinya Kitaoka 120a6e
  const std::set<brushdata> &presets() const { return m_presets; }</brushdata>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void addPreset(const BrushData &data);
Shinya Kitaoka 120a6e
  void removePreset(const std::wstring &name);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
walkerka 57fb3c
//    Smooth Stroke declaration
walkerka 57fb3c
//    Brush stroke smoothing buffer.
walkerka 57fb3c
//************************************************************************
walkerka 22f456
class SmoothStroke {
walkerka 57fb3c
public:
walkerka 22f456
  SmoothStroke() {}
walkerka 22f456
  ~SmoothStroke() {}
walkerka 22f456
walkerka 22f456
  // begin stroke
walkerka 22f456
  // smooth is smooth strength, from 0 to 100
walkerka 22f456
  void beginStroke(int smooth);
walkerka 22f456
  // add stroke point
walkerka 22f456
  void addPoint(const TThickPoint &point);
walkerka 22f456
  // end stroke
walkerka 22f456
  void endStroke();
walkerka 22f456
  // Get generated stroke points which has been smoothed.
walkerka 22f456
  // Both addPoint() and endStroke() generate new smoothed points.
walkerka 22f456
  // This method will removed generated points
walkerka 22f456
  void getSmoothPoints(std::vector<tthickpoint> &smoothPoints);</tthickpoint>
Jeremy Bullock 7f2044
  // Remove all points - used for straight lines
Jeremy Bullock 7f2044
  void clearPoints();
walkerka 57fb3c
walkerka 57fb3c
private:
walkerka 22f456
  void generatePoints();
walkerka 57fb3c
walkerka 57fb3c
private:
walkerka 22f456
  int m_smooth;
walkerka 22f456
  int m_outputIndex;
walkerka 22f456
  int m_readIndex;
walkerka 22f456
  std::vector<tthickpoint> m_rawPoints;</tthickpoint>
walkerka 22f456
  std::vector<tthickpoint> m_outputPoints;</tthickpoint>
walkerka 57fb3c
};
walkerka 57fb3c
//************************************************************************
Toshihiro Shimizu 890ddd
//    Brush Tool declaration
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class BrushTool final : public TTool {
Shinya Kitaoka 120a6e
  Q_DECLARE_TR_FUNCTIONS(BrushTool)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  BrushTool(std::string name, int targetType);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  ToolType getToolType() const override { return TTool::LevelWriteTool; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  ToolOptionsBox *createOptionsBox() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void updateTranslation() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onActivate() override;
Shinya Kitaoka 473e70
  void onDeactivate() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool preLeftButtonDown() override;
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
Jeremy Bullock cd00fd
  bool keyDown(int key, TUINT32 b, const TPoint &point) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void draw() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onEnter() override;
Shinya Kitaoka 473e70
  void onLeave() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getCursorId() const override { return ToolCursor::PenCursor; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TPropertyGroup *getProperties(int targetType) override;
Shinya Kitaoka 473e70
  bool onPropertyChanged(std::string propertyName) override;
Jeremy Bullock cd00fd
  void resetFrameRange();
Shinya Kitaoka 473e70
  void onImageChanged() override;
Shinya Kitaoka 120a6e
  void setWorkAndBackupImages();
Shinya Kitaoka 120a6e
  void updateWorkAndBackupRasters(const TRect &rect);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void initPresets();
Shinya Kitaoka 120a6e
  void loadPreset();
Shinya Kitaoka 120a6e
  void addPreset(QString name);
Shinya Kitaoka 120a6e
  void removePreset();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void finishRasterBrush(const TPointD &pos, int pressureVal);
Shinya Kitaoka 120a6e
  // return true if the pencil mode is active in the Brush / PaintBrush / Eraser
Shinya Kitaoka 120a6e
  // Tools.
Shinya Kitaoka 473e70
  bool isPencilModeActive() override;
Toshihiro Shimizu 890ddd
walkerka 22f456
  void addTrackPoint(const TThickPoint &point, double pixelSize2);
walkerka 22f456
  void flushTrackPoint();
Jeremy Bullock cd00fd
  bool doFrameRangeStrokes(TFrameId firstFrameId, TStroke *firstStroke,
Jeremy Bullock cd00fd
                           TFrameId lastFrameId, TStroke *lastStroke,
Jeremy Bullock cd00fd
                           bool drawFirstStroke = true);
Jeremy Bullock cd00fd
  void checkGuideSnapping(bool beforeMousePress);
Jeremy Bullock cd00fd
  void checkStrokeSnapping(bool beforeMousePress);
walkerka 57fb3c
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  TPropertyGroup m_prop[2];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoublePairProperty m_thickness;
Shinya Kitaoka 120a6e
  TDoublePairProperty m_rasThickness;
Shinya Kitaoka 120a6e
  TDoubleProperty m_accuracy;
walkerka bb91cd
  TDoubleProperty m_smooth;
Shinya Kitaoka 120a6e
  TDoubleProperty m_hardness;
Shinya Kitaoka 120a6e
  TEnumProperty m_preset;
Shinya Kitaoka 120a6e
  TBoolProperty m_selective;
Shinya Kitaoka 120a6e
  TBoolProperty m_breakAngles;
Shinya Kitaoka 120a6e
  TBoolProperty m_pencil;
Shinya Kitaoka 120a6e
  TBoolProperty m_pressure;
Jeremy Bullock cd00fd
  TBoolProperty m_snap;
Jeremy Bullock cd00fd
  TEnumProperty m_frameRange;
Jeremy Bullock cd00fd
  TEnumProperty m_snapSensitivity;
Shinya Kitaoka 120a6e
  TEnumProperty m_capStyle;
Shinya Kitaoka 120a6e
  TEnumProperty m_joinStyle;
Shinya Kitaoka 120a6e
  TIntProperty m_miterJoinLimit;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  StrokeGenerator m_track;
Jeremy Bullock cd00fd
  StrokeGenerator m_rangeTrack;
Shinya Kitaoka 120a6e
  RasterStrokeGenerator *m_rasterTrack;
Jeremy Bullock cd00fd
  TStroke *m_firstStroke;
Shinya Kitaoka 120a6e
  TTileSetCM32 *m_tileSet;
Shinya Kitaoka 120a6e
  TTileSaverCM32 *m_tileSaver;
Jeremy Bullock cd00fd
  TFrameId m_firstFrameId, m_veryFirstFrameId;
Shinya Kitaoka 120a6e
  TPixel32 m_currentColor;
Shinya Kitaoka 120a6e
  int m_styleId;
Shinya Kitaoka 120a6e
  double m_minThick, m_maxThick;
Shinya Kitaoka 120a6e
Jeremy Bullock cd00fd
  // for snapping and framerange
Jeremy Bullock cd00fd
  int m_strokeIndex1, m_strokeIndex2, m_col, m_firstFrame, m_veryFirstFrame,
Jeremy Bullock cd00fd
      m_veryFirstCol, m_targetType;
Jeremy Bullock cd00fd
  double m_w1, m_w2, m_pixelSize, m_currThickness, m_minDistance2;
Jeremy Bullock cd00fd
  bool m_foundFirstSnap = false, m_foundLastSnap = false, m_dragDraw = true;
Shinya Kitaoka 120a6e
  TRectD m_modifiedRegion;
Shinya Kitaoka 120a6e
  TPointD m_dpiScale,
Shinya Kitaoka 120a6e
      m_mousePos,  //!< Current mouse position, in world coordinates.
Jeremy Bullock cd00fd
      m_brushPos,  //!< World position the brush will be painted at.
Jeremy Bullock cd00fd
      m_firstSnapPoint, m_lastSnapPoint;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  BluredBrush *m_bluredBrush;
Shinya Kitaoka 120a6e
  QRadialGradient m_brushPad;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterCM32P m_backupRas;
Shinya Kitaoka 120a6e
  TRaster32P m_workRas;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::vector<tthickpoint> m_points;</tthickpoint>
Shinya Kitaoka 120a6e
  TRect m_strokeRect, m_lastRect;
Shinya Kitaoka 120a6e
walkerka bb91cd
  SmoothStroke m_smoothStroke;
walkerka bb91cd
Shinya Kitaoka 120a6e
  BrushPresetManager
Shinya Kitaoka 120a6e
      m_presetsManager;  //!< Manager for presets of this tool instance
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool m_active, m_enabled,
Shinya Kitaoka 120a6e
      m_isPrompting,  //!< Whether the tool is prompting for spline
walkerka 22f456
                      //! substitution.
Jeremy Bullock cd00fd
      m_firstTime, m_isPath, m_presetsLoaded, m_firstFrameRange;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*---
Shinya Kitaoka 120a6e
作業中のFrameIdをクリック時に保存し、マウスリリース時(Undoの登録時)に別のフレームに
Shinya Kitaoka 120a6e
移動していたときの不具合を修正する。---*/
Shinya Kitaoka 120a6e
  TFrameId m_workingFrameId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  static void drawLine(const TPointD &point, const TPointD ¢re,
Shinya Kitaoka 120a6e
                       bool horizontal, bool isDecimal);
Shinya Kitaoka 120a6e
  static void drawEmptyCircle(TPointD point, int thick, bool isLxEven,
Shinya Kitaoka 120a6e
                              bool isLyEven, bool isPencil);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // BRUSHTOOL_H