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