diff --git a/toonz/sources/include/tools/assistant.h b/toonz/sources/include/tools/assistant.h index f63abb8..c11649c 100644 --- a/toonz/sources/include/tools/assistant.h +++ b/toonz/sources/include/tools/assistant.h @@ -311,6 +311,7 @@ protected: void drawMark(const TPointD &p, const TPointD &normal, double pixelSize, double alpha) const; void drawDot(const TPointD &p, double alpha) const; void drawPoint(const TAssistantPoint &point, double pixelSize) const; + void drawIndex(const TPointD &p, int index, bool selected, double pixelSize) const; inline void drawSegment(const TPointD &p0, const TPointD &p1, double pixelSize) const { drawSegment(p0, p1, pixelSize, getDrawingAlpha()); } @@ -325,6 +326,7 @@ public: virtual void draw(TToolViewer *viewer, bool enabled) const; void draw(TToolViewer *viewer) const { draw(viewer, true); } virtual void drawEdit(TToolViewer *viewer) const; + virtual void drawEdit(TToolViewer *viewer, int index) const; }; diff --git a/toonz/sources/tnztools/assistant.cpp b/toonz/sources/tnztools/assistant.cpp index 7b63920..002d85f 100644 --- a/toonz/sources/tnztools/assistant.cpp +++ b/toonz/sources/tnztools/assistant.cpp @@ -551,6 +551,84 @@ TAssistantBase::drawPoint(const TAssistantPoint &point, double pixelSize) const //--------------------------------------------------------------------------------------------------- void +TAssistantBase::drawIndex(const TPointD &p, int index, bool selected, double pixelSize) const { + static const int segments[7][4] = { + { 0, 2, 1, 2 }, // A + { 1, 1, 1, 2 }, // B + A + + { 1, 0, 1, 1 }, // C F B + { 0, 0, 1, 0 }, // D + G + + { 0, 0, 0, 1 }, // E E C + { 0, 1, 0, 2 }, // F + D + + { 0, 1, 1, 1 } }; // G + + static const int glyphs[][7] = { + // A B C D E F G + {1,1,1,1,1,1,0}, // 0 + {0,1,1,0,0,0,0}, // 1 + {1,1,0,1,1,0,1}, // 2 + {1,1,1,1,0,0,1}, // 3 + {0,1,1,0,0,1,1}, // 4 + {1,0,1,1,0,1,1}, // 5 + {1,0,1,1,1,1,1}, // 6 + {1,1,1,0,0,1,0}, // 7 + {1,1,1,1,1,1,1}, // 8 + {1,1,1,1,0,1,1} }; // 9 + + if (index < 0) index = 0; + + int len = 0; + int digits[16] = {}; + for(int i = index; i; i /= 10) + digits[len++] = i%10; + if (!len) len = 1; + + double w = 5, h = 5, d = 0.5, dx = w+2; + double alpha = 0.5; + double colorBlack[4] = { 0.0, 0.0, 0.0, alpha }; + double colorWhite[4] = { 1.0, 1.0, 1.0, alpha }; + if (selected) colorBlack[2] = 1.0; + + glPushAttrib(GL_ALL_ATTRIB_BITS); + tglEnableBlending(); + tglEnableLineSmooth(true, 1.0 * line_width_scale); + double k = 0.5*pixelSize*line_width_scale; + + double y = p.y; + for(int i = 0; i < len; ++i) { + double x = p.x + dx*(len-i-1); + const int *g = glyphs[digits[i]]; + for(int i = 0; i < 7; ++i) { + if (!g[i]) continue; + const int *s = segments[i]; + if (s[0] == s[2]) { + // vertical + glColor4dv(colorWhite); + tglDrawSegment( + TPointD(x + s[0]*w + k, y + s[1]*h + d), + TPointD(x + s[2]*w + k, y + s[3]*h - d) ); + glColor4dv(colorBlack); + tglDrawSegment( + TPointD(x + s[0]*w - k, y + s[1]*h + d), + TPointD(x + s[2]*w - k, y + s[3]*h - d) ); + } else { + // horisontal + glColor4dv(colorWhite); + tglDrawSegment( + TPointD(x + s[0]*w + d, y + s[1]*h + k), + TPointD(x + s[2]*w - d, y + s[3]*h + k) ); + glColor4dv(colorBlack); + tglDrawSegment( + TPointD(x + s[0]*w + d, y + s[1]*h - k), + TPointD(x + s[2]*w - d, y + s[3]*h - k) ); + } + } + } + glPopAttrib(); +} + +//--------------------------------------------------------------------------------------------------- + +void TAssistantBase::draw(TToolViewer *viewer, bool enabled) const { } @@ -565,6 +643,16 @@ TAssistantBase::drawEdit(TToolViewer *viewer) const { drawPoint(i->second, pixelSize); } +//--------------------------------------------------------------------------------------------------- + +void +TAssistantBase::drawEdit(TToolViewer *viewer, int index) const { + drawEdit(viewer); + drawIndex( + getBasePoint().position + TPointD(8, 8), + index, getBasePoint().selected, sqrt(tglGetPixelSize2()) ); +} + //************************************************************************ // TAssistant implementation diff --git a/toonz/sources/tnztools/assistants/replicatoraffine.cpp b/toonz/sources/tnztools/assistants/replicatoraffine.cpp index 876ce6f..0352b5b 100644 --- a/toonz/sources/tnztools/assistants/replicatoraffine.cpp +++ b/toonz/sources/tnztools/assistants/replicatoraffine.cpp @@ -65,13 +65,13 @@ public: void updateTranslation() const override { TReplicator::updateTranslation(); - setTranslation(m_idFixScale, tr("fix scale")); - setTranslation(m_idFixAspect, tr("fix aspect")); - setTranslation(m_idFixAngle, tr("fix angle")); - setTranslation(m_idFixSkew, tr("fix skew")); - setTranslation(m_idCount, tr("count")); - setTranslation(m_idCountInv, tr("inv. count")); - setTranslation(m_idPressure, tr("pressure")); + setTranslation(m_idFixScale, tr("Fix Scale")); + setTranslation(m_idFixAspect, tr("Fix Aspect")); + setTranslation(m_idFixAngle, tr("Fix Angle")); + setTranslation(m_idFixSkew, tr("Fix Skew")); + setTranslation(m_idCount, tr("Count")); + setTranslation(m_idCountInv, tr("Inv. Count")); + setTranslation(m_idPressure, tr("Pressure")); } diff --git a/toonz/sources/tnztools/editassistantstool.cpp b/toonz/sources/tnztools/editassistantstool.cpp index edacf7a..6e9acbd 100644 --- a/toonz/sources/tnztools/editassistantstool.cpp +++ b/toonz/sources/tnztools/editassistantstool.cpp @@ -33,6 +33,64 @@ //------------------------------------------------------------------- //============================================================================= +// Edit Assistants Swap Undo +//----------------------------------------------------------------------------- + +class EditAssistantsReorderUndo final : public ToolUtils::TToolUndo { +private: + int m_oldPos; + int m_newPos; + +public: + EditAssistantsReorderUndo( + TXshSimpleLevel *level, + const TFrameId &frameId, + int m_oldPos, + int m_newPos + ): + ToolUtils::TToolUndo(level, frameId), + m_oldPos(m_oldPos), + m_newPos(m_newPos) + { } + + QString getToolName() override + { return QString("Edit Assistants Tool"); } + + int getSize() const override + { return sizeof(*this); } + + void process(int oldPos, int newPos) const { + if (oldPos == newPos || oldPos < 0 || newPos < 0) + return; + TMetaImage *metaImage = dynamic_cast(m_level->getFrame(m_frameId, true).getPointer()); + if (!metaImage) + return; + + TMetaImage::Writer writer(*metaImage); + TMetaObjectList &list = *writer; + if (oldPos >= list.size() || newPos >= writer->size()) + return; + + TMetaObjectP obj = list[oldPos]; + list.erase(list.begin() + oldPos); + list.insert(list.begin() + newPos, obj); + } + + void undo() const override { + process(m_newPos, m_oldPos); + TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged(); + notifyImageChanged(); + } + + void redo() const override { + process(m_oldPos, m_newPos); + TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged(); + notifyImageChanged(); + } +}; + + +//============================================================================= // Edit Assistants Undo //----------------------------------------------------------------------------- @@ -65,7 +123,7 @@ public: m_metaObject(metaObject), m_oldData(oldData), m_newData(m_metaObject->data()), - m_size(m_oldData.getMemSize() + m_newData.getMemSize()) + m_size(sizeof(*this) + m_oldData.getMemSize() + m_newData.getMemSize()) { } int getSize() const override @@ -145,6 +203,7 @@ protected: TPropertyGroup m_allProperties; TPropertyGroup m_toolProperties; TEnumProperty m_assistantType; + TIntProperty m_replicatorIndex; TStringId m_newAssisnantType; bool m_dragging; @@ -176,6 +235,7 @@ public: EditAssistantsTool(): TTool("T_EditAssistants"), m_assistantType("AssistantType"), + m_replicatorIndex("ReplicatorIndex", 1, 10, 1, false), m_dragging(), m_dragAllPoints(), m_currentAssistantCreated(), @@ -191,6 +251,7 @@ public: selection = new Selection(*this); bind(MetaImage | EmptyTarget); m_toolProperties.bind(m_assistantType); + m_replicatorIndex.setSpinner(); updateTranslation(); } @@ -234,6 +295,10 @@ public: m_allProperties.bind( *m_toolProperties.getProperty(i) ); if (Closer closer = read(ModeAssistant)) { m_readAssistant->updateTranslation(); + if (int i = readReplicatorIndex(*m_reader)) { + m_replicatorIndex.setValue(i); + m_allProperties.bind( m_replicatorIndex ); + } TPropertyGroup &assistantProperties = m_readAssistant->getProperties(); for(int i = 0; i < assistantProperties.getPropertyCount(); ++i) m_allProperties.bind( *assistantProperties.getProperty(i) ); @@ -251,15 +316,18 @@ public: void updateTranslation() override { m_assistantType.setQStringName( tr("Assistant Type") ); + m_replicatorIndex.setQStringName( tr("Order") ); updateAssistantTypes(); if (Closer closer = read(ModeAssistant)) m_readAssistant->updateTranslation(); } bool onPropertyChanged(std::string name, bool addToUndo) override { - if (TProperty *property = m_toolProperties.getProperty(name)) { - if (name == m_assistantType.getName()) - m_newAssisnantType = TStringId::find( to_string(m_assistantType.getValue()) ); + if (m_replicatorIndex.getName() == name) { + writeReplicatorIndex(m_replicatorIndex.getValue()); + } else + if (name == m_assistantType.getName()) { + m_newAssisnantType = TStringId::find( to_string(m_assistantType.getValue()) ); } else { if (Closer closer = write(ModeAssistant, true)) m_writeAssistant->propertyChanged(TStringId::find(name)); @@ -470,6 +538,76 @@ protected: return success; } + int readReplicatorIndex(TMetaImage::Reader &reader) { + int cnt = (int)reader->size(); + int index = 0; + for(int i = 0; i < cnt; ++i) { + if (const TMetaObjectPC &obj = (*reader)[i]) + if (obj->getHandler()) { + ++index; + if (m_currentAssistantIndex == i) + return index; + } + } + return 0; + } + + void writeReplicatorIndex(int index) { + apply(); + + int wantIndex = index; + int oldPos = -1; + int newPos = -1; + bool changed = false; + + if (Closer closer = write(ModeAssistant)) { + if (index < 1) + index = 1; + + int idx = 0; + int lastPos = -1; + + TMetaObjectList &list = **m_writer; + + int cnt = (int)list.size(); + for(int i = 0; i < cnt; ++i) { + if (list[i] && list[i]->getHandler()) { + ++idx; + if (m_currentAssistantIndex == i) oldPos = i; + if (idx == index) newPos = i; + lastPos = i; + } + } + + if (oldPos >= 0 && lastPos >= 0) { + assert(idx); + if (newPos < 0) + { index = idx; newPos = lastPos; } + if (oldPos != newPos) { + TMetaObjectP obj = list[oldPos]; + list.erase(list.begin() + oldPos); + list.insert(list.begin() + newPos, obj); + + TUndoManager::manager()->add(new EditAssistantsReorderUndo( + getApplication()->getCurrentLevel()->getLevel()->getSimpleLevel(), + getCurrentFid(), + oldPos, + newPos )); + + changed = true; + } + } + } + + if (changed) { + m_currentAssistantIndex = newPos; + invalidate(); + } + + if (wantIndex != index) + this->updateOptionsBox(); + } + public: void deselect() { resetCurrentPoint(); } @@ -595,12 +733,19 @@ public: TPointD position = m_currentPosition + m_currentPointOffset; // draw assistants + int index = 0; if (Closer closer = read(ModeImage)) for(TMetaObjectListCW::iterator i = (*m_reader)->begin(); i != (*m_reader)->end(); ++i) if (*i) if (const TAssistantBase *base = (*i)->getHandler()) { - base->drawEdit(getViewer()); + if (dynamic_cast(base)) { + ++index; + base->drawEdit(getViewer(), index); + } else { + base->drawEdit(getViewer()); + } + if (const TAssistant *assistant = dynamic_cast(base)) assistant->getGuidelines( position, diff --git a/toonz/sources/tnztools/toonzvectorbrushtool.h b/toonz/sources/tnztools/toonzvectorbrushtool.h index b15a33b..157e84a 100644 --- a/toonz/sources/tnztools/toonzvectorbrushtool.h +++ b/toonz/sources/tnztools/toonzvectorbrushtool.h @@ -211,7 +211,7 @@ protected: StrokeList m_firstStrokes; TFrameId m_firstFrameId, m_veryFirstFrameId; TPixel32 m_currentColor; - int m_styleId; // bwtodo: remove + int m_styleId; double m_minThick, m_maxThick; // for snapping and framerange diff --git a/toonz/sources/toonzqt/intfield.cpp b/toonz/sources/toonzqt/intfield.cpp index 01ff0e6..e9ad097 100644 --- a/toonz/sources/toonzqt/intfield.cpp +++ b/toonz/sources/toonzqt/intfield.cpp @@ -492,9 +492,8 @@ void IntField::onIncClicked() { m_lineEdit->setValue(value); m_slider->setValue(value2pos(value)); m_roller->setValue((double)value); - emit valueChanged(false); m_lineEdit->setCursorPosition(0); - emit valueChanged(true); + emit valueChanged(false); } //----------------------------------------------------------------------------- @@ -504,9 +503,8 @@ void IntField::onDecClicked() { m_lineEdit->setValue(value); m_slider->setValue(value2pos(value)); m_roller->setValue((double)value); - emit valueChanged(false); m_lineEdit->setCursorPosition(0); - emit valueChanged(true); + emit valueChanged(false); } //-----------------------------------------------------------------------------