diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp index 7b0bcd1..aa2fd74 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp +++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp @@ -1280,9 +1280,9 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, // Modifier to do straight line if (e.isShiftPressed()) { - m_painting.isStraight = true; - m_painting.firstPoint = pos; - m_painting.lastPoint = pos; + m_painting.straight.isStraight = true; + m_painting.straight.firstPoint = pos; + m_painting.straight.lastPoint = pos; } double pressure; @@ -1305,7 +1305,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する * ---*/ - if (m_pressure.getValue() && e.m_pressure == 1.0 && !m_painting.isStraight) + if (m_pressure.getValue() && e.m_pressure == 1.0 && !m_painting.straight.isStraight) thickness = m_rasThickness.getValue().first; TPointD halfThick(maxThick * 0.5, maxThick * 0.5); @@ -1366,7 +1366,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, } else if (m_hardness.getValue() == 100 || m_pencil.getValue()) { /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる * --*/ - if (!m_pencil.getValue() && !m_painting.isStraight) thickness -= 1.0; + if (!m_pencil.getValue() && !m_painting.straight.isStraight) thickness -= 1.0; TThickPoint thickPoint(centeredPos + convert(ras->getCenter()), thickness); @@ -1379,7 +1379,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, m_rasterTrack->setAboveStyleIds(aboveStyleIds); m_painting.tileSaver->save(m_rasterTrack->getLastRect()); - if (!m_painting.isStraight) + if (!m_painting.straight.isStraight) m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue()); std::vector pts; @@ -1403,7 +1403,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, updateWorkAndBackupRasters(m_strokeRect); m_painting.tileSaver->save(m_strokeRect); m_bluredBrush->addPoint(point, 1); - if (!m_painting.isStraight) + if (!m_painting.straight.isStraight) m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, m_painting.styleId, drawOrder, m_modifierLockAlpha.getValue()); @@ -1433,7 +1433,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { TRectD invalidateRect; - m_painting.lastPoint = pos; + m_painting.straight.lastPoint = pos; if (!m_enabled || !m_painting.active) { m_mousePos = pos; @@ -1441,7 +1441,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, return; } - TPointD centeredPos = getCenteredCursorPos(m_painting.lastPoint); + TPointD centeredPos = getCenteredCursorPos(m_painting.straight.lastPoint); double pressure; if (m_isMyPaintStyleSelected) // mypaint brush case @@ -1456,37 +1456,37 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, ? computeThickness(pressure, m_rasThickness) * 2 : maxThickness; - if (m_painting.maxPressure < pressure) m_painting.maxPressure = pressure; + if (m_painting.straight.maxPressure < pressure) m_painting.straight.maxPressure = pressure; - if (m_painting.isStraight) { - invalidateRect = TRectD(m_painting.firstPoint, m_painting.lastPoint).enlarge(2); + if (m_painting.straight.isStraight) { + invalidateRect = TRectD(m_painting.straight.firstPoint, m_painting.straight.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_painting.lastPoint.x - m_painting.firstPoint.x; + double denominator = m_painting.straight.lastPoint.x - m_painting.straight.firstPoint.x; if (denominator == 0) denominator == 0.001; - double slope = ((m_painting.lastPoint.y - m_painting.firstPoint.y) / denominator); + double slope = ((m_painting.straight.lastPoint.y - m_painting.straight.firstPoint.y) / denominator); double angle = std::atan(slope) * (180 / 3.14159); if (abs(angle) > 67.5) - m_painting.lastPoint.x = m_painting.firstPoint.x; + m_painting.straight.lastPoint.x = m_painting.straight.firstPoint.x; else if (abs(angle) < 22.5) - m_painting.lastPoint.y = m_painting.firstPoint.y; + m_painting.straight.lastPoint.y = m_painting.straight.firstPoint.y; else { - double xDistance = m_painting.lastPoint.x - m_painting.firstPoint.x; - double yDistance = m_painting.lastPoint.y - m_painting.firstPoint.y; + double xDistance = m_painting.straight.lastPoint.x - m_painting.straight.firstPoint.x; + double yDistance = m_painting.straight.lastPoint.y - m_painting.straight.firstPoint.y; if (abs(xDistance) > abs(yDistance)) { if (abs(yDistance) == yDistance) - m_painting.lastPoint.y = m_painting.firstPoint.y + abs(xDistance); + m_painting.straight.lastPoint.y = m_painting.straight.firstPoint.y + abs(xDistance); else - m_painting.lastPoint.y = m_painting.firstPoint.y - abs(xDistance); + m_painting.straight.lastPoint.y = m_painting.straight.firstPoint.y - abs(xDistance); } else { if (abs(xDistance) == xDistance) - m_painting.lastPoint.x = m_painting.firstPoint.x + abs(yDistance); + m_painting.straight.lastPoint.x = m_painting.straight.firstPoint.x + abs(yDistance); else - m_painting.lastPoint.x = m_painting.firstPoint.x - abs(yDistance); + m_painting.straight.lastPoint.x = m_painting.straight.firstPoint.x - abs(yDistance); } } } @@ -1623,8 +1623,8 @@ void ToonzRasterBrushTool::leftButtonUp(const TPointD &pos, return; } TPointD centeredPos; - if (m_painting.isStraight) - centeredPos = getCenteredCursorPos(m_painting.lastPoint); + if (m_painting.straight.isStraight) + centeredPos = getCenteredCursorPos(m_painting.straight.lastPoint); else centeredPos = getCenteredCursorPos(pos); @@ -1634,15 +1634,15 @@ void ToonzRasterBrushTool::leftButtonUp(const TPointD &pos, else pressure = m_pressure.getValue() ? e.m_pressure : 1.0; - if (m_painting.isStraight && m_painting.maxPressure > 0.0) pressure = m_painting.maxPressure; + if (m_painting.straight.isStraight && m_painting.straight.maxPressure > 0.0) pressure = m_painting.straight.maxPressure; finishRasterBrush(centeredPos, pressure); int tc = ToonzCheck::instance()->getChecks(); - if (tc & ToonzCheck::eGap || tc & ToonzCheck::eAutoclose || m_painting.isStraight) + if (tc & ToonzCheck::eGap || tc & ToonzCheck::eAutoclose || m_painting.straight.isStraight) invalidate(); - m_painting.isStraight = false; - m_painting.maxPressure = -1.0; + m_painting.straight.isStraight = false; + m_painting.straight.maxPressure = -1.0; } //--------------------------------------------------------------------------------------------------------------- @@ -1706,7 +1706,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, ? computeThickness(pressureVal, m_rasThickness) * 2 : m_rasThickness.getValue().second; - if (!m_painting.isStraight) { + if (!m_painting.straight.isStraight) { // ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する if (m_pressure.getValue() && pressureVal == 1.0) thickness = m_rasThickness.getValue().first; @@ -1718,7 +1718,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, TRectD invalidateRect; TThickPoint thickPoint(pos + rasCenter, thickness); std::vector pts; - if (m_smooth.getValue() == 0 || m_painting.isStraight) { + if (m_smooth.getValue() == 0 || m_painting.straight.isStraight) { pts.push_back(thickPoint); } else { m_smoothStroke.addPoint(thickPoint); @@ -1728,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_painting.tileSaver->save(m_rasterTrack->getLastRect(m_painting.isStraight)); + m_painting.tileSaver->save(m_rasterTrack->getLastRect(m_painting.straight.isStraight)); m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue(), true, - m_painting.isStraight); + m_painting.straight.isStraight); std::vector brushPoints = m_rasterTrack->getPointsSequence(); int m = (int)brushPoints.size(); std::vector points; - if (m_painting.isStraight) { + if (m_painting.straight.isStraight) { points.push_back(brushPoints[0]); points.push_back(brushPoints[2]); } else if (m == 3) { @@ -1757,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_painting.isStraight)); + m_rasterTrack->isAlphaLocked(), m_painting.straight.isStraight)); } delete m_rasterTrack; m_rasterTrack = 0; @@ -1770,7 +1770,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, TRectD invalidateRect; TThickPoint thickPoint(pos + rasCenter, thickness); std::vector pts; - if (m_smooth.getValue() == 0 || m_painting.isStraight) { + if (m_smooth.getValue() == 0 || m_painting.straight.isStraight) { pts.push_back(thickPoint); } else { m_smoothStroke.addPoint(thickPoint); @@ -1821,13 +1821,13 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, m_modifierLockAlpha.getValue()); m_strokeRect += bbox; } - if (!m_painting.isStraight && m_points.size() > 1) { + if (!m_painting.straight.isStraight && m_points.size() > 1) { TThickPoint point = pts.back(); m_points.push_back(point); } int m = m_points.size(); std::vector points; - if (!m_painting.isStraight && m_points.size() > 1) { + if (!m_painting.straight.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]); @@ -1865,7 +1865,7 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, m_painting.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_painting.isStraight)); + m_isFrameCreated, m_isLevelCreated, m_painting.straight.isStraight)); } } delete m_painting.tileSaver; @@ -1969,9 +1969,9 @@ void ToonzRasterBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) { //------------------------------------------------------------------------------------------------------------- void ToonzRasterBrushTool::draw() { - if (m_painting.isStraight) { - tglDrawSegment(m_painting.firstPoint, m_painting.lastPoint); - invalidate(TRectD(m_painting.firstPoint, m_painting.lastPoint).enlarge(2)); + if (m_painting.straight.isStraight) { + tglDrawSegment(m_painting.straight.firstPoint, m_painting.straight.lastPoint); + invalidate(TRectD(m_painting.straight.firstPoint, m_painting.straight.lastPoint).enlarge(2)); } /*--ショートカットでのツール切り替え時に赤点が描かれるのを防止する--*/ diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.h b/toonz/sources/tnztools/toonzrasterbrushtool.h index ee0d933..f760b3d 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.h +++ b/toonz/sources/tnztools/toonzrasterbrushtool.h @@ -185,11 +185,17 @@ protected: TTileSetCM32 *tileSet = nullptr; TTileSaverCM32 *tileSaver = nullptr; + struct MyPaint { + + } myPaint; + // straight variables - bool isStraight = false; - TPointD firstPoint; - TPointD lastPoint; - double maxPressure = -1.0; + struct Straight { + bool isStraight = false; + TPointD firstPoint; + TPointD lastPoint; + double maxPressure = -1.0; + } straight; } m_painting; TPropertyGroup m_prop[2];