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 TOONZRASTERBRUSHTOOL_H
|
|
|
|
|
#define TOONZRASTERBRUSHTOOL_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 "tools/tool.h"
|
|
|
|
|
#include "tools/cursors.h"
|
2018-09-12 13:37:07 +12:00
|
|
|
|
#include "mypainttoonzbrush.h"
|
2023-02-04 15:05:42 +13:00
|
|
|
|
#include "bluredbrush.h"
|
|
|
|
|
#include "cmrasterbrush.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QRadialGradient>
|
2018-09-12 13:37:07 +12:00
|
|
|
|
#include <QElapsedTimer>
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
|
|
|
|
|
|
class TTileSetCM32;
|
|
|
|
|
class TTileSaverCM32;
|
|
|
|
|
class RasterStrokeGenerator;
|
|
|
|
|
class BluredBrush;
|
2018-09-12 13:37:07 +12:00
|
|
|
|
class ToonzRasterBrushToolNotifier;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//************************************************************************
|
2018-09-12 13:37:07 +12:00
|
|
|
|
// Toonz Raster Brush Data declaration
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//************************************************************************
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
struct BrushData final : public TPersist {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
PERSIST_DECLARATION(BrushData)
|
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_smooth, m_hardness, m_opacityMin, m_opacityMax;
|
|
|
|
|
bool m_pencil, m_pressure;
|
|
|
|
|
int m_drawOrder;
|
2017-08-04 15:31:50 +12:00
|
|
|
|
double m_modifierSize, m_modifierOpacity;
|
2017-10-17 02:54:19 +13:00
|
|
|
|
bool m_modifierEraser, m_modifierLockAlpha;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
BrushData();
|
|
|
|
|
BrushData(const std::wstring &name);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
bool operator<(const BrushData &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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//************************************************************************
|
2018-09-12 13:37:07 +12:00
|
|
|
|
// Toonz Raster Brush Preset Manager declaration
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//************************************************************************
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
class BrushPresetManager {
|
|
|
|
|
TFilePath m_fp; //!< Presets file path
|
|
|
|
|
std::set<BrushData> m_presets; //!< Current presets container
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
BrushPresetManager() {}
|
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<BrushData> &presets() const { return m_presets; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void addPreset(const BrushData &data);
|
|
|
|
|
void removePreset(const std::wstring &name);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-10 03:43:25 +12:00
|
|
|
|
//************************************************************************
|
|
|
|
|
// Smooth Stroke declaration
|
|
|
|
|
// Brush stroke smoothing buffer.
|
|
|
|
|
//************************************************************************
|
2016-06-17 00:29:56 +12:00
|
|
|
|
class SmoothStroke {
|
2016-06-10 03:43:25 +12:00
|
|
|
|
public:
|
2016-06-17 00:29:56 +12:00
|
|
|
|
SmoothStroke() {}
|
|
|
|
|
~SmoothStroke() {}
|
|
|
|
|
|
|
|
|
|
// begin stroke
|
|
|
|
|
// smooth is smooth strength, from 0 to 100
|
|
|
|
|
void beginStroke(int smooth);
|
|
|
|
|
// add stroke point
|
|
|
|
|
void addPoint(const TThickPoint &point);
|
|
|
|
|
// end stroke
|
|
|
|
|
void endStroke();
|
|
|
|
|
// Get generated stroke points which has been smoothed.
|
|
|
|
|
// Both addPoint() and endStroke() generate new smoothed points.
|
|
|
|
|
// This method will removed generated points
|
|
|
|
|
void getSmoothPoints(std::vector<TThickPoint> &smoothPoints);
|
2017-08-10 18:31:01 +12:00
|
|
|
|
// Remove all points - used for straight lines
|
|
|
|
|
void clearPoints();
|
2016-06-10 03:43:25 +12:00
|
|
|
|
|
|
|
|
|
private:
|
2016-06-17 00:29:56 +12:00
|
|
|
|
void generatePoints();
|
2016-06-10 03:43:25 +12:00
|
|
|
|
|
|
|
|
|
private:
|
2016-06-17 00:29:56 +12:00
|
|
|
|
int m_smooth;
|
|
|
|
|
int m_outputIndex;
|
|
|
|
|
int m_readIndex;
|
|
|
|
|
std::vector<TThickPoint> m_rawPoints;
|
|
|
|
|
std::vector<TThickPoint> m_outputPoints;
|
2021-06-14 15:51:38 +12:00
|
|
|
|
int m_resampledIndex;
|
|
|
|
|
std::vector<TThickPoint> m_resampledPoints;
|
2016-06-10 03:43:25 +12:00
|
|
|
|
};
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//************************************************************************
|
2018-09-12 13:37:07 +12:00
|
|
|
|
// Toonz Raster Brush Tool declaration
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//************************************************************************
|
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
|
class ToonzRasterBrushTool final : public TTool, public RasterController {
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(ToonzRasterBrushTool)
|
|
|
|
|
|
|
|
|
|
void updateCurrentStyle();
|
|
|
|
|
double restartBrushTimer();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2018-09-12 13:37:07 +12:00
|
|
|
|
ToonzRasterBrushTool(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;
|
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
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
int getCursorId() const override { 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 onImageChanged() override;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void setWorkAndBackupImages();
|
|
|
|
|
void updateWorkAndBackupRasters(const TRect &rect);
|
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();
|
|
|
|
|
|
2018-02-19 19:55:29 +13:00
|
|
|
|
void finishRasterBrush(const TPointD &pos, double pressureVal);
|
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
|
|
|
|
|
2021-08-21 08:12:52 +12:00
|
|
|
|
void onCanvasSizeChanged();
|
2018-09-12 13:37:07 +12:00
|
|
|
|
void onColorStyleChanged();
|
|
|
|
|
bool askRead(const TRect &rect) override;
|
|
|
|
|
bool askWrite(const TRect &rect) override;
|
2021-10-17 16:14:37 +13:00
|
|
|
|
bool isMyPaintStyleSelected() override { return m_isMyPaintStyleSelected; }
|
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_rasThickness;
|
2016-06-16 03:27:23 +12:00
|
|
|
|
TDoubleProperty m_smooth;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TDoubleProperty m_hardness;
|
|
|
|
|
TEnumProperty m_preset;
|
2018-03-14 21:33:59 +13:00
|
|
|
|
TEnumProperty m_drawOrder;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TBoolProperty m_pencil;
|
|
|
|
|
TBoolProperty m_pressure;
|
2018-09-12 13:37:07 +12:00
|
|
|
|
TDoubleProperty m_modifierSize;
|
2021-06-04 10:17:41 +12:00
|
|
|
|
TBoolProperty m_modifierLockAlpha;
|
2021-11-04 16:46:49 +13:00
|
|
|
|
TBoolProperty m_snapGrid;
|
2018-09-12 13:37:07 +12:00
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
|
CMRasterBrush *m_cmRasterBrush;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TTileSetCM32 *m_tileSet;
|
|
|
|
|
TTileSaverCM32 *m_tileSaver;
|
|
|
|
|
TPixel32 m_currentColor;
|
|
|
|
|
int m_styleId;
|
|
|
|
|
double m_minThick, m_maxThick;
|
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
|
int m_targetType;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPointD m_dpiScale,
|
|
|
|
|
m_mousePos, //!< Current mouse position, in world coordinates.
|
2018-09-12 13:37:07 +12:00
|
|
|
|
m_brushPos; //!< World position the brush will be painted at.
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
|
RasterBlurredBrush *m_bluredBrush;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
QRadialGradient m_brushPad;
|
|
|
|
|
|
|
|
|
|
TRasterCM32P m_backupRas;
|
|
|
|
|
TRaster32P m_workRas;
|
|
|
|
|
|
|
|
|
|
std::vector<TThickPoint> m_points;
|
2018-09-12 13:37:07 +12:00
|
|
|
|
TRect m_strokeRect, m_lastRect,
|
|
|
|
|
m_strokeSegmentRect; // used with mypaint brush
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2016-06-16 03:27:23 +12:00
|
|
|
|
SmoothStroke m_smoothStroke;
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
BrushPresetManager
|
|
|
|
|
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.
|
2018-09-12 13:37:07 +12:00
|
|
|
|
m_firstTime, m_presetsLoaded;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
/*---
|
|
|
|
|
作業中のFrameIdをクリック時に保存し、マウスリリース時(Undoの登録時)に別のフレームに
|
|
|
|
|
移動していたときの不具合を修正する。---*/
|
|
|
|
|
TFrameId m_workingFrameId;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
|
ToonzRasterBrushToolNotifier *m_notifier;
|
|
|
|
|
bool m_isMyPaintStyleSelected = false;
|
|
|
|
|
MyPaintToonzBrush *m_toonz_brush = 0;
|
|
|
|
|
QElapsedTimer m_brushTimer;
|
|
|
|
|
int m_minCursorThick, m_maxCursorThick;
|
|
|
|
|
|
2019-09-15 01:50:49 +12:00
|
|
|
|
bool m_propertyUpdating = false;
|
|
|
|
|
|
2020-06-04 17:09:51 +12:00
|
|
|
|
bool m_isStraight = false;
|
|
|
|
|
TPointD m_firstPoint;
|
|
|
|
|
TPointD m_lastPoint;
|
2020-06-21 16:58:33 +12:00
|
|
|
|
double m_oldPressure = -1.0;
|
|
|
|
|
// double m_oldThickness = -1.0;
|
|
|
|
|
// int m_dragCount = 0;
|
2020-06-04 17:09:51 +12:00
|
|
|
|
|
2021-11-04 16:46:49 +13:00
|
|
|
|
int m_perspectiveIndex = -1;
|
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
static void drawLine(const TPointD &point, const TPointD ¢re,
|
|
|
|
|
bool horizontal, bool isDecimal);
|
|
|
|
|
static void drawEmptyCircle(TPointD point, int thick, bool isLxEven,
|
|
|
|
|
bool isLyEven, bool isPencil);
|
2019-08-22 10:21:22 +12:00
|
|
|
|
|
2019-09-02 16:44:53 +12:00
|
|
|
|
TPointD getCenteredCursorPos(const TPointD &originalCursorPos);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
2018-09-12 13:37:07 +12:00
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class ToonzRasterBrushToolNotifier final : public QObject {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
ToonzRasterBrushTool *m_tool;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ToonzRasterBrushToolNotifier(ToonzRasterBrushTool *tool);
|
|
|
|
|
|
|
|
|
|
protected slots:
|
2021-08-21 08:12:52 +12:00
|
|
|
|
void onCanvasSizeChanged() { m_tool->onCanvasSizeChanged(); }
|
2018-09-12 13:37:07 +12:00
|
|
|
|
void onColorStyleChanged() { m_tool->onColorStyleChanged(); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // TOONZRASTERBRUSHTOOL_H
|