From 6cb65735489f4c7a37cb88f5ae11f12821658393 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Oct 08 2023 12:58:08 +0000 Subject: #assistants: apply column filter color --- diff --git a/toonz/sources/include/tools/assistant.h b/toonz/sources/include/tools/assistant.h index a8e8ea3..64bd2e0 100644 --- a/toonz/sources/include/tools/assistant.h +++ b/toonz/sources/include/tools/assistant.h @@ -62,9 +62,10 @@ class DVAPI TGuideline : public TSmartObject { public: const bool enabled; const double magnetism; + const TPixelD color; - TGuideline(bool enabled, double magnetism): - enabled(enabled), magnetism(magnetism) { } + TGuideline(bool enabled, double magnetism, const TPixelD &color): + enabled(enabled), magnetism(magnetism), color(color) { } virtual TTrackPoint transformPoint(const TTrackPoint &point) const { return point; } @@ -204,6 +205,10 @@ public: DRAW_ERROR = 1, }; + static TPixelD colorBase; + static TPixelD colorError; + static TPixelD colorEdit; + static TPixelD colorSelect; static unsigned int drawFlags; static const double lineWidthScale; @@ -318,8 +323,18 @@ protected: double getDrawingAlpha(bool enabled = true) const; double getDrawingGridAlpha() const; + TIntProperty* createSpinProperty(const TStringId &id, int def, int min, int max, bool hasMax = true); + inline TIntProperty* createSpinProperty(const TStringId &id, int def, int min) + { return createSpinProperty(id, def, min, 0, false); } + + void addProperty(TProperty *p); + void setTranslation(const TStringId &name, const QString &localName) const; + +public: + static TPixelD makeContrastColor(const TPixelD &color); static void drawSegment(const TPointD &p0, const TPointD &p1, double pixelSize, double alpha0, double alpha1); static void drawMark(const TPointD &p, const TPointD &normal, double pixelSize, double alpha); + static void drawDot(const TPointD &p, const TPixelD &color); static void drawDot(const TPointD &p, double alpha); static void drawPoint(const TAssistantPoint &point, double pixelSize); static void drawIndex(const TPointD &p, int index, bool selected, double pixelSize); @@ -331,14 +346,6 @@ protected: inline void drawDot(const TPointD &p) const { drawDot(p, getDrawingAlpha()); } - TIntProperty* createSpinProperty(const TStringId &id, int def, int min, int max, bool hasMax = true); - inline TIntProperty* createSpinProperty(const TStringId &id, int def, int min) - { return createSpinProperty(id, def, min, 0, false); } - - void addProperty(TProperty *p); - void setTranslation(const TStringId &name, const QString &localName) const; - -public: virtual void updateTranslation() const; virtual void draw(TToolViewer *viewer, bool enabled) const; void draw(TToolViewer *viewer) const { draw(viewer, true); } @@ -369,7 +376,11 @@ public: public: void updateTranslation() const override; - virtual void getGuidelines(const TPointD &position, const TAffine &toTool, TGuidelineList &outGuidelines) const; + virtual void getGuidelines( + const TPointD &position, + const TAffine &toTool, + const TPixelD &color, + TGuidelineList &outGuidelines) const; // calc W-coefficient and i-bounds for formula: x0 + 1/(i*W + 1) static bool calcPerspectiveStep( diff --git a/toonz/sources/include/tools/assistants/guidelineellipse.h b/toonz/sources/include/tools/assistants/guidelineellipse.h index faefda3..e8c8746 100644 --- a/toonz/sources/include/tools/assistants/guidelineellipse.h +++ b/toonz/sources/include/tools/assistants/guidelineellipse.h @@ -34,17 +34,20 @@ public: TGuidelineEllipse( bool enabled, double magnetism, + const TPixelD &color, const TAffine &matrix ); TGuidelineEllipse( bool enabled, double magnetism, + const TPixelD &color, const TAffine &matrix, const TAffine &matrixInv ); TGuidelineEllipse( bool enabled, double magnetism, + const TPixelD &color, const TAffine &matrix, const TAffine &matrixInv, double Rx, diff --git a/toonz/sources/include/tools/assistants/guidelineline.h b/toonz/sources/include/tools/assistants/guidelineline.h index 7373be9..a45b118 100644 --- a/toonz/sources/include/tools/assistants/guidelineline.h +++ b/toonz/sources/include/tools/assistants/guidelineline.h @@ -29,7 +29,7 @@ public: const TPointD p0; const TPointD p1; - TGuidelineLineBase(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1); + TGuidelineLineBase(bool enabled, double magnetism, const TPixelD &color, const TPointD &p0, const TPointD &p1); void drawLine(const TPointD &p0, const TPointD &p1, bool restrict0, bool restrict1, bool active, bool enabled) const; static TPointD calcDirection(const TPointD &p0, const TPointD &p1); static bool truncateInfiniteLine(const TRectD &bounds, TPointD &p0, TPointD &p1); @@ -47,7 +47,7 @@ public: const TPointD dir; const double dist; - TGuidelineLine(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1); + TGuidelineLine(bool enabled, double magnetism, const TPixelD &color, const TPointD &p0, const TPointD &p1); TTrackPoint transformPoint(const TTrackPoint &point) const override; void draw(bool active, bool enabled) const override; }; @@ -61,7 +61,7 @@ class DVAPI TGuidelineInfiniteLine : public TGuidelineLineBase { public: const TPointD dir; - TGuidelineInfiniteLine(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1); + TGuidelineInfiniteLine(bool enabled, double magnetism, const TPixelD &color, const TPointD &p0, const TPointD &p1); TTrackPoint transformPoint(const TTrackPoint &point) const override; void draw(bool active, bool enabled) const override; }; @@ -75,7 +75,7 @@ class DVAPI TGuidelineRay : public TGuidelineLineBase { public: const TPointD dir; - TGuidelineRay(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1); + TGuidelineRay(bool enabled, double magnetism, const TPixelD &color, const TPointD &p0, const TPointD &p1); TTrackPoint transformPoint(const TTrackPoint &point) const override; void draw(bool active, bool enabled) const override; }; diff --git a/toonz/sources/tnztools/assistant.cpp b/toonz/sources/tnztools/assistant.cpp index 40061e4..3cd82ed 100644 --- a/toonz/sources/tnztools/assistant.cpp +++ b/toonz/sources/tnztools/assistant.cpp @@ -10,9 +10,12 @@ #include #include #include +#include +#include #include #include +#include #include #include @@ -27,6 +30,10 @@ const double TAssistantBase::lineWidthScale = 1.0; unsigned int TAssistantBase::drawFlags = 0; +TPixelD TAssistantBase::colorBase (0, 0, 0, 1); +TPixelD TAssistantBase::colorError (1, 0, 0, 1); +TPixelD TAssistantBase::colorEdit (0, 0, 0, 1); +TPixelD TAssistantBase::colorSelect(0, 0, 1, 1); //************************************************************************ @@ -41,13 +48,12 @@ TGuideline::drawSegment( bool active, bool enabled ) const { - double colorBlack[4] = { 0.0, 0.0, 0.0, 0.25 }; - double colorWhite[4] = { 1.0, 1.0, 1.0, 0.25 }; - - if (!this->enabled || !enabled) - colorBlack[3] = (colorWhite[3] = 0.125); - else if (active) - colorBlack[3] = (colorWhite[3] = 0.5); + double alpha = !this->enabled || !enabled ? 0.125 + : active ? 0.5 + : 0.25; + TPixelD cl = color; + cl.m *= alpha; + TPixelD clBack = TAssistantBase::makeContrastColor(cl); glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableBlending(); @@ -57,9 +63,9 @@ TGuideline::drawSegment( if (k > TConsts::epsilon*TConsts::epsilon) { k = 0.5*pixelSize*TAssistant::lineWidthScale/sqrt(k); d = TPointD(-k*d.y, k*d.x); - glColor4dv(colorWhite); + tglColor(clBack); tglDrawSegment(p0 - d, p1 - d); - glColor4dv(colorBlack); + tglColor(cl); tglDrawSegment(p0 + d, p1 + d); } glPopAttrib(); @@ -434,17 +440,23 @@ TAssistantBase::getDrawingGridAlpha() const //--------------------------------------------------------------------------------------------------- +TPixelD +TAssistantBase::makeContrastColor(const TPixelD &color) { + return color.r + color.g + color.b < 1.5 + ? TPixelD(1, 1, 1, color.m) + : TPixelD(0, 0, 0, color.m); +} + +//--------------------------------------------------------------------------------------------------- + void TAssistantBase::drawSegment(const TPointD &p0, const TPointD &p1, double pixelSize, double alpha0, double alpha1) { - double colors[][4] = { - { 1, 1, 1, alpha0 }, - { 1, 1, 1, alpha1 }, - { 0, 0, 0, alpha0 }, - { 0, 0, 0, alpha1 }, - }; - - if (drawFlags & DRAW_ERROR) - colors[2][0] = colors[3][0] = 1; + TPixelD color0 = (drawFlags & DRAW_ERROR) ? colorError : colorBase; + TPixelD color1 = color0; + color0.m *= alpha0; + color1.m *= alpha1; + TPixelD colorBack0 = makeContrastColor(color0); + TPixelD colorBack1 = makeContrastColor(color1); glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableBlending(); @@ -455,10 +467,10 @@ TAssistantBase::drawSegment(const TPointD &p0, const TPointD &p1, double pixelSi k = 0.5*pixelSize*lineWidthScale/sqrt(k); d = TPointD(-k*d.y, k*d.x); glBegin(GL_LINES); - glColor4dv(colors[0]); tglVertex(p0 - d); - glColor4dv(colors[1]); tglVertex(p1 - d); - glColor4dv(colors[2]); tglVertex(p0 + d); - glColor4dv(colors[3]); tglVertex(p1 + d); + tglColor(colorBack0); tglVertex(p0 - d); + tglColor(colorBack1); tglVertex(p1 - d); + tglColor(color0); tglVertex(p0 + d); + tglColor(color1); tglVertex(p1 + d); glEnd(); } glPopAttrib(); @@ -475,20 +487,19 @@ TAssistantBase::drawMark(const TPointD &p, const TPointD &normal, double pixelSi //--------------------------------------------------------------------------------------------------- void -TAssistantBase::drawDot(const TPointD &p, double alpha) { - double colorBlack[4] = { 0.0, 0.0, 0.0, alpha }; - double colorWhite[4] = { 1.0, 1.0, 1.0, alpha }; +TAssistantBase::drawDot(const TPointD &p, const TPixelD &color) { + TPixelD colorBack = makeContrastColor(color); glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableBlending(); - glColor4dv(colorWhite); + tglColor(colorBack); tglEnablePointSmooth(6.0); glBegin(GL_POINTS); glVertex2d(p.x, p.y); glEnd(); - glColor4dv(colorBlack); + tglColor(color); tglEnablePointSmooth(3.0); glBegin(GL_POINTS); glVertex2d(p.x, p.y); @@ -500,30 +511,35 @@ TAssistantBase::drawDot(const TPointD &p, double alpha) { //--------------------------------------------------------------------------------------------------- void +TAssistantBase::drawDot(const TPointD &p, double alpha) { + TPixelD color = (drawFlags & DRAW_ERROR) ? colorError : colorBase; + color.m *= alpha; + drawDot(p, color); +} + +//--------------------------------------------------------------------------------------------------- + +void TAssistantBase::drawPoint(const TAssistantPoint &point, double pixelSize) { if (!point.visible) return; double radius = point.radius; double crossSize = 1.2*radius; - + double width = point.selected ? 2.0 : 1.5; + double alpha = 0.5; - double colorBlack[4] = { 0.0, 0.0, 0.0, alpha }; - double colorGray[4] = { 0.5, 0.5, 0.5, alpha }; - double colorWhite[4] = { 1.0, 1.0, 1.0, alpha }; - double width = 1.5; - - if (point.selected) { - colorBlack[2] = 1.0; - colorGray[2] = 1.0; - width = 2.0; - } + TPixelD colorStroke = point.selected ? colorSelect : colorEdit; + colorStroke.m *= alpha; + TPixelD colorFill = colorStroke; + colorFill.m *= 0.5; + TPixelD colorBack = makeContrastColor(colorStroke); glPushAttrib(GL_ALL_ATTRIB_BITS); // fill tglEnableBlending(); if (point.type == TAssistantPoint::CircleFill) { - glColor4dv(colorGray); + tglColor(colorFill); tglDrawDisk(point.position, radius*pixelSize); } @@ -539,7 +555,7 @@ TAssistantBase::drawPoint(const TAssistantPoint &point, double pixelSize) { // back line tglEnableLineSmooth(true, 2.0*width*lineWidthScale); - glColor4dv(colorWhite); + tglColor(colorBack); if (cross) { tglDrawSegment(point.position - crossA, point.position + crossA); tglDrawSegment(point.position - crossB, point.position + crossB); @@ -548,7 +564,7 @@ TAssistantBase::drawPoint(const TAssistantPoint &point, double pixelSize) { // front line glLineWidth(width * lineWidthScale); - glColor4dv(colorBlack); + tglColor(colorStroke); if (cross) { tglDrawSegment(point.position - crossA, point.position + crossA); tglDrawSegment(point.position - crossB, point.position + crossB); @@ -558,19 +574,19 @@ TAssistantBase::drawPoint(const TAssistantPoint &point, double pixelSize) { // dots switch(point.type) { case TAssistantPoint::CircleDoubleDots: - drawDot(point.position - gridDx*0.5, alpha); - drawDot(point.position + gridDx*0.5, alpha); - drawDot(point.position - gridDy*0.5, alpha); - drawDot(point.position + gridDy*0.5, alpha); + drawDot(point.position - gridDx*0.5, colorStroke); + drawDot(point.position + gridDx*0.5, colorStroke); + drawDot(point.position - gridDy*0.5, colorStroke); + drawDot(point.position + gridDy*0.5, colorStroke); //no break case TAssistantPoint::CircleDots: - drawDot(point.position - gridDx, alpha); - drawDot(point.position + gridDx, alpha); - drawDot(point.position - gridDy, alpha); - drawDot(point.position + gridDy, alpha); + drawDot(point.position - gridDx, colorStroke); + drawDot(point.position + gridDx, colorStroke); + drawDot(point.position - gridDy, colorStroke); + drawDot(point.position + gridDy, colorStroke); //no break case TAssistantPoint::Circle: - drawDot(point.position, alpha); + drawDot(point.position, colorStroke); break; default: break; @@ -615,9 +631,9 @@ TAssistantBase::drawIndex(const TPointD &p, int index, bool selected, double pix 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; + TPixelD color = selected ? colorSelect : colorEdit; + color.m *= alpha; + TPixelD colorBack = makeContrastColor(color); glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableBlending(); @@ -633,21 +649,21 @@ TAssistantBase::drawIndex(const TPointD &p, int index, bool selected, double pix const int *s = segments[i]; if (s[0] == s[2]) { // vertical - glColor4dv(colorWhite); + tglColor(colorBack); 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); + tglColor(color); 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); + tglColor(colorBack); 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); + tglColor(color); tglDrawSegment( TPointD(x + s[0]*w + d, y + s[1]*h - k), TPointD(x + s[2]*w - d, y + s[3]*h - k) ); @@ -721,7 +737,7 @@ TAssistant::onFixData() { //--------------------------------------------------------------------------------------------------- void -TAssistant::getGuidelines(const TPointD&, const TAffine&, TGuidelineList&) const +TAssistant::getGuidelines(const TPointD&, const TAffine&, const TPixelD&, TGuidelineList&) const { } //--------------------------------------------------------------------------------------------------- @@ -830,6 +846,8 @@ TAssistant::scanAssistants( if (TXsheetHandle *XsheetHandle = application->getCurrentXsheet()) if (TXsheet *Xsheet = XsheetHandle->getXsheet()) { + ToonzScene *scene = Xsheet->getScene(); + TSceneProperties *props = scene ? scene->getProperties() : nullptr; TPointD dpiScale = getCurrentDpiScale(simpleLevel, tool->getCurrentFid()); int frame = frameHandle->getFrame(); int count = Xsheet->getColumnCount(); @@ -841,7 +859,7 @@ TAssistant::scanAssistants( worldToTrack.a22 /= dpiScale.y; } - for(int i = 0; i < count; ++i) + for(int i = 0; i < count; ++i) { if (TXshColumn *column = Xsheet->getColumn(i)) if (column->isCamstandVisible()) if (column->isPreviewVisible()) @@ -851,10 +869,21 @@ TAssistant::scanAssistants( if (TMetaImage *metaImage = dynamic_cast(image.getPointer())) { TAffine imageToTrack = worldToTrack * tool->getColumnMatrix(i); - if (draw) { glPushMatrix(); tglMultMatrix(imageToTrack); } + + TPixelD origColor = TAssistantBase::colorBase; + TPixelD color = props && column->getColorFilterId() + ? toPixelD(props->getColorFilterColor( column->getColorFilterId() )) + : origColor; + color.m *= column->getOpacity()/255.0; + + if (draw) { + TAssistantBase::colorBase = color; + glPushMatrix(); + tglMultMatrix(imageToTrack); + } TMetaImage::Reader reader(*metaImage); - for(TMetaObjectListCW::iterator i = reader->begin(); i != reader->end(); ++i) + for(TMetaObjectListCW::iterator i = reader->begin(); i != reader->end(); ++i) { if (*i) if (const TAssistant *assistant = (*i)->getHandler()) if (!enabledOnly || assistant->getEnabled()) @@ -863,12 +892,17 @@ TAssistant::scanAssistants( if (!doSomething) return true; if (findGuidelines) for(int i = 0; i < positionsCount; ++i) - assistant->getGuidelines(positions[i], imageToTrack, *outGuidelines); + assistant->getGuidelines(positions[i], imageToTrack, color, *outGuidelines); if (draw) assistant->draw(viewer, assistant->getEnabled() && markEnabled); } - - if (draw) glPopMatrix(); + } // for each meta object + + if (draw) { + glPopMatrix(); + TAssistantBase::colorBase = origColor; + } } + } // for each replication } if (drawGuidelines) diff --git a/toonz/sources/tnztools/assistants/assistantellipse.cpp b/toonz/sources/tnztools/assistants/assistantellipse.cpp index dbca015..332895c 100644 --- a/toonz/sources/tnztools/assistants/assistantellipse.cpp +++ b/toonz/sources/tnztools/assistants/assistantellipse.cpp @@ -130,6 +130,7 @@ TAffine TAssistantEllipse::calcEllipseMatrix() const { void TAssistantEllipse::getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const { bool restrictA = getRestrictA(); @@ -153,6 +154,7 @@ void TAssistantEllipse::getGuidelines( new TGuidelineEllipse( getEnabled(), getMagnetism(), + color, matrix, matrixInv ))); } else @@ -164,6 +166,7 @@ void TAssistantEllipse::getGuidelines( new TGuidelineEllipse( getEnabled(), getMagnetism(), + color, matrix * TAffine::scale(l) ))); } else { // restrictA TPointD p = matrixInv*position; @@ -180,6 +183,7 @@ void TAssistantEllipse::getGuidelines( new TGuidelineInfiniteLine( getEnabled(), getMagnetism(), + color, matrix*TPointD(-1.0, 0.0), matrix*TPointD(-1.0, 1.0) ))); } else @@ -189,6 +193,7 @@ void TAssistantEllipse::getGuidelines( new TGuidelineInfiniteLine( getEnabled(), getMagnetism(), + color, matrix*TPointD(1.0, 0.0), matrix*TPointD(1.0, 1.0) ))); } else { @@ -198,6 +203,7 @@ void TAssistantEllipse::getGuidelines( new TGuidelineEllipse( getEnabled(), getMagnetism(), + color, matrix * TAffine::scale(1.0, k) ))); } } diff --git a/toonz/sources/tnztools/assistants/assistantellipse.h b/toonz/sources/tnztools/assistants/assistantellipse.h index 394ea96..2f181dd 100644 --- a/toonz/sources/tnztools/assistants/assistantellipse.h +++ b/toonz/sources/tnztools/assistants/assistantellipse.h @@ -76,6 +76,7 @@ public: void getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const override; static void drawEllipseRanges( diff --git a/toonz/sources/tnztools/assistants/assistantfisheye.cpp b/toonz/sources/tnztools/assistants/assistantfisheye.cpp index 6ebfe5f..39d00e7 100644 --- a/toonz/sources/tnztools/assistants/assistantfisheye.cpp +++ b/toonz/sources/tnztools/assistants/assistantfisheye.cpp @@ -176,6 +176,7 @@ public: void getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const override { TAffine matrix = calcEllipseMatrix(); @@ -193,6 +194,7 @@ public: new TGuidelineLine( getEnabled(), getMagnetism(), + color, matrix*TPointD(0, 0), matrix*(p/l) ))); } @@ -203,6 +205,7 @@ public: new TGuidelineEllipse( getEnabled(), getMagnetism(), + color, matrix ))); } else { // ellipse scaled by X @@ -211,6 +214,7 @@ public: new TGuidelineEllipse( getEnabled(), getMagnetism(), + color, matrix * TAffine::scale(kx, 1.0) ))); // ellipse scaled by Y @@ -219,6 +223,7 @@ public: new TGuidelineEllipse( getEnabled(), getMagnetism(), + color, matrix * TAffine::scale(1.0, ky) ))); } } diff --git a/toonz/sources/tnztools/assistants/assistantline.cpp b/toonz/sources/tnztools/assistants/assistantline.cpp index f0a00aa..ea013dc 100644 --- a/toonz/sources/tnztools/assistants/assistantline.cpp +++ b/toonz/sources/tnztools/assistants/assistantline.cpp @@ -90,6 +90,7 @@ void TAssistantLine::onMovePoint(TAssistantPoint &point, const TPointD &position void TAssistantLine::getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const { bool restrictA = getRestrictA(); @@ -122,19 +123,19 @@ void TAssistantLine::getGuidelines( if (restrictA && restrictB) outGuidelines.push_back(TGuidelineP( new TGuidelineLine( - getEnabled(), getMagnetism(), a, b ))); + getEnabled(), getMagnetism(), color, a, b ))); else if (restrictA) outGuidelines.push_back(TGuidelineP( new TGuidelineRay( - getEnabled(), getMagnetism(), a, b ))); + getEnabled(), getMagnetism(), color, a, b ))); else if (restrictB) outGuidelines.push_back(TGuidelineP( new TGuidelineRay( - getEnabled(), getMagnetism(), b, a ))); // b first + getEnabled(), getMagnetism(), color, b, a ))); // b first else outGuidelines.push_back(TGuidelineP( new TGuidelineInfiniteLine( - getEnabled(), getMagnetism(), a, b ))); + getEnabled(), getMagnetism(), color, a, b ))); } diff --git a/toonz/sources/tnztools/assistants/assistantline.h b/toonz/sources/tnztools/assistants/assistantline.h index 135ac5f..62957e3 100644 --- a/toonz/sources/tnztools/assistants/assistantline.h +++ b/toonz/sources/tnztools/assistants/assistantline.h @@ -61,6 +61,7 @@ public: void getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const override; static void drawRuler( diff --git a/toonz/sources/tnztools/assistants/assistantperspective.cpp b/toonz/sources/tnztools/assistants/assistantperspective.cpp index 3aabbe3..d908667 100644 --- a/toonz/sources/tnztools/assistants/assistantperspective.cpp +++ b/toonz/sources/tnztools/assistants/assistantperspective.cpp @@ -255,6 +255,7 @@ private: void addGuideline( const TPointD &position, const TAffine &toTool, + const TPixelD &color, const TAssistantPoint &v, TGuidelineList &outGuidelines ) const { @@ -265,6 +266,7 @@ private: new TGuidelineRay( getEnabled(), getMagnetism(), + color, p, position )); } else { @@ -274,6 +276,7 @@ private: new TGuidelineInfiniteLine( getEnabled(), getMagnetism(), + color, position, position + d )); } @@ -350,11 +353,12 @@ public: void getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const override { - addGuideline(position, toTool, m_vx, outGuidelines); - addGuideline(position, toTool, m_vy, outGuidelines); - addGuideline(position, toTool, m_vz, outGuidelines); + addGuideline(position, toTool, color, m_vx, outGuidelines); + addGuideline(position, toTool, color, m_vy, outGuidelines); + addGuideline(position, toTool, color, m_vz, outGuidelines); } void drawGrid( diff --git a/toonz/sources/tnztools/assistants/assistantvanishingpoint.cpp b/toonz/sources/tnztools/assistants/assistantvanishingpoint.cpp index 23e8aa3..13f05b0 100644 --- a/toonz/sources/tnztools/assistants/assistantvanishingpoint.cpp +++ b/toonz/sources/tnztools/assistants/assistantvanishingpoint.cpp @@ -149,6 +149,7 @@ void TAssistantVanishingPoint::onMovePoint(TAssistantPoint &point, const TPointD void TAssistantVanishingPoint::getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const { if (getPassThrough()) { @@ -156,6 +157,7 @@ void TAssistantVanishingPoint::getGuidelines( new TGuidelineInfiniteLine( getEnabled(), getMagnetism(), + color, toTool * m_center.position, position ))); } else { @@ -163,6 +165,7 @@ void TAssistantVanishingPoint::getGuidelines( new TGuidelineRay( getEnabled(), getMagnetism(), + color, toTool * m_center.position, position ))); } diff --git a/toonz/sources/tnztools/assistants/assistantvanishingpoint.h b/toonz/sources/tnztools/assistants/assistantvanishingpoint.h index b7b276c..e363262 100644 --- a/toonz/sources/tnztools/assistants/assistantvanishingpoint.h +++ b/toonz/sources/tnztools/assistants/assistantvanishingpoint.h @@ -61,6 +61,7 @@ public: void getGuidelines( const TPointD &position, const TAffine &toTool, + const TPixelD &color, TGuidelineList &outGuidelines ) const override; static void drawSimpleGrid( diff --git a/toonz/sources/tnztools/assistants/guidelineellipse.cpp b/toonz/sources/tnztools/assistants/guidelineellipse.cpp index c18934f..a63bbc3 100644 --- a/toonz/sources/tnztools/assistants/guidelineellipse.cpp +++ b/toonz/sources/tnztools/assistants/guidelineellipse.cpp @@ -75,12 +75,13 @@ static TPointD findNearestPoint(const TPointD &p, double Rx, double Ry) { TGuidelineEllipse::TGuidelineEllipse( bool enabled, double magnetism, + const TPixelD &color, const TAffine &matrix, const TAffine &matrixInv, double Rx, double Ry ): - TGuideline(enabled, magnetism), + TGuideline(enabled, magnetism, color), matrix(matrix), matrixInv(matrixInv), Rx(Rx), @@ -91,11 +92,12 @@ TGuidelineEllipse::TGuidelineEllipse( TGuidelineEllipse::TGuidelineEllipse( bool enabled, double magnetism, + const TPixelD &color, const TAffine &matrix, const TAffine &matrixInv ): TGuidelineEllipse( - enabled, magnetism, matrix, matrixInv, + enabled, magnetism, color, matrix, matrixInv, sqrt(matrix.a11*matrix.a11 + matrix.a21*matrix.a21), sqrt(matrix.a12*matrix.a12 + matrix.a22*matrix.a22) ) { } @@ -104,9 +106,10 @@ TGuidelineEllipse::TGuidelineEllipse( TGuidelineEllipse::TGuidelineEllipse( bool enabled, double magnetism, + const TPixelD &color, const TAffine &matrix ): - TGuidelineEllipse(enabled, magnetism, matrix, matrix.inv()) + TGuidelineEllipse(enabled, magnetism, color, matrix, matrix.inv()) { } diff --git a/toonz/sources/tnztools/assistants/guidelineline.cpp b/toonz/sources/tnztools/assistants/guidelineline.cpp index cc8707a..91fdd14 100644 --- a/toonz/sources/tnztools/assistants/guidelineline.cpp +++ b/toonz/sources/tnztools/assistants/guidelineline.cpp @@ -10,8 +10,11 @@ // TGuidelineLineBase implementation //***************************************************************************************** -TGuidelineLineBase::TGuidelineLineBase(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1): - TGuideline(enabled, magnetism), p0(p0), p1(p1) { } +TGuidelineLineBase::TGuidelineLineBase( + bool enabled, double magnetism, const TPixelD &color, + const TPointD &p0, const TPointD &p1 +): + TGuideline(enabled, magnetism, color), p0(p0), p1(p1) { } TPointD TGuidelineLineBase::calcDirection(const TPointD &p0, const TPointD &p1) { @@ -124,8 +127,10 @@ TGuidelineLineBase::drawLine(const TPointD &p0, const TPointD &p1, bool restrict // TGuidelineLine implementation //***************************************************************************************** -TGuidelineLine::TGuidelineLine(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1): - TGuidelineLineBase(enabled, magnetism, p0, p1), +TGuidelineLine::TGuidelineLine( + bool enabled, double magnetism, const TPixelD &color, const TPointD &p0, const TPointD &p1 +): + TGuidelineLineBase(enabled, magnetism, color, p0, p1), dir(calcDirection(p0, p1)), dist(norm(p1 - p0)) { } @@ -145,8 +150,10 @@ TGuidelineLine::draw(bool active, bool enabled) const // TGuidelineInfiniteLine implementation //***************************************************************************************** -TGuidelineInfiniteLine::TGuidelineInfiniteLine(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1): - TGuidelineLineBase(enabled, magnetism, p0, p1), +TGuidelineInfiniteLine::TGuidelineInfiniteLine( + bool enabled, double magnetism, const TPixelD &color, const TPointD &p0, const TPointD &p1 +): + TGuidelineLineBase(enabled, magnetism, color, p0, p1), dir(calcDirection(p0, p1)) { } TTrackPoint @@ -165,8 +172,10 @@ TGuidelineInfiniteLine::draw(bool active, bool enabled) const // TGuidelineRay implementation //***************************************************************************************** -TGuidelineRay::TGuidelineRay(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1): - TGuidelineLineBase(enabled, magnetism, p0, p1), +TGuidelineRay::TGuidelineRay( + bool enabled, double magnetism, const TPixelD &color, const TPointD &p0, const TPointD &p1 +): + TGuidelineLineBase(enabled, magnetism, color, p0, p1), dir(calcDirection(p0, p1)) { } TTrackPoint diff --git a/toonz/sources/tnztools/editassistantstool.cpp b/toonz/sources/tnztools/editassistantstool.cpp index 67cd997..b8d2b29 100644 --- a/toonz/sources/tnztools/editassistantstool.cpp +++ b/toonz/sources/tnztools/editassistantstool.cpp @@ -12,13 +12,18 @@ #include #include #include +#include +#include #include #include +#include +#include // TnzCore includes #include #include #include +#include #include #include @@ -778,27 +783,49 @@ public: void draw() override { m_currentGuidelines.clear(); TPointD position = m_currentPosition + m_currentPointOffset; - + + // get current column color + TPixelD color = TAssistantBase::colorBase; + if (TApplication *app = getApplication()) + if (TXsheetHandle *XsheetHandle = app->getCurrentXsheet()) + if (TXsheet *Xsheet = XsheetHandle->getXsheet()) + if (TColumnHandle *columnHandle = app->getCurrentColumn()) + if (TXshColumn *column = Xsheet->getColumn( columnHandle->getColumnIndex() )) + { + if (int filterId = column->getColorFilterId()) + if (TSceneHandle *sceneHandle = app->getCurrentScene()) + if (ToonzScene *scene = sceneHandle->getScene()) + if (TSceneProperties *props = scene->getProperties()) + color = toPixelD(props->getColorFilterColor( filterId )); + color.m *= column->getOpacity()/255.0; + } + // 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()) - { - if (dynamic_cast(base)) { - ++index; - base->drawEdit(getViewer(), index); - } else { - base->drawEdit(getViewer()); + if (Closer closer = read(ModeImage)) { + TPixelD origColor = TAssistantBase::colorBase; + TAssistantBase::colorBase = color; + for(TMetaObjectListCW::iterator i = (*m_reader)->begin(); i != (*m_reader)->end(); ++i) { + if (*i) + if (const TAssistantBase *base = (*i)->getHandler()) + { + if (dynamic_cast(base)) { + ++index; + base->drawEdit(getViewer(), index); + } else { + base->drawEdit(getViewer()); + } + + if (const TAssistant *assistant = dynamic_cast(base)) + assistant->getGuidelines( + position, + TAffine(), + color, + m_currentGuidelines ); } - - if (const TAssistant *assistant = dynamic_cast(base)) - assistant->getGuidelines( - position, - TAffine(), - m_currentGuidelines ); } + TAssistantBase::colorBase = origColor; + } TImage *img = getImage(false); diff --git a/toonz/sources/tnztools/replicator.cpp b/toonz/sources/tnztools/replicator.cpp index b7c9d27..94c16aa 100644 --- a/toonz/sources/tnztools/replicator.cpp +++ b/toonz/sources/tnztools/replicator.cpp @@ -10,8 +10,11 @@ #include #include #include +#include +#include #include +#include @@ -86,8 +89,9 @@ TReplicator::transformPoints(const TAffine &aff, PointList &points, int i0, int void TReplicator::drawReplicatorPoints(const TPointD *points, int count) { - double colorBlack[4] = { 0.0, 0.0, 0.0, 0.3 }; - double colorWhite[4] = { 1.0, 1.0, 1.0, 0.3 }; + TPixelD color = (drawFlags & DRAW_ERROR) ? colorError : colorBase; + color.m *= 0.3; + TPixelD colorBack = makeContrastColor(color); glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableBlending(); @@ -99,10 +103,10 @@ TReplicator::drawReplicatorPoints(const TPointD *points, int count) { for(int i = 0; i < count; ++i) { const TPointD &p = points[i]; - glColor4dv(colorWhite); + tglColor(colorBack); tglDrawSegment(p - a - da, p + a - da); tglDrawSegment(p - b - db, p + b - db); - glColor4dv(colorBlack); + tglColor(color); tglDrawSegment(p - a + da, p + a + da); tglDrawSegment(p - b + db, p + b + db); } @@ -137,6 +141,8 @@ TReplicator::scanReplicators( if (TXsheetHandle *XsheetHandle = application->getCurrentXsheet()) if (TXsheet *Xsheet = XsheetHandle->getXsheet()) { + ToonzScene *scene = Xsheet->getScene(); + TSceneProperties *props = scene ? scene->getProperties() : nullptr; TPointD dpiScale = getCurrentDpiScale(simpleLevel, tool->getCurrentFid()); int frame = frameHandle->getFrame(); int count = Xsheet->getColumnCount(); @@ -148,7 +154,7 @@ TReplicator::scanReplicators( worldToTrack.a22 /= dpiScale.y; } - for(int i = 0; i < count; ++i) + for(int i = 0; i < count; ++i) { if (TXshColumn *column = Xsheet->getColumn(i)) if (column->isCamstandVisible()) if (column->isPreviewVisible()) @@ -157,11 +163,18 @@ TReplicator::scanReplicators( if (image->getType() == TImage::META) if (TMetaImage *metaImage = dynamic_cast(image.getPointer())) { + TPixelD origColor = TAssistantBase::colorBase; TAffine imageToTrack = worldToTrack * tool->getColumnMatrix(i); - if (draw) { glPushMatrix(); tglMultMatrix(imageToTrack); } + if (draw) { + if (props) + TAssistantBase::colorBase = toPixelD(props->getColorFilterColor( column->getColorFilterId() )); + TAssistantBase::colorBase.m *= column->getOpacity()/255.0; + glPushMatrix(); + tglMultMatrix(imageToTrack); + } TMetaImage::Reader reader(*metaImage); - for(TMetaObjectListCW::iterator i = reader->begin(); i != reader->end(); ++i) + for(TMetaObjectListCW::iterator i = reader->begin(); i != reader->end(); ++i) { if (*i) if (const TReplicator *replicator = (*i)->getHandler()) if (!enabledOnly || replicator->getEnabled()) @@ -190,9 +203,14 @@ TReplicator::scanReplicators( TReplicator::drawFlags = oldFlags; } } - - if (draw) glPopMatrix(); + } // for each meta object + + if (draw) { + glPopMatrix(); + TAssistantBase::colorBase = origColor; + } } + } // for each column }