OpenToonz - An open-source full-featured 2D animation creation software
C
fix updating animated guide (#2264)
shun-iwasawa18a7c631a594
diff --git a/toonz/sources/common/tvrender/tglregions.cpp b/toonz/sources/common/tvrender/tglregions.cppindex f698d848b..8ae913966 100644--- a/toonz/sources/common/tvrender/tglregions.cpp+++ b/toonz/sources/common/tvrender/tglregions.cpp@@ -146,10 +146,13 @@ void drawArrows(TStroke *stroke, bool onlyFirstPoint) {for (int i = 0; i <= points; i++) {currentPosition = i / (double)points;point = stroke->getPointAtLength(length * currentPosition);- prePoint = (i == 0) ? point : stroke->getPointAtLength(- length * (currentPosition - 0.02));- postPoint = (i == points) ? point : stroke->getPointAtLength(- length * (currentPosition + 0.02));+ prePoint =+ (i == 0) ? point+ : stroke->getPointAtLength(length * (currentPosition - 0.02));+ postPoint =+ (i == points)+ ? point+ : stroke->getPointAtLength(length * (currentPosition + 0.02));if (prePoint == postPoint) continue;@@ -565,7 +568,7 @@ static void tglDoDraw(const TVectorRenderData &rd, TRegion *r) {//-------------------------------------------------------------------------------------static void tglDoDraw(const TVectorRenderData &rd, const TStroke *s) {+static bool tglDoDraw(const TVectorRenderData &rd, const TStroke *s) {bool visible = false;int colorCount = 0;@@ -587,6 +590,8 @@ static void tglDoDraw(const TVectorRenderData &rd, const TStroke *s) {}}+ bool ret = false;+if (visible) {// Change stroke color to blue if guided drawingif (rd.m_showGuidedDrawing && rd.m_highLightNow) {@@ -596,6 +601,7 @@ static void tglDoDraw(const TVectorRenderData &rd, const TStroke *s) {delete newRd;TStroke *new_s = (TStroke *)s;drawFirstControlPoint(rd, new_s);+ ret = rd.m_animatedGuidedDrawing;} else {tglDraw(rd, s, false);}@@ -604,6 +610,7 @@ static void tglDoDraw(const TVectorRenderData &rd, const TStroke *s) {// drawControlPoints(rd, vim->getStroke(i), sqrt(tglGetPixelSize2()), true);// assert(checkQuadraticDistance(vim->getStroke(i),true));#endif+ return ret;}//------------------------------------------------------------------------------------@@ -611,7 +618,7 @@ static void tglDoDraw(const TVectorRenderData &rd, const TStroke *s) {namespace {void doDraw(const TVectorImage *vim, const TVectorRenderData &_rd,- bool drawEnteredGroup) {+ bool drawEnteredGroup, TStroke **guidedStroke = 0) {static TOnionFader *fade = new TOnionFader(TPixel::White, 0.5);TVectorRenderData rd(_rd);@@ -663,7 +670,8 @@ rdRegions.m_alphaChannel = rdRegions.m_antiAliasing = false;*/CurrStrokeIndex = strokeIndex;CurrVimg = vim;#endif- tglDoDraw(rd, vim->getStroke(strokeIndex));+ bool isGuided = tglDoDraw(rd, vim->getStroke(strokeIndex));+ if (isGuided && guidedStroke) *guidedStroke = vim->getStroke(strokeIndex);strokeIndex++;}}@@ -672,7 +680,8 @@ rdRegions.m_alphaChannel = rdRegions.m_antiAliasing = false;*///-------------------------------------------------------------------------------------void tglDraw(const TVectorRenderData &rd, const TVectorImage *vim) {+void tglDraw(const TVectorRenderData &rd, const TVectorImage *vim,+ TStroke **guidedStroke) {assert(vim);if (!vim) return;@@ -689,8 +698,9 @@ void tglDraw(const TVectorRenderData &rd, const TVectorImage *vim) {glEnable(GL_ALPHA_TEST);glAlphaFunc(GL_GREATER, 0);- doDraw(vim, rd, false);- if (!rd.m_isIcon && vim->isInsideGroup() > 0) doDraw(vim, rd, true);+ doDraw(vim, rd, false, guidedStroke);+ if (!rd.m_isIcon && vim->isInsideGroup() > 0)+ doDraw(vim, rd, true, guidedStroke);glDisable(GL_ALPHA_TEST);diff --git a/toonz/sources/include/toonz/stagevisitor.h b/toonz/sources/include/toonz/stagevisitor.hindex a861222a6..6d134e554 100644--- a/toonz/sources/include/toonz/stagevisitor.h+++ b/toonz/sources/include/toonz/stagevisitor.h@@ -252,6 +252,8 @@ private:// darken blended view mode for viewing the non-cleanuped and stacked drawingsbool m_doRasterDarkenBlendedView;+ std::vector<TStroke *> m_guidedStrokes;+public:RasterPainter(const TDimension &dim, const TAffine &viewAff,const TRect &rect, const ImagePainter::VisualSettings &vs,@@ -279,6 +281,8 @@ public:bool isSingleColumnEnabled() const { return m_singleColumnEnabled; }void setRasterDarkenBlendedView(bool on) { m_doRasterDarkenBlendedView = on; }++ std::vector<TStroke *> &getGuidedStrokes() { return m_guidedStrokes; }};//=============================================================================diff --git a/toonz/sources/include/tvectorgl.h b/toonz/sources/include/tvectorgl.hindex 2909c9812..0e8a1968d 100644--- a/toonz/sources/include/tvectorgl.h+++ b/toonz/sources/include/tvectorgl.h@@ -49,7 +49,8 @@ class TVectorRenderData;\par stroke is element to draw\par rd: \sa TVectorRenderData*/-void DVAPI tglDraw(const TVectorRenderData &rd, const TVectorImage *vim);+void DVAPI tglDraw(const TVectorRenderData &rd, const TVectorImage *vim,+ TStroke **guidedStroke = (TStroke **)nullptr);void DVAPI tglDrawMask(const TVectorRenderData &rd, const TVectorImage *vim);void DVAPI tglDraw(const TVectorRenderData &rd, const TStroke *stroke,bool pushAttribs = true);diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cppindex e5c946fdd..229441199 100644--- a/toonz/sources/toonz/preferencespopup.cpp+++ b/toonz/sources/toonz/preferencespopup.cpp@@ -814,7 +814,7 @@ void PreferencesPopup::onOnionColorsForShiftAndTraceChanged(int index) {//-----------------------------------------------------------------------------void PreferencesPopup::onGuidedDrawingStyleChanged(int index) {- m_pref->setAnimatedGuidedDrawing(index);+ m_pref->setAnimatedGuidedDrawing(index == 1);}//-----------------------------------------------------------------------------@@ -1913,7 +1913,8 @@ PreferencesPopup::PreferencesPopup()QStringList guidedDrawingStyles;guidedDrawingStyles << tr("Arrow Markers") << tr("Animated Guide");m_guidedDrawingStyle->addItems(guidedDrawingStyles);- m_guidedDrawingStyle->setCurrentIndex(m_pref->getAnimatedGuidedDrawing());+ m_guidedDrawingStyle->setCurrentIndex(m_pref->getAnimatedGuidedDrawing() ? 1+ : 0);//--- Version Control ------------------------------m_enableVersionControl->setChecked(m_pref->isSVNEnabled());diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cppindex 2655b3eea..f00b9c81c 100644--- a/toonz/sources/toonz/sceneviewer.cpp+++ b/toonz/sources/toonz/sceneviewer.cpp@@ -1607,6 +1607,13 @@ void SceneViewer::drawScene() {drawSpline(getViewMatrix(), clipRect,m_referenceMode == CAMERA3D_REFERENCE, m_pixelSize);assert(glGetError() == 0);++ // gather animated guide strokes' bounding boxes+ // it is used for updating viewer next time+ std::vector<TStroke *> guidedStrokes = painter.getGuidedStrokes();+ for (auto itr = guidedStrokes.begin(); itr != guidedStrokes.end(); ++itr) {+ m_guidedDrawingBBox += (*itr)->getBBox();+ }}}@@ -1748,11 +1755,19 @@ void SceneViewer::GLInvalidateRect(const TRectD &rect) {return;else if (rect.isEmpty())m_clipRect = InvalidateAllRect;- else+ else {m_clipRect += rect;+ if (!m_guidedDrawingBBox.isEmpty()) {+ TTool *tool = TApp::instance()->getCurrentTool()->getTool();+ TPointD topLeft = tool->getMatrix() * m_guidedDrawingBBox.getP00();+ TPointD bottomRight = tool->getMatrix() * m_guidedDrawingBBox.getP11();+ m_clipRect += TRectD(topLeft, bottomRight);+ }+ }update();if (m_vRuler) m_vRuler->update();if (m_hRuler) m_hRuler->update();+ m_guidedDrawingBBox.empty();}//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.hindex 03d3e1ab3..a07252fed 100644--- a/toonz/sources/toonz/sceneviewer.h+++ b/toonz/sources/toonz/sceneviewer.h@@ -173,6 +173,10 @@ class SceneViewer final : public GLWidgetForHighDpi,// So discarding the resources in old context in initializeGL.TGlContext m_currentContext;+ // used for updating viewer where the animated guide appears+ // updated in drawScene() and used in GLInvalidateRect()+ TRectD m_guidedDrawingBBox;+public:enum ReferenceMode {NORMAL_REFERENCE = 1,diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cppindex e5a7872bc..8399b3cec 100644--- a/toonz/sources/toonzlib/preferences.cpp+++ b/toonz/sources/toonzlib/preferences.cpp@@ -1598,7 +1598,7 @@ void Preferences::setGuidedDrawing(int status) {void Preferences::setAnimatedGuidedDrawing(bool status) {m_animatedGuidedDrawing = status;- m_settings->setValue("animatedGuidedDrawing", status);+ m_settings->setValue("animatedGuidedDrawing", status ? "1" : "0");}//-----------------------------------------------------------------diff --git a/toonz/sources/toonzlib/stagevisitor.cpp b/toonz/sources/toonzlib/stagevisitor.cppindex 46be1251f..58784eefa 100644--- a/toonz/sources/toonzlib/stagevisitor.cpp+++ b/toonz/sources/toonzlib/stagevisitor.cpp@@ -925,10 +925,11 @@ void RasterPainter::onVectorImage(TVectorImage *vi,vi->selectFill(vi->getBBox(), 0, 1, true, true, false);}+ TStroke *guidedStroke = 0;if (m_maskLevel > 0)tglDrawMask(rd, vi);else- tglDraw(rd, vi);+ tglDraw(rd, vi, &guidedStroke);if (tc & ToonzCheck::eAutoclose) drawAutocloses(vi, rd);@@ -937,6 +938,8 @@ void RasterPainter::onVectorImage(TVectorImage *vi,delete cf;delete guidedCf;++ if (guidedStroke) m_guidedStrokes.push_back(guidedStroke);}//-----------------------------------------------------