2016-03-19 06:57:51 +13:00
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
/*! Finger Tool : 線のノイズを埋めるツール
|
2019-10-11 16:13:41 +13:00
|
|
|
|
*/
|
2016-03-19 06:57:51 +13:00
|
|
|
|
#include "tstroke.h"
|
|
|
|
|
#include "tools/toolutils.h"
|
|
|
|
|
#include "tools/tool.h"
|
|
|
|
|
#include "tmathutil.h"
|
|
|
|
|
#include "tools/cursors.h"
|
|
|
|
|
#include "drawutil.h"
|
|
|
|
|
#include "tcolorstyles.h"
|
|
|
|
|
#include "tundo.h"
|
|
|
|
|
#include "tvectorimage.h"
|
|
|
|
|
#include "ttoonzimage.h"
|
|
|
|
|
#include "tproperty.h"
|
|
|
|
|
#include "toonz/ttilesaver.h"
|
|
|
|
|
#include "toonz/txshsimplelevel.h"
|
|
|
|
|
#include "toonz/observer.h"
|
|
|
|
|
#include "toonz/toonzimageutils.h"
|
|
|
|
|
#include "toonz/levelproperties.h"
|
|
|
|
|
#include "toonz/stage2.h"
|
|
|
|
|
#include "toonz/ttileset.h"
|
2018-05-17 18:03:05 +12:00
|
|
|
|
#include "toonz/preferences.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
#include "tgl.h"
|
|
|
|
|
#include "tenv.h"
|
|
|
|
|
|
|
|
|
|
#include "trop.h"
|
|
|
|
|
|
|
|
|
|
#include "tinbetween.h"
|
|
|
|
|
#include "ttile.h"
|
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
|
#include "cmrasterbrush.h"
|
|
|
|
|
#include "symmetrytool.h"
|
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
|
#include "toonz/tpalettehandle.h"
|
|
|
|
|
#include "toonz/txsheethandle.h"
|
|
|
|
|
#include "toonz/txshlevelhandle.h"
|
|
|
|
|
#include "toonz/tframehandle.h"
|
|
|
|
|
#include "tools/toolhandle.h"
|
|
|
|
|
|
|
|
|
|
// For Qt translation support
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
|
|
#include "tools/stylepicker.h"
|
|
|
|
|
#include "toonzqt/tselectionhandle.h"
|
|
|
|
|
#include "toonzqt/styleselection.h"
|
|
|
|
|
#include "historytypes.h"
|
|
|
|
|
|
|
|
|
|
using namespace ToolUtils;
|
|
|
|
|
|
|
|
|
|
TEnv::IntVar FingerInvert("InknpaintFingerInvert", 0);
|
|
|
|
|
TEnv::DoubleVar FingerSize("InknpaintFingerSize", 10);
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const int BackgroundStyle = 0;
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
namespace {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class FingerUndo final : public TRasterUndo {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
std::vector<TThickPoint> m_points;
|
|
|
|
|
int m_styleId;
|
|
|
|
|
bool m_invert;
|
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
|
|
|
|
FingerUndo(TTileSetCM32 *tileSet, const std::vector<TThickPoint> &points,
|
|
|
|
|
int styleId, bool invert, TXshSimpleLevel *level,
|
2023-02-04 15:05:42 +13:00
|
|
|
|
const TFrameId &frameId, TPointD dpiScale, double symmetryLines,
|
|
|
|
|
double rotation, TPointD centerPoint, bool useLineSymmetry)
|
2016-06-15 18:43:10 +12:00
|
|
|
|
: TRasterUndo(tileSet, level, frameId, false, false, 0)
|
|
|
|
|
, m_points(points)
|
|
|
|
|
, m_styleId(styleId)
|
2023-02-04 15:05:42 +13:00
|
|
|
|
, m_invert(invert)
|
|
|
|
|
, 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
|
|
|
|
TToonzImageP image = m_level->getFrame(m_frameId, true);
|
|
|
|
|
TRasterCM32P ras = image->getRaster();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
CMRasterBrush m_cmRasterBrush(ras, FINGER, INK, m_styleId, m_points[0],
|
|
|
|
|
m_invert, 0, false, false);
|
|
|
|
|
|
|
|
|
|
if (m_brushCount > 1)
|
|
|
|
|
m_cmRasterBrush.addSymmetryBrushes(m_brushCount, m_rotation,
|
|
|
|
|
m_centerPoint, m_useLineSymmetry,
|
|
|
|
|
m_dpiScale);
|
|
|
|
|
|
|
|
|
|
m_cmRasterBrush.setPointsSequence(m_points);
|
|
|
|
|
m_cmRasterBrush.generateStroke(true);
|
|
|
|
|
image->setSavebox(
|
|
|
|
|
image->getSavebox() +
|
|
|
|
|
m_cmRasterBrush.getBBox(m_cmRasterBrush.getPointsSequence()));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
ToolUtils::updateSaveBox();
|
|
|
|
|
|
|
|
|
|
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
|
|
|
notifyImageChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
|
int getSize() const override {
|
|
|
|
|
return sizeof(*this) + TRasterUndo::getSize();
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
QString getToolName() override { return QString("Finger Tool"); }
|
|
|
|
|
int getHistoryType() override { return HistoryType::FingerTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void drawLine(const TPointD &point, const TPointD ¢re, bool horizontal,
|
|
|
|
|
bool isDecimal) {
|
|
|
|
|
if (!isDecimal) {
|
|
|
|
|
if (horizontal) {
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 1.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y - 0.5, -point.x + 1.5) + centre,
|
|
|
|
|
TPointD(point.y - 0.5, -point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, -point.y + 0.5) + centre,
|
|
|
|
|
TPointD(-point.x - 0.5, -point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
|
|
|
|
|
|
|
|
tglDrawSegment(TPointD(point.y - 0.5, point.x + 0.5) + centre,
|
|
|
|
|
TPointD(point.y - 0.5, point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 0.5, -point.y + 0.5) + centre,
|
|
|
|
|
TPointD(point.x - 1.5, -point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, -point.x + 1.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x - 0.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
|
|
|
} else {
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 1.5, point.y + 1.5) + centre,
|
|
|
|
|
TPointD(point.x - 1.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 1.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 1.5) + centre,
|
|
|
|
|
TPointD(point.y - 0.5, -point.x + 1.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y - 0.5, -point.x + 1.5) + centre,
|
|
|
|
|
TPointD(point.y - 0.5, -point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 0.5) + centre,
|
|
|
|
|
TPointD(-point.x + 0.5, -point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, -point.y + 0.5) + centre,
|
|
|
|
|
TPointD(-point.x - 0.5, -point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 1.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
|
|
|
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(point.y - 0.5, point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y - 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(point.y - 0.5, point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 1.5, -point.y - 0.5) + centre,
|
|
|
|
|
TPointD(point.x - 1.5, -point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 1.5, -point.y + 0.5) + centre,
|
|
|
|
|
TPointD(point.x - 0.5, -point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 1.5, -point.x + 1.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, -point.x + 1.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 1.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, -point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 1.5) + centre,
|
|
|
|
|
TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (horizontal) {
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 0.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(point.x + 0.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(point.y + 0.5, point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 0.5) + centre,
|
|
|
|
|
TPointD(point.y + 0.5, -point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x + 0.5, -point.y - 0.5) + centre,
|
|
|
|
|
TPointD(point.x - 0.5, -point.y - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x - 0.5, -point.y - 0.5) + centre,
|
|
|
|
|
TPointD(-point.x + 0.5, -point.y - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, -point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
|
|
|
} else {
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 0.5, point.y + 1.5) + centre,
|
|
|
|
|
TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 0.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(point.x + 0.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 1.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(point.y + 0.5, point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(point.y + 0.5, point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 1.5, -point.x + 0.5) + centre,
|
|
|
|
|
TPointD(point.y + 0.5, -point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 0.5) + centre,
|
|
|
|
|
TPointD(point.y + 0.5, -point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 0.5, -point.y - 1.5) + centre,
|
|
|
|
|
TPointD(point.x - 0.5, -point.y - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(point.x - 0.5, -point.y - 0.5) + centre,
|
|
|
|
|
TPointD(point.x + 0.5, -point.y - 0.5) + centre);
|
|
|
|
|
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 1.5) + centre,
|
|
|
|
|
TPointD(-point.x + 0.5, -point.y - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 0.5) + centre,
|
|
|
|
|
TPointD(-point.x - 0.5, -point.y - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 1.5, -point.x + 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, -point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, -point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 1.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, point.x - 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
|
|
|
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 1.5) + centre,
|
|
|
|
|
TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
|
|
|
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre,
|
|
|
|
|
TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void drawEmptyCircle(int thick, const TPointD &mousePos, bool isPencil,
|
|
|
|
|
bool isLxEven, bool isLyEven) {
|
|
|
|
|
TPointD pos = mousePos;
|
|
|
|
|
if (isLxEven) pos.x += 0.5;
|
|
|
|
|
if (isLyEven) pos.y += 0.5;
|
|
|
|
|
if (!isPencil)
|
|
|
|
|
tglDrawCircle(pos, (thick + 1) * 0.5);
|
|
|
|
|
else {
|
|
|
|
|
int x = 0, y = tround((thick * 0.5) - 0.5);
|
|
|
|
|
int d = 3 - 2 * (int)(thick * 0.5);
|
|
|
|
|
bool horizontal = true, isDecimal = thick % 2 != 0;
|
|
|
|
|
drawLine(TPointD(x, y), pos, horizontal, isDecimal);
|
|
|
|
|
while (y > x) {
|
|
|
|
|
if (d < 0) {
|
|
|
|
|
d = d + 4 * x + 6;
|
|
|
|
|
horizontal = true;
|
|
|
|
|
} else {
|
|
|
|
|
d = d + 4 * (x - y) + 10;
|
|
|
|
|
horizontal = false;
|
|
|
|
|
y--;
|
|
|
|
|
}
|
|
|
|
|
x++;
|
|
|
|
|
drawLine(TPointD(x, y), pos, horizontal, isDecimal);
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class FingerTool final : public TTool {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(FingerTool)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
|
CMRasterBrush *m_cmRasterBrush;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
bool m_firstTime;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double m_pointSize, m_distance2;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
bool m_selecting;
|
|
|
|
|
TTileSaverCM32 *m_tileSaver;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPointD m_mousePos;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TIntProperty m_toolSize;
|
|
|
|
|
TBoolProperty m_invert;
|
|
|
|
|
TPropertyGroup m_prop;
|
|
|
|
|
int m_cursor;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*--- 作業中のFrameIdをクリック時に保存し、マウスリリース時(Undoの登録時)
|
|
|
|
|
に別のフレームに移動している場合があるため ---*/
|
|
|
|
|
TFrameId m_workingFrameId;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*-- 最初のクリックでStyleを切り替える --*/
|
|
|
|
|
void pick(const TPointD &pos);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
FingerTool();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void draw() override;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void update(TToonzImageP ti, TRectD area);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void updateTranslation() override;
|
|
|
|
|
|
|
|
|
|
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 &) override;
|
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void onEnter() override;
|
|
|
|
|
void onLeave() override;
|
|
|
|
|
void onActivate() override;
|
|
|
|
|
void onDeactivate() override;
|
|
|
|
|
bool onPropertyChanged(std::string propertyName) override;
|
|
|
|
|
|
|
|
|
|
TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
|
|
|
|
|
ToolType getToolType() const override { return TTool::LevelWriteTool; }
|
|
|
|
|
int getCursorId() const override { return m_cursor; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
int getColorClass() const { return 2; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*--
|
|
|
|
|
* ドラッグ中にツールが切り替わった場合に備え、onDeactivateにもMouseReleaseと同じ処理を行う
|
|
|
|
|
* --*/
|
|
|
|
|
void finishBrush();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FingerTool fingerTool;
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//
|
2021-07-08 13:39:28 +12:00
|
|
|
|
// InkPaintTool implementation
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
FingerTool::FingerTool()
|
2016-06-15 18:43:10 +12:00
|
|
|
|
: TTool("T_Finger")
|
2023-02-04 15:05:42 +13:00
|
|
|
|
, m_cmRasterBrush(0)
|
2016-06-15 18:43:10 +12:00
|
|
|
|
, m_pointSize(-1)
|
|
|
|
|
, m_selecting(false)
|
|
|
|
|
, m_tileSaver(0)
|
|
|
|
|
, m_cursor(ToolCursor::EraserCursor)
|
2019-10-11 16:13:41 +13:00
|
|
|
|
, m_toolSize("Size:", 1, 1000, 10, false)
|
2016-06-15 18:43:10 +12:00
|
|
|
|
, m_invert("Invert", false)
|
|
|
|
|
, m_firstTime(true)
|
|
|
|
|
, m_workingFrameId(TFrameId()) {
|
|
|
|
|
bind(TTool::ToonzImage);
|
|
|
|
|
|
2019-10-11 16:13:41 +13:00
|
|
|
|
m_toolSize.setNonLinearSlider();
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_prop.bind(m_toolSize);
|
|
|
|
|
m_prop.bind(m_invert);
|
|
|
|
|
|
|
|
|
|
m_invert.setId("Invert");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::updateTranslation() {
|
|
|
|
|
m_toolSize.setQStringName(tr("Size:"));
|
|
|
|
|
m_invert.setQStringName(tr("Invert", NULL));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::draw() {
|
|
|
|
|
if (m_pointSize == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
TToonzImageP ti = (TToonzImageP)getImage(false);
|
|
|
|
|
if (!ti) return;
|
|
|
|
|
TRasterP ras = ti->getRaster();
|
|
|
|
|
int lx = ras->getLx();
|
|
|
|
|
int ly = ras->getLy();
|
|
|
|
|
|
|
|
|
|
if ((ToonzCheck::instance()->getChecks() & ToonzCheck::eInk) ||
|
|
|
|
|
(ToonzCheck::instance()->getChecks() & ToonzCheck::ePaint))
|
|
|
|
|
glColor3d(0.5, 0.8, 0.8);
|
|
|
|
|
else
|
|
|
|
|
glColor3d(1.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
|
|
drawEmptyCircle(m_toolSize.getValue(), m_mousePos, true, lx % 2 == 0,
|
|
|
|
|
ly % 2 == 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const UINT pointCount = 20;
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
bool FingerTool::onPropertyChanged(std::string propertyName) {
|
|
|
|
|
/*-- サイズ --*/
|
|
|
|
|
if (propertyName == m_toolSize.getName()) {
|
|
|
|
|
FingerSize = m_toolSize.getValue();
|
|
|
|
|
double x = m_toolSize.getValue();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double minRange = 1;
|
|
|
|
|
double maxRange = 100;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double minSize = 0.01;
|
|
|
|
|
double maxSize = 100;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_pointSize =
|
|
|
|
|
(x - minRange) / (maxRange - minRange) * (maxSize - minSize) + minSize;
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
// Invert
|
|
|
|
|
else if (propertyName == m_invert.getName()) {
|
|
|
|
|
FingerInvert = (int)(m_invert.getValue());
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return true;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
|
pick(pos);
|
|
|
|
|
|
|
|
|
|
m_selecting = true;
|
|
|
|
|
TImageP image(getImage(true));
|
|
|
|
|
|
|
|
|
|
if (TToonzImageP ti = image) {
|
|
|
|
|
TRasterCM32P ras = ti->getRaster();
|
|
|
|
|
if (ras) {
|
|
|
|
|
int thickness = m_toolSize.getValue();
|
|
|
|
|
int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
|
|
|
|
|
TTileSetCM32 *tileSet = new TTileSetCM32(ras->getSize());
|
|
|
|
|
m_tileSaver = new TTileSaverCM32(ras, tileSet);
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_cmRasterBrush = new CMRasterBrush(
|
2016-06-15 18:43:10 +12:00
|
|
|
|
ras, FINGER, INK, styleId,
|
|
|
|
|
TThickPoint(pos + convert(ras->getCenter()), thickness),
|
2021-06-04 01:36:17 +12:00
|
|
|
|
m_invert.getValue(), 0, false, false);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
|
SymmetryTool *symmetryTool = dynamic_cast<SymmetryTool *>(
|
|
|
|
|
TTool::getTool("T_Symmetry", TTool::RasterImage));
|
|
|
|
|
if (symmetryTool && symmetryTool->isGuideEnabled()) {
|
|
|
|
|
TPointD dpiScale = getViewer()->getDpiScale();
|
|
|
|
|
SymmetryObject symmObj = symmetryTool->getSymmetryObject();
|
|
|
|
|
m_cmRasterBrush->addSymmetryBrushes(
|
|
|
|
|
symmObj.getLines(), symmObj.getRotation(), symmObj.getCenterPoint(),
|
|
|
|
|
symmObj.isUsingLineSymmetry(), dpiScale);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*-- 作業中Fidを現在のFIDにする --*/
|
|
|
|
|
m_workingFrameId = getFrameId();
|
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_tileSaver->save(m_cmRasterBrush->getLastRect());
|
|
|
|
|
TRect modifiedBbox = m_cmRasterBrush->generateLastPieceOfStroke(true);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
|
if (!m_selecting) return;
|
|
|
|
|
|
|
|
|
|
m_mousePos = pos;
|
|
|
|
|
if (TToonzImageP ri = TImageP(getImage(true))) {
|
|
|
|
|
/*--- マウスを動かしながらショートカットで切り替わった場合、
|
|
|
|
|
いきなりleftButtonDragから呼ばれることがあり、
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_cmRasterBrushが無くて落ちることがある。 ---*/
|
|
|
|
|
if (m_cmRasterBrush) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
int thickness = m_toolSize.getValue();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_cmRasterBrush->add(
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TThickPoint(pos + convert(ri->getRaster()->getCenter()), thickness));
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_tileSaver->save(m_cmRasterBrush->getLastRect());
|
|
|
|
|
TRect modifiedBbox = m_cmRasterBrush->generateLastPieceOfStroke(true);
|
2018-06-18 16:01:39 +12:00
|
|
|
|
invalidate();
|
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 FingerTool::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
if (!m_selecting) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_mousePos = pos;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
finishBrush();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
|
m_mousePos = pos;
|
|
|
|
|
TPointD pp(tround(pos.x), tround(pos.y));
|
|
|
|
|
m_mousePos = pp;
|
|
|
|
|
invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::onEnter() {
|
|
|
|
|
if (m_firstTime) {
|
|
|
|
|
m_invert.setValue(FingerInvert ? 1 : 0);
|
|
|
|
|
m_toolSize.setValue(FingerSize);
|
|
|
|
|
m_firstTime = false;
|
|
|
|
|
}
|
|
|
|
|
double x = m_toolSize.getValue();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double minRange = 1;
|
|
|
|
|
double maxRange = 100;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double minSize = 0.01;
|
|
|
|
|
double maxSize = 100;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_pointSize =
|
|
|
|
|
(x - minRange) / (maxRange - minRange) * (maxSize - minSize) + minSize;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if ((TToonzImageP)getImage(false))
|
|
|
|
|
m_cursor = ToolCursor::PenCursor;
|
|
|
|
|
else
|
|
|
|
|
m_cursor = ToolCursor::CURSOR_NO;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::onLeave() { m_pointSize = -1; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::onActivate() { onEnter(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::onDeactivate() {
|
|
|
|
|
/*---
|
|
|
|
|
* マウスドラッグ中(m_selecting=true)にツールが切り替わったときに線を終わらせる
|
|
|
|
|
* ---*/
|
|
|
|
|
if (m_selecting) finishBrush();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*!
|
|
|
|
|
* ドラッグ中にツールが切り替わった場合に備え、onDeactivateにもMouseReleaseと同じ処理を行う
|
2019-10-11 16:13:41 +13:00
|
|
|
|
*/
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::finishBrush() {
|
|
|
|
|
if (TToonzImageP ti = (TToonzImageP)getImage(true)) {
|
2023-02-04 15:05:42 +13:00
|
|
|
|
if (m_cmRasterBrush) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
int thickness = m_toolSize.getValue();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_cmRasterBrush->add(TThickPoint(
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_mousePos + convert(ti->getRaster()->getCenter()), thickness));
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_tileSaver->save(m_cmRasterBrush->getLastRect());
|
|
|
|
|
TRect modifiedBbox =
|
|
|
|
|
m_cmRasterBrush->generateLastPieceOfStroke(true, true);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
|
|
|
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
|
|
|
|
|
|
|
|
TFrameId frameId =
|
|
|
|
|
m_workingFrameId.isEmptyFrame() ? getCurrentFid() : m_workingFrameId;
|
|
|
|
|
|
2023-02-04 15:05:42 +13:00
|
|
|
|
double symmetryLines = 0;
|
|
|
|
|
double rotation = 0;
|
|
|
|
|
bool useLineSymmetry = false;
|
|
|
|
|
TPointD dpiScale = getViewer()->getDpiScale();
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TUndoManager::manager()->add(new FingerUndo(
|
2023-02-04 15:05:42 +13:00
|
|
|
|
m_tileSaver->getTileSet(), m_cmRasterBrush->getPointsSequence(),
|
|
|
|
|
m_cmRasterBrush->getStyleId(), m_cmRasterBrush->isSelective(),
|
|
|
|
|
simLevel.getPointer(), frameId, dpiScale, symmetryLines, rotation,
|
|
|
|
|
centerPoint, useLineSymmetry));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
ToolUtils::updateSaveBox();
|
|
|
|
|
|
|
|
|
|
/*! FIdを指定して、作業中にフレームが動いても、
|
|
|
|
|
クリック時のFidのサムネイルが更新されるようにする。
|
|
|
|
|
*/
|
|
|
|
|
notifyImageChanged(frameId);
|
|
|
|
|
|
|
|
|
|
invalidate();
|
2023-02-04 15:05:42 +13:00
|
|
|
|
delete m_cmRasterBrush;
|
|
|
|
|
m_cmRasterBrush = 0;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
delete m_tileSaver;
|
|
|
|
|
|
|
|
|
|
/*-- 作業中fIdをリセット --*/
|
|
|
|
|
m_workingFrameId = TFrameId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_selecting = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void FingerTool::pick(const TPointD &pos) {
|
|
|
|
|
int modeValue = 2; // LINES
|
|
|
|
|
|
|
|
|
|
TImageP image = getImage(false);
|
|
|
|
|
TToonzImageP ti = image;
|
|
|
|
|
TVectorImageP vi = image;
|
|
|
|
|
TXshSimpleLevel *level =
|
|
|
|
|
getApplication()->getCurrentLevel()->getSimpleLevel();
|
|
|
|
|
if (!ti || !level) return;
|
|
|
|
|
|
|
|
|
|
/*--- 画面外をpickしても拾えないようにする ---*/
|
|
|
|
|
if (!m_viewer->getGeometry().contains(pos)) return;
|
|
|
|
|
|
|
|
|
|
int subsampling = level->getImageSubsampling(getCurrentFid());
|
|
|
|
|
|
2022-02-28 11:18:09 +13:00
|
|
|
|
StylePicker picker(getViewer()->viewerWidget(), image);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
int styleId =
|
|
|
|
|
picker.pickStyleId(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5),
|
2021-03-23 20:43:41 +13:00
|
|
|
|
getPixelSize() * getPixelSize(), 1.0, modeValue);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
if (styleId < 0) return;
|
|
|
|
|
|
|
|
|
|
if (modeValue == 2) // LINES
|
|
|
|
|
{
|
|
|
|
|
/*--- pickLineモードのとき、取得Styleが0の場合はカレントStyleを変えない。
|
|
|
|
|
* ---*/
|
|
|
|
|
if (styleId == 0) return;
|
|
|
|
|
|
|
|
|
|
/*---
|
|
|
|
|
* pickLineモードのとき、PurePaintの部分をクリックしてもカレントStyleを変えない
|
|
|
|
|
* ---*/
|
2019-10-11 16:13:41 +13:00
|
|
|
|
if (ti && picker.pickTone(TScale(1.0 / subsampling) * pos +
|
|
|
|
|
TPointD(-0.5, -0.5)) == 255)
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--- Styleを選択している場合は選択を解除する ---*/
|
|
|
|
|
TSelection *selection =
|
|
|
|
|
TTool::getApplication()->getCurrentSelection()->getSelection();
|
|
|
|
|
if (selection) {
|
|
|
|
|
TStyleSelection *styleSelection =
|
|
|
|
|
dynamic_cast<TStyleSelection *>(selection);
|
|
|
|
|
if (styleSelection) styleSelection->selectNone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getApplication()->setCurrentLevelStyleIndex(styleId);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|