From bce58dc69f1cd410179c325915c1926a348d4cbd Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Fri, 25 Oct 2019 11:02:38 +0900 Subject: [PATCH] animate tool : precise control with pressing Alt --- toonz/sources/include/tools/cursors.h | 3 +- .../sources/tnztools/Resources/ex_precise.png | Bin 0 -> 1001 bytes .../tnztools/Resources/ex_precise_left.png | Bin 0 -> 1002 bytes toonz/sources/tnztools/cursormanager.cpp | 7 +- toonz/sources/tnztools/edittool.cpp | 143 +++++++++++------- toonz/sources/tnztools/edittoolgadgets.cpp | 16 +- toonz/sources/tnztools/tnztools.qrc | 2 + 7 files changed, 109 insertions(+), 62 deletions(-) create mode 100644 toonz/sources/tnztools/Resources/ex_precise.png create mode 100644 toonz/sources/tnztools/Resources/ex_precise_left.png diff --git a/toonz/sources/include/tools/cursors.h b/toonz/sources/include/tools/cursors.h index 2988e230..7947a7ec 100644 --- a/toonz/sources/include/tools/cursors.h +++ b/toonz/sources/include/tools/cursors.h @@ -96,6 +96,7 @@ enum { Ex_StyleArea = 0x40000, Ex_RGB = 0x80000, Ex_HV = 0x100000, + Ex_Precise = 0x200000, // This section is for cursors that have fixed text that needs to // be handled separately when flipping for left-handed cursors. @@ -110,6 +111,6 @@ enum { ScaleHVCursor = ScaleHVCursorBase | Ex_HV }; -} // namespace +} // namespace ToolCursor #endif diff --git a/toonz/sources/tnztools/Resources/ex_precise.png b/toonz/sources/tnztools/Resources/ex_precise.png new file mode 100644 index 0000000000000000000000000000000000000000..e44862f9bc5d8fd21fa03c4cc981fb8d69d066f7 GIT binary patch literal 1001 zcmVKLZ*U+lnSp_Ufq@}0xwybFAi#%#fq@|}KQEO51AM#2z{tSB zz;IdD(Z$J?fi%FHTu@ZPz`$^Tfq}s&CAB!2fq~%*0|P^Pc}YPD0|R3W0|SFdQg%TJ z0|R3L0|SFdc1Vyj0|R3V0|OIJNoqw20|NttbACZ(QD%BZiGrb}rKN&nN`6wRLU3hq zNosDff@fZGeo;YwQDRAI3IhWJ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N#(Wb zR<%ZTKMh%px0?I3CTgeZSnCSuzS29QKi{CnFv`f%Skm~n$vxA{#r++CO)=?RdfInDbtjt*-0cR=O|sSme3TYk~JdpT)k*{8ss|57-*GH|SXK z`H)+o&%(Y$FhvSRDMcH{xWz`r<;Axo%ud{#bT;{UDpQ(Vx=lt@W>wa#>^(X6@|g0~ z3w#QTi)I%eE_qufQSMSvSUIoiZ1vw-y}J1NNe#yue>WSnq_@s%yWSz#>D|@deYlsQ z&%VEI!oG?BCp%7QoqA$A?~LG?vt~V-qcyi=-o6D~3&R#IUi@*X!?Fp>AFecB)w=rT zTHSR`>u+u}*wnH4!B(qnQ@4NE>AP#y9*(`~`;H$_KiGNb^%1|Ln~#g1s6F}QwD*}U z=VZ^fU-)z>?((Ut7T1>D5WU%Y>+7BLyEpIqJUH;k^zrJaiqB@g5PaG7n)yxL+n?`C zKYaRB@cG@>yl?M*RI+y?e7jKeZ#YO-C082?kK~#9!?9ed^05Avx!2JKyb}-P; zDYkSA;v!r`QMfMz2L}fS|HddljfY4!?xBwf*)BeEhHrV=%$o&IZf1bso-P0Y0RR63 Y0MQOx&uOfsQ2+n{07*qoM6N<$g2(O7{{R30 literal 0 HcmV?d00001 diff --git a/toonz/sources/tnztools/cursormanager.cpp b/toonz/sources/tnztools/cursormanager.cpp index 48cf7fbb..0381006c 100644 --- a/toonz/sources/tnztools/cursormanager.cpp +++ b/toonz/sources/tnztools/cursormanager.cpp @@ -114,8 +114,9 @@ const struct { {ToolCursor::Ex_StyleArea, "ex_style_area"}, {ToolCursor::Ex_RGB, "ex_rgb"}, {ToolCursor::Ex_HV, "ex_hv"}, + {ToolCursor::Ex_Precise, "ex_precise"}, {0, 0}}; -}; +}; // namespace //============================================================================= // CursorManager @@ -141,9 +142,9 @@ public: p.setCompositionMode(QPainter::CompositionMode_SourceOver); for (int i = 0; decorateInfo[i].pixmapFilename; i++) if (decorationFlag & decorateInfo[i].decorateType) { - QString leftStr = ""; + QString leftStr = ""; if (useLeft) leftStr = "_left"; - QString path = QString(":Resources/") + + QString path = QString(":Resources/") + decorateInfo[i].pixmapFilename + leftStr + ".png"; p.drawPixmap(0, 0, QPixmap(path)); } diff --git a/toonz/sources/tnztools/edittool.cpp b/toonz/sources/tnztools/edittool.cpp index 1e62f3db..a557a030 100644 --- a/toonz/sources/tnztools/edittool.cpp +++ b/toonz/sources/tnztools/edittool.cpp @@ -105,14 +105,16 @@ public: m_affine.a13 = m_affine.a23 = 0; } - void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override { + void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override { if (m_lockCenterX && m_lockCenterY) return; double factor = 1.0 / Stage::inch; + // precise control with pressing Alt key + if (e.isAltPressed()) factor *= 0.1; TPointD delta = pos - m_firstPos; if (m_lockCenterX) delta = TPointD(0.0, delta.y); else if (m_lockCenterY) - delta = TPointD(delta.x, 0.0); + delta = TPointD(delta.x, 0.0); m_center = m_oldCenter + (m_affine * delta) * factor; TTool::getApplication() ->getCurrentTool() @@ -276,6 +278,8 @@ public: delta.x = 0; } double factor = 1.0 / Stage::inch; + // precise control with pressing Alt key + if (e.isAltPressed()) factor *= 0.1; setValues(getOldValue(0) + delta.x * factor, getOldValue(1) + delta.y * factor); } @@ -389,7 +393,7 @@ public: m_center = getCenter(); start(); } - void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override { + void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override { if (m_lockRotation) return; TPointD a = m_lastPos - m_center; TPointD b = pos - m_center; @@ -408,6 +412,8 @@ a = m_viewer->mouseToTool(gc) - m_curCenter; if (a2 < eps || b2 < eps) return; double dang = asin(cross(a, b) / sqrt(a2 * b2)) * M_180_PI; + // precise control with pressing Alt key + if (e.isAltPressed()) dang *= 0.1; setValue(getValue(0) + dang); } }; @@ -441,6 +447,8 @@ public: // TPointD a = m_firstPos - m_center; double r1 = norm(pos - m_center); if (r1 < 0.0001) return; + // precise control with pressing Alt key + if (e.isAltPressed()) r1 = m_r0 + (r1 - m_r0) * 0.1; setValue(getOldValue(0) * r1 / m_r0); } }; @@ -480,9 +488,9 @@ public: const double eps = 1e-8; if (norm2(a) < eps || norm2(b) < eps) return; - double fx = b.x / a.x; + double fx = b.x / a.x; if (fabs(fx) > 1) fx = tsign(fx) * sqrt(abs(fx)); - double fy = b.y / a.y; + double fy = b.y / a.y; if (fabs(fy) > 1) fy = tsign(fy) * sqrt(abs(fy)); int constraint = m_constraint; @@ -503,11 +511,15 @@ public: fy = byax / bxay; } if (fabs(fx) > eps && fabs(fy) > eps) { - double oldv0 = getOldValue(0); - double oldv1 = getOldValue(1); + double oldv0 = getOldValue(0); + double oldv1 = getOldValue(1); if (fabs(oldv0) < 0.001) oldv0 = 0.001; if (fabs(oldv1) < 0.001) oldv1 = 0.001; - + // precise control with pressing Alt key + if (e.isAltPressed()) { + fx = 1.0 + (fx - 1.0) * 0.1; + fy = 1.0 + (fy - 1.0) * 0.1; + } double valueX = oldv0 * fx; double valueY = oldv1 * fy; if (m_lockScaleH) @@ -560,6 +572,11 @@ public: else fx = 0; } + // precise control with pressing Alt key + if (e.isAltPressed()) { + fx *= 0.1; + fy *= 0.1; + } setValues(getOldValue(0) + 0.01 * fx, getOldValue(1) + 0.01 * fy); } }; @@ -586,6 +603,8 @@ public: } void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override { double dz = m_viewer->projectToZ(e.m_pos - m_lastPos); + // precise control with pressing Alt key + if (e.isAltPressed()) dz *= 0.1; m_lastPos = e.m_pos; if (dz != 0.0) { m_dz += dz; @@ -639,6 +658,8 @@ class EditTool final : public TTool { double m_currentScaleFactor; FxGadgetController *m_fxGadgetController; + bool m_isAltPressed; + TEnumProperty m_scaleConstraint; TEnumProperty m_autoSelect; TBoolProperty m_globalKeyframes; @@ -752,7 +773,8 @@ EditTool::EditTool() , m_showCenterPosition("Center Position", true) , m_dragTool(0) , m_firstTime(true) - , m_activeAxis("Active Axis") { + , m_activeAxis("Active Axis") + , m_isAltPressed(false) { bind(TTool::AllTargets); m_prop.bind(m_scaleConstraint); m_prop.bind(m_autoSelect); @@ -907,6 +929,9 @@ void EditTool::mouseMove(const TPointD &, const TMouseEvent &e) { m_fxGadgetController->selectById(selectedDevice); invalidate(); } + + // for adding decoration to the cursor while pressing Alt key + m_isAltPressed = e.isAltPressed(); } //----------------------------------------------------------------------------- @@ -1647,56 +1672,62 @@ bool EditTool::onPropertyChanged(std::string propertyName) { //----------------------------------------------------------------------------- int EditTool::getCursorId() const { - /*--- FxParameter操作中のカーソル ---*/ - if (m_highlightedDevice >= 1000) return ToolCursor::FxGadgetCursor; - - /*--- カーソルをアクティブな軸に応じて選ぶ --*/ - std::wstring activeAxis = m_activeAxis.getValue(); - if (activeAxis == L"Position") { - if (m_highlightedDevice == ZTranslation) - return ToolCursor::MoveZCursor; - else if (LockPositionX && LockPositionY) - return ToolCursor::DisableCursor; - else if (LockPositionX) - return ToolCursor::MoveNSCursor; - else if (LockPositionY) - return ToolCursor::MoveEWCursor; - else - return ToolCursor::MoveCursor; - } else if (activeAxis == L"Rotation") { - return ToolCursor::RotCursor; - } else if (activeAxis == L"Scale") { - if (m_highlightedDevice == ScaleXY) { - if (LockScaleH && LockScaleV) + int ret; + // cursor for controling the fx gadget + if (m_highlightedDevice >= 1000) + ret = ToolCursor::FxGadgetCursor; + else { + // switch cursors depending on the active axis + std::wstring activeAxis = m_activeAxis.getValue(); + if (activeAxis == L"Position") { + if (m_highlightedDevice == ZTranslation) + ret = ToolCursor::MoveZCursor; + else if (LockPositionX && LockPositionY) return ToolCursor::DisableCursor; - else if (LockScaleH) - return ToolCursor::ScaleVCursor; - else if (LockScaleV) - return ToolCursor::ScaleHCursor; + else if (LockPositionX) + ret = ToolCursor::MoveNSCursor; + else if (LockPositionY) + ret = ToolCursor::MoveEWCursor; else - return ToolCursor::ScaleHVCursor; + ret = ToolCursor::MoveCursor; + } else if (activeAxis == L"Rotation") { + ret = ToolCursor::RotCursor; + } else if (activeAxis == L"Scale") { + if (m_highlightedDevice == ScaleXY) { + if (LockScaleH && LockScaleV) + return ToolCursor::DisableCursor; + else if (LockScaleH) + ret = ToolCursor::ScaleVCursor; + else if (LockScaleV) + ret = ToolCursor::ScaleHCursor; + else + ret = ToolCursor::ScaleHVCursor; + } else + ret = ToolCursor::ScaleGlobalCursor; + } else if (activeAxis == L"Shear") { + if (LockShearH && LockShearV) + return ToolCursor::DisableCursor; + else if (LockShearH) + ret = ToolCursor::ScaleVCursor; + else if (LockShearV) + ret = ToolCursor::ScaleHCursor; + else + ret = ToolCursor::ScaleCursor; + } else if (activeAxis == L"Center") { + if (LockCenterX && LockCenterY) + return ToolCursor::DisableCursor; + else if (LockCenterX) + ret = ToolCursor::MoveNSCursor; + else if (LockCenterY) + ret = ToolCursor::MoveEWCursor; + else + ret = ToolCursor::MoveCursor; } else - return ToolCursor::ScaleGlobalCursor; - } else if (activeAxis == L"Shear") { - if (LockShearH && LockShearV) - return ToolCursor::DisableCursor; - else if (LockShearH) - return ToolCursor::ScaleVCursor; - else if (LockShearV) - return ToolCursor::ScaleHCursor; - else - return ToolCursor::ScaleCursor; - } else if (activeAxis == L"Center") { - if (LockCenterX && LockCenterY) - return ToolCursor::DisableCursor; - else if (LockCenterX) - return ToolCursor::MoveNSCursor; - else if (LockCenterY) - return ToolCursor::MoveEWCursor; - else - return ToolCursor::MoveCursor; - } else - return ToolCursor::StrokeSelectCursor; + ret = ToolCursor::StrokeSelectCursor; + } + // precise control with pressing Alt key + if (m_isAltPressed) ret = ret | ToolCursor::Ex_Precise; + return ret; } //============================================================================= diff --git a/toonz/sources/tnztools/edittoolgadgets.cpp b/toonz/sources/tnztools/edittoolgadgets.cpp index c3c30ee2..489c4d85 100644 --- a/toonz/sources/tnztools/edittoolgadgets.cpp +++ b/toonz/sources/tnztools/edittoolgadgets.cpp @@ -110,6 +110,7 @@ public: class GadgetDragTool final : public DragTool { FxGadgetController *m_controller; FxGadget *m_gadget; + TPointD m_firstPos; public: GadgetDragTool(FxGadgetController *controller, FxGadget *gadget) @@ -120,14 +121,25 @@ public: void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override { m_gadget->createUndo(); m_gadget->leftButtonDown(getMatrix() * pos, e); + m_firstPos = pos; } void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override { - m_gadget->leftButtonDrag(getMatrix() * pos, e); + // precise control with pressing Alt key + if (e.isAltPressed()) { + TPointD precisePos = m_firstPos + (pos - m_firstPos) * 0.1; + m_gadget->leftButtonDrag(getMatrix() * precisePos, e); + } else + m_gadget->leftButtonDrag(getMatrix() * pos, e); } void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override { - m_gadget->leftButtonUp(getMatrix() * pos, e); + // precise control with pressing Alt key + if (e.isAltPressed()) { + TPointD precisePos = m_firstPos + (pos - m_firstPos) * 0.1; + m_gadget->leftButtonUp(getMatrix() * precisePos, e); + } else + m_gadget->leftButtonUp(getMatrix() * pos, e); m_gadget->commitUndo(); } }; diff --git a/toonz/sources/tnztools/tnztools.qrc b/toonz/sources/tnztools/tnztools.qrc index a95ee1e3..8d163479 100644 --- a/toonz/sources/tnztools/tnztools.qrc +++ b/toonz/sources/tnztools/tnztools.qrc @@ -78,6 +78,8 @@ Resources/ex_style_line_left.png Resources/ex_z.png Resources/ex_z_left.png + Resources/ex_precise.png + Resources/ex_precise_left.png Resources/brush_large.png Resources/brush_crosshair.png Resources/tracker.png