| #pragma once |
| |
| #ifndef VECTORSELECTIONTOOL_H |
| #define VECTORSELECTIONTOOL_H |
| |
| #include "selectiontool.h" |
| |
| |
| #include "tools/strokeselection.h" |
| #include "tools/levelselection.h" |
| |
| |
| #include "tstroke.h" |
| #include "tregion.h" |
| |
| |
| #include <QSet> |
| |
| |
| #include "tcg/tcg_unique_ptr.h" |
| |
| |
| |
| |
| |
| class VectorSelectionTool; |
| |
| |
| |
| |
| |
| |
| |
| enum SelectionTarget |
| { |
| NORMAL_TYPE_IDX, |
| SELECTED_FRAMES_TYPE_IDX, |
| ALL_LEVEL_TYPE_IDX, |
| SAME_STYLE_TYPE_IDX, |
| STYLE_SELECTED_FRAMES_TYPE_IDX, |
| STYLE_LEVEL_TYPE_IDX, |
| BOUNDARY_TYPE_IDX, |
| BOUNDARY_SELECTED_FRAMES_TYPE_IDX, |
| BOUNDARY_LEVEL_TYPE_IDX, |
| }; |
| |
| #define NORMAL_TYPE L"Standard" |
| #define SELECTED_FRAMES_TYPE L"Selected Frames" |
| #define ALL_LEVEL_TYPE L"Whole Level" |
| #define SAME_STYLE_TYPE L"Same Style" |
| #define STYLE_SELECTED_FRAMES_TYPE L"Same Style on Selected Frames" |
| #define STYLE_LEVEL_TYPE L"Same Style on Whole Level" |
| #define BOUNDARY_TYPE L"Boundary Strokes" |
| #define BOUNDARY_SELECTED_FRAMES_TYPE L"Boundaries on Selected Frames" |
| #define BOUNDARY_LEVEL_TYPE L"Boundaries on Whole Level" |
| |
| #define ROUNDC_WSTR L"round_cap" |
| #define BUTT_WSTR L"butt_cap" |
| #define PROJECTING_WSTR L"projecting_cap" |
| #define ROUNDJ_WSTR L"round_join" |
| #define BEVEL_WSTR L"bevel_join" |
| #define MITER_WSTR L"miter_join" |
| |
| |
| |
| |
| |
| class VectorFreeDeformer : public FreeDeformer |
| { |
| TVectorImageP m_vi; |
| std::set<int> m_strokeIndexes; |
| std::vector<TStroke *> m_originalStrokes; |
| |
| bool m_preserveThickness, m_computeRegion, m_flip; |
| |
| TThickPoint deform(TThickPoint point); |
| |
| public: |
| VectorFreeDeformer(TVectorImageP vi, std::set<int> strokeIndexes); |
| ~VectorFreeDeformer(); |
| |
| void setPreserveThickness(bool preserveThickness); |
| void setComputeRegion(bool computeRegion); |
| void setFlip(bool flip); |
| |
| |
| TPointD getPoint(int index) const { return m_newPoints[index]; } |
| |
| void setPoint(int index, const TPointD &p); |
| |
| void setPoints(const TPointD &p0, const TPointD &p1, const TPointD &p2, const TPointD &p3); |
| |
| TVectorImage *getDeformedImage() const { return m_vi.getPointer(); } |
| |
| void deformRegions(); |
| void deformImage(); |
| }; |
| |
| |
| |
| |
| |
| namespace DragSelectionTool |
| { |
| |
| |
| |
| |
| |
| class UndoChangeStrokes : public ToolUtils::TToolUndo |
| { |
| public: |
| UndoChangeStrokes(TXshSimpleLevel *level, const TFrameId &frameId, VectorSelectionTool *tool, |
| const StrokeSelection &selection); |
| UndoChangeStrokes(TXshSimpleLevel *level, const TFrameId &frameId, VectorSelectionTool *tool, |
| const LevelSelection &selection); |
| ~UndoChangeStrokes(); |
| |
| void registerStrokes(bool beforeModify = false); |
| void setFlip(bool value) { m_flip = value; } |
| void transform(const std::vector<TStroke *> &strokes, FourPoints bbox, TPointD center, DeformValues deformValue) const; |
| void restoreRegions() const; |
| void undo() const; |
| void redo() const; |
| int getSize() const; |
| |
| private: |
| VectorSelectionTool *m_tool; |
| |
| std::vector<TStroke *> m_oldStrokes, |
| m_newStrokes; |
| |
| std::vector<int> m_indexes; |
| std::vector<TFilledRegionInf> |
| m_regionsData; |
| |
| int m_selectionCount; |
| |
| FourPoints m_oldBBox, |
| m_newBBox; |
| |
| TPointD m_oldCenter, |
| m_newCenter; |
| |
| DeformValues m_oldDeformValues, |
| m_newDeformValues; |
| |
| bool m_flip; |
| }; |
| |
| |
| |
| |
| |
| class VectorDeformTool : public DeformTool |
| { |
| public: |
| VectorDeformTool(VectorSelectionTool *tool); |
| ~VectorDeformTool(); |
| |
| void applyTransform(FourPoints bbox); |
| void addTransformUndo(); |
| |
| |
| void transformWholeLevel(); |
| bool isFlip(); |
| |
| protected: |
| tcg::unique_ptr<UndoChangeStrokes> m_undo; |
| |
| protected: |
| virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {} |
| virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &e); |
| virtual void draw() {} |
| |
| private: |
| struct VFDScopedBlock; |
| tcg::unique_ptr<VFDScopedBlock> m_vfdScopedBlock; |
| }; |
| |
| |
| |
| |
| |
| class VectorRotationTool : public VectorDeformTool |
| { |
| tcg::unique_ptr<Rotation> m_rotation; |
| |
| public: |
| VectorRotationTool(VectorSelectionTool *tool); |
| |
| void transform(TAffine aff, double angle); |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e); |
| void draw(); |
| }; |
| |
| |
| |
| |
| |
| class VectorFreeDeformTool : public VectorDeformTool |
| { |
| tcg::unique_ptr<FreeDeform> m_freeDeform; |
| |
| public: |
| VectorFreeDeformTool(VectorSelectionTool *tool); |
| |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e); |
| }; |
| |
| |
| |
| |
| |
| class VectorMoveSelectionTool : public VectorDeformTool |
| { |
| tcg::unique_ptr<MoveSelection> m_moveSelection; |
| |
| public: |
| VectorMoveSelectionTool(VectorSelectionTool *tool); |
| |
| void transform(TAffine aff); |
| void leftButtonDown(const TPointD &pos, const TMouseEvent &e); |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e); |
| }; |
| |
| |
| |
| |
| |
| class VectorScaleTool : public VectorDeformTool |
| { |
| tcg::unique_ptr<Scale> m_scale; |
| |
| public: |
| VectorScaleTool(VectorSelectionTool *tool, int type); |
| |
| TPointD transform(int index, TPointD newPos); |
| |
| void leftButtonDown(const TPointD &pos, const TMouseEvent &e); |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e); |
| }; |
| |
| |
| |
| |
| |
| class VectorChangeThicknessTool : public DragTool |
| { |
| TPointD m_curPos, m_firstPos; |
| std::map<int, std::vector<double>> m_strokesThickness; |
| double m_thicknessChange; |
| |
| tcg::unique_ptr<UndoChangeStrokes> m_undo; |
| |
| public: |
| VectorChangeThicknessTool(VectorSelectionTool *tool); |
| ~VectorChangeThicknessTool(); |
| |
| void setStrokesThickness(TVectorImage &vi); |
| void setThicknessChange(double value) { m_thicknessChange = value; } |
| |
| void changeImageThickness(TVectorImage &vi, double newThickness); |
| void addUndo(); |
| |
| void leftButtonDown(const TPointD &pos, const TMouseEvent &e); |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e); |
| void leftButtonUp(const TPointD &pos, const TMouseEvent &e); |
| void draw() {} |
| }; |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class VectorSelectionTool : public SelectionTool |
| { |
| Q_DECLARE_TR_FUNCTIONS(VectorSelectionTool) |
| |
| public: |
| VectorSelectionTool(int targetType); |
| |
| void setNewFreeDeformer(); |
| |
| void setCanEnterGroup(bool value) { m_canEnterGroup = value; } |
| |
| bool isConstantThickness() const { return m_constantThickness.getValue(); } |
| bool isLevelType() const; |
| bool isSelectedFramesType() const; |
| bool isSameStyleType() const; |
| bool isModifiableSelectionType() const; |
| |
| const std::set<int> &selectedStyles() const |
| { |
| return m_levelSelection.styles(); |
| } |
| std::set<int> &selectedStyles() |
| { |
| return m_levelSelection.styles(); |
| } |
| |
| int getSelectionCount() const { return m_selectionCount; } |
| |
| void selectionOutlineStyle(int &capStyle, int &joinStyle); |
| |
| const StrokeSelection &strokeSelection() const |
| { |
| return m_strokeSelection; |
| } |
| |
| const LevelSelection &levelSelection() const |
| { |
| return m_levelSelection; |
| } |
| |
| TSelection *getSelection(); |
| bool isSelectionEmpty(); |
| |
| void computeBBox(); |
| |
| TPropertyGroup *getProperties(int targetType); |
| |
| protected: |
| void onActivate(); |
| void onDeactivate(); |
| |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &); |
| void leftButtonUp(const TPointD &pos, const TMouseEvent &); |
| void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e); |
| void addContextMenuItems(QMenu *menu); |
| |
| void draw(); |
| |
| void updateAction(TPointD pos, const TMouseEvent &e); |
| void onSelectedFramesChanged(); |
| |
| bool onPropertyChanged(std::string propertyName); |
| void onImageChanged(); |
| |
| private: |
| class AttachedLevelSelection : public LevelSelection |
| { |
| StrokeSelection &m_strokeSelection; |
| |
| public: |
| AttachedLevelSelection(StrokeSelection &strokeSelection) |
| : m_strokeSelection(strokeSelection) {} |
| |
| void selectNone() |
| { |
| LevelSelection::selectNone(), m_strokeSelection.selectNone(); |
| } |
| }; |
| |
| private: |
| TEnumProperty m_selectionTarget; |
| TBoolProperty m_constantThickness; |
| |
| StrokeSelection m_strokeSelection; |
| AttachedLevelSelection m_levelSelection; |
| |
| TEnumProperty m_capStyle; |
| TEnumProperty m_joinStyle; |
| TIntProperty m_miterJoinLimit; |
| |
| TPropertyGroup m_outlineProps; |
| |
| int m_selectionCount; |
| |
| bool m_canEnterGroup; |
| |
| private: |
| void modifySelectionOnClick(TImageP image, const TPointD &pos, const TMouseEvent &e); |
| bool selectStroke(int index, bool toggle); |
| |
| void doOnActivate(); |
| void doOnDeactivate(); |
| |
| void selectRegionVectorImage(); |
| |
| void updateTranslation(); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void updateSelectionTarget(); |
| void clearSelectedStrokes(); |
| void finalizeSelection(); |
| |
| void drawInLevelType(const TVectorImage &vi); |
| void drawSelectedStrokes(const TVectorImage &vi); |
| void drawGroup(const TVectorImage &vi); |
| }; |
| |
| #endif |