2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
// TnzTools includes
|
|
|
|
#include "tools/tool.h"
|
|
|
|
#include "tools/cursors.h"
|
|
|
|
#include "tools/toolcommandids.h"
|
|
|
|
#include "tools/toolutils.h"
|
|
|
|
#include "tools/toolhandle.h"
|
|
|
|
|
|
|
|
#include "historytypes.h"
|
|
|
|
|
|
|
|
// TnzLib includes
|
|
|
|
#include "toonz/txsheethandle.h"
|
|
|
|
#include "toonz/txshlevelhandle.h"
|
|
|
|
#include "toonz/tcolumnhandle.h"
|
|
|
|
#include "toonz/tframehandle.h"
|
|
|
|
#include "toonz/ttileset.h"
|
|
|
|
#include "toonz/ttilesaver.h"
|
|
|
|
#include "toonz/trasterimageutils.h"
|
|
|
|
#include "toonz/stage2.h"
|
|
|
|
#include "toonz/levelproperties.h"
|
2018-05-17 18:03:05 +12:00
|
|
|
#include "toonz/preferences.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// TnzBase includes
|
|
|
|
#include "tenv.h"
|
|
|
|
|
|
|
|
// TnzCore includes
|
|
|
|
#include "tproperty.h"
|
|
|
|
#include "trasterimage.h"
|
|
|
|
#include "bluredbrush.h"
|
|
|
|
#include "trop.h"
|
|
|
|
#include "tgl.h"
|
|
|
|
#include "tstroke.h"
|
|
|
|
#include "drawutil.h"
|
|
|
|
#include "tinbetween.h"
|
|
|
|
#include "tpixelutils.h"
|
2023-02-04 15:05:42 +13:00
|
|
|
#include "cmrasterbrush.h"
|
|
|
|
#include "symmetrytool.h"
|
|
|
|
#include "vectorbrush.h"
|
|
|
|
#include "symmetrystroke.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
using namespace ToolUtils;
|
|
|
|
|
|
|
|
#define NORMALERASE L"Normal"
|
|
|
|
#define RECTERASE L"Rectangular"
|
|
|
|
#define FREEHANDERASE L"Freehand"
|
|
|
|
#define POLYLINEERASE L"Polyline"
|
|
|
|
|
|
|
|
TEnv::DoubleVar FullcolorEraseSize("FullcolorEraseSize", 5);
|
|
|
|
TEnv::DoubleVar FullcolorEraseHardness("FullcolorEraseHardness", 100);
|
|
|
|
TEnv::DoubleVar FullcolorEraserOpacity("FullcolorEraserOpacity", 100);
|
|
|
|
TEnv::StringVar FullcolorEraserType("FullcolorEraseType", "Normal");
|
|
|
|
TEnv::IntVar FullcolorEraserInvert("FullcolorEraseInvert", 0);
|
|
|
|
TEnv::IntVar FullcolorEraserRange("FullcolorEraseRange", 0);
|
|
|
|
|
|
|
|
//**********************************************************************************
|
|
|
|
// Local namespace stuff
|
|
|
|
//**********************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int computeThickness(int pressure, const TIntPairProperty &property) {
|
|
|
|
double p = pressure / 255.0;
|
|
|
|
double t = p * p * p;
|
|
|
|
int thick0 = property.getValue().first;
|
|
|
|
int thick1 = property.getValue().second;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return tround(thick0 + (thick1 - thick0) * t);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void eraseImage(const TRasterImageP &ri, const TRaster32P &image,
|
|
|
|
const TPoint &pos, bool invert) {
|
|
|
|
TRect rasBounds = ri->getRaster()->getBounds();
|
|
|
|
TRect imageBounds = image->getBounds() + pos;
|
|
|
|
|
|
|
|
if (invert) {
|
|
|
|
TRect rect(imageBounds.x0, rasBounds.y0, rasBounds.x1, imageBounds.y0 - 1);
|
|
|
|
TRasterImageUtils::eraseRect(
|
|
|
|
ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
|
|
|
|
|
|
|
|
rect =
|
|
|
|
TRect(imageBounds.x1 + 1, imageBounds.y0, rasBounds.x1, rasBounds.y1);
|
|
|
|
TRasterImageUtils::eraseRect(
|
|
|
|
ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
|
|
|
|
|
|
|
|
rect =
|
|
|
|
TRect(rasBounds.x0, imageBounds.y1 + 1, imageBounds.x1, rasBounds.y1);
|
|
|
|
TRasterImageUtils::eraseRect(
|
|
|
|
ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
|
|
|
|
|
|
|
|
rect =
|
|
|
|
TRect(rasBounds.x0, rasBounds.y0, imageBounds.x0 - 1, imageBounds.y1);
|
|
|
|
TRasterImageUtils::eraseRect(
|
|
|
|
ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
|
|
|
|
}
|
|
|
|
|
|
|
|
TRaster32P workRas;
|
|
|
|
if (TRasterGR8P ras = ri->getRaster()) {
|
|
|
|
workRas = TRaster32P(imageBounds.getSize());
|
|
|
|
TRop::convert(workRas, ras->extract(imageBounds));
|
|
|
|
} else
|
|
|
|
workRas = ri->getRaster()->extract(imageBounds);
|
|
|
|
|
|
|
|
int y;
|
|
|
|
for (y = 0; y < workRas->getLy(); y++) {
|
|
|
|
TPixel32 *outPix = workRas->pixels(y);
|
|
|
|
TPixel32 *outEndPix = outPix + workRas->getLx();
|
|
|
|
TPixel32 *inPix = image->pixels(y);
|
2020-04-12 17:19:20 +12:00
|
|
|
for (; outPix != outEndPix; outPix++, inPix++) {
|
2016-06-15 18:43:10 +12:00
|
|
|
if (outPix->m == 0) continue;
|
|
|
|
TPixel32 pix = depremultiply(*outPix);
|
|
|
|
pix.m =
|
|
|
|
invert ? pix.m * (inPix->m) / 255 : pix.m * (255 - inPix->m) / 255;
|
|
|
|
*outPix = premultiply(pix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TRasterGR8P ras = ri->getRaster()) {
|
|
|
|
TRop::addBackground(workRas, TPixel32::White);
|
|
|
|
TRop::over(ras, workRas, pos);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class RectFullColorUndo final : public TFullColorRasterUndo {
|
2016-06-15 18:43:10 +12:00
|
|
|
TRectD m_modifyArea;
|
|
|
|
TStroke *m_stroke;
|
|
|
|
std::wstring m_eraseType;
|
|
|
|
bool m_invert;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
RectFullColorUndo(TTileSetFullColor *tileSet, const TRectD &modifyArea,
|
|
|
|
TStroke stroke, std::wstring eraseType,
|
|
|
|
TXshSimpleLevel *level, bool invert,
|
|
|
|
const TFrameId &frameId)
|
|
|
|
: TFullColorRasterUndo(tileSet, level, frameId, false, false, 0)
|
|
|
|
, m_modifyArea(modifyArea)
|
|
|
|
, m_eraseType(eraseType)
|
|
|
|
, m_invert(invert) {
|
|
|
|
m_stroke = new TStroke(stroke);
|
|
|
|
}
|
|
|
|
|
|
|
|
~RectFullColorUndo() { delete m_stroke; }
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void redo() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
TRasterImageP ri = getImage();
|
|
|
|
if (!ri) return;
|
|
|
|
|
|
|
|
if (m_eraseType == RECTERASE)
|
|
|
|
TRect rect = TRasterImageUtils::eraseRect(ri, m_modifyArea);
|
|
|
|
else if (m_eraseType == FREEHANDERASE || m_eraseType == POLYLINEERASE) {
|
|
|
|
TPoint pos;
|
|
|
|
|
|
|
|
TRaster32P image =
|
|
|
|
convertStrokeToImage(m_stroke, ri->getRaster()->getBounds(), pos);
|
|
|
|
if (!image) return;
|
|
|
|
|
|
|
|
eraseImage(ri, image, pos, m_invert);
|
|
|
|
}
|
|
|
|
|
|
|
|
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
|
|
notifyImageChanged();
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
int getSize() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
return TFullColorRasterUndo::getSize() +
|
|
|
|
m_stroke->getControlPointCount() * sizeof(TThickPoint) + 100 +
|
|
|
|
sizeof(this);
|
|
|
|
}
|
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
QString getToolName() override {
|
|
|
|
return QString("Raster Eraser Tool (Rect)");
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
int getHistoryType() override { return HistoryType::EraserTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class FullColorEraserUndo final : public TFullColorRasterUndo {
|
2016-06-15 18:43:10 +12:00
|
|
|
std::vector<TThickPoint> m_points;
|
|
|
|
int m_size;
|
|
|
|
double m_hardness;
|
|
|
|
double m_opacity;
|
2023-02-04 15:05:42 +13:00
|
|
|
TPointD m_dpiScale;
|
|
|
|
int m_brushCount;
|
|
|
|
double m_rotation;
|
|
|
|
TPointD m_centerPoint;
|
|
|
|
bool m_useLineSymmetry;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
FullColorEraserUndo(TTileSetFullColor *tileSet,
|
|
|
|
const std::vector<TThickPoint> &points,
|
|
|
|
TXshSimpleLevel *level, const TFrameId &frameId, int size,
|
2023-02-04 15:05:42 +13:00
|
|
|
double hardness, double opacity, TPointD dpiScale,
|
|
|
|
double symmetryLines, double rotation,
|
|
|
|
TPointD centerPoint, bool useLineSymmetry)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TFullColorRasterUndo(tileSet, level, frameId, false, false, 0)
|
|
|
|
, m_points(points)
|
|
|
|
, m_size(size)
|
|
|
|
, m_hardness(hardness)
|
2023-02-04 15:05:42 +13:00
|
|
|
, m_opacity(opacity)
|
|
|
|
, m_dpiScale(dpiScale)
|
|
|
|
, m_brushCount(symmetryLines)
|
|
|
|
, m_rotation(rotation)
|
|
|
|
, m_centerPoint(centerPoint)
|
|
|
|
, m_useLineSymmetry(useLineSymmetry) {}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void redo() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_points.size() == 0) return;
|
|
|
|
TRasterImageP image = getImage();
|
|
|
|
TRasterP ras = image->getRaster();
|
|
|
|
QRadialGradient brushPad = getBrushPad(m_size, m_hardness);
|
|
|
|
TRaster32P workRaster = TRaster32P(ras->getSize());
|
|
|
|
TRasterP backUpRas = ras->clone();
|
|
|
|
workRaster->clear();
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
RasterBlurredBrush brush(workRaster, m_size, brushPad, false);
|
|
|
|
|
|
|
|
if (m_brushCount > 1)
|
|
|
|
brush.addSymmetryBrushes(m_brushCount, m_rotation, m_centerPoint,
|
|
|
|
m_useLineSymmetry, m_dpiScale);
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
points.push_back(m_points[0]);
|
|
|
|
TRect bbox = brush.getBoundFromPoints(points);
|
|
|
|
brush.addPoint(m_points[0], 1);
|
|
|
|
brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
|
|
|
|
if (m_points.size() > 1) {
|
|
|
|
points.clear();
|
|
|
|
points.push_back(m_points[0]);
|
|
|
|
points.push_back(m_points[1]);
|
|
|
|
bbox = brush.getBoundFromPoints(points);
|
|
|
|
brush.addArc(m_points[0], (m_points[1] + m_points[0]) * 0.5, m_points[1],
|
|
|
|
1, 1);
|
|
|
|
brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
|
|
|
|
int i;
|
|
|
|
for (i = 1; i + 2 < (int)m_points.size(); i = i + 2) {
|
|
|
|
points.clear();
|
|
|
|
points.push_back(m_points[i]);
|
|
|
|
points.push_back(m_points[i + 1]);
|
|
|
|
points.push_back(m_points[i + 2]);
|
|
|
|
bbox = brush.getBoundFromPoints(points);
|
|
|
|
brush.addArc(m_points[i], m_points[i + 1], m_points[i + 2], 1, 1);
|
|
|
|
brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
|
|
notifyImageChanged();
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
int getSize() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
return sizeof(*this) + TFullColorRasterUndo::getSize();
|
|
|
|
}
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
QString getToolName() override { return QString("Raster Eraser Tool"); }
|
|
|
|
int getHistoryType() override { return HistoryType::EraserTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void eraseStroke(const TRasterImageP &ri, TStroke *stroke,
|
|
|
|
std::wstring eraseType, bool invert,
|
|
|
|
const TXshSimpleLevelP &level, const TFrameId &frameId) {
|
|
|
|
assert(stroke);
|
|
|
|
TPoint pos;
|
|
|
|
TRasterP ras = ri->getRaster();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRaster32P image = convertStrokeToImage(stroke, ras->getBounds(), pos);
|
|
|
|
if (!image) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRect rasterErasedArea = image->getBounds() + pos;
|
|
|
|
TRect area;
|
|
|
|
if (!invert)
|
|
|
|
area = rasterErasedArea.enlarge(2);
|
|
|
|
else
|
|
|
|
area = ras->getBounds();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TTileSetFullColor *tileSet = new TTileSetFullColor(ras->getSize());
|
|
|
|
tileSet->add(ras, area);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TUndoManager::manager()->add(
|
|
|
|
new RectFullColorUndo(tileSet, convert(area), *stroke, eraseType,
|
|
|
|
level.getPointer(), invert, frameId));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
eraseImage(ri, image, pos, invert);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//**********************************************************************************
|
|
|
|
// FullColorEraserTool definition
|
|
|
|
//**********************************************************************************
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class FullColorEraserTool final : public TTool {
|
2016-06-15 18:43:10 +12:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(FullColorEraserTool)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
FullColorEraserTool(std::string name);
|
|
|
|
~FullColorEraserTool();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
ToolType getToolType() const override { return TTool::LevelWriteTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void updateTranslation() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void onActivate() override;
|
|
|
|
void onDeactivate() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void draw() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
int getCursorId() const override { return ToolCursor::PenCursor; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
bool onPropertyChanged(std::string propertyName) override;
|
|
|
|
void onImageChanged() override;
|
|
|
|
void onEnter() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void update(const TRasterImageP &ri, TRectD selArea,
|
|
|
|
const TXshSimpleLevelP &level, bool multi = false,
|
|
|
|
const TFrameId &frameId = -1);
|
|
|
|
void multiUpdate(const TRectD firstRect, const TRectD lastRect);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void multiAreaEraser(TFrameId &firstFid, TFrameId &lastFid,
|
2023-02-04 15:05:42 +13:00
|
|
|
std::vector<TStroke *> firstStrokes,
|
|
|
|
std::vector<TStroke *> lastStrokes);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void doMultiEraser(const TImageP &img, double t, const TFrameId &fid,
|
|
|
|
const TVectorImageP &firstImage,
|
|
|
|
const TVectorImageP &lastImage);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void resetMulti();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
TPropertyGroup m_prop;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TIntProperty m_size;
|
|
|
|
TDoubleProperty m_opacity;
|
|
|
|
TDoubleProperty m_hardness;
|
|
|
|
TEnumProperty m_eraseType;
|
|
|
|
TBoolProperty m_invertOption;
|
|
|
|
TBoolProperty m_multi;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TXshSimpleLevelP m_level;
|
|
|
|
std::pair<int, int> m_currCell;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFrameId m_firstFrameId, m_veryFirstFrameId;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRaster32P m_workRaster;
|
|
|
|
TRasterP m_backUpRas;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QRadialGradient m_brushPad;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::vector<TThickPoint> m_points;
|
2023-02-04 15:05:42 +13:00
|
|
|
RasterBlurredBrush *m_brush;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TTileSetFullColor *m_tileSet;
|
|
|
|
TTileSaverFullColor *m_tileSaver;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
VectorBrush m_track;
|
|
|
|
SymmetryStroke m_polyline;
|
|
|
|
std::vector<TStroke *> m_firstStrokes;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRectD m_selectingRect, m_firstRect;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPointD m_mousePos, m_brushPos, m_firstPos;
|
2017-05-31 22:53:58 +12:00
|
|
|
TMouseEvent m_mouseEvent;
|
2016-06-15 18:43:10 +12:00
|
|
|
double m_thick;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool m_firstTime, m_selecting, m_firstFrameSelected, m_isXsheetCell;
|
2017-05-31 22:53:58 +12:00
|
|
|
bool m_mousePressed = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} fullColorEraser(T_Eraser); // Tools are statically instantiated
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//===================================================================================================
|
|
|
|
|
2016-04-19 19:32:17 +12:00
|
|
|
FullColorEraserTool::FullColorEraserTool(std::string name)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TTool(name)
|
2019-10-11 16:13:41 +13:00
|
|
|
, m_size("Size:", 1, 1000, 5, false)
|
2016-06-15 18:43:10 +12:00
|
|
|
, m_opacity("Opacity:", 0, 100, 100)
|
|
|
|
, m_hardness("Hardness:", 0, 100, 100)
|
|
|
|
, m_eraseType("Type:")
|
|
|
|
, m_invertOption("Invert", false)
|
|
|
|
, m_multi("Frame Range", false)
|
|
|
|
, m_currCell(-1, -1)
|
|
|
|
, m_brush(0)
|
|
|
|
, m_tileSet(0)
|
|
|
|
, m_tileSaver(0)
|
|
|
|
, m_thick(0.5)
|
|
|
|
, m_firstTime(true)
|
|
|
|
, m_selecting(false)
|
|
|
|
, m_firstFrameSelected(false)
|
|
|
|
, m_isXsheetCell(false) {
|
|
|
|
bind(TTool::RasterImage);
|
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
m_size.setNonLinearSlider();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_prop.bind(m_size);
|
|
|
|
m_prop.bind(m_hardness);
|
|
|
|
m_prop.bind(m_opacity);
|
|
|
|
m_prop.bind(m_eraseType);
|
|
|
|
m_prop.bind(m_invertOption);
|
|
|
|
m_prop.bind(m_multi);
|
|
|
|
|
|
|
|
m_eraseType.addValue(NORMALERASE);
|
|
|
|
m_eraseType.addValue(RECTERASE);
|
|
|
|
m_eraseType.addValue(FREEHANDERASE);
|
|
|
|
m_eraseType.addValue(POLYLINEERASE);
|
2019-08-26 08:45:30 +12:00
|
|
|
|
|
|
|
m_eraseType.setId("Type");
|
|
|
|
m_invertOption.setId("Invert");
|
|
|
|
m_multi.setId("FrameRange");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
FullColorEraserTool::~FullColorEraserTool() { m_firstStrokes.clear(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::updateTranslation() {
|
|
|
|
m_size.setQStringName(tr("Size:"));
|
|
|
|
m_opacity.setQStringName(tr("Opacity:"));
|
|
|
|
m_hardness.setQStringName(tr("Hardness:"));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_eraseType.setQStringName(tr("Type:"));
|
2018-04-26 21:24:25 +12:00
|
|
|
m_eraseType.setItemUIName(NORMALERASE, tr("Normal"));
|
|
|
|
m_eraseType.setItemUIName(RECTERASE, tr("Rectangular"));
|
|
|
|
m_eraseType.setItemUIName(FREEHANDERASE, tr("Freehand"));
|
|
|
|
m_eraseType.setItemUIName(POLYLINEERASE, tr("Polyline"));
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_invertOption.setQStringName(tr("Invert"));
|
|
|
|
m_multi.setQStringName(tr("Frame Range"));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::onActivate() {
|
|
|
|
if (m_firstTime) {
|
|
|
|
m_firstTime = false;
|
|
|
|
m_size.setValue(FullcolorEraseSize);
|
|
|
|
m_opacity.setValue(FullcolorEraserOpacity);
|
|
|
|
m_hardness.setValue(FullcolorEraseHardness);
|
|
|
|
m_eraseType.setValue(::to_wstring(FullcolorEraserType.getValue()));
|
|
|
|
m_invertOption.setValue((bool)FullcolorEraserInvert);
|
|
|
|
m_multi.setValue((bool)FullcolorEraserRange);
|
|
|
|
m_firstTime = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_brushPad = getBrushPad(m_size.getValue(), m_hardness.getValue() * 0.01);
|
2018-03-14 15:42:03 +13:00
|
|
|
|
|
|
|
// setting m_level in resetMulti() will take care when the tool is switched
|
|
|
|
// via shortcut ( i.e. the case skipping onEnter() )
|
|
|
|
resetMulti();
|
|
|
|
// clear previous polyline when the tool is activated
|
2023-02-04 15:05:42 +13:00
|
|
|
m_polyline.reset();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2017-05-31 22:53:58 +12:00
|
|
|
void FullColorEraserTool::onDeactivate() {
|
|
|
|
if (m_mousePressed) leftButtonUp(m_mousePos, m_mouseEvent);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::leftButtonDown(const TPointD &pos,
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
m_brushPos = m_mousePos = pos;
|
2017-05-31 22:53:58 +12:00
|
|
|
m_mouseEvent = e;
|
|
|
|
m_mousePressed = true;
|
|
|
|
TRasterImageP ri = (TRasterImageP)getImage(true);
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!ri) return;
|
|
|
|
TRectD invalidateRect;
|
|
|
|
TRasterP ras = ri->getRaster();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
SymmetryTool *symmetryTool = dynamic_cast<SymmetryTool *>(
|
|
|
|
TTool::getTool("T_Symmetry", TTool::RasterImage));
|
|
|
|
TPointD dpiScale = getViewer()->getDpiScale();
|
|
|
|
SymmetryObject symmObj = symmetryTool->getSymmetryObject();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_eraseType.getValue() == NORMALERASE) {
|
|
|
|
TDimension dim = ras->getSize();
|
|
|
|
double opacity = m_opacity.getValue() * 0.01;
|
|
|
|
double hardness = m_hardness.getValue() * 0.01;
|
|
|
|
m_workRaster = TRaster32P(dim);
|
|
|
|
m_workRaster->clear();
|
|
|
|
m_backUpRas = ras->clone();
|
|
|
|
|
|
|
|
int maxThick = m_size.getValue();
|
|
|
|
TPointD rasCenter = ras->getCenterD();
|
|
|
|
TThickPoint point(pos + rasCenter, maxThick);
|
|
|
|
TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
|
|
|
|
invalidateRect = TRectD(pos - halfThick, pos + halfThick);
|
|
|
|
|
|
|
|
m_points.clear();
|
|
|
|
m_points.push_back(point);
|
|
|
|
|
|
|
|
m_tileSet = new TTileSetFullColor(ras->getSize());
|
|
|
|
m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
|
2023-02-04 15:05:42 +13:00
|
|
|
m_brush = new RasterBlurredBrush(m_workRaster, m_size.getValue(),
|
|
|
|
m_brushPad, false);
|
|
|
|
if (symmetryTool && symmetryTool->isGuideEnabled()) {
|
|
|
|
m_brush->addSymmetryBrushes(symmObj.getLines(), symmObj.getRotation(),
|
|
|
|
symmObj.getCenterPoint(),
|
|
|
|
symmObj.isUsingLineSymmetry(), dpiScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<TThickPoint> points = m_points;
|
|
|
|
std::vector<TThickPoint> symmPts;
|
|
|
|
symmPts = m_brush->getSymmetryPoints(m_points);
|
|
|
|
points.insert(points.end(), symmPts.begin(), symmPts.end());
|
|
|
|
|
|
|
|
invalidateRect += ToolUtils::getBounds(points, maxThick) - rasCenter;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRect bbox = m_brush->getBoundFromPoints(m_points);
|
|
|
|
m_tileSaver->save(bbox);
|
|
|
|
m_brush->addPoint(point, 1);
|
|
|
|
m_brush->eraseDrawing(ras, m_backUpRas, bbox, opacity);
|
|
|
|
} else if (m_eraseType.getValue() == RECTERASE) {
|
|
|
|
if (m_multi.getValue() && m_firstRect.isEmpty()) {
|
|
|
|
invalidateRect = m_selectingRect;
|
|
|
|
m_selectingRect.empty();
|
|
|
|
invalidate(invalidateRect.enlarge(2));
|
|
|
|
}
|
|
|
|
m_selecting = true;
|
|
|
|
m_selectingRect.x0 = pos.x;
|
|
|
|
m_selectingRect.y0 = pos.y;
|
|
|
|
m_selectingRect.x1 = pos.x + 1;
|
|
|
|
m_selectingRect.y1 = pos.y + 1;
|
|
|
|
invalidateRect = m_selectingRect;
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
if (!m_invertOption.getValue() && symmetryTool &&
|
|
|
|
symmetryTool->isGuideEnabled()) {
|
|
|
|
// We'll use polyline
|
|
|
|
m_polyline.reset();
|
|
|
|
m_polyline.addSymmetryBrushes(symmObj.getLines(), symmObj.getRotation(),
|
|
|
|
symmObj.getCenterPoint(),
|
|
|
|
symmObj.isUsingLineSymmetry(), dpiScale);
|
|
|
|
m_polyline.setRectangle(TPointD(m_selectingRect.x0, m_selectingRect.y0),
|
|
|
|
TPointD(m_selectingRect.x1, m_selectingRect.y1));
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
} else if (m_eraseType.getValue() == FREEHANDERASE ||
|
|
|
|
m_eraseType.getValue() == POLYLINEERASE) {
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_multi.getValue() && m_firstStrokes.size() && !m_firstFrameSelected) {
|
|
|
|
m_firstStrokes.clear();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_track.reset();
|
|
|
|
if (!m_invertOption.getValue() && symmetryTool &&
|
|
|
|
symmetryTool->isGuideEnabled()) {
|
|
|
|
m_track.addSymmetryBrushes(symmObj.getLines(), symmObj.getRotation(),
|
|
|
|
symmObj.getCenterPoint(),
|
|
|
|
symmObj.isUsingLineSymmetry(), dpiScale);
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
m_firstPos = pos;
|
|
|
|
double pixelSize2 = getPixelSize() * getPixelSize();
|
|
|
|
m_track.add(TThickPoint(pos, m_thick), pixelSize2);
|
|
|
|
|
|
|
|
if (m_eraseType.getValue() == POLYLINEERASE) {
|
2023-02-04 15:05:42 +13:00
|
|
|
if (!m_invertOption.getValue() && symmetryTool &&
|
|
|
|
symmetryTool->isGuideEnabled() && !m_polyline.hasSymmetryBrushes()) {
|
|
|
|
m_polyline.addSymmetryBrushes(symmObj.getLines(), symmObj.getRotation(),
|
|
|
|
symmObj.getCenterPoint(),
|
|
|
|
symmObj.isUsingLineSymmetry(), dpiScale);
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_polyline.empty() || m_polyline.back() != pos)
|
|
|
|
m_polyline.push_back(pos);
|
2017-11-14 16:38:01 +13:00
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
int maxThick = 2 * m_thick;
|
|
|
|
TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
|
|
|
|
invalidateRect = TRectD(pos - halfThick, pos + halfThick);
|
|
|
|
}
|
|
|
|
invalidate(invalidateRect.enlarge(2));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::leftButtonDrag(const TPointD &pos,
|
|
|
|
const TMouseEvent &e) {
|
2018-12-25 16:13:47 +13:00
|
|
|
if (!m_mousePressed) return;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_brushPos = m_mousePos = pos;
|
2017-05-31 22:53:58 +12:00
|
|
|
m_mouseEvent = e;
|
|
|
|
double pixelSize2 = getPixelSize() * getPixelSize();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
|
|
if (!ri) return;
|
|
|
|
if (m_eraseType.getValue() == NORMALERASE) {
|
|
|
|
double thickness = m_size.getValue();
|
|
|
|
TDimension size = m_workRaster->getSize();
|
|
|
|
TPointD rasCenter = ri->getRaster()->getCenterD();
|
|
|
|
TThickPoint point(pos + rasCenter, thickness);
|
|
|
|
|
|
|
|
TThickPoint old = m_points.back();
|
|
|
|
if (norm2(point - old) < 4) return;
|
|
|
|
|
|
|
|
TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
|
|
|
|
m_points.push_back(mid);
|
|
|
|
m_points.push_back(point);
|
|
|
|
|
|
|
|
int m = m_points.size();
|
|
|
|
double opacity = m_opacity.getValue() * 0.01;
|
|
|
|
|
|
|
|
TThickPoint pa = m_points.front();
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
points.push_back(pa);
|
|
|
|
points.push_back(mid);
|
|
|
|
TRect bbox;
|
|
|
|
TRectD invalidateRect;
|
|
|
|
if (m == 3) {
|
|
|
|
TThickPoint pa = m_points.front();
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
points.push_back(pa);
|
|
|
|
points.push_back(mid);
|
|
|
|
invalidateRect = ToolUtils::getBounds(points, thickness);
|
|
|
|
bbox = m_brush->getBoundFromPoints(points);
|
|
|
|
m_tileSaver->save(bbox);
|
|
|
|
m_brush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);
|
|
|
|
} else {
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
points.push_back(m_points[m - 4]);
|
|
|
|
points.push_back(old);
|
|
|
|
points.push_back(mid);
|
|
|
|
invalidateRect = ToolUtils::getBounds(points, thickness);
|
|
|
|
bbox = m_brush->getBoundFromPoints(points);
|
|
|
|
m_tileSaver->save(bbox);
|
|
|
|
m_brush->addArc(m_points[m - 4], old, mid, 1, 1);
|
|
|
|
}
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
std::vector<TThickPoint> allPts = points;
|
|
|
|
std::vector<TThickPoint> symmPts;
|
|
|
|
symmPts = m_brush->getSymmetryPoints(allPts);
|
|
|
|
allPts.insert(allPts.end(), symmPts.begin(), symmPts.end());
|
|
|
|
|
|
|
|
invalidateRect += ToolUtils::getBounds(allPts, thickness);
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_brush->eraseDrawing(ri->getRaster(), m_backUpRas, bbox, opacity);
|
|
|
|
invalidate(invalidateRect.enlarge(2) - rasCenter);
|
|
|
|
}
|
|
|
|
if (m_eraseType.getValue() == RECTERASE) {
|
|
|
|
assert(m_selecting);
|
|
|
|
TRectD oldRect = m_selectingRect;
|
2018-08-30 20:18:43 +12:00
|
|
|
if (oldRect.x0 > oldRect.x1) std::swap(oldRect.x1, oldRect.x0);
|
|
|
|
if (oldRect.y0 > oldRect.y1) std::swap(oldRect.y1, oldRect.y0);
|
2016-06-15 18:43:10 +12:00
|
|
|
m_selectingRect.x1 = pos.x;
|
|
|
|
m_selectingRect.y1 = pos.y;
|
|
|
|
TRectD invalidateRect(m_selectingRect);
|
|
|
|
if (invalidateRect.x0 > invalidateRect.x1)
|
2018-08-30 20:18:43 +12:00
|
|
|
std::swap(invalidateRect.x1, invalidateRect.x0);
|
2016-06-15 18:43:10 +12:00
|
|
|
if (invalidateRect.y0 > invalidateRect.y1)
|
2018-08-30 20:18:43 +12:00
|
|
|
std::swap(invalidateRect.y1, invalidateRect.y0);
|
2016-06-15 18:43:10 +12:00
|
|
|
invalidateRect += oldRect;
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
if (m_polyline.size() > 1 && m_polyline.hasSymmetryBrushes()) {
|
|
|
|
m_polyline.clear();
|
|
|
|
m_polyline.setRectangle(TPointD(m_selectingRect.x0, m_selectingRect.y0),
|
|
|
|
TPointD(m_selectingRect.x1, m_selectingRect.y1));
|
|
|
|
invalidate();
|
|
|
|
} else
|
|
|
|
invalidate(invalidateRect.enlarge(2));
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
if (m_eraseType.getValue() == FREEHANDERASE) {
|
|
|
|
m_track.add(TThickPoint(pos, m_thick), pixelSize2);
|
2017-11-14 16:38:01 +13:00
|
|
|
invalidate(m_track.getModifiedRegion());
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::leftButtonUp(const TPointD &pos,
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
m_brushPos = m_mousePos = pos;
|
|
|
|
TRasterImageP ri = (TRasterImageP)getImage(true);
|
|
|
|
if (!ri) return;
|
|
|
|
if (m_eraseType.getValue() == NORMALERASE) {
|
|
|
|
if (m_points.size() != 1) {
|
|
|
|
TPointD rasCenter = ri->getRaster()->getCenterD();
|
|
|
|
TThickPoint point(pos + rasCenter, m_size.getValue());
|
|
|
|
m_points.push_back(point);
|
|
|
|
int m = m_points.size();
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
points.push_back(m_points[m - 3]);
|
|
|
|
points.push_back(m_points[m - 2]);
|
|
|
|
points.push_back(m_points[m - 1]);
|
|
|
|
TRect bbox = m_brush->getBoundFromPoints(points);
|
|
|
|
m_tileSaver->save(bbox);
|
|
|
|
m_brush->addArc(points[0], points[1], points[2], 1, 1);
|
|
|
|
double opacity = m_opacity.getValue() * 0.01;
|
|
|
|
m_brush->eraseDrawing(ri->getRaster(), m_backUpRas, bbox, opacity);
|
|
|
|
TRectD invalidateRect = ToolUtils::getBounds(points, m_size.getValue());
|
2023-02-04 15:05:42 +13:00
|
|
|
std::vector<TThickPoint> symmPts = m_brush->getSymmetryPoints(points);
|
|
|
|
points.insert(points.end(), symmPts.begin(), symmPts.end());
|
|
|
|
invalidateRect += ToolUtils::getBounds(points, m_thick);
|
2016-06-15 18:43:10 +12:00
|
|
|
invalidate(invalidateRect.enlarge(2) - rasCenter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_brush) {
|
|
|
|
delete m_brush;
|
|
|
|
m_brush = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_workRaster->unlock();
|
|
|
|
double opacity = m_opacity.getValue() * 0.01;
|
|
|
|
double hardness = m_hardness.getValue() * 0.01;
|
|
|
|
|
|
|
|
m_workRaster = TRaster32P();
|
|
|
|
m_backUpRas = TRaster32P();
|
|
|
|
|
|
|
|
delete m_tileSaver;
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
|
|
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
|
|
TFrameId frameId = getCurrentFid();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
double symmetryLines = 0;
|
|
|
|
double rotation = 0;
|
|
|
|
bool useLineSymmetry = false;
|
|
|
|
TPointD centerPoint(0, 0);
|
|
|
|
SymmetryTool *symmetryTool = dynamic_cast<SymmetryTool *>(
|
|
|
|
TTool::getTool("T_Symmetry", TTool::RasterImage));
|
|
|
|
if (symmetryTool && symmetryTool->isGuideEnabled()) {
|
|
|
|
SymmetryObject symmObj = symmetryTool->getSymmetryObject();
|
|
|
|
symmetryLines = symmObj.getLines();
|
|
|
|
rotation = symmObj.getRotation();
|
|
|
|
centerPoint = symmObj.getCenterPoint();
|
|
|
|
useLineSymmetry = symmObj.isUsingLineSymmetry();
|
|
|
|
}
|
|
|
|
|
|
|
|
TPointD dpiScale = getViewer()->getDpiScale();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TUndoManager::manager()->add(new FullColorEraserUndo(
|
|
|
|
m_tileSet, m_points, simLevel.getPointer(), frameId, m_size.getValue(),
|
2023-02-04 15:05:42 +13:00
|
|
|
m_hardness.getValue() * 0.01, opacity, dpiScale, symmetryLines,
|
|
|
|
rotation, centerPoint, useLineSymmetry));
|
2016-06-15 18:43:10 +12:00
|
|
|
notifyImageChanged();
|
|
|
|
} else if (m_eraseType.getValue() == RECTERASE) {
|
2023-02-04 15:05:42 +13:00
|
|
|
m_selecting = false;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_selectingRect.x0 > m_selectingRect.x1)
|
2018-08-30 20:18:43 +12:00
|
|
|
std::swap(m_selectingRect.x1, m_selectingRect.x0);
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_selectingRect.y0 > m_selectingRect.y1)
|
2018-08-30 20:18:43 +12:00
|
|
|
std::swap(m_selectingRect.y1, m_selectingRect.y0);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_polyline.size() > 1 && m_polyline.hasSymmetryBrushes()) {
|
|
|
|
// We'll use polyline
|
|
|
|
m_polyline.clear();
|
|
|
|
m_polyline.setRectangle(TPointD(m_selectingRect.x0, m_selectingRect.y0),
|
|
|
|
TPointD(m_selectingRect.x1, m_selectingRect.y1));
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_multi.getValue()) {
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
if (m_firstFrameSelected) {
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_polyline.size() > 1 && m_polyline.hasSymmetryBrushes()) {
|
|
|
|
// We'll use polyline
|
|
|
|
TFrameId tmp = getCurrentFid();
|
|
|
|
std::vector<TStroke *> lastStrokes;
|
|
|
|
for (int i = 0; i < m_polyline.getBrushCount(); i++)
|
|
|
|
lastStrokes.push_back(m_polyline.makeRectangleStroke(i));
|
|
|
|
multiAreaEraser(m_firstFrameId, tmp, m_firstStrokes, lastStrokes);
|
|
|
|
} else {
|
|
|
|
multiUpdate(m_firstRect, m_selectingRect);
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
notifyImageChanged();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (e.isShiftPressed()) {
|
|
|
|
m_firstRect = m_selectingRect;
|
|
|
|
m_firstFrameId = getFrameId();
|
2023-02-04 15:05:42 +13:00
|
|
|
m_firstStrokes.clear();
|
|
|
|
if (m_polyline.size() > 1) {
|
|
|
|
for (int i = 0; i < m_polyline.getBrushCount(); i++)
|
|
|
|
m_firstStrokes.push_back(m_polyline.makeRectangleStroke(i));
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
invalidate();
|
|
|
|
} else {
|
|
|
|
if (m_isXsheetCell) {
|
|
|
|
app->getCurrentColumn()->setColumnIndex(m_currCell.first);
|
|
|
|
app->getCurrentFrame()->setFrame(m_currCell.second);
|
|
|
|
} else
|
|
|
|
app->getCurrentFrame()->setFid(m_veryFirstFrameId);
|
|
|
|
resetMulti();
|
2023-02-04 15:05:42 +13:00
|
|
|
m_polyline.reset();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
} else {
|
2023-02-04 15:05:42 +13:00
|
|
|
m_firstStrokes.clear();
|
|
|
|
if (m_polyline.size() > 1) {
|
|
|
|
for (int i = 0; i < m_polyline.getBrushCount(); i++)
|
|
|
|
m_firstStrokes.push_back(m_polyline.makeRectangleStroke(i));
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
|
|
|
|
m_currCell = std::pair<int, int>(getColumnIndex(), getFrame());
|
2023-02-04 15:05:42 +13:00
|
|
|
invalidate();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
|
|
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
|
|
TFrameId frameId = getCurrentFid();
|
|
|
|
if (m_invertOption.getValue()) {
|
|
|
|
TUndoManager::manager()->beginBlock();
|
|
|
|
TRect rect =
|
|
|
|
TRasterImageUtils::convertWorldToRaster(m_selectingRect, ri);
|
|
|
|
rect *= ri->getSavebox();
|
|
|
|
TDimension dim = ri->getRaster()->getSize();
|
|
|
|
TRectD rect01 =
|
|
|
|
TRectD(TPointD(0., 0.), TPointD((double)rect.x0, (double)dim.ly));
|
|
|
|
if (rect01.getLx() > 0 && rect01.getLy() > 0) {
|
|
|
|
rect01 = TRasterImageUtils::convertRasterToWorld(convert(rect01), ri);
|
|
|
|
update(ri, rect01, simLevel, false, frameId);
|
|
|
|
}
|
|
|
|
TRectD rect02 = TRectD(convert(rect.getP01()),
|
|
|
|
TPointD((double)rect.x1, (double)dim.ly));
|
|
|
|
if (rect02.getLx() > 0 && rect02.getLy() > 0) {
|
|
|
|
rect02 = TRasterImageUtils::convertRasterToWorld(convert(rect02), ri);
|
|
|
|
update(ri, rect02, simLevel, false, frameId);
|
|
|
|
}
|
|
|
|
TRectD rect03 =
|
|
|
|
TRectD(TPointD((double)rect.x0, 0.), convert(rect.getP10()));
|
|
|
|
if (rect03.getLx() > 0 && rect03.getLy() > 0) {
|
|
|
|
rect03 = TRasterImageUtils::convertRasterToWorld(convert(rect03), ri);
|
|
|
|
update(ri, rect03, simLevel, false, frameId);
|
|
|
|
}
|
|
|
|
TRectD rect04 = TRectD(TPointD((double)rect.x1, 0.),
|
|
|
|
TPointD((double)dim.lx, (double)dim.ly));
|
|
|
|
if (rect04.getLx() > 0 && rect04.getLy() > 0) {
|
|
|
|
rect04 = TRasterImageUtils::convertRasterToWorld(convert(rect04), ri);
|
|
|
|
update(ri, rect04, simLevel, false, frameId);
|
|
|
|
}
|
2023-02-04 15:05:42 +13:00
|
|
|
TUndoManager::manager()->endBlock();
|
|
|
|
invalidate();
|
|
|
|
} else if (m_polyline.size() > 1 && m_polyline.hasSymmetryBrushes()) {
|
|
|
|
TUndoManager::manager()->beginBlock();
|
|
|
|
|
|
|
|
TStroke *stroke = m_polyline.makeRectangleStroke();
|
|
|
|
eraseStroke(ri, stroke, POLYLINEERASE, m_invertOption.getValue(),
|
|
|
|
/*m_multi.getValue(),*/ m_level, frameId);
|
|
|
|
|
|
|
|
for (int i = 1; i < m_polyline.getBrushCount(); i++) {
|
|
|
|
TStroke *symmStroke = m_polyline.makeRectangleStroke(i);
|
|
|
|
symmStroke->setStyle(stroke->getStyle());
|
|
|
|
eraseStroke(ri, symmStroke, POLYLINEERASE, m_invertOption.getValue(),
|
|
|
|
/*m_multi.getValue(),*/ m_level, frameId);
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TUndoManager::manager()->endBlock();
|
|
|
|
invalidate();
|
|
|
|
} else {
|
|
|
|
update(ri, m_selectingRect, simLevel, false, frameId);
|
|
|
|
invalidate(m_selectingRect.enlarge(2));
|
|
|
|
}
|
|
|
|
m_selectingRect.empty();
|
2023-02-04 15:05:42 +13:00
|
|
|
m_polyline.reset();
|
2016-06-15 18:43:10 +12:00
|
|
|
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
|
|
m_selecting = false;
|
|
|
|
notifyImageChanged();
|
|
|
|
}
|
|
|
|
} else if (m_eraseType.getValue() == FREEHANDERASE) {
|
|
|
|
if (m_track.isEmpty()) return;
|
|
|
|
double pixelSize2 = getPixelSize() * getPixelSize();
|
|
|
|
m_track.add(TThickPoint(pos, m_thick), pixelSize2);
|
|
|
|
m_track.add(TThickPoint(m_firstPos, m_thick), pixelSize2);
|
|
|
|
m_track.filterPoints();
|
|
|
|
double error = (30.0 / 11) * sqrt(pixelSize2);
|
|
|
|
TStroke *stroke = m_track.makeStroke(error);
|
|
|
|
|
|
|
|
stroke->setStyle(1);
|
|
|
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
if (m_multi.getValue()) // stroke multi
|
|
|
|
{
|
|
|
|
if (m_firstFrameSelected) {
|
|
|
|
TFrameId tmp = getCurrentFid();
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_firstStrokes.size() && stroke) {
|
|
|
|
std::vector<TStroke *> lastStrokes;
|
|
|
|
for (int i = 0; i < m_track.getBrushCount(); i++)
|
|
|
|
lastStrokes.push_back(m_track.makeStroke(error, i));
|
|
|
|
multiAreaEraser(m_firstFrameId, tmp, m_firstStrokes, lastStrokes);
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
notifyImageChanged();
|
|
|
|
if (e.isShiftPressed()) {
|
2023-02-04 15:05:42 +13:00
|
|
|
m_firstStrokes.clear();
|
|
|
|
for (int i = 0; i < m_track.getBrushCount(); i++)
|
|
|
|
m_firstStrokes.push_back(m_track.makeStroke(error, i));
|
|
|
|
invalidate();
|
2016-06-15 18:43:10 +12:00
|
|
|
m_firstFrameId = getFrameId();
|
|
|
|
} else {
|
|
|
|
if (m_isXsheetCell) {
|
|
|
|
app->getCurrentColumn()->setColumnIndex(m_currCell.first);
|
|
|
|
app->getCurrentFrame()->setFrame(m_currCell.second);
|
|
|
|
} else
|
|
|
|
app->getCurrentFrame()->setFid(m_veryFirstFrameId);
|
|
|
|
resetMulti();
|
|
|
|
delete stroke;
|
|
|
|
}
|
|
|
|
} else // primo frame
|
|
|
|
{
|
2023-02-04 15:05:42 +13:00
|
|
|
m_firstStrokes.clear();
|
|
|
|
for (int i = 0; i < m_track.getBrushCount(); i++)
|
|
|
|
m_firstStrokes.push_back(m_track.makeStroke(error, i));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
|
|
|
|
m_currCell = std::pair<int, int>(getColumnIndex(), getFrame());
|
2023-02-04 15:05:42 +13:00
|
|
|
invalidate();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
} else // stroke non multi
|
|
|
|
{
|
|
|
|
if (!getImage(true)) return;
|
|
|
|
TFrameId frameId = getCurrentFid();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
if (m_track.hasSymmetryBrushes()) TUndoManager::manager()->beginBlock();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
eraseStroke(ri, stroke, m_eraseType.getValue(), m_invertOption.getValue(),
|
|
|
|
/*m_multi.getValue(),*/ m_level, frameId);
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
if (m_track.hasSymmetryBrushes()) {
|
|
|
|
std::vector<TStroke *> symmStrokes = m_track.makeSymmetryStrokes(error);
|
|
|
|
for (int i = 0; i < symmStrokes.size(); i++) {
|
|
|
|
symmStrokes[i]->setStyle(stroke->getStyle());
|
|
|
|
eraseStroke(ri, symmStrokes[i], m_eraseType.getValue(),
|
|
|
|
m_invertOption.getValue(),
|
|
|
|
/*m_multi.getValue(),*/ m_level, frameId);
|
|
|
|
}
|
|
|
|
|
|
|
|
TUndoManager::manager()->endBlock();
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
notifyImageChanged();
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_invertOption.getValue() || m_track.hasSymmetryBrushes())
|
2016-06-15 18:43:10 +12:00
|
|
|
invalidate();
|
|
|
|
else
|
|
|
|
invalidate(stroke->getBBox().enlarge(2));
|
|
|
|
}
|
2023-02-04 15:05:42 +13:00
|
|
|
m_track.reset();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2017-05-31 22:53:58 +12:00
|
|
|
m_mousePressed = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::leftButtonDoubleClick(const TPointD &pos,
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
TRasterImageP ri(getImage(true));
|
|
|
|
if (!ri) return;
|
|
|
|
TStroke *stroke;
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
if (m_polyline.size() <= 1) {
|
|
|
|
resetMulti();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_polyline.back() != pos) m_polyline.push_back(pos);
|
|
|
|
if (m_polyline.back() != m_polyline.front())
|
|
|
|
m_polyline.push_back(m_polyline.front());
|
2023-02-04 15:05:42 +13:00
|
|
|
stroke = m_polyline.makePolylineStroke();
|
2016-06-15 18:43:10 +12:00
|
|
|
assert(stroke->getPoint(0) == stroke->getPoint(1));
|
|
|
|
|
|
|
|
if (m_multi.getValue()) // stroke multi
|
|
|
|
{
|
|
|
|
if (m_firstFrameSelected) {
|
|
|
|
TFrameId tmp = getFrameId();
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_firstStrokes.size() && stroke) {
|
|
|
|
std::vector<TStroke *> lastStrokes;
|
|
|
|
for (int i = 0; i < m_polyline.getBrushCount(); i++)
|
|
|
|
lastStrokes.push_back(m_polyline.makePolylineStroke(i));
|
|
|
|
multiAreaEraser(m_firstFrameId, tmp, m_firstStrokes, lastStrokes);
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
if (e.isShiftPressed()) {
|
2023-02-04 15:05:42 +13:00
|
|
|
m_firstStrokes.clear();
|
|
|
|
for (int i = 0; i < m_polyline.getBrushCount(); i++)
|
|
|
|
m_firstStrokes.push_back(m_polyline.makePolylineStroke(i));
|
|
|
|
invalidate();
|
2016-06-15 18:43:10 +12:00
|
|
|
m_firstFrameId = getFrameId();
|
|
|
|
} else {
|
|
|
|
if (m_isXsheetCell) {
|
|
|
|
app->getCurrentColumn()->setColumnIndex(m_currCell.first);
|
|
|
|
app->getCurrentFrame()->setFrame(m_currCell.second);
|
|
|
|
} else
|
|
|
|
app->getCurrentFrame()->setFid(m_veryFirstFrameId);
|
|
|
|
resetMulti();
|
|
|
|
delete stroke;
|
|
|
|
}
|
|
|
|
} else // primo frame
|
|
|
|
{
|
2023-02-04 15:05:42 +13:00
|
|
|
m_firstStrokes.clear();
|
|
|
|
for (int i = 0; i < m_polyline.getBrushCount(); i++)
|
|
|
|
m_firstStrokes.push_back(m_polyline.makePolylineStroke(i));
|
2016-06-15 18:43:10 +12:00
|
|
|
m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
|
|
|
|
m_currCell = std::pair<int, int>(getColumnIndex(), getFrame());
|
2023-02-04 15:05:42 +13:00
|
|
|
invalidate();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!getImage(true)) return;
|
|
|
|
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
|
|
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
|
|
TFrameId frameId = getFrameId();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
if (m_polyline.hasSymmetryBrushes()) TUndoManager::manager()->beginBlock();
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
eraseStroke(ri, stroke, m_eraseType.getValue(), m_invertOption.getValue(),
|
|
|
|
/*m_multi.getValue(),*/ m_level, frameId);
|
2023-02-04 15:05:42 +13:00
|
|
|
|
|
|
|
if (m_polyline.hasSymmetryBrushes()) {
|
|
|
|
for (int i = 1; i < m_polyline.getBrushCount(); i++) {
|
|
|
|
TStroke *symmStroke = m_polyline.makePolylineStroke(i);
|
|
|
|
symmStroke->setStyle(stroke->getStyle());
|
|
|
|
eraseStroke(ri, symmStroke, m_eraseType.getValue(),
|
|
|
|
m_invertOption.getValue(),
|
|
|
|
/*m_multi.getValue(),*/ m_level, frameId);
|
|
|
|
}
|
|
|
|
|
|
|
|
TUndoManager::manager()->endBlock();
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
notifyImageChanged();
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_invertOption.getValue() || m_polyline.hasSymmetryBrushes())
|
2016-06-15 18:43:10 +12:00
|
|
|
invalidate();
|
|
|
|
else
|
|
|
|
invalidate(stroke->getBBox().enlarge(2));
|
|
|
|
}
|
2023-02-04 15:05:42 +13:00
|
|
|
m_polyline.reset();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
struct Locals {
|
|
|
|
FullColorEraserTool *m_this;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setValue(TIntProperty &prop, int value) {
|
|
|
|
prop.setValue(value);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_this->onPropertyChanged(prop.getName());
|
|
|
|
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void addValue(TIntProperty &prop, double add) {
|
|
|
|
const TIntProperty::Range &range = prop.getRange();
|
|
|
|
setValue(prop,
|
|
|
|
tcrop<double>(prop.getValue() + add, range.first, range.second));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} locals = {this};
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
switch (e.getModifiersMask()) {
|
|
|
|
case TMouseEvent::ALT_KEY: {
|
|
|
|
// User wants to alter the maximum brush size
|
|
|
|
const TPointD &diff = pos - m_mousePos;
|
|
|
|
double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
locals.addValue(m_size, add);
|
|
|
|
break;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
default:
|
|
|
|
m_brushPos = pos;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_mousePos = pos;
|
|
|
|
invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::draw() {
|
|
|
|
double pixelSize2 = getPixelSize() * getPixelSize();
|
|
|
|
m_thick = sqrt(pixelSize2) / 2.0;
|
|
|
|
TRasterImageP img = (TRasterImageP)getImage(false);
|
|
|
|
if (!img) return;
|
2023-02-04 15:05:42 +13:00
|
|
|
// TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
|
|
|
|
// ? TPixel32::White
|
|
|
|
// : TPixel32::Black;
|
|
|
|
TPixel color = TPixel32::Red;
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_eraseType.getValue() == NORMALERASE) {
|
2018-05-17 18:03:05 +12:00
|
|
|
// If toggled off, don't draw brush outline
|
|
|
|
if (!Preferences::instance()->isCursorOutlineEnabled()) return;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
glColor3d(1.0, 0.0, 0.0);
|
|
|
|
tglDrawCircle(m_brushPos, (m_size.getValue() + 1) * 0.5);
|
|
|
|
} else if (m_eraseType.getValue() == RECTERASE) {
|
2023-02-04 15:05:42 +13:00
|
|
|
if (m_multi.getValue() && m_firstFrameSelected) {
|
|
|
|
if (m_firstStrokes.size()) {
|
|
|
|
tglColor(color);
|
|
|
|
for (int i = 0; i < m_firstStrokes.size(); i++)
|
|
|
|
drawStrokeCenterline(*m_firstStrokes[i], 1);
|
|
|
|
} else
|
|
|
|
drawRect(m_firstRect, color, 0x3F33, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_selecting || (m_multi.getValue() && !m_firstFrameSelected)) {
|
|
|
|
if (m_polyline.size() > 1) {
|
|
|
|
glPushMatrix();
|
|
|
|
m_polyline.drawRectangle(color);
|
|
|
|
glPopMatrix();
|
|
|
|
} else
|
|
|
|
drawRect(m_selectingRect, color, 0xFFFF, true);
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
if ((m_eraseType.getValue() == FREEHANDERASE ||
|
|
|
|
m_eraseType.getValue() == POLYLINEERASE) &&
|
|
|
|
m_multi.getValue()) {
|
|
|
|
tglColor(color);
|
2023-02-04 15:05:42 +13:00
|
|
|
for (int i = 0; i < m_firstStrokes.size(); i++)
|
|
|
|
drawStrokeCenterline(*m_firstStrokes[i], 1);
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
if (m_eraseType.getValue() == POLYLINEERASE && !m_polyline.empty()) {
|
2023-02-04 15:05:42 +13:00
|
|
|
m_polyline.drawPolyline(m_mousePos, color);
|
2017-11-14 16:38:01 +13:00
|
|
|
} else if (m_eraseType.getValue() == FREEHANDERASE && !m_track.isEmpty()) {
|
|
|
|
tglColor(color);
|
2023-02-04 15:05:42 +13:00
|
|
|
glPushMatrix();
|
2017-11-14 16:38:01 +13:00
|
|
|
m_track.drawAllFragments();
|
2023-02-04 15:05:42 +13:00
|
|
|
glPopMatrix();
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool FullColorEraserTool::onPropertyChanged(std::string propertyName) {
|
|
|
|
FullcolorEraseSize = m_size.getValue();
|
|
|
|
FullcolorEraseHardness = m_hardness.getValue();
|
|
|
|
FullcolorEraserOpacity = m_opacity.getValue();
|
|
|
|
FullcolorEraserType = ::to_string(m_eraseType.getValue());
|
|
|
|
FullcolorEraserInvert = (int)m_invertOption.getValue();
|
|
|
|
FullcolorEraserRange = (int)m_multi.getValue();
|
|
|
|
if (propertyName == "Hardness:" || propertyName == "Size:") {
|
|
|
|
m_brushPad = getBrushPad(m_size.getValue(), m_hardness.getValue() * 0.01);
|
|
|
|
TRectD rect(
|
|
|
|
m_brushPos - TPointD(FullcolorEraseSize + 2, FullcolorEraseSize + 2),
|
|
|
|
m_brushPos + TPointD(FullcolorEraseSize + 2, FullcolorEraseSize + 2));
|
|
|
|
invalidate(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::update(const TRasterImageP &ri, TRectD selArea,
|
|
|
|
const TXshSimpleLevelP &level, bool multi,
|
|
|
|
const TFrameId &frameId) {
|
|
|
|
if (m_selectingRect.x0 > m_selectingRect.x1) {
|
|
|
|
selArea.x1 = m_selectingRect.x0;
|
|
|
|
selArea.x0 = m_selectingRect.x1;
|
|
|
|
}
|
|
|
|
if (m_selectingRect.y0 > m_selectingRect.y1) {
|
|
|
|
selArea.y1 = m_selectingRect.y0;
|
|
|
|
selArea.y0 = m_selectingRect.y1;
|
|
|
|
}
|
|
|
|
if (selArea.getLx() < 1 || selArea.getLy() < 1) return;
|
|
|
|
|
|
|
|
TRasterP raster = ri->getRaster();
|
|
|
|
TTileSetFullColor *tileSet = new TTileSetFullColor(raster->getSize());
|
|
|
|
tileSet->add(raster, TRasterImageUtils::convertWorldToRaster(selArea, ri));
|
|
|
|
TUndo *undo;
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
std::wstring eraseType =
|
|
|
|
(m_eraseType.getValue() == RECTERASE && m_polyline.hasSymmetryBrushes())
|
|
|
|
? POLYLINEERASE
|
|
|
|
: m_eraseType.getValue();
|
|
|
|
undo = new RectFullColorUndo(tileSet, selArea, TStroke(), eraseType,
|
|
|
|
level.getPointer(),
|
2016-06-15 18:43:10 +12:00
|
|
|
m_invertOption.getValue(), frameId);
|
|
|
|
TRect rect = TRasterImageUtils::eraseRect(ri, selArea);
|
|
|
|
|
|
|
|
TUndoManager::manager()->add(undo);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::resetMulti() {
|
|
|
|
m_isXsheetCell = false;
|
|
|
|
m_firstFrameSelected = false;
|
|
|
|
m_firstRect.empty();
|
|
|
|
m_selectingRect.empty();
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
m_level = app->getCurrentLevel()->getLevel()
|
|
|
|
? app->getCurrentLevel()->getSimpleLevel()
|
|
|
|
: 0;
|
|
|
|
m_firstFrameId = m_veryFirstFrameId = getCurrentFid();
|
2023-02-04 15:05:42 +13:00
|
|
|
m_firstStrokes.clear();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::onImageChanged() {
|
|
|
|
if (!m_multi.getValue()) return;
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
TXshSimpleLevel *xshl = 0;
|
|
|
|
if (app->getCurrentLevel()->getLevel())
|
|
|
|
xshl = app->getCurrentLevel()->getSimpleLevel();
|
|
|
|
|
|
|
|
if (!xshl || m_level.getPointer() != xshl ||
|
2023-02-04 15:05:42 +13:00
|
|
|
(m_selectingRect.isEmpty() && !m_firstStrokes.size()))
|
2016-06-15 18:43:10 +12:00
|
|
|
resetMulti();
|
|
|
|
else if (m_firstFrameId == getCurrentFid())
|
|
|
|
m_firstFrameSelected = false; // nel caso sono passato allo stato 1 e torno
|
|
|
|
// all'immagine iniziale, torno allo stato
|
|
|
|
// iniziale
|
2016-06-20 14:23:05 +12:00
|
|
|
else { // cambio stato.
|
2016-06-15 18:43:10 +12:00
|
|
|
m_firstFrameSelected = true;
|
|
|
|
if (m_eraseType.getValue() != FREEHANDERASE &&
|
|
|
|
m_eraseType.getValue() != POLYLINEERASE) {
|
|
|
|
assert(!m_selectingRect.isEmpty());
|
|
|
|
m_firstRect = m_selectingRect;
|
|
|
|
}
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::multiUpdate(const TRectD firstRect,
|
|
|
|
const TRectD lastRect) {
|
|
|
|
bool backward = false;
|
|
|
|
TFrameId firstFid = m_firstFrameId;
|
|
|
|
TFrameId lastFid = getCurrentFid();
|
|
|
|
if (firstFid > lastFid) {
|
2018-08-30 20:18:43 +12:00
|
|
|
std::swap(firstFid, lastFid);
|
2016-06-15 18:43:10 +12:00
|
|
|
backward = true;
|
|
|
|
}
|
|
|
|
assert(firstFid <= lastFid);
|
|
|
|
std::vector<TFrameId> allFids;
|
|
|
|
m_level->getFids(allFids);
|
|
|
|
|
|
|
|
std::vector<TFrameId>::iterator i0 = allFids.begin();
|
|
|
|
while (i0 != allFids.end() && *i0 < firstFid) i0++;
|
|
|
|
if (i0 == allFids.end()) return;
|
|
|
|
std::vector<TFrameId>::iterator i1 = i0;
|
|
|
|
while (i1 != allFids.end() && *i1 <= lastFid) i1++;
|
|
|
|
assert(i0 < i1);
|
|
|
|
std::vector<TFrameId> fids(i0, i1);
|
|
|
|
int m = fids.size();
|
|
|
|
assert(m > 0);
|
|
|
|
|
|
|
|
TUndoManager::manager()->beginBlock();
|
|
|
|
for (int i = 0; i < m; ++i) {
|
|
|
|
TFrameId fid = fids[i];
|
|
|
|
assert(firstFid <= fid && fid <= lastFid);
|
|
|
|
TRasterImageP ri = m_level->getFrame(fid, true);
|
|
|
|
assert(ri);
|
|
|
|
double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;
|
|
|
|
TRectD rect = interpolateRect(firstRect, lastRect, backward ? 1 - t : t);
|
|
|
|
if (m_invertOption.getValue()) {
|
|
|
|
TRectD rect01 =
|
|
|
|
TRectD(TPointD(-100000., -100000.), TPointD(rect.x0, 100000.));
|
|
|
|
update(ri, rect01, m_level, true, fid);
|
|
|
|
TRectD rect02 = TRectD(rect.getP01(), TPointD(rect.x1, 100000.));
|
|
|
|
update(ri, rect02, m_level, true, fid);
|
|
|
|
TRectD rect03 = TRectD(TPointD(rect.x0, -100000.), rect.getP10());
|
|
|
|
update(ri, rect03, m_level, true, fid);
|
|
|
|
TRectD rect04 =
|
|
|
|
TRectD(TPointD(rect.x1, -100000.), TPointD(100000., 100000.));
|
|
|
|
update(ri, rect04, m_level, true, fid);
|
|
|
|
} else
|
|
|
|
update(ri, rect, m_level, true, fid);
|
|
|
|
m_level->getProperties()->setDirtyFlag(true);
|
|
|
|
notifyImageChanged(fid);
|
|
|
|
}
|
|
|
|
TUndoManager::manager()->endBlock();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void FullColorEraserTool::onEnter() {
|
|
|
|
TRasterImageP ti(getImage(false));
|
|
|
|
if (!ti) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
m_level = app->getCurrentLevel()->getLevel()
|
|
|
|
? app->getCurrentLevel()->getSimpleLevel()
|
|
|
|
: 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FullColorEraserTool::multiAreaEraser(TFrameId &firstFid, TFrameId &lastFid,
|
2023-02-04 15:05:42 +13:00
|
|
|
std::vector<TStroke *>firstStrokes,
|
|
|
|
std::vector<TStroke *>lastStrokes) {
|
|
|
|
// TStroke *first = new TStroke();
|
|
|
|
// TStroke *last = new TStroke();
|
|
|
|
// *first = *firstStrokes[0];
|
|
|
|
// *last = *lastStrokes[0];
|
2016-06-15 18:43:10 +12:00
|
|
|
TVectorImageP firstImage = new TVectorImage();
|
|
|
|
TVectorImageP lastImage = new TVectorImage();
|
2023-02-04 15:05:42 +13:00
|
|
|
for (int i = 0; i < firstStrokes.size(); i++)
|
|
|
|
firstImage->addStroke(firstStrokes[i]);
|
|
|
|
for (int i = 0; i < lastStrokes.size(); i++)
|
|
|
|
lastImage->addStroke(lastStrokes[i]);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
bool backward = false;
|
|
|
|
if (firstFid > lastFid) {
|
2018-08-30 20:18:43 +12:00
|
|
|
std::swap(firstFid, lastFid);
|
2016-06-15 18:43:10 +12:00
|
|
|
backward = true;
|
|
|
|
}
|
|
|
|
assert(firstFid <= lastFid);
|
|
|
|
std::vector<TFrameId> allFids;
|
|
|
|
m_level->getFids(allFids);
|
|
|
|
|
|
|
|
std::vector<TFrameId>::iterator i0 = allFids.begin();
|
|
|
|
while (i0 != allFids.end() && *i0 < firstFid) i0++;
|
|
|
|
if (i0 == allFids.end()) return;
|
|
|
|
std::vector<TFrameId>::iterator i1 = i0;
|
|
|
|
while (i1 != allFids.end() && *i1 <= lastFid) i1++;
|
|
|
|
assert(i0 < i1);
|
|
|
|
std::vector<TFrameId> fids(i0, i1);
|
|
|
|
int m = fids.size();
|
|
|
|
assert(m > 0);
|
|
|
|
TUndoManager::manager()->beginBlock();
|
|
|
|
for (int i = 0; i < m; ++i) {
|
|
|
|
TFrameId fid = fids[i];
|
|
|
|
assert(firstFid <= fid && fid <= lastFid);
|
|
|
|
TImageP img = m_level->getFrame(fid, true);
|
|
|
|
double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;
|
|
|
|
doMultiEraser(img, backward ? 1 - t : t, fid, firstImage, lastImage);
|
|
|
|
m_level->getProperties()->setDirtyFlag(true);
|
|
|
|
notifyImageChanged(fid);
|
|
|
|
}
|
|
|
|
TUndoManager::manager()->endBlock();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FullColorEraserTool::doMultiEraser(const TImageP &img, double t,
|
2016-06-15 18:43:10 +12:00
|
|
|
const TFrameId &fid,
|
|
|
|
const TVectorImageP &firstImage,
|
|
|
|
const TVectorImageP &lastImage) {
|
|
|
|
int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
|
2023-02-04 15:05:42 +13:00
|
|
|
std::wstring eraseType = m_eraseType.getValue() == RECTERASE
|
|
|
|
? POLYLINEERASE
|
|
|
|
: m_eraseType.getValue();
|
2016-06-15 18:43:10 +12:00
|
|
|
if (t == 0)
|
2023-02-04 15:05:42 +13:00
|
|
|
for (int i = 0; i < firstImage->getStrokeCount(); i++)
|
|
|
|
eraseStroke(img, firstImage->getStroke(i), eraseType,
|
|
|
|
m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level,
|
|
|
|
fid);
|
2016-06-15 18:43:10 +12:00
|
|
|
else if (t == 1)
|
2023-02-04 15:05:42 +13:00
|
|
|
for (int i = 0; i < lastImage->getStrokeCount(); i++)
|
|
|
|
eraseStroke(img, lastImage->getStroke(i), eraseType,
|
|
|
|
m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level,
|
|
|
|
fid);
|
2016-06-15 18:43:10 +12:00
|
|
|
else {
|
2023-02-04 15:05:42 +13:00
|
|
|
// assert(firstImage->getStrokeCount() == 1);
|
|
|
|
// assert(lastImage->getStrokeCount() == 1);
|
2016-06-15 18:43:10 +12:00
|
|
|
TVectorImageP vi = TInbetween(firstImage, lastImage).tween(t);
|
2023-02-04 15:05:42 +13:00
|
|
|
// assert(vi->getStrokeCount() == 1);
|
|
|
|
for (int i = 0; i < vi->getStrokeCount(); i++)
|
|
|
|
eraseStroke(img, vi->getStroke(i), eraseType, m_invertOption.getValue(),
|
|
|
|
/*m_multi.getValue(),*/ m_level, fid);
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|