Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Feat(PaintBrush): Add Option: Paint By Filling

Abel Youd01895740a6f
diff --git a/toonz/sources/include/tools/tooloptions.h b/toonz/sources/include/tools/tooloptions.h
index 2d30c7338..c9b312054 100644
--- a/toonz/sources/include/tools/tooloptions.h
+++ b/toonz/sources/include/tools/tooloptions.h
@@ -477,6 +477,7 @@ class PaintbrushToolOptionsBox final : public ToolOptionsBox {
ToolOptionCombo *m_colorMode;
ToolOptionCheckbox *m_selectiveMode;
ToolOptionCheckbox *m_lockAlphaMode;
+ ToolOptionCheckbox *m_FillingMode;
public:
PaintbrushToolOptionsBox(QWidget *parent, TTool *tool,
diff --git a/toonz/sources/tnztools/paintbrushtool.cpp b/toonz/sources/tnztools/paintbrushtool.cpp
index d3799eba8..58279420d 100644
--- a/toonz/sources/tnztools/paintbrushtool.cpp
+++ b/toonz/sources/tnztools/paintbrushtool.cpp
@@ -51,6 +51,7 @@ TEnv::IntVar PaintBrushSelective("InknpaintPaintBrushSelective", 0);
TEnv::DoubleVar PaintBrushSize("InknpaintPaintBrushSize", 10);
TEnv::IntVar PaintBrushModifierLockAlpha("PaintBrushModifierLockAlpha", 0);
TEnv::IntVar PaintBrushPick("PaintBrushPick", 0);
+TEnv::IntVar PaintBrushFill("PaintBrushFill", 1);
//-----------------------------------------------------------------------------
@@ -266,6 +267,7 @@ class PaintBrushTool final : public TTool {
TBoolProperty m_selective;
TEnumProperty m_colorType;
TBoolProperty m_pick;
+ TBoolProperty m_fillingMode;
TPropertyGroup m_prop;
int m_cursor;
ColorType m_colorTypeBrush;
@@ -339,7 +341,8 @@ PaintBrushTool::PaintBrushTool()
, m_firstTime(true)
, m_workingFrameId(TFrameId())
, m_modifierLockAlpha("Lock Alpha", false)
- , m_pick("Pick", false) {
+ , m_pick("Pick", false)
+ , m_fillingMode("Paint by Filling", true) {
m_toolSize.setNonLinearSlider();
m_colorType.addValue(LINES);
@@ -353,11 +356,13 @@ PaintBrushTool::PaintBrushTool()
m_prop.bind(m_selective);
m_prop.bind(m_modifierLockAlpha);
m_prop.bind(m_pick);
+ m_prop.bind(m_fillingMode);
m_selective.setId("Selective");
m_colorType.setId("Mode");
m_modifierLockAlpha.setId("LockAlpha");
m_pick.setId("Pick");
+ m_fillingMode.setId("FillingMode");
}
//-----------------------------------------------------------------------------
@@ -373,6 +378,7 @@ void PaintBrushTool::updateTranslation() {
m_selective.setQStringName(tr("Selective", NULL));
m_modifierLockAlpha.setQStringName(tr("Lock Alpha"));
m_pick.setQStringName(tr("Pick"));
+ m_fillingMode.setQStringName(tr("Paint by Filling"));
}
//-------------------------------------------------------------------------------------------------------
@@ -458,7 +464,8 @@ bool PaintBrushTool::onPropertyChanged(std::string propertyName) {
PaintBrushSelective = (int)(m_selective.getValue());
if (m_selective.getValue() && m_modifierLockAlpha.getValue())
m_modifierLockAlpha.setValue(false);
- if (m_selective.getValue() && m_pick.getValue()) m_pick.setValue(false);
+ if (m_selective.getValue() && m_pick.getValue())
+ m_pick.setValue(false);
}
// Areas, Lines etc.
@@ -480,6 +487,9 @@ bool PaintBrushTool::onPropertyChanged(std::string propertyName) {
PaintBrushPick = (int)m_pick.getValue();
if (m_pick.getValue() && m_selective.getValue()) m_selective.setValue(false);
}
+ // Filling Mode
+ else if (propertyName == m_fillingMode.getName()) {
+ PaintBrushFill = (int)(m_fillingMode.getValue());
}
return true;
}
@@ -501,13 +511,13 @@ void PaintBrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
if (m_pick.getValue() || m_selective.getValue()) {
TApplication *app = getApplication();
pickedStyle = pick(ti, pos,
- app->getCurrentFrame()->isEditingLevel()
- ? -1
- : app->getCurrentFrame()->getFrame());
+ app->getCurrentFrame()->isEditingLevel()
+ ? -1
+ : app->getCurrentFrame()->getFrame());
if (m_pick.getValue()) {
- m_orignalStyle = app->getCurrentLevelStyleIndex();
- app->setCurrentLevelStyleIndex(pickedStyle);
- }
+ m_orignalStyle = app->getCurrentLevelStyleIndex();
+ app->setCurrentLevelStyleIndex(pickedStyle);
+ }
}
int thickness = m_toolSize.getValue();
int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
@@ -516,8 +526,8 @@ void PaintBrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
m_rasterTrack = new RasterStrokeGenerator(
ras, PAINTBRUSH, m_colorTypeBrush, styleId,
TThickPoint(m_mousePos + convert(ras->getCenter()), thickness),
- m_selective.getValue(), pickedStyle, m_modifierLockAlpha.getValue(), false);
- false);
+ m_selective.getValue(), pickedStyle, m_modifierLockAlpha.getValue(),
+ m_fillingMode.getValue());
/*-- 現在のFidを記憶 --*/
m_workingFrameId = getFrameId();
m_tileSaver->save(m_rasterTrack->getLastRect());
@@ -579,6 +589,7 @@ void PaintBrushTool::onEnter() {
m_toolSize.setValue(PaintBrushSize);
m_modifierLockAlpha.setValue(PaintBrushModifierLockAlpha ? 1 : 0);
m_pick.setValue(PaintBrushPick ? 1 : 0);
+ m_fillingMode.setValue(PaintBrushFill ? 1 : 0);
m_firstTime = false;
}
double x = m_toolSize.getValue();
diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp
index 50379e7fb..51d9d0210 100644
--- a/toonz/sources/tnztools/tooloptions.cpp
+++ b/toonz/sources/tnztools/tooloptions.cpp
@@ -1682,10 +1682,13 @@ PaintbrushToolOptionsBox::PaintbrushToolOptionsBox(QWidget *parent, TTool *tool,
dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Selective"));
m_lockAlphaMode =
dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Lock Alpha"));
+ m_FillingMode =
+ dynamic_cast<ToolOptionCheckbox*>(m_controls.value("Paint by Filling"));
if (m_colorMode->getProperty()->getValue() == L"Lines") {
m_selectiveMode->setVisible(false);
m_lockAlphaMode->setVisible(false);
+ m_FillingMode->setVisible(false);
}
bool ret = connect(m_colorMode, SIGNAL(currentIndexChanged(int)), this,
@@ -1708,6 +1711,7 @@ void PaintbrushToolOptionsBox::onColorModeChanged(int index) {
bool enabled = range[index] != L"Lines";
m_selectiveMode->setVisible(enabled);
m_lockAlphaMode->setVisible(enabled);
+ m_FillingMode->setVisible(enabled);
}
//=============================================================================
diff --git a/toonz/sources/toonzlib/rasterstrokegenerator.cpp b/toonz/sources/toonzlib/rasterstrokegenerator.cpp
index 199716fc9..116568504 100644
--- a/toonz/sources/toonzlib/rasterstrokegenerator.cpp
+++ b/toonz/sources/toonzlib/rasterstrokegenerator.cpp
@@ -193,7 +193,8 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
TRect box2 = box - p;
TRasterCM32P rIn = in->extract(box2);
TRect box3 = rOut->getBounds();
- if (m_task == PAINTBRUSH && m_colorType == PAINT) {
+ // Paint By Filling
+ if (m_task == PAINTBRUSH && m_colorType == PAINT && m_keepAntiAlias) {
TPoint center = in->getCenter() - p;
if (!box3.contains(center)) center = rIn->getCenter();
int lx = rOut->getLx();
@@ -207,12 +208,10 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
int toPaint = (rIn->pixels(y) + x)->getInk();
if (!m_selective && !toPaint) return true;
- TPixelCM32 *pix = rOut->pixels(y) + x;
- int paintIdx = pix->getPaint();
- bool changePaint = (!m_selective && !m_modifierLockAlpha) ||
- (m_selective && toPaint != 0) ||
- (m_modifierLockAlpha && paintIdx != 0);
- return !changePaint;
+ TPixelCM32 *pix = rOut->pixels(y) + x;
+ int paintIdx = pix->getPaint();
+ return (m_selective && toPaint != m_selectedStyle && toPaint != m_styleId) ||
+ (m_modifierLockAlpha && toPaint == 0);
};
while (!stack.empty()) {
@@ -276,90 +275,89 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
}
}
} else
- for (int y = 0; y < rOut->getLy(); y++) {
- /*--Finger Tool Boundary Conditions --*/
- if (m_task == FINGER && (y == 0 || y == rOut->getLy() - 1)) continue;
-
- TPixelCM32 *inPix = rIn->pixels(y);
- TPixelCM32 *outPix = rOut->pixels(y);
- TPixelCM32 *outEnd = outPix + rOut->getLx();
- for (; outPix < outEnd; ++inPix, ++outPix) {
- if (m_task == BRUSH) {
- int inTone = inPix->getTone();
- int outTone = outPix->getTone();
- if (inPix->isPureInk() && !m_selective && !m_modifierLockAlpha) {
- *outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(), inTone);
- continue;
- }
- if (m_modifierLockAlpha && !outPix->isPureInk() &&
- outPix->getPaint() == 0 && outPix->getTone() == 255) {
- *outPix = TPixelCM32(outPix->getInk(), outPix->getPaint(), outTone);
- continue;
- }
- if (outPix->isPureInk() && m_selective) {
+ for (int y = 0; y < rOut->getLy(); y++) {
+ /*--Finger Tool Boundary Conditions --*/
+ if (m_task == FINGER && (y == 0 || y == rOut->getLy() - 1)) continue;
+
+ TPixelCM32 *inPix = rIn->pixels(y);
+ TPixelCM32 *outPix = rOut->pixels(y);
+ TPixelCM32 *outEnd = outPix + rOut->getLx();
+ for (; outPix < outEnd; ++inPix, ++outPix) {
+ if (m_task == BRUSH) {
+ int inTone = inPix->getTone();
+ int outTone = outPix->getTone();
+ if (inPix->isPureInk() && !m_selective && !m_modifierLockAlpha) {
+ *outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(), inTone);
+ continue;
+ }
+ if (m_modifierLockAlpha && !outPix->isPureInk() &&
+ outPix->getPaint() == 0 && outPix->getTone() == 255) {
+ *outPix = TPixelCM32(outPix->getInk(), outPix->getPaint(), outTone);
+ continue;
+ }
+ if (outPix->isPureInk() && m_selective) {
if (!m_isPaletteOrder ||
m_aboveStyleIds.contains(outPix->getInk())) {
*outPix =
TPixelCM32(outPix->getInk(), outPix->getPaint(), outTone);
- continue;
+ continue;
+ }
+ }
+ if (inTone <= outTone) {
+ *outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(),
+ m_modifierLockAlpha ? outTone : inTone);
}
- }
- if (inTone <= outTone) {
- *outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(),
- m_modifierLockAlpha ? outTone : inTone);
- }
} else if (m_task == ERASE) {
- if (m_colorType == INK) {
- if (!m_keepAntiAlias) {
- if (inPix->getTone() == 0 &&
- (!m_selective ||
- (m_selective && outPix->getInk() == m_selectedStyle))) {
- outPix->setTone(255);
+ if (m_colorType == INK) {
+ if (!m_keepAntiAlias) {
+ if (inPix->getTone() == 0 &&
+ (!m_selective ||
+ (m_selective && outPix->getInk() == m_selectedStyle))) {
+ outPix->setTone(255);
+ }
+ } else if (inPix->getTone() < 255 &&
+ (!m_selective ||
+ (m_selective && outPix->getInk() == m_selectedStyle))) {
+ outPix->setTone(
+ std::max(outPix->getTone(), 255 - inPix->getTone()));
}
- } else if (inPix->getTone() < 255 &&
- (!m_selective ||
- (m_selective && outPix->getInk() == m_selectedStyle))) {
- outPix->setTone(
- std::max(outPix->getTone(), 255 - inPix->getTone()));
}
- }
- if (m_colorType == PAINT) {
- if (inPix->getTone() == 0 &&
- (!m_selective ||
- (m_selective && outPix->getPaint() == m_selectedStyle)))
- outPix->setPaint(0);
- }
- if (m_colorType == INKNPAINT) {
- if (inPix->getTone() < 255 &&
- (!m_selective ||
- (m_selective && outPix->getPaint() == m_selectedStyle)))
- outPix->setPaint(0);
- if (!m_keepAntiAlias) {
+ if (m_colorType == PAINT) {
if (inPix->getTone() == 0 &&
(!m_selective ||
- (m_selective && outPix->getInk() == m_selectedStyle))) {
- outPix->setTone(255);
+ (m_selective && outPix->getPaint() == m_selectedStyle)))
+ outPix->setPaint(0);
+ }
+ if (m_colorType == INKNPAINT) {
+ if (inPix->getTone() < 255 &&
+ (!m_selective ||
+ (m_selective && outPix->getPaint() == m_selectedStyle)))
+ outPix->setPaint(0);
+ if (!m_keepAntiAlias) {
+ if (inPix->getTone() == 0 &&
+ (!m_selective ||
+ (m_selective && outPix->getInk() == m_selectedStyle))) {
+ outPix->setTone(255);
+ }
+ } else if (inPix->getTone() < 255 &&
+ (!m_selective ||
+ (m_selective && outPix->getInk() == m_selectedStyle))) {
+ outPix->setTone(
+ std::max(outPix->getTone(), 255 - inPix->getTone()));
}
- } else if (inPix->getTone() < 255 &&
- (!m_selective ||
- (m_selective && outPix->getInk() == m_selectedStyle))) {
- outPix->setTone(
- std::max(outPix->getTone(), 255 - inPix->getTone()));
}
- }
- }
- else if (m_task == PAINTBRUSH) {
- if (!inPix->isPureInk()) continue;
- int paintIdx = outPix->getPaint();
- bool changePaint = (!m_selective && !m_modifierLockAlpha) ||
+ } else if (m_task == PAINTBRUSH) {
+ if (!inPix->isPureInk()) continue;
+ int paintIdx = outPix->getPaint();
+ bool changePaint = (!m_selective && !m_modifierLockAlpha) ||
(m_selective && paintIdx == m_selectedStyle) ||
- (m_modifierLockAlpha && paintIdx != 0);
- if (m_colorType == INK)
- *outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(),
- outPix->getTone());
+ (m_modifierLockAlpha && paintIdx != 0);
+ if (m_colorType == INK)
+ *outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(),
+ outPix->getTone());
if (m_colorType == PAINT)
- if (changePaint)
- *outPix = TPixelCM32(outPix->getInk(), inPix->getInk(),
+ if (changePaint)
+ *outPix = TPixelCM32(outPix->getInk(), inPix->getInk(),
outPix->getTone());
if (m_colorType == INKNPAINT)
*outPix =
@@ -413,10 +411,10 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
else {
if (outPix->isPurePaint() || outPix->getInk() != inStyle) continue;
- /*-- For 4 neighborhood pixels --*/
- int maxTone = tone;
- for (int p = 0; p < 4; p++) {
- /*--
+ /*-- For 4 neighborhood pixels --*/
+ int maxTone = tone;
+ for (int p = 0; p < 4; p++) {
+ /*--
* Count up items whose Ink# is not Current or whose line is
* thinner than your Pixel (Tone is higher).
* --*/