diff --git a/toonz/sources/tnztools/controlpointeditortool.cpp b/toonz/sources/tnztools/controlpointeditortool.cpp index 6e56dfef..ad43d5c0 100644 --- a/toonz/sources/tnztools/controlpointeditortool.cpp +++ b/toonz/sources/tnztools/controlpointeditortool.cpp @@ -268,7 +268,7 @@ TPointD ControlPointEditorTool::calculateSnap(TPointD pos) { else if (areAlmostEqual(outW, 1.0, 1e-3)) w = 1.0; else - w = outW; + w = outW; TThickPoint point = stroke->getPoint(w); snapPoint = TPointD(point.x, point.y); m_foundSnap = true; @@ -560,7 +560,7 @@ void ControlPointEditorTool::leftButtonDown(const TPointD &pos, getViewer()->doPickGuideStroke(pos); return; } - + m_selection.setArePointsDeleted(false); m_pos = pos; double pix = getPixelSize() * 2.0f; double maxDist = 5 * pix; @@ -797,6 +797,13 @@ void ControlPointEditorTool::moveSegment(const TPointD &delta, bool dragging, void ControlPointEditorTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) { + if (m_selection.getPointsDeleted()) { + m_selection.selectNone(); + m_lastPointSelected = -1; + if (m_undo) delete(m_undo); + m_undo = 0; + return; + } TVectorImageP vi(getImage(true)); int currentStroke = m_controlPointEditorStroke.getStrokeIndex(); if (!vi || currentStroke == -1 || m_action == NONE) return; @@ -814,7 +821,15 @@ void ControlPointEditorTool::leftButtonDrag(const TPointD &pos, TThickPoint cp; TPointD controlPoint; TPointD newPos; + int count = m_controlPointEditorStroke.getControlPointCount(); + if (m_lastPointSelected > count - 1) { + m_selection.selectNone(); + m_lastPointSelected = -1; + if (m_undo) delete(m_undo); + m_undo = 0; + return; + } cp = m_controlPointEditorStroke.getControlPoint(m_lastPointSelected); controlPoint = TPointD(cp.x, cp.y); newPos = calculateSnap(pos); @@ -881,6 +896,12 @@ void ControlPointEditorTool::selectRegion(TStroke *stroke) { void ControlPointEditorTool::leftButtonUp(const TPointD &realPos, const TMouseEvent &e) { + if (m_selection.getPointsDeleted()) { + m_selection.setArePointsDeleted(false); + if (m_undo) delete(m_undo); + m_undo = 0; + return; + } TVectorImageP vi(getImage(true)); int currentStroke = m_controlPointEditorStroke.getStrokeIndex(); if (!vi || currentStroke == -1) return; @@ -917,6 +938,7 @@ void ControlPointEditorTool::leftButtonUp(const TPointD &realPos, m_isImageChanged = false; } } + std::set oldPoints = m_selection.getSelectedPoints(); if (m_action == NONE || !m_isImageChanged) { m_undo = 0; @@ -927,6 +949,16 @@ void ControlPointEditorTool::leftButtonUp(const TPointD &realPos, notifyImageChanged(); invalidate(); + if (m_action == CP_MOVEMENT) { + if (oldPoints.size() >= 1) { + for (auto point : oldPoints) { + m_selection.select(point); + m_lastPointSelected = point; + } + m_selection.makeCurrent(); + } + } + // Registro l'UNDO if (m_undo) { TUndoManager::manager()->add(m_undo); diff --git a/toonz/sources/tnztools/controlpointselection.cpp b/toonz/sources/tnztools/controlpointselection.cpp index cb67c7fa..9f706591 100644 --- a/toonz/sources/tnztools/controlpointselection.cpp +++ b/toonz/sources/tnztools/controlpointselection.cpp @@ -1076,6 +1076,10 @@ void ControlPointSelection::setUnlinear() { //----------------------------------------------------------------------------- void ControlPointSelection::deleteControlPoints() { + if (!m_controlPointEditorStroke) { + m_arePointsDeleted = true; + return; + } TTool *tool = TTool::getApplication()->getCurrentTool()->getTool(); TVectorImageP vi(tool->getImage(false)); int currentStrokeIndex = m_controlPointEditorStroke->getStrokeIndex(); diff --git a/toonz/sources/tnztools/controlpointselection.h b/toonz/sources/tnztools/controlpointselection.h index 44fa20f6..f107b371 100644 --- a/toonz/sources/tnztools/controlpointselection.h +++ b/toonz/sources/tnztools/controlpointselection.h @@ -140,6 +140,7 @@ private: std::set m_selectedPoints; int m_strokeIndex; ControlPointEditorStroke *m_controlPointEditorStroke; + bool m_arePointsDeleted = false; public: ControlPointSelection() : m_controlPointEditorStroke(0), m_strokeIndex(-1) {} @@ -162,6 +163,10 @@ public: void enableCommands() override; + bool getPointsDeleted() { return m_arePointsDeleted; } + void setArePointsDeleted(bool value) { m_arePointsDeleted = value; } + std::set getSelectedPoints() { return m_selectedPoints; } + protected slots: void setLinear(); void setUnlinear();