Skip to content

Commit

Permalink
Merge pull request #5066 from blackwarthog/feature08g_assistants_sqash
Browse files Browse the repository at this point in the history
Assistants for Toonz Vector brushes
  • Loading branch information
RodneyBaker authored Sep 9, 2023
2 parents 2d0ea75 + fa009d0 commit 858030b
Show file tree
Hide file tree
Showing 36 changed files with 1,523 additions and 1,446 deletions.
14 changes: 12 additions & 2 deletions toonz/sources/include/tgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ inline TPointD normalize(const TPointD &p) {
return (1.0 / n) * p;
}

/*!
\relates TPointT
This helper function returns the normalized version of the specified point
or zero if it is not possible
*/
inline TPointD normalizeOrZero(const TPointD &p) {
double n = norm2(p);
return fabs(n) > TConsts::epsilon*TConsts::epsilon ? p*(1/sqrt(n)) : TPointD();
}

/*!
\relates TPointT
This helper function converts a TPoint (TPointT<int>) into a TPointD
Expand Down Expand Up @@ -1426,9 +1436,9 @@ class DVAPI TAngleRangeSet {
inline Range range() const
{ return Range(a0(), a1()); }
inline int size() const
{ return (m_end - m_begin)/2 + 1; }
{ return (int)(m_end - m_begin)/2 + 1; }
inline int index() const
{ return (m_current - m_begin)/2; }
{ return (int)(m_current - m_begin)/2; }
inline int reverseIndex() const
{ int i = index(); return i == 0 ? 0 : size() - i; }
inline bool lapped() const
Expand Down
12 changes: 12 additions & 0 deletions toonz/sources/include/tools/assistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
class TProperty;
class TPropertyGroup;

class TTool;
class TToolViewer;
class TAssistant;
class TAssistantPoint;
Expand Down Expand Up @@ -340,6 +341,17 @@ class DVAPI TAssistant : public TMetaObjectHandler {
double &outK,
double &outMin,
double &outMax );

static bool scanAssistants(
TTool *tool,
const TPointD *positions,
int positionsCount,
TGuidelineList *outGuidelines,
bool draw,
bool enabledOnly,
bool markEnabled,
bool drawGuidelines,
TImage *skipImage );
};


Expand Down
6 changes: 4 additions & 2 deletions toonz/sources/include/tools/inputmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ class DVAPI TInputManager {
TInputState::DeviceId deviceId,
TInputState::TouchId touchId,
const TPointD &position,
const double *pressure,
const TPointD *tilt,
const double pressure,
const TPointD &tilt,
bool hasPressure,
bool hasTilt,
bool final,
TTimerTicks ticks );
bool keyEvent(
Expand Down
20 changes: 12 additions & 8 deletions toonz/sources/include/tools/modifiers/modifierassistants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

class DVAPI TModifierAssistants: public TInputModifier {
public:
class DVAPI Modifier: public TTrackModifier {
typedef TSubTrackHandler Handler;
class DVAPI Interpolator: public TTrackInterpolator {
public:
bool initialized;
const double magnetism;
TGuidelineList guidelines;

Modifier(TTrackHandler &handler);
TTrackPoint calcPoint(double originalIndex) override;
inline Interpolator(TTrack &track, double magnetism):
TTrackInterpolator(track),
magnetism(magnetism > 0 ? (magnetism < 1 ? magnetism : 1) : 0)
{ }
TTrackPoint interpolate(double index) override;
};

private:
Expand All @@ -41,13 +44,14 @@ class DVAPI TModifierAssistants: public TInputModifier {
int positionsCount,
TGuidelineList *outGuidelines,
bool draw,
bool enabledOnly ) const;
bool enabledOnly,
bool drawGuidelines ) const;

public:
bool drawOnly;
double magnetism;
double sensitiveLength;

explicit TModifierAssistants(bool drawOnly = false);
explicit TModifierAssistants(double magnetism = 1);

void modifyTrack(
const TTrack &track,
Expand Down
11 changes: 3 additions & 8 deletions toonz/sources/include/tools/modifiers/modifierline.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@
// TModifierLine definition
//*****************************************************************************************

class TModifierLine: public TInputModifier {
class DVAPI TModifierLine: public TInputModifier {
public:
class Modifier: public TTrackModifier {
class DVAPI Handler: public TSubTrackHandler {
public:
explicit Modifier(TTrackHandler &handler):
TTrackModifier(handler), fixAngle(), maxPressure() { }

bool fixAngle;
double maxPressure;

TTrackPoint calcPoint(double originalIndex) override;
inline Handler(): maxPressure() { }
};

void modifyTrack(
Expand Down
6 changes: 5 additions & 1 deletion toonz/sources/include/tools/modifiers/modifiersegmentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
//*****************************************************************************************

class DVAPI TModifierSegmentation: public TInputModifier {
public:
typedef TSubTrackHandler Handler;
typedef TTrackIntrOrig Interpolator;

private:
TPointD m_step;
int m_maxLevel;

void addSegments(TTrack &track, const TTrackPoint &p0, const TTrackPoint &p1, int maxLevel);

public:
TModifierSegmentation(const TPointD &step = TPointD(1.0, 1.0), int level = 10);
explicit TModifierSegmentation(const TPointD &step = TPointD(1.0, 1.0), int level = 10);

void setStep(const TPointD &step);
inline const TPointD& getStep() const { return m_step; }
Expand Down
42 changes: 42 additions & 0 deletions toonz/sources/include/tools/modifiers/modifiersimplify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#ifndef MODIFIERSIMPLIFY_INCLUDED
#define MODIFIERSIMPLIFY_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


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

//*****************************************************************************************
// TModifierSimplify definition
//*****************************************************************************************

class DVAPI TModifierSimplify: public TInputModifier {
public:
typedef TSubTrackHandler Handler;
typedef TTrackIntrOrig Interpolator;

double step;

explicit TModifierSimplify(double step = 1.0);

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


#endif
16 changes: 4 additions & 12 deletions toonz/sources/include/tools/modifiers/modifiersmooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,15 @@

class DVAPI TModifierSmooth: public TInputModifier {
public:
class DVAPI Modifier: public TTrackModifier {
class DVAPI Handler: public TSubTrackHandler {
public:
const int radius;
TTrack *smoothedTrack;

Modifier(TTrackHandler &handler, int radius);
TTrackPoint calcPoint(double originalIndex) override;
inline explicit Handler(int radius): radius(radius) { }
};

private:
int m_radius;

public:
TModifierSmooth(int radius = 10);
int radius;

void setRadius(int radius);
int getRadius() const { return m_radius; }
explicit TModifierSmooth(int radius = 10);

void modifyTrack(
const TTrack &track,
Expand Down
12 changes: 5 additions & 7 deletions toonz/sources/include/tools/modifiers/modifiertangents.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@

class DVAPI TModifierTangents: public TInputModifier {
public:
class DVAPI Modifier: public TTrackModifier {
typedef TSubTrackHandler Handler;
class DVAPI Interpolator: public TTrackInterpolator {
public:
explicit Modifier(TTrackHandler &handler):
TTrackModifier(handler) { }

TTrackTangentList tangents;

TTrackPoint calcPoint(double originalIndex) override;
using TTrackInterpolator::TTrackInterpolator;
TTrackPoint interpolate(double index) override;
};

TTrackTangent calcTangent(const TTrack &track, int index) const;
static TTrackTangent calcTangent(const TTrack &track, int index);

void modifyTrack(
const TTrack &track,
Expand Down
29 changes: 16 additions & 13 deletions toonz/sources/include/tools/modifiers/modifiertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,31 @@

class DVAPI TModifierTest : public TInputModifier {
public:
class DVAPI Handler : public TTrackHandler {
class DVAPI Handler : public TMultiTrackHandler {
public:
const double radius;
std::vector<double> angles;
Handler(const TTrack &original) : TTrackHandler(original) {}
inline explicit Handler(double radius):
radius(std::max(TConsts::epsilon, radius)) { }
};

class DVAPI Modifier : public TTrackModifier {
class DVAPI Interpolator : public TTrackInterpolator {
public:
double angle;
double radius;
double speed;

Modifier(TTrackHandler &handler, double angle, double radius,
double speed = 0.25);
TTrackPoint calcPoint(double originalIndex) override;
const double angle;
const double radius;
const double speed;
inline Interpolator(TTrack &track, double angle, double radius, double speed):
TTrackInterpolator(track), angle(angle), radius(radius), speed(speed) { }
TTrackPoint interpolateFromOriginal(double originalIndex);
TTrackPoint interpolate(double index) override;
};

public:
const int count;
const double radius;
int count;
double radius;
double speed;

TModifierTest(int count, double radius);
TModifierTest(int count = 3, double radius = 40, double speed = 0.25);

void modifyTrack(const TTrack &track,
TTrackList &outTracks) override;
Expand Down
12 changes: 12 additions & 0 deletions toonz/sources/include/tools/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ class DVAPI TTool {
AllTargets = 0xffffffff,
};

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

HintAssistantsAll = HintAssistants
| HintGuidelines
| HintAssistantsEnabled,
};

public:
static TTool *getTool(std::string toolName, ToolTargetType targetType);

Expand Down Expand Up @@ -346,6 +357,7 @@ least

virtual ToolType getToolType() const = 0;
ToolTargetType getTargetType() const { return (ToolTargetType)m_targetType; }
virtual unsigned int getToolHints() const;

std::string getName() const { return m_name; }

Expand Down
Loading

0 comments on commit 858030b

Please sign in to comment.