Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef SELECTIONTOOL_INCLUDED
Toshihiro Shimizu 890ddd
#define SELECTIONTOOL_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/selection.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/strokegenerator.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// For Qt translation support
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
#include <qset></qset>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class SelectionTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Constants / Defines
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
enum SelectionType {
Toshihiro Shimizu 890ddd
	RECT_SELECTION_IDX,
Toshihiro Shimizu 890ddd
	FREEHAND_SELECTION_IDX,
Toshihiro Shimizu 890ddd
	POLYLINE_SELECTION_IDX,
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define RECT_SELECTION L"Rectangular"
Toshihiro Shimizu 890ddd
#define FREEHAND_SELECTION L"Freehand"
Toshihiro Shimizu 890ddd
#define POLYLINE_SELECTION L"Polyline"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// FreeDeformer
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FreeDeformer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TPointD m_originalP00;
Toshihiro Shimizu 890ddd
	TPointD m_originalP11;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	vector<tpointd> m_newPoints;</tpointd>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FreeDeformer() {}
Toshihiro Shimizu 890ddd
	virtual ~FreeDeformer() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Set \b index point to \b p, with index from 0 to 3. */
Toshihiro Shimizu 890ddd
	virtual void setPoint(int index, const TPointD &p) = 0;
Toshihiro Shimizu 890ddd
	/*! Helper function. */
Toshihiro Shimizu 890ddd
	virtual void setPoints(const TPointD &p0, const TPointD &p1, const TPointD &p2, const TPointD &p3) = 0;
Toshihiro Shimizu 890ddd
	virtual void deformImage() = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragSelectionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace DragSelectionTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// FourPoints
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FourPoints
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_p00, m_p01, m_p10, m_p11;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FourPoints(TPointD p00, TPointD p01, TPointD p10, TPointD p11)
Toshihiro Shimizu 890ddd
		: m_p00(p00), m_p01(p01), m_p10(p10), m_p11(p11)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	FourPoints() : m_p00(TPointD()), m_p01(TPointD()), m_p10(TPointD()), m_p11(TPointD()) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setP00(TPointD p) { m_p00 = p; }
Toshihiro Shimizu 890ddd
	void setP01(TPointD p) { m_p01 = p; }
Toshihiro Shimizu 890ddd
	void setP10(TPointD p) { m_p10 = p; }
Toshihiro Shimizu 890ddd
	void setP11(TPointD p) { m_p11 = p; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD getP00() const { return m_p00; }
Toshihiro Shimizu 890ddd
	TPointD getP01() const { return m_p01; }
Toshihiro Shimizu 890ddd
	TPointD getP10() const { return m_p10; }
Toshihiro Shimizu 890ddd
	TPointD getP11() const { return m_p11; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Order four point from BottomLeft to TopRight. */
Toshihiro Shimizu 890ddd
	FourPoints orderedPoints() const;
Toshihiro Shimizu 890ddd
	TPointD getBottomLeft() const { return orderedPoints().getP00(); }
Toshihiro Shimizu 890ddd
	TPointD getBottomRight() const { return orderedPoints().getP10(); }
Toshihiro Shimizu 890ddd
	TPointD getTopRight() const { return orderedPoints().getP11(); }
Toshihiro Shimizu 890ddd
	TPointD getTopLeft() const { return orderedPoints().getP01(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Point = index: P00 =  0; P10 = 1; P11 = 2; P01 = 3; P0M = 4; P1M = 5; PM1 = 6; P0M = 7. */
Toshihiro Shimizu 890ddd
	TPointD getPoint(int index) const;
Toshihiro Shimizu 890ddd
	/*! Point = index: P00 =  0; P10 = 1; P11 = 2; P01 = 3. */
Toshihiro Shimizu 890ddd
	void setPoint(int index, const TPointD &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FourPoints enlarge(double d);
Toshihiro Shimizu 890ddd
	bool isEmpty();
Toshihiro Shimizu 890ddd
	void empty();
Toshihiro Shimizu 890ddd
	bool contains(TPointD p);
Toshihiro Shimizu 890ddd
	TRectD getBox() const;
Toshihiro Shimizu 890ddd
	FourPoints &operator=(const TRectD &r);
Toshihiro Shimizu 890ddd
	bool operator==(const FourPoints &p) const;
Toshihiro Shimizu 890ddd
	FourPoints operator*(const TAffine &aff) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
void drawFourPoints(const FourPoints &rect, const TPixel32 &color,
Toshihiro Shimizu 890ddd
					unsigned short stipple, bool doContrast);
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DeformValues
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct DeformValues {
Toshihiro Shimizu 890ddd
	double m_rotationAngle, m_maxSelectionThickness;
Toshihiro Shimizu 890ddd
	TPointD m_scaleValue, m_moveValue;
Toshihiro Shimizu 890ddd
	bool m_isSelectionModified;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DeformValues(double rotationAngle = 0, double maxSelectionThickness = 0,
Toshihiro Shimizu 890ddd
				 TPointD scaleValue = TPointD(1, 1), TPointD moveValue = TPointD(), bool isSelectionModified = false)
Toshihiro Shimizu 890ddd
		: m_rotationAngle(rotationAngle), m_maxSelectionThickness(maxSelectionThickness), m_scaleValue(scaleValue), m_moveValue(moveValue), m_isSelectionModified(isSelectionModified)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void reset()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_rotationAngle = 0;
Toshihiro Shimizu 890ddd
		m_maxSelectionThickness = 0;
Toshihiro Shimizu 890ddd
		m_scaleValue = TPointD(1, 1);
Toshihiro Shimizu 890ddd
		m_moveValue = TPointD();
Toshihiro Shimizu 890ddd
		m_isSelectionModified = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	SelectionTool *m_tool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragTool(SelectionTool *tool)
Toshihiro Shimizu 890ddd
		: m_tool(tool)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	virtual ~DragTool() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SelectionTool *getTool() const { return m_tool; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void transform(TAffine aff, double angle){};
Toshihiro Shimizu 890ddd
	virtual void transform(TAffine aff){};
Toshihiro Shimizu 890ddd
	virtual TPointD transform(int index, TPointD newPos) { return TPointD(); };
Toshihiro Shimizu 890ddd
	virtual void addTransformUndo(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void draw() = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DeformTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DeformTool : public DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TPointD m_curPos;
Toshihiro Shimizu 890ddd
	bool m_isDragging;
Toshihiro Shimizu 890ddd
	TPointD m_startScaleValue;
Toshihiro Shimizu 890ddd
	TPointD m_startPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DeformTool(SelectionTool *tool);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void applyTransform(FourPoints bbox) = 0;
Toshihiro Shimizu 890ddd
	virtual void applyTransform(TAffine aff){};
Toshihiro Shimizu 890ddd
	virtual void addTransformUndo() = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSimmetricPointIndex(int index) const;
Toshihiro Shimizu 890ddd
	/*! Return before point \b index between possible point index {0,4,1,5,2,6,3,7}, include middle point. */
Toshihiro Shimizu 890ddd
	int getBeforePointIndex(int index) const;
Toshihiro Shimizu 890ddd
	/*! Return next point \b index between possible point index {0,4,1,5,2,6,3,7}, include middle point. */
Toshihiro Shimizu 890ddd
	int getNextPointIndex(int index) const;
Toshihiro Shimizu 890ddd
	/*! Return before vertex \b index between possible point vertex index {0,1,2,3}*/
Toshihiro Shimizu 890ddd
	int getBeforeVertexIndex(int index) const;
Toshihiro Shimizu 890ddd
	/*! Return next vertex \b index between possible point vertex index {0,1,2,3}*/
Toshihiro Shimizu 890ddd
	int getNextVertexIndex(int index) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD getStartPos() const { return m_startPos; }
Toshihiro Shimizu 890ddd
	void setStartPos(const TPointD &pos) { m_startPos = pos; }
Toshihiro Shimizu 890ddd
	TPointD getCurPos() const { return m_curPos; }
Toshihiro Shimizu 890ddd
	void setCurPos(const TPointD &pos) { m_curPos = pos; }
Toshihiro Shimizu 890ddd
	bool isDragging() const { return m_isDragging; }
Toshihiro Shimizu 890ddd
	TPointD getStartScaleValue() const { return m_startScaleValue; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) = 0;
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	virtual void draw() = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Rotation
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Rotation
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double m_curAng, m_dstAng;
Toshihiro Shimizu 890ddd
	DeformTool *m_deformTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Rotation(DeformTool *deformTool);
Toshihiro Shimizu 890ddd
	TPointD getStartCenter() const;
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
// FreeDeform
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FreeDeform
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	DeformTool *m_deformTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FreeDeform(DeformTool *deformTool);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// MoveSelection
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class MoveSelection
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	DeformTool *m_deformTool;
Toshihiro Shimizu 890ddd
	TPointD m_lastDelta, m_firstPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	MoveSelection(DeformTool *deformTool);
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
// Scale
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Scale
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_startCenter;
Toshihiro Shimizu 890ddd
	bool m_isShiftPressed;
Toshihiro Shimizu 890ddd
	bool m_isAltPressed;
Toshihiro Shimizu 890ddd
	bool m_scaleInCenter;
Toshihiro Shimizu 890ddd
	std::vector<fourpoints> m_startBboxs;</fourpoints>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DeformTool *m_deformTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum Type { GLOBAL = 0,
Toshihiro Shimizu 890ddd
				HORIZONTAL = 1,
Toshihiro Shimizu 890ddd
				VERTICAL = 2 };
Toshihiro Shimizu 890ddd
	int m_type;
Toshihiro Shimizu 890ddd
	Scale(DeformTool *deformTool, int type);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! Return intersection between straight line in \b point0, \b point1 and straight line for
Toshihiro Shimizu 890ddd
      \b p parallel to straight line in \b point2, \b point3. */
Toshihiro Shimizu 890ddd
	TPointD getIntersectionPoint(const TPointD &point0, const TPointD &point1,
Toshihiro Shimizu 890ddd
								 const TPointD &point2, const TPointD &point3, const TPointD &p) const;
Toshihiro Shimizu 890ddd
	/*! Scale \b index point of \b bbox in \b pos and return scaled bbox. */
Toshihiro Shimizu 890ddd
	FourPoints bboxScale(int index, const FourPoints &oldBbox, const TPointD &pos);
Toshihiro Shimizu 890ddd
	/*! Compute new scale value take care of new position of \b movedIndex point in \b bbox. */
Toshihiro Shimizu 890ddd
	TPointD computeScaleValue(int movedIndex, const FourPoints newBbox);
Toshihiro Shimizu 890ddd
	/*! Return \b index point scaled in \b center of \b scaleValue. */
Toshihiro Shimizu 890ddd
	TPointD getScaledPoint(int index, const FourPoints &oldBbox, const TPointD scaleValue, const TPointD center);
Toshihiro Shimizu 890ddd
	/*! Compute new center after scale of \b bbox \b index point. */
Toshihiro Shimizu 890ddd
	TPointD getNewCenter(int index, const FourPoints bbox, const TPointD scaleValue);
Toshihiro Shimizu 890ddd
	/*! Scale \b bbox \b index point in pos and if \b m_scaleInCenter is true scale in \b center \b bbox simmetric point;
Toshihiro Shimizu 890ddd
      compute scaleValue. */
Toshihiro Shimizu 890ddd
	FourPoints bboxScaleInCenter(int index, const FourPoints &oldBbox, const TPointD newPos, TPointD &scaleValue,
Toshihiro Shimizu 890ddd
								 const TPointD center, bool recomputeScaleValue);
Toshihiro Shimizu 890ddd
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
	std::vector<fourpoints> getStartBboxs() const { return m_startBboxs; }</fourpoints>
Toshihiro Shimizu 890ddd
	TPointD getStartCenter() const { return m_startCenter; }
Toshihiro Shimizu 890ddd
	bool scaleInCenter() const { return m_scaleInCenter; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Utility
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DragSelectionTool::DragTool *createNewMoveSelectionTool(SelectionTool *st);
Toshihiro Shimizu 890ddd
DragSelectionTool::DragTool *createNewRotationTool(SelectionTool *st);
Toshihiro Shimizu 890ddd
DragSelectionTool::DragTool *createNewFreeDeformTool(SelectionTool *st);
Toshihiro Shimizu 890ddd
DragSelectionTool::DragTool *createNewScaleTool(SelectionTool *st, int type);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// SelectionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class SelectionTool : public TTool, public TSelection::View
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_DECLARE_TR_FUNCTIONS(SelectionTool)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	bool m_firstTime;
Toshihiro Shimizu 890ddd
	DragSelectionTool::DragTool *m_dragTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	StrokeGenerator m_track;
Toshihiro Shimizu 890ddd
	vector<tpointd> m_polyline;</tpointd>
Toshihiro Shimizu 890ddd
	TPointD m_mousePosition;
Toshihiro Shimizu 890ddd
	TStroke *m_stroke;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//To modify selection
Toshihiro Shimizu 890ddd
	TPointD m_curPos;
Toshihiro Shimizu 890ddd
	TPointD m_firstPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_selecting;
Toshihiro Shimizu 890ddd
	bool m_justSelected;
Toshihiro Shimizu 890ddd
	bool m_shiftPressed;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	enum { Outside,
Toshihiro Shimizu 890ddd
		   Inside,
Toshihiro Shimizu 890ddd
		   DEFORM,
Toshihiro Shimizu 890ddd
		   ROTATION,
Toshihiro Shimizu 890ddd
		   MOVE_CENTER,
Toshihiro Shimizu 890ddd
		   SCALE,
Toshihiro Shimizu 890ddd
		   SCALE_X,
Toshihiro Shimizu 890ddd
		   SCALE_Y,
Toshihiro Shimizu 890ddd
		   GLOBAL_THICKNESS,
Toshihiro Shimizu 890ddd
		   ADD_SELECTION } m_what; //RV
Toshihiro Shimizu 890ddd
	enum { P00 = 0,
Toshihiro Shimizu 890ddd
		   P10 = 1,
Toshihiro Shimizu 890ddd
		   P11 = 2,
Toshihiro Shimizu 890ddd
		   P01 = 3,
Toshihiro Shimizu 890ddd
		   PM0 = 4,
Toshihiro Shimizu 890ddd
		   P1M = 5,
Toshihiro Shimizu 890ddd
		   PM1 = 6,
Toshihiro Shimizu 890ddd
		   P0M = 7,
Toshihiro Shimizu 890ddd
		   NONE } m_selectedPoint; //RV
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int m_cursorId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_leftButtonMousePressed;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DragSelectionTool::FourPoints m_selectingRect;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<dragselectiontool::fourpoints> m_bboxs;</dragselectiontool::fourpoints>
Toshihiro Shimizu 890ddd
	std::vector<tpointd> m_centers;</tpointd>
Toshihiro Shimizu 890ddd
	std::vector<freedeformer *=""> m_freeDeformers;</freedeformer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEnumProperty m_strokeSelectionType;
Toshihiro Shimizu 890ddd
	TPropertyGroup m_prop;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void updateAction(TPointD pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void modifySelectionOnClick(TImageP image, const TPointD &pos, const TMouseEvent &e) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void doOnActivate() = 0;
Toshihiro Shimizu 890ddd
	virtual void doOnDeactivate() = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Metodi per disegnare la linea della selezione Freehand
Toshihiro Shimizu 890ddd
	void startFreehand(const TPointD &pos);
Toshihiro Shimizu 890ddd
	void freehandDrag(const TPointD &pos);
Toshihiro Shimizu 890ddd
	void closeFreehand(const TPointD &pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Metodi per disegnare la linea della selezione Polyline
Toshihiro Shimizu 890ddd
	void addPointPolyline(const TPointD &pos);
Toshihiro Shimizu 890ddd
	void closePolyline(const TPointD &pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void updateTranslation();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void drawPolylineSelection();
Toshihiro Shimizu 890ddd
	void drawRectSelection(const TImage *image);
Toshihiro Shimizu 890ddd
	void drawCommandHandle(const TImage *image);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragSelectionTool::DeformValues m_deformValues;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SelectionTool(int targetType);
Toshihiro Shimizu 890ddd
	~SelectionTool();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ToolType getToolType() const { return TTool::LevelWriteTool; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD getCenter(int index = 0) const;
Toshihiro Shimizu 890ddd
	void setCenter(const TPointD ¢er, int index = 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getBBoxsCount() const;
Toshihiro Shimizu 890ddd
	DragSelectionTool::FourPoints getBBox(int index = 0) const;
Toshihiro Shimizu 890ddd
	virtual void setBBox(const DragSelectionTool::FourPoints &points, int index = 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FreeDeformer *getFreeDeformer(int index = 0) const;
Toshihiro Shimizu 890ddd
	virtual void setNewFreeDeformer() = 0;
Toshihiro Shimizu 890ddd
	void clearDeformers();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSelectedPoint() const { return m_selectedPoint; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual bool isConstantThickness() const { return true; }
Toshihiro Shimizu 890ddd
	virtual bool isLevelType() const { return false; }
Toshihiro Shimizu 890ddd
	virtual bool isSelectedFramesType() const { return false; }
Toshihiro Shimizu 890ddd
	virtual bool isSameStyleType() const { return false; }
Toshihiro Shimizu 890ddd
	virtual bool isModifiableSelectionType() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return !(isLevelType() || isSelectedFramesType());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	virtual bool isFloating() const { return false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QSet<int> getSelectedStyles() const { return QSet<int>(); }</int></int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &);
Toshihiro Shimizu 890ddd
	virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	void mouseMove(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	virtual void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) = 0;
Toshihiro Shimizu 890ddd
	bool keyDown(int key, TUINT32 flags, const TPoint &pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getCursorId() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void draw() = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual TSelection *getSelection() = 0;
Toshihiro Shimizu 890ddd
	virtual bool isSelectionEmpty() = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void computeBBox() = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onActivate();
Toshihiro Shimizu 890ddd
	void onDeactivate();
Toshihiro Shimizu 890ddd
	virtual void onImageChanged() = 0;
Toshihiro Shimizu 890ddd
	void onSelectionChanged();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPropertyGroup *getProperties(int targetType) { return &m_prop; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool onPropertyChanged(string propertyName);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif //SELECTIONTOOL_INCLUDED