| #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> |
| |
| |
| |
| |
| |
| 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 final : 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) override; |
| |
| void setPoints(const TPointD &p0, const TPointD &p1, const TPointD &p2, |
| const TPointD &p3) override; |
| |
| TVectorImage *getDeformedImage() const { return m_vi.getPointer(); } |
| |
| void deformRegions(); |
| void deformImage() override; |
| }; |
| |
| |
| |
| |
| |
| namespace DragSelectionTool { |
| |
| |
| |
| |
| |
| class UndoChangeStrokes final : 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 override; |
| void redo() const override; |
| int getSize() const override; |
| |
| 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) override; |
| void addTransformUndo() override; |
| |
| |
| void transformWholeLevel(); |
| bool isFlip(); |
| |
| protected: |
| std::unique_ptr<UndoChangeStrokes> m_undo; |
| |
| protected: |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {} |
| |
| void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override; |
| |
| void draw() override {} |
| |
| private: |
| struct VFDScopedBlock; |
| std::unique_ptr<VFDScopedBlock> m_vfdScopedBlock; |
| }; |
| |
| |
| |
| |
| |
| class VectorRotationTool final : public VectorDeformTool { |
| std::unique_ptr<Rotation> m_rotation; |
| |
| public: |
| VectorRotationTool(VectorSelectionTool *tool); |
| |
| void transform(TAffine aff, double angle) override; |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override; |
| void draw() override; |
| }; |
| |
| |
| |
| |
| |
| class VectorFreeDeformTool final : public VectorDeformTool { |
| std::unique_ptr<FreeDeform> m_freeDeform; |
| |
| public: |
| VectorFreeDeformTool(VectorSelectionTool *tool); |
| |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override; |
| }; |
| |
| |
| |
| |
| |
| class VectorMoveSelectionTool final : public VectorDeformTool { |
| std::unique_ptr<MoveSelection> m_moveSelection; |
| |
| public: |
| VectorMoveSelectionTool(VectorSelectionTool *tool); |
| |
| void transform(TAffine aff) override; |
| void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override; |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override; |
| }; |
| |
| |
| |
| |
| |
| class VectorScaleTool final : public VectorDeformTool { |
| std::unique_ptr<Scale> m_scale; |
| |
| public: |
| VectorScaleTool(VectorSelectionTool *tool, int type); |
| |
| TPointD transform(int index, |
| TPointD newPos) override; |
| |
| void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override; |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override; |
| }; |
| |
| |
| |
| |
| |
| class VectorChangeThicknessTool final : public DragTool { |
| TPointD m_curPos, m_firstPos; |
| std::map<int, std::vector<double>> m_strokesThickness; |
| double m_thicknessChange; |
| |
| std::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) override; |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override; |
| void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override; |
| void draw() override {} |
| }; |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class VectorSelectionTool final : public SelectionTool { |
| Q_DECLARE_TR_FUNCTIONS(VectorSelectionTool) |
| |
| public: |
| VectorSelectionTool(int targetType); |
| |
| void setNewFreeDeformer() override; |
| |
| void setCanEnterGroup(bool value) { m_canEnterGroup = value; } |
| |
| bool isConstantThickness() const override { |
| return m_constantThickness.getValue(); |
| } |
| bool isLevelType() const override; |
| bool isSelectedFramesType() const override; |
| bool isSameStyleType() const override; |
| bool isModifiableSelectionType() const override; |
| |
| 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() override; |
| bool isSelectionEmpty() override; |
| |
| void computeBBox() override; |
| |
| TPropertyGroup *getProperties(int targetType) override; |
| |
| protected: |
| void onActivate() override; |
| void onDeactivate() override; |
| |
| void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override; |
| void leftButtonUp(const TPointD &pos, const TMouseEvent &) override; |
| void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) override; |
| void addContextMenuItems(QMenu *menu) override; |
| |
| void draw() override; |
| |
| void updateAction(TPointD pos, const TMouseEvent &e) override; |
| void onSelectedFramesChanged() override; |
| |
| bool onPropertyChanged(std::string propertyName) override; |
| void onImageChanged() override; |
| |
| private: |
| class AttachedLevelSelection final : public LevelSelection { |
| StrokeSelection &m_strokeSelection; |
| |
| |
| public: |
| AttachedLevelSelection(StrokeSelection &strokeSelection) |
| : m_strokeSelection(strokeSelection) {} |
| |
| void selectNone() override { |
| LevelSelection::selectNone(), m_strokeSelection.selectNone(); |
| } |
| void enableCommands() override { m_strokeSelection.enableCommands(); } |
| }; |
| |
| 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) override; |
| bool selectStroke(int index, bool toggle); |
| |
| void doOnActivate() override; |
| void doOnDeactivate() override; |
| |
| void selectRegionVectorImage(); |
| |
| void updateTranslation() override; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void updateSelectionTarget(); |
| |
| void |
| clearSelectedStrokes(); |
| void finalizeSelection(); |
| |
| |
| void drawInLevelType(const TVectorImage &vi); |
| void drawSelectedStrokes(const TVectorImage &vi); |
| void drawGroup(const TVectorImage &vi); |
| }; |
| |
| #endif |