|
Shinya Kitaoka |
810553 |
#pragma once
|
|
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 {
|
|
Shinya Kitaoka |
120a6e |
RECT_SELECTION_IDX,
|
|
Shinya Kitaoka |
120a6e |
FREEHAND_SELECTION_IDX,
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
Shinya Kitaoka |
120a6e |
class FreeDeformer {
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
TPointD m_originalP00;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_originalP11;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::vector<tpointd> m_newPoints;</tpointd>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
FreeDeformer() {}
|
|
Shinya Kitaoka |
120a6e |
virtual ~FreeDeformer() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*! Set \b index point to \b p, with index from 0 to 3. */
|
|
Shinya Kitaoka |
120a6e |
virtual void setPoint(int index, const TPointD &p) = 0;
|
|
Shinya Kitaoka |
120a6e |
/*! Helper function. */
|
|
Shinya Kitaoka |
120a6e |
virtual void setPoints(const TPointD &p0, const TPointD &p1,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &p2, const TPointD &p3) = 0;
|
|
shun-iwasawa |
9905f5 |
virtual void deformImage() = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DragSelectionTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace DragSelectionTool {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// FourPoints
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class FourPoints {
|
|
Shinya Kitaoka |
120a6e |
TPointD m_p00, m_p01, m_p10, m_p11;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
FourPoints(TPointD p00, TPointD p01, TPointD p10, TPointD p11)
|
|
Shinya Kitaoka |
120a6e |
: m_p00(p00), m_p01(p01), m_p10(p10), m_p11(p11) {}
|
|
Shinya Kitaoka |
120a6e |
FourPoints()
|
|
Shinya Kitaoka |
120a6e |
: m_p00(TPointD())
|
|
Shinya Kitaoka |
120a6e |
, m_p01(TPointD())
|
|
Shinya Kitaoka |
120a6e |
, m_p10(TPointD())
|
|
Shinya Kitaoka |
120a6e |
, m_p11(TPointD()) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setP00(TPointD p) { m_p00 = p; }
|
|
Shinya Kitaoka |
120a6e |
void setP01(TPointD p) { m_p01 = p; }
|
|
Shinya Kitaoka |
120a6e |
void setP10(TPointD p) { m_p10 = p; }
|
|
Shinya Kitaoka |
120a6e |
void setP11(TPointD p) { m_p11 = p; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPointD getP00() const { return m_p00; }
|
|
Shinya Kitaoka |
120a6e |
TPointD getP01() const { return m_p01; }
|
|
Shinya Kitaoka |
120a6e |
TPointD getP10() const { return m_p10; }
|
|
Shinya Kitaoka |
120a6e |
TPointD getP11() const { return m_p11; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*! Order four point from BottomLeft to TopRight. */
|
|
Shinya Kitaoka |
120a6e |
FourPoints orderedPoints() const;
|
|
Shinya Kitaoka |
120a6e |
TPointD getBottomLeft() const { return orderedPoints().getP00(); }
|
|
Shinya Kitaoka |
120a6e |
TPointD getBottomRight() const { return orderedPoints().getP10(); }
|
|
Shinya Kitaoka |
120a6e |
TPointD getTopRight() const { return orderedPoints().getP11(); }
|
|
Shinya Kitaoka |
120a6e |
TPointD getTopLeft() const { return orderedPoints().getP01(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*! Point = index: P00 = 0; P10 = 1; P11 = 2; P01 = 3; P0M = 4; P1M = 5; PM1
|
|
Shinya Kitaoka |
120a6e |
* = 6; P0M = 7. */
|
|
Shinya Kitaoka |
120a6e |
TPointD getPoint(int index) const;
|
|
Shinya Kitaoka |
120a6e |
/*! Point = index: P00 = 0; P10 = 1; P11 = 2; P01 = 3. */
|
|
Shinya Kitaoka |
120a6e |
void setPoint(int index, const TPointD &p);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FourPoints enlarge(double d);
|
|
Shinya Kitaoka |
120a6e |
bool isEmpty();
|
|
Shinya Kitaoka |
120a6e |
void empty();
|
|
Shinya Kitaoka |
120a6e |
bool contains(TPointD p);
|
|
Shinya Kitaoka |
120a6e |
TRectD getBox() const;
|
|
Shinya Kitaoka |
120a6e |
FourPoints &operator=(const TRectD &r);
|
|
Shinya Kitaoka |
120a6e |
bool operator==(const FourPoints &p) const;
|
|
Shinya Kitaoka |
120a6e |
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,
|
|
Shinya Kitaoka |
120a6e |
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 {
|
|
Shinya Kitaoka |
120a6e |
double m_rotationAngle, m_maxSelectionThickness;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_scaleValue, m_moveValue;
|
|
Shinya Kitaoka |
120a6e |
bool m_isSelectionModified;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
DeformValues(double rotationAngle = 0, double maxSelectionThickness = 0,
|
|
Shinya Kitaoka |
120a6e |
TPointD scaleValue = TPointD(1, 1),
|
|
Shinya Kitaoka |
120a6e |
TPointD moveValue = TPointD(), bool isSelectionModified = false)
|
|
Shinya Kitaoka |
120a6e |
: m_rotationAngle(rotationAngle)
|
|
Shinya Kitaoka |
120a6e |
, m_maxSelectionThickness(maxSelectionThickness)
|
|
Shinya Kitaoka |
120a6e |
, m_scaleValue(scaleValue)
|
|
Shinya Kitaoka |
120a6e |
, m_moveValue(moveValue)
|
|
Shinya Kitaoka |
120a6e |
, m_isSelectionModified(isSelectionModified) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void reset() {
|
|
Shinya Kitaoka |
120a6e |
m_rotationAngle = 0;
|
|
Shinya Kitaoka |
120a6e |
m_maxSelectionThickness = 0;
|
|
Shinya Kitaoka |
120a6e |
m_scaleValue = TPointD(1, 1);
|
|
Shinya Kitaoka |
120a6e |
m_moveValue = TPointD();
|
|
Shinya Kitaoka |
120a6e |
m_isSelectionModified = false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DragTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DragTool {
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
SelectionTool *m_tool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
DragTool(SelectionTool *tool) : m_tool(tool) {}
|
|
Shinya Kitaoka |
120a6e |
virtual ~DragTool() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SelectionTool *getTool() const { return m_tool; }
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
9905f5 |
virtual void transform(TAffine aff, double angle) {}
|
|
shun-iwasawa |
9905f5 |
virtual void transform(TAffine aff) {}
|
|
shun-iwasawa |
9905f5 |
virtual TPointD transform(int index, TPointD newPos,
|
|
shun-iwasawa |
9905f5 |
bool onFastDragging = false) {
|
|
shun-iwasawa |
9905f5 |
return TPointD();
|
|
shun-iwasawa |
9905f5 |
}
|
|
shun-iwasawa |
9905f5 |
virtual void addTransformUndo() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &) = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &) = 0;
|
|
shun-iwasawa |
9905f5 |
virtual void draw() = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DeformTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DeformTool : public DragTool {
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
TPointD m_curPos;
|
|
Shinya Kitaoka |
120a6e |
bool m_isDragging;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_startScaleValue;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_startPos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
DeformTool(SelectionTool *tool);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
9905f5 |
virtual void applyTransform(FourPoints bbox, bool onFastDragging = false) = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void applyTransform(TAffine aff){};
|
|
Shinya Kitaoka |
473e70 |
|
|
Shinya Kitaoka |
473e70 |
void addTransformUndo() override = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
MCCCS |
a0ce32 |
int getSymmetricPointIndex(int index) const;
|
|
Shinya Kitaoka |
120a6e |
/*! Return before point \b index between possible point index
|
|
Shinya Kitaoka |
120a6e |
* {0,4,1,5,2,6,3,7}, include middle point. */
|
|
Shinya Kitaoka |
120a6e |
int getBeforePointIndex(int index) const;
|
|
Shinya Kitaoka |
120a6e |
/*! Return next point \b index between possible point index {0,4,1,5,2,6,3,7},
|
|
Shinya Kitaoka |
120a6e |
* include middle point. */
|
|
Shinya Kitaoka |
120a6e |
int getNextPointIndex(int index) const;
|
|
Shinya Kitaoka |
120a6e |
/*! Return before vertex \b index between possible point vertex index
|
|
Shinya Kitaoka |
120a6e |
* {0,1,2,3}*/
|
|
Shinya Kitaoka |
120a6e |
int getBeforeVertexIndex(int index) const;
|
|
Shinya Kitaoka |
120a6e |
/*! Return next vertex \b index between possible point vertex index
|
|
Shinya Kitaoka |
120a6e |
* {0,1,2,3}*/
|
|
Shinya Kitaoka |
120a6e |
int getNextVertexIndex(int index) const;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPointD getStartPos() const { return m_startPos; }
|
|
Shinya Kitaoka |
120a6e |
void setStartPos(const TPointD &pos) { m_startPos = pos; }
|
|
Shinya Kitaoka |
120a6e |
TPointD getCurPos() const { return m_curPos; }
|
|
Shinya Kitaoka |
120a6e |
void setCurPos(const TPointD &pos) { m_curPos = pos; }
|
|
Shinya Kitaoka |
120a6e |
bool isDragging() const { return m_isDragging; }
|
|
Shinya Kitaoka |
120a6e |
TPointD getStartScaleValue() const { return m_startScaleValue; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
|
|
Shinya Kitaoka |
473e70 |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override = 0;
|
|
Shinya Kitaoka |
473e70 |
void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
|
|
Shinya Kitaoka |
473e70 |
void draw() override = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// Rotation
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class Rotation {
|
|
Shinya Kitaoka |
120a6e |
double m_curAng, m_dstAng;
|
|
Shinya Kitaoka |
120a6e |
DeformTool *m_deformTool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
Rotation(DeformTool *deformTool);
|
|
Shinya Kitaoka |
120a6e |
TPointD getStartCenter() const;
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void draw();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// FreeDeform
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class FreeDeform {
|
|
Shinya Kitaoka |
120a6e |
DeformTool *m_deformTool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
FreeDeform(DeformTool *deformTool);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
|
|
shun-iwasawa |
9905f5 |
void leftButtonUp();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// MoveSelection
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class MoveSelection {
|
|
Shinya Kitaoka |
120a6e |
DeformTool *m_deformTool;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_lastDelta, m_firstPos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
MoveSelection(DeformTool *deformTool);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDown(const TPointD &pos, const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
shun-iwasawa |
9905f5 |
enum class ScaleType { GLOBAL = 0, HORIZONTAL, VERTICAL };
|
|
caryoscelus |
fb92fd |
|
|
Shinya Kitaoka |
120a6e |
class Scale {
|
|
Shinya Kitaoka |
120a6e |
TPointD m_startCenter;
|
|
Shinya Kitaoka |
120a6e |
bool m_isShiftPressed;
|
|
Shinya Kitaoka |
120a6e |
bool m_isAltPressed;
|
|
Shinya Kitaoka |
120a6e |
bool m_scaleInCenter;
|
|
Shinya Kitaoka |
120a6e |
std::vector<fourpoints> m_startBboxs;</fourpoints>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DeformTool *m_deformTool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
caryoscelus |
fb92fd |
ScaleType m_type;
|
|
caryoscelus |
fb92fd |
Scale(DeformTool *deformTool, ScaleType type);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*! Return intersection between straight line in \b point0, \b point1 and
|
|
Shinya Kitaoka |
120a6e |
straight line for
|
|
Shinya Kitaoka |
120a6e |
\b p parallel to straight line in \b point2, \b point3. */
|
|
Shinya Kitaoka |
120a6e |
TPointD getIntersectionPoint(const TPointD &point0, const TPointD &point1,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &point2, const TPointD &point3,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &p) const;
|
|
Shinya Kitaoka |
120a6e |
/*! Scale \b index point of \b bbox in \b pos and return scaled bbox. */
|
|
Shinya Kitaoka |
120a6e |
FourPoints bboxScale(int index, const FourPoints &oldBbox,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &pos);
|
|
Shinya Kitaoka |
120a6e |
/*! Compute new scale value take care of new position of \b movedIndex point
|
|
Shinya Kitaoka |
120a6e |
* in \b bbox. */
|
|
Shinya Kitaoka |
120a6e |
TPointD computeScaleValue(int movedIndex, const FourPoints newBbox);
|
|
Shinya Kitaoka |
120a6e |
/*! Return \b index point scaled in \b center of \b scaleValue. */
|
|
Shinya Kitaoka |
120a6e |
TPointD getScaledPoint(int index, const FourPoints &oldBbox,
|
|
Shinya Kitaoka |
120a6e |
const TPointD scaleValue, const TPointD center);
|
|
Shinya Kitaoka |
120a6e |
/*! Compute new center after scale of \b bbox \b index point. */
|
|
Shinya Kitaoka |
120a6e |
TPointD getNewCenter(int index, const FourPoints bbox,
|
|
Shinya Kitaoka |
120a6e |
const TPointD scaleValue);
|
|
Shinya Kitaoka |
120a6e |
/*! Scale \b bbox \b index point in pos and if \b m_scaleInCenter is true
|
|
MCCCS |
a0ce32 |
scale in \b center \b bbox symmetric point;
|
|
Shinya Kitaoka |
120a6e |
compute scaleValue. */
|
|
Shinya Kitaoka |
120a6e |
FourPoints bboxScaleInCenter(int index, const FourPoints &oldBbox,
|
|
Shinya Kitaoka |
120a6e |
const TPointD newPos, TPointD &scaleValue,
|
|
Shinya Kitaoka |
120a6e |
const TPointD center, bool recomputeScaleValue);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDown(const TPointD &pos, const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
|
|
shun-iwasawa |
9905f5 |
void leftButtonUp();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<fourpoints> getStartBboxs() const { return m_startBboxs; }</fourpoints>
|
|
Shinya Kitaoka |
120a6e |
TPointD getStartCenter() const { return m_startCenter; }
|
|
Shinya Kitaoka |
120a6e |
bool scaleInCenter() const { return m_scaleInCenter; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
shun-iwasawa |
9905f5 |
}; // namespace DragSelectionTool
|
|
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);
|
|
shun-iwasawa |
9905f5 |
DragSelectionTool::DragTool *createNewScaleTool(
|
|
shun-iwasawa |
9905f5 |
SelectionTool *st, DragSelectionTool::ScaleType type);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// SelectionTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
manongjohn |
19dec5 |
class SelectionTool : public QObject, public TTool, public TSelection::View {
|
|
manongjohn |
19dec5 |
Q_OBJECT
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
bool m_firstTime;
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::DragTool *m_dragTool;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
StrokeGenerator m_track;
|
|
Shinya Kitaoka |
120a6e |
std::vector<tpointd> m_polyline;</tpointd>
|
|
Shinya Kitaoka |
120a6e |
TPointD m_mousePosition;
|
|
Shinya Kitaoka |
120a6e |
TStroke *m_stroke;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// To modify selection
|
|
Shinya Kitaoka |
120a6e |
TPointD m_curPos;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_firstPos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool m_selecting;
|
|
Shinya Kitaoka |
120a6e |
bool m_justSelected;
|
|
Shinya Kitaoka |
120a6e |
bool m_shiftPressed;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
enum {
|
|
Shinya Kitaoka |
120a6e |
Outside,
|
|
Shinya Kitaoka |
120a6e |
Inside,
|
|
Shinya Kitaoka |
120a6e |
DEFORM,
|
|
Shinya Kitaoka |
120a6e |
ROTATION,
|
|
Shinya Kitaoka |
120a6e |
MOVE_CENTER,
|
|
Shinya Kitaoka |
120a6e |
SCALE,
|
|
Shinya Kitaoka |
120a6e |
SCALE_X,
|
|
Shinya Kitaoka |
120a6e |
SCALE_Y,
|
|
Shinya Kitaoka |
120a6e |
GLOBAL_THICKNESS,
|
|
Shinya Kitaoka |
120a6e |
ADD_SELECTION
|
|
Shinya Kitaoka |
120a6e |
} m_what; // RV
|
|
caryoscelus |
fb92fd |
|
|
Shinya Kitaoka |
120a6e |
enum {
|
|
Shinya Kitaoka |
120a6e |
P00 = 0,
|
|
Shinya Kitaoka |
120a6e |
P10 = 1,
|
|
Shinya Kitaoka |
120a6e |
P11 = 2,
|
|
Shinya Kitaoka |
120a6e |
P01 = 3,
|
|
Shinya Kitaoka |
120a6e |
PM0 = 4,
|
|
Shinya Kitaoka |
120a6e |
P1M = 5,
|
|
Shinya Kitaoka |
120a6e |
PM1 = 6,
|
|
Shinya Kitaoka |
120a6e |
P0M = 7,
|
|
Shinya Kitaoka |
120a6e |
NONE
|
|
Shinya Kitaoka |
120a6e |
} m_selectedPoint; // RV
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int m_cursorId;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool m_leftButtonMousePressed;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::FourPoints m_selectingRect;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<dragselectiontool::fourpoints> m_bboxs;</dragselectiontool::fourpoints>
|
|
Shinya Kitaoka |
120a6e |
std::vector<tpointd> m_centers;</tpointd>
|
|
Shinya Kitaoka |
120a6e |
std::vector<freedeformer *=""> m_freeDeformers;</freedeformer>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TEnumProperty m_strokeSelectionType;
|
|
Shinya Kitaoka |
120a6e |
TPropertyGroup m_prop;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual void updateAction(TPointD pos, const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual void modifySelectionOnClick(TImageP image, const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
virtual void doOnActivate() = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void doOnDeactivate() = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Metodi per disegnare la linea della selezione Freehand
|
|
Shinya Kitaoka |
120a6e |
void startFreehand(const TPointD &pos);
|
|
Shinya Kitaoka |
120a6e |
void freehandDrag(const TPointD &pos);
|
|
Shinya Kitaoka |
120a6e |
void closeFreehand(const TPointD &pos);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Metodi per disegnare la linea della selezione Polyline
|
|
Shinya Kitaoka |
120a6e |
void addPointPolyline(const TPointD &pos);
|
|
Shinya Kitaoka |
120a6e |
void closePolyline(const TPointD &pos);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void updateTranslation() override;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void drawPolylineSelection();
|
|
Shinya Kitaoka |
120a6e |
void drawRectSelection(const TImage *image);
|
|
shun-iwasawa |
c189d1 |
void drawFreehandSelection();
|
|
Shinya Kitaoka |
120a6e |
void drawCommandHandle(const TImage *image);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::DeformValues m_deformValues;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SelectionTool(int targetType);
|
|
caryoscelus |
fb92fd |
~SelectionTool() override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
ToolType getToolType() const override { return TTool::LevelWriteTool; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPointD getCenter(int index = 0) const;
|
|
Shinya Kitaoka |
120a6e |
void setCenter(const TPointD ¢er, int index = 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int getBBoxsCount() const;
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::FourPoints getBBox(int index = 0) const;
|
|
Shinya Kitaoka |
120a6e |
virtual void setBBox(const DragSelectionTool::FourPoints &points,
|
|
Shinya Kitaoka |
120a6e |
int index = 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FreeDeformer *getFreeDeformer(int index = 0) const;
|
|
shun-iwasawa |
9905f5 |
virtual void setNewFreeDeformer() = 0;
|
|
Shinya Kitaoka |
120a6e |
void clearDeformers();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int getSelectedPoint() const { return m_selectedPoint; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual bool isConstantThickness() const { return true; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool isLevelType() const { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool isSelectedFramesType() const { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool isSameStyleType() const { return false; }
|
|
Shinya Kitaoka |
120a6e |
virtual bool isModifiableSelectionType() const {
|
|
Shinya Kitaoka |
120a6e |
return !(isLevelType() || isSelectedFramesType());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
virtual bool isFloating() const { return false; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual QSet<int> getSelectedStyles() const { return QSet<int>(); }</int></int>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
|
|
Shinya Kitaoka |
473e70 |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override = 0;
|
|
Shinya Kitaoka |
38fd86 |
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override = 0;
|
|
Shinya Kitaoka |
473e70 |
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
|
Shinya Kitaoka |
38fd86 |
void leftButtonDoubleClick(const TPointD &,
|
|
Shinya Kitaoka |
38fd86 |
const TMouseEvent &e) override = 0;
|
|
shun-iwasawa |
7f1e30 |
bool keyDown(QKeyEvent *) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
int getCursorId() const override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
void draw() override = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
TSelection *getSelection() override = 0;
|
|
Shinya Kitaoka |
38fd86 |
virtual bool isSelectionEmpty() = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual void computeBBox() = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
void onActivate() override;
|
|
Shinya Kitaoka |
473e70 |
void onDeactivate() override;
|
|
Shinya Kitaoka |
473e70 |
void onImageChanged() override = 0;
|
|
Shinya Kitaoka |
473e70 |
void onSelectionChanged() override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
bool onPropertyChanged(std::string propertyName) override;
|
|
shun_iwasawa |
d51821 |
|
|
shun_iwasawa |
d51821 |
// returns true if the pressed key is recognized and processed.
|
|
shun_iwasawa |
d51821 |
bool isEventAcceptable(QEvent *e) override;
|
|
manongjohn |
6939a3 |
|
|
manongjohn |
6939a3 |
virtual bool isSelectionEditable() { return true; }
|
|
manongjohn |
19dec5 |
|
|
manongjohn |
19dec5 |
signals:
|
|
manongjohn |
19dec5 |
void clickFlipHorizontal();
|
|
manongjohn |
19dec5 |
void clickFlipVertical();
|
|
manongjohn |
19dec5 |
void clickRotateLeft();
|
|
manongjohn |
19dec5 |
void clickRotateRight();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // SELECTIONTOOL_INCLUDED
|