2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
#ifndef TOONZVECTORBRUSHTOOL_H
|
|
|
|
#define TOONZVECTORBRUSHTOOL_H
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#include "tgeometry.h"
|
|
|
|
#include "tproperty.h"
|
|
|
|
#include "trasterimage.h"
|
|
|
|
#include "ttoonzimage.h"
|
2017-08-14 22:59:51 +12:00
|
|
|
#include "tstroke.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "toonz/strokegenerator.h"
|
|
|
|
|
|
|
|
#include "tools/tool.h"
|
|
|
|
#include "tools/cursors.h"
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
#include "toonzrasterbrushtool.h"
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QRadialGradient>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
|
|
|
|
class TTileSetCM32;
|
|
|
|
class TTileSaverCM32;
|
|
|
|
class RasterStrokeGenerator;
|
|
|
|
class BluredBrush;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// Brush Data declaration
|
|
|
|
//************************************************************************
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
struct VectorBrushData final : public TPersist {
|
|
|
|
PERSIST_DECLARATION(VectorBrushData)
|
2017-09-11 20:03:53 +12:00
|
|
|
// frameRange, snapSensitivity and snap are not included
|
2018-02-19 19:34:13 +13:00
|
|
|
// Those options are not really a part of the brush settings,
|
|
|
|
// just the overall tool.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring m_name;
|
2018-09-12 13:37:07 +12:00
|
|
|
double m_min, m_max, m_acc, m_smooth;
|
|
|
|
bool m_breakAngles, m_pressure;
|
|
|
|
int m_cap, m_join, m_miter;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
VectorBrushData();
|
|
|
|
VectorBrushData(const std::wstring &name);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
bool operator<(const VectorBrushData &other) const {
|
|
|
|
return m_name < other.m_name;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void saveData(TOStream &os) override;
|
|
|
|
void loadData(TIStream &is) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// Brush Preset Manager declaration
|
|
|
|
//************************************************************************
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
class VectorBrushPresetManager {
|
|
|
|
TFilePath m_fp; //!< Presets file path
|
|
|
|
std::set<VectorBrushData> m_presets; //!< Current presets container
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2018-09-12 13:37:07 +12:00
|
|
|
VectorBrushPresetManager() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void load(const TFilePath &fp);
|
|
|
|
void save();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
const TFilePath &path() { return m_fp; };
|
2018-09-12 13:37:07 +12:00
|
|
|
const std::set<VectorBrushData> &presets() const { return m_presets; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
void addPreset(const VectorBrushData &data);
|
2016-06-15 18:43:10 +12:00
|
|
|
void removePreset(const std::wstring &name);
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// Brush Tool declaration
|
|
|
|
//************************************************************************
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
class ToonzVectorBrushTool final : public TTool {
|
2020-01-27 16:09:44 +13:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(ToonzVectorBrushTool)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2018-09-12 13:37:07 +12:00
|
|
|
ToonzVectorBrushTool(std::string name, int targetType);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
ToolType getToolType() const override { return TTool::LevelWriteTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
ToolOptionsBox *createOptionsBox() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void updateTranslation() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void onActivate() override;
|
|
|
|
void onDeactivate() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
bool preLeftButtonDown() override;
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
2018-02-19 19:34:13 +13:00
|
|
|
bool keyDown(QKeyEvent *event) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void draw() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void onEnter() override;
|
|
|
|
void onLeave() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2019-12-25 17:04:57 +13:00
|
|
|
int getCursorId() const override {
|
|
|
|
if (m_viewer && m_viewer->getGuidedStrokePickerMode())
|
|
|
|
return m_viewer->getGuidedStrokePickerCursor();
|
|
|
|
return ToolCursor::PenCursor;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TPropertyGroup *getProperties(int targetType) override;
|
|
|
|
bool onPropertyChanged(std::string propertyName) override;
|
2017-08-14 22:59:51 +12:00
|
|
|
void resetFrameRange();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void initPresets();
|
|
|
|
void loadPreset();
|
|
|
|
void addPreset(QString name);
|
|
|
|
void removePreset();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2019-09-14 04:16:27 +12:00
|
|
|
void loadLastBrush();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// return true if the pencil mode is active in the Brush / PaintBrush / Eraser
|
|
|
|
// Tools.
|
2016-06-19 20:06:29 +12:00
|
|
|
bool isPencilModeActive() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-17 00:29:56 +12:00
|
|
|
void addTrackPoint(const TThickPoint &point, double pixelSize2);
|
|
|
|
void flushTrackPoint();
|
2017-08-14 22:59:51 +12:00
|
|
|
bool doFrameRangeStrokes(TFrameId firstFrameId, TStroke *firstStroke,
|
|
|
|
TFrameId lastFrameId, TStroke *lastStroke,
|
2019-12-25 17:04:57 +13:00
|
|
|
int interpolationType, bool breakAngles,
|
|
|
|
bool autoGroup = false, bool autoFill = false,
|
|
|
|
bool drawFirstStroke = true,
|
2020-09-23 15:04:03 +12:00
|
|
|
bool drawLastStroke = true, bool withUndo = true,
|
|
|
|
bool sendToBack = false);
|
2018-05-25 19:21:25 +12:00
|
|
|
void checkGuideSnapping(bool beforeMousePress, bool invertCheck);
|
|
|
|
void checkStrokeSnapping(bool beforeMousePress, bool invertCheck);
|
2019-12-25 17:04:57 +13:00
|
|
|
bool doGuidedAutoInbetween(TFrameId cFid, const TVectorImageP &cvi,
|
|
|
|
TStroke *cStroke, bool breakAngles,
|
|
|
|
bool autoGroup = false, bool autoFill = false,
|
2020-09-23 15:04:03 +12:00
|
|
|
bool drawStroke = true, bool sendToBack = false);
|
2016-06-10 03:43:25 +12:00
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
TPropertyGroup m_prop[2];
|
|
|
|
|
|
|
|
TDoublePairProperty m_thickness;
|
|
|
|
TDoubleProperty m_accuracy;
|
2016-06-16 03:27:23 +12:00
|
|
|
TDoubleProperty m_smooth;
|
2016-06-15 18:43:10 +12:00
|
|
|
TEnumProperty m_preset;
|
|
|
|
TBoolProperty m_breakAngles;
|
|
|
|
TBoolProperty m_pressure;
|
2017-08-14 22:59:51 +12:00
|
|
|
TBoolProperty m_snap;
|
2020-09-23 15:04:03 +12:00
|
|
|
TBoolProperty m_sendToBack;
|
2020-09-26 16:55:33 +12:00
|
|
|
TBoolProperty m_autoFill;
|
|
|
|
TBoolProperty m_autoClose;
|
|
|
|
TBoolProperty m_autoGroup;
|
2017-08-14 22:59:51 +12:00
|
|
|
TEnumProperty m_frameRange;
|
|
|
|
TEnumProperty m_snapSensitivity;
|
2016-06-15 18:43:10 +12:00
|
|
|
TEnumProperty m_capStyle;
|
|
|
|
TEnumProperty m_joinStyle;
|
|
|
|
TIntProperty m_miterJoinLimit;
|
|
|
|
|
|
|
|
StrokeGenerator m_track;
|
2017-08-14 22:59:51 +12:00
|
|
|
StrokeGenerator m_rangeTrack;
|
2016-06-15 18:43:10 +12:00
|
|
|
RasterStrokeGenerator *m_rasterTrack;
|
2017-08-14 22:59:51 +12:00
|
|
|
TStroke *m_firstStroke;
|
2016-06-15 18:43:10 +12:00
|
|
|
TTileSetCM32 *m_tileSet;
|
|
|
|
TTileSaverCM32 *m_tileSaver;
|
2017-08-14 22:59:51 +12:00
|
|
|
TFrameId m_firstFrameId, m_veryFirstFrameId;
|
2016-06-15 18:43:10 +12:00
|
|
|
TPixel32 m_currentColor;
|
|
|
|
int m_styleId;
|
|
|
|
double m_minThick, m_maxThick;
|
|
|
|
|
2017-08-14 22:59:51 +12:00
|
|
|
// for snapping and framerange
|
|
|
|
int m_strokeIndex1, m_strokeIndex2, m_col, m_firstFrame, m_veryFirstFrame,
|
|
|
|
m_veryFirstCol, m_targetType;
|
|
|
|
double m_w1, m_w2, m_pixelSize, m_currThickness, m_minDistance2;
|
2018-05-25 19:21:25 +12:00
|
|
|
bool m_foundFirstSnap = false, m_foundLastSnap = false, m_dragDraw = true,
|
2020-09-14 06:43:02 +12:00
|
|
|
m_toggleSnap = false, m_snapSelf = false;
|
2016-06-15 18:43:10 +12:00
|
|
|
TRectD m_modifiedRegion;
|
|
|
|
TPointD m_dpiScale,
|
|
|
|
m_mousePos, //!< Current mouse position, in world coordinates.
|
2017-08-14 22:59:51 +12:00
|
|
|
m_brushPos, //!< World position the brush will be painted at.
|
|
|
|
m_firstSnapPoint, m_lastSnapPoint;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
BluredBrush *m_bluredBrush;
|
|
|
|
QRadialGradient m_brushPad;
|
|
|
|
|
|
|
|
TRasterCM32P m_backupRas;
|
|
|
|
TRaster32P m_workRas;
|
|
|
|
|
|
|
|
std::vector<TThickPoint> m_points;
|
|
|
|
TRect m_strokeRect, m_lastRect;
|
|
|
|
|
2016-06-16 03:27:23 +12:00
|
|
|
SmoothStroke m_smoothStroke;
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
VectorBrushPresetManager
|
2016-06-15 18:43:10 +12:00
|
|
|
m_presetsManager; //!< Manager for presets of this tool instance
|
|
|
|
|
|
|
|
bool m_active, m_enabled,
|
|
|
|
m_isPrompting, //!< Whether the tool is prompting for spline
|
2016-06-17 00:29:56 +12:00
|
|
|
//! substitution.
|
2017-08-14 22:59:51 +12:00
|
|
|
m_firstTime, m_isPath, m_presetsLoaded, m_firstFrameRange;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
TFrameId m_workingFrameId;
|
2019-07-19 10:19:25 +12:00
|
|
|
|
2019-09-14 04:16:27 +12:00
|
|
|
TPointD m_lastDragPos; //!< Position where mouse was last dragged.
|
|
|
|
TMouseEvent m_lastDragEvent; //!< Previous mouse-drag event.
|
2019-09-15 01:50:49 +12:00
|
|
|
|
|
|
|
bool m_propertyUpdating = false;
|
2020-09-14 06:43:02 +12:00
|
|
|
|
|
|
|
TPointD m_firstPoint;
|
|
|
|
TPointD m_lastPoint;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
#endif // TOONZVECTORBRUSHTOOL_H
|