Skip to content

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

C

Feat(PaintBrush): Change selective to only fill the area of picked style

Abel You537bb6f31451
diff --git a/toonz/sources/tnztools/paintbrushtool.cpp b/toonz/sources/tnztools/paintbrushtool.cpp
index 8875ffaef..d3799eba8 100644
--- a/toonz/sources/tnztools/paintbrushtool.cpp
+++ b/toonz/sources/tnztools/paintbrushtool.cpp
@@ -263,7 +263,7 @@ class PaintBrushTool final : public TTool {
TPointD m_mousePos;
TIntProperty m_toolSize;
- TBoolProperty m_onlyEmptyAreas;
+ TBoolProperty m_selective;
TEnumProperty m_colorType;
TBoolProperty m_pick;
TPropertyGroup m_prop;
@@ -335,7 +335,7 @@ PaintBrushTool::PaintBrushTool()
// sostituire i nomi con quelli del current, tipo W_ToolOptions...
, m_toolSize("Size:", 1, 1000, 10, false) // W_ToolOptions_BrushToolSize
, m_colorType("Mode:") // W_ToolOptions_InkOrPaint
- , m_onlyEmptyAreas("Selective", false) // W_ToolOptions_Selective
+ , m_selective("Selective", false) // W_ToolOptions_Selective
, m_firstTime(true)
, m_workingFrameId(TFrameId())
, m_modifierLockAlpha("Lock Alpha", false)
@@ -350,11 +350,11 @@ PaintBrushTool::PaintBrushTool()
m_prop.bind(m_toolSize);
m_prop.bind(m_colorType);
- m_prop.bind(m_onlyEmptyAreas);
+ m_prop.bind(m_selective);
m_prop.bind(m_modifierLockAlpha);
m_prop.bind(m_pick);
- m_onlyEmptyAreas.setId("Selective");
+ m_selective.setId("Selective");
m_colorType.setId("Mode");
m_modifierLockAlpha.setId("LockAlpha");
m_pick.setId("Pick");
@@ -370,7 +370,7 @@ void PaintBrushTool::updateTranslation() {
m_colorType.setItemUIName(AREAS, tr("Areas"));
m_colorType.setItemUIName(ALL, tr("Lines & Areas"));
- m_onlyEmptyAreas.setQStringName(tr("Selective", NULL));
+ m_selective.setQStringName(tr("Selective", NULL));
m_modifierLockAlpha.setQStringName(tr("Lock Alpha"));
m_pick.setQStringName(tr("Pick"));
}
@@ -454,10 +454,11 @@ bool PaintBrushTool::onPropertyChanged(std::string propertyName) {
}
// Selective
- else if (propertyName == m_onlyEmptyAreas.getName()) {
- PaintBrushSelective = (int)(m_onlyEmptyAreas.getValue());
- if (m_onlyEmptyAreas.getValue() && m_modifierLockAlpha.getValue())
+ else if (propertyName == m_selective.getName()) {
+ 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);
}
// Areas, Lines etc.
@@ -470,14 +471,14 @@ bool PaintBrushTool::onPropertyChanged(std::string propertyName) {
// Lock Alpha
else if (propertyName == m_modifierLockAlpha.getName()) {
PaintBrushModifierLockAlpha = (int)(m_modifierLockAlpha.getValue());
- if (m_modifierLockAlpha.getValue() && m_onlyEmptyAreas.getValue())
- m_onlyEmptyAreas.setValue(false);
- } else if (propertyName == m_pick.getName()) {
- PaintBrushPick = (int)(m_pick.getValue());
- }
-
+ if (m_modifierLockAlpha.getValue() && m_selective.getValue())
+ m_selective.setValue(false);
+ }
+
+ //Pick
else if (propertyName == m_pick.getName()) {
PaintBrushPick = (int)m_pick.getValue();
+ if (m_pick.getValue() && m_selective.getValue()) m_selective.setValue(false);
}
}
return true;
@@ -496,15 +497,18 @@ void PaintBrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
if (TToonzImageP ti = image) {
TRasterCM32P ras = ti->getRaster();
if (ras) {
- if (m_pick.getValue()) {
+ int pickedStyle = 0;
+ if (m_pick.getValue() || m_selective.getValue()) {
TApplication *app = getApplication();
- int pickedStyle = pick(ti, pos,
- app->getCurrentFrame()->isEditingLevel()
- ? -1
- : app->getCurrentFrame()->getFrame());
- m_orignalStyle = app->getCurrentLevelStyleIndex();
+ pickedStyle = pick(ti, pos,
+ app->getCurrentFrame()->isEditingLevel()
+ ? -1
+ : app->getCurrentFrame()->getFrame());
+ if (m_pick.getValue()) {
+ m_orignalStyle = app->getCurrentLevelStyleIndex();
app->setCurrentLevelStyleIndex(pickedStyle);
}
+ }
int thickness = m_toolSize.getValue();
int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
TTileSetCM32 *tileSet = new TTileSetCM32(ras->getSize());
@@ -512,7 +516,7 @@ 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_onlyEmptyAreas.getValue(), 0, m_modifierLockAlpha.getValue(),
+ m_selective.getValue(), pickedStyle, m_modifierLockAlpha.getValue(), false);
false);
/*-- 現在のFidを記憶 --*/
m_workingFrameId = getFrameId();
@@ -570,7 +574,7 @@ void PaintBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
void PaintBrushTool::onEnter() {
if (m_firstTime) {
- m_onlyEmptyAreas.setValue(PaintBrushSelective ? 1 : 0);
+ m_selective.setValue(PaintBrushSelective ? 1 : 0);
m_colorType.setValue(::to_wstring(PaintBrushColorType.getValue()));
m_toolSize.setValue(PaintBrushSize);
m_modifierLockAlpha.setValue(PaintBrushModifierLockAlpha ? 1 : 0);
diff --git a/toonz/sources/toonzlib/rasterstrokegenerator.cpp b/toonz/sources/toonzlib/rasterstrokegenerator.cpp
index ae8bb2ef7..199716fc9 100644
--- a/toonz/sources/toonzlib/rasterstrokegenerator.cpp
+++ b/toonz/sources/toonzlib/rasterstrokegenerator.cpp
@@ -252,7 +252,7 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
int paintIdx = outPix->getPaint();
bool changePaint = (!m_selective && !m_modifierLockAlpha) ||
- (m_selective && paintIdx == 0) ||
+ (m_selective && paintIdx == m_selectedStyle) ||
(m_modifierLockAlpha && paintIdx != 0);
if (changePaint)
@@ -275,8 +275,7 @@ 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;
@@ -298,8 +297,10 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
continue;
}
if (outPix->isPureInk() && m_selective) {
- if (!m_isPaletteOrder || m_aboveStyleIds.contains(outPix->getInk())) {
- *outPix = TPixelCM32(outPix->getInk(), outPix->getPaint(), outTone);
+ if (!m_isPaletteOrder ||
+ m_aboveStyleIds.contains(outPix->getInk())) {
+ *outPix =
+ TPixelCM32(outPix->getInk(), outPix->getPaint(), outTone);
continue;
}
}
@@ -307,8 +308,7 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
*outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(),
m_modifierLockAlpha ? outTone : inTone);
}
- }
- if (m_task == ERASE) {
+ } else if (m_task == ERASE) {
if (m_colorType == INK) {
if (!m_keepAntiAlias) {
if (inPix->getTone() == 0 &&
@@ -352,15 +352,15 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
if (!inPix->isPureInk()) continue;
int paintIdx = outPix->getPaint();
bool changePaint = (!m_selective && !m_modifierLockAlpha) ||
- (m_selective && paintIdx == 0) ||
+ (m_selective && paintIdx == m_selectedStyle) ||
(m_modifierLockAlpha && paintIdx != 0);
if (m_colorType == INK)
*outPix = TPixelCM32(inPix->getInk(), outPix->getPaint(),
outPix->getTone());
- /*if (m_colorType == PAINT)
+ if (m_colorType == PAINT)
if (changePaint)
*outPix = TPixelCM32(outPix->getInk(), inPix->getInk(),
- outPix->getTone());*/
+ outPix->getTone());
if (m_colorType == INKNPAINT)
*outPix =
TPixelCM32(inPix->getInk(),
@@ -417,8 +417,8 @@ void RasterStrokeGenerator::placeOver(const TRasterCM32P &out,
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).
+ * Count up items whose Ink# is not Current or whose line is
+ * thinner than your Pixel (Tone is higher).
* --*/
if (neighbourPixels[p]->getInk() != inStyle) {
count++;