fix updating animated guide (#2264)

This commit is contained in:
shun-iwasawa 2018-09-11 15:41:56 +09:00 committed by masafumi-inoue
parent 045b61c7fa
commit 18a7c631a5
8 changed files with 54 additions and 16 deletions

View file

@ -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 drawing
if (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);

View file

@ -252,6 +252,8 @@ private:
// darken blended view mode for viewing the non-cleanuped and stacked drawings
bool 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; }
};
//=============================================================================

View file

@ -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);

View file

@ -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());

View file

@ -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();
}
//-----------------------------------------------------------------------------

View file

@ -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,

View file

@ -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");
}
//-----------------------------------------------------------------

View file

@ -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);
}
//-----------------------------------------------------