tahoma2d/toonz/sources/tnztools/toonzvectorbrushtool.h

224 lines
6.8 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13: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"
#include "tstroke.h"
2016-03-19 06:57:51 +13:00
#include "toonz/strokegenerator.h"
#include "tools/tool.h"
#include "tools/cursors.h"
#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
//************************************************************************
struct VectorBrushData final : public TPersist {
PERSIST_DECLARATION(VectorBrushData)
// 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;
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
VectorBrushData();
VectorBrushData(const std::wstring &name);
2016-03-19 06:57:51 +13: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
//************************************************************************
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:
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; };
const std::set<VectorBrushData> &presets() const { return m_presets; }
2016-03-19 06:57:51 +13: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
//************************************************************************
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:
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
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;
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();
bool doFrameRangeStrokes(TFrameId firstFrameId, TStroke *firstStroke,
TFrameId lastFrameId, TStroke *lastStroke,
int interpolationType, bool breakAngles,
bool autoGroup = false, bool autoFill = false,
bool drawFirstStroke = true,
bool drawLastStroke = true, bool withUndo = true,
bool sendToBack = false);
void checkGuideSnapping(bool beforeMousePress, bool invertCheck);
void checkStrokeSnapping(bool beforeMousePress, bool invertCheck);
bool doGuidedAutoInbetween(TFrameId cFid, const TVectorImageP &cvi,
TStroke *cStroke, bool breakAngles,
bool autoGroup = false, bool autoFill = false,
bool drawStroke = true, bool sendToBack = false);
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;
TDoubleProperty m_smooth;
2016-06-15 18:43:10 +12:00
TEnumProperty m_preset;
TBoolProperty m_breakAngles;
TBoolProperty m_pressure;
TBoolProperty m_snap;
TBoolProperty m_sendToBack;
TBoolProperty m_autoFill;
TBoolProperty m_autoClose;
TBoolProperty m_autoGroup;
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;
StrokeGenerator m_rangeTrack;
2016-06-15 18:43:10 +12:00
RasterStrokeGenerator *m_rasterTrack;
TStroke *m_firstStroke;
2016-06-15 18:43:10 +12:00
TTileSetCM32 *m_tileSet;
TTileSaverCM32 *m_tileSaver;
TFrameId m_firstFrameId, m_veryFirstFrameId;
2016-06-15 18:43:10 +12:00
TPixel32 m_currentColor;
int m_styleId;
double m_minThick, m_maxThick;
// 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;
bool m_foundFirstSnap = false, m_foundLastSnap = false, m_dragDraw = true,
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.
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;
SmoothStroke m_smoothStroke;
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.
m_firstTime, m_isPath, m_presetsLoaded, m_firstFrameRange;
2016-06-15 18:43:10 +12:00
TFrameId m_workingFrameId;
2019-09-14 04:16:27 +12:00
TPointD m_lastDragPos; //!< Position where mouse was last dragged.
TMouseEvent m_lastDragEvent; //!< Previous mouse-drag event.
bool m_propertyUpdating = false;
std::vector<TPointD> m_assistantPoints;
bool m_addingAssistant = false;
TPointD m_firstPoint;
TPointD m_lastPoint;
int m_highlightAssistant = -1;
2016-03-19 06:57:51 +13:00
};
#endif // TOONZVECTORBRUSHTOOL_H