2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "fullcolorbrushtool.h"
|
|
|
|
|
|
|
|
// TnzTools includes
|
|
|
|
#include "tools/tool.h"
|
|
|
|
#include "tools/cursors.h"
|
|
|
|
#include "tools/toolutils.h"
|
|
|
|
#include "tools/toolhandle.h"
|
|
|
|
#include "tools/tooloptions.h"
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
#include "mypainttoonzbrush.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// TnzQt includes
|
|
|
|
#include "toonzqt/dvdialog.h"
|
|
|
|
|
|
|
|
// TnzLib includes
|
|
|
|
#include "toonz/tpalettehandle.h"
|
|
|
|
#include "toonz/txsheethandle.h"
|
|
|
|
#include "toonz/txshlevelhandle.h"
|
|
|
|
#include "toonz/tobjecthandle.h"
|
2021-03-17 14:48:43 +13:00
|
|
|
#include "toonz/tframehandle.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "toonz/ttileset.h"
|
|
|
|
#include "toonz/ttilesaver.h"
|
|
|
|
#include "toonz/strokegenerator.h"
|
|
|
|
#include "toonz/tstageobject.h"
|
|
|
|
#include "toonz/palettecontroller.h"
|
2017-08-04 15:31:50 +12:00
|
|
|
#include "toonz/mypaintbrushstyle.h"
|
2018-05-17 18:03:05 +12:00
|
|
|
#include "toonz/preferences.h"
|
2020-10-22 03:59:24 +13:00
|
|
|
#include "toonz/toonzfolders.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// TnzCore includes
|
|
|
|
#include "tgl.h"
|
|
|
|
#include "tproperty.h"
|
|
|
|
#include "trasterimage.h"
|
|
|
|
#include "tenv.h"
|
|
|
|
#include "tpalette.h"
|
|
|
|
#include "trop.h"
|
|
|
|
#include "tstream.h"
|
|
|
|
#include "tstroke.h"
|
|
|
|
#include "timagecache.h"
|
2017-08-04 15:31:50 +12:00
|
|
|
#include "tpixelutils.h"
|
2020-10-22 03:59:24 +13:00
|
|
|
#include "tsystem.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// Qt includes
|
2016-06-15 18:43:10 +12:00
|
|
|
#include <QCoreApplication> // Qt translation support
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TEnv::IntVar FullcolorBrushMinSize("FullcolorBrushMinSize", 1);
|
|
|
|
TEnv::IntVar FullcolorBrushMaxSize("FullcolorBrushMaxSize", 5);
|
2016-06-29 22:49:17 +12:00
|
|
|
TEnv::IntVar FullcolorPressureSensitivity("FullcolorPressureSensitivity", 1);
|
2016-03-19 06:57:51 +13:00
|
|
|
TEnv::DoubleVar FullcolorBrushHardness("FullcolorBrushHardness", 100);
|
|
|
|
TEnv::DoubleVar FullcolorMinOpacity("FullcolorMinOpacity", 100);
|
|
|
|
TEnv::DoubleVar FullcolorMaxOpacity("FullcolorMaxOpacity", 100);
|
2017-08-04 15:31:50 +12:00
|
|
|
TEnv::DoubleVar FullcolorModifierSize("FullcolorModifierSize", 0);
|
|
|
|
TEnv::DoubleVar FullcolorModifierOpacity("FullcolorModifierOpacity", 100);
|
2017-10-17 02:54:19 +13:00
|
|
|
TEnv::IntVar FullcolorModifierEraser("FullcolorModifierEraser", 0);
|
|
|
|
TEnv::IntVar FullcolorModifierLockAlpha("FullcolorModifierLockAlpha", 0);
|
2019-09-14 04:16:27 +12:00
|
|
|
TEnv::StringVar FullcolorBrushPreset("FullcolorBrushPreset", "<custom>");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define CUSTOM_WSTR L"<custom>"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class FullColorBrushUndo final : public ToolUtils::TFullColorRasterUndo {
|
2016-06-15 18:43:10 +12:00
|
|
|
TPoint m_offset;
|
|
|
|
QString m_id;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
FullColorBrushUndo(TTileSetFullColor *tileSet, TXshSimpleLevel *level,
|
|
|
|
const TFrameId &frameId, bool isFrameCreated,
|
|
|
|
const TRasterP &ras, const TPoint &offset)
|
|
|
|
: ToolUtils::TFullColorRasterUndo(tileSet, level, frameId, isFrameCreated,
|
|
|
|
false, 0)
|
|
|
|
, m_offset(offset) {
|
|
|
|
static int counter = 0;
|
|
|
|
|
|
|
|
m_id = QString("FullColorBrushUndo") + QString::number(counter++);
|
|
|
|
TImageCache::instance()->add(m_id.toStdString(), TRasterImageP(ras));
|
|
|
|
}
|
|
|
|
|
|
|
|
~FullColorBrushUndo() { TImageCache::instance()->remove(m_id); }
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void redo() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
insertLevelAndFrameIfNeeded();
|
|
|
|
|
|
|
|
TRasterImageP image = getImage();
|
|
|
|
TRasterP ras = image->getRaster();
|
|
|
|
|
|
|
|
TRasterImageP srcImg =
|
|
|
|
TImageCache::instance()->get(m_id.toStdString(), false);
|
|
|
|
ras->copy(srcImg->getRaster(), m_offset);
|
|
|
|
|
|
|
|
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
|
|
notifyImageChanged();
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
int getSize() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
return sizeof(*this) + ToolUtils::TFullColorRasterUndo::getSize();
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
QString getToolName() override { return QString("Raster Brush Tool"); }
|
|
|
|
int getHistoryType() override { return HistoryType::BrushTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// FullColor Brush Tool implementation
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-04-19 19:32:17 +12:00
|
|
|
FullColorBrushTool::FullColorBrushTool(std::string name)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TTool(name)
|
2019-10-11 16:13:41 +13:00
|
|
|
, m_thickness("Size", 1, 1000, 1, 5, false)
|
2017-01-20 00:46:50 +13:00
|
|
|
, m_pressure("Pressure", true)
|
|
|
|
, m_opacity("Opacity", 0, 100, 100, 100, true)
|
2016-06-15 18:43:10 +12:00
|
|
|
, m_hardness("Hardness:", 0, 100, 100)
|
2017-08-04 15:31:50 +12:00
|
|
|
, m_modifierSize("ModifierSize", -3, 3, 0, true)
|
|
|
|
, m_modifierOpacity("ModifierOpacity", 0, 100, 100, true)
|
2017-10-17 02:54:19 +13:00
|
|
|
, m_modifierEraser("ModifierEraser", false)
|
|
|
|
, m_modifierLockAlpha("ModifierLockAlpha", false)
|
2016-06-15 18:43:10 +12:00
|
|
|
, m_preset("Preset:")
|
2017-08-04 15:31:50 +12:00
|
|
|
, m_minCursorThick(0)
|
|
|
|
, m_maxCursorThick(0)
|
|
|
|
, m_enabledPressure(false)
|
|
|
|
, m_toonz_brush(0)
|
2016-06-15 18:43:10 +12:00
|
|
|
, m_tileSet(0)
|
|
|
|
, m_tileSaver(0)
|
|
|
|
, m_notifier(0)
|
|
|
|
, m_presetsLoaded(false)
|
|
|
|
, m_firstTime(true) {
|
|
|
|
bind(TTool::RasterImage | TTool::EmptyTarget);
|
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
m_thickness.setNonLinearSlider();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_prop.bind(m_thickness);
|
|
|
|
m_prop.bind(m_hardness);
|
|
|
|
m_prop.bind(m_opacity);
|
2017-08-04 15:31:50 +12:00
|
|
|
m_prop.bind(m_modifierSize);
|
|
|
|
m_prop.bind(m_modifierOpacity);
|
2017-10-17 02:54:19 +13:00
|
|
|
m_prop.bind(m_modifierEraser);
|
|
|
|
m_prop.bind(m_modifierLockAlpha);
|
2016-06-15 18:43:10 +12:00
|
|
|
m_prop.bind(m_pressure);
|
|
|
|
m_prop.bind(m_preset);
|
2017-08-04 15:31:50 +12:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_preset.setId("BrushPreset");
|
2019-06-20 18:02:37 +12:00
|
|
|
m_modifierEraser.setId("RasterEraser");
|
|
|
|
m_modifierLockAlpha.setId("LockAlpha");
|
|
|
|
m_pressure.setId("PressureSensitivity");
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
m_brushTimer.start();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
ToolOptionsBox *FullColorBrushTool::createOptionsBox() {
|
|
|
|
TPaletteHandle *currPalette =
|
|
|
|
TTool::getApplication()->getPaletteController()->getCurrentLevelPalette();
|
|
|
|
ToolHandle *currTool = TTool::getApplication()->getCurrentTool();
|
|
|
|
return new BrushToolOptionsBox(0, this, currPalette, currTool);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::onCanvasSizeChanged() {
|
|
|
|
onDeactivate();
|
|
|
|
setWorkAndBackupImages();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
void FullColorBrushTool::onColorStyleChanged() {
|
|
|
|
getApplication()->getCurrentTool()->notifyToolChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::updateTranslation() {
|
2017-01-20 00:46:50 +13:00
|
|
|
m_thickness.setQStringName(tr("Size"));
|
|
|
|
m_pressure.setQStringName(tr("Pressure"));
|
|
|
|
m_opacity.setQStringName(tr("Opacity"));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_hardness.setQStringName(tr("Hardness:"));
|
|
|
|
m_preset.setQStringName(tr("Preset:"));
|
2017-08-04 15:31:50 +12:00
|
|
|
m_modifierSize.setQStringName(tr("Size"));
|
|
|
|
m_modifierOpacity.setQStringName(tr("Opacity"));
|
2017-10-17 02:54:19 +13:00
|
|
|
m_modifierEraser.setQStringName(tr("Eraser"));
|
|
|
|
m_modifierLockAlpha.setQStringName(tr("Lock Alpha"));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::onActivate() {
|
|
|
|
if (!m_notifier) m_notifier = new FullColorBrushToolNotifier(this);
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
updateCurrentStyle();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
if (m_firstTime) {
|
|
|
|
m_firstTime = false;
|
2019-09-14 04:16:27 +12:00
|
|
|
|
|
|
|
std::wstring wpreset =
|
|
|
|
QString::fromStdString(FullcolorBrushPreset.getValue()).toStdWString();
|
|
|
|
if (wpreset != CUSTOM_WSTR) {
|
|
|
|
initPresets();
|
2020-10-23 06:03:17 +13:00
|
|
|
if (!m_preset.isValue(wpreset)) wpreset = CUSTOM_WSTR;
|
2019-09-14 04:16:27 +12:00
|
|
|
m_preset.setValue(wpreset);
|
2020-10-23 06:03:17 +13:00
|
|
|
FullcolorBrushPreset = m_preset.getValueAsString();
|
2019-09-14 04:16:27 +12:00
|
|
|
loadPreset();
|
|
|
|
} else
|
|
|
|
loadLastBrush();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
setWorkAndBackupImages();
|
2017-08-04 15:31:50 +12:00
|
|
|
onColorStyleChanged();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::onDeactivate() {
|
2017-05-31 22:53:58 +12:00
|
|
|
if (m_mousePressed) leftButtonUp(m_mousePos, m_mouseEvent);
|
2016-06-15 18:43:10 +12:00
|
|
|
m_workRaster = TRaster32P();
|
|
|
|
m_backUpRas = TRasterP();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::updateWorkAndBackupRasters(const TRect &rect) {
|
2017-08-04 15:31:50 +12:00
|
|
|
if (rect.isEmpty()) return;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterImageP ri = TImageP(getImage(false, 1));
|
|
|
|
if (!ri) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterP ras = ri->getRaster();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
const int denominator = 8;
|
2017-11-07 20:24:20 +13:00
|
|
|
TRect enlargedRect = rect + m_lastRect;
|
|
|
|
int dx = (enlargedRect.getLx() - 1) / denominator + 1;
|
|
|
|
int dy = (enlargedRect.getLy() - 1) / denominator + 1;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_lastRect.isEmpty()) {
|
2017-08-04 15:31:50 +12:00
|
|
|
enlargedRect.x0 -= dx;
|
|
|
|
enlargedRect.y0 -= dy;
|
|
|
|
enlargedRect.x1 += dx;
|
|
|
|
enlargedRect.y1 += dy;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TRect _rect = enlargedRect * ras->getBounds();
|
2017-08-04 15:31:50 +12:00
|
|
|
if (_rect.isEmpty()) return;
|
|
|
|
|
|
|
|
m_workRaster->extract(_rect)->copy(ras->extract(_rect));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_backUpRas->extract(_rect)->copy(ras->extract(_rect));
|
2017-08-04 15:31:50 +12:00
|
|
|
} else {
|
|
|
|
if (enlargedRect.x0 < m_lastRect.x0) enlargedRect.x0 -= dx;
|
|
|
|
if (enlargedRect.y0 < m_lastRect.y0) enlargedRect.y0 -= dy;
|
|
|
|
if (enlargedRect.x1 > m_lastRect.x1) enlargedRect.x1 += dx;
|
|
|
|
if (enlargedRect.y1 > m_lastRect.y1) enlargedRect.y1 += dy;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TRect _rect = enlargedRect * ras->getBounds();
|
2017-08-04 15:31:50 +12:00
|
|
|
if (_rect.isEmpty()) return;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TRect _lastRect = m_lastRect * ras->getBounds();
|
2017-08-04 15:31:50 +12:00
|
|
|
QList<TRect> rects = ToolUtils::splitRect(_rect, _lastRect);
|
|
|
|
for (int i = 0; i < rects.size(); i++) {
|
|
|
|
m_workRaster->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
|
|
m_backUpRas->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
m_lastRect = enlargedRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
bool FullColorBrushTool::askRead(const TRect &rect) { return askWrite(rect); }
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool FullColorBrushTool::askWrite(const TRect &rect) {
|
|
|
|
if (rect.isEmpty()) return true;
|
|
|
|
m_strokeRect += rect;
|
|
|
|
m_strokeSegmentRect += rect;
|
|
|
|
updateWorkAndBackupRasters(rect);
|
|
|
|
m_tileSaver->save(rect);
|
|
|
|
return true;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool FullColorBrushTool::preLeftButtonDown() {
|
|
|
|
touchImage();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2021-03-17 14:48:43 +13:00
|
|
|
if (m_isFrameCreated) {
|
|
|
|
setWorkAndBackupImages();
|
|
|
|
// When the xsheet frame is selected, whole viewer will be updated from
|
|
|
|
// SceneViewer::onXsheetChanged() on adding a new frame.
|
|
|
|
// We need to take care of a case when the level frame is selected.
|
|
|
|
if (m_application->getCurrentFrame()->isEditingLevel()) invalidate();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return true;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::leftButtonDown(const TPointD &pos,
|
|
|
|
const TMouseEvent &e) {
|
2017-08-04 15:31:50 +12:00
|
|
|
TPointD previousBrushPos = m_brushPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
m_brushPos = m_mousePos = pos;
|
2017-05-31 22:53:58 +12:00
|
|
|
m_mousePressed = true;
|
|
|
|
m_mouseEvent = e;
|
|
|
|
Viewer *viewer = getViewer();
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!viewer) return;
|
|
|
|
|
|
|
|
TRasterImageP ri = (TRasterImageP)getImage(true);
|
2021-03-17 14:48:43 +13:00
|
|
|
if (!ri) ri = (TRasterImageP)touchImage();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
if (!ri) return;
|
|
|
|
|
2020-06-17 17:06:09 +12:00
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
if (!app) return;
|
2020-09-11 05:38:41 +12:00
|
|
|
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
|
|
if (level == NULL) {
|
|
|
|
m_active = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:06:09 +12:00
|
|
|
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
|
|
m_assistantPoints = simLevel->getProperties()->getVanishingPoints();
|
|
|
|
|
|
|
|
if (e.isAltPressed() && e.isCtrlPressed() && !e.isShiftPressed()) {
|
|
|
|
m_addingAssistant = true;
|
|
|
|
bool deletedPoint = false;
|
|
|
|
for (int i = 0; i < m_assistantPoints.size(); i++) {
|
2020-09-28 11:19:47 +13:00
|
|
|
if (areAlmostEqual(m_assistantPoints.at(i).x, pos.x, 12) &&
|
|
|
|
areAlmostEqual(m_assistantPoints.at(i).y, pos.y, 12)) {
|
|
|
|
TRectD pointRect = TRectD(
|
|
|
|
m_assistantPoints.at(i).x - 15, m_assistantPoints.at(i).y - 15,
|
|
|
|
m_assistantPoints.at(i).x + 15, m_assistantPoints.at(i).x + 15);
|
2020-06-17 17:06:09 +12:00
|
|
|
m_assistantPoints.erase(m_assistantPoints.begin() + i);
|
2020-09-28 11:19:47 +13:00
|
|
|
deletedPoint = true;
|
2020-06-17 17:06:09 +12:00
|
|
|
invalidate(pointRect);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!deletedPoint) m_assistantPoints.push_back(pos);
|
|
|
|
simLevel->getProperties()->setVanishingPoints(m_assistantPoints);
|
|
|
|
level->setDirtyFlag(true);
|
2020-09-20 16:06:44 +12:00
|
|
|
invalidate();
|
2020-06-17 17:06:09 +12:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (e.isAltPressed() && e.isShiftPressed() && !e.isCtrlPressed()) {
|
|
|
|
m_addingAssistant = true;
|
|
|
|
std::vector<TPointD> pointsToClear = m_assistantPoints;
|
|
|
|
m_assistantPoints.clear();
|
|
|
|
for (auto point : pointsToClear) {
|
|
|
|
TRectD pointRect =
|
|
|
|
TRectD(point.x - 3, point.y - 3, point.x + 3, point.y + 3);
|
|
|
|
invalidate(pointRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((e.isShiftPressed() || e.isCtrlPressed()) && !e.isAltPressed()) {
|
2020-06-05 14:50:21 +12:00
|
|
|
m_isStraight = true;
|
|
|
|
m_firstPoint = pos;
|
|
|
|
m_lastPoint = pos;
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:06:09 +12:00
|
|
|
if (e.isAltPressed()) {
|
|
|
|
m_snapAssistant = true;
|
|
|
|
m_isStraight = true;
|
|
|
|
m_firstPoint = pos;
|
|
|
|
m_lastPoint = pos;
|
|
|
|
}
|
|
|
|
|
2016-11-24 20:02:18 +13:00
|
|
|
/* update color here since the current style might be switched with numpad
|
|
|
|
* shortcut keys */
|
2017-08-04 15:31:50 +12:00
|
|
|
updateCurrentStyle();
|
2016-11-24 20:02:18 +13:00
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
TRasterP ras = ri->getRaster();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
if (!(m_workRaster && m_backUpRas)) setWorkAndBackupImages();
|
|
|
|
|
|
|
|
m_workRaster->lock();
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
TPointD rasCenter = ras->getCenterD();
|
|
|
|
TPointD point(pos + rasCenter);
|
2019-10-11 16:13:41 +13:00
|
|
|
|
|
|
|
double pressure;
|
|
|
|
if (getApplication()->getCurrentLevelStyle()->getTagId() ==
|
|
|
|
4001) // mypaint brush case
|
|
|
|
pressure = m_enabledPressure && e.isTablet() ? e.m_pressure : 0.5;
|
|
|
|
else
|
2020-06-21 16:58:33 +12:00
|
|
|
pressure = m_enabledPressure ? e.m_pressure : 1.0;
|
|
|
|
m_oldPressure = pressure;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
m_tileSet = new TTileSetFullColor(ras->getSize());
|
|
|
|
m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
mypaint::Brush mypaintBrush;
|
|
|
|
applyToonzBrushSettings(mypaintBrush);
|
|
|
|
m_toonz_brush = new MyPaintToonzBrush(m_workRaster, *this, mypaintBrush);
|
|
|
|
|
|
|
|
m_strokeRect.empty();
|
|
|
|
m_strokeSegmentRect.empty();
|
|
|
|
m_toonz_brush->beginStroke();
|
|
|
|
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
|
2017-11-07 20:24:20 +13:00
|
|
|
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
|
2017-08-04 15:31:50 +12:00
|
|
|
if (!updateRect.isEmpty())
|
|
|
|
ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
|
2017-08-04 15:31:50 +12:00
|
|
|
TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
|
|
|
|
invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
|
2017-11-07 20:24:20 +13:00
|
|
|
invalidateRect +=
|
|
|
|
TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
|
2017-08-04 15:31:50 +12:00
|
|
|
invalidate(invalidateRect.enlarge(2.0));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::leftButtonDrag(const TPointD &pos,
|
|
|
|
const TMouseEvent &e) {
|
2020-06-17 17:06:09 +12:00
|
|
|
if ((e.isCtrlPressed() && e.isAltPressed()) ||
|
|
|
|
(e.isShiftPressed() && e.isAltPressed()) || m_addingAssistant) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-05 14:50:21 +12:00
|
|
|
TRectD invalidateRect;
|
|
|
|
if (m_isStraight) {
|
|
|
|
invalidateRect = TRectD(m_firstPoint, m_lastPoint).enlarge(2);
|
|
|
|
m_lastPoint = pos;
|
2020-06-17 17:06:09 +12:00
|
|
|
if (e.isAltPressed()) {
|
|
|
|
double distance = (m_brushPos.x - m_maxCursorThick + 1) * 0.5;
|
|
|
|
TRectD brushRect =
|
|
|
|
TRectD(TPointD(m_brushPos.x - distance, m_brushPos.y - distance),
|
|
|
|
TPointD(m_brushPos.x + distance, m_brushPos.y + distance));
|
|
|
|
invalidateRect += (brushRect);
|
|
|
|
|
|
|
|
// let's get info about our current location
|
|
|
|
double denominator = m_lastPoint.x - m_firstPoint.x;
|
|
|
|
double numerator = m_lastPoint.y - m_firstPoint.y;
|
|
|
|
if (areAlmostEqual(denominator, 0.0, 0.0001)) {
|
|
|
|
denominator = denominator < 0 ? -0.0001 : 0.0001;
|
|
|
|
}
|
|
|
|
if (areAlmostEqual(numerator, 0.0, 0.0001)) {
|
|
|
|
numerator = numerator < 0 ? -0.0001 : 0.0001;
|
|
|
|
}
|
|
|
|
double slope = (numerator / denominator);
|
|
|
|
double angle = std::atan(slope) * (180 / 3.14159);
|
|
|
|
|
|
|
|
// now let's get the angle of each of the assistant points
|
|
|
|
std::vector<double> anglesToAssistants;
|
|
|
|
for (auto point : m_assistantPoints) {
|
|
|
|
double newDenominator = point.x - m_firstPoint.x;
|
|
|
|
double newNumerator = point.y - m_firstPoint.y;
|
|
|
|
if (areAlmostEqual(newDenominator, 0.0, 0.0001)) {
|
|
|
|
newDenominator = newDenominator < 0 ? -0.0001 : 0.0001;
|
|
|
|
}
|
|
|
|
if (areAlmostEqual(newNumerator, 0.0, 0.0001)) {
|
|
|
|
newNumerator = newNumerator < 0 ? -0.0001 : 0.0001;
|
|
|
|
}
|
|
|
|
|
|
|
|
double newSlope = (newNumerator / newDenominator);
|
|
|
|
double newAngle = std::atan(newSlope) * (180 / 3.14159);
|
|
|
|
anglesToAssistants.push_back(newAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// figure out which angle is closer
|
|
|
|
TPointD pointToUse = TPointD(0.0, 0.0);
|
|
|
|
double difference = 360;
|
|
|
|
for (int i = 0; i < anglesToAssistants.size(); i++) {
|
|
|
|
double newDifference = abs(angle - anglesToAssistants.at(i));
|
|
|
|
if (newDifference < difference || (180 - newDifference) < difference) {
|
|
|
|
difference = std::min(newDifference, (180 - newDifference));
|
|
|
|
pointToUse = m_assistantPoints.at(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double distanceFirstToLast =
|
|
|
|
std::sqrt(std::pow((m_lastPoint.x - m_firstPoint.x), 2) +
|
|
|
|
std::pow((m_lastPoint.y - m_firstPoint.y), 2));
|
|
|
|
double distanceLastToAssistant =
|
|
|
|
std::sqrt(std::pow((pointToUse.x - m_lastPoint.x), 2) +
|
|
|
|
std::pow((pointToUse.y - m_lastPoint.y), 2));
|
|
|
|
double distanceFirstToAssistant =
|
|
|
|
std::sqrt(std::pow((pointToUse.x - m_firstPoint.x), 2) +
|
|
|
|
std::pow((pointToUse.y - m_firstPoint.y), 2));
|
|
|
|
|
|
|
|
if (distanceFirstToAssistant == 0.0) distanceFirstToAssistant = 0.001;
|
|
|
|
|
|
|
|
double ratio = distanceFirstToLast / distanceFirstToAssistant;
|
|
|
|
|
|
|
|
double newX;
|
|
|
|
double newY;
|
|
|
|
|
|
|
|
// flip the direction if the last point is farther than the first point
|
|
|
|
if (distanceFirstToAssistant < distanceLastToAssistant &&
|
|
|
|
distanceFirstToLast < distanceLastToAssistant) {
|
|
|
|
newX = ((1 + ratio) * m_firstPoint.x) - (ratio * pointToUse.x);
|
|
|
|
newY = ((1 + ratio) * m_firstPoint.y) - (ratio * pointToUse.y);
|
|
|
|
} else {
|
|
|
|
newX = ((1 - ratio) * m_firstPoint.x) + (ratio * pointToUse.x);
|
|
|
|
newY = ((1 - ratio) * m_firstPoint.y) + (ratio * pointToUse.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastPoint = TPointD(newX, newY);
|
|
|
|
invalidateRect += TRectD(m_firstPoint, m_lastPoint).enlarge(2);
|
|
|
|
} else if (e.isCtrlPressed()) {
|
2020-06-05 14:50:21 +12:00
|
|
|
double distance = (m_brushPos.x - m_maxCursorThick + 1) * 0.5;
|
|
|
|
TRectD brushRect =
|
|
|
|
TRectD(TPointD(m_brushPos.x - distance, m_brushPos.y - distance),
|
|
|
|
TPointD(m_brushPos.x + distance, m_brushPos.y + distance));
|
|
|
|
invalidateRect += (brushRect);
|
|
|
|
double denominator = m_lastPoint.x - m_firstPoint.x;
|
|
|
|
if (denominator == 0) denominator == 0.001;
|
2020-09-20 16:06:44 +12:00
|
|
|
double slope = ((m_lastPoint.y - m_firstPoint.y) / denominator);
|
2020-09-14 06:42:34 +12:00
|
|
|
double radAngle = std::atan(abs(slope));
|
2020-09-20 16:06:44 +12:00
|
|
|
double angle = radAngle * (180 / 3.14159);
|
2020-09-14 06:42:34 +12:00
|
|
|
if (abs(angle) >= 82.5)
|
2020-06-05 14:50:21 +12:00
|
|
|
m_lastPoint.x = m_firstPoint.x;
|
2020-09-14 06:42:34 +12:00
|
|
|
else if (abs(angle) < 7.5)
|
2020-06-05 14:50:21 +12:00
|
|
|
m_lastPoint.y = m_firstPoint.y;
|
|
|
|
else {
|
2020-09-20 16:06:44 +12:00
|
|
|
double xDistance = m_lastPoint.x - m_firstPoint.x;
|
|
|
|
double yDistance = m_lastPoint.y - m_firstPoint.y;
|
|
|
|
|
|
|
|
double totalDistance =
|
|
|
|
std::sqrt(std::pow(xDistance, 2) + std::pow(yDistance, 2));
|
|
|
|
double xLength = 0.0;
|
|
|
|
double yLength = 0.0;
|
|
|
|
if (angle >= 7.5 && angle < 22.5) {
|
|
|
|
yLength = std::sin(15 * (3.14159 / 180)) * totalDistance;
|
|
|
|
xLength = std::cos(15 * (3.14159 / 180)) * totalDistance;
|
|
|
|
} else if (angle >= 22.5 && angle < 37.5) {
|
|
|
|
yLength = std::sin(30 * (3.14159 / 180)) * totalDistance;
|
|
|
|
xLength = std::cos(30 * (3.14159 / 180)) * totalDistance;
|
|
|
|
} else if (angle >= 37.5 && angle < 52.5) {
|
|
|
|
yLength = std::sin(45 * (3.14159 / 180)) * totalDistance;
|
|
|
|
xLength = std::cos(45 * (3.14159 / 180)) * totalDistance;
|
|
|
|
} else if (angle >= 52.5 && angle < 67.5) {
|
|
|
|
yLength = std::sin(60 * (3.14159 / 180)) * totalDistance;
|
|
|
|
xLength = std::cos(60 * (3.14159 / 180)) * totalDistance;
|
|
|
|
} else if (angle >= 67.5 && angle < 82.5) {
|
|
|
|
yLength = std::sin(75 * (3.14159 / 180)) * totalDistance;
|
|
|
|
xLength = std::cos(75 * (3.14159 / 180)) * totalDistance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yDistance == abs(yDistance)) {
|
|
|
|
m_lastPoint.y = m_firstPoint.y + yLength;
|
|
|
|
} else {
|
|
|
|
m_lastPoint.y = m_firstPoint.y - yLength;
|
|
|
|
}
|
|
|
|
if (xDistance == abs(xDistance)) {
|
|
|
|
m_lastPoint.x = m_firstPoint.x + xLength;
|
|
|
|
} else {
|
|
|
|
m_lastPoint.x = m_firstPoint.x - xLength;
|
|
|
|
}
|
2020-06-05 14:50:21 +12:00
|
|
|
}
|
|
|
|
}
|
2020-06-21 16:58:33 +12:00
|
|
|
|
|
|
|
// keep this here for possible eventual variable width
|
|
|
|
// if (getApplication()->getCurrentLevelStyle()->getTagId() ==
|
|
|
|
// 4001) // mypaint brush case
|
|
|
|
// m_oldPressure = m_enabledPressure && e.isTablet() ? e.m_pressure : 0.5;
|
|
|
|
// else
|
|
|
|
// m_oldPressure = m_enabledPressure ? e.m_pressure : 1.0;
|
|
|
|
|
2020-06-05 14:50:21 +12:00
|
|
|
m_mousePos = pos;
|
|
|
|
m_brushPos = pos;
|
|
|
|
invalidate(invalidateRect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
TPointD previousBrushPos = m_brushPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
m_brushPos = m_mousePos = pos;
|
2017-05-31 22:53:58 +12:00
|
|
|
m_mouseEvent = e;
|
|
|
|
TRasterImageP ri = (TRasterImageP)getImage(true);
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!ri) return;
|
|
|
|
|
2018-11-05 18:37:27 +13:00
|
|
|
if (!m_toonz_brush) return;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TRasterP ras = ri->getRaster();
|
2017-08-04 15:31:50 +12:00
|
|
|
TPointD rasCenter = ras->getCenterD();
|
|
|
|
TPointD point(pos + rasCenter);
|
2019-10-11 16:13:41 +13:00
|
|
|
double pressure;
|
|
|
|
if (getApplication()->getCurrentLevelStyle()->getTagId() ==
|
|
|
|
4001) // mypaint brush case
|
|
|
|
pressure = m_enabledPressure && e.isTablet() ? e.m_pressure : 0.5;
|
|
|
|
else
|
|
|
|
pressure = m_enabledPressure ? e.m_pressure : 1.0;
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
m_strokeSegmentRect.empty();
|
|
|
|
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
|
2017-11-07 20:24:20 +13:00
|
|
|
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
|
2017-08-04 15:31:50 +12:00
|
|
|
if (!updateRect.isEmpty())
|
|
|
|
ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
|
2020-06-05 14:50:21 +12:00
|
|
|
invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
|
2017-08-04 15:31:50 +12:00
|
|
|
invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
|
2017-11-07 20:24:20 +13:00
|
|
|
invalidateRect +=
|
|
|
|
TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
|
2017-08-04 15:31:50 +12:00
|
|
|
invalidate(invalidateRect.enlarge(2.0));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::leftButtonUp(const TPointD &pos,
|
|
|
|
const TMouseEvent &e) {
|
2017-08-04 15:31:50 +12:00
|
|
|
TPointD previousBrushPos = m_brushPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
m_brushPos = m_mousePos = pos;
|
|
|
|
|
2020-06-17 17:06:09 +12:00
|
|
|
if ((e.isAltPressed() && e.isCtrlPressed()) ||
|
|
|
|
(e.isShiftPressed() && e.isAltPressed()) || m_addingAssistant) {
|
|
|
|
m_addingAssistant = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
|
|
if (!ri) return;
|
|
|
|
|
2018-12-20 14:52:15 +13:00
|
|
|
if (!m_toonz_brush) return;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TRasterP ras = ri->getRaster();
|
2017-08-04 15:31:50 +12:00
|
|
|
TPointD rasCenter = ras->getCenterD();
|
2020-06-05 14:50:21 +12:00
|
|
|
TPointD point;
|
2020-06-17 17:06:09 +12:00
|
|
|
if (e.isCtrlPressed() || m_snapAssistant || e.isAltPressed())
|
2020-06-05 14:50:21 +12:00
|
|
|
point = TPointD(m_lastPoint + rasCenter);
|
2020-06-17 17:06:09 +12:00
|
|
|
else
|
|
|
|
point = TPointD(pos + rasCenter);
|
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
double pressure;
|
|
|
|
if (getApplication()->getCurrentLevelStyle()->getTagId() ==
|
|
|
|
4001) // mypaint brush case
|
|
|
|
pressure = m_enabledPressure && e.isTablet() ? e.m_pressure : 0.5;
|
|
|
|
else
|
|
|
|
pressure = m_enabledPressure ? e.m_pressure : 1.0;
|
2020-06-21 16:58:33 +12:00
|
|
|
if (m_isStraight) {
|
|
|
|
pressure = m_oldPressure;
|
|
|
|
}
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
m_strokeSegmentRect.empty();
|
|
|
|
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
|
|
|
|
m_toonz_brush->endStroke();
|
2017-11-07 20:24:20 +13:00
|
|
|
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
|
2017-08-04 15:31:50 +12:00
|
|
|
if (!updateRect.isEmpty())
|
|
|
|
ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
|
2017-08-04 15:31:50 +12:00
|
|
|
TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
|
|
|
|
invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
|
2017-11-07 20:24:20 +13:00
|
|
|
invalidateRect +=
|
|
|
|
TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
|
2017-08-04 15:31:50 +12:00
|
|
|
invalidate(invalidateRect.enlarge(2.0));
|
|
|
|
|
|
|
|
if (m_toonz_brush) {
|
|
|
|
delete m_toonz_brush;
|
|
|
|
m_toonz_brush = 0;
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
m_lastRect.empty();
|
2016-06-15 18:43:10 +12:00
|
|
|
m_workRaster->unlock();
|
|
|
|
|
|
|
|
if (m_tileSet->getTileCount() > 0) {
|
|
|
|
delete m_tileSaver;
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
|
|
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
|
|
TFrameId frameId = getCurrentFid();
|
2017-08-04 15:31:50 +12:00
|
|
|
TRasterP subras = ras->extract(m_strokeRect)->clone();
|
2017-11-07 20:24:20 +13:00
|
|
|
TUndoManager::manager()->add(new FullColorBrushUndo(
|
|
|
|
m_tileSet, simLevel.getPointer(), frameId, m_isFrameCreated, subras,
|
|
|
|
m_strokeRect.getP00()));
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
notifyImageChanged();
|
|
|
|
m_strokeRect.empty();
|
2020-06-17 17:06:09 +12:00
|
|
|
m_mousePressed = false;
|
|
|
|
m_isStraight = false;
|
|
|
|
m_snapAssistant = false;
|
2020-06-21 16:58:33 +12:00
|
|
|
m_oldPressure = -1.0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
struct Locals {
|
|
|
|
FullColorBrushTool *m_this;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setValue(TIntPairProperty &prop,
|
|
|
|
const TIntPairProperty::Value &value) {
|
|
|
|
prop.setValue(value);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_this->onPropertyChanged(prop.getName());
|
|
|
|
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void addMinMax(TIntPairProperty &prop, double add) {
|
|
|
|
const TIntPairProperty::Range &range = prop.getRange();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TIntPairProperty::Value value = prop.getValue();
|
|
|
|
value.second =
|
|
|
|
tcrop<double>(value.second + add, range.first, range.second);
|
|
|
|
value.first = tcrop<double>(value.first + add, range.first, range.second);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
setValue(prop, value);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-01-20 00:46:50 +13:00
|
|
|
void addMinMaxSeparate(TIntPairProperty &prop, double min, double max) {
|
|
|
|
if (min == 0.0 && max == 0.0) return;
|
|
|
|
const TIntPairProperty::Range &range = prop.getRange();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-01-20 00:46:50 +13:00
|
|
|
TIntPairProperty::Value value = prop.getValue();
|
|
|
|
value.first += min;
|
|
|
|
value.second += max;
|
|
|
|
if (value.first > value.second) value.first = value.second;
|
|
|
|
value.first = tcrop<double>(value.first, range.first, range.second);
|
|
|
|
value.second = tcrop<double>(value.second, range.first, range.second);
|
|
|
|
|
|
|
|
setValue(prop, value);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-01-20 00:46:50 +13:00
|
|
|
} locals = {this};
|
2016-05-13 22:49:17 +12:00
|
|
|
|
2017-01-20 00:46:50 +13:00
|
|
|
// if (e.isAltPressed() && !e.isCtrlPressed()) {
|
|
|
|
// const TPointD &diff = pos - m_mousePos;
|
|
|
|
// double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-01-20 00:46:50 +13:00
|
|
|
// locals.addMinMax(m_thickness, int(add));
|
|
|
|
//} else
|
2020-06-17 17:06:09 +12:00
|
|
|
// if (e.isCtrlPressed() && e.isAltPressed()) {
|
|
|
|
// const TPointD &diff = pos - m_mousePos;
|
|
|
|
// double max = diff.x / 2;
|
|
|
|
// double min = diff.y / 2;
|
2017-01-20 00:46:50 +13:00
|
|
|
|
2020-06-17 17:06:09 +12:00
|
|
|
// locals.addMinMaxSeparate(m_thickness, int(min), int(max));
|
|
|
|
//} else {
|
|
|
|
m_brushPos = pos;
|
|
|
|
//}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_mousePos = pos;
|
2020-09-28 11:19:47 +13:00
|
|
|
|
|
|
|
if (e.isAltPressed() && e.isCtrlPressed() && !e.isShiftPressed()) {
|
|
|
|
if (m_highlightAssistant != -1 &&
|
|
|
|
m_highlightAssistant < m_assistantPoints.size()) {
|
|
|
|
TRectD pointRect =
|
|
|
|
TRectD(m_assistantPoints.at(m_highlightAssistant).x - 15,
|
|
|
|
m_assistantPoints.at(m_highlightAssistant).y - 15,
|
|
|
|
m_assistantPoints.at(m_highlightAssistant).x + 15,
|
|
|
|
m_assistantPoints.at(m_highlightAssistant).x + 15);
|
|
|
|
invalidate(pointRect);
|
|
|
|
}
|
|
|
|
m_highlightAssistant = -1;
|
|
|
|
for (int i = 0; i < m_assistantPoints.size(); i++) {
|
|
|
|
if (areAlmostEqual(m_assistantPoints.at(i).x, pos.x, 12) &&
|
|
|
|
areAlmostEqual(m_assistantPoints.at(i).y, pos.y, 12)) {
|
|
|
|
m_highlightAssistant = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (m_highlightAssistant != -1 &&
|
|
|
|
m_highlightAssistant < m_assistantPoints.size()) {
|
|
|
|
TRectD pointRect =
|
|
|
|
TRectD(m_assistantPoints.at(m_highlightAssistant).x - 15,
|
|
|
|
m_assistantPoints.at(m_highlightAssistant).y - 15,
|
|
|
|
m_assistantPoints.at(m_highlightAssistant).x + 15,
|
|
|
|
m_assistantPoints.at(m_highlightAssistant).x + 15);
|
|
|
|
invalidate(pointRect);
|
|
|
|
m_highlightAssistant = -1;
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::draw() {
|
|
|
|
if (TRasterImageP ri = TRasterImageP(getImage(false))) {
|
2020-06-05 14:50:21 +12:00
|
|
|
if (m_isStraight) {
|
|
|
|
tglDrawSegment(m_firstPoint, m_lastPoint);
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:06:09 +12:00
|
|
|
if (m_assistantPoints.size() > 0) {
|
2020-09-28 11:19:47 +13:00
|
|
|
for (int i = 0; i < m_assistantPoints.size(); i++) {
|
|
|
|
if (m_highlightAssistant == i) {
|
|
|
|
glColor3d(1.0, 0.0, 0.0);
|
|
|
|
tglDrawDisk(m_assistantPoints.at(i), 15.0);
|
|
|
|
} else {
|
|
|
|
glColor3d(0.0, 1.0, 0.0);
|
|
|
|
tglDrawCircle(m_assistantPoints.at(i), 5.0);
|
|
|
|
glColor3d(1.0, 1.0, 0.0);
|
|
|
|
tglDrawCircle(m_assistantPoints.at(i), 8.0);
|
|
|
|
}
|
2020-06-17 17:06:09 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 18:03:05 +12:00
|
|
|
// If toggled off, don't draw brush outline
|
|
|
|
if (!Preferences::instance()->isCursorOutlineEnabled()) return;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterP ras = ri->getRaster();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
double alpha = 1.0;
|
2017-08-04 15:31:50 +12:00
|
|
|
double alphaRadius = 3.0;
|
2017-11-07 20:24:20 +13:00
|
|
|
double pixelSize = sqrt(tglGetPixelSize2());
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
// circles with lesser radius looks more bold
|
|
|
|
// to avoid these effect we'll reduce alpha for small radiuses
|
2017-11-07 20:24:20 +13:00
|
|
|
double minX = m_minCursorThick / (alphaRadius * pixelSize);
|
|
|
|
double maxX = m_maxCursorThick / (alphaRadius * pixelSize);
|
|
|
|
double minAlpha = alpha * (1.0 - 1.0 / (1.0 + minX));
|
|
|
|
double maxAlpha = alpha * (1.0 - 1.0 / (1.0 + maxX));
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
tglEnableBlending();
|
|
|
|
tglEnableLineSmooth(true, 0.5);
|
|
|
|
|
|
|
|
if (m_minCursorThick < m_maxCursorThick - pixelSize) {
|
|
|
|
glColor4d(1.0, 1.0, 1.0, minAlpha);
|
2017-11-07 20:24:20 +13:00
|
|
|
tglDrawCircle(m_brushPos, (m_minCursorThick + 1) * 0.5 - pixelSize);
|
2017-08-04 15:31:50 +12:00
|
|
|
glColor4d(0.0, 0.0, 0.0, minAlpha);
|
2017-11-07 20:24:20 +13:00
|
|
|
tglDrawCircle(m_brushPos, (m_minCursorThick + 1) * 0.5);
|
2017-08-04 15:31:50 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
glColor4d(1.0, 1.0, 1.0, maxAlpha);
|
2017-11-07 20:24:20 +13:00
|
|
|
tglDrawCircle(m_brushPos, (m_maxCursorThick + 1) * 0.5 - pixelSize);
|
2017-08-04 15:31:50 +12:00
|
|
|
glColor4d(0.0, 0.0, 0.0, maxAlpha);
|
2017-11-07 20:24:20 +13:00
|
|
|
tglDrawCircle(m_brushPos, (m_maxCursorThick + 1) * 0.5);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
glPopAttrib();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
void FullColorBrushTool::onEnter() { updateCurrentStyle(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::onLeave() {
|
2017-08-04 15:31:50 +12:00
|
|
|
m_minCursorThick = 0;
|
|
|
|
m_maxCursorThick = 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPropertyGroup *FullColorBrushTool::getProperties(int targetType) {
|
|
|
|
if (!m_presetsLoaded) initPresets();
|
|
|
|
return &m_prop;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::onImageChanged() { setWorkAndBackupImages(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::setWorkAndBackupImages() {
|
|
|
|
TRasterImageP ri = (TRasterImageP)getImage(false, 1);
|
|
|
|
if (!ri) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterP ras = ri->getRaster();
|
|
|
|
TDimension dim = ras->getSize();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-06-04 06:19:53 +12:00
|
|
|
if (!m_workRaster || m_workRaster->getLx() != dim.lx ||
|
|
|
|
m_workRaster->getLy() != dim.ly)
|
2016-06-15 18:43:10 +12:00
|
|
|
m_workRaster = TRaster32P(dim);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-06-04 06:19:53 +12:00
|
|
|
if (!m_backUpRas || m_backUpRas->getLx() != dim.lx ||
|
|
|
|
m_backUpRas->getLy() != dim.ly ||
|
2016-06-15 18:43:10 +12:00
|
|
|
m_backUpRas->getPixelSize() != ras->getPixelSize())
|
|
|
|
m_backUpRas = ras->create(dim.lx, dim.ly);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_strokeRect.empty();
|
|
|
|
m_lastRect.empty();
|
2020-06-17 17:06:09 +12:00
|
|
|
|
|
|
|
TXshLevelHandle *level = getApplication()->getCurrentLevel();
|
|
|
|
TXshSimpleLevel *sl;
|
|
|
|
if (level) sl = level->getSimpleLevel();
|
|
|
|
if (sl) {
|
|
|
|
if (sl->getProperties()->getVanishingPoints() != m_assistantPoints) {
|
|
|
|
m_assistantPoints = sl->getProperties()->getVanishingPoints();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool FullColorBrushTool::onPropertyChanged(std::string propertyName) {
|
2019-09-15 01:50:49 +12:00
|
|
|
if (m_propertyUpdating) return true;
|
|
|
|
|
2019-09-14 04:16:27 +12:00
|
|
|
updateCurrentStyle();
|
|
|
|
|
|
|
|
if (propertyName == "Preset:") {
|
|
|
|
if (m_preset.getValue() != CUSTOM_WSTR)
|
|
|
|
loadPreset();
|
|
|
|
else // Chose <custom>, go back to last saved brush settings
|
|
|
|
loadLastBrush();
|
|
|
|
|
|
|
|
FullcolorBrushPreset = m_preset.getValueAsString();
|
2019-09-15 01:50:49 +12:00
|
|
|
m_propertyUpdating = true;
|
2019-09-14 04:16:27 +12:00
|
|
|
getApplication()->getCurrentTool()->notifyToolChanged();
|
2019-09-15 01:50:49 +12:00
|
|
|
m_propertyUpdating = false;
|
2019-09-14 04:16:27 +12:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
FullcolorBrushMinSize = m_thickness.getValue().first;
|
|
|
|
FullcolorBrushMaxSize = m_thickness.getValue().second;
|
2016-06-29 22:49:17 +12:00
|
|
|
FullcolorPressureSensitivity = m_pressure.getValue();
|
2016-06-15 18:43:10 +12:00
|
|
|
FullcolorBrushHardness = m_hardness.getValue();
|
|
|
|
FullcolorMinOpacity = m_opacity.getValue().first;
|
|
|
|
FullcolorMaxOpacity = m_opacity.getValue().second;
|
2017-08-04 15:31:50 +12:00
|
|
|
FullcolorModifierSize = m_modifierSize.getValue();
|
|
|
|
FullcolorModifierOpacity = m_modifierOpacity.getValue();
|
2017-10-17 02:54:19 +13:00
|
|
|
FullcolorModifierEraser = m_modifierEraser.getValue() ? 1 : 0;
|
|
|
|
FullcolorModifierLockAlpha = m_modifierLockAlpha.getValue() ? 1 : 0;
|
2017-08-04 15:31:50 +12:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_preset.getValue() != CUSTOM_WSTR) {
|
|
|
|
m_preset.setValue(CUSTOM_WSTR);
|
2019-09-14 04:16:27 +12:00
|
|
|
FullcolorBrushPreset = m_preset.getValueAsString();
|
2019-09-15 01:50:49 +12:00
|
|
|
m_propertyUpdating = true;
|
2016-06-15 18:43:10 +12:00
|
|
|
getApplication()->getCurrentTool()->notifyToolChanged();
|
2019-09-15 01:50:49 +12:00
|
|
|
m_propertyUpdating = false;
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::initPresets() {
|
|
|
|
if (!m_presetsLoaded) {
|
|
|
|
// If necessary, load the presets from file
|
|
|
|
m_presetsLoaded = true;
|
2020-10-22 03:59:24 +13:00
|
|
|
m_presetsManager.load(ToonzFolder::getMyModuleDir() + "brush_raster.txt");
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Rebuild the presets property entries
|
|
|
|
const std::set<BrushData> &presets = m_presetsManager.presets();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_preset.deleteAllValues();
|
|
|
|
m_preset.addValue(CUSTOM_WSTR);
|
2018-06-04 15:18:43 +12:00
|
|
|
m_preset.setItemUIName(CUSTOM_WSTR, tr("<custom>"));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::set<BrushData>::const_iterator it, end = presets.end();
|
|
|
|
for (it = presets.begin(); it != end; ++it) m_preset.addValue(it->m_name);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::loadPreset() {
|
|
|
|
const std::set<BrushData> &presets = m_presetsManager.presets();
|
|
|
|
std::set<BrushData>::const_iterator it;
|
|
|
|
|
|
|
|
it = presets.find(BrushData(m_preset.getValue()));
|
|
|
|
if (it == presets.end()) return;
|
|
|
|
|
|
|
|
const BrushData &preset = *it;
|
|
|
|
|
|
|
|
try // Don't bother with RangeErrors
|
|
|
|
{
|
|
|
|
m_thickness.setValue(
|
|
|
|
TIntPairProperty::Value(std::max((int)preset.m_min, 1), preset.m_max));
|
|
|
|
m_hardness.setValue(preset.m_hardness, true);
|
|
|
|
m_opacity.setValue(
|
|
|
|
TDoublePairProperty::Value(preset.m_opacityMin, preset.m_opacityMax));
|
|
|
|
m_pressure.setValue(preset.m_pressure);
|
2017-08-04 15:31:50 +12:00
|
|
|
m_modifierSize.setValue(preset.m_modifierSize);
|
|
|
|
m_modifierOpacity.setValue(preset.m_modifierOpacity);
|
2017-10-17 02:54:19 +13:00
|
|
|
m_modifierEraser.setValue(preset.m_modifierEraser);
|
|
|
|
m_modifierLockAlpha.setValue(preset.m_modifierLockAlpha);
|
2016-06-15 18:43:10 +12:00
|
|
|
} catch (...) {
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::addPreset(QString name) {
|
|
|
|
// Build the preset
|
|
|
|
BrushData preset(name.toStdWString());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-10-17 02:54:19 +13:00
|
|
|
preset.m_min = m_thickness.getValue().first;
|
|
|
|
preset.m_max = m_thickness.getValue().second;
|
|
|
|
preset.m_hardness = m_hardness.getValue();
|
|
|
|
preset.m_opacityMin = m_opacity.getValue().first;
|
|
|
|
preset.m_opacityMax = m_opacity.getValue().second;
|
|
|
|
preset.m_pressure = m_pressure.getValue();
|
|
|
|
preset.m_modifierSize = m_modifierSize.getValue();
|
|
|
|
preset.m_modifierOpacity = m_modifierOpacity.getValue();
|
|
|
|
preset.m_modifierEraser = m_modifierEraser.getValue();
|
|
|
|
preset.m_modifierLockAlpha = m_modifierLockAlpha.getValue();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Pass the preset to the manager
|
|
|
|
m_presetsManager.addPreset(preset);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Reinitialize the associated preset enum
|
|
|
|
initPresets();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Set the value to the specified one
|
|
|
|
m_preset.setValue(preset.m_name);
|
2020-10-23 06:03:17 +13:00
|
|
|
FullcolorBrushPreset = m_preset.getValueAsString();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorBrushTool::removePreset() {
|
|
|
|
std::wstring name(m_preset.getValue());
|
|
|
|
if (name == CUSTOM_WSTR) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_presetsManager.removePreset(name);
|
|
|
|
initPresets();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// No parameter change, and set the preset value to custom
|
|
|
|
m_preset.setValue(CUSTOM_WSTR);
|
2020-10-23 06:03:17 +13:00
|
|
|
FullcolorBrushPreset = m_preset.getValueAsString();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-11-24 20:02:18 +13:00
|
|
|
//------------------------------------------------------------------
|
2019-09-14 04:16:27 +12:00
|
|
|
|
|
|
|
void FullColorBrushTool::loadLastBrush() {
|
|
|
|
m_thickness.setValue(
|
|
|
|
TIntPairProperty::Value(FullcolorBrushMinSize, FullcolorBrushMaxSize));
|
|
|
|
m_pressure.setValue(FullcolorPressureSensitivity ? 1 : 0);
|
|
|
|
m_opacity.setValue(
|
|
|
|
TDoublePairProperty::Value(FullcolorMinOpacity, FullcolorMaxOpacity));
|
|
|
|
m_hardness.setValue(FullcolorBrushHardness);
|
|
|
|
m_modifierSize.setValue(FullcolorModifierSize);
|
|
|
|
m_modifierOpacity.setValue(FullcolorModifierOpacity);
|
|
|
|
m_modifierEraser.setValue(FullcolorModifierEraser ? true : false);
|
|
|
|
m_modifierLockAlpha.setValue(FullcolorModifierLockAlpha ? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2016-11-24 20:02:18 +13:00
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
void FullColorBrushTool::updateCurrentStyle() {
|
|
|
|
m_currentColor = TPixel32::Black;
|
|
|
|
if (TTool::Application *app = getApplication()) {
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
m_currentColor = TPixel32::Red;
|
2017-11-07 20:24:20 +13:00
|
|
|
} else if (TPalette *plt = app->getCurrentPalette()->getPalette()) {
|
2017-08-04 15:31:50 +12:00
|
|
|
int style = app->getCurrentLevelStyleIndex();
|
|
|
|
TColorStyle *colorStyle = plt->getStyle(style);
|
|
|
|
m_currentColor = colorStyle->getMainColor();
|
|
|
|
}
|
2016-11-24 20:02:18 +13:00
|
|
|
}
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
int prevMinCursorThick = m_minCursorThick;
|
|
|
|
int prevMaxCursorThick = m_maxCursorThick;
|
|
|
|
|
|
|
|
m_enabledPressure = m_pressure.getValue();
|
|
|
|
if (TMyPaintBrushStyle *brushStyle = getBrushStyle()) {
|
2017-11-07 20:24:20 +13:00
|
|
|
double radiusLog = brushStyle->getBrush().getBaseValue(
|
|
|
|
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC) +
|
|
|
|
m_modifierSize.getValue() * log(2.0);
|
|
|
|
double radius = exp(radiusLog);
|
|
|
|
m_minCursorThick = m_maxCursorThick = (int)round(2.0 * radius);
|
2017-08-04 15:31:50 +12:00
|
|
|
} else {
|
|
|
|
m_minCursorThick = std::max(m_thickness.getValue().first, 1);
|
2017-11-07 20:24:20 +13:00
|
|
|
m_maxCursorThick =
|
|
|
|
std::max(m_thickness.getValue().second, m_minCursorThick);
|
2019-10-11 16:13:41 +13:00
|
|
|
if (!m_enabledPressure) m_minCursorThick = m_maxCursorThick;
|
2017-08-04 15:31:50 +12:00
|
|
|
}
|
|
|
|
|
2018-05-21 18:33:03 +12:00
|
|
|
// if this function is called from onEnter(), the clipping rect will not be
|
|
|
|
// set in order to update whole viewer.
|
|
|
|
if (prevMinCursorThick == 0 && prevMaxCursorThick == 0) return;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
if (m_minCursorThick != prevMinCursorThick ||
|
|
|
|
m_maxCursorThick != prevMaxCursorThick) {
|
|
|
|
TRectD rect(
|
|
|
|
m_brushPos - TPointD(m_maxCursorThick + 2, m_maxCursorThick + 2),
|
|
|
|
m_brushPos + TPointD(m_maxCursorThick + 2, m_maxCursorThick + 2));
|
2017-08-04 15:31:50 +12:00
|
|
|
invalidate(rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
double FullColorBrushTool::restartBrushTimer() {
|
2017-11-07 20:24:20 +13:00
|
|
|
double dtime = m_brushTimer.nsecsElapsed() * 1e-9;
|
2017-08-04 15:31:50 +12:00
|
|
|
m_brushTimer.restart();
|
|
|
|
return dtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TMyPaintBrushStyle *FullColorBrushTool::getBrushStyle() {
|
2017-08-04 15:31:50 +12:00
|
|
|
if (TTool::Application *app = getApplication())
|
2017-11-07 20:24:20 +13:00
|
|
|
return dynamic_cast<TMyPaintBrushStyle *>(app->getCurrentLevelStyle());
|
2017-08-04 15:31:50 +12:00
|
|
|
return 0;
|
2016-11-24 20:02:18 +13:00
|
|
|
}
|
|
|
|
|
2017-08-04 15:31:50 +12:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
void FullColorBrushTool::applyClassicToonzBrushSettings(
|
|
|
|
mypaint::Brush &mypaintBrush) {
|
|
|
|
const double precision = 1e-5;
|
2017-08-04 15:31:50 +12:00
|
|
|
const double hardnessOpacity = 0.1;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
double minThickness = 0.5 * m_thickness.getValue().first;
|
|
|
|
double maxThickness = 0.5 * m_thickness.getValue().second;
|
|
|
|
double minOpacity = 0.01 * m_opacity.getValue().first;
|
|
|
|
double maxOpacity = 0.01 * m_opacity.getValue().second;
|
|
|
|
double hardness = 0.01 * m_hardness.getValue();
|
2017-08-04 15:31:50 +12:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TPixelD color = PixelConverter<TPixelD>::from(m_currentColor);
|
|
|
|
double colorH = 0.0;
|
|
|
|
double colorS = 0.0;
|
|
|
|
double colorV = 0.0;
|
2017-08-04 15:31:50 +12:00
|
|
|
RGB2HSV(color.r, color.g, color.b, &colorH, &colorS, &colorV);
|
|
|
|
|
|
|
|
// avoid log(0)
|
2017-11-07 20:24:20 +13:00
|
|
|
if (minThickness < precision) minThickness = precision;
|
|
|
|
if (maxThickness < precision) maxThickness = precision;
|
2017-08-04 15:31:50 +12:00
|
|
|
|
|
|
|
// tune hardness opacity for better visual softness
|
|
|
|
hardness *= hardness;
|
2017-11-07 20:24:20 +13:00
|
|
|
double opacityAmplifier = 1.0 - hardnessOpacity + hardness * hardnessOpacity;
|
2017-08-04 15:31:50 +12:00
|
|
|
minOpacity *= opacityAmplifier;
|
|
|
|
maxOpacity *= opacityAmplifier;
|
|
|
|
|
|
|
|
// reset
|
|
|
|
mypaintBrush.fromDefaults();
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY, 1.0);
|
2017-11-07 20:24:20 +13:00
|
|
|
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_OPAQUE_MULTIPLY,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 0);
|
|
|
|
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_HARDNESS,
|
|
|
|
0.5 * hardness + 0.5);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_H, colorH / 360.0);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_S, colorS);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_V, colorV);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_DABS_PER_ACTUAL_RADIUS,
|
|
|
|
5.0 + hardness * 10.0);
|
2017-08-04 15:31:50 +12:00
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_DABS_PER_BASIC_RADIUS, 0.0);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_DABS_PER_SECOND, 0.0);
|
|
|
|
|
|
|
|
// thickness may be dynamic
|
|
|
|
if (minThickness + precision >= maxThickness) {
|
2017-11-07 20:24:20 +13:00
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
|
|
log(maxThickness));
|
|
|
|
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 0);
|
2017-08-04 15:31:50 +12:00
|
|
|
} else {
|
2017-11-07 20:24:20 +13:00
|
|
|
double minThicknessLog = log(minThickness);
|
|
|
|
double maxThicknessLog = log(maxThickness);
|
|
|
|
double baseThicknessLog = 0.5 * (minThicknessLog + maxThicknessLog);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
|
|
baseThicknessLog);
|
|
|
|
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 2);
|
|
|
|
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 0, 0.0,
|
|
|
|
minThicknessLog - baseThicknessLog);
|
|
|
|
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 1, 1.0,
|
|
|
|
maxThicknessLog - baseThicknessLog);
|
2017-08-04 15:31:50 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
// opacity may be dynamic
|
|
|
|
if (minOpacity + precision >= maxOpacity) {
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE, maxOpacity);
|
2017-11-07 20:24:20 +13:00
|
|
|
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_OPAQUE,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 0);
|
2017-08-04 15:31:50 +12:00
|
|
|
} else {
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE, minOpacity);
|
2017-11-07 20:24:20 +13:00
|
|
|
mypaintBrush.setMappingN(MYPAINT_BRUSH_SETTING_OPAQUE,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 2);
|
|
|
|
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_OPAQUE,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 0, 0.0, 0.0);
|
|
|
|
mypaintBrush.setMappingPoint(MYPAINT_BRUSH_SETTING_OPAQUE,
|
|
|
|
MYPAINT_BRUSH_INPUT_PRESSURE, 1, 1.0,
|
|
|
|
maxOpacity - minOpacity);
|
2017-08-04 15:31:50 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FullColorBrushTool::applyToonzBrushSettings(mypaint::Brush &mypaintBrush) {
|
|
|
|
TMyPaintBrushStyle *mypaintStyle = getBrushStyle();
|
|
|
|
|
|
|
|
if (mypaintStyle) {
|
|
|
|
const double precision = 1e-5;
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
double modifierSize = m_modifierSize.getValue() * log(2.0);
|
|
|
|
double modifierOpacity = 0.01 * m_modifierOpacity.getValue();
|
2017-11-09 19:27:53 +13:00
|
|
|
bool modifierEraser = m_modifierEraser.getValue();
|
|
|
|
bool modifierLockAlpha = m_modifierLockAlpha.getValue();
|
2017-08-04 15:31:50 +12:00
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
TPixelD color = PixelConverter<TPixelD>::from(m_currentColor);
|
|
|
|
double colorH = 0.0;
|
|
|
|
double colorS = 0.0;
|
|
|
|
double colorV = 0.0;
|
2017-08-04 15:31:50 +12:00
|
|
|
RGB2HSV(color.r, color.g, color.b, &colorH, &colorS, &colorV);
|
|
|
|
|
|
|
|
mypaintBrush.fromBrush(mypaintStyle->getBrush());
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
float baseSize =
|
|
|
|
mypaintBrush.getBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC);
|
2017-08-04 15:31:50 +12:00
|
|
|
float baseOpacity = mypaintBrush.getBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE);
|
|
|
|
|
2017-11-07 20:24:20 +13:00
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
|
|
baseSize + modifierSize);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_OPAQUE,
|
|
|
|
baseOpacity * modifierOpacity);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_H, colorH / 360.0);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_S, colorS);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_COLOR_V, colorV);
|
2017-10-17 02:54:19 +13:00
|
|
|
|
|
|
|
if (modifierEraser) {
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_ERASER, 1.0);
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_LOCK_ALPHA, 0.0);
|
|
|
|
} else if (modifierLockAlpha) {
|
|
|
|
// lock-alpha already disables eraser
|
|
|
|
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_LOCK_ALPHA, 1.0);
|
|
|
|
}
|
2017-08-04 15:31:50 +12:00
|
|
|
} else {
|
|
|
|
applyClassicToonzBrushSettings(mypaintBrush);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
//==========================================================================================================
|
|
|
|
|
|
|
|
FullColorBrushToolNotifier::FullColorBrushToolNotifier(FullColorBrushTool *tool)
|
2016-06-15 18:43:10 +12:00
|
|
|
: m_tool(tool) {
|
2017-08-04 15:31:50 +12:00
|
|
|
if (TTool::Application *app = m_tool->getApplication()) {
|
|
|
|
if (TXshLevelHandle *levelHandle = app->getCurrentLevel()) {
|
|
|
|
bool ret = connect(levelHandle, SIGNAL(xshCanvasSizeChanged()), this,
|
|
|
|
SLOT(onCanvasSizeChanged()));
|
|
|
|
assert(ret);
|
|
|
|
}
|
|
|
|
if (TPaletteHandle *paletteHandle = app->getCurrentPalette()) {
|
|
|
|
bool ret;
|
2017-11-07 20:24:20 +13:00
|
|
|
ret = connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
|
2017-08-04 15:31:50 +12:00
|
|
|
SLOT(onColorStyleChanged()));
|
|
|
|
assert(ret);
|
|
|
|
ret = connect(paletteHandle, SIGNAL(colorStyleSwitched()), this,
|
|
|
|
SLOT(onColorStyleChanged()));
|
|
|
|
assert(ret);
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================================================
|
|
|
|
|
|
|
|
FullColorBrushTool fullColorPencil("T_Brush");
|