| #pragma once |
| |
| #ifndef TOOL_INCLUDED |
| #define TOOL_INCLUDED |
| |
| |
| #include "toonz/tstageobjectid.h" |
| #include "toonz/txsheet.h" |
| #include "toonz/imagepainter.h" |
| #include "toonz/tapplication.h" |
| #include "tools/cursors.h" |
| |
| |
| #include "tcommon.h" |
| #include "tgeometry.h" |
| #include "tfilepath.h" |
| |
| |
| #include <QString> |
| #include <QPoint> |
| |
| #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 |
| |
| |
| |
| |
| |
| class TToolParam; |
| class TMouseEvent; |
| class TStroke; |
| class TImage; |
| class TPropertyGroup; |
| class TColorStyle; |
| class TFrameId; |
| class TPalette; |
| class TSelection; |
| |
| class TFrameHandle; |
| class TXshLevelHandle; |
| class TXsheetHandle; |
| class TObjectHandle; |
| class TColumnHandle; |
| class TSceneHandle; |
| class TPaletteHandle; |
| class ToolHandle; |
| class TSelectionHandle; |
| class TOnionSkinMaskHandle; |
| class PaletteController; |
| class TFxHandle; |
| |
| class ToolOptionsBox; |
| |
| class TToolViewer; |
| |
| class QMenu; |
| class QKeyEvent; |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TMouseEvent { |
| public: |
| enum ModifierBitshift |
| |
| { SHIFT_BITSHIFT, |
| ALT_BITSHIFT, |
| CTRL_BITSHIFT |
| }; |
| |
| enum ModifierMask |
| { |
| NO_KEY = 0x0, |
| SHIFT_KEY = (1 << SHIFT_BITSHIFT), |
| ALT_KEY = (1 << ALT_BITSHIFT), |
| CTRL_KEY = (1 << CTRL_BITSHIFT) |
| }; |
| |
| public: |
| TPointD m_pos; |
| double m_pressure; |
| |
| |
| ModifierMask m_modifiersMask; |
| |
| |
| Qt::MouseButtons m_buttons; |
| Qt::MouseButton m_button; |
| QPointF m_mousePos; |
| |
| bool m_isTablet; |
| bool m_isHighFrequent; |
| |
| public: |
| TMouseEvent() |
| : m_pressure(1.0) |
| , m_modifiersMask(NO_KEY) |
| , m_buttons(Qt::NoButton) |
| , m_button(Qt::NoButton) |
| , m_isTablet(false) |
| , m_isHighFrequent(false) {} |
| |
| bool isShiftPressed() const { return (m_modifiersMask & SHIFT_KEY); } |
| bool isAltPressed() const { return (m_modifiersMask & ALT_KEY); } |
| bool isCtrlPressed() const { return (m_modifiersMask & CTRL_KEY); } |
| |
| bool isLeftButtonPressed() const { return (m_buttons & Qt::LeftButton) != 0; } |
| Qt::MouseButtons buttons() const { return m_buttons; } |
| Qt::MouseButton button() const { return m_button; } |
| QPointF mousePos() const { return m_mousePos; } |
| bool isTablet() const { return m_isTablet; } |
| bool isHighFrequent() const { return m_isHighFrequent; } |
| |
| void setModifiers(bool shiftPressed, bool altPressed, bool ctrlPressed) { |
| m_modifiersMask = ModifierMask((shiftPressed << SHIFT_BITSHIFT) | |
| (altPressed << ALT_BITSHIFT) | |
| (ctrlPressed << CTRL_BITSHIFT)); |
| } |
| |
| ModifierMask getModifiersMask() const { return m_modifiersMask; } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TTool { |
| public: |
| class Viewer; |
| |
| typedef TApplication Application; |
| |
| public: |
| enum ToolType |
| { GenericTool = 1, |
| ColumnTool = 2, |
| LevelReadTool = 4, |
| LevelWriteTool = |
| 8, |
| |
| |
| |
| LevelTool = LevelReadTool | LevelWriteTool }; |
| |
| enum ToolTargetType |
| { NoTarget = 0x0, |
| VectorImage = 0x1, |
| ToonzImage = 0x2, |
| RasterImage = 0x4, |
| MeshImage = 0x8, |
| Splines = 0x10, |
| |
| LevelColumns= 0x20, |
| MeshColumns = 0x40, |
| |
| EmptyTarget = 0x80, |
| |
| MetaImage = 0x100, |
| |
| CommonImages = VectorImage | ToonzImage | RasterImage, |
| AllImages = CommonImages | MeshImage | MetaImage, |
| Vectors = VectorImage | Splines, |
| |
| CommonLevels = CommonImages | LevelColumns, |
| MeshLevels = MeshImage | MeshColumns, |
| |
| AllTargets = 0xffffffff, |
| }; |
| |
| public: |
| static TTool *getTool(std::string toolName, ToolTargetType targetType); |
| |
| static TApplication *getApplication(); |
| static void setApplication(TApplication *application) { |
| m_application = application; |
| } |
| |
| |
| |
| |
| |
| static TXshCell |
| getImageCell(); |
| |
| |
| |
| |
| |
| static TImage *getImage( |
| bool toBeModified, |
| int subsampling = 0); |
| |
| static TImage *touchImage(); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static void updateToolsPropertiesTranslation(); |
| |
| |
| |
| public: |
| TTool(std::string toolName); |
| virtual ~TTool() {} |
| |
| virtual ToolType getToolType() const = 0; |
| ToolTargetType getTargetType() const { return (ToolTargetType)m_targetType; } |
| |
| std::string getName() const { return m_name; } |
| |
| |
| |
| |
| |
| virtual ToolOptionsBox * |
| createOptionsBox(); |
| |
| |
| void setViewer(TToolViewer *viewer) { |
| m_viewer = viewer; |
| onSetViewer(); |
| } |
| TToolViewer *getViewer() const { return m_viewer; } |
| |
| double getPixelSize() const; |
| |
| |
| |
| |
| void invalidate(const TRectD &rect = TRectD()); |
| |
| |
| |
| |
| |
| |
| int pick(const TPointD &p); |
| bool isPicking() const { return m_picking; } |
| |
| virtual void updateTranslation(){}; |
| |
| |
| |
| |
| |
| |
| virtual bool preLeftButtonDown() { return false; } |
| |
| virtual void mouseMove(const TPointD &, const TMouseEvent &) {} |
| virtual void leftButtonDown(const TPointD &, const TMouseEvent &) {} |
| virtual void leftButtonDrag(const TPointD &, const TMouseEvent &) {} |
| virtual void leftButtonUp(const TPointD &, const TMouseEvent &) {} |
| virtual void leftButtonDoubleClick(const TPointD &, const TMouseEvent &) {} |
| virtual void rightButtonDown(const TPointD &, const TMouseEvent &) {} |
| virtual bool keyDown(QKeyEvent *) { return false; } |
| |
| virtual void onInputText(const std::wstring&, const std::wstring&, int, int){}; |
| |
| virtual void onSetViewer() {} |
| |
| virtual void onActivate() { |
| } |
| virtual void onDeactivate() { |
| } |
| |
| virtual void onImageChanged() {} |
| |
| virtual void onEnter() { |
| } |
| virtual void onLeave() { |
| } |
| |
| |
| |
| virtual void onFrameSwitched() {} |
| |
| virtual void reset() {} |
| |
| virtual void draw() {} |
| |
| bool isActive() const { |
| return m_active; |
| } |
| void setActive(bool active) { m_active = active; } |
| |
| virtual TPropertyGroup *getProperties(int) { return 0; } |
| |
| |
| |
| |
| |
| virtual bool onPropertyChanged(std::string propertyName) { |
| return false; |
| } |
| |
| virtual TSelection *getSelection() { |
| return 0; |
| } |
| |
| |
| virtual int getCursorId() const { |
| return 0; |
| } |
| |
| |
| |
| |
| virtual bool isEventAcceptable(QEvent *e) { return false; } |
| |
| TXsheet *getXsheet() const; |
| |
| int getFrame(); |
| int getColumnIndex(); |
| |
| TStageObjectId getObjectId() |
| const; |
| |
| void notifyImageChanged(); |
| |
| |
| void notifyImageChanged(const TFrameId &fid); |
| |
| |
| |
| |
| |
| |
| |
| TFrameId getCurrentFid() |
| const; |
| |
| const TAffine &getMatrix() const { return m_matrix; } |
| void setMatrix(const TAffine &matrix) { m_matrix = matrix; } |
| |
| TAffine getCurrentColumnMatrix(int frame = -1) |
| const; |
| |
| |
| |
| TAffine getCurrentColumnParentMatrix() |
| const; |
| |
| TAffine getCurrentObjectParentMatrix() const; |
| TAffine getCurrentObjectParentMatrix2() const; |
| |
| |
| |
| |
| |
| |
| |
| |
| TAffine getColumnMatrix(int index, int frame = -1) const; |
| |
| |
| |
| |
| |
| |
| virtual void updateMatrix(); |
| |
| |
| |
| |
| |
| |
| virtual void addContextMenuItems(QMenu *menu) {} |
| |
| void enable(bool on) { m_enabled = on; } |
| bool isEnabled() const { return m_enabled; } |
| |
| QString updateEnabled(); |
| |
| virtual QString updateEnabled(int rowIndex, int columnIndex); |
| |
| bool isColumnLocked(int columnIndex) const; |
| |
| void resetInputMethod(); |
| |
| |
| |
| virtual bool isPencilModeActive() { return false; } |
| |
| |
| virtual bool isDragging() const { return false; }; |
| |
| void setSelectedFrames(const std::set<TFrameId> &selectedFrames); |
| static const std::set<TFrameId> &getSelectedFrames() { |
| return m_selectedFrames; |
| } |
| |
| void tweenSelectedGuideStrokes(); |
| void tweenGuideStrokeToSelected(); |
| void flipGuideStrokeDirection(int mode); |
| |
| public: |
| struct CellOps { |
| int r0; |
| int r1; |
| enum Type { ExistingToNew = 0, BlankToExisting, BlankToNew } type; |
| }; |
| static std::vector<CellOps> |
| m_cellsData; |
| |
| |
| |
| static bool m_isLevelCreated; |
| |
| static bool m_isFrameCreated; |
| |
| static std::vector<TFrameId> m_oldFids; |
| static std::vector<TFrameId> m_newFids; |
| static bool m_isLevelRenumbererd; |
| |
| protected: |
| std::string m_name; |
| |
| TToolViewer *m_viewer; |
| TAffine m_matrix; |
| |
| int m_targetType; |
| |
| bool m_enabled; |
| bool m_active; |
| bool m_picking; |
| |
| static TApplication *m_application; |
| |
| static std::set<TFrameId> m_selectedFrames; |
| |
| protected: |
| void bind(int targetType); |
| |
| virtual void onSelectedFramesChanged() {} |
| |
| virtual QString disableString() { |
| return QString(); |
| } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class TToolViewer { |
| protected: |
| ImagePainter::VisualSettings |
| m_visualSettings; |
| |
| int guidedStrokePickMode = 0; |
| int m_guidedFrontStroke = -1; |
| int m_guidedBackStroke = -1; |
| QWidget *m_viewerWidget = nullptr; |
| |
| public: |
| TToolViewer(QWidget *widget) : m_viewerWidget(widget) {} |
| virtual ~TToolViewer() {} |
| |
| const ImagePainter::VisualSettings &visualSettings() const { |
| return m_visualSettings; |
| } |
| ImagePainter::VisualSettings &visualSettings() { return m_visualSettings; } |
| |
| virtual double getPixelSize() const = 0; |
| |
| |
| virtual void invalidateAll() = 0; |
| |
| virtual void GLInvalidateAll() = 0; |
| |
| virtual void GLInvalidateRect(const TRectD &rect) = 0; |
| |
| |
| |
| virtual void invalidateToolStatus() = 0; |
| |
| virtual TAffine getViewMatrix() const { |
| return TAffine(); |
| } |
| |
| |
| virtual TAffine4 get3dViewMatrix() const { |
| return TAffine4(getViewMatrix()); |
| } |
| |
| |
| |
| |
| virtual int posToColumnIndex(const TPointD &p, double distance, |
| bool includeInvisible = true) const = 0; |
| virtual void posToColumnIndexes(const TPointD &p, std::vector<int> &indexes, |
| double distance, |
| bool includeInvisible = true) const = 0; |
| |
| |
| |
| |
| virtual int posToRow(const TPointD &p, double distance, |
| bool includeInvisible = true, |
| bool currentColumnOnly = false) const = 0; |
| |
| |
| virtual TPointD worldToPos(const TPointD &worldPos) const = 0; |
| |
| |
| |
| virtual int pick(const TPointD &point) = 0; |
| |
| |
| |
| |
| virtual TPointD winToWorld(const TPointD &winPos) const = 0; |
| |
| |
| virtual void pan(const TPointD &delta) = 0; |
| |
| |
| virtual void zoom(const TPointD ¢er, double scaleFactor) = 0; |
| |
| virtual void rotate(const TPointD ¢er, double angle) = 0; |
| virtual void rotate3D(double dPhi, double dTheta) = 0; |
| virtual bool is3DView() const = 0; |
| virtual bool getIsFlippedX() const = 0; |
| virtual bool getIsFlippedY() const = 0; |
| |
| virtual double projectToZ(const TPointD &delta) = 0; |
| |
| virtual TPointD getDpiScale() const = 0; |
| virtual int getVGuideCount() = 0; |
| virtual int getHGuideCount() = 0; |
| virtual double getHGuide(int index) = 0; |
| virtual double getVGuide(int index) = 0; |
| |
| virtual void |
| resetInputMethod() = 0; |
| |
| virtual void setFocus() = 0; |
| |
| |
| virtual TRectD getGeometry() const = 0; |
| virtual TRectD getCameraRect() const { return TRectD(); } |
| |
| virtual void bindFBO() {} |
| virtual void releaseFBO() {} |
| |
| int getGuidedStrokePickerMode() { return guidedStrokePickMode; } |
| void setGuidedStrokePickerMode(int mode) { guidedStrokePickMode = mode; } |
| |
| int getGuidedStrokePickerCursor() { |
| if (guidedStrokePickMode < 0) |
| return ToolCursor::PickPrevCursor; |
| else if (guidedStrokePickMode > 0) |
| return ToolCursor::PickNextCursor; |
| else |
| return ToolCursor::PointingHandCursor; |
| } |
| |
| int getGuidedFrontStroke() { return m_guidedFrontStroke; } |
| void setGuidedFrontStroke(int strokeIdx) { |
| m_guidedFrontStroke = strokeIdx; |
| invalidateAll(); |
| } |
| |
| int getGuidedBackStroke() { return m_guidedBackStroke; } |
| void setGuidedBackStroke(int strokeIdx) { |
| m_guidedBackStroke = strokeIdx; |
| invalidateAll(); |
| } |
| |
| void getGuidedFrameIdx(int *backIdx, int *frontIdx); |
| void doPickGuideStroke(const TPointD &pos); |
| |
| QWidget *viewerWidget() { return m_viewerWidget; } |
| }; |
| |
| #endif |