|
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 |
120a6e |
class RasterFreeDeformer : 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 |
120a6e |
void setPoint(int index, const TPointD &p);
|
|
Shinya Kitaoka |
120a6e |
/*! Helper function. */
|
|
Shinya Kitaoka |
120a6e |
void setPoints(const TPointD &p0, const TPointD &p1, const TPointD &p2,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &p3);
|
|
Shinya Kitaoka |
120a6e |
TRasterP getImage() const { return m_newRas; }
|
|
Shinya Kitaoka |
120a6e |
void deformImage();
|
|
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 |
120a6e |
class UndoRasterDeform : 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 |
120a6e |
void undo() const;
|
|
Shinya Kitaoka |
120a6e |
void redo() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int getSize() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QString getHistoryString() { 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 |
120a6e |
class UndoRasterTransform : 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 |
120a6e |
void undo() const;
|
|
Shinya Kitaoka |
120a6e |
void redo() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int getSize() const { return sizeof(*this); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QString getHistoryString() { return QObject::tr("Transform Raster"); }
|
|
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 |
120a6e |
void applyTransform(FourPoints bbox);
|
|
Shinya Kitaoka |
120a6e |
void applyTransform(TAffine aff, bool modifyCenter);
|
|
Shinya Kitaoka |
120a6e |
void addTransformUndo();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e){};
|
|
Shinya Kitaoka |
120a6e |
void draw(){};
|
|
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 |
120a6e |
class RasterRotationTool : public RasterDeformTool {
|
|
Shinya Kitaoka |
120a6e |
Rotation *m_rotation;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RasterRotationTool(RasterSelectionTool *tool);
|
|
Shinya Kitaoka |
120a6e |
void transform(TAffine aff, double angle);
|
|
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 |
// RasterFreeDeformTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class RasterFreeDeformTool : public RasterDeformTool {
|
|
Shinya Kitaoka |
120a6e |
FreeDeform *m_freeDeform;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RasterFreeDeformTool(RasterSelectionTool *tool);
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
Shinya Kitaoka |
120a6e |
class RasterMoveSelectionTool : public RasterDeformTool {
|
|
Shinya Kitaoka |
120a6e |
MoveSelection *m_moveSelection;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RasterMoveSelectionTool(RasterSelectionTool *tool);
|
|
Shinya Kitaoka |
120a6e |
void transform(TAffine aff);
|
|
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 |
// RasterScaleTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class RasterScaleTool : public RasterDeformTool {
|
|
Shinya Kitaoka |
120a6e |
Scale *m_scale;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RasterScaleTool(RasterSelectionTool *tool, int type);
|
|
Shinya Kitaoka |
120a6e |
/*! Return scale value. */
|
|
Shinya Kitaoka |
120a6e |
TPointD transform(int index, TPointD newPos);
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
} // namespace DragSelectionTool
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// RasterSelectionTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class RasterSelectionTool : 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 |
120a6e |
const TMouseEvent &e);
|
|
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 |
120a6e |
void setBBox(const DragSelectionTool::FourPoints &points, int index = 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setNewFreeDeformer();
|
|
Shinya Kitaoka |
120a6e |
VectorFreeDeformer *getSelectionFreeDeformer() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool isFloating() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDown(const TPointD &pos, const TMouseEvent &);
|
|
Shinya Kitaoka |
120a6e |
void mouseMove(const TPointD &pos, const TMouseEvent &e);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonUp(const TPointD &pos, const TMouseEvent &);
|
|
Shinya Kitaoka |
120a6e |
void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void draw();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TSelection *getSelection();
|
|
Shinya Kitaoka |
120a6e |
bool isSelectionEmpty();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void computeBBox();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void doOnActivate();
|
|
Shinya Kitaoka |
120a6e |
void doOnDeactivate();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void onImageChanged();
|
|
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 |
120a6e |
void onActivate();
|
|
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 |
120a6e |
bool onPropertyChanged(std::string propertyName);
|
|
Shinya Kitaoka |
120a6e |
bool getNoAntialiasingValue() { return m_noAntialiasing.getValue(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
void updateTranslation();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // RASTERSELECTIONTOOL_INCLUDED
|