Merge pull request #2858 from shun-iwasawa/g/precise_control_with_alt_key
Enable Animate tool to control precisely by pressing the Alt key
This commit is contained in:
commit
be0c0511f7
7 changed files with 109 additions and 62 deletions
|
@ -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
|
||||
|
|
BIN
toonz/sources/tnztools/Resources/ex_precise.png
Normal file
BIN
toonz/sources/tnztools/Resources/ex_precise.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1,001 B |
BIN
toonz/sources/tnztools/Resources/ex_precise_left.png
Normal file
BIN
toonz/sources/tnztools/Resources/ex_precise_left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1,002 B |
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -78,6 +78,8 @@
|
|||
<file>Resources/ex_style_line_left.png</file>
|
||||
<file>Resources/ex_z.png</file>
|
||||
<file>Resources/ex_z_left.png</file>
|
||||
<file>Resources/ex_precise.png</file>
|
||||
<file>Resources/ex_precise_left.png</file>
|
||||
<file>Resources/brush_large.png</file>
|
||||
<file>Resources/brush_crosshair.png</file>
|
||||
<file>Resources/tracker.png</file>
|
||||
|
|
Loading…
Reference in a new issue