Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzTools includes
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "tools/toolcommandids.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "historytypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttileset.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttilesaver.h"
Toshihiro Shimizu 890ddd
#include "toonz/trasterimageutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/strokegenerator.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "bluredbrush.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "drawutil.h"
Toshihiro Shimizu 890ddd
#include "tinbetween.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToolUtils;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define NORMALERASE L"Normal"
Toshihiro Shimizu 890ddd
#define RECTERASE L"Rectangular"
Toshihiro Shimizu 890ddd
#define FREEHANDERASE L"Freehand"
Toshihiro Shimizu 890ddd
#define POLYLINEERASE L"Polyline"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::DoubleVar FullcolorEraseSize("FullcolorEraseSize", 5);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar FullcolorEraseHardness("FullcolorEraseHardness", 100);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar FullcolorEraserOpacity("FullcolorEraserOpacity", 100);
Toshihiro Shimizu 890ddd
TEnv::StringVar FullcolorEraserType("FullcolorEraseType", "Normal");
Toshihiro Shimizu 890ddd
TEnv::IntVar FullcolorEraserInvert("FullcolorEraseInvert", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FullcolorEraserRange("FullcolorEraseRange", 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace  stuff
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int computeThickness(int pressure, const TIntPairProperty &property)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double p = pressure / 255.0;
Toshihiro Shimizu 890ddd
	double t = p * p * p;
Toshihiro Shimizu 890ddd
	int thick0 = property.getValue().first;
Toshihiro Shimizu 890ddd
	int thick1 = property.getValue().second;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return tround(thick0 + (thick1 - thick0) * t);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void eraseImage(const TRasterImageP &ri, const TRaster32P &image, const TPoint &pos, bool invert)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect rasBounds = ri->getRaster()->getBounds();
Toshihiro Shimizu 890ddd
	TRect imageBounds = image->getBounds() + pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (invert) {
Toshihiro Shimizu 890ddd
		TRect rect(imageBounds.x0, rasBounds.y0, rasBounds.x1, imageBounds.y0 - 1);
Toshihiro Shimizu 890ddd
		TRasterImageUtils::eraseRect(ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		rect = TRect(imageBounds.x1 + 1, imageBounds.y0, rasBounds.x1, rasBounds.y1);
Toshihiro Shimizu 890ddd
		TRasterImageUtils::eraseRect(ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		rect = TRect(rasBounds.x0, imageBounds.y1 + 1, imageBounds.x1, rasBounds.y1);
Toshihiro Shimizu 890ddd
		TRasterImageUtils::eraseRect(ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		rect = TRect(rasBounds.x0, rasBounds.y0, imageBounds.x0 - 1, imageBounds.y1);
Toshihiro Shimizu 890ddd
		TRasterImageUtils::eraseRect(ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P workRas;
Toshihiro Shimizu 890ddd
	if (TRasterGR8P ras = ri->getRaster()) {
Toshihiro Shimizu 890ddd
		workRas = TRaster32P(imageBounds.getSize());
Toshihiro Shimizu 890ddd
		TRop::convert(workRas, ras->extract(imageBounds));
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		workRas = ri->getRaster()->extract(imageBounds);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int y;
Toshihiro Shimizu 890ddd
	for (y = 0; y < workRas->getLy(); y++) {
Toshihiro Shimizu 890ddd
		TPixel32 *outPix = workRas->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *outEndPix = outPix + workRas->getLx();
Toshihiro Shimizu 890ddd
		TPixel32 *inPix = image->pixels(y);
Toshihiro Shimizu 890ddd
		for (outPix; outPix != outEndPix; outPix++, inPix++) {
Toshihiro Shimizu 890ddd
			if (outPix->m == 0)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			TPixel32 pix = depremultiply(*outPix);
Toshihiro Shimizu 890ddd
			pix.m = invert ? pix.m * (inPix->m) / 255 : pix.m * (255 - inPix->m) / 255;
Toshihiro Shimizu 890ddd
			*outPix = premultiply(pix);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TRasterGR8P ras = ri->getRaster()) {
Toshihiro Shimizu 890ddd
		TRop::addBackground(workRas, TPixel32::White);
Toshihiro Shimizu 890ddd
		TRop::over(ras, workRas, pos);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RectFullColorUndo : public TFullColorRasterUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRectD m_modifyArea;
Toshihiro Shimizu 890ddd
	TStroke *m_stroke;
Shinya Kitaoka 3bfa54
	std::wstring m_eraseType;
Toshihiro Shimizu 890ddd
	bool m_invert;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	RectFullColorUndo(TTileSetFullColor *tileSet, const TRectD &modifyArea, TStroke stroke,
Shinya Kitaoka 3bfa54
					  std::wstring eraseType,
Toshihiro Shimizu 890ddd
					  TXshSimpleLevel *level, bool invert,
Toshihiro Shimizu 890ddd
					  const TFrameId &frameId)
Toshihiro Shimizu 890ddd
		: TFullColorRasterUndo(tileSet, level, frameId, false, false, 0), m_modifyArea(modifyArea), m_eraseType(eraseType), m_invert(invert)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_stroke = new TStroke(stroke);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~RectFullColorUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		delete m_stroke;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TRasterImageP ri = getImage();
Toshihiro Shimizu 890ddd
		if (!ri)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_eraseType == RECTERASE)
Toshihiro Shimizu 890ddd
			TRect rect = TRasterImageUtils::eraseRect(ri, m_modifyArea);
Toshihiro Shimizu 890ddd
		else if (m_eraseType == FREEHANDERASE || m_eraseType == POLYLINEERASE) {
Toshihiro Shimizu 890ddd
			TPoint pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TRaster32P image = convertStrokeToImage(m_stroke, ri->getRaster()->getBounds(), pos);
Toshihiro Shimizu 890ddd
			if (!image)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			eraseImage(ri, image, pos, m_invert);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return TFullColorRasterUndo::getSize() +
Toshihiro Shimizu 890ddd
			   m_stroke->getControlPointCount() * sizeof(TThickPoint) +
Toshihiro Shimizu 890ddd
			   100 +
Toshihiro Shimizu 890ddd
			   sizeof(this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QString getToolName()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QString("Raster Eraser Tool (Rect)");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::EraserTool;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FullColorEraserUndo : public TFullColorRasterUndo
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::vector<tthickpoint> m_points;</tthickpoint>
Toshihiro Shimizu 890ddd
	int m_size;
Toshihiro Shimizu 890ddd
	double m_hardness;
Toshihiro Shimizu 890ddd
	double m_opacity;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FullColorEraserUndo(TTileSetFullColor *tileSet,
Shinya Kitaoka 3bfa54
						const std::vector<tthickpoint> &points,</tthickpoint>
Toshihiro Shimizu 890ddd
						TXshSimpleLevel *level, const TFrameId &frameId,
Toshihiro Shimizu 890ddd
						int size, double hardness, double opacity)
Toshihiro Shimizu 890ddd
		: TFullColorRasterUndo(tileSet, level, frameId, false, false, 0), m_points(points), m_size(size), m_hardness(hardness), m_opacity(opacity) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_points.size() == 0)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TRasterImageP image = getImage();
Toshihiro Shimizu 890ddd
		TRasterP ras = image->getRaster();
Toshihiro Shimizu 890ddd
		QRadialGradient brushPad = getBrushPad(m_size, m_hardness);
Toshihiro Shimizu 890ddd
		TRaster32P workRaster = TRaster32P(ras->getSize());
Toshihiro Shimizu 890ddd
		TRasterP backUpRas = ras->clone();
Toshihiro Shimizu 890ddd
		workRaster->clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		BluredBrush brush(workRaster, m_size, brushPad, false);
Shinya Kitaoka 3bfa54
		std::vector<tthickpoint> points;</tthickpoint>
Toshihiro Shimizu 890ddd
		points.push_back(m_points[0]);
Toshihiro Shimizu 890ddd
		TRect bbox = brush.getBoundFromPoints(points);
Toshihiro Shimizu 890ddd
		brush.addPoint(m_points[0], 1);
Toshihiro Shimizu 890ddd
		brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
Toshihiro Shimizu 890ddd
		if (m_points.size() > 1) {
Toshihiro Shimizu 890ddd
			points.clear();
Toshihiro Shimizu 890ddd
			points.push_back(m_points[0]);
Toshihiro Shimizu 890ddd
			points.push_back(m_points[1]);
Toshihiro Shimizu 890ddd
			bbox = brush.getBoundFromPoints(points);
Toshihiro Shimizu 890ddd
			brush.addArc(m_points[0], (m_points[1] + m_points[0]) * 0.5, m_points[1], 1, 1);
Toshihiro Shimizu 890ddd
			brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
Toshihiro Shimizu 890ddd
			int i;
Toshihiro Shimizu 890ddd
			for (i = 1; i + 2 < (int)m_points.size(); i = i + 2) {
Toshihiro Shimizu 890ddd
				points.clear();
Toshihiro Shimizu 890ddd
				points.push_back(m_points[i]);
Toshihiro Shimizu 890ddd
				points.push_back(m_points[i + 1]);
Toshihiro Shimizu 890ddd
				points.push_back(m_points[i + 2]);
Toshihiro Shimizu 890ddd
				bbox = brush.getBoundFromPoints(points);
Toshihiro Shimizu 890ddd
				brush.addArc(m_points[i], m_points[i + 1], m_points[i + 2], 1, 1);
Toshihiro Shimizu 890ddd
				brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + TFullColorRasterUndo::getSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QString getToolName()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QString("Raster Eraser Tool");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::EraserTool;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void eraseStroke(const TRasterImageP &ri, TStroke *stroke, std::wstring eraseType,
Toshihiro Shimizu 890ddd
				 bool invert, const TXshSimpleLevelP &level, const TFrameId &frameId)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(stroke);
Toshihiro Shimizu 890ddd
	TPoint pos;
Toshihiro Shimizu 890ddd
	TRasterP ras = ri->getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P image = convertStrokeToImage(stroke, ras->getBounds(), pos);
Toshihiro Shimizu 890ddd
	if (!image)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRect rasterErasedArea = image->getBounds() + pos;
Toshihiro Shimizu 890ddd
	TRect area;
Toshihiro Shimizu 890ddd
	if (!invert)
Toshihiro Shimizu 890ddd
		area = rasterErasedArea.enlarge(2);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		area = ras->getBounds();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTileSetFullColor *tileSet = new TTileSetFullColor(ras->getSize());
Toshihiro Shimizu 890ddd
	tileSet->add(ras, area);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(new RectFullColorUndo(tileSet, convert(area), *stroke, eraseType, level.getPointer(),
Toshihiro Shimizu 890ddd
													   invert, frameId));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	eraseImage(ri, image, pos, invert);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    FullColorEraserTool  definition
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FullColorEraserTool : public TTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_DECLARE_TR_FUNCTIONS(FullColorEraserTool)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	FullColorEraserTool(std::string name);
Toshihiro Shimizu 890ddd
	~FullColorEraserTool();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ToolType getToolType() const { return TTool::LevelWriteTool; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void updateTranslation();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onActivate();
Toshihiro Shimizu 890ddd
	void onDeactivate();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void mouseMove(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getCursorId() const { return ToolCursor::PenCursor; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPropertyGroup *getProperties(int targetType) { return &m_prop; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	bool onPropertyChanged(std::string propertyName);
Toshihiro Shimizu 890ddd
	void onImageChanged();
Toshihiro Shimizu 890ddd
	void onEnter();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void update(const TRasterImageP &ri, TRectD selArea, const TXshSimpleLevelP &level, bool multi = false,
Toshihiro Shimizu 890ddd
				const TFrameId &frameId = -1);
Toshihiro Shimizu 890ddd
	void multiUpdate(const TRectD firstRect, const TRectD lastRect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void multiAreaEraser(TFrameId &firstFid, TFrameId &lastFid,
Toshihiro Shimizu 890ddd
						 TStroke *firstStroke, TStroke *lastStroke);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doMultiEraser(const TImageP &img, double t,
Toshihiro Shimizu 890ddd
					   const TFrameId &fid,
Toshihiro Shimizu 890ddd
					   const TVectorImageP &firstImage,
Toshihiro Shimizu 890ddd
					   const TVectorImageP &lastImage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void resetMulti();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	TPropertyGroup m_prop;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TIntProperty m_size;
Toshihiro Shimizu 890ddd
	TDoubleProperty m_opacity;
Toshihiro Shimizu 890ddd
	TDoubleProperty m_hardness;
Toshihiro Shimizu 890ddd
	TEnumProperty m_eraseType;
Toshihiro Shimizu 890ddd
	TBoolProperty m_invertOption;
Toshihiro Shimizu 890ddd
	TBoolProperty m_multi;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshSimpleLevelP m_level;
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> m_currCell;</int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameId m_firstFrameId,
Toshihiro Shimizu 890ddd
		m_veryFirstFrameId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P m_workRaster;
Toshihiro Shimizu 890ddd
	TRasterP m_backUpRas;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QRadialGradient m_brushPad;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::vector<tthickpoint> m_points;</tthickpoint>
Toshihiro Shimizu 890ddd
	BluredBrush *m_brush;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTileSetFullColor *m_tileSet;
Toshihiro Shimizu 890ddd
	TTileSaverFullColor *m_tileSaver;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	StrokeGenerator m_track;
Shinya Kitaoka 3bfa54
	std::vector<tpointd> m_polyline;</tpointd>
Toshihiro Shimizu 890ddd
	TStroke *m_firstStroke;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD m_selectingRect,
Toshihiro Shimizu 890ddd
		m_firstRect;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD m_mousePos,
Toshihiro Shimizu 890ddd
		m_brushPos,
Toshihiro Shimizu 890ddd
		m_firstPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double m_thick;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_firstTime,
Toshihiro Shimizu 890ddd
		m_selecting,
Toshihiro Shimizu 890ddd
		m_firstFrameSelected,
Toshihiro Shimizu 890ddd
		m_isXsheetCell;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} fullColorEraser(T_Eraser); // Tools are statically instantiated
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
FullColorEraserTool::FullColorEraserTool(std::string name)
Toshihiro Shimizu 890ddd
	: TTool(name), m_size("Size:", 1, 100, 5, false), m_opacity("Opacity:", 0, 100, 100), m_hardness("Hardness:", 0, 100, 100), m_eraseType("Type:"), m_invertOption("Invert", false), m_multi("Frame Range", false), m_currCell(-1, -1), m_brush(0), m_tileSet(0), m_tileSaver(0), m_thick(0.5), m_firstTime(true), m_selecting(false), m_firstFrameSelected(false), m_isXsheetCell(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bind(TTool::RasterImage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_prop.bind(m_size);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_hardness);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_opacity);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_eraseType);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_invertOption);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_multi);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_eraseType.addValue(NORMALERASE);
Toshihiro Shimizu 890ddd
	m_eraseType.addValue(RECTERASE);
Toshihiro Shimizu 890ddd
	m_eraseType.addValue(FREEHANDERASE);
Toshihiro Shimizu 890ddd
	m_eraseType.addValue(POLYLINEERASE);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FullColorEraserTool::~FullColorEraserTool()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_firstStroke;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::updateTranslation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_size.setQStringName(tr("Size:"));
Toshihiro Shimizu 890ddd
	m_opacity.setQStringName(tr("Opacity:"));
Toshihiro Shimizu 890ddd
	m_hardness.setQStringName(tr("Hardness:"));
Toshihiro Shimizu 890ddd
	m_eraseType.setQStringName(tr("Type:"));
Toshihiro Shimizu 890ddd
	m_invertOption.setQStringName(tr("Invert"));
Toshihiro Shimizu 890ddd
	m_multi.setQStringName(tr("Frame Range"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::onActivate()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_firstTime) {
Toshihiro Shimizu 890ddd
		m_firstTime = false;
Toshihiro Shimizu 890ddd
		m_size.setValue(FullcolorEraseSize);
Toshihiro Shimizu 890ddd
		m_opacity.setValue(FullcolorEraserOpacity);
Toshihiro Shimizu 890ddd
		m_hardness.setValue(FullcolorEraseHardness);
Toshihiro Shimizu 890ddd
		m_eraseType.setValue(toWideString(FullcolorEraserType.getValue()));
Toshihiro Shimizu 890ddd
		m_invertOption.setValue((bool)FullcolorEraserInvert);
Toshihiro Shimizu 890ddd
		m_multi.setValue((bool)FullcolorEraserRange);
Toshihiro Shimizu 890ddd
		m_firstTime = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_brushPad = getBrushPad(m_size.getValue(), m_hardness.getValue() * 0.01);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::onDeactivate()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_brushPos = m_mousePos = pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterImageP ri = (TRasterImageP)getImage(true);
Toshihiro Shimizu 890ddd
	if (!ri)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TRectD invalidateRect;
Toshihiro Shimizu 890ddd
	TRasterP ras = ri->getRaster();
Toshihiro Shimizu 890ddd
	if (m_eraseType.getValue() == NORMALERASE) {
Toshihiro Shimizu 890ddd
		TDimension dim = ras->getSize();
Toshihiro Shimizu 890ddd
		double opacity = m_opacity.getValue() * 0.01;
Toshihiro Shimizu 890ddd
		double hardness = m_hardness.getValue() * 0.01;
Toshihiro Shimizu 890ddd
		m_workRaster = TRaster32P(dim);
Toshihiro Shimizu 890ddd
		m_workRaster->clear();
Toshihiro Shimizu 890ddd
		m_backUpRas = ras->clone();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int maxThick = m_size.getValue();
Toshihiro Shimizu 890ddd
		TPointD rasCenter = ras->getCenterD();
Toshihiro Shimizu 890ddd
		TThickPoint point(pos + rasCenter, maxThick);
Toshihiro Shimizu 890ddd
		TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
Toshihiro Shimizu 890ddd
		invalidateRect = TRectD(pos - halfThick, pos + halfThick);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_points.clear();
Toshihiro Shimizu 890ddd
		m_points.push_back(point);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_tileSet = new TTileSetFullColor(ras->getSize());
Toshihiro Shimizu 890ddd
		m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
Toshihiro Shimizu 890ddd
		m_brush = new BluredBrush(m_workRaster, m_size.getValue(), m_brushPad, false);
Toshihiro Shimizu 890ddd
		TRect bbox = m_brush->getBoundFromPoints(m_points);
Toshihiro Shimizu 890ddd
		m_tileSaver->save(bbox);
Toshihiro Shimizu 890ddd
		m_brush->addPoint(point, 1);
Toshihiro Shimizu 890ddd
		m_brush->eraseDrawing(ras, m_backUpRas, bbox, opacity);
Toshihiro Shimizu 890ddd
	} else if (m_eraseType.getValue() == RECTERASE) {
Toshihiro Shimizu 890ddd
		if (m_multi.getValue() && m_firstRect.isEmpty()) {
Toshihiro Shimizu 890ddd
			invalidateRect = m_selectingRect;
Toshihiro Shimizu 890ddd
			m_selectingRect.empty();
Toshihiro Shimizu 890ddd
			invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_selecting = true;
Toshihiro Shimizu 890ddd
		m_selectingRect.x0 = pos.x;
Toshihiro Shimizu 890ddd
		m_selectingRect.y0 = pos.y;
Toshihiro Shimizu 890ddd
		m_selectingRect.x1 = pos.x + 1;
Toshihiro Shimizu 890ddd
		m_selectingRect.y1 = pos.y + 1;
Toshihiro Shimizu 890ddd
		invalidateRect = m_selectingRect;
Toshihiro Shimizu 890ddd
	} else if (m_eraseType.getValue() == FREEHANDERASE || m_eraseType.getValue() == POLYLINEERASE) {
Toshihiro Shimizu 890ddd
		if (m_multi.getValue() && m_firstStroke && !m_firstFrameSelected) {
Toshihiro Shimizu 890ddd
			invalidateRect = m_firstStroke->getBBox();
Toshihiro Shimizu 890ddd
			delete m_firstStroke;
Toshihiro Shimizu 890ddd
			m_firstStroke = 0;
Toshihiro Shimizu 890ddd
			invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_track.clear();
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		double pixelSize2 = getPixelSize() * getPixelSize();
Toshihiro Shimizu 890ddd
		m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
		TPointD dpiScale = m_viewer->getDpiScale();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg ? TPixel32::White : TPixel32::Black;
Toshihiro Shimizu 890ddd
		tglColor(color);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		getViewer()->startForegroundDrawing();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		glScaled(dpiScale.x, dpiScale.y, 1);
Toshihiro Shimizu 890ddd
		if (m_eraseType.getValue() == POLYLINEERASE) {
Toshihiro Shimizu 890ddd
			if (m_polyline.empty() || m_polyline.back() != pos)
Toshihiro Shimizu 890ddd
				m_polyline.push_back(pos);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_track.drawLastFragments();
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
		getViewer()->endForegroundDrawing();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int maxThick = 2 * m_thick;
Toshihiro Shimizu 890ddd
		TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
Toshihiro Shimizu 890ddd
		invalidateRect = TRectD(pos - halfThick, pos + halfThick);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_brushPos = m_mousePos = pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double pixelSize2 = getPixelSize() * getPixelSize();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterImageP ri = (TRasterImageP)getImage(true);
Toshihiro Shimizu 890ddd
	if (!ri)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (m_eraseType.getValue() == NORMALERASE) {
Toshihiro Shimizu 890ddd
		double thickness = m_size.getValue();
Toshihiro Shimizu 890ddd
		TDimension size = m_workRaster->getSize();
Toshihiro Shimizu 890ddd
		TPointD rasCenter = ri->getRaster()->getCenterD();
Toshihiro Shimizu 890ddd
		TThickPoint point(pos + rasCenter, thickness);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TThickPoint old = m_points.back();
Toshihiro Shimizu 890ddd
		if (norm2(point - old) < 4)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
Toshihiro Shimizu 890ddd
		m_points.push_back(mid);
Toshihiro Shimizu 890ddd
		m_points.push_back(point);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int m = m_points.size();
Toshihiro Shimizu 890ddd
		double opacity = m_opacity.getValue() * 0.01;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TThickPoint pa = m_points.front();
Shinya Kitaoka 3bfa54
		std::vector<tthickpoint> points;</tthickpoint>
Toshihiro Shimizu 890ddd
		points.push_back(pa);
Toshihiro Shimizu 890ddd
		points.push_back(mid);
Toshihiro Shimizu 890ddd
		TRect bbox;
Toshihiro Shimizu 890ddd
		TRectD invalidateRect;
Toshihiro Shimizu 890ddd
		if (m == 3) {
Toshihiro Shimizu 890ddd
			TThickPoint pa = m_points.front();
Shinya Kitaoka 3bfa54
			std::vector<tthickpoint> points;</tthickpoint>
Toshihiro Shimizu 890ddd
			points.push_back(pa);
Toshihiro Shimizu 890ddd
			points.push_back(mid);
Toshihiro Shimizu 890ddd
			invalidateRect = ToolUtils::getBounds(points, thickness);
Toshihiro Shimizu 890ddd
			bbox = m_brush->getBoundFromPoints(points);
Toshihiro Shimizu 890ddd
			m_tileSaver->save(bbox);
Toshihiro Shimizu 890ddd
			m_brush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);
Toshihiro Shimizu 890ddd
		} else {
Shinya Kitaoka 3bfa54
			std::vector<tthickpoint> points;</tthickpoint>
Toshihiro Shimizu 890ddd
			points.push_back(m_points[m - 4]);
Toshihiro Shimizu 890ddd
			points.push_back(old);
Toshihiro Shimizu 890ddd
			points.push_back(mid);
Toshihiro Shimizu 890ddd
			invalidateRect = ToolUtils::getBounds(points, thickness);
Toshihiro Shimizu 890ddd
			bbox = m_brush->getBoundFromPoints(points);
Toshihiro Shimizu 890ddd
			m_tileSaver->save(bbox);
Toshihiro Shimizu 890ddd
			m_brush->addArc(m_points[m - 4], old, mid, 1, 1);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_brush->eraseDrawing(ri->getRaster(), m_backUpRas, bbox, opacity);
Toshihiro Shimizu 890ddd
		invalidate(invalidateRect.enlarge(2) - rasCenter);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_eraseType.getValue() == RECTERASE) {
Toshihiro Shimizu 890ddd
		assert(m_selecting);
Toshihiro Shimizu 890ddd
		TRectD oldRect = m_selectingRect;
Toshihiro Shimizu 890ddd
		if (oldRect.x0 > oldRect.x1)
Toshihiro Shimizu 890ddd
			tswap(oldRect.x1, oldRect.x0);
Toshihiro Shimizu 890ddd
		if (oldRect.y0 > oldRect.y1)
Toshihiro Shimizu 890ddd
			tswap(oldRect.y1, oldRect.y0);
Toshihiro Shimizu 890ddd
		m_selectingRect.x1 = pos.x;
Toshihiro Shimizu 890ddd
		m_selectingRect.y1 = pos.y;
Toshihiro Shimizu 890ddd
		TRectD invalidateRect(m_selectingRect);
Toshihiro Shimizu 890ddd
		if (invalidateRect.x0 > invalidateRect.x1)
Toshihiro Shimizu 890ddd
			tswap(invalidateRect.x1, invalidateRect.x0);
Toshihiro Shimizu 890ddd
		if (invalidateRect.y0 > invalidateRect.y1)
Toshihiro Shimizu 890ddd
			tswap(invalidateRect.y1, invalidateRect.y0);
Toshihiro Shimizu 890ddd
		invalidateRect += oldRect;
Toshihiro Shimizu 890ddd
		invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_eraseType.getValue() == FREEHANDERASE) {
Toshihiro Shimizu 890ddd
		getViewer()->startForegroundDrawing();
Toshihiro Shimizu 890ddd
		TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg ? TPixel32::White : TPixel32::Black;
Toshihiro Shimizu 890ddd
		tglColor(color);
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		tglMultMatrix(getMatrix());
Toshihiro Shimizu 890ddd
		TPointD dpiScale = m_viewer->getDpiScale();
Toshihiro Shimizu 890ddd
		glScaled(dpiScale.x, dpiScale.y, 1);
Toshihiro Shimizu 890ddd
		m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
		m_track.drawLastFragments();
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
		getViewer()->endForegroundDrawing();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_brushPos = m_mousePos = pos;
Toshihiro Shimizu 890ddd
	TRasterImageP ri = (TRasterImageP)getImage(true);
Toshihiro Shimizu 890ddd
	if (!ri)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (m_eraseType.getValue() == NORMALERASE) {
Toshihiro Shimizu 890ddd
		if (m_points.size() != 1) {
Toshihiro Shimizu 890ddd
			TPointD rasCenter = ri->getRaster()->getCenterD();
Toshihiro Shimizu 890ddd
			TThickPoint point(pos + rasCenter, m_size.getValue());
Toshihiro Shimizu 890ddd
			m_points.push_back(point);
Toshihiro Shimizu 890ddd
			int m = m_points.size();
Shinya Kitaoka 3bfa54
			std::vector<tthickpoint> points;</tthickpoint>
Toshihiro Shimizu 890ddd
			points.push_back(m_points[m - 3]);
Toshihiro Shimizu 890ddd
			points.push_back(m_points[m - 2]);
Toshihiro Shimizu 890ddd
			points.push_back(m_points[m - 1]);
Toshihiro Shimizu 890ddd
			TRect bbox = m_brush->getBoundFromPoints(points);
Toshihiro Shimizu 890ddd
			m_tileSaver->save(bbox);
Toshihiro Shimizu 890ddd
			m_brush->addArc(points[0], points[1], points[2], 1, 1);
Toshihiro Shimizu 890ddd
			double opacity = m_opacity.getValue() * 0.01;
Toshihiro Shimizu 890ddd
			m_brush->eraseDrawing(ri->getRaster(), m_backUpRas, bbox, opacity);
Toshihiro Shimizu 890ddd
			TRectD invalidateRect = ToolUtils::getBounds(points, m_size.getValue());
Toshihiro Shimizu 890ddd
			invalidate(invalidateRect.enlarge(2) - rasCenter);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_brush) {
Toshihiro Shimizu 890ddd
			delete m_brush;
Toshihiro Shimizu 890ddd
			m_brush = 0;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_workRaster->unlock();
Toshihiro Shimizu 890ddd
		double opacity = m_opacity.getValue() * 0.01;
Toshihiro Shimizu 890ddd
		double hardness = m_hardness.getValue() * 0.01;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_workRaster = TRaster32P();
Toshihiro Shimizu 890ddd
		m_backUpRas = TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		delete m_tileSaver;
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		TXshLevel *level = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		TXshSimpleLevelP simLevel = level->getSimpleLevel();
Toshihiro Shimizu 890ddd
		TFrameId frameId = getCurrentFid();
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(new FullColorEraserUndo(m_tileSet, m_points, simLevel.getPointer(),
Toshihiro Shimizu 890ddd
															 frameId, m_size.getValue(), m_hardness.getValue() * 0.01, opacity));
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	} else if (m_eraseType.getValue() == RECTERASE) {
Toshihiro Shimizu 890ddd
		if (m_selectingRect.x0 > m_selectingRect.x1)
Toshihiro Shimizu 890ddd
			tswap(m_selectingRect.x1, m_selectingRect.x0);
Toshihiro Shimizu 890ddd
		if (m_selectingRect.y0 > m_selectingRect.y1)
Toshihiro Shimizu 890ddd
			tswap(m_selectingRect.y1, m_selectingRect.y0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_multi.getValue()) {
Toshihiro Shimizu 890ddd
			TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
			if (m_firstFrameSelected) {
Toshihiro Shimizu 890ddd
				multiUpdate(m_firstRect, m_selectingRect);
Toshihiro Shimizu 890ddd
				notifyImageChanged();
Toshihiro Shimizu 890ddd
				if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
					m_firstRect = m_selectingRect;
Toshihiro Shimizu 890ddd
					m_firstFrameId = getFrameId();
Toshihiro Shimizu 890ddd
					invalidate();
Toshihiro Shimizu 890ddd
				} else {
Toshihiro Shimizu 890ddd
					if (m_isXsheetCell) {
Toshihiro Shimizu 890ddd
						app->getCurrentColumn()->setColumnIndex(m_currCell.first);
Toshihiro Shimizu 890ddd
						app->getCurrentFrame()->setFrame(m_currCell.second);
Toshihiro Shimizu 890ddd
					} else
Toshihiro Shimizu 890ddd
						app->getCurrentFrame()->setFid(m_veryFirstFrameId);
Toshihiro Shimizu 890ddd
					resetMulti();
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Toshihiro Shimizu 890ddd
				m_currCell = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
			TXshLevel *level = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
			TXshSimpleLevelP simLevel = level->getSimpleLevel();
Toshihiro Shimizu 890ddd
			TFrameId frameId = getCurrentFid();
Toshihiro Shimizu 890ddd
			if (m_invertOption.getValue()) {
Toshihiro Shimizu 890ddd
				TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
				TRect rect = TRasterImageUtils::convertWorldToRaster(m_selectingRect, ri);
Toshihiro Shimizu 890ddd
				rect *= ri->getSavebox();
Toshihiro Shimizu 890ddd
				TDimension dim = ri->getRaster()->getSize();
Toshihiro Shimizu 890ddd
				TRectD rect01 = TRectD(TPointD(0., 0.), TPointD((double)rect.x0, (double)dim.ly));
Toshihiro Shimizu 890ddd
				if (rect01.getLx() > 0 && rect01.getLy() > 0) {
Toshihiro Shimizu 890ddd
					rect01 = TRasterImageUtils::convertRasterToWorld(convert(rect01), ri);
Toshihiro Shimizu 890ddd
					update(ri, rect01, simLevel, false, frameId);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				TRectD rect02 = TRectD(convert(rect.getP01()), TPointD((double)rect.x1, (double)dim.ly));
Toshihiro Shimizu 890ddd
				if (rect02.getLx() > 0 && rect02.getLy() > 0) {
Toshihiro Shimizu 890ddd
					rect02 = TRasterImageUtils::convertRasterToWorld(convert(rect02), ri);
Toshihiro Shimizu 890ddd
					update(ri, rect02, simLevel, false, frameId);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				TRectD rect03 = TRectD(TPointD((double)rect.x0, 0.), convert(rect.getP10()));
Toshihiro Shimizu 890ddd
				if (rect03.getLx() > 0 && rect03.getLy() > 0) {
Toshihiro Shimizu 890ddd
					rect03 = TRasterImageUtils::convertRasterToWorld(convert(rect03), ri);
Toshihiro Shimizu 890ddd
					update(ri, rect03, simLevel, false, frameId);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				TRectD rect04 = TRectD(TPointD((double)rect.x1, 0.), TPointD((double)dim.lx, (double)dim.ly));
Toshihiro Shimizu 890ddd
				if (rect04.getLx() > 0 && rect04.getLy() > 0) {
Toshihiro Shimizu 890ddd
					rect04 = TRasterImageUtils::convertRasterToWorld(convert(rect04), ri);
Toshihiro Shimizu 890ddd
					update(ri, rect04, simLevel, false, frameId);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
				invalidate();
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				update(ri, m_selectingRect, simLevel, false, frameId);
Toshihiro Shimizu 890ddd
				invalidate(m_selectingRect.enlarge(2));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			m_selectingRect.empty();
Toshihiro Shimizu 890ddd
			TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
			m_selecting = false;
Toshihiro Shimizu 890ddd
			notifyImageChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else if (m_eraseType.getValue() == FREEHANDERASE) {
Toshihiro Shimizu 890ddd
		if (m_track.isEmpty())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		double pixelSize2 = getPixelSize() * getPixelSize();
Toshihiro Shimizu 890ddd
		m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
		m_track.add(TThickPoint(m_firstPos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
		getViewer()->startForegroundDrawing();
Toshihiro Shimizu 890ddd
		m_track.drawLastFragments();
Toshihiro Shimizu 890ddd
		getViewer()->endForegroundDrawing();
Toshihiro Shimizu 890ddd
		m_track.filterPoints();
Toshihiro Shimizu 890ddd
		double error = (30.0 / 11) * sqrt(pixelSize2);
Toshihiro Shimizu 890ddd
		TStroke *stroke = m_track.makeStroke(error);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		stroke->setStyle(1);
Toshihiro Shimizu 890ddd
		m_track.clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (m_multi.getValue()) //stroke multi
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			if (m_firstFrameSelected) {
Toshihiro Shimizu 890ddd
				TFrameId tmp = getCurrentFid();
Toshihiro Shimizu 890ddd
				if (m_firstStroke && stroke)
Toshihiro Shimizu 890ddd
					multiAreaEraser(m_firstFrameId, tmp, m_firstStroke, stroke);
Toshihiro Shimizu 890ddd
				notifyImageChanged();
Toshihiro Shimizu 890ddd
				if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
					TRectD invalidateRect = m_firstStroke->getBBox();
Toshihiro Shimizu 890ddd
					delete m_firstStroke;
Toshihiro Shimizu 890ddd
					m_firstStroke = 0;
Toshihiro Shimizu 890ddd
					invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
					m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
					invalidateRect = m_firstStroke->getBBox();
Toshihiro Shimizu 890ddd
					invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
					m_firstFrameId = getFrameId();
Toshihiro Shimizu 890ddd
				} else {
Toshihiro Shimizu 890ddd
					if (m_isXsheetCell) {
Toshihiro Shimizu 890ddd
						app->getCurrentColumn()->setColumnIndex(m_currCell.first);
Toshihiro Shimizu 890ddd
						app->getCurrentFrame()->setFrame(m_currCell.second);
Toshihiro Shimizu 890ddd
					} else
Toshihiro Shimizu 890ddd
						app->getCurrentFrame()->setFid(m_veryFirstFrameId);
Toshihiro Shimizu 890ddd
					resetMulti();
Toshihiro Shimizu 890ddd
					delete stroke;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else //primo frame
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
				m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Toshihiro Shimizu 890ddd
				m_currCell = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Toshihiro Shimizu 890ddd
				invalidate(m_firstStroke->getBBox().enlarge(2));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else //stroke non multi
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			if (!getImage(true))
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			TFrameId frameId = getCurrentFid();
Toshihiro Shimizu 890ddd
			eraseStroke(ri, stroke, m_eraseType.getValue(),
Toshihiro Shimizu 890ddd
						m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level,
Toshihiro Shimizu 890ddd
						frameId);
Toshihiro Shimizu 890ddd
			notifyImageChanged();
Toshihiro Shimizu 890ddd
			if (m_invertOption.getValue())
Toshihiro Shimizu 890ddd
				invalidate();
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				invalidate(stroke->getBBox().enlarge(2));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterImageP ri(getImage(true));
Toshihiro Shimizu 890ddd
	if (!ri)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TStroke *stroke;
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	if (m_polyline.size() <= 1) {
Toshihiro Shimizu 890ddd
		resetMulti();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_polyline.back() != pos)
Toshihiro Shimizu 890ddd
		m_polyline.push_back(pos);
Toshihiro Shimizu 890ddd
	if (m_polyline.back() != m_polyline.front())
Toshihiro Shimizu 890ddd
		m_polyline.push_back(m_polyline.front());
Shinya Kitaoka 3bfa54
	std::vector<tthickpoint> strokePoints;</tthickpoint>
Toshihiro Shimizu 890ddd
	for (UINT i = 0; i < m_polyline.size() - 1; i++) {
Toshihiro Shimizu 890ddd
		strokePoints.push_back(TThickPoint(m_polyline[i], 1));
Toshihiro Shimizu 890ddd
		strokePoints.push_back(TThickPoint(0.5 * (m_polyline[i] + m_polyline[i + 1]), 1));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	strokePoints.push_back(TThickPoint(m_polyline.back(), 1));
Toshihiro Shimizu 890ddd
	m_polyline.clear();
Toshihiro Shimizu 890ddd
	stroke = new TStroke(strokePoints);
Toshihiro Shimizu 890ddd
	assert(stroke->getPoint(0) == stroke->getPoint(1));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_multi.getValue()) //stroke multi
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_firstFrameSelected) {
Toshihiro Shimizu 890ddd
			TFrameId tmp = getFrameId();
Toshihiro Shimizu 890ddd
			if (m_firstStroke && stroke)
Toshihiro Shimizu 890ddd
				multiAreaEraser(m_firstFrameId, tmp, m_firstStroke, stroke);
Toshihiro Shimizu 890ddd
			if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
				TRectD invalidateRect = m_firstStroke->getBBox();
Toshihiro Shimizu 890ddd
				delete m_firstStroke;
Toshihiro Shimizu 890ddd
				m_firstStroke = 0;
Toshihiro Shimizu 890ddd
				invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
				m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
				invalidateRect = m_firstStroke->getBBox();
Toshihiro Shimizu 890ddd
				invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
				m_firstFrameId = getFrameId();
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				if (m_isXsheetCell) {
Toshihiro Shimizu 890ddd
					app->getCurrentColumn()->setColumnIndex(m_currCell.first);
Toshihiro Shimizu 890ddd
					app->getCurrentFrame()->setFrame(m_currCell.second);
Toshihiro Shimizu 890ddd
				} else
Toshihiro Shimizu 890ddd
					app->getCurrentFrame()->setFid(m_veryFirstFrameId);
Toshihiro Shimizu 890ddd
				resetMulti();
Toshihiro Shimizu 890ddd
				delete stroke;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else //primo frame
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
			m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Toshihiro Shimizu 890ddd
			m_currCell = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Toshihiro Shimizu 890ddd
			invalidate(m_firstStroke->getBBox().enlarge(2));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (!getImage(true))
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TXshLevel *level = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		TXshSimpleLevelP simLevel = level->getSimpleLevel();
Toshihiro Shimizu 890ddd
		TFrameId frameId = getFrameId();
Toshihiro Shimizu 890ddd
		eraseStroke(ri, stroke, m_eraseType.getValue(),
Toshihiro Shimizu 890ddd
					m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level, frameId);
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
		if (m_invertOption.getValue())
Toshihiro Shimizu 890ddd
			invalidate();
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			invalidate(stroke->getBBox().enlarge(2));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::mouseMove(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	struct Locals {
Toshihiro Shimizu 890ddd
		FullColorEraserTool *m_this;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		void setValue(TIntProperty &prop, int value)
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			prop.setValue(value);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_this->onPropertyChanged(prop.getName());
Toshihiro Shimizu 890ddd
			TTool::getApplication()->getCurrentTool()->notifyToolChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		void addValue(TIntProperty &prop, double add)
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			const TIntProperty::Range &range = prop.getRange();
Toshihiro Shimizu 890ddd
			setValue(prop, tcrop<double>(prop.getValue() + add, range.first, range.second));</double>
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	} locals = {this};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	switch (e.getModifiersMask()) {
Toshihiro Shimizu 890ddd
	case TMouseEvent::ALT_KEY: {
Toshihiro Shimizu 890ddd
		// User wants to alter the maximum brush size
Toshihiro Shimizu 890ddd
		const TPointD &diff = pos - m_mousePos;
Toshihiro Shimizu 890ddd
		double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		locals.addValue(m_size, add);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DEFAULT:
Toshihiro Shimizu 890ddd
		m_brushPos = pos;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_mousePos = pos;
Toshihiro Shimizu 890ddd
	invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::draw()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double pixelSize2 = getPixelSize() * getPixelSize();
Toshihiro Shimizu 890ddd
	m_thick = sqrt(pixelSize2) / 2.0;
Toshihiro Shimizu 890ddd
	TRasterImageP img = (TRasterImageP)getImage(false);
Toshihiro Shimizu 890ddd
	if (!img)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (m_eraseType.getValue() == NORMALERASE) {
Toshihiro Shimizu 890ddd
		glColor3d(1.0, 0.0, 0.0);
Toshihiro Shimizu 890ddd
		tglDrawCircle(m_brushPos, (m_size.getValue() + 1) * 0.5);
Toshihiro Shimizu 890ddd
	} else if (m_eraseType.getValue() == RECTERASE) {
Toshihiro Shimizu 890ddd
		TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg ? TPixel32::White : TPixel32::Black;
Toshihiro Shimizu 890ddd
		if (m_multi.getValue() && m_firstFrameSelected)
Toshihiro Shimizu 890ddd
			drawRect(m_firstRect, color, 0x3F33, true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_selecting || (m_multi.getValue() && !m_firstFrameSelected))
Toshihiro Shimizu 890ddd
			drawRect(m_selectingRect, color, 0x3F33, true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if ((m_eraseType.getValue() == FREEHANDERASE || m_eraseType.getValue() == POLYLINEERASE) && m_multi.getValue()) {
Toshihiro Shimizu 890ddd
		TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg ? TPixel32::White : TPixel32::Black;
Toshihiro Shimizu 890ddd
		tglColor(color);
Toshihiro Shimizu 890ddd
		if (m_firstStroke)
Toshihiro Shimizu 890ddd
			drawStrokeCenterline(*m_firstStroke, 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_eraseType.getValue() == POLYLINEERASE && !m_polyline.empty()) {
Toshihiro Shimizu 890ddd
		TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg ? TPixel32::White : TPixel32::Black;
Toshihiro Shimizu 890ddd
		tglColor(color);
Toshihiro Shimizu 890ddd
		tglDrawCircle(m_polyline[0], 2 * m_thick);
Toshihiro Shimizu 890ddd
		glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
		for (UINT i = 0; i < m_polyline.size(); i++)
Toshihiro Shimizu 890ddd
			tglVertex(m_polyline[i]);
Toshihiro Shimizu 890ddd
		tglVertex(m_mousePos);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
bool FullColorEraserTool::onPropertyChanged(std::string propertyName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FullcolorEraseSize = m_size.getValue();
Toshihiro Shimizu 890ddd
	FullcolorEraseHardness = m_hardness.getValue();
Toshihiro Shimizu 890ddd
	FullcolorEraserOpacity = m_opacity.getValue();
Toshihiro Shimizu 890ddd
	FullcolorEraserType = toString(m_eraseType.getValue());
Toshihiro Shimizu 890ddd
	FullcolorEraserInvert = (int)m_invertOption.getValue();
Toshihiro Shimizu 890ddd
	FullcolorEraserRange = (int)m_multi.getValue();
Toshihiro Shimizu 890ddd
	if (propertyName == "Hardness:" || propertyName == "Size:") {
Toshihiro Shimizu 890ddd
		m_brushPad = getBrushPad(m_size.getValue(), m_hardness.getValue() * 0.01);
Toshihiro Shimizu 890ddd
		TRectD rect(m_brushPos - TPointD(FullcolorEraseSize + 2, FullcolorEraseSize + 2),
Toshihiro Shimizu 890ddd
					m_brushPos + TPointD(FullcolorEraseSize + 2, FullcolorEraseSize + 2));
Toshihiro Shimizu 890ddd
		invalidate(rect);
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 FullColorEraserTool::update(const TRasterImageP &ri, TRectD selArea, const TXshSimpleLevelP &level,
Toshihiro Shimizu 890ddd
								 bool multi, const TFrameId &frameId)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_selectingRect.x0 > m_selectingRect.x1) {
Toshihiro Shimizu 890ddd
		selArea.x1 = m_selectingRect.x0;
Toshihiro Shimizu 890ddd
		selArea.x0 = m_selectingRect.x1;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_selectingRect.y0 > m_selectingRect.y1) {
Toshihiro Shimizu 890ddd
		selArea.y1 = m_selectingRect.y0;
Toshihiro Shimizu 890ddd
		selArea.y0 = m_selectingRect.y1;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (selArea.getLx() < 1 || selArea.getLy() < 1)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP raster = ri->getRaster();
Toshihiro Shimizu 890ddd
	TTileSetFullColor *tileSet = new TTileSetFullColor(raster->getSize());
Toshihiro Shimizu 890ddd
	tileSet->add(raster, TRasterImageUtils::convertWorldToRaster(selArea, ri));
Toshihiro Shimizu 890ddd
	TUndo *undo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	undo = new RectFullColorUndo(tileSet, selArea, TStroke(), m_eraseType.getValue(),
Toshihiro Shimizu 890ddd
								 level.getPointer(), m_invertOption.getValue(), frameId);
Toshihiro Shimizu 890ddd
	TRect rect = TRasterImageUtils::eraseRect(ri, selArea);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::resetMulti()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_isXsheetCell = false;
Toshihiro Shimizu 890ddd
	m_firstFrameSelected = false;
Toshihiro Shimizu 890ddd
	m_firstRect.empty();
Toshihiro Shimizu 890ddd
	m_selectingRect.empty();
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	m_level = app->getCurrentLevel()->getLevel()
Toshihiro Shimizu 890ddd
				  ? app->getCurrentLevel()->getSimpleLevel()
Toshihiro Shimizu 890ddd
				  : 0;
Toshihiro Shimizu 890ddd
	m_firstFrameId = m_veryFirstFrameId = getCurrentFid();
Toshihiro Shimizu 890ddd
	if (m_firstStroke) {
Toshihiro Shimizu 890ddd
		delete m_firstStroke;
Toshihiro Shimizu 890ddd
		m_firstStroke = 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::onImageChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_multi.getValue())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *xshl = 0;
Toshihiro Shimizu 890ddd
	if (app->getCurrentLevel()->getLevel())
Toshihiro Shimizu 890ddd
		xshl = app->getCurrentLevel()->getSimpleLevel();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!xshl || m_level.getPointer() != xshl || (m_selectingRect.isEmpty() && !m_firstStroke))
Toshihiro Shimizu 890ddd
		resetMulti();
Toshihiro Shimizu 890ddd
	else if (m_firstFrameId == getCurrentFid())
Toshihiro Shimizu 890ddd
		m_firstFrameSelected = false; //nel caso sono passato allo stato 1 e torno all'immagine iniziale, torno allo stato iniziale
Toshihiro Shimizu 890ddd
	else {							  //cambio stato.
Toshihiro Shimizu 890ddd
		m_firstFrameSelected = true;
Toshihiro Shimizu 890ddd
		if (m_eraseType.getValue() != FREEHANDERASE && m_eraseType.getValue() != POLYLINEERASE) {
Toshihiro Shimizu 890ddd
			assert(!m_selectingRect.isEmpty());
Toshihiro Shimizu 890ddd
			m_firstRect = m_selectingRect;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::multiUpdate(const TRectD firstRect, const TRectD lastRect)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool backward = false;
Toshihiro Shimizu 890ddd
	TFrameId firstFid = m_firstFrameId;
Toshihiro Shimizu 890ddd
	TFrameId lastFid = getCurrentFid();
Toshihiro Shimizu 890ddd
	if (firstFid > lastFid) {
Toshihiro Shimizu 890ddd
		tswap(firstFid, lastFid);
Toshihiro Shimizu 890ddd
		backward = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	assert(firstFid <= lastFid);
Shinya Kitaoka 3bfa54
	std::vector<tframeid> allFids;</tframeid>
Toshihiro Shimizu 890ddd
	m_level->getFids(allFids);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<tframeid>::iterator i0 = allFids.begin();</tframeid>
Toshihiro Shimizu 890ddd
	while (i0 != allFids.end() && *i0 < firstFid)
Toshihiro Shimizu 890ddd
		i0++;
Toshihiro Shimizu 890ddd
	if (i0 == allFids.end())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	std::vector<tframeid>::iterator i1 = i0;</tframeid>
Toshihiro Shimizu 890ddd
	while (i1 != allFids.end() && *i1 <= lastFid)
Toshihiro Shimizu 890ddd
		i1++;
Toshihiro Shimizu 890ddd
	assert(i0 < i1);
Shinya Kitaoka 3bfa54
	std::vector<tframeid> fids(i0, i1);</tframeid>
Toshihiro Shimizu 890ddd
	int m = fids.size();
Toshihiro Shimizu 890ddd
	assert(m > 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < m; ++i) {
Toshihiro Shimizu 890ddd
		TFrameId fid = fids[i];
Toshihiro Shimizu 890ddd
		assert(firstFid <= fid && fid <= lastFid);
Toshihiro Shimizu 890ddd
		TRasterImageP ri = m_level->getFrame(fid, true);
Toshihiro Shimizu 890ddd
		assert(ri);
Toshihiro Shimizu 890ddd
		double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;
Toshihiro Shimizu 890ddd
		TRectD rect = interpolateRect(firstRect, lastRect, backward ? 1 - t : t);
Toshihiro Shimizu 890ddd
		if (m_invertOption.getValue()) {
Toshihiro Shimizu 890ddd
			TRectD rect01 = TRectD(TPointD(-100000., -100000.), TPointD(rect.x0, 100000.));
Toshihiro Shimizu 890ddd
			update(ri, rect01, m_level, true, fid);
Toshihiro Shimizu 890ddd
			TRectD rect02 = TRectD(rect.getP01(), TPointD(rect.x1, 100000.));
Toshihiro Shimizu 890ddd
			update(ri, rect02, m_level, true, fid);
Toshihiro Shimizu 890ddd
			TRectD rect03 = TRectD(TPointD(rect.x0, -100000.), rect.getP10());
Toshihiro Shimizu 890ddd
			update(ri, rect03, m_level, true, fid);
Toshihiro Shimizu 890ddd
			TRectD rect04 = TRectD(TPointD(rect.x1, -100000.), TPointD(100000., 100000.));
Toshihiro Shimizu 890ddd
			update(ri, rect04, m_level, true, fid);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			update(ri, rect, m_level, true, fid);
Toshihiro Shimizu 890ddd
		m_level->getProperties()->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		notifyImageChanged(fid);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::onEnter()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterImageP ti(getImage(false));
Toshihiro Shimizu 890ddd
	if (!ti)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	m_level = app->getCurrentLevel()->getLevel()
Toshihiro Shimizu 890ddd
				  ? app->getCurrentLevel()->getSimpleLevel()
Toshihiro Shimizu 890ddd
				  : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::multiAreaEraser(TFrameId &firstFid, TFrameId &lastFid,
Toshihiro Shimizu 890ddd
										  TStroke *firstStroke, TStroke *lastStroke)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStroke *first = new TStroke();
Toshihiro Shimizu 890ddd
	TStroke *last = new TStroke();
Toshihiro Shimizu 890ddd
	*first = *firstStroke;
Toshihiro Shimizu 890ddd
	*last = *lastStroke;
Toshihiro Shimizu 890ddd
	TVectorImageP firstImage = new TVectorImage();
Toshihiro Shimizu 890ddd
	TVectorImageP lastImage = new TVectorImage();
Toshihiro Shimizu 890ddd
	firstImage->addStroke(first);
Toshihiro Shimizu 890ddd
	lastImage->addStroke(last);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool backward = false;
Toshihiro Shimizu 890ddd
	if (firstFid > lastFid) {
Toshihiro Shimizu 890ddd
		tswap(firstFid, lastFid);
Toshihiro Shimizu 890ddd
		backward = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	assert(firstFid <= lastFid);
Shinya Kitaoka 3bfa54
	std::vector<tframeid> allFids;</tframeid>
Toshihiro Shimizu 890ddd
	m_level->getFids(allFids);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<tframeid>::iterator i0 = allFids.begin();</tframeid>
Toshihiro Shimizu 890ddd
	while (i0 != allFids.end() && *i0 < firstFid)
Toshihiro Shimizu 890ddd
		i0++;
Toshihiro Shimizu 890ddd
	if (i0 == allFids.end())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	std::vector<tframeid>::iterator i1 = i0;</tframeid>
Toshihiro Shimizu 890ddd
	while (i1 != allFids.end() && *i1 <= lastFid)
Toshihiro Shimizu 890ddd
		i1++;
Toshihiro Shimizu 890ddd
	assert(i0 < i1);
Shinya Kitaoka 3bfa54
	std::vector<tframeid> fids(i0, i1);</tframeid>
Toshihiro Shimizu 890ddd
	int m = fids.size();
Toshihiro Shimizu 890ddd
	assert(m > 0);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < m; ++i) {
Toshihiro Shimizu 890ddd
		TFrameId fid = fids[i];
Toshihiro Shimizu 890ddd
		assert(firstFid <= fid && fid <= lastFid);
Toshihiro Shimizu 890ddd
		TImageP img = m_level->getFrame(fid, true);
Toshihiro Shimizu 890ddd
		double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;
Toshihiro Shimizu 890ddd
		doMultiEraser(img, backward ? 1 - t : t, fid, firstImage, lastImage);
Toshihiro Shimizu 890ddd
		m_level->getProperties()->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		notifyImageChanged(fid);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::doMultiEraser(const TImageP &img, double t,
Toshihiro Shimizu 890ddd
										const TFrameId &fid,
Toshihiro Shimizu 890ddd
										const TVectorImageP &firstImage,
Toshihiro Shimizu 890ddd
										const TVectorImageP &lastImage)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
Toshihiro Shimizu 890ddd
	if (t == 0)
Toshihiro Shimizu 890ddd
		eraseStroke(img, firstImage->getStroke(0), m_eraseType.getValue(),
Toshihiro Shimizu 890ddd
					m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level, fid);
Toshihiro Shimizu 890ddd
	else if (t == 1)
Toshihiro Shimizu 890ddd
		eraseStroke(img, lastImage->getStroke(0), m_eraseType.getValue(),
Toshihiro Shimizu 890ddd
					m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level, fid);
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		assert(firstImage->getStrokeCount() == 1);
Toshihiro Shimizu 890ddd
		assert(lastImage->getStrokeCount() == 1);
Toshihiro Shimizu 890ddd
		TVectorImageP vi = TInbetween(firstImage, lastImage).tween(t);
Toshihiro Shimizu 890ddd
		assert(vi->getStrokeCount() == 1);
Toshihiro Shimizu 890ddd
		eraseStroke(img, vi->getStroke(0), m_eraseType.getValue(),
Toshihiro Shimizu 890ddd
					m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level, fid);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}