Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/tonionskinmaskhandle.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
#include "tools/stylepicker.h"
Toshihiro Shimizu 890ddd
#include "toonz/fill.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "drawutil.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tinbetween.h"
Toshihiro Shimizu 890ddd
#include "tregion.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/onionskinmask.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttileset.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttilesaver.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzimageutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/strokegenerator.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/imageutils.h"
Toshihiro Shimizu 890ddd
#include "autofill.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "historytypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <stack></stack>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// For Qt translation support
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToolUtils;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define LINES L"Lines"
Toshihiro Shimizu 890ddd
#define AREAS L"Areas"
Toshihiro Shimizu 890ddd
#define ALL L"Lines & Areas"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define NORMALFILL L"Normal"
Toshihiro Shimizu 890ddd
#define RECTFILL L"Rectangular"
Toshihiro Shimizu 890ddd
#define FREEHANDFILL L"Freehand"
Toshihiro Shimizu 890ddd
#define POLYLINEFILL L"Polyline"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::IntVar MinFillDepth("InknpaintMinFillDepth", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar MaxFillDepth("InknpaintMaxFillDepth", 10);
Toshihiro Shimizu 890ddd
TEnv::StringVar FillType("InknpaintFillType", "Normal");
Toshihiro Shimizu 890ddd
TEnv::StringVar FillColorType("InknpaintFillColorType", "Areas");
Toshihiro Shimizu 890ddd
TEnv::IntVar FillSelective("InknpaintFillSelective", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FillOnion("InknpaintFillOnion", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FillSegment("InknpaintFillSegment", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FillRange("InknpaintFillRange", 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
inline int vectorFill(const TVectorImageP &img, const std::wstring &type, const TPointD &point, int style, bool emptyOnly = false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (type == ALL || type == LINES) {
Toshihiro Shimizu 890ddd
		int oldStyleId = img->fillStrokes(point, style);
Toshihiro Shimizu 890ddd
		if (oldStyleId != -1)
Toshihiro Shimizu 890ddd
			return oldStyleId;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (type == ALL || type == AREAS)
Toshihiro Shimizu 890ddd
		return img->fill(point, style, emptyOnly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return -1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// VectorFillUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class VectorFillUndo : public TToolUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int m_oldColorStyle;
Toshihiro Shimizu 890ddd
	int m_newColorStyle;
Toshihiro Shimizu 890ddd
	TPointD m_point;
Shinya Kitaoka 3bfa54
	std::wstring m_type;
Toshihiro Shimizu 890ddd
	int m_row;
Toshihiro Shimizu 890ddd
	int m_column;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	VectorFillUndo(
Toshihiro Shimizu 890ddd
		int newColorStyle,
Toshihiro Shimizu 890ddd
		int oldColorStyle,
Shinya Kitaoka 3bfa54
		std::wstring fillType,
Toshihiro Shimizu 890ddd
		TPointD clickPoint,
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl,
Toshihiro Shimizu 890ddd
		const TFrameId &fid)
Toshihiro Shimizu 890ddd
		: TToolUndo(sl, fid), m_newColorStyle(newColorStyle), m_oldColorStyle(oldColorStyle), m_point(clickPoint), m_type(fillType)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (app) {
Toshihiro Shimizu 890ddd
			m_row = app->getCurrentFrame()->getFrame();
Toshihiro Shimizu 890ddd
			m_column = app->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		app->getCurrentLevel()->setLevel(m_level.getPointer());
Toshihiro Shimizu 890ddd
		TVectorImageP img = m_level->getFrame(m_frameId, true);
Toshihiro Shimizu 890ddd
		if (app->getCurrentFrame()->isEditingScene()) {
Toshihiro Shimizu 890ddd
			app->getCurrentFrame()->setFrame(m_row);
Toshihiro Shimizu 890ddd
			app->getCurrentColumn()->setColumnIndex(m_column);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			app->getCurrentFrame()->setFid(m_frameId);
Toshihiro Shimizu 890ddd
		assert(img);
Toshihiro Shimizu 890ddd
		if (!img)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		QMutexLocker lock(img->getMutex());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		vectorFill(img, m_type, m_point, m_oldColorStyle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		app->getCurrentLevel()->setLevel(m_level.getPointer());
Toshihiro Shimizu 890ddd
		TVectorImageP img = m_level->getFrame(m_frameId, true);
Toshihiro Shimizu 890ddd
		if (app->getCurrentFrame()->isEditingScene()) {
Toshihiro Shimizu 890ddd
			app->getCurrentFrame()->setFrame(m_row);
Toshihiro Shimizu 890ddd
			app->getCurrentColumn()->setColumnIndex(m_column);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			app->getCurrentFrame()->setFid(m_frameId);
Toshihiro Shimizu 890ddd
		assert(img);
Toshihiro Shimizu 890ddd
		if (!img)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		QMutexLocker lock(img->getMutex());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		vectorFill(img, m_type, m_point, m_newColorStyle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onAdd()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QString getToolName()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QString("Fill Tool : %1").arg(QString::fromStdWString(m_type));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::FillTool;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// VectorRectFillUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class VectorRectFillUndo : public TToolUndo
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::vector<tfilledregioninf> *m_regionFillInformation;</tfilledregioninf>
Shinya Kitaoka 3bfa54
	std::vector<std::pair<int, int="">> *m_strokeFillInformation;</std::pair<int,>
Toshihiro Shimizu 890ddd
	TRectD m_selectionArea;
Toshihiro Shimizu 890ddd
	int m_styleId;
Toshihiro Shimizu 890ddd
	bool m_unpaintedOnly;
Toshihiro Shimizu 890ddd
	TStroke *m_stroke;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	~VectorRectFillUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_regionFillInformation)
Toshihiro Shimizu 890ddd
			delete m_regionFillInformation;
Toshihiro Shimizu 890ddd
		if (m_strokeFillInformation)
Toshihiro Shimizu 890ddd
			delete m_strokeFillInformation;
Toshihiro Shimizu 890ddd
		if (m_stroke)
Toshihiro Shimizu 890ddd
			delete m_stroke;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	VectorRectFillUndo(
Shinya Kitaoka 3bfa54
		std::vector<tfilledregioninf> *regionFillInformation,</tfilledregioninf>
Shinya Kitaoka 3bfa54
		std::vector<std::pair<int, int="">> *strokeFillInformation,</std::pair<int,>
Toshihiro Shimizu 890ddd
		TRectD selectionArea,
Toshihiro Shimizu 890ddd
		TStroke *stroke,
Toshihiro Shimizu 890ddd
		int styleId,
Toshihiro Shimizu 890ddd
		bool unpaintedOnly,
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl,
Toshihiro Shimizu 890ddd
		const TFrameId &fid)
Toshihiro Shimizu 890ddd
		: TToolUndo(sl, fid), m_regionFillInformation(regionFillInformation), m_strokeFillInformation(strokeFillInformation), m_selectionArea(selectionArea), m_styleId(styleId), m_unpaintedOnly(unpaintedOnly), m_stroke(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (stroke)
Toshihiro Shimizu 890ddd
			m_stroke = new TStroke(*stroke);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TVectorImageP img = m_level->getFrame(m_frameId, true);
Toshihiro Shimizu 890ddd
		assert(!!img);
Toshihiro Shimizu 890ddd
		if (!img)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		if (m_regionFillInformation) {
Toshihiro Shimizu 890ddd
			for (UINT i = 0; i < m_regionFillInformation->size(); i++) {
Toshihiro Shimizu 890ddd
				TRegion *reg = img->getRegion((*m_regionFillInformation)[i].m_regionId);
Toshihiro Shimizu 890ddd
				if (reg)
Toshihiro Shimizu 890ddd
					reg->setStyle((*m_regionFillInformation)[i].m_styleId);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (m_strokeFillInformation) {
Toshihiro Shimizu 890ddd
			for (UINT i = 0; i < m_strokeFillInformation->size(); i++) {
Toshihiro Shimizu 890ddd
				TStroke *s = img->getStroke((*m_strokeFillInformation)[i].first);
Toshihiro Shimizu 890ddd
				s->setStyle((*m_strokeFillInformation)[i].second);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TVectorImageP img = m_level->getFrame(m_frameId, true);
Toshihiro Shimizu 890ddd
		assert(img);
Toshihiro Shimizu 890ddd
		if (!img)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		img->selectFill(m_selectionArea, m_stroke, m_styleId, m_unpaintedOnly, m_regionFillInformation != 0, m_strokeFillInformation != 0);
Toshihiro Shimizu 890ddd
		app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onAdd()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int size1 = m_regionFillInformation ? m_regionFillInformation->capacity() * sizeof(m_regionFillInformation) : 0;
Toshihiro Shimizu 890ddd
		int size2 = m_strokeFillInformation ? m_strokeFillInformation->capacity() * sizeof(m_strokeFillInformation) : 0;
Toshihiro Shimizu 890ddd
		return sizeof(*this) + size1 + size2 + 500;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QString getToolName()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QString("Fill Tool : ");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::FillTool;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterFillUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RasterFillUndo : public TRasterUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FillParameters m_params;
Toshihiro Shimizu 890ddd
	bool m_saveboxOnly;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	/*RasterFillUndo(TTileSetCM32 *tileSet, TPoint fillPoint,
Toshihiro Shimizu 890ddd
								 int paintId, int fillDepth,
Shinya Kitaoka 3bfa54
								 std::wstring fillType, bool isSegment,
Toshihiro Shimizu 890ddd
								 bool selective, bool isShiftFill,
Toshihiro Shimizu 890ddd
								 TXshSimpleLevel* sl, const TFrameId& fid)*/
Toshihiro Shimizu 890ddd
	RasterFillUndo(TTileSetCM32 *tileSet, const FillParameters ¶ms,
Toshihiro Shimizu 890ddd
				   TXshSimpleLevel *sl, const TFrameId &fid, bool saveboxOnly)
Toshihiro Shimizu 890ddd
		: TRasterUndo(tileSet, sl, fid, false, false, 0), m_params(params), m_saveboxOnly(saveboxOnly)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TToonzImageP image = getImage();
Toshihiro Shimizu 890ddd
		if (!image)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		bool recomputeSavebox = false;
Toshihiro Shimizu 890ddd
		TRasterCM32P r;
Toshihiro Shimizu 890ddd
		if (m_saveboxOnly) {
Toshihiro Shimizu 890ddd
			TRectD temp = image->getBBox();
Toshihiro Shimizu 890ddd
			TRect ttemp = convert(temp);
Toshihiro Shimizu 890ddd
			r = image->getRaster()->extract(ttemp);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			r = image->getRaster();
Toshihiro Shimizu 890ddd
		if (m_params.m_fillType == ALL || m_params.m_fillType == AREAS) {
Toshihiro Shimizu 890ddd
			if (m_params.m_shiftFill) {
Toshihiro Shimizu 890ddd
				FillParameters aux(m_params);
Toshihiro Shimizu 890ddd
				aux.m_styleId = (m_params.m_styleId == 0) ? 1 : 0;
Toshihiro Shimizu 890ddd
				recomputeSavebox = fill(r, aux);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			recomputeSavebox = fill(r, m_params);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (m_params.m_fillType == ALL || m_params.m_fillType == LINES) {
Toshihiro Shimizu 890ddd
			if (m_params.m_segment)
Toshihiro Shimizu 890ddd
				inkSegment(r, m_params.m_p, m_params.m_styleId, 2.51, true);
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				inkFill(r, m_params.m_p, m_params.m_styleId, 2);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (recomputeSavebox)
Toshihiro Shimizu 890ddd
			ToolUtils::updateSaveBox();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (app) {
Toshihiro Shimizu 890ddd
			app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
			notifyImageChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + TRasterUndo::getSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QString getToolName()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QString("Fill Tool : %1").arg(QString::fromStdWString(m_params.m_fillType));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::FillTool;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterRectFillUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RasterRectFillUndo : public TRasterUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect m_fillArea;
Toshihiro Shimizu 890ddd
	int m_paintId;
Shinya Kitaoka 3bfa54
	std::wstring m_colorType;
Toshihiro Shimizu 890ddd
	TStroke *m_s;
Toshihiro Shimizu 890ddd
	bool m_onlyUnfilled;
Toshihiro Shimizu 890ddd
	TPalette *m_palette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	~RasterRectFillUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_s)
Toshihiro Shimizu 890ddd
			delete m_s;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	RasterRectFillUndo(TTileSetCM32 *tileSet, TStroke *s,
Toshihiro Shimizu 890ddd
					   TRect fillArea, int paintId,
Toshihiro Shimizu 890ddd
					   TXshSimpleLevel *level,
Shinya Kitaoka 3bfa54
					   std::wstring colorType, bool onlyUnfilled,
Toshihiro Shimizu 890ddd
					   const TFrameId &fid, TPalette *palette)
Toshihiro Shimizu 890ddd
		: TRasterUndo(tileSet, level, fid, false, false, 0), m_fillArea(fillArea), m_paintId(paintId), m_colorType(colorType), m_onlyUnfilled(onlyUnfilled), m_palette(palette)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_s = s ? new TStroke(*s) : 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TToonzImageP image = getImage();
Toshihiro Shimizu 890ddd
		if (!image)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TRasterCM32P ras = image->getRaster();
Toshihiro Shimizu 890ddd
		AreaFiller filler(ras);
Toshihiro Shimizu 890ddd
		if (!m_s)
Toshihiro Shimizu 890ddd
			filler.rectFill(m_fillArea, m_paintId, m_onlyUnfilled, m_colorType != LINES, m_colorType != AREAS);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			filler.strokeFill(m_s, m_paintId, m_onlyUnfilled, m_colorType != LINES, m_colorType != AREAS);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_palette) {
Toshihiro Shimizu 890ddd
			TRect rect = m_fillArea;
Toshihiro Shimizu 890ddd
			TRect bounds = ras->getBounds();
Toshihiro Shimizu 890ddd
			if (bounds.overlaps(rect)) {
Toshihiro Shimizu 890ddd
				rect *= bounds;
Toshihiro Shimizu 890ddd
				const TTileSetCM32::Tile *tile = m_tiles->getTile(m_tiles->getTileCount() - 1);
Toshihiro Shimizu 890ddd
				TRasterCM32P rbefore;
Toshihiro Shimizu 890ddd
				tile->getRaster(rbefore);
Toshihiro Shimizu 890ddd
				fillautoInks(ras, rect, rbefore, m_palette);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (app) {
Toshihiro Shimizu 890ddd
			app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
			notifyImageChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int size = m_s ? m_s->getControlPointCount() * sizeof(TThickPoint) + 100 : 0;
Toshihiro Shimizu 890ddd
		return sizeof(*this) + TRasterUndo::getSize() + size;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QString getToolName()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QString("Fill Tool : %1").arg(QString::fromStdWString(m_colorType));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::FillTool;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterRectAutoFillUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RasterRectAutoFillUndo : public TRasterUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect m_rectToFill;
Toshihiro Shimizu 890ddd
	TFrameId m_fidToLearn;
Toshihiro Shimizu 890ddd
	bool m_onlyUnfilled;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	~RasterRectAutoFillUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	RasterRectAutoFillUndo(TTileSetCM32 *tileSet,
Toshihiro Shimizu 890ddd
						   const TRect &rectToFill,
Toshihiro Shimizu 890ddd
						   TXshSimpleLevel *level,
Toshihiro Shimizu 890ddd
						   bool onlyUnfilled,
Toshihiro Shimizu 890ddd
						   const TFrameId ¤tFid, const TFrameId &fidToLearn)
Toshihiro Shimizu 890ddd
		: TRasterUndo(tileSet, level, currentFid, false, false, 0), m_rectToFill(rectToFill), m_onlyUnfilled(onlyUnfilled), m_fidToLearn(fidToLearn)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TToonzImageP image = getImage();
Toshihiro Shimizu 890ddd
		TToonzImageP imageToLearn = m_level->getFrame(m_fidToLearn, false);
Toshihiro Shimizu 890ddd
		if (!image || !imageToLearn)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		rect_autofill_learn(imageToLearn,
Toshihiro Shimizu 890ddd
							m_rectToFill.x0,
Toshihiro Shimizu 890ddd
							m_rectToFill.y0,
Toshihiro Shimizu 890ddd
							m_rectToFill.x1,
Toshihiro Shimizu 890ddd
							m_rectToFill.y1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTileSetCM32 tileSet(image->getRaster()->getSize());
Toshihiro Shimizu 890ddd
		bool recomputeBBox = rect_autofill_apply(image,
Toshihiro Shimizu 890ddd
												 m_rectToFill.x0,
Toshihiro Shimizu 890ddd
												 m_rectToFill.y0,
Toshihiro Shimizu 890ddd
												 m_rectToFill.x1,
Toshihiro Shimizu 890ddd
												 m_rectToFill.y1,
Toshihiro Shimizu 890ddd
												 m_onlyUnfilled, &tileSet);
Toshihiro Shimizu 890ddd
		if (recomputeBBox)
Toshihiro Shimizu 890ddd
			ToolUtils::updateSaveBox();
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (app) {
Toshihiro Shimizu 890ddd
			app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
			notifyImageChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + TRasterUndo::getSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterStrokeAutoFillUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RasterStrokeAutoFillUndo : public TRasterUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTileSetCM32 *m_tileSet;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	~RasterStrokeAutoFillUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_tileSet)
Toshihiro Shimizu 890ddd
			delete m_tileSet;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	RasterStrokeAutoFillUndo(TTileSetCM32 *tileSet,
Toshihiro Shimizu 890ddd
							 TXshSimpleLevel *level,
Toshihiro Shimizu 890ddd
							 const TFrameId ¤tFid)
Toshihiro Shimizu 890ddd
		: TRasterUndo(tileSet, level, currentFid, false, false, 0), m_tileSet(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setTileSet(TTileSetCM32 *tileSet) { m_tileSet = tileSet; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TToonzImageP image = getImage();
Toshihiro Shimizu 890ddd
		if (!image)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ToonzImageUtils::paste(image, m_tileSet);
Toshihiro Shimizu 890ddd
		ToolUtils::updateSaveBox(m_level, m_frameId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (app) {
Toshihiro Shimizu 890ddd
			app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
			notifyImageChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + TRasterUndo::getSize() + m_tileSet->getMemorySize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RasterRectAutoFillUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class VectorAutoFillUndo : public TToolUndo
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::vector<tfilledregioninf> *m_regionFillInformation;</tfilledregioninf>
Toshihiro Shimizu 890ddd
	TRectD m_selectionArea;
Toshihiro Shimizu 890ddd
	TStroke *m_selectingStroke;
Toshihiro Shimizu 890ddd
	bool m_unpaintedOnly;
Toshihiro Shimizu 890ddd
	TFrameId m_onionFid;
Toshihiro Shimizu 890ddd
	int m_row;
Toshihiro Shimizu 890ddd
	int m_column;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	~VectorAutoFillUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_regionFillInformation)
Toshihiro Shimizu 890ddd
			delete m_regionFillInformation;
Toshihiro Shimizu 890ddd
		if (m_selectingStroke)
Toshihiro Shimizu 890ddd
			delete m_selectingStroke;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	VectorAutoFillUndo(
Shinya Kitaoka 3bfa54
		std::vector<tfilledregioninf> *regionFillInformation,</tfilledregioninf>
Toshihiro Shimizu 890ddd
		TRectD selectionArea,
Toshihiro Shimizu 890ddd
		TStroke *selectingStroke,
Toshihiro Shimizu 890ddd
		bool unpaintedOnly,
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl,
Toshihiro Shimizu 890ddd
		const TFrameId &fid,
Toshihiro Shimizu 890ddd
		const TFrameId &onionFid)
Toshihiro Shimizu 890ddd
		: TToolUndo(sl, fid), m_regionFillInformation(regionFillInformation), m_selectionArea(selectionArea), m_unpaintedOnly(unpaintedOnly), m_onionFid(onionFid)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_selectingStroke = selectingStroke ? new TStroke(*selectingStroke) : 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TVectorImageP img = m_level->getFrame(m_frameId, true);
Toshihiro Shimizu 890ddd
		;
Toshihiro Shimizu 890ddd
		assert(!!img);
Toshihiro Shimizu 890ddd
		if (!img)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		if (m_regionFillInformation) {
Toshihiro Shimizu 890ddd
			for (UINT i = 0; i < m_regionFillInformation->size(); i++) {
Toshihiro Shimizu 890ddd
				TRegion *reg = img->getRegion((*m_regionFillInformation)[i].m_regionId);
Toshihiro Shimizu 890ddd
				if (reg)
Toshihiro Shimizu 890ddd
					reg->setStyle((*m_regionFillInformation)[i].m_styleId);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TVectorImageP img = m_level->getFrame(m_frameId, true);
Toshihiro Shimizu 890ddd
		assert(img);
Toshihiro Shimizu 890ddd
		if (!img)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TVectorImageP onionImg = m_level->getFrame(m_onionFid, false);
Toshihiro Shimizu 890ddd
		if (!onionImg)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_selectingStroke) {
Toshihiro Shimizu 890ddd
			stroke_autofill_learn(onionImg, m_selectingStroke);
Toshihiro Shimizu 890ddd
			stroke_autofill_apply(img, m_selectingStroke, m_unpaintedOnly);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			rect_autofill_learn(onionImg, m_selectionArea);
Toshihiro Shimizu 890ddd
			rect_autofill_apply(img, m_selectionArea, m_unpaintedOnly);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		notifyImageChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int size = m_selectingStroke ? m_selectingStroke->getControlPointCount() * sizeof(TThickPoint) + 100 : 0;
Toshihiro Shimizu 890ddd
		return sizeof(*this) + m_regionFillInformation->capacity() * sizeof(m_regionFillInformation) + 500 + size;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void doRectAutofill(const TImageP &img, const TRectD selectingRect, bool onlyUnfilled, const OnionSkinMask &osMask,
Toshihiro Shimizu 890ddd
					TXshSimpleLevel *sl, const TFrameId ¤tFid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TToonzImageP ti(img);
Toshihiro Shimizu 890ddd
	TVectorImageP vi(img);
Toshihiro Shimizu 890ddd
	if (!img || !sl)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<int> rows;</int>
Toshihiro Shimizu 890ddd
	osMask.getAll(sl->guessIndex(currentFid), rows);
Toshihiro Shimizu 890ddd
	if (rows.empty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameId onionFid;
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < (int)rows.size(); i++) {
Toshihiro Shimizu 890ddd
		const TFrameId &app = sl->index2fid(rows[i]);
Toshihiro Shimizu 890ddd
		if (app > currentFid)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		onionFid = app;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (onionFid.isEmptyFrame())
Toshihiro Shimizu 890ddd
		onionFid = sl->index2fid(rows[0]);
Toshihiro Shimizu 890ddd
	if (onionFid.isEmptyFrame() || onionFid == currentFid || !sl->isFid(onionFid))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (ti) {
Toshihiro Shimizu 890ddd
		TRect rect = ToonzImageUtils::convertWorldToRaster(selectingRect, ti);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TToonzImageP onionImg(sl->getFrame(onionFid, false));
Toshihiro Shimizu 890ddd
		if (!onionImg)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TRect workRect = rect * ti->getRaster()->getBounds();
Toshihiro Shimizu 890ddd
		if (workRect.isEmpty())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		rect_autofill_learn(onionImg,
Toshihiro Shimizu 890ddd
							workRect.x0,
Toshihiro Shimizu 890ddd
							workRect.y0,
Toshihiro Shimizu 890ddd
							workRect.x1,
Toshihiro Shimizu 890ddd
							workRect.y1);
Toshihiro Shimizu 890ddd
		TTileSetCM32 *tileSet = new TTileSetCM32(ti->getRaster()->getSize());
Toshihiro Shimizu 890ddd
		bool recomputeBBox = rect_autofill_apply(ti,
Toshihiro Shimizu 890ddd
												 workRect.x0,
Toshihiro Shimizu 890ddd
												 workRect.y0,
Toshihiro Shimizu 890ddd
												 workRect.x1,
Toshihiro Shimizu 890ddd
												 workRect.y1,
Toshihiro Shimizu 890ddd
												 onlyUnfilled, tileSet);
Toshihiro Shimizu 890ddd
		if (recomputeBBox)
Toshihiro Shimizu 890ddd
			ToolUtils::updateSaveBox();
Toshihiro Shimizu 890ddd
		if (tileSet->getTileCount() > 0)
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->add(new RasterRectAutoFillUndo(tileSet, workRect, sl, onlyUnfilled,
Toshihiro Shimizu 890ddd
																	currentFid, onionFid));
Toshihiro Shimizu 890ddd
	} else if (vi) {
Toshihiro Shimizu 890ddd
		TVectorImageP onionImg(sl->getFrame(onionFid, false));
Toshihiro Shimizu 890ddd
		if (!onionImg)
Toshihiro Shimizu 890ddd
			return;
Shinya Kitaoka 3bfa54
		std::vector<tfilledregioninf> *regionFillInformation = new std::vector<tfilledregioninf>;</tfilledregioninf></tfilledregioninf>
Toshihiro Shimizu 890ddd
		ImageUtils::getFillingInformationInArea(vi, *regionFillInformation, selectingRect);
Toshihiro Shimizu 890ddd
		onionImg->findRegions();
Toshihiro Shimizu 890ddd
		vi->findRegions();
Toshihiro Shimizu 890ddd
		rect_autofill_learn(onionImg, selectingRect);
Toshihiro Shimizu 890ddd
		bool hasFilled = rect_autofill_apply(vi, selectingRect, onlyUnfilled);
Toshihiro Shimizu 890ddd
		if (hasFilled)
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->add(new VectorAutoFillUndo(regionFillInformation, selectingRect, 0,
Toshihiro Shimizu 890ddd
																onlyUnfilled, sl, currentFid, onionFid));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void doStrokeAutofill(const TImageP &img, TStroke *selectingStroke, bool onlyUnfilled, const OnionSkinMask &osMask,
Toshihiro Shimizu 890ddd
					  TXshSimpleLevel *sl, const TFrameId ¤tFid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TToonzImageP ti(img);
Toshihiro Shimizu 890ddd
	TVectorImageP vi(img);
Toshihiro Shimizu 890ddd
	if (!img || !sl)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<int> rows;</int>
Toshihiro Shimizu 890ddd
	osMask.getAll(sl->guessIndex(currentFid), rows);
Toshihiro Shimizu 890ddd
	if (rows.empty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameId onionFid;
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < (int)rows.size(); i++) {
Toshihiro Shimizu 890ddd
		const TFrameId &app = sl->index2fid(rows[i]);
Toshihiro Shimizu 890ddd
		if (app > currentFid)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		onionFid = app;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (onionFid.isEmptyFrame())
Toshihiro Shimizu 890ddd
		onionFid = sl->index2fid(rows[0]);
Toshihiro Shimizu 890ddd
	if (onionFid.isEmptyFrame() || onionFid == currentFid || !sl->isFid(onionFid))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (ti) {
Toshihiro Shimizu 890ddd
		TToonzImageP onionImg(sl->getFrame(onionFid, false));
Toshihiro Shimizu 890ddd
		if (!onionImg)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRasterCM32P ras = onionImg->getRaster();
Toshihiro Shimizu 890ddd
		TPointD center = ras->getCenterD();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPoint pos;
Toshihiro Shimizu 890ddd
		TRaster32P image = convertStrokeToImage(selectingStroke, ras->getBounds(), pos);
Toshihiro Shimizu 890ddd
		TRect bbox = (image->getBounds() + pos).enlarge(2);
Toshihiro Shimizu 890ddd
		pos = bbox.getP00();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRasterCM32P onionAppRas = ras->extract(bbox)->clone();
Toshihiro Shimizu 890ddd
		TRasterCM32P tiAppRas = ti->getRaster()->extract(bbox)->clone();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRect workRect = onionAppRas->getBounds().enlarge(-1);
Toshihiro Shimizu 890ddd
		TToonzImageP onionApp(onionAppRas, workRect);
Toshihiro Shimizu 890ddd
		TToonzImageP tiApp(tiAppRas, workRect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ToonzImageUtils::eraseImage(onionApp, image, TPoint(2, 2), true, true, true, false, 1);
Toshihiro Shimizu 890ddd
		ToonzImageUtils::eraseImage(tiApp, image, TPoint(2, 2), true, true, true, false, 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		rect_autofill_learn(onionApp,
Toshihiro Shimizu 890ddd
							workRect.x0,
Toshihiro Shimizu 890ddd
							workRect.y0,
Toshihiro Shimizu 890ddd
							workRect.x1,
Toshihiro Shimizu 890ddd
							workRect.y1);
Toshihiro Shimizu 890ddd
		TTileSetCM32 *tileSet = new TTileSetCM32(ti->getRaster()->getSize());
Toshihiro Shimizu 890ddd
		bool recomputeBBox = rect_autofill_apply(tiApp,
Toshihiro Shimizu 890ddd
												 workRect.x0,
Toshihiro Shimizu 890ddd
												 workRect.y0,
Toshihiro Shimizu 890ddd
												 workRect.x1,
Toshihiro Shimizu 890ddd
												 workRect.y1,
Toshihiro Shimizu 890ddd
												 onlyUnfilled, tileSet);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		delete tileSet;
Toshihiro Shimizu 890ddd
		tileSet = new TTileSetCM32(ti->getRaster()->getSize());
Toshihiro Shimizu 890ddd
		tileSet->add(ti->getRaster(), bbox);
Toshihiro Shimizu 890ddd
		RasterStrokeAutoFillUndo *undo = new RasterStrokeAutoFillUndo(tileSet, sl, currentFid);
Toshihiro Shimizu 890ddd
		TRop::over(ti->getRaster(), tiAppRas, pos);
Toshihiro Shimizu 890ddd
		TTileSetCM32 *newTileSet = new TTileSetCM32(ti->getRaster()->getSize());
Toshihiro Shimizu 890ddd
		newTileSet->add(ti->getRaster(), bbox);
Toshihiro Shimizu 890ddd
		undo->setTileSet(newTileSet);
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	} else if (vi) {
Toshihiro Shimizu 890ddd
		TVectorImageP onionImg(sl->getFrame(onionFid, false));
Toshihiro Shimizu 890ddd
		if (!onionImg)
Toshihiro Shimizu 890ddd
			return;
Shinya Kitaoka 3bfa54
		std::vector<tfilledregioninf> *regionFillInformation = new std::vector<tfilledregioninf>;</tfilledregioninf></tfilledregioninf>
Toshihiro Shimizu 890ddd
		ImageUtils::getFillingInformationInArea(vi, *regionFillInformation, selectingStroke->getBBox());
Toshihiro Shimizu 890ddd
		onionImg->findRegions();
Toshihiro Shimizu 890ddd
		vi->findRegions();
Toshihiro Shimizu 890ddd
		stroke_autofill_learn(onionImg, selectingStroke);
Toshihiro Shimizu 890ddd
		bool hasFilled = stroke_autofill_apply(vi, selectingStroke, onlyUnfilled);
Toshihiro Shimizu 890ddd
		if (hasFilled)
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->add(new VectorAutoFillUndo(regionFillInformation, TRectD(), selectingStroke,
Toshihiro Shimizu 890ddd
																onlyUnfilled, sl, currentFid, onionFid));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// fillRectWithUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool inline hasAutoInks(const TPalette *plt)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < plt->getStyleCount(); i++)
Toshihiro Shimizu 890ddd
		if (plt->getStyle(i)->getFlags() != 0)
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void fillAreaWithUndo(
Toshihiro Shimizu 890ddd
	const TImageP &img,
Toshihiro Shimizu 890ddd
	const TRectD &area,
Toshihiro Shimizu 890ddd
	TStroke *stroke,
Toshihiro Shimizu 890ddd
	bool onlyUnfilled,
Shinya Kitaoka 3bfa54
	std::wstring colorType,
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl,
Toshihiro Shimizu 890ddd
	const TFrameId &fid,
Toshihiro Shimizu 890ddd
	int cs)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRectD selArea = stroke ? stroke->getBBox() : area;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TToonzImageP ti = img) {
Toshihiro Shimizu 890ddd
		//allargo di 1 la savebox, perche cosi' il rectfill di tutta l'immagine fa una sola fillata
Toshihiro Shimizu 890ddd
		TRect enlargedSavebox = ti->getSavebox().enlarge(1) * TRect(TPoint(0, 0), ti->getSize());
Toshihiro Shimizu 890ddd
		TRect rasterFillArea = ToonzImageUtils::convertWorldToRaster(selArea, ti) * enlargedSavebox;
Toshihiro Shimizu 890ddd
		if (rasterFillArea.isEmpty())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRasterCM32P ras = ti->getRaster();
Toshihiro Shimizu 890ddd
		/*-- tileSetでFill範囲のRectをUndoに格納しておく --*/
Toshihiro Shimizu 890ddd
		TTileSetCM32 *tileSet = new TTileSetCM32(ras->getSize());
Toshihiro Shimizu 890ddd
		tileSet->add(ras, rasterFillArea);
Toshihiro Shimizu 890ddd
		AreaFiller filler(ti->getRaster());
Toshihiro Shimizu 890ddd
		if (!stroke)
Toshihiro Shimizu 890ddd
			filler.rectFill(rasterFillArea, cs, onlyUnfilled, colorType != LINES, colorType != AREAS);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			filler.strokeFill(stroke, cs, onlyUnfilled, colorType != LINES, colorType != AREAS);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPalette *plt = ti->getPalette();
Toshihiro Shimizu 890ddd
		if (plt && !hasAutoInks(plt))
Toshihiro Shimizu 890ddd
			plt = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::set<int> autoInks;</int>
Toshihiro Shimizu 890ddd
		autoInks.insert(3);
Toshihiro Shimizu 890ddd
		autoInks.insert(4);
Toshihiro Shimizu 890ddd
		autoInks.insert(5);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (plt) {
Toshihiro Shimizu 890ddd
			TRect rect = rasterFillArea;
Toshihiro Shimizu 890ddd
			TRect bounds = ras->getBounds();
Toshihiro Shimizu 890ddd
			if (bounds.overlaps(rect)) {
Toshihiro Shimizu 890ddd
				rect *= bounds;
Toshihiro Shimizu 890ddd
				const TTileSetCM32::Tile *tile = tileSet->getTile(tileSet->getTileCount() - 1);
Toshihiro Shimizu 890ddd
				TRasterCM32P rbefore;
Toshihiro Shimizu 890ddd
				tile->getRaster(rbefore);
Toshihiro Shimizu 890ddd
				fillautoInks(ras, rect, rbefore, plt);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		ToolUtils::updateSaveBox(sl, fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(new RasterRectFillUndo(tileSet, stroke,
Toshihiro Shimizu 890ddd
															rasterFillArea,
Toshihiro Shimizu 890ddd
															cs, sl, colorType,
Toshihiro Shimizu 890ddd
															onlyUnfilled, fid, plt));
Toshihiro Shimizu 890ddd
	} else if (TVectorImageP vi = img) {
Toshihiro Shimizu 890ddd
		TPalette *palette = vi->getPalette();
Toshihiro Shimizu 890ddd
		assert(palette);
Toshihiro Shimizu 890ddd
		const TColorStyle *style = palette->getStyle(cs);
Toshihiro Shimizu 890ddd
		//if( !style->isRegionStyle() )
Toshihiro Shimizu 890ddd
		//return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		vi->findRegions();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
		std::vector<tfilledregioninf> *regionFillInformation = 0;</tfilledregioninf>
Shinya Kitaoka 3bfa54
		std::vector<std::pair<int, int="">> *strokeFillInformation = 0;</std::pair<int,>
Toshihiro Shimizu 890ddd
		if (colorType != LINES) {
Shinya Kitaoka 3bfa54
			regionFillInformation = new std::vector<tfilledregioninf>;</tfilledregioninf>
Toshihiro Shimizu 890ddd
			ImageUtils::getFillingInformationInArea(vi, *regionFillInformation, selArea);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (colorType != AREAS) {
Shinya Kitaoka 3bfa54
			strokeFillInformation = new std::vector<std::pair<int, int="">>;</std::pair<int,>
Toshihiro Shimizu 890ddd
			ImageUtils::getStrokeStyleInformationInArea(vi, *strokeFillInformation, selArea);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		VectorRectFillUndo *fUndo =
Toshihiro Shimizu 890ddd
			new VectorRectFillUndo(regionFillInformation, strokeFillInformation, selArea, stroke, cs, onlyUnfilled, sl, fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QMutexLocker lock(vi->getMutex());
Toshihiro Shimizu 890ddd
		if (vi->selectFill(area, stroke, cs, onlyUnfilled, colorType != LINES, colorType != AREAS))
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->add(fUndo);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			delete fUndo;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// doFill
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void doFill(const TImageP &img,
Toshihiro Shimizu 890ddd
			const TPointD &pos,
Toshihiro Shimizu 890ddd
			FillParameters ¶ms,
Toshihiro Shimizu 890ddd
			bool isShiftFill,
Toshihiro Shimizu 890ddd
			TXshSimpleLevel *sl,
Toshihiro Shimizu 890ddd
			const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	if (!app)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TToonzImageP ti = TToonzImageP(img)) {
Toshihiro Shimizu 890ddd
		TPoint offs(0, 0);
Toshihiro Shimizu 890ddd
		TRasterCM32P ras = ti->getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (Preferences::instance()->getFillOnlySavebox()) {
Toshihiro Shimizu 890ddd
			TRectD bbox = ti->getBBox();
Toshihiro Shimizu 890ddd
			TRect ibbox = convert(bbox);
Toshihiro Shimizu 890ddd
			offs = ibbox.getP00();
Toshihiro Shimizu 890ddd
			ras = ti->getRaster()->extract(ibbox);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bool recomputeSavebox = false;
Toshihiro Shimizu 890ddd
		TPalette *plt = ti->getPalette();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!ras.getPointer() || ras->isEmpty())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ras->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTileSetCM32 *tileSet = new TTileSetCM32(ras->getSize());
Toshihiro Shimizu 890ddd
		TTileSaverCM32 tileSaver(ras, tileSet);
Toshihiro Shimizu 890ddd
		TDimension imageSize = ti->getSize();
Toshihiro Shimizu 890ddd
		TPointD p(imageSize.lx % 2 ? 0.0 : 0.5, imageSize.ly % 2 ? 0.0 : 0.5);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/*-- params.m_p = convert(pos-p)では、マイナス座標でずれが生じる --*/
Toshihiro Shimizu 890ddd
		TPointD tmp_p = pos - p;
Toshihiro Shimizu 890ddd
		params.m_p = TPoint((int)floor(tmp_p.x + 0.5), (int)floor(tmp_p.y + 0.5));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		params.m_p += ti->getRaster()->getCenter();
Toshihiro Shimizu 890ddd
		params.m_p -= offs;
Toshihiro Shimizu 890ddd
		params.m_shiftFill = isShiftFill;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRect rasRect(ras->getSize());
Toshihiro Shimizu 890ddd
		if (!rasRect.contains(params.m_p)) {
Toshihiro Shimizu 890ddd
			ras->unlock();
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (plt && hasAutoInks(plt))
Toshihiro Shimizu 890ddd
			params.m_palette = plt;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (params.m_fillType == ALL || params.m_fillType == AREAS) {
Toshihiro Shimizu 890ddd
			if (isShiftFill) {
Toshihiro Shimizu 890ddd
				FillParameters aux(params);
Toshihiro Shimizu 890ddd
				aux.m_styleId = (params.m_styleId == 0) ? 1 : 0;
Toshihiro Shimizu 890ddd
				recomputeSavebox = fill(ras, aux, &tileSaver);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			recomputeSavebox = fill(ras, params, &tileSaver);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (params.m_fillType == ALL || params.m_fillType == LINES) {
Toshihiro Shimizu 890ddd
			if (params.m_segment)
Toshihiro Shimizu 890ddd
				inkSegment(ras, params.m_p, params.m_styleId, 2.51, true, &tileSaver);
Toshihiro Shimizu 890ddd
			else if (!params.m_segment)
Toshihiro Shimizu 890ddd
				inkFill(ras, params.m_p, params.m_styleId, 2, &tileSaver);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (tileSaver.getTileSet()->getTileCount() != 0) {
Toshihiro Shimizu 890ddd
			static int count = 0;
Toshihiro Shimizu 890ddd
			TSystem::outputDebug("FILL" + toString(count++) + "\n");
Toshihiro Shimizu 890ddd
			if (offs != TPoint())
Toshihiro Shimizu 890ddd
				for (int i = 0; i < tileSet->getTileCount(); i++) {
Toshihiro Shimizu 890ddd
					TTileSet::Tile *t = tileSet->editTile(i);
Toshihiro Shimizu 890ddd
					t->m_rasterBounds = t->m_rasterBounds + offs;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->add(new RasterFillUndo(tileSet, params, sl, fid, Preferences::instance()->getFillOnlySavebox()));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// al posto di updateFrame:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TXshLevel *xl = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		if (!xl)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = xl->getSimpleLevel();
Toshihiro Shimizu 890ddd
		sl->getProperties()->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		if (recomputeSavebox && Preferences::instance()->isMinimizeSaveboxAfterEditing())
Toshihiro Shimizu 890ddd
			ToolUtils::updateSaveBox(sl, fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ras->unlock();
Toshihiro Shimizu 890ddd
	} else if (TVectorImageP vi = TImageP(img)) {
Toshihiro Shimizu 890ddd
		int oldStyleId;
Toshihiro Shimizu 890ddd
		QMutexLocker lock(vi->getMutex());
Toshihiro Shimizu 890ddd
		/*if(params.m_fillType==ALL || params.m_fillType==AREAS)
Toshihiro Shimizu 890ddd
    vi->computeRegion(pos, params.m_styleId);*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if ((oldStyleId = vectorFill(vi, params.m_fillType, pos, params.m_styleId, params.m_emptyOnly)) != -1)
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->add(
Toshihiro Shimizu 890ddd
				new VectorFillUndo(params.m_styleId, oldStyleId, params.m_fillType, pos, sl, fid));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTool *t = app->getCurrentTool()->getTool();
Toshihiro Shimizu 890ddd
	if (t)
Toshihiro Shimizu 890ddd
		t->notifyImageChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// SequencePainter
Toshihiro Shimizu 890ddd
// da spostare in toolutils?
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class SequencePainter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual void process(TImageP img /*, TImageLocation &imgloc*/, double t, TXshSimpleLevel *sl, const TFrameId &fid) = 0;
Toshihiro Shimizu 890ddd
	void processSequence(TXshSimpleLevel *sl, TFrameId firstFid, TFrameId lastFid);
Toshihiro Shimizu 890ddd
	virtual ~SequencePainter() {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SequencePainter::processSequence(TXshSimpleLevel *sl, TFrameId firstFid, TFrameId lastFid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!sl)
Toshihiro Shimizu 890ddd
		return;
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
	sl->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
		TImageP img = sl->getFrame(fid, true);
Toshihiro Shimizu 890ddd
		double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;
Toshihiro Shimizu 890ddd
		process(img, backward ? 1 - t : t, sl, fid);
Toshihiro Shimizu 890ddd
		//Setto il fid come corrente per notificare il cambiamento dell'immagine
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (app) {
Toshihiro Shimizu 890ddd
			if (app->getCurrentFrame()->isEditingScene())
Toshihiro Shimizu 890ddd
				app->getCurrentFrame()->setFrame(fid.getNumber());
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				app->getCurrentFrame()->setFid(fid);
Toshihiro Shimizu 890ddd
			TTool *tool = app->getCurrentTool()->getTool();
Toshihiro Shimizu 890ddd
			if (tool)
Toshihiro Shimizu 890ddd
				tool->notifyImageChanged(fid);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// MultiAreaFiller : SequencePainter
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class MultiAreaFiller : public SequencePainter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRectD m_firstRect, m_lastRect;
Toshihiro Shimizu 890ddd
	bool m_unfilledOnly;
Shinya Kitaoka 3bfa54
	std::wstring m_colorType;
Toshihiro Shimizu 890ddd
	TVectorImageP m_firstImage, m_lastImage;
Toshihiro Shimizu 890ddd
	int m_styleIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	MultiAreaFiller(
Toshihiro Shimizu 890ddd
		const TRectD &firstRect,
Toshihiro Shimizu 890ddd
		const TRectD &lastRect,
Toshihiro Shimizu 890ddd
		bool unfilledOnly,
Shinya Kitaoka 3bfa54
		std::wstring colorType,
Toshihiro Shimizu 890ddd
		int styleIndex)
Toshihiro Shimizu 890ddd
		: m_firstRect(firstRect), m_lastRect(lastRect), m_unfilledOnly(unfilledOnly), m_colorType(colorType), m_firstImage(), m_lastImage(), m_styleIndex(styleIndex)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~MultiAreaFiller()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_firstImage) {
Toshihiro Shimizu 890ddd
			m_firstImage->removeStroke(0);
Toshihiro Shimizu 890ddd
			m_lastImage->removeStroke(0);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	MultiAreaFiller(
Toshihiro Shimizu 890ddd
		TStroke *&firstStroke,
Toshihiro Shimizu 890ddd
		TStroke *&lastStroke,
Toshihiro Shimizu 890ddd
		bool unfilledOnly,
Shinya Kitaoka 3bfa54
		std::wstring colorType,
Toshihiro Shimizu 890ddd
		int styleIndex)
Toshihiro Shimizu 890ddd
		: m_firstRect(), m_lastRect(), m_unfilledOnly(unfilledOnly), m_colorType(colorType), m_styleIndex(styleIndex)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_firstImage = new TVectorImage();
Toshihiro Shimizu 890ddd
		m_lastImage = new TVectorImage();
Toshihiro Shimizu 890ddd
		m_firstImage->addStroke(firstStroke);
Toshihiro Shimizu 890ddd
		m_lastImage->addStroke(lastStroke);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void process(TImageP img, double t, TXshSimpleLevel *sl, const TFrameId &fid)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_firstImage) {
Toshihiro Shimizu 890ddd
			TPointD p0 = m_firstRect.getP00() * (1 - t) + m_lastRect.getP00() * t;
Toshihiro Shimizu 890ddd
			TPointD p1 = m_firstRect.getP11() * (1 - t) + m_lastRect.getP11() * t;
Toshihiro Shimizu 890ddd
			TRectD rect(p0.x, p0.y, p1.x, p1.y);
Toshihiro Shimizu 890ddd
			fillAreaWithUndo(img, rect, 0, m_unfilledOnly, m_colorType, sl, fid, m_styleIndex);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			if (t == 0)
Toshihiro Shimizu 890ddd
				fillAreaWithUndo(img, TRectD(), m_firstImage->getStroke(0), m_unfilledOnly, m_colorType, sl, fid, m_styleIndex);
Toshihiro Shimizu 890ddd
			else if (t == 1)
Toshihiro Shimizu 890ddd
				fillAreaWithUndo(img, TRectD(), m_lastImage->getStroke(0), m_unfilledOnly, m_colorType, sl, fid, m_styleIndex);
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
			//if(t>1)
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				assert(t > 0 && t < 1);
Toshihiro Shimizu 890ddd
				assert(m_firstImage->getStrokeCount() == 1);
Toshihiro Shimizu 890ddd
				assert(m_lastImage->getStrokeCount() == 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				TVectorImageP vi = TInbetween(m_firstImage, m_lastImage).tween(t);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				assert(vi->getStrokeCount() == 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				fillAreaWithUndo(img, TRectD(), vi->getStroke(0) /*, imgloc*/, m_unfilledOnly, m_colorType, sl, fid, m_styleIndex);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// MultiFiller : SequencePainter
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class MultiFiller : public SequencePainter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_firstPoint, m_lastPoint;
Toshihiro Shimizu 890ddd
	FillParameters m_params;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	MultiFiller(
Toshihiro Shimizu 890ddd
		const TPointD &firstPoint,
Toshihiro Shimizu 890ddd
		const TPointD &lastPoint,
Toshihiro Shimizu 890ddd
		const FillParameters ¶ms)
Toshihiro Shimizu 890ddd
		: m_firstPoint(firstPoint), m_lastPoint(lastPoint), m_params(params)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void process(TImageP img, double t, TXshSimpleLevel *sl, const TFrameId &fid)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPointD p = m_firstPoint * (1 - t) + m_lastPoint * t;
Toshihiro Shimizu 890ddd
		doFill(img, p, m_params, false, sl, fid);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
					if(e.isShiftPressed())  
Toshihiro Shimizu 890ddd
            {
Toshihiro Shimizu 890ddd
						m_firstPoint = pos;
Toshihiro Shimizu 890ddd
						m_firstFrameId = TApplication::instance()->getCurrentFrameId();
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
					else
Toshihiro Shimizu 890ddd
					  {
Toshihiro Shimizu 890ddd
						m_firstClick = false;
Toshihiro Shimizu 890ddd
						TApplication::instance()->setCurrentFrame(m_veryFirstFrameId);
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
					TNotifier::instance()->notify(TLevelChange());
Toshihiro Shimizu 890ddd
          TNotifier::instance()->notify(TStageChange());
Toshihiro Shimizu 890ddd
          }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// AreaFillTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void drawPolyline(const std::vector<tpointd> &points)</tpointd>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (points.empty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	tglDrawCircle(points[0], 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (UINT i = 0; i < points.size() - 1; i++)
Toshihiro Shimizu 890ddd
		tglDrawSegment(points[i], points[i + 1]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class AreaFillTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum Type { RECT,
Toshihiro Shimizu 890ddd
				FREEHAND,
Toshihiro Shimizu 890ddd
				POLYLINE };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	bool m_frameRange;
Toshihiro Shimizu 890ddd
	bool m_onlyUnfilled;
Toshihiro Shimizu 890ddd
	Type m_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_selecting;
Toshihiro Shimizu 890ddd
	TRectD m_selectingRect;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD m_firstRect;
Toshihiro Shimizu 890ddd
	bool m_firstFrameSelected;
Toshihiro Shimizu 890ddd
	TXshSimpleLevelP m_level;
Toshihiro Shimizu 890ddd
	TFrameId m_firstFrameId, m_veryFirstFrameId;
Toshihiro Shimizu 890ddd
	TTool *m_parent;
Shinya Kitaoka 3bfa54
	std::wstring m_colorType;
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> m_currCell;</int,>
Toshihiro Shimizu 890ddd
	StrokeGenerator m_track;
Shinya Kitaoka 3bfa54
	std::vector<tpointd> m_polyline;</tpointd>
Toshihiro Shimizu 890ddd
	bool m_isPath;
Toshihiro Shimizu 890ddd
	bool m_active;
Toshihiro Shimizu 890ddd
	bool m_enabled;
Toshihiro Shimizu 890ddd
	double m_thick;
Toshihiro Shimizu 890ddd
	TPointD m_firstPos;
Toshihiro Shimizu 890ddd
	TStroke *m_firstStroke;
Toshihiro Shimizu 890ddd
	TPointD m_mousePosition;
Toshihiro Shimizu 890ddd
	bool m_onion;
Toshihiro Shimizu 890ddd
	bool m_isLeftButtonPressed;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	AreaFillTool(TTool *parent)
Toshihiro Shimizu 890ddd
		: m_frameRange(false), m_onlyUnfilled(false), m_selecting(false), m_selectingRect(TRectD()), m_firstRect(TRectD()), m_firstFrameSelected(false), m_level(0), m_parent(parent), m_colorType(AREAS), m_currCell(-1, -1), m_type(RECT), m_isPath(false), m_enabled(false), m_active(false), m_firstStroke(0), m_thick(0.5), m_mousePosition(), m_onion(false), m_isLeftButtonPressed(false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_thick = m_parent->getPixelSize() / 2.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPixel color = TPixel32::Red;
Toshihiro Shimizu 890ddd
		if (m_type == RECT) {
Toshihiro Shimizu 890ddd
			if (m_frameRange && m_firstFrameSelected)
Toshihiro Shimizu 890ddd
				drawRect(m_firstRect, color, 0x3F33, true);
Toshihiro Shimizu 890ddd
			if (m_selecting || (m_frameRange && !m_firstFrameSelected))
Toshihiro Shimizu 890ddd
				drawRect(m_selectingRect, color, 0xFFFF, true);
Toshihiro Shimizu 890ddd
		} else if ((m_type == FREEHAND || m_type == POLYLINE) && m_frameRange) {
Toshihiro Shimizu 890ddd
			tglColor(color);
Toshihiro Shimizu 890ddd
			if (m_firstStroke)
Toshihiro Shimizu 890ddd
				drawStrokeCenterline(*m_firstStroke, 1);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_type == POLYLINE && !m_polyline.empty()) {
Toshihiro Shimizu 890ddd
			glPushMatrix();
Toshihiro Shimizu 890ddd
			tglColor(TPixel::Red);
Toshihiro Shimizu 890ddd
			tglDrawCircle(m_polyline[0], 2);
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_mousePosition);
Toshihiro Shimizu 890ddd
			glEnd();
Toshihiro Shimizu 890ddd
			glPopMatrix();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void resetMulti()
Toshihiro Shimizu 890ddd
	{
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
		TXshLevel *xl = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		m_level = xl ? xl->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
		m_firstFrameId = m_veryFirstFrameId = m_parent->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
	void leftButtonDown(const TPointD &pos, const TMouseEvent &, TImage *img)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TVectorImageP vi = TImageP(img);
Toshihiro Shimizu 890ddd
		TToonzImageP ti = TToonzImageP(img);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!vi && !ti) {
Toshihiro Shimizu 890ddd
			m_selecting = false;
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_selecting = true;
Toshihiro Shimizu 890ddd
		if (m_type == RECT) {
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
		} else if (m_type == FREEHAND || m_type == POLYLINE) {
Toshihiro Shimizu 890ddd
			int col = TTool::getApplication()->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
			m_isPath = TTool::getApplication()->getCurrentObject()->isSpline(); //getApplication()->isEditingSpline();
Toshihiro Shimizu 890ddd
			m_enabled = col >= 0 || m_isPath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (!m_enabled)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			m_active = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_track.clear();
Toshihiro Shimizu 890ddd
			m_firstPos = pos;
Toshihiro Shimizu 890ddd
			double pixelSize2 = m_parent->getPixelSize() * m_parent->getPixelSize();
Toshihiro Shimizu 890ddd
			m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
			if (m_type == POLYLINE) {
Toshihiro Shimizu 890ddd
				if (m_polyline.empty() || m_polyline.back() != pos)
Toshihiro Shimizu 890ddd
					m_polyline.push_back(pos);
Toshihiro Shimizu 890ddd
				m_mousePosition = pos;
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TPointD dpiScale = m_parent->getViewer()->getDpiScale();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Toshihiro Shimizu 890ddd
//m_parent->m_viewer->prepareForegroundDrawing();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//      m_parent->m_viewer->makeCurrent();
Toshihiro Shimizu 890ddd
			tglColor(TPixel::Red);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_parent->getViewer()->startForegroundDrawing();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Toshihiro Shimizu 890ddd
// m_parent->m_viewer->enableRedraw(m_type == POLYLINE);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
			glPushMatrix();
Toshihiro Shimizu 890ddd
			tglMultMatrix(m_parent->getMatrix());
Toshihiro Shimizu 890ddd
			glScaled(dpiScale.x, dpiScale.y, 1);
Toshihiro Shimizu 890ddd
			if (m_type == POLYLINE) {
Toshihiro Shimizu 890ddd
				if (m_polyline.empty() || m_polyline.back() != pos)
Toshihiro Shimizu 890ddd
					m_polyline.push_back(pos);
Toshihiro Shimizu 890ddd
				//drawPolyline(m_polyline);
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				m_track.drawLastFragments();
Toshihiro Shimizu 890ddd
			glPopMatrix();
Toshihiro Shimizu 890ddd
			m_parent->getViewer()->endForegroundDrawing();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_isLeftButtonPressed = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- PolyLineFillを閉じる時に呼ばれる --*/
Toshihiro Shimizu 890ddd
	void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TStroke *stroke;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_polyline.size() <= 1) {
Toshihiro Shimizu 890ddd
			resetMulti();
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
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_type==POLYLINE)
Toshihiro Shimizu 890ddd
		//      m_polyline.push_back(pos);
Toshihiro Shimizu 890ddd
		// drawPolyline(m_polyline);
Toshihiro Shimizu 890ddd
		int styleIndex = app->getCurrentLevelStyleIndex();
Toshihiro Shimizu 890ddd
		if (m_frameRange) //stroke multi
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			if (m_firstFrameSelected) {
Toshihiro Shimizu 890ddd
				MultiAreaFiller filler(m_firstStroke, stroke, m_onlyUnfilled, m_colorType, styleIndex);
Toshihiro Shimizu 890ddd
				filler.processSequence(
Toshihiro Shimizu 890ddd
					m_level.getPointer(),
Toshihiro Shimizu 890ddd
					m_firstFrameId,
Toshihiro Shimizu 890ddd
					m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
				m_parent->invalidate(m_selectingRect.enlarge(2));
Toshihiro Shimizu 890ddd
				if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
					m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
					m_firstFrameId = m_parent->getCurrentFid();
Toshihiro Shimizu 890ddd
				} else {
Toshihiro Shimizu 890ddd
					if (app->getCurrentFrame()->isEditingScene()) {
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 //primo frame
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
				//if (app->getCurrentFrame()->isEditingScene())
Toshihiro Shimizu 890ddd
				m_currCell = std::pair<int, int="">(app->getCurrentColumn()->getColumnIndex(),</int,>
Toshihiro Shimizu 890ddd
												 app->getCurrentFrame()->getFrame());
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			if (m_onion) {
Toshihiro Shimizu 890ddd
				OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask();
Toshihiro Shimizu 890ddd
				doStrokeAutofill(m_parent->getImage(true), stroke, m_onlyUnfilled, osMask,
Toshihiro Shimizu 890ddd
								 m_level.getPointer(), m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				fillAreaWithUndo(m_parent->getImage(true), TRectD(), stroke, m_onlyUnfilled, m_colorType,
Toshihiro Shimizu 890ddd
								 m_level.getPointer(), m_parent->getCurrentFid(), styleIndex);
Toshihiro Shimizu 890ddd
			TTool *t = app->getCurrentTool()->getTool();
Toshihiro Shimizu 890ddd
			if (t)
Toshihiro Shimizu 890ddd
				t->notifyImageChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_type == RECT) {
Toshihiro Shimizu 890ddd
			m_selectingRect.x1 = pos.x;
Toshihiro Shimizu 890ddd
			m_selectingRect.y1 = pos.y;
Toshihiro Shimizu 890ddd
			m_parent->invalidate();
Toshihiro Shimizu 890ddd
		} else if (m_type == FREEHAND) {
Toshihiro Shimizu 890ddd
			if (!m_enabled || !m_active)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Toshihiro Shimizu 890ddd
//m_parent->m_viewer->enableRedraw(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_parent->getViewer()->startForegroundDrawing();
Toshihiro Shimizu 890ddd
			tglColor(TPixel::Red);
Toshihiro Shimizu 890ddd
			glPushMatrix();
Toshihiro Shimizu 890ddd
			tglMultMatrix(m_parent->getMatrix());
Toshihiro Shimizu 890ddd
			TPointD dpiScale = m_parent->getViewer()->getDpiScale();
Toshihiro Shimizu 890ddd
			glScaled(dpiScale.x, dpiScale.y, 1);
Toshihiro Shimizu 890ddd
			double pixelSize2 = m_parent->getPixelSize() * m_parent->getPixelSize();
Toshihiro Shimizu 890ddd
			m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
			m_track.drawLastFragments();
Toshihiro Shimizu 890ddd
			glPopMatrix();
Toshihiro Shimizu 890ddd
			m_parent->getViewer()->endForegroundDrawing();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void mouseMove(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_type != POLYLINE || m_polyline.empty())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		if (!m_enabled || !m_active)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		m_mousePosition = pos;
Toshihiro Shimizu 890ddd
		m_parent->invalidate();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_isLeftButtonPressed)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		m_isLeftButtonPressed = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TXshLevel *xl = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		m_level = xl ? xl->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int styleIndex = app->getCurrentLevelStyleIndex();
Toshihiro Shimizu 890ddd
		m_selecting = false;
Toshihiro Shimizu 890ddd
		if (m_type == RECT) {
Toshihiro Shimizu 890ddd
			if (m_selectingRect.x0 > m_selectingRect.x1)
Toshihiro Shimizu 890ddd
				tswap(m_selectingRect.x0, m_selectingRect.x1);
Toshihiro Shimizu 890ddd
			if (m_selectingRect.y0 > m_selectingRect.y1)
Toshihiro Shimizu 890ddd
				tswap(m_selectingRect.y0, m_selectingRect.y1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (m_frameRange) {
Toshihiro Shimizu 890ddd
				if (m_firstFrameSelected) {
Toshihiro Shimizu 890ddd
					MultiAreaFiller filler(m_firstRect, m_selectingRect, m_onlyUnfilled, m_colorType, styleIndex);
Toshihiro Shimizu 890ddd
					filler.processSequence(
Toshihiro Shimizu 890ddd
						m_level.getPointer(),
Toshihiro Shimizu 890ddd
						m_firstFrameId,
Toshihiro Shimizu 890ddd
						m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
					m_parent->invalidate(m_selectingRect.enlarge(2));
Toshihiro Shimizu 890ddd
					if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
						m_firstRect = m_selectingRect;
Toshihiro Shimizu 890ddd
						m_firstFrameId = m_parent->getCurrentFid();
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						if (app->getCurrentFrame()->isEditingScene()) {
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
					//if (app->getCurrentFrame()->isEditingScene())
Toshihiro Shimizu 890ddd
					m_currCell = std::pair<int, int="">(app->getCurrentColumn()->getColumnIndex(),</int,>
Toshihiro Shimizu 890ddd
													 app->getCurrentFrame()->getFrame());
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				if (m_onion) {
Toshihiro Shimizu 890ddd
					OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask();
Toshihiro Shimizu 890ddd
					doRectAutofill(m_parent->getImage(true), m_selectingRect, m_onlyUnfilled, osMask,
Toshihiro Shimizu 890ddd
								   m_level.getPointer(), m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
				} else
Toshihiro Shimizu 890ddd
					fillAreaWithUndo(m_parent->getImage(true), m_selectingRect, 0, m_onlyUnfilled, m_colorType, m_level.getPointer(), m_parent->getCurrentFid(), styleIndex);
Toshihiro Shimizu 890ddd
				m_parent->invalidate();
Toshihiro Shimizu 890ddd
				m_selectingRect.empty();
Toshihiro Shimizu 890ddd
				TTool *t = app->getCurrentTool()->getTool();
Toshihiro Shimizu 890ddd
				if (t)
Toshihiro Shimizu 890ddd
					t->notifyImageChanged();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else if (m_type == FREEHAND) {
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Toshihiro Shimizu 890ddd
//m_parent->m_viewer->enableRedraw(true);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			bool isValid = m_enabled && m_active;
Toshihiro Shimizu 890ddd
			m_enabled = m_active = false;
Toshihiro Shimizu 890ddd
			if (!isValid || m_track.isEmpty())
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			double pixelSize2 = m_parent->getPixelSize() * m_parent->getPixelSize();
Toshihiro Shimizu 890ddd
			m_track.add(TThickPoint(m_firstPos, m_thick), pixelSize2);
Toshihiro Shimizu 890ddd
			m_track.filterPoints();
Toshihiro Shimizu 890ddd
			double error = (m_isPath ? 20.0 : 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
			if (m_frameRange) //stroke multi
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				if (m_firstFrameSelected) {
Toshihiro Shimizu 890ddd
					MultiAreaFiller filler(m_firstStroke, stroke, m_onlyUnfilled, m_colorType, styleIndex);
Toshihiro Shimizu 890ddd
					filler.processSequence(
Toshihiro Shimizu 890ddd
						m_level.getPointer(),
Toshihiro Shimizu 890ddd
						m_firstFrameId,
Toshihiro Shimizu 890ddd
						m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
					m_parent->invalidate(m_selectingRect.enlarge(2));
Toshihiro Shimizu 890ddd
					if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
						m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
						m_firstFrameId = m_parent->getCurrentFid();
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						if (app->getCurrentFrame()->isEditingScene()) {
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 //primo frame
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					m_firstStroke = stroke;
Toshihiro Shimizu 890ddd
					//if (app->getCurrentFrame()->isEditingScene())
Toshihiro Shimizu 890ddd
					m_currCell = std::pair<int, int="">(app->getCurrentColumn()->getColumnIndex(),</int,>
Toshihiro Shimizu 890ddd
													 app->getCurrentFrame()->getFrame());
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			} else //stroke non multi
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				if (!m_parent->getImage(true))
Toshihiro Shimizu 890ddd
					return;
Toshihiro Shimizu 890ddd
				if (m_onion) {
Toshihiro Shimizu 890ddd
					OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask();
Toshihiro Shimizu 890ddd
					doStrokeAutofill(m_parent->getImage(true), stroke, m_onlyUnfilled, osMask,
Toshihiro Shimizu 890ddd
									 m_level.getPointer(), m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
				} else
Toshihiro Shimizu 890ddd
					fillAreaWithUndo(
Toshihiro Shimizu 890ddd
						m_parent->getImage(true),
Toshihiro Shimizu 890ddd
						TRectD(),
Toshihiro Shimizu 890ddd
						stroke /*, imageLocation*/,
Toshihiro Shimizu 890ddd
						m_onlyUnfilled,
Toshihiro Shimizu 890ddd
						m_colorType,
Toshihiro Shimizu 890ddd
						m_level.getPointer(),
Toshihiro Shimizu 890ddd
						m_parent->getCurrentFid(),
Toshihiro Shimizu 890ddd
						styleIndex);
Toshihiro Shimizu 890ddd
				delete stroke;
Toshihiro Shimizu 890ddd
				TTool *t = app->getCurrentTool()->getTool();
Toshihiro Shimizu 890ddd
				if (t)
Toshihiro Shimizu 890ddd
					t->notifyImageChanged();
Toshihiro Shimizu 890ddd
				m_parent->invalidate();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onImageChanged()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_frameRange)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TXshLevel *xshl = app->getCurrentLevel()->getLevel();
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 == m_parent->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_type != FREEHAND && m_type != POLYLINE) {
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
	/*--Normal以外のTypeが選択された場合に呼ばれる--*/
Shinya Kitaoka 3bfa54
	bool onPropertyChanged(bool multi, bool onlyUnfilled, bool onion, Type type, std::wstring colorType)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_frameRange = multi;
Toshihiro Shimizu 890ddd
		m_onlyUnfilled = onlyUnfilled;
Toshihiro Shimizu 890ddd
		m_colorType = colorType;
Toshihiro Shimizu 890ddd
		m_type = type;
Toshihiro Shimizu 890ddd
		m_onion = onion;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_frameRange)
Toshihiro Shimizu 890ddd
			resetMulti();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/*--動作中にプロパティが変わったら、現在の動作を無効にする--*/
Toshihiro Shimizu 890ddd
		if (m_isLeftButtonPressed)
Toshihiro Shimizu 890ddd
			m_isLeftButtonPressed = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_type == POLYLINE && !m_polyline.empty())
Toshihiro Shimizu 890ddd
			m_polyline.clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onActivate()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		//getApplication()->editImage();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_frameRange)
Toshihiro Shimizu 890ddd
			resetMulti();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (TVectorImageP vi = TImageP(m_parent->getImage(false)))
Toshihiro Shimizu 890ddd
			vi->findRegions();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onEnter()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		//getApplication()->editImage();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! NormalLineFillTool 
Toshihiro Shimizu 890ddd
	マウスドラッグで直線を延ばし、その直線がまたいだ点をFillLineするツール。
Toshihiro Shimizu 890ddd
	Raster - Normal - Line Fillツール(FrameRangeなし)のとき使用可能にする
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class NormalLineFillTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool *m_parent;
Toshihiro Shimizu 890ddd
	TPointD m_startPosition, m_mousePosition;
Toshihiro Shimizu 890ddd
	bool m_isEditing;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	NormalLineFillTool(TTool *parent)
Toshihiro Shimizu 890ddd
		: m_parent(parent), m_isEditing(false), m_mousePosition()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- FillLineツールに戻ってきたときに前の位置情報をリセットする --*/
Toshihiro Shimizu 890ddd
	void init()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_startPosition = TPointD();
Toshihiro Shimizu 890ddd
		m_mousePosition = TPointD();
Toshihiro Shimizu 890ddd
		m_isEditing = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_startPosition = pos; /*-始点-*/
Toshihiro Shimizu 890ddd
		m_mousePosition = pos; /*-終点-*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_isEditing = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_isEditing)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_mousePosition = pos;
Toshihiro Shimizu 890ddd
		m_parent->invalidate();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &pos, const TMouseEvent &e, TImage *img, FillParameters ¶ms)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_isEditing)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_mousePosition = pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (!app)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TXshLevel *xl = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TToonzImageP ti = TImageP(m_parent->getImage(true));
Toshihiro Shimizu 890ddd
		if (!ti)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TRasterCM32P ras = ti->getRaster();
Toshihiro Shimizu 890ddd
		if (!ras)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		int styleId = params.m_styleId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/*--- 線分上にある全ての点でdoFillを行う ---*/
Toshihiro Shimizu 890ddd
		double dx = m_mousePosition.x - m_startPosition.x;
Toshihiro Shimizu 890ddd
		double dy = m_mousePosition.y - m_startPosition.y;
Shinya Kitaoka 8016de
		if (std::abs(dx) > std::abs(dy)) /*-- 横長の線分の場合 --*/
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			double k = dy / dx; /*-- 直線の傾き --*/
Toshihiro Shimizu 890ddd
			/*--- roundでは負値のときにうまく繋がらない ---*/
Toshihiro Shimizu 890ddd
			int start = tmin((int)floor(m_startPosition.x + 0.5), (int)floor(m_mousePosition.x + 0.5));
Toshihiro Shimizu 890ddd
			int end = tmax((int)floor(m_startPosition.x + 0.5), (int)floor(m_mousePosition.x + 0.5));
Toshihiro Shimizu 890ddd
			double start_x = (m_startPosition.x < m_mousePosition.x) ? m_startPosition.x : m_mousePosition.x;
Toshihiro Shimizu 890ddd
			double start_y = (m_startPosition.x < m_mousePosition.x) ? m_startPosition.y : m_mousePosition.y;
Toshihiro Shimizu 890ddd
			for (int x = start; x <= end; x++) {
Toshihiro Shimizu 890ddd
				double ddx = (double)(x - start);
Toshihiro Shimizu 890ddd
				TPointD tmpPos(start_x + ddx, ddx * k + start_y);
Toshihiro Shimizu 890ddd
				TPoint ipos((int)(tmpPos.x + ras->getLx() / 2), (int)(tmpPos.y + ras->getLy() / 2));
Toshihiro Shimizu 890ddd
				if (!ras->getBounds().contains(ipos))
Toshihiro Shimizu 890ddd
					continue;
Toshihiro Shimizu 890ddd
				TPixelCM32 pix = ras->pixels(ipos.y)[ipos.x];
Toshihiro Shimizu 890ddd
				if (pix.getInk() == styleId || pix.isPurePaint())
Toshihiro Shimizu 890ddd
					continue;
Toshihiro Shimizu 890ddd
				doFill(img, tmpPos, params, e.isShiftPressed(), sl, m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else /*-- 縦長の線分の場合 --*/
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			double k = dx / dy; /*-- 直線の傾き --*/
Toshihiro Shimizu 890ddd
			/*--- roundでは負値のときにうまく繋がらない ---*/
Toshihiro Shimizu 890ddd
			int start = tmin((int)floor(m_startPosition.y + 0.5), (int)floor(m_mousePosition.y + 0.5));
Toshihiro Shimizu 890ddd
			int end = tmax((int)floor(m_startPosition.y + 0.5), (int)floor(m_mousePosition.y + 0.5));
Toshihiro Shimizu 890ddd
			double start_x = (m_startPosition.y < m_mousePosition.y) ? m_startPosition.x : m_mousePosition.x;
Toshihiro Shimizu 890ddd
			double start_y = (m_startPosition.y < m_mousePosition.y) ? m_startPosition.y : m_mousePosition.y;
Toshihiro Shimizu 890ddd
			for (int y = start; y <= end; y++) {
Toshihiro Shimizu 890ddd
				double ddy = (double)(y - start);
Toshihiro Shimizu 890ddd
				TPointD tmpPos(ddy * k + start_x, ddy + start_y);
Toshihiro Shimizu 890ddd
				TPoint ipos((int)(tmpPos.x + ras->getLx() / 2), (int)(tmpPos.y + ras->getLy() / 2));
Toshihiro Shimizu 890ddd
				if (!ras->getBounds().contains(ipos))
Toshihiro Shimizu 890ddd
					continue;
Toshihiro Shimizu 890ddd
				TPixelCM32 pix = ras->pixels(ipos.y)[ipos.x];
Toshihiro Shimizu 890ddd
				if (pix.getInk() == styleId || pix.isPurePaint())
Toshihiro Shimizu 890ddd
					continue;
Toshihiro Shimizu 890ddd
				doFill(img, tmpPos, params, e.isShiftPressed(), sl, m_parent->getCurrentFid());
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_isEditing = false;
Toshihiro Shimizu 890ddd
		m_parent->invalidate();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_isEditing) {
Toshihiro Shimizu 890ddd
			tglColor(TPixel32::Red);
Toshihiro Shimizu 890ddd
			glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
			tglVertex(m_startPosition);
Toshihiro Shimizu 890ddd
			tglVertex(m_mousePosition);
Toshihiro Shimizu 890ddd
			glEnd();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Fill Tool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FillTool : public TTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Q_DECLARE_TR_FUNCTIONS(FillTool)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_firstTime;
Toshihiro Shimizu 890ddd
	TPointD m_firstPoint, m_clickPoint;
Toshihiro Shimizu 890ddd
	bool m_firstClick;
Toshihiro Shimizu 890ddd
	TXshSimpleLevelP m_level;
Toshihiro Shimizu 890ddd
	TFrameId m_firstFrameId, m_veryFirstFrameId;
Toshihiro Shimizu 890ddd
	int m_onionStyleId;
Toshihiro Shimizu 890ddd
	TEnumProperty m_colorType; //Line, Area
Toshihiro Shimizu 890ddd
	TEnumProperty m_fillType;  //Rect, Polyline etc.
Toshihiro Shimizu 890ddd
	TBoolProperty m_onion;
Toshihiro Shimizu 890ddd
	TBoolProperty m_frameRange;
Toshihiro Shimizu 890ddd
	TBoolProperty m_selective;
Toshihiro Shimizu 890ddd
	TDoublePairProperty m_fillDepth;
Toshihiro Shimizu 890ddd
	TBoolProperty m_segment;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	AreaFillTool *m_rectFill;
Toshihiro Shimizu 890ddd
	NormalLineFillTool *m_normalLineFillTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPropertyGroup m_prop;
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> m_currCell;</int,>
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Shinya Kitaoka 3bfa54
	std::vector<trect> m_rects;</trect>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FillTool(int targetType);
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
	TPropertyGroup *getProperties(int targetType) { return &m_prop; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FillParameters getFillParameters() const;
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 mouseMove(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void resetMulti();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	bool onPropertyChanged(std::string propertyName);
Toshihiro Shimizu 890ddd
	void onImageChanged();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int pick(const TImageP &image, const TPointD &pos);
Toshihiro Shimizu 890ddd
	int pickOnionColor(const TPointD &pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onEnter();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onActivate();
Toshihiro Shimizu 890ddd
	void onDeactivate();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getCursorId() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getColorClass() const { return 2; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FillTool::FillTool(int targetType)
Toshihiro Shimizu 890ddd
	: TTool("T_Fill"), m_frameRange("Frame Range", false) //W_ToolOptions_FrameRange
Toshihiro Shimizu 890ddd
	  ,
Toshihiro Shimizu 890ddd
	  m_fillType("Type:"), m_selective("Selective", false), m_colorType("Mode:"), m_onion("Onion Skin", false), m_fillDepth("Fill Depth", 0, 15, 0, 15), m_segment("Segment", false), m_onionStyleId(0), m_currCell(-1, -1), m_firstTime(true)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_rectFill = new AreaFillTool(this);
Toshihiro Shimizu 890ddd
	m_normalLineFillTool = new NormalLineFillTool(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bind(targetType);
Toshihiro Shimizu 890ddd
#ifndef STUDENT
Toshihiro Shimizu 890ddd
	m_prop.bind(m_fillType);
Toshihiro Shimizu 890ddd
	m_fillType.addValue(NORMALFILL);
Toshihiro Shimizu 890ddd
	m_fillType.addValue(RECTFILL);
Toshihiro Shimizu 890ddd
	m_fillType.addValue(FREEHANDFILL);
Toshihiro Shimizu 890ddd
	m_fillType.addValue(POLYLINEFILL);
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
	m_fillType.addValue(NORMALFILL);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_prop.bind(m_colorType);
Toshihiro Shimizu 890ddd
	m_colorType.addValue(LINES);
Toshihiro Shimizu 890ddd
	m_colorType.addValue(AREAS);
Toshihiro Shimizu 890ddd
	m_colorType.addValue(ALL);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_prop.bind(m_selective);
Toshihiro Shimizu 890ddd
	if (targetType == TTool::ToonzImage) {
Toshihiro Shimizu 890ddd
		m_prop.bind(m_fillDepth);
Toshihiro Shimizu 890ddd
		m_prop.bind(m_segment);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_prop.bind(m_onion);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_frameRange);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_selective.setId("Selective");
Toshihiro Shimizu 890ddd
	m_onion.setId("OnionSkin");
Toshihiro Shimizu 890ddd
	m_frameRange.setId("FrameRange");
Toshihiro Shimizu 890ddd
	m_segment.setId("SegmentInk");
Toshihiro Shimizu 890ddd
	m_fillType.setId("Type");
Toshihiro Shimizu 890ddd
	m_colorType.setId("Mode");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FillTool::getCursorId() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool isBlackBG = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_colorType.getValue() == LINES) {
Toshihiro Shimizu 890ddd
		if (m_fillType.getValue() == NORMALFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorLWhite : ToolCursor::FillCursorL;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == FREEHANDFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorLFWhite : ToolCursor::FillCursorLF;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == POLYLINEFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorLPWhite : ToolCursor::FillCursorLP;
Toshihiro Shimizu 890ddd
		else //Rect
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorLRWhite : ToolCursor::FillCursorLR;
Toshihiro Shimizu 890ddd
	} else if (m_colorType.getValue() == AREAS) {
Toshihiro Shimizu 890ddd
		if (m_fillType.getValue() == NORMALFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorAWhite : ToolCursor::FillCursorA;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == FREEHANDFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorAFWhite : ToolCursor::FillCursorAF;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == POLYLINEFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorAPWhite : ToolCursor::FillCursorAP;
Toshihiro Shimizu 890ddd
		else //Rect
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorARWhite : ToolCursor::FillCursorAR;
Toshihiro Shimizu 890ddd
	} else //line&areas
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_fillType.getValue() == NORMALFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorWhite : ToolCursor::FillCursor;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == FREEHANDFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorFWhite : ToolCursor::FillCursorF;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == POLYLINEFILL)
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorPWhite : ToolCursor::FillCursorP;
Toshihiro Shimizu 890ddd
		else //Rect
Toshihiro Shimizu 890ddd
			return (isBlackBG) ? ToolCursor::FillCursorRWhite : ToolCursor::FillCursorR;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::updateTranslation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_frameRange.setQStringName(tr("Frame Range"));
Toshihiro Shimizu 890ddd
	m_fillType.setQStringName(tr("Type:"));
Toshihiro Shimizu 890ddd
	m_selective.setQStringName(tr("Selective"));
Toshihiro Shimizu 890ddd
	m_colorType.setQStringName(tr("Mode:"));
Toshihiro Shimizu 890ddd
	m_onion.setQStringName(tr("Onion Skin"));
Toshihiro Shimizu 890ddd
	m_fillDepth.setQStringName(tr("Fill Depth"));
Toshihiro Shimizu 890ddd
	m_segment.setQStringName(tr("Segment"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FillParameters FillTool::getFillParameters() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FillParameters params;
Toshihiro Shimizu 890ddd
	int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
Toshihiro Shimizu 890ddd
	params.m_styleId = styleId;
Toshihiro Shimizu 890ddd
	/*---紛らわしいことに、colorTypeをfillTypeに名前を変えて保存している。間違いではない。---*/
Toshihiro Shimizu 890ddd
	params.m_fillType = m_colorType.getValue();
Toshihiro Shimizu 890ddd
	params.m_emptyOnly = m_selective.getValue();
Toshihiro Shimizu 890ddd
	params.m_segment = m_segment.getValue();
Toshihiro Shimizu 890ddd
	params.m_minFillDepth = (int)m_fillDepth.getValue().first;
Toshihiro Shimizu 890ddd
	params.m_maxFillDepth = (int)m_fillDepth.getValue().second;
Toshihiro Shimizu 890ddd
	return params;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	if (!app)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_clickPoint = pos;
Toshihiro Shimizu 890ddd
	if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
		m_rectFill->leftButtonDown(pos, e, getImage(true));
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--以下、NormalFillの場合--*/
Toshihiro Shimizu 890ddd
	FillParameters params = getFillParameters();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_onion.getValue()) {
Toshihiro Shimizu 890ddd
		m_onionStyleId = pickOnionColor(pos);
Toshihiro Shimizu 890ddd
		if (m_onionStyleId > 0)
Toshihiro Shimizu 890ddd
			app->setCurrentLevelStyleIndex(m_onionStyleId);
Toshihiro Shimizu 890ddd
	} else if (m_frameRange.getValue()) {
Toshihiro Shimizu 890ddd
		if (!m_firstClick) {
Toshihiro Shimizu 890ddd
			// PRIMO CLICK
Toshihiro Shimizu 890ddd
			//if (app->getCurrentFrame()->isEditingScene())
Toshihiro Shimizu 890ddd
			m_currCell = std::pair<int, int="">(getColumnIndex(),</int,>
Toshihiro Shimizu 890ddd
											 getFrame());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_firstClick = true;
Toshihiro Shimizu 890ddd
			m_firstPoint = pos;
Toshihiro Shimizu 890ddd
			m_firstFrameId = m_veryFirstFrameId = getCurrentFid();
Toshihiro Shimizu 890ddd
			// gmt. NON BISOGNA DISEGNARE DENTRO LE CALLBACKS!!!!
Toshihiro Shimizu 890ddd
			// drawCross(m_firstPoint, 6);
Toshihiro Shimizu 890ddd
			invalidate();
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			// SECONDO CLICK
Toshihiro Shimizu 890ddd
			TFrameId fid = getCurrentFid();
Toshihiro Shimizu 890ddd
			MultiFiller filler(m_firstPoint, pos, params);
Toshihiro Shimizu 890ddd
			filler.processSequence(m_level.getPointer(), m_firstFrameId, fid);
Toshihiro Shimizu 890ddd
			if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
				m_firstPoint = pos;
Toshihiro Shimizu 890ddd
				m_firstFrameId = getCurrentFid();
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				m_firstClick = false;
Toshihiro Shimizu 890ddd
				if (app->getCurrentFrame()->isEditingScene()) {
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
			}
Toshihiro Shimizu 890ddd
			TTool *t = app->getCurrentTool()->getTool();
Toshihiro Shimizu 890ddd
			if (t)
Toshihiro Shimizu 890ddd
				t->notifyImageChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (params.m_fillType == LINES && m_targetType == TTool::ToonzImage)
Toshihiro Shimizu 890ddd
			m_normalLineFillTool->leftButtonDown(pos, e);
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			TXshLevel *xl = app->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
			m_level = xl ? xl->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
			doFill(getImage(true), pos, params, e.isShiftPressed(), m_level.getPointer(), getCurrentFid());
Toshihiro Shimizu 890ddd
			invalidate();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
		m_rectFill->leftButtonDoubleClick(pos, e);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fillType.getValue() != NORMALFILL && !m_onion.getValue() ||
Toshihiro Shimizu 890ddd
		(m_colorType.getValue() == AREAS && m_onion.getValue()))
Toshihiro Shimizu 890ddd
		m_rectFill->leftButtonDrag(pos, e);
Toshihiro Shimizu 890ddd
	else if (!m_onion.getValue() && !m_frameRange.getValue()) {
Toshihiro Shimizu 890ddd
		FillParameters params = getFillParameters();
Toshihiro Shimizu 890ddd
		if (params.m_fillType == LINES && m_targetType == TTool::ToonzImage) {
Toshihiro Shimizu 890ddd
			m_normalLineFillTool->leftButtonDrag(pos, e);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (m_clickPoint == pos)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TImageP img = getImage(true);
Toshihiro Shimizu 890ddd
		int styleId = params.m_styleId;
Toshihiro Shimizu 890ddd
		if (TVectorImageP vi = img) {
Toshihiro Shimizu 890ddd
			TRegion *r = vi->getRegion(pos);
Toshihiro Shimizu 890ddd
			if (r && r->getStyle() == styleId)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
		} else if (TToonzImageP ti = img) {
Toshihiro Shimizu 890ddd
			TRasterCM32P ras = ti->getRaster();
Toshihiro Shimizu 890ddd
			if (!ras)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			TPointD center = ras->getCenterD();
Toshihiro Shimizu 890ddd
			TPoint ipos = convert(pos + center);
Toshihiro Shimizu 890ddd
			if (!ras->getBounds().contains(ipos))
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			TPixelCM32 pix = ras->pixels(ipos.y)[ipos.x];
Toshihiro Shimizu 890ddd
			if (pix.getPaint() == styleId) {
Toshihiro Shimizu 890ddd
				invalidate();
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			TSystem::outputDebug("ok. pix=" + toString(pix.getTone()) + "," + toString(pix.getPaint()) + "\n");
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		doFill(img, pos, params, e.isShiftPressed(), m_level.getPointer(), getCurrentFid());
Toshihiro Shimizu 890ddd
		invalidate();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_onion.getValue()) {
Toshihiro Shimizu 890ddd
		if (m_fillType.getValue() != NORMALFILL && m_colorType.getValue() == AREAS)
Toshihiro Shimizu 890ddd
			m_rectFill->leftButtonUp(pos, e);
Toshihiro Shimizu 890ddd
		else if (m_onionStyleId > 0) {
Toshihiro Shimizu 890ddd
			FillParameters tmp = getFillParameters();
Toshihiro Shimizu 890ddd
			doFill(getImage(true), pos, tmp, e.isShiftPressed(), m_level.getPointer(), getCurrentFid());
Toshihiro Shimizu 890ddd
			invalidate();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
		m_rectFill->leftButtonUp(pos, e);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_frameRange.getValue()) {
Toshihiro Shimizu 890ddd
		TFrameId fid = getCurrentFid();
Toshihiro Shimizu 890ddd
		//notifyImageChanged();
Toshihiro Shimizu 890ddd
		if (getFillParameters().m_fillType == LINES && m_targetType == TTool::ToonzImage) {
Toshihiro Shimizu 890ddd
			FillParameters params = getFillParameters();
Toshihiro Shimizu 890ddd
			m_normalLineFillTool->leftButtonUp(pos, e, getImage(true), params);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::resetMulti()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_firstClick = false;
Toshihiro Shimizu 890ddd
	m_firstFrameId = -1;
Toshihiro Shimizu 890ddd
	m_firstPoint = TPointD();
Toshihiro Shimizu 890ddd
	TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
	m_level = xl ? xl->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
bool FillTool::onPropertyChanged(std::string propertyName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*--- m_rectFill->onPropertyChangedを呼ぶかどうかのフラグ
Toshihiro Shimizu 890ddd
			fillType, frameRange, selective, colorTypeが変わったときに呼ぶ---*/
Toshihiro Shimizu 890ddd
	bool rectPropChangedflag = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Areas, Lines etc.
Toshihiro Shimizu 890ddd
	if (propertyName == m_colorType.getName()) {
Toshihiro Shimizu 890ddd
		FillColorType = toString(m_colorType.getValue());
Toshihiro Shimizu 890ddd
		rectPropChangedflag = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/*--- ColorModelのCursor更新のためにSIGNALを出す ---*/
Toshihiro Shimizu 890ddd
		TTool::getApplication()->getCurrentTool()->notifyToolChanged();
Toshihiro Shimizu 890ddd
		/*--- FillLineツールに戻ってきたときに前回の位置情報をリセットする ---*/
Toshihiro Shimizu 890ddd
		if (FillColorType.getValue() == "Lines")
Toshihiro Shimizu 890ddd
			m_normalLineFillTool->init();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// Rect, Polyline etc.
Toshihiro Shimizu 890ddd
	else if (propertyName == m_fillType.getName()) {
Toshihiro Shimizu 890ddd
		if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
			FillOnion = (int)(m_onion.getValue());
Toshihiro Shimizu 890ddd
			FillSegment = (int)(m_segment.getValue());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		FillType = toString(m_fillType.getValue());
Toshihiro Shimizu 890ddd
		rectPropChangedflag = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// Onion Skin
Toshihiro Shimizu 890ddd
	else if (propertyName == m_onion.getName()) {
Toshihiro Shimizu 890ddd
		if (m_onion.getValue())
Toshihiro Shimizu 890ddd
			FillType = toString(m_fillType.getValue());
Toshihiro Shimizu 890ddd
		FillOnion = (int)(m_onion.getValue());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// Frame Range
Toshihiro Shimizu 890ddd
	else if (propertyName == m_frameRange.getName()) {
Toshihiro Shimizu 890ddd
		FillRange = (int)(m_frameRange.getValue());
Toshihiro Shimizu 890ddd
		resetMulti();
Toshihiro Shimizu 890ddd
		rectPropChangedflag = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// Selective
Toshihiro Shimizu 890ddd
	else if (propertyName == m_selective.getName()) {
Toshihiro Shimizu 890ddd
		rectPropChangedflag = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// Fill Depth
Toshihiro Shimizu 890ddd
	else if (propertyName == m_fillDepth.getName()) {
Toshihiro Shimizu 890ddd
		MinFillDepth = (int)m_fillDepth.getValue().first;
Toshihiro Shimizu 890ddd
		MaxFillDepth = (int)m_fillDepth.getValue().second;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	// Segment
Toshihiro Shimizu 890ddd
	else if (propertyName == m_segment.getName()) {
Toshihiro Shimizu 890ddd
		if (m_segment.getValue())
Toshihiro Shimizu 890ddd
			FillType = toString(m_fillType.getValue());
Toshihiro Shimizu 890ddd
		FillSegment = (int)(m_segment.getValue());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*--- fillType, frameRange, selective, colorTypeが変わったとき ---*/
Toshihiro Shimizu 890ddd
	if (rectPropChangedflag && m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
		AreaFillTool::Type type;
Toshihiro Shimizu 890ddd
		if (m_fillType.getValue() == RECTFILL)
Toshihiro Shimizu 890ddd
			type = AreaFillTool::RECT;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == FREEHANDFILL)
Toshihiro Shimizu 890ddd
			type = AreaFillTool::FREEHAND;
Toshihiro Shimizu 890ddd
		else if (m_fillType.getValue() == POLYLINEFILL)
Toshihiro Shimizu 890ddd
			type = AreaFillTool::POLYLINE;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			assert(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_rectFill->onPropertyChanged(m_frameRange.getValue(), m_selective.getValue(),
Toshihiro Shimizu 890ddd
									  m_onion.getValue(), type, m_colorType.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 FillTool::mouseMove(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fillType.getValue() != NORMALFILL)
Toshihiro Shimizu 890ddd
		m_rectFill->mouseMove(pos, e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::onImageChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
		m_rectFill->onImageChanged();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!m_level)
Toshihiro Shimizu 890ddd
		resetMulti();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::draw()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (Preferences::instance()->getFillOnlySavebox()) {
Toshihiro Shimizu 890ddd
		TToonzImageP ti = (TToonzImageP)getImage(false);
Toshihiro Shimizu 890ddd
		if (ti) {
Toshihiro Shimizu 890ddd
			TRectD bbox = ToonzImageUtils::convertRasterToWorld(convert(ti->getBBox()), ti);
Toshihiro Shimizu 890ddd
			drawRect(bbox.enlarge(0.5) * ti->getSubsampling(), TPixel32::Black, 0x5555, true);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
		m_rectFill->draw();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_frameRange.getValue() && m_firstClick) {
Toshihiro Shimizu 890ddd
		tglColor(TPixel::Red);
Toshihiro Shimizu 890ddd
		drawCross(m_firstPoint, 6);
Toshihiro Shimizu 890ddd
	} else if (!m_frameRange.getValue() && getFillParameters().m_fillType == LINES && m_targetType == TTool::ToonzImage)
Toshihiro Shimizu 890ddd
		m_normalLineFillTool->draw();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FillTool::pick(const TImageP &image, const TPointD &pos)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TToonzImageP ti = image;
Toshihiro Shimizu 890ddd
	TVectorImageP vi = image;
Toshihiro Shimizu 890ddd
	if (!ti && !vi)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	StylePicker picker(image);
Toshihiro Shimizu 890ddd
	double pixelSize2 = getPixelSize() * getPixelSize();
Toshihiro Shimizu 890ddd
	return picker.pickStyleId(pos, pixelSize2);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FillTool::pickOnionColor(const TPointD &pos)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	if (!app)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	bool filmStripEditing = !app->getCurrentObject()->isSpline();
Toshihiro Shimizu 890ddd
	OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameId fid = getCurrentFid();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl = m_level.getPointer();
Toshihiro Shimizu 890ddd
	if (!sl)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<int> rows;</int>
Toshihiro Shimizu 890ddd
	osMask.getAll(sl->guessIndex(fid), rows);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int i, j;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < (int)rows.size(); i++)
Toshihiro Shimizu 890ddd
		if (sl->index2fid(rows[i]) > fid)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int onionStyleId = 0;
Toshihiro Shimizu 890ddd
	for (j = i - 1; j >= 0; j--) {
Toshihiro Shimizu 890ddd
		TFrameId onionFid = sl->index2fid(rows[j]);
Toshihiro Shimizu 890ddd
		if (onionFid != fid && ((onionStyleId = pick(m_level->getFrame(onionFid, ImageManager::none, 1), pos)) > 0)) //subsabling must be 1, otherwise onionfill does  not work
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (onionStyleId == 0)
Toshihiro Shimizu 890ddd
		for (j = i; j < (int)rows.size(); j++) {
Toshihiro Shimizu 890ddd
			TFrameId onionFid = sl->index2fid(rows[j]);
Toshihiro Shimizu 890ddd
			if (onionFid != fid && ((onionStyleId = pick(m_level->getFrame(onionFid, ImageManager::none, 1), pos)) > 0)) //subsabling must be 1, otherwise onionfill does  not work
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	return onionStyleId;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::onEnter()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//resetMulti();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// getApplication()->editImage();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::onActivate()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//OnionSkinMask osMask = getApplication()->getOnionSkinMask(false);
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
	for (int i=0; i
Toshihiro Shimizu 890ddd
	boh = osMask.getMos(i);
Toshihiro Shimizu 890ddd
	for (i=0; i
Toshihiro Shimizu 890ddd
	boh = osMask.getFos(i);
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	if (m_firstTime) {
Toshihiro Shimizu 890ddd
		m_fillDepth.setValue(TDoublePairProperty::Value(MinFillDepth, MaxFillDepth));
Toshihiro Shimizu 890ddd
		m_fillType.setValue(toWideString((FillType.getValue())));
Toshihiro Shimizu 890ddd
		m_colorType.setValue(toWideString((FillColorType.getValue())));
Toshihiro Shimizu 890ddd
		//		m_onlyEmpty.setValue(FillSelective ? 1 :0);
Toshihiro Shimizu 890ddd
		m_onion.setValue(FillOnion ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_segment.setValue(FillSegment ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_frameRange.setValue(FillRange ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_firstTime = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
			AreaFillTool::Type type;
Toshihiro Shimizu 890ddd
			if (m_fillType.getValue() == RECTFILL)
Toshihiro Shimizu 890ddd
				type = AreaFillTool::RECT;
Toshihiro Shimizu 890ddd
			else if (m_fillType.getValue() == FREEHANDFILL)
Toshihiro Shimizu 890ddd
				type = AreaFillTool::FREEHAND;
Toshihiro Shimizu 890ddd
			else if (m_fillType.getValue() == POLYLINEFILL)
Toshihiro Shimizu 890ddd
				type = AreaFillTool::POLYLINE;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				assert(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_rectFill->onPropertyChanged(m_frameRange.getValue(), m_selective.getValue(), m_onion.getValue(),
Toshihiro Shimizu 890ddd
										  type, m_colorType.getValue());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_fillType.getValue() != NORMALFILL) {
Toshihiro Shimizu 890ddd
		m_rectFill->onActivate();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (FillColorType.getValue() == "Lines")
Toshihiro Shimizu 890ddd
		m_normalLineFillTool->init();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	resetMulti();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//  getApplication()->editImage();
Toshihiro Shimizu 890ddd
	TVectorImageP vi = TImageP(getImage(false));
Toshihiro Shimizu 890ddd
	if (!vi)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	vi->findRegions();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FillTool::onDeactivate()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FillTool FillVectorTool(TTool::VectorImage);
Toshihiro Shimizu 890ddd
FillTool FiilRasterTool(TTool::ToonzImage);