Skip to content

Commit

Permalink
Merge pull request #5069 from blackwarthog/feature08h_assistants_sqash
Browse files Browse the repository at this point in the history
Brush strokes replication feature
  • Loading branch information
RodneyBaker authored Sep 14, 2023
2 parents eddf03f + da847a9 commit 40e62cf
Show file tree
Hide file tree
Showing 37 changed files with 2,599 additions and 130 deletions.
6 changes: 4 additions & 2 deletions toonz/sources/include/tmetaimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ class DVAPI TMetaObjectHandler {
virtual void onFixData() { }

public:
void setDefaults()
{ onSetDefaults(); }
void setDefaults() {
{ LockEvents lock(*this); onSetDefaults(); }
data().touch();
}
void dataChanged(const TVariant &value)
{ if (m_locks == 0) onDataChanged(value); }
void fixData()
Expand Down
63 changes: 49 additions & 14 deletions toonz/sources/include/tools/assistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TPropertyGroup;
class TTool;
class TToolViewer;
class TAssistant;
class TAssistantBase;
class TAssistantPoint;
class TGuideline;

Expand Down Expand Up @@ -134,7 +135,7 @@ class DVAPI TAssistantType: public TMetaObjectType {
TAssistantType(const TStringId &name):
TMetaObjectType(name) { }
TMetaObjectHandler* createHandler(TMetaObject &obj) const override;
virtual TAssistant* createAssistant(TMetaObject &obj) const
virtual TAssistantBase* createAssistant(TMetaObject &obj) const
{ return 0; }
};

Expand Down Expand Up @@ -182,7 +183,7 @@ class TAssistantTypeT: public TAssistantType {
if (!alias5.empty()) registerAlias(TStringId(alias5));
}

TAssistant* createAssistant(TMetaObject &obj) const override
TAssistantBase* createAssistant(TMetaObject &obj) const override
{ return new Type(obj); }
QString getLocalName() const override {
QString localName = Type::getLocalName();
Expand All @@ -192,11 +193,19 @@ class TAssistantTypeT: public TAssistantType {


//*****************************************************************************************
// TAssistant definition
// TAssistantBase definition
//*****************************************************************************************

class DVAPI TAssistant : public TMetaObjectHandler {
Q_DECLARE_TR_FUNCTIONS(TAssistant)
class DVAPI TAssistantBase : public TMetaObjectHandler {
Q_DECLARE_TR_FUNCTIONS(TAssistantBase)
public:
enum {
DRAW_ERROR = 1,
};

static unsigned int drawFlags;
static const double lineWidthScale;

protected:
const TStringId m_idEnabled;
const TStringId m_idPoints;
Expand All @@ -211,7 +220,7 @@ class DVAPI TAssistant : public TMetaObjectHandler {
mutable TPropertyGroup m_properties;

public:
TAssistant(TMetaObject &object);
TAssistantBase(TMetaObject &object);

static QString getLocalName()
{ return QString(); }
Expand All @@ -237,19 +246,14 @@ class DVAPI TAssistant : public TMetaObjectHandler {
void setEnabled(bool x)
{ if (getEnabled() != x) data()[m_idEnabled].setBool(x); }

double getMagnetism() const
{ return data()[m_idMagnetism].getDouble(); }
void setMagnetism(double x)
{ if (getMagnetism() != x) data()[m_idMagnetism].setDouble(x); }

inline void selectPoint(const TStringId &name) const
{ setPointSelection(name, true); }
inline void deselectPoint(const TStringId &name) const
{ setPointSelection(name, false); }
inline void selectAll() const
{ setAllPointsSelection(true); }
inline void deselectAll() const
{ setAllPointsSelection(false); }
{ setAllPointsSelection(false); }

TPropertyGroup& getProperties() const
{ return m_properties; }
Expand Down Expand Up @@ -300,7 +304,7 @@ class DVAPI TAssistant : public TMetaObjectHandler {
//! try to move point
virtual void onMovePoint(TAssistantPoint &point, const TPointD &position);
//! save object data to variant
virtual void onFixData();
void onFixData() override;
//! load all properties from variant
virtual void updateProperties();
//! load single property from variant
Expand All @@ -315,21 +319,52 @@ class DVAPI TAssistant : public TMetaObjectHandler {
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()); }
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 getGuidelines(const TPointD &position, const TAffine &toTool, TGuidelineList &outGuidelines) const;
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;
};


//*****************************************************************************************
// TAssistant definition
//*****************************************************************************************

class DVAPI TAssistant : public TAssistantBase {
Q_DECLARE_TR_FUNCTIONS(TAssistant)
protected:
const TStringId m_idMagnetism;

void onSetDefaults() override;
void onFixData() override;

public:
TAssistant(TMetaObject &object);

double getMagnetism() const
{ return data()[m_idMagnetism].getDouble(); }
void setMagnetism(double x)
{ if (getMagnetism() != x) data()[m_idMagnetism].setDouble(x); }

public:
void updateTranslation() const override;
virtual void getGuidelines(const TPointD &position, const TAffine &toTool, TGuidelineList &outGuidelines) const;

static bool calcPerspectiveStep(
double minStep,
Expand Down
4 changes: 4 additions & 0 deletions toonz/sources/include/tools/inputmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ class DVAPI TInputManager {
void insertModifier(int index, const TInputModifierP &modifier);
void addModifier(const TInputModifierP &modifier)
{ insertModifier(getModifiersCount(), modifier); }
void addModifiers(const TInputModifier::List &modifiers) {
for(TInputModifier::List::const_iterator i = modifiers.begin(); i != modifiers.end(); ++i)
addModifier(*i);
}
void removeModifier(int index);
void removeModifier(const TInputModifierP &modifier)
{ removeModifier(findModifier(modifier)); }
Expand Down
55 changes: 55 additions & 0 deletions toonz/sources/include/tools/modifiers/modifierclone.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#ifndef MODIFIERCLONE_INCLUDED
#define MODIFIERCLONE_INCLUDED

// TnzTools includes
#include <tools/inputmanager.h>

#undef DVAPI
#undef DVVAR
#ifdef TNZTOOLS_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif

//===================================================================

//*****************************************************************************************
// TModifierClone definition
//*****************************************************************************************

class DVAPI TModifierClone : public TInputModifier {
public:
class DVAPI Handler : public TMultiTrackHandler {
public:
TTrackP original;
inline explicit Handler(const TTrackP &original = TTrackP()):
original(original) { }
};

class DVAPI Interpolator : public TTrackInterpolator {
public:
const TTrackTransform transform;
inline Interpolator(TTrack &track, const TTrackTransform &transform):
TTrackInterpolator(track), transform(transform) { }
TTrackPoint interpolateFromOriginal(double originalIndex);
TTrackPoint interpolate(double index) override;
};


public:
bool keepOriginals;
TTrackTransformList transforms;

TModifierClone(bool keepOriginals = true);

void modifyTrack(
const TTrack &track,
TTrackList &outTracks ) override;
};

#endif
61 changes: 61 additions & 0 deletions toonz/sources/include/tools/modifiers/modifierjitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#ifndef MODIFIERJITTER_INCLUDED
#define MODIFIERJITTER_INCLUDED

// TnzTools includes
#include <tools/inputmanager.h>

#undef DVAPI
#undef DVVAR
#ifdef TNZTOOLS_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif

//===================================================================

//*****************************************************************************************
// TModifierJitter definition
//*****************************************************************************************

class DVAPI TModifierJitter : public TInputModifier {
public:
typedef TSubTrackHandler Handler;

class DVAPI Interpolator : public TTrackInterpolator {
public:
const unsigned int seedX;
const unsigned int seedY;
const double frequency;
const double amplitude;
Interpolator(TTrack &track, double period, double amplitude);
TTrackPoint interpolateFromOriginal(double originalIndex);
TTrackPoint interpolate(double index) override;
};

public:
double period;
double amplitude;
int skipFirst;

TModifierJitter(
double period = 30,
double amplitude = 10,
int skipFirst = 0 );

void modifyTrack(
const TTrack &track,
TTrackList &outTracks ) override;

void modifyTracks(
const TTrackList &tracks,
TTrackList &outTracks ) override;

static double func(unsigned int seed, double x);
};

#endif
58 changes: 58 additions & 0 deletions toonz/sources/include/tools/replicator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

#ifndef REPLICATOR_INCLUDED
#define REPLICATOR_INCLUDED

// TnzTools includes
#include <tools/assistant.h>
#include <tools/inputmanager.h>

#undef DVAPI
#undef DVVAR
#ifdef TNZTOOLS_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif


//*****************************************************************************************
// TReplicator definition
//*****************************************************************************************

class DVAPI TReplicator : public TAssistantBase {
Q_DECLARE_TR_FUNCTIONS(TReplicator)
public:
typedef std::vector<TPointD> PointList;

static const int multiplierSoftLimit;
static const int multiplierLimit;

TReplicator(TMetaObject &object);

virtual int getMultipler() const;
virtual void getPoints(const TAffine &toTool, PointList &points) const;
virtual void getModifiers(const TAffine &toTool, TInputModifier::List &outModifiers) const;

static void transformPoints(const TAffine &aff, PointList &points, int count);
static void drawReplicatorPoints(const TPointD *points, int count);

//! return summary multiplier, or 0 is no replicators found
static int scanReplicators(
TTool *tool,
PointList *inOutPoints,
TInputModifier::List *outModifiers,
bool draw,
bool enabledOnly,
bool markEnabled,
bool drawPoints,
TImage *skipImage );

protected:
TIntProperty* createCountProperty(const TStringId &id, int def = 1, int min = 1, int max = 0);
};


#endif
15 changes: 10 additions & 5 deletions toonz/sources/include/tools/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,19 @@ class DVAPI TTool {
};

enum ToolHints //! Misc flags related with tool
{ HintNone = 0,
HintAssistants = 1 << 0, //!< Draw asistants when tool active
HintGuidelines = 1 << 1, //!< Draw asistant guidelines
HintAssistantsEnabled = 1 << 2, //!< Tool will use assisnats
{ HintNone = 0,
HintAssistants = 1 << 0, //!< Draw asistants when tool active
HintAssistantsGuidelines = 1 << 1, //!< Draw asistant guidelines
HintAssistantsEnabled = 1 << 2, //!< Mark active assistants
HintReplicators = 1 << 3, //!< Draw replicators
HintReplicatorsPoints = 1 << 4, //!< Draw replicated points
HintReplicatorsEnabled = 1 << 5, //!< Mark active replicators

HintAssistantsAll = HintAssistants
| HintGuidelines
| HintAssistantsGuidelines
| HintAssistantsEnabled,
HintReplicatorsAll = HintReplicators
| HintReplicatorsEnabled,
};

public:
Expand Down
Loading

0 comments on commit 40e62cf

Please sign in to comment.