tahoma2d/toonz/sources/tnztools/skeletonsubtools.h

249 lines
5.9 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef SKELETON_SUBTOOLS_INCLUDED
#define SKELETON_SUBTOOLS_INCLUDED
#include "tools/tool.h"
#include "toonz/txsheet.h"
#include "toonz/skeleton.h"
#include "toonz/stageobjectutil.h"
#include "toonz/ikengine.h"
#include <QObject>
class SkeletonTool;
2016-06-15 18:43:10 +12:00
namespace SkeletonSubtools {
2016-03-19 06:57:51 +13:00
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DragTool {
SkeletonTool *m_tool;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
DragTool(SkeletonTool *tool) : m_tool(tool) {}
virtual ~DragTool() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void draw() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &) = 0;
virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) = 0;
virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &) = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
SkeletonTool *getTool() const { return m_tool; }
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DragCenterTool : public DragTool {
TStageObjectId m_objId;
int m_frame;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPointD m_firstPos;
TPointD m_oldCenter;
TPointD m_center;
TAffine m_affine;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
DragCenterTool(SkeletonTool *tool);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TPointD &pos, const TMouseEvent &);
void leftButtonDrag(const TPointD &pos, const TMouseEvent &);
void leftButtonUp(const TPointD &pos, const TMouseEvent &);
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DragChannelTool : public DragTool {
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
TStageObjectValues m_before, m_after;
bool m_dragged;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
DragChannelTool(SkeletonTool *tool, TStageObject::Channel a0);
DragChannelTool(SkeletonTool *tool, TStageObject::Channel a0,
TStageObject::Channel a1);
void start();
TPointD getCenter();
double getOldValue(int index) const { return m_before.getValue(index); }
double getValue(int index) const { return m_after.getValue(index); }
void setValue(double v) {
m_after.setValue(v);
m_after.applyValues();
}
void setValues(double v0, double v1) {
m_after.setValues(v0, v1);
m_after.applyValues();
}
void leftButtonUp(const TPointD &pos, const TMouseEvent &);
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DragPositionTool : public DragChannelTool {
TPointD m_firstPos;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
DragPositionTool(SkeletonTool *tool);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TPointD &pos, const TMouseEvent &);
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DragRotationTool : public DragChannelTool {
TPointD m_lastPos;
TPointD m_center;
bool m_snapped;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
DragRotationTool(SkeletonTool *tool, bool snapped);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TPointD &pos, const TMouseEvent &);
void leftButtonDrag(const TPointD &pos, const TMouseEvent &);
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class ParentChangeTool : public DragTool {
TTool::Viewer *m_viewer;
TPoint m_firstWinPos;
TPointD m_lastPos, m_lastPos2;
TPointD m_center;
int m_index;
int m_handle;
bool m_snapped;
int m_mode;
TAffine m_affine;
TStageObjectId m_objId;
TPointD m_oldCenter, m_oldOffset;
struct Peer {
TPointD m_pos;
int m_columnIndex;
int m_handle; // 0=centerB,-1,-2,....=H1,H2...
int m_name; // per glPushName()
};
struct Element {
int m_columnIndex;
TRectD m_bbox;
TAffine m_aff;
std::vector<Peer> m_peers;
};
std::map<int, Element> m_elements;
double m_pixelSize;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ParentChangeTool(SkeletonTool *tool, TTool::Viewer *viewer);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TPointD &pos, const TMouseEvent &e);
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
void leftButtonUp(const TPointD &pos, const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw();
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
class IKToolUndo;
2016-06-15 18:43:10 +12:00
class IKTool : public DragTool {
TTool::Viewer *m_viewer;
TPointD m_pos;
Skeleton *m_skeleton;
int m_columnIndex;
IKEngine m_engine;
bool m_valid;
TAffine m_footPlacement, m_firstFootPlacement;
TStageObject *m_foot, *m_firstFoot;
bool m_IHateIK;
IKToolUndo *m_undo;
struct Joint {
Skeleton::Bone *m_bone, *m_prevBone;
int m_prevColumnIndex;
double m_angleOffset;
double m_sign;
bool m_active;
TStageObjectValues m_oldValues;
Joint()
: m_bone(0)
, m_prevBone(0)
, m_angleOffset(0)
, m_sign(1)
, m_active(true) {}
Joint(Skeleton::Bone *bone, Skeleton::Bone *prevBone, double sign)
: m_bone(bone)
, m_prevBone(prevBone)
, m_angleOffset(0)
, m_sign(sign)
, m_active(true) {}
};
std::vector<Joint> m_joints;
bool isParentOf(int columnIndex, int childColumnIndex) const;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
IKTool(SkeletonTool *tool, TTool::Viewer *viewer, Skeleton *skeleton,
int columnIndex);
~IKTool();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void initEngine(const TPointD &pos);
void storeOldValues();
void computeIHateIK();
void setAngleOffsets();
void apply();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TPointD &, const TMouseEvent &e);
void leftButtonDrag(const TPointD &, const TMouseEvent &e);
void leftButtonUp(const TPointD &, const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void draw();
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class ChangeDrawingTool : public DragTool {
int m_oldY;
int m_dir;
TUndo *m_undo;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ChangeDrawingTool(SkeletonTool *tool, int d);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TPointD &, const TMouseEvent &e);
void leftButtonDrag(const TPointD &, const TMouseEvent &e);
void leftButtonUp(const TPointD &, const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool changeDrawing(int delta);
2016-03-19 06:57:51 +13:00
};
//---------------------------------------------------------
2016-06-15 18:43:10 +12:00
class CommandHandler : public QObject {
Q_OBJECT
Skeleton *m_skeleton;
std::set<int> *m_tempPinnedSet;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
CommandHandler();
~CommandHandler();
void setTempPinnedSet(std::set<int> *tempPinnedSet) {
m_tempPinnedSet = tempPinnedSet;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setSkeleton(Skeleton *skeleton);
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
void clearPinnedRanges();
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
} // namespace SkeletonSubtools
2016-03-19 06:57:51 +13:00
#endif