Skip to content

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

C

FillToolAreaFiller: Use Ctrl to paint all autoInks in area mode

Abel You0961afcf3dd3
diff --git a/toonz/sources/include/toonz/fill.h b/toonz/sources/include/toonz/fill.h
index a760d8327..3a6a64221 100644
--- a/toonz/sources/include/toonz/fill.h
+++ b/toonz/sources/include/toonz/fill.h
@@ -140,7 +140,7 @@ else if \b fillInks is false fill only paint delimited by ink;
else fill ink and paint in rect.
*/
bool rectFill(const TRect &rect, int color, bool onlyUnfilled,
- bool fillPaints, bool fillInks);
+ bool fillPaints, bool fillInks, bool fillAllautoPaintLines = false);
// Only for Fill Check
bool rectFastFill(const TRect &rect, int color);
@@ -152,7 +152,7 @@ else if \b fillInks is false fill only paint delimited by ink;
else fill ink and paint in region contained in spline.
*/
void strokeFill(const TRect &rect, TStroke *s, int color, bool onlyUnfilled,
- bool fillPaints, bool fillInks);
+ bool fillPaints, bool fillInks, bool fillAllautoPaintLines);
private:
const void processPixel(TPixelCM32 &pix, const TPixelCM32 &bak, bool invert,
diff --git a/toonz/sources/tnztools/filltool.cpp b/toonz/sources/tnztools/filltool.cpp
index 0364a85eb..f9fe1140c 100644
--- a/toonz/sources/tnztools/filltool.cpp
+++ b/toonz/sources/tnztools/filltool.cpp
@@ -452,6 +452,7 @@ class RasterRectFillUndo final : public TRasterUndo {
bool m_refGapFill;
TPalette *m_palette;
TTileSetCM32 *m_tileSet = nullptr;
+ bool m_fillAllautoPaintLines;
public:
~RasterRectFillUndo() {
@@ -462,14 +463,16 @@ public:
RasterRectFillUndo(TTileSetCM32 *tileSet, TStroke *s, TRect oldSaveBox,
TRect fillArea, int paintId, TXshSimpleLevel *level,
std::wstring colorType, bool onlyUnfilled,
- const TFrameId &fid, bool refImgPut, TPalette *palette)
+ const TFrameId &fid, bool refImgPut, TPalette *palette,
+ bool fillAllautoPaintLines)
: TRasterUndo(tileSet, level, fid, false, false, 0, false)
, m_saveBox(oldSaveBox)
, m_fillArea(fillArea)
, m_paintId(paintId)
, m_colorType(colorType)
, m_onlyUnfilled(onlyUnfilled)
- , m_palette(palette) {
+ , m_palette(palette)
+ , m_fillAllautoPaintLines(fillAllautoPaintLines) {
TToonzImageP image = getImage();
if (refImgPut) {
@@ -494,22 +497,12 @@ public:
AreaFiller filler(ras, TRaster32P(), m_palette);
if (!m_s)
filler.rectFill(m_fillArea, m_paintId, m_onlyUnfilled,
- m_colorType != LINES, m_colorType != AREAS);
+ m_colorType != LINES, m_colorType != AREAS,
+ m_fillAllautoPaintLines);
else
filler.strokeFill(m_fillArea, m_s, m_paintId, m_onlyUnfilled,
- m_colorType != LINES, m_colorType != AREAS);
- if (m_palette) {
- TRect rect = m_saveBox;
- TRect bounds = ras->getBounds();
- if (bounds.overlaps(rect)) {
- rect *= bounds;
- const TTileSetCM32::Tile *tile =
- m_tiles->getTile(m_tiles->getTileCount() - 1);
- TRasterCM32P rbefore;
- tile->getRaster(rbefore);
- fillautoInks(ras, rect, rbefore, m_palette);
- }
- }
+ m_colorType != LINES, m_colorType != AREAS,
+ m_fillAllautoPaintLines);
}
TTool::Application *app = TTool::getApplication();
if (app) {
@@ -855,7 +848,8 @@ bool inline hasAutoInks(const TPalette *plt) {
void fillAreaWithUndo(const TImageP &img, const TRaster32P &ref,
const TRectD &area, TStroke *stroke, bool onlyUnfilled,
std::wstring colorType, TXshSimpleLevel *sl,
- const TFrameId &fid, int cs, bool autopaintLines) {
+ const TFrameId &fid, int cs, bool autopaintLines,
+ bool fillAllautoPaintLines) {
TRectD selArea = stroke ? stroke->getBBox().enlarge(1) : area;
if (TToonzImageP ti = img) {
// allargo di 1 la savebox, perche cosi' il rectfill di tutta l'immagine fa
@@ -895,30 +889,20 @@ void fillAreaWithUndo(const TImageP &img, const TRaster32P &ref,
AreaFiller filler(raux, ref, plt);
if (!stroke) {
- bool ret = filler.rectFill(auxFillArea, cs, onlyUnfilled,
- colorType != LINES, colorType != AREAS);
+ bool ret =
+ filler.rectFill(auxFillArea, cs, onlyUnfilled, colorType != LINES,
+ colorType != AREAS, fillAllautoPaintLines);
if (!ret) {
delete rasTileSet;
return;
}
- if (plt) {
- TRect rect = auxFillArea;
- TRect bounds = raux->getBounds();
- if (bounds.overlaps(rect)) {
- rect *= bounds;
- const TTileSetCM32::Tile *tile =
- rasTileSet->getTile(rasTileSet->getTileCount() - 1);
- TRasterCM32P rbefore;
- tile->getRaster(rbefore);
- fillautoInks(raux, rect, rbefore, plt);
- }
- }
} else {
TPointD total = convert(ras->getCenter()) - convert(offs) -
TPointD(auxFillArea.x0, auxFillArea.y0);
stroke->transform(TTranslation(total));
filler.strokeFill(auxFillArea, stroke, cs, onlyUnfilled,
- colorType != LINES, colorType != AREAS);
+ colorType != LINES, colorType != AREAS,
+ fillAllautoPaintLines);
// Restore original position because the stroke might be used
// for calculating inbetween frames
stroke->transform(TTranslation(-total));
@@ -927,7 +911,7 @@ void fillAreaWithUndo(const TImageP &img, const TRaster32P &ref,
// ToolUtils::updateSaveBox(sl, fid);
TUndoManager::manager()->add(new RasterRectFillUndo(
rasTileSet, stroke, rasSaveBox, auxFillArea, cs, sl, colorType,
- onlyUnfilled, fid, ref.getPointer(), plt));
+ onlyUnfilled, fid, ref.getPointer(), plt, fillAllautoPaintLines));
} else if (TVectorImageP vi = img) {
TPalette *palette = vi->getPalette();
assert(palette);
@@ -1257,6 +1241,7 @@ class MultiAreaFiller final : public SequencePainter {
int m_styleIndex;
bool m_autopaintLines;
RefImgTable m_refImgTable;
+ bool m_fillAllautoPaintLines;
public:
MultiAreaFiller(RefImgTable refImgTable, const TRectD &firstRect,
@@ -1279,14 +1264,16 @@ public:
MultiAreaFiller(RefImgTable &refImgTable, TStroke *&firstStroke,
TStroke *&lastStroke, bool unfilledOnly,
- std::wstring colorType, int styleIndex, bool autopaintLines)
+ std::wstring colorType, int styleIndex, bool autopaintLines,
+ bool fillAllautoPaintLines)
: m_firstRect()
, m_lastRect()
, m_unfilledOnly(unfilledOnly)
, m_colorType(colorType)
, m_styleIndex(styleIndex)
, m_autopaintLines(autopaintLines)
- , m_refImgTable(std::move(refImgTable)) {
+ , m_refImgTable(std::move(refImgTable))
+ , m_fillAllautoPaintLines(fillAllautoPaintLines) {
firstStroke->addRef();
lastStroke->addRef();
m_firstImage = new TVectorImage();
@@ -1303,16 +1290,19 @@ public:
TPointD p1 = m_firstRect.getP11() * (1 - t) + m_lastRect.getP11() * t;
TRectD rect(p0.x, p0.y, p1.x, p1.y);
fillAreaWithUndo(img, m_refImgTable[imgId], rect, 0, m_unfilledOnly,
- m_colorType, sl, fid, m_styleIndex, m_autopaintLines);
+ m_colorType, sl, fid, m_styleIndex, m_autopaintLines,
+ m_fillAllautoPaintLines);
} else {
if (t == 0)
fillAreaWithUndo(img, m_refImgTable[imgId], TRectD(),
m_firstImage->getStroke(0), m_unfilledOnly,
- m_colorType, sl, fid, m_styleIndex, m_autopaintLines);
+ m_colorType, sl, fid, m_styleIndex, m_autopaintLines,
+ m_fillAllautoPaintLines);
else if (t == 1)
fillAreaWithUndo(img, m_refImgTable[imgId], TRectD(),
m_lastImage->getStroke(0), m_unfilledOnly, m_colorType,
- sl, fid, m_styleIndex, m_autopaintLines);
+ sl, fid, m_styleIndex, m_autopaintLines,
+ m_fillAllautoPaintLines);
else
// if(t>1)
{
@@ -1326,7 +1316,8 @@ public:
fillAreaWithUndo(img, m_refImgTable[imgId], TRectD(),
vi->getStroke(0) /*, imgloc*/, m_unfilledOnly,
- m_colorType, sl, fid, m_styleIndex, m_autopaintLines);
+ m_colorType, sl, fid, m_styleIndex, m_autopaintLines,
+ m_fillAllautoPaintLines);
}
}
}
@@ -1505,6 +1496,7 @@ void AreaFillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e,
TImage *img) {
TVectorImageP vi = TImageP(img);
TToonzImageP ti = TToonzImageP(img);
+ m_paintAllAPs = e.isCtrlPressed();
if (!vi && !ti) {
m_selecting = false;
@@ -1594,7 +1586,8 @@ void AreaFillTool::leftButtonDoubleClick(const TPointD &pos,
{
if (m_firstFrameSelected && !slFidsPairs.empty()) {
MultiAreaFiller filler(refImgTable, m_firstStroke, stroke, m_onlyUnfilled,
- m_colorType, styleIndex, m_autopaintLines);
+ m_colorType, styleIndex, m_autopaintLines,
+ m_paintAllAPs);
filler.setSelectionUndo(new FillToolSelectionUndo(
m_currCell.second, m_currCell.first, slFidsPairs[0].first,
slFidsPairs[0].second));
@@ -1631,7 +1624,7 @@ void AreaFillTool::leftButtonDoubleClick(const TPointD &pos,
fillAreaWithUndo(m_parent->getImage(true), refImgTable[imgId], TRectD(),
stroke, m_onlyUnfilled, m_colorType,
m_level.getPointer(), m_parent->getCurrentFid(),
- styleIndex, m_autopaintLines);
+ styleIndex, m_autopaintLines, m_paintAllAPs);
TTool *t = app->getCurrentTool()->getTool();
if (t) t->notifyImageChanged();
}
@@ -1720,7 +1713,7 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {
fillAreaWithUndo(m_parent->getImage(true), refImgTable[imgId],
m_selectingRect, 0, m_onlyUnfilled, m_colorType,
m_level.getPointer(), m_parent->getCurrentFid(),
- styleIndex, m_autopaintLines);
+ styleIndex, m_autopaintLines, m_paintAllAPs);
m_parent->invalidate();
m_selectingRect.empty();
TTool *t = app->getCurrentTool()->getTool();
@@ -1749,7 +1742,7 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {
if (m_firstFrameSelected) {
MultiAreaFiller filler(refImgTable, m_firstStroke, stroke,
m_onlyUnfilled, m_colorType, styleIndex,
- m_autopaintLines);
+ m_autopaintLines, m_paintAllAPs);
filler.setSelectionUndo(new FillToolSelectionUndo(
m_currCell.second, m_currCell.first, slFidsPairs[0].first,
slFidsPairs[0].second));
@@ -1792,7 +1785,7 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {
stroke /*, imageLocation*/, m_onlyUnfilled,
m_colorType, m_level.getPointer(),
m_parent->getCurrentFid(), styleIndex,
- m_autopaintLines);
+ m_autopaintLines, m_paintAllAPs);
delete stroke;
TTool *t = app->getCurrentTool()->getTool();
if (t) t->notifyImageChanged();
diff --git a/toonz/sources/tnztools/filltool.h b/toonz/sources/tnztools/filltool.h
index fe28e2604..c83b9e461 100644
--- a/toonz/sources/tnztools/filltool.h
+++ b/toonz/sources/tnztools/filltool.h
@@ -59,6 +59,7 @@ private:
TPointD m_mousePosition;
bool m_onion;
bool m_isLeftButtonPressed;
+ bool m_paintAllAPs;
bool m_autopaintLines;
int m_bckStyleId;
diff --git a/toonz/sources/toonzlib/fillutil.cpp b/toonz/sources/toonzlib/fillutil.cpp
index 294dd1dd3..01704dfaf 100644
--- a/toonz/sources/toonzlib/fillutil.cpp
+++ b/toonz/sources/toonzlib/fillutil.cpp
@@ -57,7 +57,8 @@ void computeSeeds(const TRasterCM32P &r, TStroke *stroke,
//-----------------------------------------------------------------------------
void fillRegionExcept(const TRasterCM32P &ras, TRegion *r, int positive,
- int negative, TPalette *plt, int color, bool fillInks) {
+ int negative, TPalette *plt, int color, bool fillInks,
+ bool fillAllautoPaintLines) {
TRect bbox = convert(r->getBBox());
bbox *= ras->getBounds();
ras->lock();
@@ -74,12 +75,20 @@ void fillRegionExcept(const TRasterCM32P &ras, TRegion *r, int positive,
int to = std::min(tceil(intersections[j + 1]), bbox.x1);
TPixelCM32 *pix = line + from;
for (int k = from; k < to; k++, pix++) {
- if (fillInks && !pix->isPurePaint())
- pix->setInk(color); // Paint all inks
- // paint auto-paint lines
- else if (plt && plt->getStyle(pix->getInk())->getFlags() != 0)
- pix->setInk(color);
+ if (fillInks && !pix->isPurePaint()) pix->setInk(color);
if (pix->getPaint() != positive) pix->setPaint(negative);
+ if (!fillInks && plt) {
+ if (fillAllautoPaintLines &&
+ plt->getStyle(pix->getInk())->getFlags() != 0)
+ pix->setInk(color);
+ else if (pix->getPaint() == negative && pix->getTone()) {
+ TPoint pInk = nearestInkNotDiagonal(ras, TPoint(k, i));
+ TPixelCM32 *inkPix = ras->pixels(pInk.y) + pInk.x;
+ int ink = inkPix->getInk();
+ if (pInk != TPoint(-1, -1) && plt->getStyle(ink)->getFlags() != 0)
+ inkFill(ras, pInk, color, 0);
+ }
+ }
}
}
}
@@ -97,7 +106,7 @@ void fillOutsideOfStroke(const TRasterCM32P &r, TStroke *stroke, int color) {
TPoint oldP;
FillParameters params;
params.m_styleId = color;
- params.m_prevailing = false;
+ params.m_prevailing = true;
for (int i = 0; i < length; i++) {
TPoint p = convert(stroke->getPointAtLength(i));
if (p == oldP || !bbox.contains(p) ||
@@ -207,7 +216,8 @@ void fillautoInks(TRasterCM32P &rin, TRect &rect, const TRasterCM32P &rbefore,
//-----------------------------------------------------------------------------
bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,
- bool fillPaints, bool fillInks) {
+ bool fillPaints, bool fillInks,
+ bool fillAllautoPaintLines) {
// Viene trattato il caso fillInks
/*- In case of FillInk only -*/
m_ras->lock();
@@ -231,7 +241,7 @@ bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,
// fill borders with maxPaint
FillParameters params;
- params.m_prevailing = false;
+ params.m_prevailing = true;
params.m_styleId = TPixelCM32::getMaxPaint();
int ly = ras->getLy();
@@ -305,10 +315,21 @@ bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,
// paint auto-paint lines
if (fillInks && !pix->isPurePaint())
pix->setInk(color); // Paint all inks
- else if (m_palette && m_palette->getStyle(pix->getInk())->getFlags() != 0)
- inkFill(ras, TPoint(x, y), color, 0);
processPixel(*pix, *bak, true, color, onlyUnfilled, fillPaints, fillInks,
defRegionWithPaint, usePrevailingReferFill);
+ if (!fillInks && m_palette) {
+ if (fillAllautoPaintLines &&
+ m_palette->getStyle(pix->getInk())->getFlags() != 0)
+ inkSegment(ras, TPoint(x, y), color, 2.5, true);
+ else if (pix->getPaint() == color && pix->getTone()) {
+ TPoint pInk = nearestInkNotDiagonal(ras, TPoint(x, y));
+ TPixelCM32 *inkPix = ras->pixels(pInk.y) + pInk.x;
+ int ink = inkPix->getInk();
+ if (pInk != TPoint(-1, -1) &&
+ m_palette->getStyle(ink)->getFlags() != 0)
+ inkFill(ras, pInk, color, 0);
+ }
+ }
}
}
@@ -410,7 +431,7 @@ bool AreaFiller::rectFastFill(const TRect &rect, int color) {
void AreaFiller::strokeFill(const TRect &rect, TStroke *stroke, int color,
const bool onlyUnfilled, const bool fillPaints,
- const bool fillInks) {
+ const bool fillInks, bool fillAllautoPaintLines) {
TRect box = rect;
TRect bbox = m_ras->getBounds();
box *= bbox;
@@ -457,13 +478,14 @@ void AreaFiller::strokeFill(const TRect &rect, TStroke *stroke, int color,
if (refFill && fillInks) {
for (UINT i = 0; i < app.getRegionCount(); i++)
fillRegionExcept(ras, app.getRegion(i), TPixelCM32::getMaxPaint() - 1,
- TPixelCM32::getMaxPaint(), 0, color, false);
+ TPixelCM32::getMaxPaint(), 0, color, false, false);
removeUnneedReferLines(ras);
}
// Paint Lines and Areas
for (UINT i = 0; i < app.getRegionCount(); i++)
fillRegionExcept(ras, app.getRegion(i), TPixelCM32::getMaxPaint() - 1,
- TPixelCM32::getMaxPaint(), m_palette, color, fillInks);
+ TPixelCM32::getMaxPaint(), m_palette, color, fillInks,
+ fillAllautoPaintLines);
app.removeStroke(0);
if (!fillInks && refFill) removeUnneedReferLines(ras);