Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

make thickness option of vectorSelectTool as fixed

Abel You966eb1d41711
diff --git a/toonz/sources/tnztools/tooloptionscontrols.cpp b/toonz/sources/tnztools/tooloptionscontrols.cpp
index 33aef0fb4..5ae56c2dd 100644
--- a/toonz/sources/tnztools/tooloptionscontrols.cpp
+++ b/toonz/sources/tnztools/tooloptionscontrols.cpp
@@ -751,7 +751,6 @@ void MeasuredValueField::setMeasure(std::string name) {
//-----------------------------------------------------------------------------
void MeasuredValueField::commit() {
- if (!m_modified && !isReturnPressed()) return;
// commit is called when the field comes out of focus.
// mouse drag will call this - return if coming from mouse drag.
// else undo is set twice
@@ -759,6 +758,8 @@ void MeasuredValueField::commit() {
m_mouseEdit = false;
return;
}
+ if (!m_modified && !isReturnPressed()) return;
+
int err = 1;
bool isSet = m_value->setValue(text().toStdWString(), &err);
m_modified = false;
@@ -856,7 +857,7 @@ void MeasuredValueField::mouseMoveEvent(QMouseEvent *e) {
void MeasuredValueField::mouseReleaseEvent(QMouseEvent *e) {
if (!isEnabled()) return;
- // m_mouseEdit will be set false in commit
+ // m_mouseEdit will be set false in commit and at HERE
if (m_mouseEdit) {
// This seems redundant, but this is necessary for undo to work
double valueToRestore = m_value->getValue(TMeasuredValue::CurrentUnit);
@@ -868,6 +869,7 @@ void MeasuredValueField::mouseReleaseEvent(QMouseEvent *e) {
setText(QString::fromStdWString(m_value->toWideString(m_precision)));
emit measuredValueChanged(m_value, true);
clearFocus();
+ m_mouseEdit= false;
} else
QLineEdit::mouseReleaseEvent(e);
}
@@ -886,7 +888,9 @@ void MeasuredValueField::receiveMousePress(QMouseEvent *e) {
mousePressEvent(e);
}
-void MeasuredValueField::receiveMouseMove(QMouseEvent *e) { mouseMoveEvent(e); }
+void MeasuredValueField::receiveMouseMove(QMouseEvent *e) {
+ mouseMoveEvent(e);
+}
void MeasuredValueField::receiveMouseRelease(QMouseEvent *e) {
mouseReleaseEvent(e);
@@ -1472,18 +1476,20 @@ ThickChangeField::ThickChangeField(SelectionTool *tool, QString name)
void ThickChangeField::onChange(TMeasuredValue *fld, bool addToUndo) {
if (!m_tool || (m_tool->isSelectionEmpty() && !m_tool->isLevelType())) return;
-
- DragSelectionTool::VectorChangeThicknessTool *changeThickTool =
- new DragSelectionTool::VectorChangeThicknessTool(
- (VectorSelectionTool *)m_tool);
+ if (!m_changeThickTool)
+ m_changeThickTool.reset(new DragSelectionTool::VectorChangeThicknessTool(
+ (VectorSelectionTool *)m_tool));
TVectorImageP vi = (TVectorImageP)m_tool->getImage(true);
-
double p = 0.5 * getValue();
- double newThickness = p - m_tool->m_deformValues.m_maxSelectionThickness;
-
- changeThickTool->setThicknessChange(newThickness);
- changeThickTool->changeImageThickness(*vi, newThickness);
+
+ if (isLabelClicked()) {
+ m_changeThickTool->setStrokesThickness(*vi);
+ double newThickness = p - m_tool->m_deformValues.m_maxSelectionThickness;
+ m_changeThickTool->setThicknessChange(newThickness);
+ m_changeThickTool->changeImageThickness(*vi, newThickness);
+ } else
+ m_changeThickTool->setImageThickness(*vi, p);
// DragSelectionTool::DeformValues deformValues = m_tool->m_deformValues;
// // Like when I found it - it's a noop.
@@ -1491,7 +1497,8 @@ void ThickChangeField::onChange(TMeasuredValue *fld, bool addToUndo) {
// // Seems that the actual update is performed inside
// the above change..() instruction... >_<
if (addToUndo) {
- changeThickTool->addUndo();
+ m_changeThickTool->addUndo();
+ m_changeThickTool.release();
}
m_tool->computeBBox();
m_tool->invalidate();
diff --git a/toonz/sources/tnztools/tooloptionscontrols.h b/toonz/sources/tnztools/tooloptionscontrols.h
index 263919a47..814fb3753 100644
--- a/toonz/sources/tnztools/tooloptionscontrols.h
+++ b/toonz/sources/tnztools/tooloptionscontrols.h
@@ -24,6 +24,9 @@
#include "toonz/tstageobject.h"
#include "toonz/stageobjectutil.h"
+// ToonzTools
+#include "vectorselectiontool.h"
+
// STD includes
#include <string>
@@ -357,7 +360,9 @@ public:
void setValue(double v);
double getValue() const;
-
+
+ bool isLabelClicked() const { return m_labelClicked; }
+
void setPrecision(int precision);
int getPrecision() { return m_precision; }
@@ -554,6 +559,8 @@ class ThickChangeField final : public MeasuredValueField {
Q_OBJECT
SelectionTool *m_tool;
+ std::unique_ptr<DragSelectionTool::VectorChangeThicknessTool>
+ m_changeThickTool;
public:
ThickChangeField(SelectionTool *tool, QString name);
diff --git a/toonz/sources/tnztools/vectorselectiontool.cpp b/toonz/sources/tnztools/vectorselectiontool.cpp
index a9ae7d1e6..00897f7ca 100644
--- a/toonz/sources/tnztools/vectorselectiontool.cpp
+++ b/toonz/sources/tnztools/vectorselectiontool.cpp
@@ -1003,7 +1003,7 @@ void DragSelectionTool::VectorChangeThicknessTool::changeImageThickness(
for (int cp = 0; cp < (int)stroke.getControlPointCount(); ++cp) {
double thickness =
tcrop(data.m_tool.m_strokesThickness[s][cp] + data.m_newThickness,
- 0.0, 255.0);
+ 0.0, 255.0);
TThickPoint point(TPointD(stroke.getControlPoint(cp)), thickness);
@@ -1033,6 +1033,35 @@ void DragSelectionTool::VectorChangeThicknessTool::changeImageThickness(
}
}
+void DragSelectionTool::VectorChangeThicknessTool::setImageThickness(
+ TVectorImage &vi, double newFixedThickness) {
+ newFixedThickness = tcrop(newFixedThickness, 0.0, 255.0);
+
+ VectorSelectionTool *vsTool = static_cast<VectorSelectionTool *>(getTool());
+ const LevelSelection &levelSelection = vsTool->levelSelection();
+
+ std::vector<int> strokeIdxs;
+
+ if (levelSelection.isEmpty()) {
+ StrokeSelection *strokeSelection =
+ static_cast<StrokeSelection *>(m_tool->getSelection());
+ const std::set<int> &selectedStrokeIdxs = strokeSelection->getSelection();
+ strokeIdxs.assign(selectedStrokeIdxs.begin(), selectedStrokeIdxs.end());
+ } else {
+ strokeIdxs = getSelectedStrokes(vi, levelSelection);
+ }
+
+ std::for_each(strokeIdxs.begin(), strokeIdxs.end(),
+ [&newFixedThickness, &vi](int s) {
+ TStroke &stroke = *vi.getStroke(s);
+ for (int cp = 0; cp < stroke.getControlPointCount(); ++cp) {
+ stroke.setControlPoint(
+ cp, TThickPoint(TPointD(stroke.getControlPoint(cp)),
+ newFixedThickness));
+ }
+ });
+}
+
//-----------------------------------------------------------------------------
void DragSelectionTool::VectorChangeThicknessTool::addUndo() {
diff --git a/toonz/sources/tnztools/vectorselectiontool.h b/toonz/sources/tnztools/vectorselectiontool.h
index 8711c4e75..bac59ae8c 100644
--- a/toonz/sources/tnztools/vectorselectiontool.h
+++ b/toonz/sources/tnztools/vectorselectiontool.h
@@ -251,6 +251,8 @@ public:
void setThicknessChange(double value) { m_thicknessChange = value; }
void changeImageThickness(TVectorImage &vi, double newThickness);
+ void setImageThickness(TVectorImage &vi, double newThickness);
+
void addUndo();
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;