diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp index 12c78db..3ce5708 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp +++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp @@ -1120,11 +1120,11 @@ void ToonzRasterBrushTool::updateWorkAndBackupRasters(const TRect &rect) { if (m_isMyPaintStyleSelected) { const int denominator = 8; - TRect enlargedRect = rect + m_lastRect; + TRect enlargedRect = rect + m_painting.lastRect; int dx = (enlargedRect.getLx() - 1) / denominator + 1; int dy = (enlargedRect.getLy() - 1) / denominator + 1; - if (m_lastRect.isEmpty()) { + if (m_painting.lastRect.isEmpty()) { enlargedRect.x0 -= dx; enlargedRect.y0 -= dy; enlargedRect.x1 += dx; @@ -1136,15 +1136,15 @@ void ToonzRasterBrushTool::updateWorkAndBackupRasters(const TRect &rect) { m_workRas->extract(_rect)->copy(ras->extract(_rect)); m_backupRas->extract(_rect)->copy(ras->extract(_rect)); } else { - if (enlargedRect.x0 < m_lastRect.x0) enlargedRect.x0 -= dx; - if (enlargedRect.y0 < m_lastRect.y0) enlargedRect.y0 -= dy; - if (enlargedRect.x1 > m_lastRect.x1) enlargedRect.x1 += dx; - if (enlargedRect.y1 > m_lastRect.y1) enlargedRect.y1 += dy; + if (enlargedRect.x0 < m_painting.lastRect.x0) enlargedRect.x0 -= dx; + if (enlargedRect.y0 < m_painting.lastRect.y0) enlargedRect.y0 -= dy; + if (enlargedRect.x1 > m_painting.lastRect.x1) enlargedRect.x1 += dx; + if (enlargedRect.y1 > m_painting.lastRect.y1) enlargedRect.y1 += dy; TRect _rect = enlargedRect * ras->getBounds(); if (_rect.isEmpty()) return; - TRect _lastRect = m_lastRect * ras->getBounds(); + TRect _lastRect = m_painting.lastRect * ras->getBounds(); QList<TRect> rects = ToolUtils::splitRect(_rect, _lastRect); for (int i = 0; i < rects.size(); i++) { m_workRas->extract(rects[i])->copy(ras->extract(rects[i])); @@ -1152,16 +1152,16 @@ void ToonzRasterBrushTool::updateWorkAndBackupRasters(const TRect &rect) { } } - m_lastRect = enlargedRect; + m_painting.lastRect = enlargedRect; return; } TRect _rect = rect * ras->getBounds(); - TRect _lastRect = m_lastRect * ras->getBounds(); + TRect _lastRect = m_painting.lastRect * ras->getBounds(); if (_rect.isEmpty()) return; - if (m_lastRect.isEmpty()) { + if (m_painting.lastRect.isEmpty()) { m_workRas->extract(_rect)->clear(); m_backupRas->extract(_rect)->copy(ras->extract(_rect)); return; @@ -1228,8 +1228,8 @@ bool ToonzRasterBrushTool::askRead(const TRect &rect) { return askWrite(rect); } bool ToonzRasterBrushTool::askWrite(const TRect &rect) { if (rect.isEmpty()) return true; - m_strokeRect += rect; - m_strokeSegmentRect += rect; + m_painting.myPaint.strokeRect += rect; + m_painting.myPaint.strokeSegmentRect += rect; updateWorkAndBackupRasters(rect); m_painting.tileSaver->save(rect); return true; @@ -1344,19 +1344,19 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, baseSize + modifierSize); } m_painting.myPaint.brush = new MyPaintToonzBrush(m_workRas, *this, mypaintBrush); - m_strokeRect.empty(); - m_strokeSegmentRect.empty(); + m_painting.myPaint.strokeRect.empty(); + m_painting.myPaint.strokeSegmentRect.empty(); m_painting.myPaint.brush->beginStroke(); m_painting.myPaint.brush->strokeTo(point, pressure, TPointD(), restartBrushTimer()); - TRect updateRect = m_strokeSegmentRect * ras->getBounds(); + TRect updateRect = m_painting.myPaint.strokeSegmentRect * ras->getBounds(); if (!updateRect.isEmpty()) { - m_painting.myPaint.brush->updateDrawing( ri->getRaster(), m_backupRas, m_strokeRect, + m_painting.myPaint.brush->updateDrawing( ri->getRaster(), m_backupRas, m_painting.myPaint.strokeRect, m_painting.styleId, m_modifierLockAlpha.getValue() ); } - m_lastRect = m_strokeRect; + m_painting.lastRect = m_painting.myPaint.strokeRect; TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5); - invalidateRect = convert(m_strokeSegmentRect) - rasCenter; + invalidateRect = convert(m_painting.myPaint.strokeSegmentRect) - rasCenter; invalidateRect += TRectD(centeredPos - thickOffset, centeredPos + thickOffset); invalidateRect += @@ -1397,15 +1397,15 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, if (drawOrder == PaletteOrder) m_bluredBrush->setAboveStyleIds(aboveStyleIds); - m_strokeRect = m_bluredBrush->getBoundFromPoints(m_points); - updateWorkAndBackupRasters(m_strokeRect); - m_painting.tileSaver->save(m_strokeRect); + TRect strokeRect = m_bluredBrush->getBoundFromPoints(m_points); + updateWorkAndBackupRasters(strokeRect); + m_painting.tileSaver->save(strokeRect); m_bluredBrush->addPoint(point, 1); if (!m_painting.straight.isStraight) - m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, + m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, strokeRect, m_painting.styleId, drawOrder, m_modifierLockAlpha.getValue()); - m_lastRect = m_strokeRect; + m_painting.lastRect = strokeRect; std::vector<TThickPoint> pts; if (m_smooth.getValue() == 0) { @@ -1498,17 +1498,17 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, TRasterP ras = ti->getRaster(); TPointD point(centeredPos + rasCenter); - m_strokeSegmentRect.empty(); + m_painting.myPaint.strokeSegmentRect.empty(); m_painting.myPaint.brush->strokeTo(point, pressure, TPointD(), restartBrushTimer()); - TRect updateRect = m_strokeSegmentRect * ras->getBounds(); + TRect updateRect = m_painting.myPaint.strokeSegmentRect * ras->getBounds(); if (!updateRect.isEmpty()) { - m_painting.myPaint.brush->updateDrawing( ras, m_backupRas, m_strokeSegmentRect, + m_painting.myPaint.brush->updateDrawing( ras, m_backupRas, m_painting.myPaint.strokeSegmentRect, m_painting.styleId, m_modifierLockAlpha.getValue() ); } - m_lastRect = m_strokeRect; + m_painting.lastRect = m_painting.myPaint.strokeRect; TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5); - invalidateRect = convert(m_strokeSegmentRect) - rasCenter; + invalidateRect = convert(m_painting.myPaint.strokeSegmentRect) - rasCenter; invalidateRect += TRectD(centeredPos - thickOffset, centeredPos + thickOffset); invalidateRect += @@ -1573,26 +1573,25 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, points.push_back(pa); points.push_back(mid); bbox = m_bluredBrush->getBoundFromPoints(points); - updateWorkAndBackupRasters(bbox + m_lastRect); + updateWorkAndBackupRasters(bbox + m_painting.lastRect); m_painting.tileSaver->save(bbox); m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1); - m_lastRect += bbox; + m_painting.lastRect += bbox; } else { points.push_back(m_points[m - 4]); points.push_back(old); points.push_back(mid); bbox = m_bluredBrush->getBoundFromPoints(points); - updateWorkAndBackupRasters(bbox + m_lastRect); + updateWorkAndBackupRasters(bbox + m_painting.lastRect); m_painting.tileSaver->save(bbox); m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1); - m_lastRect += bbox; + m_painting.lastRect += bbox; } invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter; m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, m_painting.styleId, m_drawOrder.getIndex(), m_modifierLockAlpha.getValue()); - m_strokeRect += bbox; } } @@ -1667,31 +1666,31 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, TPointD point(pos + rasCenter); double pressure = m_pressure.getValue() ? pressureVal : 0.5; - m_strokeSegmentRect.empty(); + m_painting.myPaint.strokeSegmentRect.empty(); m_painting.myPaint.brush->strokeTo(point, pressure, TPointD(), restartBrushTimer()); m_painting.myPaint.brush->endStroke(); - TRect updateRect = m_strokeSegmentRect * ras->getBounds(); + TRect updateRect = m_painting.myPaint.strokeSegmentRect * ras->getBounds(); if (!updateRect.isEmpty()) { - m_painting.myPaint.brush->updateDrawing( ras, m_backupRas, m_strokeSegmentRect, + m_painting.myPaint.brush->updateDrawing( ras, m_backupRas, m_painting.myPaint.strokeSegmentRect, m_painting.styleId, m_modifierLockAlpha.getValue() ); } TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5); // TODO - TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter; + TRectD invalidateRect = convert(m_painting.myPaint.strokeSegmentRect) - rasCenter; invalidateRect += TRectD(pos - thickOffset, pos + thickOffset); invalidate(invalidateRect.enlarge(2.0)); delete m_painting.myPaint.brush; m_painting.myPaint.brush = nullptr; - m_lastRect.empty(); + m_painting.lastRect.empty(); m_workRas->unlock(); if (m_painting.tileSet->getTileCount() > 0) { - TRasterCM32P subras = ras->extract(m_strokeRect)->clone(); + TRasterCM32P subras = ras->extract(m_painting.myPaint.strokeRect)->clone(); TUndoManager::manager()->add(new MyPaintBrushUndo( m_painting.tileSet, simLevel.getPointer(), frameId, m_isFrameCreated, - m_isLevelCreated, subras, m_strokeRect.getP00())); + m_isLevelCreated, subras, m_painting.myPaint.strokeRect.getP00())); } } else if (m_rasterTrack && @@ -1792,19 +1791,19 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, points.push_back(pa); points.push_back(mid); bbox = m_bluredBrush->getBoundFromPoints(points); - updateWorkAndBackupRasters(bbox + m_lastRect); + updateWorkAndBackupRasters(bbox + m_painting.lastRect); m_painting.tileSaver->save(bbox); m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1); - m_lastRect += bbox; + m_painting.lastRect += bbox; } else { points.push_back(m_points[m - 4]); points.push_back(old); points.push_back(mid); bbox = m_bluredBrush->getBoundFromPoints(points); - updateWorkAndBackupRasters(bbox + m_lastRect); + updateWorkAndBackupRasters(bbox + m_painting.lastRect); m_painting.tileSaver->save(bbox); m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1); - m_lastRect += bbox; + m_painting.lastRect += bbox; } invalidateRect += @@ -1813,7 +1812,6 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, m_painting.styleId, m_drawOrder.getIndex(), m_modifierLockAlpha.getValue()); - m_strokeRect += bbox; } if (!m_painting.straight.isStraight && m_points.size() > 1) { TThickPoint point = pts.back(); @@ -1845,11 +1843,10 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter; - m_lastRect += bbox; - m_strokeRect += bbox; + m_painting.lastRect += bbox; } if (!invalidateRect.isEmpty()) invalidate(invalidateRect.enlarge(2)); - m_lastRect.empty(); + m_painting.lastRect.empty(); delete m_bluredBrush; m_bluredBrush = 0; @@ -1869,8 +1866,6 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, 描画開始時のFidのサムネイルが更新されるようにする。--*/ notifyImageChanged(frameId); - m_strokeRect.empty(); - ToolUtils::updateSaveBox(); /*-- 作業中のフレームをリセット --*/ @@ -2073,8 +2068,8 @@ void ToonzRasterBrushTool::setWorkAndBackupImages() { m_backupRas->getLy() > dim.ly) m_backupRas = TRasterCM32P(dim); - m_strokeRect.empty(); - m_lastRect.empty(); + m_painting.myPaint.strokeRect.empty(); + m_painting.lastRect.empty(); } } diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.h b/toonz/sources/tnztools/toonzrasterbrushtool.h index 453dd7b..7db0c83 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.h +++ b/toonz/sources/tnztools/toonzrasterbrushtool.h @@ -184,9 +184,12 @@ protected: // common variables TTileSetCM32 *tileSet = nullptr; TTileSaverCM32 *tileSaver = nullptr; + TRect lastRect; struct MyPaint { MyPaintToonzBrush *brush = nullptr; + TRect strokeRect; + TRect strokeSegmentRect; } myPaint; // straight variables @@ -225,8 +228,6 @@ protected: TRaster32P m_workRas; std::vector<TThickPoint> m_points; - TRect m_strokeRect, m_lastRect, - m_strokeSegmentRect; // used with mypaint brush SmoothStroke m_smoothStroke;