OpenToonz - An open-source full-featured 2D animation creation software
C
Add Preference for whether define region with both paint and inks allow to fill inside the saveBox or bounds Ink for area filler(FreeHand&Rectangle)
Abel You53216dbb7322
diff --git a/toonz/sources/include/tools/toolutils.h b/toonz/sources/include/tools/toolutils.hindex 4df92ed4e..bee595516 100644--- a/toonz/sources/include/tools/toolutils.h+++ b/toonz/sources/include/tools/toolutils.h@@ -200,13 +200,13 @@ public:class DVAPI TRasterUndo : public TToolUndo {protected:TTileSetCM32 *m_tiles;-+ bool m_updateSaveBox;TToonzImageP getImage() const;public:TRasterUndo(TTileSetCM32 *tiles, TXshSimpleLevel *level,const TFrameId &frameId, bool createdFrame, bool createdLevel,- const TPaletteP &oldPalette); // get tiles ownership+ const TPaletteP &oldPalette, bool updateSaveBox = true); // get tiles ownership~TRasterUndo();int getSize() const override;diff --git a/toonz/sources/include/toonz/fill.h b/toonz/sources/include/toonz/fill.hindex 697f8413f..2b14c7092 100644--- a/toonz/sources/include/toonz/fill.h+++ b/toonz/sources/include/toonz/fill.h@@ -11,7 +11,8 @@#else#define DVAPI DV_IMPORT_API#define DVVAR DV_IMPORT_VAR-#endif+#endif+#include <set>#include "ttilesaver.h"@@ -22,6 +23,10 @@#include "traster.h"#include "trastercm.h"+#include "preferences.h"+#define DEF_REGION_WITH_PAINT \+ Preferences::instance()->getBoolValue(PreferencesItemId::DefRegionWithPaint)+class TPalette;class FillParameters {@@ -122,7 +127,7 @@ Fill \b rect in raster with \b color.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 rectFill(const TRect &rect, const TRect &saveBox, int color, bool onlyUnfilled,bool fillPaints, bool fillInks);/*!@@ -131,7 +136,7 @@ Fill the raster region contained in spline \b s with \b color.else if \b fillInks is false fill only paint delimited by ink;else fill ink and paint in region contained in spline.*/- void strokeFill(TStroke *s, int color, bool onlyUnfilled, bool fillPaints,+ void strokeFill(const TRect& rect, TStroke *s, int color, bool onlyUnfilled, bool fillPaints,bool fillInks);};diff --git a/toonz/sources/include/toonz/preferencesitemids.h b/toonz/sources/include/toonz/preferencesitemids.hindex 2737a91b6..44c388d6d 100644--- a/toonz/sources/include/toonz/preferencesitemids.h+++ b/toonz/sources/include/toonz/preferencesitemids.h@@ -110,6 +110,7 @@ enum PreferencesItemId {// Tools// dropdownShortcutsCycleOptions, // removedFillOnlysavebox,+ DefRegionWithPaint,multiLayerStylePickerEnabled,cursorBrushType,cursorBrushStyle,diff --git a/toonz/sources/tnztools/filltool.cpp b/toonz/sources/tnztools/filltool.cppindex 307d23400..52ea58ce1 100644--- a/toonz/sources/tnztools/filltool.cpp+++ b/toonz/sources/tnztools/filltool.cpp@@ -458,7 +458,7 @@ public:int paintId, TXshSimpleLevel *level,std::wstring colorType, bool onlyUnfilled,const TFrameId &fid, TRaster32P refImg, TPalette *palette)- : TRasterUndo(tileSet, level, fid, false, false, 0)+ : TRasterUndo(tileSet, level, fid, false, false, 0, false), m_fillArea(fillArea), m_paintId(paintId), m_colorType(colorType)@@ -474,10 +474,10 @@ public:TRasterCM32P ras = image->getRaster();AreaFiller filler(ras, m_refImg, m_palette);if (!m_s)- filler.rectFill(m_fillArea, m_paintId, m_onlyUnfilled,+ filler.rectFill(m_fillArea, image->getSavebox(), m_paintId, m_onlyUnfilled,m_colorType != LINES, m_colorType != AREAS);else- filler.strokeFill(m_s, m_paintId, m_onlyUnfilled, m_colorType != LINES,+ filler.strokeFill(m_fillArea, m_s, m_paintId, m_onlyUnfilled, m_colorType != LINES,m_colorType != AREAS);if (m_palette) {@@ -840,14 +840,14 @@ void fillAreaWithUndo(const TImageP &img, const TRaster32P &ref,if (TToonzImageP ti = img) {// allargo di 1 la savebox, perche cosi' il rectfill di tutta l'immagine fa// una sola fillata+ TRasterCM32P ras = ti->getRaster();TRect refSavebox = ref ? ref->getBounds() : TRect();- TRect enlargedSavebox = (ti->getSavebox().enlarge(1) + refSavebox) *- TRect(TPoint(0, 0), ti->getSize());+ //TRect enlargedSavebox = (ti->getSavebox().enlarge(1) + refSavebox) * ras->getBounds();TRect strokeBox = ToonzImageUtils::convertWorldToRaster(selArea, ti);- TRect rasterFillArea = strokeBox * enlargedSavebox;+ TRect savebox = ti->getSavebox();+ TRect rasterFillArea = strokeBox * savebox;if (rasterFillArea.isEmpty()) return;- TRasterCM32P ras = ti->getRaster();/*-- tileSetでFill範囲のRectをUndoに格納しておく --*/TTileSetCM32 *tileSet = new TTileSetCM32(ras->getSize());tileSet->add(ras, rasterFillArea);@@ -866,7 +866,7 @@ void fillAreaWithUndo(const TImageP &img, const TRaster32P &ref,}AreaFiller filler(raux, ref, plt);if (!stroke) {- bool ret = filler.rectFill(rasterFillArea, cs, onlyUnfilled,+ bool ret = filler.rectFill(rasterFillArea, ti->getSavebox(), cs, onlyUnfilled,colorType != LINES, colorType != AREAS);if (!ret) {delete tileSet;@@ -888,11 +888,11 @@ void fillAreaWithUndo(const TImageP &img, const TRaster32P &ref,if (stroke) stroke->transform(TTranslation(convert(ras->getCenter())));if (ref)stroke->transform(TTranslation(-convert(ti->getSavebox().getP00())));- filler.strokeFill(stroke, cs, onlyUnfilled, colorType != LINES,+ filler.strokeFill(rasterFillArea, stroke, cs, onlyUnfilled, colorType != LINES,colorType != AREAS);}- ToolUtils::updateSaveBox(sl, fid);+ //ToolUtils::updateSaveBox(sl, fid);TUndoManager::manager()->add(new RasterRectFillUndo(tileSet, stroke, rasterFillArea, cs, sl,diff --git a/toonz/sources/tnztools/toolutils.cpp b/toonz/sources/tnztools/toolutils.cppindex 3d7ec35cc..80a7e3024 100644--- a/toonz/sources/tnztools/toolutils.cpp+++ b/toonz/sources/tnztools/toolutils.cpp@@ -670,9 +670,11 @@ int ToolUtils::TToolUndo::m_idCount = 0;ToolUtils::TRasterUndo::TRasterUndo(TTileSetCM32 *tiles, TXshSimpleLevel *level,const TFrameId &frameId, bool createdFrame,bool createdLevel,- const TPaletteP &oldPalette)+ const TPaletteP &oldPalette,+ bool updateSavebox): TToolUndo(level, frameId, createdFrame, createdLevel, oldPalette)- , m_tiles(tiles) {}+ , m_tiles(tiles)+ , m_updateSaveBox(updateSavebox){}//------------------------------------------------------------------------------------------@@ -708,7 +710,8 @@ void ToolUtils::TRasterUndo::undo() const {if (!image) return;ToonzImageUtils::paste(image, m_tiles);- ToolUtils::updateSaveBox(m_level, m_frameId);+ if(m_updateSaveBox)+ ToolUtils::updateSaveBox(m_level, m_frameId);}removeLevelAndFrameIfNeeded();diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cppindex 5b1e3a3fd..c320c5e33 100644--- a/toonz/sources/toonz/preferencespopup.cpp+++ b/toonz/sources/toonz/preferencespopup.cpp@@ -458,17 +458,17 @@ QList<ComboBoxItem> PreferencesPopup::buildFontStyleList() const {//------------------------------------------------------------------------------QList<ComboBoxItem> PreferencesPopup::buildSvnUserList() const {- PermissionsManager* instance = PermissionsManager::instance();- QList<ComboBoxItem> userList;- std::string username;- username = instance->getSVNUserName(0);- for (int i = 1; !username.empty(); i++) {- userList.append(ComboBoxItem(QString::fromStdString(username),- QString::fromStdString(username)));- username = instance->getSVNUserName(i);- }- return userList;+QList<ComboBoxItem> PreferencesPopup::buildSvnUserList() const {+ PermissionsManager* instance = PermissionsManager::instance();+ QList<ComboBoxItem> userList;+ std::string username;+ username = instance->getSVNUserName(0);+ for (int i = 1; !username.empty(); i++) {+ userList.append(ComboBoxItem(QString::fromStdString(username),+ QString::fromStdString(username)));+ username = instance->getSVNUserName(i);+ }+ return userList;}QList<ComboBoxItem> PreferencesPopup::buildSvnRepList() const {@@ -477,11 +477,9 @@ QList<ComboBoxItem> PreferencesPopup::buildSvnRepList() const {QList<SVNRepository> repositories = instance->getRepositories();for (int i = 0; i < repositories.size(); i++) {SVNRepository r = repositories.at(i);- repList.append(ComboBoxItem(r.m_name,- r.m_name));+ repList.append(ComboBoxItem(r.m_name, r.m_name));}return repList;-}//-----------------------------------------------------------------------------@@ -1310,6 +1308,8 @@ QString PreferencesPopup::getUIString(PreferencesItemId id) {// {dropdownShortcutsCycleOptions, tr("Dropdown Shortcuts:")}, //// removed{FillOnlysavebox, tr("Use the TLV Savebox to Limit Filling Operations")},+ {DefRegionWithPaint,+ tr("Define filling region with both PAINT and INK")},{multiLayerStylePickerEnabled,tr("Multi Layer Style Picker: Switch Levels by Picking")},{cursorBrushType, tr("Basic Cursor Type:")},@@ -1765,7 +1765,9 @@ QWidget* PreferencesPopup::createInterfacePage() {->setSizeAdjustPolicy(QComboBox::AdjustToContents);QGridLayout* colorCalibLay = insertGroupBoxUI(colorCalibrationEnabled, lay);- { insertUI(colorCalibrationLutPaths, colorCalibLay); }+ {+ insertUI(colorCalibrationLutPaths, colorCalibLay);+ }insertUI(displayIn30bit, lay);row = lay->rowCount();lay->addWidget(check30bitBtn, row - 1, 2, Qt::AlignRight);@@ -1842,7 +1844,9 @@ QWidget* PreferencesPopup::createLoadingPage() {insertUI(importPolicy, lay, getComboItemList(importPolicy));insertUI(renamePolicy, lay, getComboItemList(renamePolicy));QGridLayout* autoExposeLay = insertGroupBoxUI(autoExposeEnabled, lay);- { insertUI(autoRemoveUnusedLevels, autoExposeLay); }+ {+ insertUI(autoRemoveUnusedLevels, autoExposeLay);+ }insertUI(subsceneFolderEnabled, lay);insertUI(removeSceneNumberFromLoadedLevelName, lay);insertUI(IgnoreImageDpi, lay);@@ -1902,7 +1906,9 @@ QWidget* PreferencesPopup::createSavingPage() {}insertUI(replaceAfterSaveLevelAs, lay);QGridLayout* backupLay = insertGroupBoxUI(backupEnabled, lay);- { insertUI(backupKeepCount, backupLay); }+ {+ insertUI(backupKeepCount, backupLay);+ }QLabel* matteColorLabel =new QLabel(tr("Matte color is used for background when overwriting ""raster levels with transparent pixels\nin non "@@ -2052,6 +2058,7 @@ QWidget* PreferencesPopup::createToolsPage() {// insertUI(dropdownShortcutsCycleOptions, lay,// getComboItemList(dropdownShortcutsCycleOptions));+ insertUI(PreferencesItemId::DefRegionWithPaint, lay);insertUI(FillOnlysavebox, lay);insertUI(multiLayerStylePickerEnabled, lay);QGridLayout* cursorOptionsLay = insertGroupBox(tr("Cursor Options"), lay);@@ -2100,7 +2107,9 @@ QWidget* PreferencesPopup::createXsheetPage() {insertUI(ignoreAlphaonColumn1Enabled, lay);QGridLayout* showKeyLay =insertGroupBoxUI(showKeyframesOnXsheetCellArea, lay);- { insertUI(showXsheetCameraColumn, showKeyLay); }+ {+ insertUI(showXsheetCameraColumn, showKeyLay);+ }insertUI(useArrowKeyToShiftCellSelection, lay);insertUI(inputCellsWithoutDoubleClickingEnabled, lay);insertUI(shortcutCommandsWhileRenamingCellEnabled, lay);@@ -2273,12 +2282,11 @@ QWidget* PreferencesPopup::createColorsPage() {//-----------------------------------------------------------------------------QWidget* PreferencesPopup::createVersionControlPage() {-SVNConfigWriter* writer = new SVNConfigWriter();- QWidget* widget = new QWidget(this);- QGridLayout* lay = new QGridLayout();+ QWidget* widget = new QWidget(this);+ QGridLayout* lay = new QGridLayout();QHBoxLayout* svnUserLay = new QHBoxLayout();- QHBoxLayout* svnRepLay = new QHBoxLayout();+ QHBoxLayout* svnRepLay = new QHBoxLayout();QLabel* repLabel = new QLabel(QString("Repositories*: "));svnRepLay->addWidget(repLabel);@@ -2286,7 +2294,7 @@ QWidget* PreferencesPopup::createVersionControlPage() {QList<ComboBoxItem> repositoryList = PreferencesPopup::buildSvnRepList();for (const ComboBoxItem& item : repositoryList)repoCombo->addItem(item.first, item.second);- QPushButton* addRep = new QPushButton("+");+ QPushButton* addRep = new QPushButton("+");addRep->setFixedSize(20, 20);QPushButton* removeRep = new QPushButton("-");removeRep->setFixedSize(20, 20);@@ -2294,7 +2302,7 @@ QWidget* PreferencesPopup::createVersionControlPage() {QLabel* userLabel = new QLabel(QString("Users*: "));svnUserLay->addWidget(userLabel);- QComboBox* userCombo = new QComboBox();+ QComboBox* userCombo = new QComboBox();QList<ComboBoxItem> userList = PreferencesPopup::buildSvnUserList();for (const ComboBoxItem& item : userList)userCombo->addItem(item.first, item.second);@@ -2309,7 +2317,7 @@ QWidget* PreferencesPopup::createVersionControlPage() {svnRepLay->addWidget(addRep);svnRepLay->addWidget(removeRep);svnRepLay->addWidget(editRep);-+svnUserLay->setSpacing(5);svnUserLay->addWidget(userCombo);svnUserLay->addWidget(addUser);@@ -2324,13 +2332,13 @@ QWidget* PreferencesPopup::createVersionControlPage() {lay->addLayout(svnRepLay, 4, 0);insertUI(automaticSVNFolderRefreshEnabled, lay);insertUI(latestVersionCheckEnabled, lay);-+lay->setRowStretch(lay->rowCount(), 1);insertFootNote(lay);widget->setLayout(lay);m_onEditedFuncMap.insert(SVNEnabled, &PreferencesPopup::onSVNEnabledChanged);-+connect(addRep, &QPushButton::clicked, this, [repoCombo, writer]() {QString addedRepo = writer->writeRepository("");if (repoCombo->findText(addedRepo) == -1 && !addedRepo.isEmpty()) {@@ -2339,8 +2347,8 @@ QWidget* PreferencesPopup::createVersionControlPage() {}});connect(removeRep, &QPushButton::clicked, this, [repoCombo, writer]() {- writer->writeRepository(repoCombo->currentText(), QString(),- QString(), true);+ writer->writeRepository(repoCombo->currentText(), QString(), QString(),+ true);repoCombo->removeItem(repoCombo->currentIndex());});connect(editRep, &QPushButton::clicked, this, [repoCombo, writer]() {@@ -2348,7 +2356,7 @@ QWidget* PreferencesPopup::createVersionControlPage() {writer->writeRepository(repoCombo->currentText());});- connect(addUser, &QPushButton::clicked, this, [userCombo, writer]() {+ connect(addUser, &QPushButton::clicked, this, [userCombo, writer]() {QString addedUser = writer->writeSvnUser("");if (userCombo->findText(addedUser) == -1 && !addedUser.isEmpty()) {userCombo->addItem(addedUser);@@ -2361,7 +2369,7 @@ QWidget* PreferencesPopup::createVersionControlPage() {});connect(editUser, &QPushButton::clicked, this, [userCombo, writer]() {if (userCombo->currentText().isEmpty()) return;- writer->writeSvnUser(userCombo->currentText());+ writer->writeSvnUser(userCombo->currentText());});return widget;diff --git a/toonz/sources/toonzlib/fill.cpp b/toonz/sources/toonzlib/fill.cppindex 6a08bc16b..e78469f19 100644--- a/toonz/sources/toonzlib/fill.cpp+++ b/toonz/sources/toonzlib/fill.cpp@@ -54,6 +54,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,oldtone = pix->getTone();tone = oldtone;for (; pix <= limit; pix++) {+ if (DEF_REGION_WITH_PAINT && pix->getPaint() != paintAtClickPos) break;if (pix->getPaint() == paint) break;tone = pix->getTone();if (tone == 0) break;@@ -90,6 +91,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,tmp_limit = pix + 10; // edge stop fill == 10 per defaultif (limit > tmp_limit) limit = tmp_limit;for (; pix <= limit; pix++) {+ if (DEF_REGION_WITH_PAINT && pix->getPaint() != paintAtClickPos) break;if (pix->getPaint() == paint) break;if (pix->getTone() != 0) break;}@@ -104,6 +106,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,oldtone = pix->getTone();tone = oldtone;for (pix--; pix >= limit; pix--) {+ if (DEF_REGION_WITH_PAINT && pix->getPaint() != paintAtClickPos) break;if (pix->getPaint() == paint) break;tone = pix->getTone();if (tone == 0) break;@@ -140,6 +143,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,tmp_limit = pix - 10;if (limit < tmp_limit) limit = tmp_limit;for (; pix >= limit; pix--) {+ if (DEF_REGION_WITH_PAINT && pix->getPaint() != paintAtClickPos) break;if (pix->getPaint() == paint) break;if (pix->getTone() != 0) break;}@@ -167,20 +171,25 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,}}}- if (refImagePut && pix->getInk() == TPixelCM32::getMaxInk())+ if (refImagePut && pix->getInk() == TPixelCM32::getMaxInk() &&+ !DEF_REGION_WITH_PAINT)pix->setInk(paint);pix->setPaint(paint);}- // Make sure the up and down ref Ink Pixels can be painted- if (refImagePut && p.y > 0 && p.y < r->getLy() - 1) {+ // Make sure the Surround ref Ink Pixels can be painted+ if (refImagePut && !DEF_REGION_WITH_PAINT && p.y > 0 &&+ p.y < r->getLy() - 1) {pix = line + xa;for (n = 0; n < xb - xa + 1; n++, pix++) {if (pix->isPurePaint()) {TPixelCM32 *upPix = pix - r->getWrap();TPixelCM32 *downPix = pix + r->getWrap();- if (upPix->getInk() == TPixelCM32::getMaxInk()) upPix->setInk(paint);- if (downPix->getInk() == TPixelCM32::getMaxInk())+ if (upPix->getInk() == TPixelCM32::getMaxInk() &&+ !DEF_REGION_WITH_PAINT)+ upPix->setInk(paint);+ if (downPix->getInk() == TPixelCM32::getMaxInk() &&+ !DEF_REGION_WITH_PAINT)downPix->setInk(paint);}}@@ -585,7 +594,8 @@ bool fill(const TRasterCM32P &r, const FillParameters ¶ms,// protruding behind the colored lineif (pix->getPaint() != paint && tone <= oldtone && tone != 0 &&(pix->getPaint() != pix->getInk() ||- pix->getPaint() == paintAtClickedPos)) {+ pix->getPaint() == paintAtClickedPos) &&+ (!DEF_REGION_WITH_PAINT || pix->getPaint() == paintAtClickedPos)) {fillRow(r, TPoint(x, y), xc, xd, paint, params.m_palette, saver,params.m_prevailing, refImagePut, paintAtClickedPos);if (xc < xa) seeds.push(FillSeed(xc, xa - 1, y, -dy));diff --git a/toonz/sources/toonzlib/fillutil.cpp b/toonz/sources/toonzlib/fillutil.cppindex f1c335e34..3d38df225 100644--- a/toonz/sources/toonzlib/fillutil.cpp+++ b/toonz/sources/toonzlib/fillutil.cpp@@ -11,9 +11,14 @@#include "skeletonlut.h"#include "tpixelutils.h"#include "tropcm.h"-+#include "tenv.h"#include <stack>+#include "toonz/preferences.h"++#define DEF_REGION_WITH_PAINT \+ Preferences::instance()->getBoolValue(PreferencesItemId::DefRegionWithPaint)+using namespace SkeletonLut;//-----------------------------------------------------------------------------@@ -38,8 +43,8 @@ void computeSeeds(const TRasterCM32P &r, TStroke *stroke,//------------------------------------------------------------------------------void fillArea(const TRasterCM32P &ras, TRegion *r, int colorId,- bool onlyUnfilled, bool fillPaints, bool fillInks, TPalette *plt) {+void fillRegionExcept(const TRasterCM32P &ras, TRegion *r, int positive,+ int negative) {TRect bbox = convert(r->getBBox());bbox *= ras->getBounds();ras->lock();@@ -56,11 +61,7 @@ void fillArea(const TRasterCM32P &ras, TRegion *r, int colorId,int to = std::min(tceil(intersections[j + 1]), bbox.x1);TPixelCM32 *pix = line + from;for (int k = from; k < to; k++, pix++) {- if (plt && plt->getStyle(pix->getInk())->getFlags() != 0)- pix->setInk(colorId);- if (fillPaints && (!onlyUnfilled || pix->getPaint() == 0))- pix->setPaint(colorId);- if (fillInks) pix->setInk(colorId);+ if (pix->getPaint() != positive) pix->setPaint(negative);}}}@@ -69,6 +70,27 @@ void fillArea(const TRasterCM32P &ras, TRegion *r, int colorId,//-----------------------------------------------------------------------------+void fillOutsideOfStroke(const TRasterCM32P &r, TStroke *stroke, int color) {+ int length = (int)stroke->getLength();+ TRect bbox = r->getBounds();+ int lx = r->getLx();+ int ly = r->getLy();++ TPoint oldP;+ FillParameters params;+ params.m_styleId = color;+ params.m_prevailing = false;+ for (int i = 0; i < length; i++) {+ TPoint p = convert(stroke->getPointAtLength(i));+ if (p == oldP || !bbox.contains(p)) continue;+ params.m_p = p;+ fill(r, params);+ oldP = p;+ }+}++//-----------------------------------------------------------------------------+void restoreColors(const TRasterCM32P &r,const std::vector<std::pair<TPoint, int>> &seeds) {FillParameters params;@@ -164,8 +186,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 AreaFiller::rectFill(const TRect &rect, const TRect &saveBox, int color,+ bool onlyUnfilled, bool fillPaints, bool fillInks) {// Viene trattato il caso fillInks/*- In case of FillInk only -*/if (!fillPaints) {@@ -180,130 +202,163 @@ bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,return true;}- TRect r = m_bounds * rect;+ if (m_refRas) TRop::putRefImage(m_ras, m_refRas);- int dx = r.x1 - r.x0;- int dy = (r.y1 - r.y0) * m_wrap;+ TRect r = m_bounds * rect;+ int dx = r.x1 - r.x0;+ int dy = (r.y1 - r.y0) * m_wrap;if (dx < 2 || dy < 2) // rect degenere(area contenuta nulla), skippo.return false;-- std::vector<int> frameSeed(2 * (r.getLx() + r.getLy() - 2));-- int x, y, count1, count2;- /*- Move ptr to the start of the Rectangular range -*/- Pixel *ptr = m_pixels + r.y0 * m_wrap + r.x0;- count1 = 0;- count2 = r.y1 - r.y0 + 1;-// Se il rettangolo non contiene il bordo del raster e se tutti i pixels// contenuti nel rettangolo sono pure paint non deve fare nulla!- if (!rect.contains(m_bounds) && areRectPixelsPurePaint(m_pixels, r, m_wrap))+ if (!DEF_REGION_WITH_PAINT && !rect.contains(m_bounds) &&+ areRectPixelsPurePaint(m_pixels, r, m_wrap))return false;- if (m_refRas) TRop::putRefImage(m_ras, m_refRas);+ TRasterCM32P ras = m_ras->extract(rect.x0, rect.y0, rect.x1, rect.y1);+ TRasterCM32P backupRas = ras->clone();- // Viene riempito frameSeed con tutti i paint delle varie aree del rettangolo- // di contorno.- // Viene verificato se i pixels del rettangolo sono tutti pure paint.- /*- Store the Paint ID of the contour in the frameseed -*/- for (y = r.y0; y <= r.y1; y++, ptr += m_wrap, count1++, count2++) {- if (r.x0 > 0) frameSeed[count1] = ptr->getPaint();- if (r.x1 < m_ras->getLx() - 1) frameSeed[count2] = (ptr + dx)->getPaint();- }- ptr = m_pixels + r.y0 * m_wrap + r.x0 + 1;- count1 = count2;- count2 = count1 + r.x1 - r.x0 - 1;- for (x = r.x0 + 1; x < r.x1; x++, ptr++, count1++, count2++) {- if (r.y0 > 0) frameSeed[count1] = ptr->getPaint();- if (r.y1 < m_ras->getLy() - 1) frameSeed[count2] = (ptr + dy)->getPaint();- }- assert(count2 == 2 * (r.getLx() + r.getLy() - 2));-- // Viene fillato l'interno e il bordo del rettangolo rect con color- Pixel *pix = m_pixels + r.y0 * m_wrap + r.x0;- if (onlyUnfilled)- for (y = r.y0; y <= r.y1; y++, pix += m_wrap - dx - 1) {- for (x = r.x0; x <= r.x1; x++, pix++) {- if (pix->getPaint() == 0) // BackgroundStyle- pix->setPaint(color);- if (fillInks) pix->setInk(color);+ // fill borders with maxPaint+ FillParameters params;+ params.m_prevailing = false;+ params.m_styleId = TPixelCM32::getMaxPaint();++ int ly = ras->getLy();+ int lx = ras->getLx();++ TPixelCM32 *upPix = ras->pixels(0);+ TPixelCM32 *dnPix = backupRas->pixels(ly - 1);+ bool fillOnlySaveBox =+ saveBox != TRect() && Preferences::instance()->getFillOnlySavebox();+ bool topSame = (fillOnlySaveBox ? rect.y0 == saveBox.y0 : rect.x1 == rect.y0);+ bool bottomSame = (fillOnlySaveBox ? rect.y1 == saveBox.y1 : rect.x1 == m_bounds.y1);+ bool leftSame = (fillOnlySaveBox ? rect.x0 == saveBox.x0 : rect.x1 == m_bounds.x0);+ bool rightSame = (fillOnlySaveBox ? rect.x1 == saveBox.x1 : rect.x1 == m_bounds.x1);++ int sameCount = Preferences::instance()->getFillOnlySavebox() ?+ (int)topSame + (int)bottomSame + (int)leftSame + (int)rightSame : 0;++ // --- Top Edge ---+ if (!(sameCount != 4 && topSame)) {+ TPixelCM32 *upPix = ras->pixels(0);+ for (int x = 1; x < lx - 1; ++x) {+ if (upPix->getPaint() != TPixelCM32::getMaxPaint()) {+ params.m_p = TPoint(x, 0);+ fill(ras, params);}+ ++upPix;}- else- for (y = r.y0; y <= r.y1; y++, pix += m_wrap - dx - 1) {- for (x = r.x0; x <= r.x1; x++, pix++) {- pix->setPaint(color);- if (fillInks) pix->setInk(color);+ }++ // --- Bottom Edge ---+ if (!(sameCount != 4 && bottomSame)) {+ TPixelCM32 *dnPix = backupRas->pixels(ly - 1);+ for (int x = 1; x < lx - 1; ++x) {+ if (dnPix->getPaint() != TPixelCM32::getMaxPaint()) {+ params.m_p = TPoint(x, ly - 1);+ fill(ras, params);}+ ++dnPix;}+ }- // Vengono fillati i pixel del rettangolo con i paint (mantenuti in frameSeed)- // che- // c'erano prima di fillare l'intero rettangolo, in questo modo si riportano- // al colore originale le aree che non sono chiuse e non dovevano essere- // fillate.- count1 = 0;- FillParameters params;- // in order to make the paint to protlude behind the line- params.m_prevailing = false;- if (r.x0 > 0)- for (y = r.y0; y <= r.y1; y++) {- params.m_p = TPoint(r.x0, y);- params.m_styleId = frameSeed[count1++];- fill(m_ras, params);- }- else- count1 += r.y1 - r.y0 + 1;-- if (r.x1 < m_ras->getLx() - 1)- for (y = r.y0; y <= r.y1; y++) {- params.m_p = TPoint(r.x1, y);- params.m_styleId = frameSeed[count1++];- fill(m_ras, params);+ // --- Left Edge ---+ if (!(sameCount != 4 && leftSame)) {+ for (int y = 0; y < ly; ++y) {+ TPixelCM32 *pix = ras->pixels(y);+ if (pix->getPaint() != TPixelCM32::getMaxPaint()) {+ params.m_p = TPoint(0, y);+ fill(ras, params);+ }}- else- count1 += r.y1 - r.y0 + 1;-- if (r.y0 > 0)- for (x = r.x0 + 1; x < r.x1; x++) {- params.m_p = TPoint(x, r.y0);- params.m_styleId = frameSeed[count1++];- fill(m_ras, params);+ }++ // --- Right Edge ---+ if (!(sameCount != 4 && rightSame)) {+ for (int y = 0; y < ly; ++y) {+ TPixelCM32 *pix = ras->pixels(y) + (lx - 1);+ if (pix->getPaint() != TPixelCM32::getMaxPaint()) {+ params.m_p = TPoint(lx - 1, y);+ fill(ras, params);+ }}- else- count1 += r.x1 - r.x0 - 1;-- if (r.y1 < m_ras->getLy() - 1)- for (x = r.x0 + 1; x < r.x1; x++) {- params.m_p = TPoint(x, r.y1);- params.m_styleId = frameSeed[count1++];- fill(m_ras, params);+ }++ for (int y = 0; y < ly; ++y) {+ TPixelCM32 *pix = ras->pixels(y);+ TPixelCM32 *bak = backupRas->pixels(y);+ for (int x = 0; x < lx; ++x, ++pix, ++bak) {+ if (fillInks && !pix->isPurePaint()) pix->setInk(color);+ if (!DEF_REGION_WITH_PAINT && pix->getInk() == TPixelCM32::getMaxInk())+ pix->setInk(color);+ if (pix->getPaint() == TPixelCM32::getMaxPaint())+ pix->setPaint(bak->getPaint());+ else if (onlyUnfilled && pix->getPaint() != 0)+ continue;+ else+ pix->setPaint(color);}+ }if (m_refRas) TRop::eraseRefInks(m_ras);+return true;}//------------------------------------------------------------------------------void AreaFiller::strokeFill(TStroke *stroke, int color, bool onlyUnfilled,- bool fillPaints, bool fillInks) {+void AreaFiller::strokeFill(const TRect &rect, TStroke *stroke, int color,+ bool onlyUnfilled, bool fillPaints, bool fillInks) {m_ras->lock();if (m_refRas) TRop::putRefImage(m_ras, m_refRas);+ TRect box = rect;+ TRect bbox = m_ras->getBounds();+ box *= bbox;++ TRasterCM32P ras = m_ras->extract(box);+ TRasterCM32P backupRas = ras->clone();+ stroke->transform(TTranslation(-box.x0, -box.y0));- std::vector<std::pair<TPoint, int>> seeds;- computeSeeds(m_ras, stroke, seeds);+ // std::vector<std::pair<TPoint, int>> seeds;+ // computeSeeds(m_ras, stroke, seeds);+ fillOutsideOfStroke(ras, stroke, TPixelCM32::getMaxPaint() - 1);TVectorImage app;app.addStroke(stroke);app.findRegions();for (UINT i = 0; i < app.getRegionCount(); i++)- fillArea(m_ras, app.getRegion(i), colorId, onlyUnfilled, fillPaints,- fillInks, m_palette);+ fillRegionExcept(ras, app.getRegion(i), TPixelCM32::getMaxPaint() - 1,+ TPixelCM32::getMaxPaint());app.removeStroke(0);- stroke->transform(TTranslation(convert(-m_ras->getCenter())));- restoreColors(m_ras, seeds);+ int lx = box.getLx(), ly = box.getLy();+ for (int y = 0; y < ly; ++y) {+ TPixelCM32 *pix = ras->pixels(y);+ TPixelCM32 *bak = backupRas->pixels(y);+ for (int x = 0; x < lx; ++x, ++pix, ++bak) {+ if (pix->getPaint() == TPixelCM32::getMaxPaint()) {+ if (!DEF_REGION_WITH_PAINT && pix->getInk() == TPixelCM32::getMaxInk())+ pix->setInk(color);+ if (m_palette && m_palette->getStyle(pix->getInk())->getFlags() != 0)+ pix->setInk(color);+ if (fillInks && !pix->isPurePaint()) pix->setInk(color);+ if (fillPaints) {+ if (onlyUnfilled && bak->getPaint() != 0) {+ pix->setPaint(bak->getPaint());+ continue;+ } else+ pix->setPaint(color);+ } else+ pix->setPaint(bak->getPaint());+ } else+ pix->setPaint(bak->getPaint());+ }+ }++ stroke->transform(TTranslation(box.x0, box.y0));+ // stroke->transform(TTranslation(convert(-m_ras->getCenter())));+ // restoreColors(m_ras, seeds);+if (m_refRas) TRop::eraseRefInks(m_ras);m_ras->unlock();}diff --git a/toonz/sources/toonzlib/imagepainter.cpp b/toonz/sources/toonzlib/imagepainter.cppindex b75ea52d2..0033b69ce 100644--- a/toonz/sources/toonzlib/imagepainter.cpp+++ b/toonz/sources/toonzlib/imagepainter.cpp@@ -77,7 +77,7 @@ inline void quickput(const TRasterP &rout, const TRasterP &rin,if (tc & ToonzCheck::eGap) {srcCM32 = srcCM32->clone();- AreaFiller(srcCM32).rectFill(srcCM32->getBounds(), 1, true, true,+ AreaFiller(srcCM32).rectFill(srcCM32->getBounds(), TRect(), 1, true, true,false);}diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cppindex efcb6987f..d43232077 100644--- a/toonz/sources/toonzlib/preferences.cpp+++ b/toonz/sources/toonzlib/preferences.cpp@@ -544,6 +544,7 @@ void Preferences::definePreferenceItems() {// 1); // Cycle through the available options (changed from bool to// int)define(FillOnlysavebox, "FillOnlysavebox", QMetaType::Bool, false);+ define(DefRegionWithPaint, "FillDefRegionWithPaint", QMetaType::Bool, true);define(multiLayerStylePickerEnabled, "multiLayerStylePickerEnabled",QMetaType::Bool, false);define(cursorBrushType, "cursorBrushType", QMetaType::QString, "Small");diff --git a/toonz/sources/toonzlib/stagevisitor.cpp b/toonz/sources/toonzlib/stagevisitor.cppindex 0737df78d..170e9667c 100644--- a/toonz/sources/toonzlib/stagevisitor.cpp+++ b/toonz/sources/toonzlib/stagevisitor.cpp@@ -564,7 +564,7 @@ void RasterPainter::flushRasterImages() {plt = m_nodes[i].m_palette->clone();gapCheckIndex = plt->addStyle(TPixel::Magenta);if (tc & ToonzCheck::eGap)- AreaFiller(srcCm).rectFill(m_nodes[i].m_savebox, 1, true, true,+ AreaFiller(srcCm).rectFill(m_nodes[i].m_savebox,TRect(), 1, true, true,false);if (tc & ToonzCheck::eAutoclose && m_nodes[i].m_onionMode == Node::eOnionSkinNone) {auto settings = ToonzCheck::instance()->getAutocloseSettings();@@ -583,7 +583,7 @@ void RasterPainter::flushRasterImages() {int gapFillIndex =plt->addStyle(TPixelRGBM32(244, 186, 148, 0xff)); // orangeplt->getStyle(gapFillIndex)->setFlags(1);- AreaFiller(srcCm).rectFill(m_nodes[i].m_savebox, gapFillIndex,+ AreaFiller(srcCm).rectFill(m_nodes[i].m_savebox,TRect(), gapFillIndex,true, true, false);}}