diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp index 1bac707..86e1cc1 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp +++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp @@ -870,8 +870,6 @@ void SmoothStroke::generatePoints() { ToonzRasterBrushTool::ToonzRasterBrushTool(std::string name, int targetType) : TTool(name) - , m_stroke{} - , m_painting{} , m_rasThickness("Size", 1, 1000, 1, 5) , m_smooth("Smooth:", 0, 50, 0) , m_hardness("Hardness:", 0, 100, 100) @@ -882,7 +880,6 @@ ToonzRasterBrushTool::ToonzRasterBrushTool(std::string name, int targetType) , m_modifierSize("ModifierSize", -3, 3, 0, true) , m_modifierLockAlpha("Lock Alpha", false) , m_rasterTrack(0) - , m_styleId(0) , m_targetType(targetType) , m_bluredBrush(0) , m_enabled(false) @@ -1271,21 +1268,21 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, // nel caso che il colore corrente sia un cleanup/studiopalette color // oppure il colore di un colorfield if (TColorStyle *cs = app->getCurrentLevelStyle()) { - m_styleId = app->getCurrentLevelStyleIndex(); + m_painting.styleId = app->getCurrentLevelStyleIndex(); TRasterStyleFx *rfx = cs->getRasterStyleFx(); if (!cs->isStrokeStyle() && (!rfx || !rfx->isInkStyle())) { m_painting.active = false; return; } } else { - m_styleId = 1; + m_painting.styleId = 1; } TPointD centeredPos = getCenteredCursorPos(pos); // Modifier to do straight line if (e.isShiftPressed()) { - m_isStraight = true; - m_firstPoint = pos; - m_lastPoint = pos; + m_painting.isStraight = true; + m_painting.firstPoint = pos; + m_painting.lastPoint = pos; } double pressure; @@ -1294,7 +1291,6 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, else pressure = m_pressure.getValue() ? e.m_pressure : 1.0; - // assert(0<=m_styleId && m_styleId<2); TImageP img = getImage(true); TToonzImageP ri(img); TRasterCM32P ras = ri->getRaster(); @@ -1309,7 +1305,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する * ---*/ - if (m_pressure.getValue() && e.m_pressure == 1.0 && !m_isStraight) + if (m_pressure.getValue() && e.m_pressure == 1.0 && !m_painting.isStraight) thickness = m_rasThickness.getValue().first; TPointD halfThick(maxThick * 0.5, maxThick * 0.5); @@ -1326,7 +1322,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, DrawOrder drawOrder = (DrawOrder)m_drawOrder.getIndex(); QSet<int> aboveStyleIds; if (drawOrder == PaletteOrder) { - getAboveStyleIdSet(m_styleId, ri->getPalette(), aboveStyleIds); + getAboveStyleIdSet(m_painting.styleId, ri->getPalette(), aboveStyleIds); } // mypaint brush case @@ -1357,7 +1353,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, if (!updateRect.isEmpty()) { // ras->extract(updateRect)->copy(m_workRas->extract(updateRect)); m_toonz_brush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, - m_styleId, m_modifierLockAlpha.getValue()); + m_painting.styleId, m_modifierLockAlpha.getValue()); } m_lastRect = m_strokeRect; @@ -1370,12 +1366,12 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, } else if (m_hardness.getValue() == 100 || m_pencil.getValue()) { /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる * --*/ - if (!m_pencil.getValue() && !m_isStraight) thickness -= 1.0; + if (!m_pencil.getValue() && !m_painting.isStraight) thickness -= 1.0; TThickPoint thickPoint(centeredPos + convert(ras->getCenter()), thickness); m_rasterTrack = new RasterStrokeGenerator( - ras, BRUSH, NONE, m_styleId, thickPoint, drawOrder != OverAll, 0, + ras, BRUSH, NONE, m_painting.styleId, thickPoint, drawOrder != OverAll, 0, m_modifierLockAlpha.getValue(), !m_pencil.getValue(), drawOrder == PaletteOrder); @@ -1383,7 +1379,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, m_rasterTrack->setAboveStyleIds(aboveStyleIds); m_tileSaver->save(m_rasterTrack->getLastRect()); - if (!m_isStraight) + if (!m_painting.isStraight) m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue()); std::vector<TThickPoint> pts; @@ -1407,9 +1403,9 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, updateWorkAndBackupRasters(m_strokeRect); m_tileSaver->save(m_strokeRect); m_bluredBrush->addPoint(point, 1); - if (!m_isStraight) + if (!m_painting.isStraight) m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, - m_styleId, drawOrder, + m_painting.styleId, drawOrder, m_modifierLockAlpha.getValue()); m_lastRect = m_strokeRect; @@ -1437,7 +1433,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { TRectD invalidateRect; - m_lastPoint = pos; + m_painting.lastPoint = pos; if (!m_enabled || !m_painting.active) { m_mousePos = pos; @@ -1445,7 +1441,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, return; } - TPointD centeredPos = getCenteredCursorPos(m_lastPoint); + TPointD centeredPos = getCenteredCursorPos(m_painting.lastPoint); double pressure; if (m_isMyPaintStyleSelected) // mypaint brush case @@ -1460,37 +1456,37 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, ? computeThickness(pressure, m_rasThickness) * 2 : maxThickness; - if (m_maxPressure < pressure) m_maxPressure = pressure; + if (m_painting.maxPressure < pressure) m_painting.maxPressure = pressure; - if (m_isStraight) { - invalidateRect = TRectD(m_firstPoint, m_lastPoint).enlarge(2); + if (m_painting.isStraight) { + invalidateRect = TRectD(m_painting.firstPoint, m_painting.lastPoint).enlarge(2); if (e.isCtrlPressed()) { double distance = (m_brushPos.x - m_maxCursorThick + 1) * 0.5; TRectD brushRect = TRectD(TPointD(m_brushPos.x - distance, m_brushPos.y - distance), TPointD(m_brushPos.x + distance, m_brushPos.y + distance)); invalidateRect += (brushRect); - double denominator = m_lastPoint.x - m_firstPoint.x; + double denominator = m_painting.lastPoint.x - m_painting.firstPoint.x; if (denominator == 0) denominator == 0.001; - double slope = ((m_lastPoint.y - m_firstPoint.y) / denominator); + double slope = ((m_painting.lastPoint.y - m_painting.firstPoint.y) / denominator); double angle = std::atan(slope) * (180 / 3.14159); if (abs(angle) > 67.5) - m_lastPoint.x = m_firstPoint.x; + m_painting.lastPoint.x = m_painting.firstPoint.x; else if (abs(angle) < 22.5) - m_lastPoint.y = m_firstPoint.y; + m_painting.lastPoint.y = m_painting.firstPoint.y; else { - double xDistance = m_lastPoint.x - m_firstPoint.x; - double yDistance = m_lastPoint.y - m_firstPoint.y; + double xDistance = m_painting.lastPoint.x - m_painting.firstPoint.x; + double yDistance = m_painting.lastPoint.y - m_painting.firstPoint.y; if (abs(xDistance) > abs(yDistance)) { if (abs(yDistance) == yDistance) - m_lastPoint.y = m_firstPoint.y + abs(xDistance); + m_painting.lastPoint.y = m_painting.firstPoint.y + abs(xDistance); else - m_lastPoint.y = m_firstPoint.y - abs(xDistance); + m_painting.lastPoint.y = m_painting.firstPoint.y - abs(xDistance); } else { if (abs(xDistance) == xDistance) - m_lastPoint.x = m_firstPoint.x + abs(yDistance); + m_painting.lastPoint.x = m_painting.firstPoint.x + abs(yDistance); else - m_lastPoint.x = m_firstPoint.x - abs(yDistance); + m_painting.lastPoint.x = m_painting.firstPoint.x - abs(yDistance); } } } @@ -1510,7 +1506,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, if (!updateRect.isEmpty()) { // ras->extract(updateRect)->copy(m_workRaster->extract(updateRect)); m_toonz_brush->updateDrawing(ras, m_backupRas, m_strokeSegmentRect, - m_styleId, m_modifierLockAlpha.getValue()); + m_painting.styleId, m_modifierLockAlpha.getValue()); } m_lastRect = m_strokeRect; @@ -1597,7 +1593,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter; m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, - m_styleId, m_drawOrder.getIndex(), + m_painting.styleId, m_drawOrder.getIndex(), m_modifierLockAlpha.getValue()); m_strokeRect += bbox; } @@ -1627,8 +1623,8 @@ void ToonzRasterBrushTool::leftButtonUp(const TPointD &pos, return; } TPointD centeredPos; - if (m_isStraight) - centeredPos = getCenteredCursorPos(m_lastPoint); + if (m_painting.isStraight) + centeredPos = getCenteredCursorPos(m_painting.lastPoint); else centeredPos = getCenteredCursorPos(pos); @@ -1638,15 +1634,15 @@ void ToonzRasterBrushTool::leftButtonUp(const TPointD &pos, else pressure = m_pressure.getValue() ? e.m_pressure : 1.0; - if (m_isStraight && m_maxPressure > 0.0) pressure = m_maxPressure; + if (m_painting.isStraight && m_painting.maxPressure > 0.0) pressure = m_painting.maxPressure; finishRasterBrush(centeredPos, pressure); int tc = ToonzCheck::instance()->getChecks(); - if (tc & ToonzCheck::eGap || tc & ToonzCheck::eAutoclose || m_isStraight) + if (tc & ToonzCheck::eGap || tc & ToonzCheck::eAutoclose || m_painting.isStraight) invalidate(); - m_isStraight = false; - m_maxPressure = -1.0; + m_painting.isStraight = false; + m_painting.maxPressure = -1.0; } //--------------------------------------------------------------------------------------------------------------- @@ -1681,7 +1677,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, if (!updateRect.isEmpty()) { // ras->extract(updateRect)->copy(m_workRaster->extract(updateRect)); m_toonz_brush->updateDrawing(ras, m_backupRas, m_strokeSegmentRect, - m_styleId, m_modifierLockAlpha.getValue()); + m_painting.styleId, m_modifierLockAlpha.getValue()); } TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5); // TODO @@ -1710,7 +1706,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, ? computeThickness(pressureVal, m_rasThickness) * 2 : m_rasThickness.getValue().second; - if (!m_isStraight) { + if (!m_painting.isStraight) { // ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する if (m_pressure.getValue() && pressureVal == 1.0) thickness = m_rasThickness.getValue().first; @@ -1722,7 +1718,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, TRectD invalidateRect; TThickPoint thickPoint(pos + rasCenter, thickness); std::vector<TThickPoint> pts; - if (m_smooth.getValue() == 0 || m_isStraight) { + if (m_smooth.getValue() == 0 || m_painting.isStraight) { pts.push_back(thickPoint); } else { m_smoothStroke.addPoint(thickPoint); @@ -1732,14 +1728,14 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, for (size_t i = 0; i < pts.size(); ++i) { const TThickPoint &thickPoint = pts[i]; m_rasterTrack->add(thickPoint); - m_tileSaver->save(m_rasterTrack->getLastRect(m_isStraight)); + m_tileSaver->save(m_rasterTrack->getLastRect(m_painting.isStraight)); m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue(), true, - m_isStraight); + m_painting.isStraight); std::vector<TThickPoint> brushPoints = m_rasterTrack->getPointsSequence(); int m = (int)brushPoints.size(); std::vector<TThickPoint> points; - if (m_isStraight) { + if (m_painting.isStraight) { points.push_back(brushPoints[0]); points.push_back(brushPoints[2]); } else if (m == 3) { @@ -1761,7 +1757,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, m_rasterTrack->getStyleId(), m_rasterTrack->isSelective(), simLevel.getPointer(), frameId, m_pencil.getValue(), m_isFrameCreated, m_isLevelCreated, m_rasterTrack->isPaletteOrder(), - m_rasterTrack->isAlphaLocked(), m_isStraight)); + m_rasterTrack->isAlphaLocked(), m_painting.isStraight)); } delete m_rasterTrack; m_rasterTrack = 0; @@ -1774,7 +1770,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, TRectD invalidateRect; TThickPoint thickPoint(pos + rasCenter, thickness); std::vector<TThickPoint> pts; - if (m_smooth.getValue() == 0 || m_isStraight) { + if (m_smooth.getValue() == 0 || m_painting.isStraight) { pts.push_back(thickPoint); } else { m_smoothStroke.addPoint(thickPoint); @@ -1821,17 +1817,17 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, ToolUtils::getBounds(points, maxThickness) - rasCenter; m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, - m_styleId, m_drawOrder.getIndex(), + m_painting.styleId, m_drawOrder.getIndex(), m_modifierLockAlpha.getValue()); m_strokeRect += bbox; } - if (!m_isStraight && m_points.size() > 1) { + if (!m_painting.isStraight && m_points.size() > 1) { TThickPoint point = pts.back(); m_points.push_back(point); } int m = m_points.size(); std::vector<TThickPoint> points; - if (!m_isStraight && m_points.size() > 1) { + if (!m_painting.isStraight && m_points.size() > 1) { points.push_back(m_points[m - 3]); points.push_back(m_points[m - 2]); points.push_back(m_points[m - 1]); @@ -1850,7 +1846,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, m_tileSaver->save(bbox); m_bluredBrush->addArc(points[0], points[1], points[2], 1, 1); m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, - m_styleId, m_drawOrder.getIndex(), + m_painting.styleId, m_drawOrder.getIndex(), m_modifierLockAlpha.getValue()); invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter; @@ -1866,10 +1862,10 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, if (m_tileSet->getTileCount() > 0) { TUndoManager::manager()->add(new RasterBluredBrushUndo( - m_tileSet, m_points, m_styleId, (DrawOrder)m_drawOrder.getIndex(), + m_tileSet, m_points, m_painting.styleId, (DrawOrder)m_drawOrder.getIndex(), m_modifierLockAlpha.getValue(), simLevel.getPointer(), frameId, m_rasThickness.getValue().second, m_hardness.getValue() * 0.01, - m_isFrameCreated, m_isLevelCreated, m_isStraight)); + m_isFrameCreated, m_isLevelCreated, m_painting.isStraight)); } } delete m_tileSaver; @@ -1974,9 +1970,9 @@ void ToonzRasterBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) { //------------------------------------------------------------------------------------------------------------- void ToonzRasterBrushTool::draw() { - if (m_isStraight) { - tglDrawSegment(m_firstPoint, m_lastPoint); - invalidate(TRectD(m_firstPoint, m_lastPoint).enlarge(2)); + if (m_painting.isStraight) { + tglDrawSegment(m_painting.firstPoint, m_painting.lastPoint); + invalidate(TRectD(m_painting.firstPoint, m_painting.lastPoint).enlarge(2)); } /*--ショートカットでのツール切り替え時に赤点が描かれるのを防止する--*/ @@ -2034,7 +2030,7 @@ void ToonzRasterBrushTool::onEnter() { Application *app = getApplication(); - m_styleId = app->getCurrentLevelStyleIndex(); + m_painting.styleId = app->getCurrentLevelStyleIndex(); m_painting.active = img; } diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.h b/toonz/sources/tnztools/toonzrasterbrushtool.h index ad0e2f9..5089398 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.h +++ b/toonz/sources/tnztools/toonzrasterbrushtool.h @@ -177,7 +177,13 @@ protected: } m_stroke; struct Painting { - bool active; + bool active = false; + int styleId = 0; + + bool isStraight = false; + TPointD firstPoint; + TPointD lastPoint; + double maxPressure = -1.0; } m_painting; TPropertyGroup m_prop[2]; @@ -195,7 +201,6 @@ protected: RasterStrokeGenerator *m_rasterTrack; TTileSetCM32 *m_tileSet; TTileSaverCM32 *m_tileSaver; - int m_styleId; double m_minThick, m_maxThick; int m_targetType; @@ -236,11 +241,6 @@ protected: bool m_propertyUpdating = false; - bool m_isStraight = false; - TPointD m_firstPoint; - TPointD m_lastPoint; - double m_maxPressure = -1.0; - protected: static void drawLine(const TPointD &point, const TPointD ¢re, bool horizontal, bool isDecimal);