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