tahoma2d/toonz/sources/tnztools/fullcolorbrushtool.h

137 lines
3.6 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 FULLCOLORBRUSHTOOL_H
#define FULLCOLORBRUSHTOOL_H
#include <ctime>
2016-03-19 06:57:51 +13:00
#include "brushtool.h"
#include "mypainttoonzbrush.h"
#include "toonz/mypaintbrushstyle.h"
#include <QElapsedTimer>
2016-03-19 06:57:51 +13:00
//==============================================================
// Forward declarations
class TTileSetFullColor;
class TTileSaverFullColor;
class MyPaintToonzBrush;
2016-03-19 06:57:51 +13:00
class FullColorBrushToolNotifier;
namespace mypaint { class Brush; }
2016-03-19 06:57:51 +13:00
//==============================================================
//************************************************************************
// FullColor Brush Tool declaration
//************************************************************************
class FullColorBrushTool final : public TTool, public RasterController {
2016-06-15 18:43:10 +12:00
Q_DECLARE_TR_FUNCTIONS(FullColorBrushTool)
2016-03-19 06:57:51 +13:00
void updateCurrentStyle();
double restartBrushTimer();
void applyClassicToonzBrushSettings(mypaint::Brush &mypaintBrush);
void applyToonzBrushSettings(mypaint::Brush &mypaintBrush);
2016-11-24 20:02:18 +13:00
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
FullColorBrushTool(std::string name);
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
bool askRead(const TRect &rect) override;
bool askWrite(const TRect &rect) override;
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;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
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
2016-06-15 18:43:10 +12:00
void onCanvasSizeChanged();
void onColorStyleChanged();
TMyPaintBrushStyle* getBrushStyle();
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
TPropertyGroup m_prop;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TIntPairProperty m_thickness;
TBoolProperty m_pressure;
TDoublePairProperty m_opacity;
TDoubleProperty m_hardness;
TDoubleProperty m_modifierSize;
TDoubleProperty m_modifierOpacity;
2016-06-15 18:43:10 +12:00
TEnumProperty m_preset;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPixel32 m_currentColor;
bool m_enabledPressure;
int m_minCursorThick, m_maxCursorThick;
2016-03-19 06:57:51 +13:00
TPointD m_mousePos, //!< Current mouse position, in world coordinates.
m_brushPos; //!< World position the brush will be painted at.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterP m_backUpRas;
TRaster32P m_workRaster;
2016-03-19 06:57:51 +13:00
TRect m_strokeRect, m_strokeSegmentRect, m_lastRect;
2016-03-19 06:57:51 +13:00
MyPaintToonzBrush *m_toonz_brush;
QElapsedTimer m_brushTimer;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TTileSetFullColor *m_tileSet;
TTileSaverFullColor *m_tileSaver;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
BrushPresetManager
m_presetsManager; //!< Manager for presets of this tool instance
FullColorBrushToolNotifier *m_notifier;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_presetsLoaded;
bool m_firstTime;
bool m_mousePressed = false;
TMouseEvent m_mouseEvent;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------
class FullColorBrushToolNotifier final : public QObject {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
FullColorBrushTool *m_tool;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
FullColorBrushToolNotifier(FullColorBrushTool *tool);
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onCanvasSizeChanged() { m_tool->onCanvasSizeChanged(); }
void onColorStyleChanged() { m_tool->onColorStyleChanged(); }
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // FULLCOLORBRUSHTOOL_H