tahoma2d/toonz/sources/tnztools/rasterselectiontool.h

247 lines
7.3 KiB
C
Raw Normal View History

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