diff --git a/toonz/sources/tnztools/rasterselectiontool.cpp b/toonz/sources/tnztools/rasterselectiontool.cpp index 8d22d41..649c88c 100644 --- a/toonz/sources/tnztools/rasterselectiontool.cpp +++ b/toonz/sources/tnztools/rasterselectiontool.cpp @@ -397,7 +397,7 @@ void DragSelectionTool::RasterMoveSelectionTool::leftButtonDrag( //----------------------------------------------------------------------------- DragSelectionTool::RasterScaleTool::RasterScaleTool(RasterSelectionTool *tool, - int type) + ScaleType type) : RasterDeformTool(tool, true) { m_scale = new Scale(this, type); } diff --git a/toonz/sources/tnztools/rasterselectiontool.h b/toonz/sources/tnztools/rasterselectiontool.h index b29c29c..e0f6035 100644 --- a/toonz/sources/tnztools/rasterselectiontool.h +++ b/toonz/sources/tnztools/rasterselectiontool.h @@ -167,7 +167,7 @@ class RasterScaleTool final : public RasterDeformTool { Scale *m_scale; public: - RasterScaleTool(RasterSelectionTool *tool, int type); + RasterScaleTool(RasterSelectionTool *tool, ScaleType type); /*! Return scale value. */ TPointD transform(int index, TPointD newPos) override; void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override; diff --git a/toonz/sources/tnztools/selectiontool.cpp b/toonz/sources/tnztools/selectiontool.cpp index b6f04fc..48c302a 100644 --- a/toonz/sources/tnztools/selectiontool.cpp +++ b/toonz/sources/tnztools/selectiontool.cpp @@ -13,6 +13,8 @@ #include +#include + using namespace ToolUtils; using namespace DragSelectionTool; @@ -20,50 +22,30 @@ TEnv::StringVar SelectionType("SelectionType", "Rectangular"); //----------------------------------------------------------------------------- -DragSelectionTool::DragTool *createNewMoveSelectionTool(SelectionTool *st) { +template DragSelectionTool::DragTool* createNewDragTool(SelectionTool* st, Args... args) { VectorSelectionTool *vst = dynamic_cast(st); RasterSelectionTool *rst = dynamic_cast(st); if (vst) - return new DragSelectionTool::VectorMoveSelectionTool(vst); + return new Tv(vst, args...); else if (rst) - return new DragSelectionTool::RasterMoveSelectionTool(rst); - return 0; + return new Tr(rst, args...); + return nullptr; } -//----------------------------------------------------------------------------- +DragSelectionTool::DragTool *createNewMoveSelectionTool(SelectionTool *st) { + return createNewDragTool(st); +} DragSelectionTool::DragTool *createNewRotationTool(SelectionTool *st) { - VectorSelectionTool *vst = dynamic_cast(st); - RasterSelectionTool *rst = dynamic_cast(st); - if (vst) - return new DragSelectionTool::VectorRotationTool(vst); - else if (rst) - return new DragSelectionTool::RasterRotationTool(rst); - return 0; + return createNewDragTool(st); } -//----------------------------------------------------------------------------- - DragSelectionTool::DragTool *createNewFreeDeformTool(SelectionTool *st) { - VectorSelectionTool *vst = dynamic_cast(st); - RasterSelectionTool *rst = dynamic_cast(st); - if (vst) - return new DragSelectionTool::VectorFreeDeformTool(vst); - else if (rst) - return new DragSelectionTool::RasterFreeDeformTool(rst); - return 0; + return createNewDragTool(st); } -//----------------------------------------------------------------------------- - -DragSelectionTool::DragTool *createNewScaleTool(SelectionTool *st, int type) { - VectorSelectionTool *vst = dynamic_cast(st); - RasterSelectionTool *rst = dynamic_cast(st); - if (vst) - return new DragSelectionTool::VectorScaleTool(vst, type); - else if (rst) - return new DragSelectionTool::RasterScaleTool(rst, type); - return 0; +DragSelectionTool::DragTool *createNewScaleTool(SelectionTool *st, ScaleType type) { + return createNewDragTool(st, type); } //============================================================================= @@ -559,7 +541,7 @@ void DragSelectionTool::MoveSelection::leftButtonDrag(const TPointD &pos, // Scale //----------------------------------------------------------------------------- -DragSelectionTool::Scale::Scale(DeformTool *deformTool, int type) +DragSelectionTool::Scale::Scale(DeformTool *deformTool, ScaleType type) : m_deformTool(deformTool) , m_startCenter(deformTool->getTool()->getCenter()) , m_type(type) @@ -800,7 +782,7 @@ void DragSelectionTool::Scale::leftButtonDrag(const TPointD &pos, } TPointD newPos = pos; int selectedIndex = tool->getSelectedPoint(); - if (m_isShiftPressed && m_type == GLOBAL) { + if (m_isShiftPressed && m_type == ScaleType::GLOBAL) { TPointD point = tool->getBBox().getPoint(selectedIndex); TPointD delta; if (!isBboxReset) @@ -1069,11 +1051,11 @@ void SelectionTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) { else if (m_what == MOVE_CENTER) m_dragTool = new MoveCenterTool(this); else if (m_what == SCALE) - m_dragTool = createNewScaleTool(this, 0); + m_dragTool = createNewScaleTool(this, ScaleType::GLOBAL); else if (m_what == SCALE_X) - m_dragTool = createNewScaleTool(this, 1); + m_dragTool = createNewScaleTool(this, ScaleType::HORIZONTAL); else if (m_what == SCALE_Y) - m_dragTool = createNewScaleTool(this, 2); + m_dragTool = createNewScaleTool(this, ScaleType::VERTICAL); else if (m_what == DEFORM) m_dragTool = createNewFreeDeformTool(this); else if (m_what == GLOBAL_THICKNESS) @@ -1150,15 +1132,13 @@ bool SelectionTool::keyDown(QKeyEvent *event) { if (!ti && !vi && !ri) return false; - DragTool *dragTool = createNewMoveSelectionTool(this); + std::unique_ptr dragTool(createNewMoveSelectionTool(this)); TAffine aff = TTranslation(delta); dragTool->transform(aff); double factor = 1.0 / Stage::inch; m_deformValues.m_moveValue += factor * delta; dragTool->addTransformUndo(); TTool::getApplication()->getCurrentTool()->notifyToolChanged(); - delete dragTool; - dragTool = 0; invalidate(); return true; @@ -1394,4 +1374,4 @@ bool SelectionTool::isEventAcceptable(QEvent *e) { int key = keyEvent->key(); return (key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Left || key == Qt::Key_Right); -} \ No newline at end of file +} diff --git a/toonz/sources/tnztools/selectiontool.h b/toonz/sources/tnztools/selectiontool.h index ac0d5e3..ea33176 100644 --- a/toonz/sources/tnztools/selectiontool.h +++ b/toonz/sources/tnztools/selectiontool.h @@ -152,10 +152,10 @@ public: SelectionTool *getTool() const { return m_tool; } - virtual void transform(TAffine aff, double angle){}; - virtual void transform(TAffine aff){}; - virtual TPointD transform(int index, TPointD newPos) { return TPointD(); }; - virtual void addTransformUndo(){}; + virtual void transform(TAffine aff, double angle){} + virtual void transform(TAffine aff){} + virtual TPointD transform(int index, TPointD newPos) { return TPointD(); } + virtual void addTransformUndo(){} virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &) = 0; virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) = 0; @@ -254,6 +254,12 @@ public: // Scale //----------------------------------------------------------------------------- +enum class ScaleType { + GLOBAL = 0, + HORIZONTAL, + VERTICAL +}; + class Scale { TPointD m_startCenter; bool m_isShiftPressed; @@ -264,9 +270,9 @@ class Scale { DeformTool *m_deformTool; public: - enum Type { GLOBAL = 0, HORIZONTAL = 1, VERTICAL = 2 }; - int m_type; - Scale(DeformTool *deformTool, int type); + + ScaleType m_type; + Scale(DeformTool *deformTool, ScaleType type); /*! Return intersection between straight line in \b point0, \b point1 and straight line for @@ -309,7 +315,7 @@ compute scaleValue. */ DragSelectionTool::DragTool *createNewMoveSelectionTool(SelectionTool *st); DragSelectionTool::DragTool *createNewRotationTool(SelectionTool *st); DragSelectionTool::DragTool *createNewFreeDeformTool(SelectionTool *st); -DragSelectionTool::DragTool *createNewScaleTool(SelectionTool *st, int type); +DragSelectionTool::DragTool *createNewScaleTool(SelectionTool *st, DragSelectionTool::ScaleType type); //============================================================================= // SelectionTool @@ -347,6 +353,7 @@ protected: GLOBAL_THICKNESS, ADD_SELECTION } m_what; // RV + enum { P00 = 0, P10 = 1, @@ -400,7 +407,7 @@ public: DragSelectionTool::DeformValues m_deformValues; SelectionTool(int targetType); - ~SelectionTool(); + ~SelectionTool() override; ToolType getToolType() const override { return TTool::LevelWriteTool; } diff --git a/toonz/sources/tnztools/tooloptionscontrols.cpp b/toonz/sources/tnztools/tooloptionscontrols.cpp index 06335a3..d797097 100644 --- a/toonz/sources/tnztools/tooloptionscontrols.cpp +++ b/toonz/sources/tnztools/tooloptionscontrols.cpp @@ -1595,10 +1595,11 @@ SelectionScaleField::SelectionScaleField(SelectionTool *tool, int id, bool SelectionScaleField::applyChange(bool addToUndo) { if (!m_tool || (m_tool->isSelectionEmpty() && !m_tool->isLevelType())) return false; - DragSelectionTool::DragTool *scaleTool = createNewScaleTool(m_tool, 0); + using namespace DragSelectionTool; + DragTool *scaleTool = createNewScaleTool(m_tool, ScaleType::GLOBAL); double p = getValue(); if (p == 0) p = 0.00001; - DragSelectionTool::FourPoints points = m_tool->getBBox(); + FourPoints points = m_tool->getBBox(); TPointD center = m_tool->getCenter(); TPointD p0M = points.getPoint(7); TPointD p1M = points.getPoint(5); @@ -1866,4 +1867,4 @@ void ClickableLabel::mouseMoveEvent(QMouseEvent *event) { void ClickableLabel::mouseReleaseEvent(QMouseEvent *event) { emit onMouseRelease(event); -} \ No newline at end of file +} diff --git a/toonz/sources/tnztools/vectorselectiontool.cpp b/toonz/sources/tnztools/vectorselectiontool.cpp index b77b843..f542077 100644 --- a/toonz/sources/tnztools/vectorselectiontool.cpp +++ b/toonz/sources/tnztools/vectorselectiontool.cpp @@ -841,7 +841,7 @@ void DragSelectionTool::VectorMoveSelectionTool::leftButtonDrag( //----------------------------------------------------------------------------- DragSelectionTool::VectorScaleTool::VectorScaleTool(VectorSelectionTool *tool, - int type) + ScaleType type) : VectorDeformTool(tool), m_scale(new Scale(this, type)) {} //----------------------------------------------------------------------------- diff --git a/toonz/sources/tnztools/vectorselectiontool.h b/toonz/sources/tnztools/vectorselectiontool.h index 7e10b60..b9f874c 100644 --- a/toonz/sources/tnztools/vectorselectiontool.h +++ b/toonz/sources/tnztools/vectorselectiontool.h @@ -222,7 +222,7 @@ class VectorScaleTool final : public VectorDeformTool { std::unique_ptr m_scale; public: - VectorScaleTool(VectorSelectionTool *tool, int type); + VectorScaleTool(VectorSelectionTool *tool, ScaleType type); TPointD transform(int index, TPointD newPos) override; //!< Returns scale value.