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