OpenToonz - An open-source full-featured 2D animation creation software
C
Add Lock Alpha to Smart Raster - MyPaint brush
manongjohn6c9506a71c77
diff --git a/toonz/sources/tnztools/mypainttoonzbrush.cpp b/toonz/sources/tnztools/mypainttoonzbrush.cppindex c3670dc5d..deb9b0433 100644--- a/toonz/sources/tnztools/mypainttoonzbrush.cpp+++ b/toonz/sources/tnztools/mypainttoonzbrush.cpp@@ -9,7 +9,8 @@#include <QColor>namespace {-void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId) {+void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId,+ bool lockAlpha) {if (!out.getPointer() || !in.getPointer()) return;assert(out->getSize() == in->getSize());int x, y;@@ -24,7 +25,13 @@ void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId) {TPixel32 *inPix = &in->pixels(y)[x];if (inPix->m == 0) continue;TPixelCM32 *outPix = &out->pixels(y)[x];- bool sameStyleId = styleId == outPix->getInk();+ if (lockAlpha && !outPix->isPureInk() && outPix->getPaint() == 0 &&+ outPix->getTone() == 255) {+ *outPix =+ TPixelCM32(outPix->getInk(), outPix->getPaint(), outPix->getTone());+ continue;+ }+ bool sameStyleId = styleId == outPix->getInk();// line with the same style : multiply tones// line with different style : pick darker toneint tone = sameStyleId ? outPix->getTone() * (255 - inPix->m) / 255@@ -196,7 +203,8 @@ void MyPaintToonzBrush::strokeTo(const TPointD &point, double pressure,void MyPaintToonzBrush::updateDrawing(const TRasterCM32P rasCM,const TRasterCM32P rasBackupCM,- const TRect &bbox, int styleId) const {+ const TRect &bbox, int styleId,+ bool lockAlpha) const {if (!rasCM) return;TRect rasRect = rasCM->getBounds();@@ -204,6 +212,6 @@ void MyPaintToonzBrush::updateDrawing(const TRasterCM32P rasCM,if (targetRect.isEmpty()) return;rasCM->copy(rasBackupCM->extract(targetRect), targetRect.getP00());- putOnRasterCM(rasCM->extract(targetRect), m_ras->extract(targetRect),- styleId);+ putOnRasterCM(rasCM->extract(targetRect), m_ras->extract(targetRect), styleId,+ lockAlpha);}\ No newline at end of filediff --git a/toonz/sources/tnztools/mypainttoonzbrush.h b/toonz/sources/tnztools/mypainttoonzbrush.hindex 352afa574..f26aa60e7 100644--- a/toonz/sources/tnztools/mypainttoonzbrush.h+++ b/toonz/sources/tnztools/mypainttoonzbrush.h@@ -130,7 +130,7 @@ public:// colormappedvoid updateDrawing(const TRasterCM32P rasCM, const TRasterCM32P rasBackupCM,- const TRect &bbox, int styleId) const;+ const TRect &bbox, int styleId, bool lockAlpha) const;};#endif // T_BLUREDBRUSHdiff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cppindex 0f64f6494..d4b05d259 100644--- a/toonz/sources/tnztools/tooloptions.cpp+++ b/toonz/sources/tnztools/tooloptions.cpp@@ -1784,16 +1784,18 @@ void BrushToolOptionsBox::filterControls() {for (QMap<std::string, QLabel *>::iterator it = m_labels.begin();it != m_labels.end(); it++) {bool isModifier = (it.key().substr(0, 8) == "Modifier");- bool isCommon = (it.key() == "Pressure" || it.key() == "Preset:");- bool visible = isCommon || (isModifier == showModifiers);+ bool isCommon = (it.key() == "Lock Alpha" || it.key() == "Pressure" ||+ it.key() == "Preset:");+ bool visible = isCommon || (isModifier == showModifiers);it.value()->setVisible(visible);}for (QMap<std::string, ToolOptionControl *>::iterator it = m_controls.begin();it != m_controls.end(); it++) {bool isModifier = (it.key().substr(0, 8) == "Modifier");- bool isCommon = (it.key() == "Pressure" || it.key() == "Preset:");- bool visible = isCommon || (isModifier == showModifiers);+ bool isCommon = (it.key() == "Lock Alpha" || it.key() == "Pressure" ||+ it.key() == "Preset:");+ bool visible = isCommon || (isModifier == showModifiers);if (QWidget *widget = dynamic_cast<QWidget *>(it.value()))widget->setVisible(visible);}diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cppindex 08d0621de..db1db7250 100644--- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp+++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp@@ -1335,7 +1335,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,if (!updateRect.isEmpty()) {// ras->extract(updateRect)->copy(m_workRas->extract(updateRect));m_toonz_brush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect,- m_styleId);+ m_styleId, m_modifierLockAlpha.getValue());}m_lastRect = m_strokeRect;@@ -1439,7 +1439,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,if (!updateRect.isEmpty()) {// ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));m_toonz_brush->updateDrawing(ras, m_backupRas, m_strokeSegmentRect,- m_styleId);+ m_styleId, m_modifierLockAlpha.getValue());}m_lastRect = m_strokeRect;@@ -1594,7 +1594,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos,if (!updateRect.isEmpty()) {// ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));m_toonz_brush->updateDrawing(ras, m_backupRas, m_strokeSegmentRect,- m_styleId);+ m_styleId, m_modifierLockAlpha.getValue());}TPointD thickOffset(m_maxCursorThick * 0.5,m_maxCursorThick * 0.5); // TODO