Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef RASTERSELECTIONTOOL_INCLUDED
Toshihiro Shimizu 890ddd
#define RASTERSELECTIONTOOL_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "selectiontool.h"
Toshihiro Shimizu 890ddd
#include "setsaveboxtool.h"
Toshihiro Shimizu 890ddd
#include "tools/rasterselection.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
class RasterSelectionTool;
Toshihiro Shimizu 890ddd
class VectorFreeDeformer;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterFreeDeformer
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterFreeDeformer final : public FreeDeformer {
Shinya Kitaoka 120a6e
  TRasterP m_ras;
Shinya Kitaoka 120a6e
  TRasterP m_newRas;
Shinya Kitaoka 120a6e
  bool m_noAntialiasing;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterFreeDeformer(TRasterP ras);
Shinya Kitaoka 120a6e
  ~RasterFreeDeformer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*! Set \b index point to \b p, with index from 0 to 3. */
Shinya Kitaoka 473e70
  void setPoint(int index, const TPointD &p) override;
Shinya Kitaoka 120a6e
  /*! Helper function. */
Shinya Kitaoka 120a6e
  void setPoints(const TPointD &p0, const TPointD &p1, const TPointD &p2,
Shinya Kitaoka 473e70
                 const TPointD &p3) override;
Shinya Kitaoka 120a6e
  TRasterP getImage() const { return m_newRas; }
Shinya Kitaoka 473e70
  void deformImage() override;
Shinya Kitaoka 120a6e
  void setNoAntialiasing(bool value) { m_noAntialiasing = value; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragSelectionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace DragSelectionTool {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// UndoRasterDeform
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class UndoRasterDeform final : public TUndo {
Shinya Kitaoka 120a6e
  static int m_id;
Shinya Kitaoka 120a6e
  RasterSelectionTool *m_tool;
Shinya Kitaoka 120a6e
  std::string m_oldFloatingImageId, m_newFloatingImageId;
Shinya Kitaoka 120a6e
  std::vector<tstroke> m_newStrokes;</tstroke>
Shinya Kitaoka 120a6e
  std::vector<tstroke> m_oldStrokes;</tstroke>
Shinya Kitaoka 120a6e
  DragSelectionTool::DeformValues m_oldDeformValues, m_newDeformValues;
Shinya Kitaoka 120a6e
  FourPoints m_oldBBox, m_newBBox;
Shinya Kitaoka 120a6e
  TPointD m_oldCenter, m_newCenter;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDimension m_dim;
Shinya Kitaoka 120a6e
  int m_pixelSize;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  UndoRasterDeform(RasterSelectionTool *tool);
Shinya Kitaoka 120a6e
  ~UndoRasterDeform();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void registerRasterDeformation();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void undo() const override;
Shinya Kitaoka 473e70
  void redo() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getSize() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  QString getHistoryString() override { return QObject::tr("Deform Raster"); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// UndoRasterTransform
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class UndoRasterTransform final : public TUndo {
Shinya Kitaoka 120a6e
  RasterSelectionTool *m_tool;
Shinya Kitaoka 120a6e
  TAffine m_oldTransform, m_newTransform;
Shinya Kitaoka 120a6e
  TPointD m_oldCenter, m_newCenter;
Shinya Kitaoka 120a6e
  FourPoints m_oldBbox, m_newBbox;
Shinya Kitaoka 120a6e
  DragSelectionTool::DeformValues m_oldDeformValues, m_newDeformValues;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  UndoRasterTransform(RasterSelectionTool *tool);
Shinya Kitaoka 120a6e
  void setChangedValues();
Shinya Kitaoka 473e70
  void undo() const override;
Shinya Kitaoka 473e70
  void redo() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getSize() const override { return sizeof(*this); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  QString getHistoryString() override {
Shinya Kitaoka 38fd86
    return QObject::tr("Transform Raster");
Shinya Kitaoka 38fd86
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterDeformTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class RasterDeformTool : public DeformTool {
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  TAffine m_transform;
Shinya Kitaoka 120a6e
  UndoRasterTransform *m_transformUndo;
Shinya Kitaoka 120a6e
  UndoRasterDeform *m_deformUndo;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! It's true when use RasterFreeDeformer
Shinya Kitaoka 120a6e
  bool m_isFreeDeformer;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void applyTransform(FourPoints bbox) override;
Shinya Kitaoka 120a6e
  void applyTransform(TAffine aff, bool modifyCenter);
Shinya Kitaoka 473e70
  void addTransformUndo() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override{};
Shinya Kitaoka 38fd86
  void draw() override{};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterDeformTool(RasterSelectionTool *tool, bool freeDeformer);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterRotationTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterRotationTool final : public RasterDeformTool {
Shinya Kitaoka 120a6e
  Rotation *m_rotation;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterRotationTool(RasterSelectionTool *tool);
Shinya Kitaoka 473e70
  void transform(TAffine aff, double angle) override;
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void draw() override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterFreeDeformTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterFreeDeformTool final : public RasterDeformTool {
Shinya Kitaoka 120a6e
  FreeDeform *m_freeDeform;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterFreeDeformTool(RasterSelectionTool *tool);
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterMoveSelectionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterMoveSelectionTool final : public RasterDeformTool {
Shinya Kitaoka 120a6e
  MoveSelection *m_moveSelection;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterMoveSelectionTool(RasterSelectionTool *tool);
Shinya Kitaoka 473e70
  void transform(TAffine aff) override;
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterScaleTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterScaleTool final : public RasterDeformTool {
Shinya Kitaoka 120a6e
  Scale *m_scale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
caryoscelus fb92fd
  RasterScaleTool(RasterSelectionTool *tool, ScaleType type);
Shinya Kitaoka 120a6e
  /*! Return scale value. */
Shinya Kitaoka 473e70
  TPointD transform(int index, TPointD newPos) override;
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace DragSelectionTool
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterSelectionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterSelectionTool final : public SelectionTool {
Shinya Kitaoka 120a6e
  Q_DECLARE_TR_FUNCTIONS(RasterSelectionTool)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  RasterSelection m_rasterSelection;
Shinya Kitaoka 120a6e
  int m_transformationCount;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! Used in ToonzRasterImage to switch from selection tool to modify savebox
Shinya Kitaoka 120a6e
  //! tool.
Shinya Kitaoka 120a6e
  TBoolProperty m_modifySavebox;
Shinya Kitaoka 120a6e
  SetSaveboxTool *m_setSaveboxTool;
Shinya Kitaoka 120a6e
  TBoolProperty m_noAntialiasing;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! Used to deform bbox strokes.
Shinya Kitaoka 120a6e
  VectorFreeDeformer *m_selectionFreeDeformer;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void modifySelectionOnClick(TImageP image, const TPointD &pos,
Shinya Kitaoka 473e70
                              const TMouseEvent &e) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void drawFloatingSelection();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterSelectionTool(int targetType);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void setBBox(const DragSelectionTool::FourPoints &points,
Shinya Kitaoka 38fd86
               int index = 0) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void setNewFreeDeformer() override;
Shinya Kitaoka 120a6e
  VectorFreeDeformer *getSelectionFreeDeformer() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool isFloating() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
Shinya Kitaoka 473e70
  void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override;
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
Shinya Kitaoka 473e70
  void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void draw() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TSelection *getSelection() override;
Shinya Kitaoka 473e70
  bool isSelectionEmpty() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void computeBBox() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void doOnActivate() override;
Shinya Kitaoka 473e70
  void doOnDeactivate() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onImageChanged() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void transformFloatingSelection(const TAffine &affine, const TPointD ¢er,
Shinya Kitaoka 120a6e
                                  const DragSelectionTool::FourPoints &points);
Shinya Kitaoka 120a6e
  void increaseTransformationCount();
Shinya Kitaoka 120a6e
  void decreaseTransformationCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onActivate() override;
Shinya Kitaoka 120a6e
  TBoolProperty *getModifySaveboxProperty() {
Shinya Kitaoka 120a6e
    if (m_targetType & ToonzImage) return &m_modifySavebox;
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  bool onPropertyChanged(std::string propertyName) override;
Shinya Kitaoka 120a6e
  bool getNoAntialiasingValue() { return m_noAntialiasing.getValue(); }
Toshihiro Shimizu 890ddd
manongjohn 6939a3
  bool isSelectionEditable() { return m_rasterSelection.isEditable(); }
manongjohn 6939a3
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void updateTranslation() override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // RASTERSELECTIONTOOL_INCLUDED