Skip to content

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

C

pencilmode for t.raster eraser freehand polyline

shun-iwasawad02ca13b9318
diff --git a/toonz/sources/include/tools/toolutils.h b/toonz/sources/include/tools/toolutils.h
index c17fad7fc..a5b06fc34 100644
--- a/toonz/sources/include/tools/toolutils.h
+++ b/toonz/sources/include/tools/toolutils.h
@@ -119,7 +119,7 @@ QList<TRect> splitRect(const TRect &first, const TRect &second);
//! the \b imageBounds.
//! If this intersection is empty a TRaster32P() is returned.
TRaster32P convertStrokeToImage(TStroke *stroke, const TRect &imageBounds,
- TPoint &pos);
+ TPoint &pos, bool pencilMode = false);
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/tnztools/rastererasertool.cpp b/toonz/sources/tnztools/rastererasertool.cpp
index 95b9056db..e6fd04921 100644
--- a/toonz/sources/tnztools/rastererasertool.cpp
+++ b/toonz/sources/tnztools/rastererasertool.cpp
@@ -91,19 +91,21 @@ class RectRasterUndo final : public TRasterUndo {
std::wstring m_eraseType;
bool m_selective;
bool m_invert;
+ bool m_pencilMode;
public:
RectRasterUndo(TTileSetCM32 *tileSet, const TRectD &modifyArea,
TStroke stroke, int styleId, std::wstring eraseType,
std::wstring colorType, TXshSimpleLevel *level, bool selective,
- bool invert, const TFrameId &frameId)
+ bool invert, bool pencil, const TFrameId &frameId)
: TRasterUndo(tileSet, level, frameId, false, false, 0)
, m_modifyArea(modifyArea)
, m_styleId(styleId)
, m_eraseType(eraseType)
, m_colorType(colorType)
, m_selective(selective)
- , m_invert(invert) {
+ , m_invert(invert)
+ , m_pencilMode(pencil) {
m_stroke = new TStroke(stroke);
}
@@ -120,8 +122,8 @@ public:
} else if (m_eraseType == FREEHANDERASE || m_eraseType == POLYLINEERASE) {
if (m_level) {
TPoint pos;
- TRaster32P ras =
- convertStrokeToImage(m_stroke, ti->getRaster()->getBounds(), pos);
+ TRaster32P ras = convertStrokeToImage(
+ m_stroke, ti->getRaster()->getBounds(), pos, m_pencilMode);
if (!ras) return;
ToonzImageUtils::eraseImage(ti, ras, pos, m_invert, eraseInk,
erasePaint, m_selective, m_styleId);
@@ -268,12 +270,13 @@ public:
void eraseStroke(const TToonzImageP &ti, TStroke *stroke,
std::wstring eraseType, std::wstring colorType, bool invert,
- bool selective, int styleId, const TXshSimpleLevelP &level,
- const TFrameId &frameId) {
+ bool selective, bool pencil, int styleId,
+ const TXshSimpleLevelP &level, const TFrameId &frameId) {
assert(stroke);
TPoint pos;
TRasterCM32P ras = ti->getRaster();
- TRaster32P image = convertStrokeToImage(stroke, ras->getBounds(), pos);
+ TRaster32P image =
+ convertStrokeToImage(stroke, ras->getBounds(), pos, pencil);
if (!image) return;
TRect rasterErasedArea = image->getBounds() + pos;
@@ -286,7 +289,7 @@ void eraseStroke(const TToonzImageP &ti, TStroke *stroke,
tileSet->add(ras, area);
TUndoManager::manager()->add(new RectRasterUndo(
tileSet, convert(area), *stroke, selective ? styleId : -1, eraseType,
- colorType, level.getPointer(), selective, invert, frameId));
+ colorType, level.getPointer(), selective, invert, pencil, frameId));
bool eraseInk = colorType == LINES || colorType == ALL;
bool erasePaint = colorType == AREAS || colorType == ALL;
ToonzImageUtils::eraseImage(ti, image, pos, invert, eraseInk, erasePaint,
@@ -844,10 +847,10 @@ void EraserTool::update(const TToonzImageP &ti, TRectD selArea,
TUndo *undo;
std::wstring inkPaint = m_colorType.getValue();
- undo =
- new RectRasterUndo(tileSet, selArea, TStroke(), selective ? styleId : -1,
- m_eraseType.getValue(), inkPaint, level.getPointer(),
- selective, m_invertOption.getValue(), frameId);
+ undo = new RectRasterUndo(
+ tileSet, selArea, TStroke(), selective ? styleId : -1,
+ m_eraseType.getValue(), inkPaint, level.getPointer(), selective,
+ m_invertOption.getValue(), m_pencil.getValue(), frameId);
ToonzImageUtils::eraseRect(ti, selArea, selective ? styleId : -1,
inkPaint == LINES || inkPaint == ALL,
@@ -1296,7 +1299,8 @@ void EraserTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {
TFrameId frameId = getFrameId();
eraseStroke(image, stroke, m_eraseType.getValue(),
m_colorType.getValue(), m_invertOption.getValue(),
- m_currentStyle.getValue(), styleId, simLevel, frameId);
+ m_currentStyle.getValue(), m_pencil.getValue(), styleId,
+ simLevel, frameId);
notifyImageChanged();
if (m_invertOption.getValue())
invalidate();
@@ -1374,8 +1378,8 @@ void EraserTool::leftButtonDoubleClick(const TPointD &pos,
TFrameId frameId = getFrameId();
TToonzImageP ti = (TToonzImageP)getImage(true);
eraseStroke(ti, stroke, m_eraseType.getValue(), m_colorType.getValue(),
- m_invertOption.getValue(), m_currentStyle.getValue(), styleId,
- simLevel, frameId);
+ m_invertOption.getValue(), m_currentStyle.getValue(),
+ m_pencil.getValue(), styleId, simLevel, frameId);
notifyImageChanged();
if (m_invertOption.getValue())
invalidate();
@@ -1601,11 +1605,13 @@ void EraserTool::doMultiEraser(const TImageP &img, double t,
if (t == 0)
eraseStroke(img, firstImage->getStroke(0), m_eraseType.getValue(),
m_colorType.getValue(), m_invertOption.getValue(),
- m_currentStyle.getValue(), styleId, sl, fid);
+ m_currentStyle.getValue(), m_pencil.getValue(), styleId, sl,
+ fid);
else if (t == 1)
eraseStroke(img, lastImage->getStroke(0), m_eraseType.getValue(),
m_colorType.getValue(), m_invertOption.getValue(),
- m_currentStyle.getValue(), styleId, sl, fid);
+ m_currentStyle.getValue(), m_pencil.getValue(), styleId, sl,
+ fid);
else {
assert(firstImage->getStrokeCount() == 1);
assert(lastImage->getStrokeCount() == 1);
@@ -1613,7 +1619,8 @@ void EraserTool::doMultiEraser(const TImageP &img, double t,
assert(vi->getStrokeCount() == 1);
eraseStroke(img, vi->getStroke(0), m_eraseType.getValue(),
m_colorType.getValue(), m_invertOption.getValue(),
- m_currentStyle.getValue(), styleId, sl, fid);
+ m_currentStyle.getValue(), m_pencil.getValue(), styleId, sl,
+ fid);
}
}
diff --git a/toonz/sources/tnztools/toolutils.cpp b/toonz/sources/tnztools/toolutils.cpp
index 141845b98..ebc08ae22 100644
--- a/toonz/sources/tnztools/toolutils.cpp
+++ b/toonz/sources/tnztools/toolutils.cpp
@@ -57,7 +57,7 @@ void mapToVector(const std::map<int, VIStroke *> &theMap,
std::vector<int> &theVect) {
assert(theMap.size() == theVect.size());
std::map<int, VIStroke *>::const_iterator it = theMap.begin();
- UINT i = 0;
+ UINT i = 0;
for (; it != theMap.end(); ++it) {
theVect[i++] = it->first;
}
@@ -373,7 +373,7 @@ QList<TRect> ToolUtils::splitRect(const TRect &first, const TRect &second) {
TRaster32P ToolUtils::convertStrokeToImage(TStroke *stroke,
const TRect &imageBounds,
- TPoint &pos) {
+ TPoint &pos, bool pencilMode) {
int count = stroke->getControlPointCount();
if (count == 0) return TRaster32P();
TPointD imgCenter = TPointD((imageBounds.x0 + imageBounds.x1) * 0.5,
@@ -407,7 +407,7 @@ TRaster32P ToolUtils::convertStrokeToImage(TStroke *stroke,
QPainter p(&img);
p.setPen(QPen(color, 1, Qt::SolidLine));
p.setBrush(color);
- p.setRenderHint(QPainter::Antialiasing, true);
+ p.setRenderHint(QPainter::Antialiasing, !pencilMode);
QPainterPath path = strokeToPainterPath(&s);
QRectF pathRect = path.boundingRect();
p.translate(-toQPoint(pos));