|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "rasterselectiontool.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "vectorselectiontool.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "drawutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tdistort.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/glrasterpainter.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/toonzimageutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/tselectionhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/imageutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace ToolUtils;
|
|
Toshihiro Shimizu |
890ddd |
using namespace DragSelectionTool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// RasterFreeDeformer
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterFreeDeformer::RasterFreeDeformer(TRasterP ras)
|
|
Shinya Kitaoka |
120a6e |
: FreeDeformer(), m_ras(ras), m_newRas(), m_noAntialiasing(false) {
|
|
Shinya Kitaoka |
120a6e |
TRect r = ras->getBounds();
|
|
Shinya Kitaoka |
120a6e |
m_originalP00 = convert(r.getP00());
|
|
Shinya Kitaoka |
120a6e |
m_originalP11 = convert(r.getP11());
|
|
Shinya Kitaoka |
120a6e |
m_newPoints.push_back(m_originalP00);
|
|
Shinya Kitaoka |
120a6e |
m_newPoints.push_back(convert(r.getP10()));
|
|
Shinya Kitaoka |
120a6e |
m_newPoints.push_back(m_originalP11);
|
|
Shinya Kitaoka |
120a6e |
m_newPoints.push_back(convert(r.getP01()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
RasterFreeDeformer::~RasterFreeDeformer() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterFreeDeformer::setPoint(int index, const TPointD &p) {
|
|
Shinya Kitaoka |
120a6e |
m_newPoints[index] = p;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterFreeDeformer::setPoints(const TPointD &p0, const TPointD &p1,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &p2, const TPointD &p3) {
|
|
Shinya Kitaoka |
120a6e |
m_newPoints[0] = p0;
|
|
Shinya Kitaoka |
120a6e |
m_newPoints[1] = p1;
|
|
Shinya Kitaoka |
120a6e |
m_newPoints[2] = p2;
|
|
Shinya Kitaoka |
120a6e |
m_newPoints[3] = p3;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterFreeDeformer::deformImage() {
|
|
Shinya Kitaoka |
120a6e |
TPointD p00 = TPointD();
|
|
Shinya Kitaoka |
120a6e |
TPointD p10 = m_newPoints[1] - m_newPoints[0];
|
|
Shinya Kitaoka |
120a6e |
TPointD p11 = m_newPoints[2] - m_newPoints[0];
|
|
Shinya Kitaoka |
120a6e |
TPointD p01 = m_newPoints[3] - m_newPoints[0];
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double x0 = std::min({p00.x, p10.x, p11.x, p01.x});
|
|
Shinya Kitaoka |
120a6e |
double y0 = std::min({p00.y, p10.y, p11.y, p01.y});
|
|
Shinya Kitaoka |
120a6e |
double x1 = std::max({p00.x, p10.x, p11.x, p01.x});
|
|
Shinya Kitaoka |
120a6e |
double y1 = std::max({p00.y, p10.y, p11.y, p01.y});
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRectD sourceRect(TPointD(), TPointD(m_ras->getLx(), m_ras->getLy()));
|
|
Shinya Kitaoka |
120a6e |
BilinearDistorterBase dist(sourceRect.getP00(), sourceRect.getP10(),
|
|
Shinya Kitaoka |
120a6e |
sourceRect.getP01(), sourceRect.getP11(), p00, p10,
|
|
Shinya Kitaoka |
120a6e |
p01, p11);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRect destRect(tfloor(x0), tfloor(y0), tceil(x1) - 1, tceil(y1) - 1);
|
|
Shinya Kitaoka |
120a6e |
if (TRasterCM32P ras = (TRasterCM32P)m_ras)
|
|
Shinya Kitaoka |
120a6e |
m_newRas = TRasterCM32P(destRect.getLx(), destRect.getLy());
|
|
Shinya Kitaoka |
120a6e |
else if (TRaster32P ras = (TRaster32P)m_ras)
|
|
Shinya Kitaoka |
120a6e |
m_newRas = TRaster32P(destRect.getLx(), destRect.getLy());
|
|
Shinya Kitaoka |
120a6e |
TRasterP newRas(m_newRas); // Someway, conversion from TRasterCM32P to
|
|
Shinya Kitaoka |
120a6e |
// TRasterP is not automatic
|
|
Shinya Kitaoka |
120a6e |
distort(newRas, m_ras, dist, destRect.getP00(),
|
|
Shinya Kitaoka |
120a6e |
m_noAntialiasing ? TRop::ClosestPixel : TRop::Bilinear);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// UndoRasterDeform
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DragSelectionTool::UndoRasterDeform::UndoRasterDeform(RasterSelectionTool *tool)
|
|
Shinya Kitaoka |
120a6e |
: TUndo()
|
|
Shinya Kitaoka |
120a6e |
, m_tool(tool)
|
|
Shinya Kitaoka |
120a6e |
, m_oldBBox(tool->getBBox())
|
|
Shinya Kitaoka |
120a6e |
, m_newBBox()
|
|
Shinya Kitaoka |
120a6e |
, m_oldCenter(tool->getCenter())
|
|
Shinya Kitaoka |
120a6e |
, m_newCenter()
|
|
Shinya Kitaoka |
120a6e |
, m_dim() {
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *selection = (RasterSelection *)tool->getSelection();
|
|
Shinya Kitaoka |
120a6e |
m_oldStrokes = selection->getStrokes();
|
|
Shinya Kitaoka |
120a6e |
m_oldFloatingImageId =
|
|
Shinya Kitaoka |
120a6e |
"UndoRasterDeform_old_floating_" + std::to_string(m_id++);
|
|
Shinya Kitaoka |
120a6e |
TRasterP floatingRas = selection->getFloatingSelection();
|
|
Shinya Kitaoka |
120a6e |
TImageP floatingImage;
|
|
Shinya Kitaoka |
120a6e |
if (TRasterCM32P toonzRas = (TRasterCM32P)(floatingRas)) {
|
|
Shinya Kitaoka |
120a6e |
floatingImage = TToonzImageP(toonzRas, toonzRas->getBounds());
|
|
Shinya Kitaoka |
120a6e |
m_dim = toonzRas->getSize();
|
|
Shinya Kitaoka |
120a6e |
m_pixelSize = toonzRas->getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (TRaster32P fullColorRas = (TRaster32P)(floatingRas)) {
|
|
Shinya Kitaoka |
120a6e |
floatingImage = TRasterImageP(fullColorRas);
|
|
Shinya Kitaoka |
120a6e |
m_dim = fullColorRas->getSize();
|
|
Shinya Kitaoka |
120a6e |
m_pixelSize = fullColorRas->getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (TRasterGR8P grRas = (TRasterGR8P)(floatingRas)) {
|
|
Shinya Kitaoka |
120a6e |
floatingImage = TRasterImageP(grRas);
|
|
Shinya Kitaoka |
120a6e |
m_dim = grRas->getSize();
|
|
Shinya Kitaoka |
120a6e |
m_pixelSize = grRas->getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->add(m_oldFloatingImageId, floatingImage, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::UndoRasterDeform::~UndoRasterDeform() {
|
|
Shinya Kitaoka |
120a6e |
if (TImageCache::instance()->isCached(m_oldFloatingImageId))
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->remove(m_oldFloatingImageId);
|
|
Shinya Kitaoka |
120a6e |
if (TImageCache::instance()->isCached(m_newFloatingImageId))
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->remove(m_newFloatingImageId);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::UndoRasterDeform::registerRasterDeformation() {
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *selection = (RasterSelection *)m_tool->getSelection();
|
|
Shinya Kitaoka |
120a6e |
m_newStrokes = selection->getStrokes();
|
|
Shinya Kitaoka |
120a6e |
m_newFloatingImageId =
|
|
Shinya Kitaoka |
120a6e |
"UndoRasterDeform_new_floating_" + std::to_string(m_id);
|
|
Shinya Kitaoka |
120a6e |
TRasterP floatingRas = selection->getFloatingSelection();
|
|
Shinya Kitaoka |
120a6e |
TImageP floatingImage;
|
|
Shinya Kitaoka |
120a6e |
if (TRasterCM32P toonzRas = (TRasterCM32P)(floatingRas))
|
|
Shinya Kitaoka |
120a6e |
floatingImage = TToonzImageP(toonzRas, toonzRas->getBounds());
|
|
Shinya Kitaoka |
120a6e |
if (TRaster32P fullColorRas = (TRaster32P)(floatingRas))
|
|
Shinya Kitaoka |
120a6e |
floatingImage = TRasterImageP(fullColorRas);
|
|
Shinya Kitaoka |
120a6e |
if (TRasterGR8P grRas = (TRasterGR8P)(floatingRas))
|
|
Shinya Kitaoka |
120a6e |
floatingImage = TRasterImageP(grRas);
|
|
Shinya Kitaoka |
120a6e |
TImageCache::instance()->add(m_newFloatingImageId, floatingImage, false);
|
|
Shinya Kitaoka |
120a6e |
m_newBBox = m_tool->getBBox();
|
|
Shinya Kitaoka |
120a6e |
m_newCenter = m_tool->getCenter();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::UndoRasterDeform::undo() const {
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *selection = (RasterSelection *)m_tool->getSelection();
|
|
Shinya Kitaoka |
120a6e |
if (!selection->isFloating()) return;
|
|
Shinya Kitaoka |
120a6e |
TImageP img = TImageCache::instance()->get(m_oldFloatingImageId, false);
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras;
|
|
Shinya Kitaoka |
120a6e |
if (TToonzImageP ti = (TToonzImageP)(img)) ras = ti->getRaster();
|
|
Shinya Kitaoka |
120a6e |
if (TRasterImageP ri = (TRasterImageP)(img)) ras = ri->getRaster();
|
|
Shinya Kitaoka |
120a6e |
selection->setFloatingSeletion(ras);
|
|
Shinya Kitaoka |
120a6e |
selection->setStrokes(m_oldStrokes);
|
|
Shinya Kitaoka |
120a6e |
m_tool->setBBox(m_oldBBox);
|
|
Shinya Kitaoka |
120a6e |
m_tool->setCenter(m_oldCenter);
|
|
Shinya Kitaoka |
120a6e |
m_tool->invalidate();
|
|
Shinya Kitaoka |
120a6e |
m_tool->decreaseTransformationCount();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::UndoRasterDeform::redo() const {
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *selection = (RasterSelection *)m_tool->getSelection();
|
|
Shinya Kitaoka |
120a6e |
if (!selection->isFloating()) return;
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP img = TImageCache::instance()->get(m_newFloatingImageId, false);
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras;
|
|
Shinya Kitaoka |
120a6e |
if (TToonzImageP ti = (TToonzImageP)(img)) ras = ti->getRaster();
|
|
Shinya Kitaoka |
120a6e |
if (TRasterImageP ri = (TRasterImageP)(img)) ras = ri->getRaster();
|
|
Shinya Kitaoka |
120a6e |
selection->setStrokes(m_newStrokes);
|
|
Shinya Kitaoka |
120a6e |
m_tool->setBBox(m_newBBox);
|
|
Shinya Kitaoka |
120a6e |
m_tool->setCenter(m_newCenter);
|
|
Shinya Kitaoka |
120a6e |
m_tool->invalidate();
|
|
Shinya Kitaoka |
120a6e |
m_tool->increaseTransformationCount();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int DragSelectionTool::UndoRasterDeform::getSize() const {
|
|
Shinya Kitaoka |
120a6e |
return sizeof(*this) + (m_dim.lx * m_dim.ly * m_pixelSize);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int DragSelectionTool::UndoRasterDeform::m_id = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// UndoRasterTransform
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::UndoRasterTransform::UndoRasterTransform(
|
|
Shinya Kitaoka |
120a6e |
RasterSelectionTool *tool)
|
|
Shinya Kitaoka |
120a6e |
: m_tool(tool) {
|
|
Shinya Kitaoka |
120a6e |
m_oldDeformValues = m_tool->m_deformValues;
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *selection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<rasterselection *="">(tool->getSelection());</rasterselection>
|
|
Shinya Kitaoka |
120a6e |
m_oldTransform = selection->getTransformation();
|
|
Shinya Kitaoka |
120a6e |
m_oldCenter = tool->getCenter();
|
|
Shinya Kitaoka |
120a6e |
m_oldBbox = tool->getBBox();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::UndoRasterTransform::setChangedValues() {
|
|
Shinya Kitaoka |
120a6e |
m_newDeformValues = m_tool->m_deformValues;
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *selection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<rasterselection *="">(m_tool->getSelection());</rasterselection>
|
|
Shinya Kitaoka |
120a6e |
m_newTransform = selection->getTransformation();
|
|
Shinya Kitaoka |
120a6e |
m_newCenter = m_tool->getCenter();
|
|
Shinya Kitaoka |
120a6e |
m_newBbox = m_tool->getBBox();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::UndoRasterTransform::undo() const {
|
|
Shinya Kitaoka |
120a6e |
m_tool->transformFloatingSelection(m_oldTransform, m_oldCenter, m_oldBbox);
|
|
Shinya Kitaoka |
120a6e |
m_tool->m_deformValues = m_oldDeformValues;
|
|
Shinya Kitaoka |
120a6e |
m_tool->decreaseTransformationCount();
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::UndoRasterTransform::redo() const {
|
|
Shinya Kitaoka |
120a6e |
m_tool->transformFloatingSelection(m_newTransform, m_newCenter, m_newBbox);
|
|
Shinya Kitaoka |
120a6e |
m_tool->m_deformValues = m_newDeformValues;
|
|
Shinya Kitaoka |
120a6e |
m_tool->increaseTransformationCount();
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
// RasterDeformTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::RasterDeformTool::RasterDeformTool(RasterSelectionTool *tool,
|
|
Shinya Kitaoka |
120a6e |
bool freeDeformer)
|
|
Shinya Kitaoka |
120a6e |
: DeformTool(tool)
|
|
Shinya Kitaoka |
120a6e |
, m_transformUndo(0)
|
|
Shinya Kitaoka |
120a6e |
, m_deformUndo(0)
|
|
Shinya Kitaoka |
120a6e |
, m_isFreeDeformer(freeDeformer) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_isFreeDeformer) m_transformUndo = new UndoRasterTransform(tool);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterDeformTool::applyTransform(FourPoints bbox) {
|
|
Shinya Kitaoka |
120a6e |
RasterSelectionTool *tool = (RasterSelectionTool *)getTool();
|
|
Shinya Kitaoka |
120a6e |
tool->setNewFreeDeformer();
|
|
Shinya Kitaoka |
120a6e |
if (!m_deformUndo) m_deformUndo = new UndoRasterDeform(tool);
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *selection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<rasterselection *="">(tool->getSelection());</rasterselection>
|
|
Shinya Kitaoka |
120a6e |
assert(selection);
|
|
Shinya Kitaoka |
120a6e |
FourPoints realBbox = bbox * selection->getTransformation().inv();
|
|
Shinya Kitaoka |
120a6e |
RasterFreeDeformer *freeDeformer =
|
|
Shinya Kitaoka |
120a6e |
(RasterFreeDeformer *)tool->getFreeDeformer();
|
|
Shinya Kitaoka |
120a6e |
freeDeformer->setNoAntialiasing(tool->getNoAntialiasingValue());
|
|
Shinya Kitaoka |
120a6e |
freeDeformer->setPoints(realBbox.getP00(), realBbox.getP10(),
|
|
Shinya Kitaoka |
120a6e |
realBbox.getP11(), realBbox.getP01());
|
|
Shinya Kitaoka |
120a6e |
freeDeformer->deformImage();
|
|
Shinya Kitaoka |
120a6e |
selection->setFloatingSeletion(freeDeformer->getImage());
|
|
Shinya Kitaoka |
120a6e |
VectorFreeDeformer *vectorFreeDeformer = tool->getSelectionFreeDeformer();
|
|
Shinya Kitaoka |
120a6e |
if (vectorFreeDeformer) {
|
|
Shinya Kitaoka |
120a6e |
vectorFreeDeformer->setPoints(realBbox.getP00(), realBbox.getP10(),
|
|
Shinya Kitaoka |
120a6e |
realBbox.getP11(), realBbox.getP01());
|
|
Shinya Kitaoka |
120a6e |
vectorFreeDeformer->deformImage();
|
|
Shinya Kitaoka |
120a6e |
TVectorImage *vi = vectorFreeDeformer->getDeformedImage();
|
|
Shinya Kitaoka |
120a6e |
std::vector<tstroke> newStrokes;</tstroke>
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)vi->getStrokeCount(); i++)
|
|
Shinya Kitaoka |
120a6e |
newStrokes.push_back(*(vi->getStroke(i)));
|
|
Shinya Kitaoka |
120a6e |
selection->setStrokes(newStrokes);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
tool->m_deformValues.m_isSelectionModified = true;
|
|
Shinya Kitaoka |
120a6e |
if (!m_isDragging) tool->notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterDeformTool::applyTransform(TAffine aff,
|
|
Shinya Kitaoka |
120a6e |
bool modifyCenter) {
|
|
Shinya Kitaoka |
120a6e |
m_transform *= aff;
|
|
Shinya Kitaoka |
120a6e |
RasterSelectionTool *tool = dynamic_cast<rasterselectiontool *="">(getTool());</rasterselectiontool>
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *rasterSelection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<rasterselection *="">(getTool()->getSelection());</rasterselection>
|
|
Shinya Kitaoka |
120a6e |
rasterSelection->transform(aff);
|
|
Shinya Kitaoka |
120a6e |
tool->setBBox(tool->getBBox() * aff);
|
|
Shinya Kitaoka |
120a6e |
if (modifyCenter) tool->setCenter(aff * tool->getCenter());
|
|
Shinya Kitaoka |
120a6e |
if (!m_isDragging && !rasterSelection->isFloating())
|
|
Shinya Kitaoka |
120a6e |
rasterSelection->makeFloating();
|
|
Shinya Kitaoka |
120a6e |
else if (!m_isDragging)
|
|
Shinya Kitaoka |
120a6e |
tool->notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterDeformTool::addTransformUndo() {
|
|
Shinya Kitaoka |
120a6e |
RasterSelection *rasterSelection =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<rasterselection *="">(getTool()->getSelection());</rasterselection>
|
|
Shinya Kitaoka |
120a6e |
if (!rasterSelection || !rasterSelection->isFloating()) return;
|
|
Shinya Kitaoka |
120a6e |
RasterSelectionTool *tool = dynamic_cast<rasterselectiontool *="">(getTool());</rasterselectiontool>
|
|
Shinya Kitaoka |
120a6e |
assert(tool);
|
|
Shinya Kitaoka |
120a6e |
if (!m_isFreeDeformer) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_transformUndo) return;
|
|
Shinya Kitaoka |
120a6e |
m_transformUndo->setChangedValues();
|
|
Shinya Kitaoka |
120a6e |
m_transform = TAffine();
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(m_transformUndo);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (!m_deformUndo) return;
|
|
Shinya Kitaoka |
120a6e |
m_deformUndo->registerRasterDeformation();
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(m_deformUndo);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
tool->increaseTransformationCount();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// RasterRotationTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::RasterRotationTool::RasterRotationTool(
|
|
Shinya Kitaoka |
120a6e |
RasterSelectionTool *tool)
|
|
Shinya Kitaoka |
120a6e |
: RasterDeformTool(tool, false) {
|
|
Shinya Kitaoka |
120a6e |
m_rotation = new Rotation(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterRotationTool::transform(TAffine aff,
|
|
Shinya Kitaoka |
120a6e |
double angle) {
|
|
Shinya Kitaoka |
120a6e |
applyTransform(aff, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterRotationTool::leftButtonDrag(
|
|
Shinya Kitaoka |
120a6e |
const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_rotation->leftButtonDrag(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterRotationTool::draw() { m_rotation->draw(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// RasterFreeDeformTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::RasterFreeDeformTool::RasterFreeDeformTool(
|
|
Shinya Kitaoka |
120a6e |
RasterSelectionTool *tool)
|
|
Shinya Kitaoka |
120a6e |
: RasterDeformTool(tool, true) {
|
|
Shinya Kitaoka |
120a6e |
m_freeDeform = new FreeDeform(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterFreeDeformTool::leftButtonDrag(
|
|
Shinya Kitaoka |
120a6e |
const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_freeDeform->leftButtonDrag(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// RasterMoveSelectionTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::RasterMoveSelectionTool::RasterMoveSelectionTool(
|
|
Shinya Kitaoka |
120a6e |
RasterSelectionTool *tool)
|
|
Shinya Kitaoka |
120a6e |
: RasterDeformTool(tool, false) {
|
|
Shinya Kitaoka |
120a6e |
m_moveSelection = new MoveSelection(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterMoveSelectionTool::transform(TAffine aff) {
|
|
Shinya Kitaoka |
120a6e |
applyTransform(aff, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterMoveSelectionTool::leftButtonDown(
|
|
Shinya Kitaoka |
120a6e |
const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_moveSelection->leftButtonDown(pos, e);
|
|
Shinya Kitaoka |
120a6e |
RasterDeformTool::leftButtonDown(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterMoveSelectionTool::leftButtonDrag(
|
|
Shinya Kitaoka |
120a6e |
const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_moveSelection->leftButtonDrag(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// RasterScaleTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::RasterScaleTool::RasterScaleTool(RasterSelectionTool *tool,
|
|
Shinya Kitaoka |
120a6e |
int type)
|
|
Shinya Kitaoka |
120a6e |
: RasterDeformTool(tool, true) {
|
|
Shinya Kitaoka |
120a6e |
m_scale = new Scale(this, type);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPointD DragSelectionTool::RasterScaleTool::transform(int index,
|
|
Shinya Kitaoka |
120a6e |
TPointD newPos) {
|
|
Shinya Kitaoka |
120a6e |
SelectionTool *tool = getTool();
|
|
Shinya Kitaoka |
120a6e |
TPointD scaleValue = tool->m_deformValues.m_scaleValue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::vector<fourpoints> startBboxs = m_scale->getStartBboxs();</fourpoints>
|
|
Shinya Kitaoka |
120a6e |
FourPoints bbox =
|
|
Shinya Kitaoka |
120a6e |
m_scale->bboxScaleInCenter(index, startBboxs[0], newPos, scaleValue,
|
|
Shinya Kitaoka |
120a6e |
m_scale->getStartCenter(), true);
|
|
Shinya Kitaoka |
120a6e |
if (bbox == startBboxs[0]) return scaleValue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Se non ho scalato rispetto al centro calcolo la posizione del nuovo centro
|
|
Shinya Kitaoka |
120a6e |
if (!m_scale->scaleInCenter())
|
|
Shinya Kitaoka |
120a6e |
tool->setCenter(m_scale->getNewCenter(index, startBboxs[0], scaleValue));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
applyTransform(bbox);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
tool->setBBox(bbox);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return scaleValue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterScaleTool::leftButtonDown(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_scale->leftButtonDown(pos, e);
|
|
Shinya Kitaoka |
120a6e |
RasterDeformTool::leftButtonDown(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DragSelectionTool::RasterScaleTool::leftButtonDrag(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_scale->leftButtonDrag(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar ModifySavebox("ModifySavebox", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar NoAntialiasing("NoAntialiasing", 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// RasterSelectionTool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterSelectionTool::RasterSelectionTool(int targetType)
|
|
Shinya Kitaoka |
120a6e |
: SelectionTool(targetType)
|
|
Shinya Kitaoka |
120a6e |
, m_transformationCount(0)
|
|
Shinya Kitaoka |
120a6e |
, m_selectionFreeDeformer(0)
|
|
Shinya Kitaoka |
120a6e |
, m_noAntialiasing("No Antialiasing", false)
|
|
Shinya Kitaoka |
120a6e |
, m_modifySavebox("Modify Savebox", false)
|
|
Shinya Kitaoka |
120a6e |
, m_setSaveboxTool(0) {
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_noAntialiasing);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setView(this);
|
|
Shinya Kitaoka |
120a6e |
if (m_targetType & ToonzImage) {
|
|
Shinya Kitaoka |
120a6e |
m_setSaveboxTool = new SetSaveboxTool(this);
|
|
Shinya Kitaoka |
120a6e |
m_modifySavebox.setId("ModifySavebox");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::setBBox(const DragSelectionTool::FourPoints &points,
|
|
Shinya Kitaoka |
120a6e |
int index) {
|
|
Shinya Kitaoka |
120a6e |
if (m_bboxs.empty()) return;
|
|
Shinya Kitaoka |
120a6e |
assert((int)m_bboxs.size() > index);
|
|
Shinya Kitaoka |
120a6e |
m_bboxs[index] = points;
|
|
Shinya Kitaoka |
120a6e |
TAffine aff = m_rasterSelection.getTransformation();
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::FourPoints p = points * aff.inv();
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setSelectionBbox(p.getBox());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::setNewFreeDeformer() {
|
|
Shinya Kitaoka |
120a6e |
if (!m_freeDeformers.empty() || isSelectionEmpty()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageP image = (TImageP)getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!isFloating()) m_rasterSelection.makeFloating();
|
|
Shinya Kitaoka |
120a6e |
m_freeDeformers.push_back(
|
|
Shinya Kitaoka |
120a6e |
new RasterFreeDeformer(m_rasterSelection.getFloatingSelection()));
|
|
Shinya Kitaoka |
120a6e |
std::vector<tstroke> strokes = m_rasterSelection.getOriginalStrokes();</tstroke>
|
|
Shinya Kitaoka |
120a6e |
if (!strokes.empty()) {
|
|
Shinya Kitaoka |
120a6e |
TVectorImage *vi = new TVectorImage();
|
|
Shinya Kitaoka |
120a6e |
std::set<int> indices;</int>
|
|
Shinya Kitaoka |
120a6e |
// Devo deformare anche gli strokes della selezione!!!
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)strokes.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
vi->addStroke(new TStroke(strokes[i]));
|
|
Shinya Kitaoka |
120a6e |
indices.insert(i);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_selectionFreeDeformer = new VectorFreeDeformer(vi, indices);
|
|
Shinya Kitaoka |
120a6e |
m_selectionFreeDeformer->setPreserveThickness(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
VectorFreeDeformer *RasterSelectionTool::getSelectionFreeDeformer() const {
|
|
Shinya Kitaoka |
120a6e |
return m_selectionFreeDeformer;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool RasterSelectionTool::isFloating() const {
|
|
Shinya Kitaoka |
120a6e |
return m_rasterSelection.isFloating();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::modifySelectionOnClick(TImageP image,
|
|
Shinya Kitaoka |
120a6e |
const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
const TXshCell &imageCell = TTool::getImageCell();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return;
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
updateAction(pos, e);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_firstPos = m_curPos = pos;
|
|
Shinya Kitaoka |
120a6e |
if (!m_rasterSelection.isEmpty() && !m_rasterSelection.isFloating() &&
|
|
Shinya Kitaoka |
120a6e |
e.isShiftPressed() && !m_rasterSelection.isTransformed()) {
|
|
Shinya Kitaoka |
120a6e |
m_selectingRect.empty();
|
|
Shinya Kitaoka |
120a6e |
m_transformationCount = 0;
|
|
Shinya Kitaoka |
120a6e |
m_selecting = true;
|
|
Shinya Kitaoka |
120a6e |
} else if (!m_rasterSelection.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
m_selectingRect.empty();
|
|
Shinya Kitaoka |
120a6e |
m_selecting = false;
|
|
Shinya Kitaoka |
120a6e |
if (m_what == Outside && m_rasterSelection.isFloating()) {
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.pasteFloatingSelection();
|
|
Shinya Kitaoka |
120a6e |
} else if (m_what == Outside && !m_rasterSelection.isFloating()) {
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setCurrentImage(image, imageCell);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_bboxs.clear();
|
|
Shinya Kitaoka |
120a6e |
m_selectingRect.empty();
|
|
Shinya Kitaoka |
120a6e |
m_selecting = true;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (!m_rasterSelection.isFloating() &&
|
|
Shinya Kitaoka |
120a6e |
(m_what == Inside || m_what == ROTATION || m_what == SCALE ||
|
|
Shinya Kitaoka |
120a6e |
m_what == SCALE_X || m_what == SCALE_Y)) {
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.makeFloating();
|
|
Shinya Kitaoka |
120a6e |
m_transformationCount = 0;
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setTransformationCount(0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (m_what == Outside) {
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setCurrentImage(image, imageCell);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_bboxs.clear();
|
|
Shinya Kitaoka |
120a6e |
m_selectingRect.empty();
|
|
Shinya Kitaoka |
120a6e |
m_selecting = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::leftButtonDown(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
if (m_setSaveboxTool && m_modifySavebox.getValue()) {
|
|
Shinya Kitaoka |
120a6e |
m_setSaveboxTool->leftButtonDown(pos);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
SelectionTool::leftButtonDown(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
if (m_setSaveboxTool && m_modifySavebox.getValue()) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_leftButtonMousePressed)
|
|
Shinya Kitaoka |
120a6e |
m_cursorId = m_setSaveboxTool->getCursorId(pos);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
SelectionTool::mouseMove(pos, e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::leftButtonDrag(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
if (m_setSaveboxTool && m_modifySavebox.getValue()) {
|
|
Shinya Kitaoka |
120a6e |
m_setSaveboxTool->leftButtonDrag(pos);
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (m_dragTool) {
|
|
Shinya Kitaoka |
120a6e |
m_dragTool->leftButtonDrag(pos, e);
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TImageP image = getImage(true);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_selecting) {
|
|
Shinya Kitaoka |
120a6e |
if (m_strokeSelectionType.getValue() == RECT_SELECTION) {
|
|
Shinya Kitaoka |
120a6e |
TDimension imageSize;
|
|
Shinya Kitaoka |
120a6e |
if (ti)
|
|
Shinya Kitaoka |
120a6e |
imageSize = ti->getSize();
|
|
Shinya Kitaoka |
120a6e |
else if (ri)
|
|
Shinya Kitaoka |
120a6e |
imageSize = ri->getRaster()->getSize();
|
|
Shinya Kitaoka |
120a6e |
TPointD p(imageSize.lx % 2 ? 0.5 : 0.0, imageSize.ly % 2 ? 0.5 : 0.0);
|
|
Shinya Kitaoka |
120a6e |
TRectD rectD(tround(std::min(m_firstPos.x, pos.x) - p.x) + p.x,
|
|
Shinya Kitaoka |
120a6e |
tround(std::min(m_firstPos.y, pos.y) - p.y) + p.y,
|
|
Shinya Kitaoka |
120a6e |
tround(std::max(m_firstPos.x, pos.x) - p.x) + p.x,
|
|
Shinya Kitaoka |
120a6e |
tround(std::max(m_firstPos.y, pos.y) - p.y) + p.y);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selectingRect = rectD;
|
|
Shinya Kitaoka |
120a6e |
m_bboxs.clear();
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
} else if (m_strokeSelectionType.getValue() == FREEHAND_SELECTION)
|
|
Shinya Kitaoka |
120a6e |
freehandDrag(pos);
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double pixelSize = getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
TTool::Application *app = TTool::getApplication();
|
|
Shinya Kitaoka |
120a6e |
if (!app || m_justSelected || !m_selecting ||
|
|
Shinya Kitaoka |
120a6e |
tdistance2(pos, m_curPos) < 9.0 * pixelSize * pixelSize)
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_curPos = pos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_strokeSelectionType.getValue() == FREEHAND_SELECTION)
|
|
Shinya Kitaoka |
120a6e |
freehandDrag(pos);
|
|
Shinya Kitaoka |
120a6e |
else if (m_strokeSelectionType.getValue() == RECT_SELECTION) {
|
|
Shinya Kitaoka |
120a6e |
bool selectOverlappingStroke = (m_firstPos.x > pos.x);
|
|
Shinya Kitaoka |
120a6e |
TRectD rect(m_firstPos, pos);
|
|
Shinya Kitaoka |
120a6e |
m_selectingRect = rect;
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::leftButtonUp(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
if (m_setSaveboxTool && m_modifySavebox.getValue()) {
|
|
Shinya Kitaoka |
120a6e |
m_setSaveboxTool->leftButtonUp(pos);
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_leftButtonMousePressed = false;
|
|
Shinya Kitaoka |
120a6e |
m_shiftPressed = false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_dragTool) {
|
|
Shinya Kitaoka |
120a6e |
m_dragTool->leftButtonUp(pos, e);
|
|
Shinya Kitaoka |
120a6e |
delete m_dragTool;
|
|
Shinya Kitaoka |
120a6e |
m_dragTool = 0;
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!m_selecting) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Se stavo modificando la selezione la completo
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TImageP image = getImage(true);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (ti || ri) {
|
|
Shinya Kitaoka |
120a6e |
if (m_strokeSelectionType.getValue() == RECT_SELECTION) {
|
|
Shinya Kitaoka |
120a6e |
m_bboxs.push_back(m_selectingRect);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.select(
|
|
Shinya Kitaoka |
120a6e |
TRectD(m_selectingRect.getP00(), m_selectingRect.getP11()));
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setFrameId(getCurrentFid());
|
|
Shinya Kitaoka |
120a6e |
m_selectingRect.empty();
|
|
Shinya Kitaoka |
120a6e |
} else if (m_strokeSelectionType.getValue() == FREEHAND_SELECTION) {
|
|
Shinya Kitaoka |
120a6e |
closeFreehand(pos);
|
|
Shinya Kitaoka |
120a6e |
if (m_stroke->getControlPointCount() > 5) {
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.select(*m_stroke);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setFrameId(getCurrentFid());
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_selecting = false;
|
|
Shinya Kitaoka |
120a6e |
m_justSelected = false;
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::leftButtonDoubleClick(const TPointD &pos,
|
|
Shinya Kitaoka |
120a6e |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
TImageP image = getImage(true);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return;
|
|
Shinya Kitaoka |
120a6e |
if (m_strokeSelectionType.getValue() == POLYLINE_SELECTION &&
|
|
Shinya Kitaoka |
120a6e |
!m_polyline.empty()) {
|
|
Shinya Kitaoka |
120a6e |
closePolyline(pos);
|
|
Shinya Kitaoka |
120a6e |
if (m_stroke) {
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.select(*m_stroke);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setFrameId(getCurrentFid());
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_selecting = false;
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*-- Paste後のフローティング状態の画像の描画 --*/
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::drawFloatingSelection() {
|
|
Shinya Kitaoka |
120a6e |
double pixelSize =
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentTool()->getTool()->getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TAffine aff = m_rasterSelection.getTransformation();
|
|
Shinya Kitaoka |
120a6e |
glPushMatrix();
|
|
Shinya Kitaoka |
120a6e |
tglMultMatrix(aff);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// draw m_floatingSelection
|
|
Shinya Kitaoka |
120a6e |
if (isFloating()) {
|
|
Shinya Kitaoka |
120a6e |
TRasterP floatingSelection = m_rasterSelection.getFloatingSelection();
|
|
Shinya Kitaoka |
120a6e |
TImageP app;
|
|
Shinya Kitaoka |
120a6e |
if (TRasterCM32P toonzRas = (TRasterCM32P)(floatingSelection))
|
|
Shinya Kitaoka |
120a6e |
app = TToonzImageP(toonzRas, toonzRas->getBounds());
|
|
Shinya Kitaoka |
120a6e |
if (TRaster32P fullColorRas = (TRaster32P)(floatingSelection))
|
|
Shinya Kitaoka |
120a6e |
app = TRasterImageP(fullColorRas);
|
|
Shinya Kitaoka |
120a6e |
if (TRasterGR8P grRas = (TRasterGR8P)(floatingSelection))
|
|
Shinya Kitaoka |
120a6e |
app = TRasterImageP(grRas);
|
|
Shinya Kitaoka |
120a6e |
app->setPalette(m_rasterSelection.getCurrentImage()->getPalette());
|
|
Shinya Kitaoka |
120a6e |
FourPoints points = getBBox() * aff.inv();
|
|
Shinya Kitaoka |
120a6e |
TRectD bbox = points.getBox();
|
|
Shinya Kitaoka |
120a6e |
TPointD center((bbox.getP00() + bbox.getP11()) * 0.5);
|
|
Shinya Kitaoka |
120a6e |
if (TToonzImageP ti = (TToonzImageP)app)
|
|
Shinya Kitaoka |
120a6e |
GLRasterPainter::drawRaster(TTranslation(center), ti, false);
|
|
Shinya Kitaoka |
120a6e |
if (TRasterImageP ri = (TRasterImageP)app)
|
|
Shinya Kitaoka |
120a6e |
GLRasterPainter::drawRaster(TTranslation(center), ri, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::vector<tstroke> strokes = m_rasterSelection.getStrokes();</tstroke>
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)strokes.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TStroke stroke = strokes[i];
|
|
Shinya Kitaoka |
120a6e |
glEnable(GL_LINE_STIPPLE);
|
|
Shinya Kitaoka |
120a6e |
glLineStipple(1, 0xF0F0);
|
|
Shinya Kitaoka |
120a6e |
tglColor(TPixel32::Black);
|
|
Shinya Kitaoka |
120a6e |
drawStrokeCenterline(stroke, pixelSize);
|
|
Shinya Kitaoka |
120a6e |
glDisable(GL_LINE_STIPPLE);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::draw() {
|
|
Shinya Kitaoka |
120a6e |
TImageP image = getImage(false);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_setSaveboxTool && m_modifySavebox.getValue()) {
|
|
Shinya Kitaoka |
120a6e |
m_setSaveboxTool->draw();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
glPushMatrix();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*-- フローティング画像の描画 --*/
|
|
Shinya Kitaoka |
120a6e |
drawFloatingSelection();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_strokeSelectionType.getValue() == POLYLINE_SELECTION &&
|
|
Shinya Kitaoka |
120a6e |
!m_rasterSelection.isFloating())
|
|
Shinya Kitaoka |
120a6e |
drawPolylineSelection();
|
|
Shinya Kitaoka |
120a6e |
if (m_rasterSelection.isEmpty()) m_bboxs.clear();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*-- 選択範囲の変形ハンドルの描画 --*/
|
|
Shinya Kitaoka |
120a6e |
if (getBBoxsCount() > 0) drawCommandHandle(image.getPointer());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*-- 選択範囲の四角形の描画 --*/
|
|
Shinya Kitaoka |
120a6e |
if (m_selecting && !m_selectingRect.isEmpty())
|
|
Shinya Kitaoka |
120a6e |
drawRectSelection(image.getPointer());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*-- バウンディングボックスの描画 --*/
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
if(ti)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
TRectD saveBox = ToonzImageUtils::convertRasterToWorld(ti->getSavebox(), ti);
|
|
Shinya Kitaoka |
120a6e |
drawRect(saveBox.enlarge(0.5)*ti->getSubsampling(), TPixel32::Black, 0x5555,
|
|
Shinya Kitaoka |
120a6e |
true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TSelection *RasterSelectionTool::getSelection() { return &m_rasterSelection; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool RasterSelectionTool::isSelectionEmpty() {
|
|
Shinya Kitaoka |
120a6e |
TImageP image = getImage(false);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return m_rasterSelection.isEmpty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::computeBBox() {
|
|
Shinya Kitaoka |
120a6e |
TImageP image = getImage(false);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_deformValues.reset();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_bboxs.clear();
|
|
Shinya Kitaoka |
120a6e |
m_centers.clear();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
std::vector<tstroke> strokes = m_rasterSelection.getStrokes();</tstroke>
|
|
Shinya Kitaoka |
120a6e |
TRectD strokesRect = m_rasterSelection.getStrokesBound(strokes);
|
|
Shinya Kitaoka |
120a6e |
DragSelectionTool::FourPoints p;
|
|
Shinya Kitaoka |
120a6e |
p = strokesRect;
|
|
Shinya Kitaoka |
120a6e |
p = p * m_rasterSelection.getTransformation();
|
|
Shinya Kitaoka |
120a6e |
m_bboxs.push_back(p);
|
|
Shinya Kitaoka |
120a6e |
m_centers.push_back((p.getP00() + p.getP11()) * 0.5);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setSelectionBbox(strokesRect);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_freeDeformers.empty()) clearPointerContainer(m_freeDeformers);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_selectionFreeDeformer) {
|
|
Shinya Kitaoka |
120a6e |
delete m_selectionFreeDeformer;
|
|
Shinya Kitaoka |
120a6e |
m_selectionFreeDeformer = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::doOnActivate() {
|
|
Shinya Kitaoka |
120a6e |
const TXshCell &imageCell = TTool::getImageCell();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageP image =
|
|
Shinya Kitaoka |
120a6e |
imageCell.getImage(false, 1); // => See the onImageChanged() warning !
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
if (!ti && !ri) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setCurrentImage(image, imageCell);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_noAntialiasing.setValue(NoAntialiasing);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setNoAntialiasing(m_noAntialiasing.getValue());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::doOnDeactivate() {
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentSelection()->setSelection(0);
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setCurrentImage(0, TXshCell());
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.selectNone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::onImageChanged() {
|
|
Shinya Kitaoka |
120a6e |
// ATTENTION: using getImage(false, 1) *works* here, but it's trickier than
|
|
Shinya Kitaoka |
120a6e |
// you could
|
|
Shinya Kitaoka |
120a6e |
// expect. It works because:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// 1. Invoking getImage(true) after getImage(false, 1) will return the same
|
|
Shinya Kitaoka |
120a6e |
// image
|
|
Shinya Kitaoka |
120a6e |
// 2. The cached fullsampled image may be in the 'not modified' ImageManager
|
|
Shinya Kitaoka |
120a6e |
// state.
|
|
Shinya Kitaoka |
120a6e |
// Users could then alter the required image level subsampling - but doing
|
|
Shinya Kitaoka |
120a6e |
// so will
|
|
Shinya Kitaoka |
120a6e |
// immediately redirect here through 'onXshLevelChanged()' (thus resetting
|
|
Shinya Kitaoka |
120a6e |
// the subs back to 1).
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TImageP image = getImage(false, 1);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = image;
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP ri = image;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if ((!ti && !ri) || image != m_rasterSelection.getCurrentImage())
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.selectNone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::transformFloatingSelection(
|
|
Shinya Kitaoka |
120a6e |
const TAffine &affine, const TPointD ¢er,
|
|
Shinya Kitaoka |
120a6e |
const DragSelectionTool::FourPoints &points) {
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setTransformation(affine);
|
|
Shinya Kitaoka |
120a6e |
if (isFloating()) {
|
|
Shinya Kitaoka |
120a6e |
setBBox(points);
|
|
Shinya Kitaoka |
120a6e |
setCenter(center);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::increaseTransformationCount() {
|
|
Shinya Kitaoka |
120a6e |
if (m_rasterSelection.getTransformationCount() != m_transformationCount)
|
|
Shinya Kitaoka |
120a6e |
m_transformationCount = 0;
|
|
Shinya Kitaoka |
120a6e |
m_transformationCount++;
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setTransformationCount(m_transformationCount);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::decreaseTransformationCount() {
|
|
Shinya Kitaoka |
120a6e |
m_transformationCount--;
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setTransformationCount(m_transformationCount);
|
|
Shinya Kitaoka |
120a6e |
if (m_rasterSelection.getTransformationCount() == 0)
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.pasteFloatingSelection();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::onActivate() {
|
|
Shinya Kitaoka |
120a6e |
if (m_firstTime) {
|
|
Shinya Kitaoka |
120a6e |
if (m_targetType & ToonzImage)
|
|
Shinya Kitaoka |
120a6e |
m_modifySavebox.setValue(ModifySavebox ? 1 : 0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SelectionTool::onActivate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool RasterSelectionTool::onPropertyChanged(std::string propertyName) {
|
|
Shinya Kitaoka |
120a6e |
if (!SelectionTool::onPropertyChanged(propertyName)) return false;
|
|
Shinya Kitaoka |
120a6e |
if (m_targetType & ToonzImage) {
|
|
Shinya Kitaoka |
120a6e |
ModifySavebox = (int)(m_modifySavebox.getValue());
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (propertyName == m_noAntialiasing.getName()) {
|
|
Shinya Kitaoka |
120a6e |
NoAntialiasing = m_noAntialiasing.getValue() ? 1 : 0;
|
|
Shinya Kitaoka |
120a6e |
m_rasterSelection.setNoAntialiasing(m_noAntialiasing.getValue());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void RasterSelectionTool::updateTranslation() {
|
|
Shinya Kitaoka |
120a6e |
if (m_targetType & ToonzImage)
|
|
Shinya Kitaoka |
120a6e |
m_modifySavebox.setQStringName(tr("Modify Savebox"));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_noAntialiasing.setQStringName(tr("No Antialiasing"));
|
|
Shinya Kitaoka |
120a6e |
SelectionTool::updateTranslation();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterSelectionTool toonzRasterSelectionTool(TTool::ToonzImage);
|
|
Toshihiro Shimizu |
890ddd |
RasterSelectionTool fullColorRasterSelectionTool(TTool::RasterImage);
|