2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "toonz/tpalettehandle.h"
|
|
|
|
|
#include "tools/toolhandle.h"
|
2019-12-25 17:04:57 +13:00
|
|
|
|
#include "tools/toolcommandids.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
#include "toonz/tobjecthandle.h"
|
|
|
|
|
#include "toonz/txsheethandle.h"
|
|
|
|
|
#include "toonz/txshlevelhandle.h"
|
|
|
|
|
#include "toonz/tframehandle.h"
|
|
|
|
|
#include "tools/tool.h"
|
|
|
|
|
#include "tcolorstyles.h"
|
|
|
|
|
#include "tpalette.h"
|
|
|
|
|
#include "tools/toolutils.h"
|
|
|
|
|
#include "tstroke.h"
|
|
|
|
|
#include "tmathutil.h"
|
|
|
|
|
#include "tools/cursors.h"
|
|
|
|
|
#include "tproperty.h"
|
|
|
|
|
#include "ttoonzimage.h"
|
|
|
|
|
#include "drawutil.h"
|
|
|
|
|
#include "tvectorimage.h"
|
|
|
|
|
#include "tenv.h"
|
|
|
|
|
#include "bluredbrush.h"
|
|
|
|
|
#include "toonz/ttileset.h"
|
|
|
|
|
#include "toonz/toonzimageutils.h"
|
|
|
|
|
#include "toonz/tstageobject.h"
|
|
|
|
|
#include "toonz/tstageobjectspline.h"
|
|
|
|
|
#include "toonzqt/imageutils.h"
|
|
|
|
|
#include "toonzqt/dvdialog.h"
|
|
|
|
|
#include "toonz/trasterimageutils.h"
|
|
|
|
|
#include "toonz/preferences.h"
|
|
|
|
|
#include "historytypes.h"
|
2019-12-25 17:04:57 +13:00
|
|
|
|
#include "toonzvectorbrushtool.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
// For Qt translation support
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
|
|
using namespace ToolUtils;
|
|
|
|
|
|
|
|
|
|
class GeometricTool;
|
|
|
|
|
class MultiLinePrimitive;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
class MultiArcPrimitive;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
TEnv::DoubleVar GeometricSize("InknpaintGeometricSize", 1);
|
|
|
|
|
TEnv::DoubleVar GeometricRasterSize("InknpaintGeometricRasterSize", 1);
|
|
|
|
|
TEnv::StringVar GeometricType("InknpaintGeometricType", "Rectangle");
|
|
|
|
|
TEnv::IntVar GeometricEdgeCount("InknpaintGeometricEdgeCount", 3);
|
|
|
|
|
TEnv::IntVar GeometricSelective("InknpaintGeometricSelective", 0);
|
|
|
|
|
TEnv::IntVar GeometricGroupIt("InknpaintGeometricGroupIt", 0);
|
|
|
|
|
TEnv::IntVar GeometricAutofill("InknpaintGeometricAutofill", 0);
|
2020-07-06 17:32:52 +12:00
|
|
|
|
TEnv::IntVar GeometricSmooth("InknpaintGeometricSmooth", 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
TEnv::IntVar GeometricPencil("InknpaintGeometricPencil", 0);
|
|
|
|
|
TEnv::DoubleVar GeometricBrushHardness("InknpaintGeometricHardness", 100);
|
|
|
|
|
TEnv::DoubleVar GeometricOpacity("InknpaintGeometricOpacity", 100);
|
|
|
|
|
TEnv::IntVar GeometricCapStyle("InknpaintGeometricCapStyle", 0);
|
|
|
|
|
TEnv::IntVar GeometricJoinStyle("InknpaintGeometricJoinStyle", 0);
|
|
|
|
|
TEnv::IntVar GeometricMiterValue("InknpaintGeometricMiterValue", 4);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TEnv::IntVar GeometricSnap("InknpaintGeometricSnap", 0);
|
|
|
|
|
TEnv::IntVar GeometricSnapSensitivity("InknpaintGeometricSnapSensitivity", 0);
|
2020-09-23 15:04:03 +12:00
|
|
|
|
TEnv::IntVar GeometricDrawBehind("InknpaintGeometricDrawBehind", 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#define ROUNDC_WSTR L"round_cap"
|
|
|
|
|
#define BUTT_WSTR L"butt_cap"
|
|
|
|
|
#define PROJECTING_WSTR L"projecting_cap"
|
|
|
|
|
#define ROUNDJ_WSTR L"round_join"
|
|
|
|
|
#define BEVEL_WSTR L"bevel_join"
|
|
|
|
|
#define MITER_WSTR L"miter_join"
|
2017-08-23 00:11:38 +12:00
|
|
|
|
#define LOW_WSTR L"Low"
|
|
|
|
|
#define MEDIUM_WSTR L"Medium"
|
|
|
|
|
#define HIGH_WSTR L"High"
|
|
|
|
|
|
|
|
|
|
const double SNAPPING_LOW = 5.0;
|
|
|
|
|
const double SNAPPING_MEDIUM = 25.0;
|
|
|
|
|
const double SNAPPING_HIGH = 100.0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Utility Functions
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-07-22 16:38:33 +12:00
|
|
|
|
static TPointD rectify(const TPointD &oldPos, const TPointD &pos) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
const double h = sqrt(2.0) / 2.0;
|
|
|
|
|
const TPointD directions[] = {TPointD(1, 0), TPointD(h, h), TPointD(0, 1),
|
|
|
|
|
TPointD(-h, h), TPointD(-1, 0), TPointD(-h, -h),
|
|
|
|
|
TPointD(0, -1), TPointD(h, -h)};
|
2020-09-23 15:04:03 +12:00
|
|
|
|
TPointD v = pos - oldPos;
|
|
|
|
|
int j = 0;
|
|
|
|
|
double bestValue = v * directions[j];
|
2016-06-15 18:43:10 +12:00
|
|
|
|
for (int k = 1; k < 8; k++) {
|
|
|
|
|
double value = v * directions[k];
|
|
|
|
|
if (value > bestValue) {
|
|
|
|
|
bestValue = value;
|
|
|
|
|
j = k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return oldPos + bestValue * directions[j];
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-07-22 16:38:33 +12:00
|
|
|
|
static TPointD computeSpeed(TPointD p0, TPointD p1, double factor) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPointD d = p1 - p0;
|
|
|
|
|
return (d == TPointD()) ? TPointD() : d * (factor / norm(d));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-08-04 19:23:36 +12:00
|
|
|
|
static TRect drawBluredBrush(const TRasterImageP &ri, TStroke *stroke,
|
|
|
|
|
int thick, double hardness, double opacity) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *s = new TStroke(*stroke);
|
|
|
|
|
TPointD riCenter = ri->getRaster()->getCenterD();
|
|
|
|
|
s->transform(TTranslation(riCenter));
|
|
|
|
|
int styleId = s->getStyle();
|
|
|
|
|
TPalette *plt = ri->getPalette();
|
|
|
|
|
TPixel32 color = plt->getStyle(styleId)->getMainColor();
|
|
|
|
|
|
|
|
|
|
TRectD bbox = s->getBBox();
|
|
|
|
|
TRect bboxI = convert(bbox).enlarge(1);
|
|
|
|
|
TRect rectRender = bboxI * ri->getRaster()->getBounds();
|
|
|
|
|
if (rectRender.isEmpty()) return TRect();
|
|
|
|
|
|
|
|
|
|
TRaster32P workRas(ri->getRaster()->getSize());
|
|
|
|
|
TRaster32P backupRas = ri->getRaster()->clone();
|
|
|
|
|
workRas->clear();
|
|
|
|
|
QRadialGradient brushPad = ToolUtils::getBrushPad(thick, hardness);
|
|
|
|
|
BluredBrush brush(workRas, thick, brushPad, false);
|
|
|
|
|
|
|
|
|
|
int i, chunkCount = s->getChunkCount();
|
|
|
|
|
for (i = 0; i < chunkCount; i++) {
|
|
|
|
|
const TThickQuadratic *q = s->getChunk(i);
|
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
|
points.push_back(q->getThickP0());
|
|
|
|
|
points.push_back(q->getThickP1());
|
|
|
|
|
points.push_back(q->getThickP2());
|
|
|
|
|
// i punti contenuti nello stroke sembra che haano la tickness pari al
|
|
|
|
|
// raggio e non al diametro del punto!
|
|
|
|
|
points[0].thick *= 2;
|
|
|
|
|
points[1].thick *= 2;
|
|
|
|
|
points[2].thick *= 2;
|
|
|
|
|
TRect chunkBox = brush.getBoundFromPoints(points);
|
|
|
|
|
brush.addArc(points[0], points[1], points[2], 1, 1);
|
|
|
|
|
brush.updateDrawing(ri->getRaster(), backupRas, color, chunkBox, opacity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete s;
|
|
|
|
|
return rectRender;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-07-22 16:38:33 +12:00
|
|
|
|
static TRect drawBluredBrush(const TToonzImageP &ti, TStroke *stroke, int thick,
|
|
|
|
|
double hardness, bool selective) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *s = new TStroke(*stroke);
|
|
|
|
|
TPointD riCenter = ti->getRaster()->getCenterD();
|
|
|
|
|
s->transform(TTranslation(riCenter));
|
|
|
|
|
int styleId = s->getStyle();
|
|
|
|
|
|
|
|
|
|
TRectD bbox = s->getBBox();
|
|
|
|
|
TRect bboxI = convert(bbox).enlarge(1);
|
|
|
|
|
TRect rectRender = bboxI * ti->getRaster()->getBounds();
|
|
|
|
|
if (rectRender.isEmpty()) return TRect();
|
|
|
|
|
|
|
|
|
|
TRaster32P workRas(ti->getRaster()->getSize());
|
|
|
|
|
TRasterCM32P backupRas = ti->getRaster()->clone();
|
|
|
|
|
workRas->clear();
|
|
|
|
|
QRadialGradient brushPad = ToolUtils::getBrushPad(thick, hardness);
|
|
|
|
|
BluredBrush brush(workRas, thick, brushPad, false);
|
|
|
|
|
|
|
|
|
|
int i, chunkCount = s->getChunkCount();
|
|
|
|
|
for (i = 0; i < chunkCount; i++) {
|
|
|
|
|
const TThickQuadratic *q = s->getChunk(i);
|
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
|
points.push_back(q->getThickP0());
|
|
|
|
|
points.push_back(q->getThickP1());
|
|
|
|
|
points.push_back(q->getThickP2());
|
|
|
|
|
// i punti contenuti nello stroke sembra che haano la tickness pari al
|
|
|
|
|
// raggio e non al diametro del punto!
|
|
|
|
|
points[0].thick *= 2;
|
|
|
|
|
points[1].thick *= 2;
|
|
|
|
|
points[2].thick *= 2;
|
|
|
|
|
TRect chunkBox = brush.getBoundFromPoints(points);
|
|
|
|
|
brush.addArc(points[0], points[1], points[2], 1, 1);
|
|
|
|
|
brush.updateDrawing(ti->getRaster(), backupRas, chunkBox, styleId,
|
|
|
|
|
selective);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete s;
|
|
|
|
|
return rectRender;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class MultilinePrimitiveUndo final : public TUndo {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
std::vector<TPointD> m_oldVertex;
|
|
|
|
|
std::vector<TPointD> m_newVertex;
|
|
|
|
|
MultiLinePrimitive *m_tool;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
MultilinePrimitiveUndo(const std::vector<TPointD> &vertex,
|
|
|
|
|
MultiLinePrimitive *tool)
|
|
|
|
|
: TUndo(), m_oldVertex(vertex), m_tool(tool), m_newVertex() {}
|
|
|
|
|
|
|
|
|
|
~MultilinePrimitiveUndo() {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void undo() const override;
|
|
|
|
|
void redo() const override;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void setNewVertex(const std::vector<TPointD> &vertex) {
|
|
|
|
|
m_newVertex = vertex;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
int getSize() const override { return sizeof(this); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
QString getToolName();
|
2016-06-19 20:06:29 +12:00
|
|
|
|
int getHistoryType() override { return HistoryType::GeometricTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
class MultiArcPrimitiveUndoData {
|
|
|
|
|
private:
|
|
|
|
|
TStroke *m_stroke;
|
|
|
|
|
TStroke *m_strokeTemp;
|
|
|
|
|
TPointD m_startPoint, m_endPoint, m_centralPoint;
|
|
|
|
|
int m_clickNumber;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
MultiArcPrimitiveUndoData(TStroke *stroke, TStroke *strokeTemp,
|
|
|
|
|
TPointD startPoint, TPointD endPoint,
|
|
|
|
|
TPointD centralPoint, int clickNumber)
|
|
|
|
|
: m_stroke(0)
|
|
|
|
|
, m_strokeTemp(0)
|
|
|
|
|
, m_startPoint(startPoint)
|
|
|
|
|
, m_endPoint(endPoint)
|
|
|
|
|
, m_centralPoint(centralPoint)
|
|
|
|
|
, m_clickNumber(clickNumber) {
|
|
|
|
|
if (stroke) {
|
|
|
|
|
m_stroke = new TStroke(*stroke);
|
|
|
|
|
}
|
|
|
|
|
if (strokeTemp) {
|
|
|
|
|
m_strokeTemp = new TStroke(*strokeTemp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~MultiArcPrimitiveUndoData() {
|
|
|
|
|
delete m_stroke;
|
|
|
|
|
delete m_strokeTemp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void replace(MultiArcPrimitive *tool) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class MultiArcPrimitiveUndo final : public TUndo {
|
|
|
|
|
MultiArcPrimitive *m_tool;
|
|
|
|
|
MultiArcPrimitiveUndoData m_undo;
|
|
|
|
|
MultiArcPrimitiveUndoData *m_redo;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
MultiArcPrimitiveUndo(MultiArcPrimitive *tool, TStroke *stroke,
|
|
|
|
|
TStroke *strokeTemp, TPointD startPoint,
|
|
|
|
|
TPointD endPoint, TPointD centralPoint, int clickNumber)
|
|
|
|
|
: TUndo()
|
|
|
|
|
, m_tool(tool)
|
|
|
|
|
, m_undo(stroke, strokeTemp, startPoint, endPoint, centralPoint,
|
|
|
|
|
clickNumber)
|
|
|
|
|
, m_redo(0) {}
|
|
|
|
|
|
|
|
|
|
~MultiArcPrimitiveUndo() { delete m_redo; }
|
|
|
|
|
|
|
|
|
|
void setRedoData(TStroke *stroke, TStroke *strokeTemp, TPointD startPoint,
|
|
|
|
|
TPointD endPoint, TPointD centralPoint, int clickNumber) {
|
|
|
|
|
m_redo = new MultiArcPrimitiveUndoData(stroke, strokeTemp, startPoint,
|
|
|
|
|
endPoint, centralPoint, clickNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void undo() const override;
|
|
|
|
|
void redo() const override;
|
|
|
|
|
|
|
|
|
|
int getSize() const override { return sizeof(this); }
|
|
|
|
|
|
|
|
|
|
QString getToolName();
|
|
|
|
|
int getHistoryType() override { return HistoryType::GeometricTool; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class FullColorBluredPrimitiveUndo final : public UndoFullColorPencil {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
int m_thickness;
|
|
|
|
|
double m_hardness;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
FullColorBluredPrimitiveUndo(TXshSimpleLevel *level, const TFrameId &frameId,
|
|
|
|
|
TStroke *stroke, int thickness, double hardness,
|
|
|
|
|
double opacity, bool doAntialias,
|
|
|
|
|
bool createdFrame, bool createdLevel)
|
|
|
|
|
: UndoFullColorPencil(level, frameId, stroke, opacity, doAntialias,
|
|
|
|
|
createdFrame, createdLevel)
|
|
|
|
|
, m_thickness(thickness)
|
|
|
|
|
, m_hardness(hardness) {
|
|
|
|
|
TRasterP raster = getImage()->getRaster();
|
|
|
|
|
TDimension d = raster->getSize();
|
|
|
|
|
m_tiles = new TTileSetFullColor(d);
|
|
|
|
|
TRect rect = convert(stroke->getBBox()) +
|
|
|
|
|
TPoint((int)(d.lx * 0.5), (int)(d.ly * 0.5));
|
|
|
|
|
m_tiles->add(raster, rect.enlarge(2));
|
|
|
|
|
m_stroke = new TStroke(*stroke);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~FullColorBluredPrimitiveUndo() {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void redo() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
insertLevelAndFrameIfNeeded();
|
|
|
|
|
TRasterImageP ri = getImage();
|
|
|
|
|
if (!ri) return;
|
|
|
|
|
drawBluredBrush(ri, m_stroke, m_thickness, m_hardness, m_opacity);
|
|
|
|
|
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
|
|
|
notifyImageChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
|
int getSize() const override {
|
|
|
|
|
return UndoFullColorPencil::getSize() + sizeof(this);
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
/*-- Hardness<100 のときの GeometricToolのUndo --*/
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class CMBluredPrimitiveUndo final : public UndoRasterPencil {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
int m_thickness;
|
|
|
|
|
double m_hardness;
|
|
|
|
|
bool m_selective;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
CMBluredPrimitiveUndo(TXshSimpleLevel *level, const TFrameId &frameId,
|
|
|
|
|
TStroke *stroke, int thickness, double hardness,
|
|
|
|
|
bool selective, bool doAntialias, bool createdFrame,
|
|
|
|
|
bool createdLevel, std::string primitiveName)
|
|
|
|
|
: UndoRasterPencil(level, frameId, stroke, selective, false, doAntialias,
|
|
|
|
|
createdFrame, createdLevel, primitiveName)
|
|
|
|
|
, m_thickness(thickness)
|
|
|
|
|
, m_hardness(hardness)
|
|
|
|
|
, m_selective(selective) {
|
|
|
|
|
TRasterCM32P raster = getImage()->getRaster();
|
|
|
|
|
TDimension d = raster->getSize();
|
|
|
|
|
m_tiles = new TTileSetCM32(d);
|
|
|
|
|
TRect rect = convert(stroke->getBBox()) +
|
|
|
|
|
TPoint((int)(d.lx * 0.5), (int)(d.ly * 0.5));
|
|
|
|
|
m_tiles->add(raster, rect.enlarge(2));
|
|
|
|
|
m_stroke = new TStroke(*stroke);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CMBluredPrimitiveUndo() {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void redo() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
insertLevelAndFrameIfNeeded();
|
|
|
|
|
TToonzImageP ti = getImage();
|
|
|
|
|
if (!ti) return;
|
|
|
|
|
drawBluredBrush(ti, m_stroke, m_thickness, m_hardness, m_selective);
|
|
|
|
|
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
|
|
|
notifyImageChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
|
int getSize() const override {
|
|
|
|
|
return UndoRasterPencil::getSize() + sizeof(this);
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
class PrimitiveParam {
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(PrimitiveParam)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TDoubleProperty m_toolSize;
|
|
|
|
|
TIntProperty m_rasterToolSize;
|
|
|
|
|
TDoubleProperty m_opacity;
|
|
|
|
|
TDoubleProperty m_hardness;
|
|
|
|
|
TEnumProperty m_type;
|
|
|
|
|
TIntProperty m_edgeCount;
|
|
|
|
|
TBoolProperty m_autogroup;
|
|
|
|
|
TBoolProperty m_autofill;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
TBoolProperty m_smooth;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TBoolProperty m_selective;
|
|
|
|
|
TBoolProperty m_pencil;
|
|
|
|
|
TEnumProperty m_capStyle;
|
|
|
|
|
TEnumProperty m_joinStyle;
|
|
|
|
|
TIntProperty m_miterJoinLimit;
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TBoolProperty m_snap;
|
|
|
|
|
TEnumProperty m_snapSensitivity;
|
2020-09-23 15:04:03 +12:00
|
|
|
|
TBoolProperty m_sendToBack;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPropertyGroup m_prop[2];
|
|
|
|
|
|
|
|
|
|
int m_targetType;
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
// for snapping
|
|
|
|
|
int m_strokeIndex1;
|
|
|
|
|
double m_w1, m_pixelSize, m_currThickness, m_minDistance2;
|
|
|
|
|
bool m_foundSnap = false;
|
|
|
|
|
TPointD m_snapPoint;
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
PrimitiveParam(int targetType)
|
|
|
|
|
: m_type("Shape:") // "W_ToolOptions_ShapeType")
|
|
|
|
|
, m_toolSize("Size:", 0, 100,
|
|
|
|
|
1) // "W_ToolOptions_ShapeThickness", 0,30,1)
|
|
|
|
|
, m_rasterToolSize("Size:", 1, 100, 1)
|
|
|
|
|
, m_opacity("Opacity:", 0, 100, 100)
|
|
|
|
|
, m_hardness("Hardness:", 0, 100, 100)
|
|
|
|
|
, m_edgeCount("Polygon Sides:", 3, 15, 3)
|
|
|
|
|
, m_autogroup("Auto Group", false)
|
|
|
|
|
, m_autofill("Auto Fill", false)
|
2020-07-06 17:32:52 +12:00
|
|
|
|
, m_smooth("Smooth", false)
|
2016-06-15 18:43:10 +12:00
|
|
|
|
, m_selective("Selective", false)
|
|
|
|
|
, m_pencil("Pencil Mode", false)
|
|
|
|
|
, m_capStyle("Cap")
|
|
|
|
|
, m_joinStyle("Join")
|
|
|
|
|
, m_miterJoinLimit("Miter:", 0, 100, 4)
|
2017-08-23 00:11:38 +12:00
|
|
|
|
, m_snap("Snap", false)
|
|
|
|
|
, m_snapSensitivity("Sensitivity:")
|
2020-09-23 15:04:03 +12:00
|
|
|
|
, m_sendToBack("Draw Under", 0)
|
2016-06-15 18:43:10 +12:00
|
|
|
|
, m_targetType(targetType) {
|
|
|
|
|
if (targetType & TTool::Vectors) m_prop[0].bind(m_toolSize);
|
|
|
|
|
if (targetType & TTool::ToonzImage || targetType & TTool::RasterImage) {
|
|
|
|
|
m_prop[0].bind(m_rasterToolSize);
|
|
|
|
|
m_prop[0].bind(m_hardness);
|
|
|
|
|
}
|
|
|
|
|
if (targetType & TTool::RasterImage) m_prop[0].bind(m_opacity);
|
|
|
|
|
m_prop[0].bind(m_type);
|
|
|
|
|
|
|
|
|
|
m_prop[0].bind(m_edgeCount);
|
|
|
|
|
if (targetType & TTool::Vectors) {
|
|
|
|
|
m_prop[0].bind(m_autogroup);
|
|
|
|
|
m_prop[0].bind(m_autofill);
|
2020-09-23 15:04:03 +12:00
|
|
|
|
m_prop[0].bind(m_sendToBack);
|
|
|
|
|
m_sendToBack.setId("DrawUnder");
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_prop[0].bind(m_snap);
|
|
|
|
|
m_snap.setId("Snap");
|
|
|
|
|
m_prop[0].bind(m_snapSensitivity);
|
2018-04-26 21:24:25 +12:00
|
|
|
|
m_snapSensitivity.addValue(LOW_WSTR);
|
|
|
|
|
m_snapSensitivity.addValue(MEDIUM_WSTR);
|
|
|
|
|
m_snapSensitivity.addValue(HIGH_WSTR);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_snapSensitivity.setId("SnapSensitivity");
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
if (targetType & TTool::ToonzImage) {
|
|
|
|
|
m_prop[0].bind(m_selective);
|
|
|
|
|
m_prop[0].bind(m_pencil);
|
|
|
|
|
m_pencil.setId("PencilMode");
|
|
|
|
|
}
|
2020-07-06 18:23:39 +12:00
|
|
|
|
m_prop[0].bind(m_smooth);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2018-04-26 21:24:25 +12:00
|
|
|
|
m_capStyle.addValue(BUTT_WSTR, QString::fromStdWString(BUTT_WSTR));
|
|
|
|
|
m_capStyle.addValue(ROUNDC_WSTR, QString::fromStdWString(ROUNDC_WSTR));
|
|
|
|
|
m_capStyle.addValue(PROJECTING_WSTR,
|
|
|
|
|
QString::fromStdWString(PROJECTING_WSTR));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_capStyle.setId("Cap");
|
|
|
|
|
|
2018-04-26 21:24:25 +12:00
|
|
|
|
m_joinStyle.addValue(MITER_WSTR, QString::fromStdWString(MITER_WSTR));
|
|
|
|
|
m_joinStyle.addValue(ROUNDJ_WSTR, QString::fromStdWString(ROUNDJ_WSTR));
|
|
|
|
|
m_joinStyle.addValue(BEVEL_WSTR, QString::fromStdWString(BEVEL_WSTR));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_joinStyle.setId("Join");
|
|
|
|
|
|
|
|
|
|
m_miterJoinLimit.setId("Miter");
|
|
|
|
|
|
|
|
|
|
m_prop[1].bind(m_capStyle);
|
|
|
|
|
m_prop[1].bind(m_joinStyle);
|
|
|
|
|
m_prop[1].bind(m_miterJoinLimit);
|
|
|
|
|
|
|
|
|
|
m_selective.setId("Selective");
|
|
|
|
|
m_autogroup.setId("AutoGroup");
|
|
|
|
|
m_autofill.setId("Autofill");
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_smooth.setId("Smooth");
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_type.setId("GeometricShape");
|
|
|
|
|
m_edgeCount.setId("GeometricEdge");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateTranslation() {
|
|
|
|
|
m_type.setQStringName(tr("Shape:"));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
m_type.setItemUIName(L"Rectangle", tr("Rectangle"));
|
|
|
|
|
m_type.setItemUIName(L"Circle", tr("Circle"));
|
|
|
|
|
m_type.setItemUIName(L"Ellipse", tr("Ellipse"));
|
|
|
|
|
m_type.setItemUIName(L"Line", tr("Line"));
|
|
|
|
|
m_type.setItemUIName(L"Polyline", tr("Polyline"));
|
|
|
|
|
m_type.setItemUIName(L"Arc", tr("Arc"));
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_type.setItemUIName(L"MultiArc", tr("MultiArc"));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
m_type.setItemUIName(L"Polygon", tr("Polygon"));
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_toolSize.setQStringName(tr("Size:"));
|
|
|
|
|
m_rasterToolSize.setQStringName(tr("Thickness:"));
|
|
|
|
|
m_opacity.setQStringName(tr("Opacity:"));
|
|
|
|
|
m_hardness.setQStringName(tr("Hardness:"));
|
|
|
|
|
m_edgeCount.setQStringName(tr("Polygon Sides:"));
|
|
|
|
|
m_autogroup.setQStringName(tr("Auto Group"));
|
|
|
|
|
m_autofill.setQStringName(tr("Auto Fill"));
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_smooth.setQStringName(tr("Smooth"));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_selective.setQStringName(tr("Selective"));
|
|
|
|
|
m_pencil.setQStringName(tr("Pencil Mode"));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_capStyle.setQStringName(tr("Cap"));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
m_capStyle.setItemUIName(BUTT_WSTR, tr("Butt cap"));
|
|
|
|
|
m_capStyle.setItemUIName(ROUNDC_WSTR, tr("Round cap"));
|
|
|
|
|
m_capStyle.setItemUIName(PROJECTING_WSTR, tr("Projecting cap"));
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_joinStyle.setQStringName(tr("Join"));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
m_joinStyle.setItemUIName(MITER_WSTR, tr("Miter join"));
|
|
|
|
|
m_joinStyle.setItemUIName(ROUNDJ_WSTR, tr("Round join"));
|
|
|
|
|
m_joinStyle.setItemUIName(BEVEL_WSTR, tr("Bevel join"));
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_miterJoinLimit.setQStringName(tr("Miter:"));
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_snap.setQStringName(tr("Snap"));
|
|
|
|
|
m_snapSensitivity.setQStringName(tr(""));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
if (m_targetType & TTool::Vectors) {
|
|
|
|
|
m_snapSensitivity.setItemUIName(LOW_WSTR, tr("Low"));
|
|
|
|
|
m_snapSensitivity.setItemUIName(MEDIUM_WSTR, tr("Med"));
|
|
|
|
|
m_snapSensitivity.setItemUIName(HIGH_WSTR, tr("High"));
|
2020-09-23 15:04:03 +12:00
|
|
|
|
m_sendToBack.setQStringName(tr("Draw Under"));
|
2018-04-26 21:24:25 +12:00
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Abstract Class Primitive
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
class Primitive {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
protected:
|
2020-10-06 03:11:08 +13:00
|
|
|
|
bool m_isEditing, m_rasterTool, m_isPrompting, m_doSnap;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
GeometricTool *m_tool;
|
|
|
|
|
PrimitiveParam *m_param;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Primitive(PrimitiveParam *param, GeometricTool *tool, bool rasterTool)
|
|
|
|
|
: m_param(param)
|
|
|
|
|
, m_tool(tool)
|
|
|
|
|
, m_isEditing(false)
|
|
|
|
|
, m_rasterTool(rasterTool)
|
|
|
|
|
, m_isPrompting(false) {}
|
|
|
|
|
|
|
|
|
|
double getThickness() const {
|
|
|
|
|
if (m_rasterTool)
|
|
|
|
|
return m_param->m_rasterToolSize.getValue() * 0.5;
|
|
|
|
|
else
|
|
|
|
|
return m_param->m_toolSize.getValue() * 0.5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setIsPrompting(bool value) { m_isPrompting = value; }
|
|
|
|
|
|
|
|
|
|
virtual std::string getName() const = 0;
|
|
|
|
|
|
|
|
|
|
virtual ~Primitive() {}
|
|
|
|
|
|
|
|
|
|
virtual void leftButtonDown(const TPointD &p, const TMouseEvent &e){};
|
|
|
|
|
virtual void leftButtonDrag(const TPointD &p, const TMouseEvent &e){};
|
|
|
|
|
virtual void leftButtonUp(const TPointD &p, const TMouseEvent &e){};
|
|
|
|
|
virtual void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e){};
|
|
|
|
|
virtual void rightButtonDown(const TPointD &p, const TMouseEvent &e){};
|
|
|
|
|
virtual void mouseMove(const TPointD &p, const TMouseEvent &e){};
|
2018-02-19 19:34:13 +13:00
|
|
|
|
virtual bool keyDown(QKeyEvent *event) { return false; }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
virtual void onEnter(){};
|
|
|
|
|
virtual void draw(){};
|
|
|
|
|
virtual void onActivate(){};
|
|
|
|
|
virtual void onDeactivate(){};
|
|
|
|
|
virtual void onImageChanged(){};
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD calculateSnap(TPointD pos, const TMouseEvent &e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
void drawSnap();
|
|
|
|
|
TPointD getSnap(TPointD pos);
|
|
|
|
|
void resetSnap();
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD checkGuideSnapping(TPointD pos, const TMouseEvent &e);
|
2020-07-06 17:32:52 +12:00
|
|
|
|
bool getSmooth() { return m_param->m_smooth.getValue(); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
virtual TStroke *makeStroke() const = 0;
|
2021-03-28 21:34:35 +13:00
|
|
|
|
virtual bool canTouchImageOnPreLeftClick() { return true; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void Primitive::resetSnap() {
|
|
|
|
|
m_param->m_strokeIndex1 = -1;
|
|
|
|
|
m_param->m_w1 = -1;
|
|
|
|
|
m_param->m_foundSnap = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD Primitive::calculateSnap(TPointD pos, const TMouseEvent &e) {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_param->m_foundSnap = false;
|
|
|
|
|
if (Preferences::instance()->getVectorSnappingTarget() == 1) return pos;
|
|
|
|
|
TVectorImageP vi(TTool::getImage(false));
|
|
|
|
|
TPointD snapPoint = pos;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
m_doSnap = (m_param->m_snap.getValue() &&
|
|
|
|
|
!(e.isCtrlPressed() && e.isShiftPressed())) ||
|
|
|
|
|
(!m_param->m_snap.getValue() &&
|
|
|
|
|
(e.isCtrlPressed() && e.isShiftPressed()));
|
|
|
|
|
if (vi && m_doSnap) {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
double minDistance2 = m_param->m_minDistance2;
|
|
|
|
|
m_param->m_strokeIndex1 = -1;
|
|
|
|
|
|
|
|
|
|
int i, strokeNumber = vi->getStrokeCount();
|
|
|
|
|
|
|
|
|
|
TStroke *stroke;
|
|
|
|
|
double distance2, outW;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < strokeNumber; i++) {
|
|
|
|
|
stroke = vi->getStroke(i);
|
|
|
|
|
if (stroke->getNearestW(pos, outW, distance2) &&
|
|
|
|
|
distance2 < minDistance2) {
|
|
|
|
|
minDistance2 = distance2;
|
|
|
|
|
m_param->m_strokeIndex1 = i;
|
|
|
|
|
if (areAlmostEqual(outW, 0.0, 1e-3))
|
|
|
|
|
m_param->m_w1 = 0.0;
|
|
|
|
|
else if (areAlmostEqual(outW, 1.0, 1e-3))
|
|
|
|
|
m_param->m_w1 = 1.0;
|
|
|
|
|
else
|
2020-09-23 15:04:03 +12:00
|
|
|
|
m_param->m_w1 = outW;
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TThickPoint point1 = stroke->getPoint(m_param->m_w1);
|
|
|
|
|
snapPoint = TPointD(point1.x, point1.y);
|
|
|
|
|
m_param->m_foundSnap = true;
|
|
|
|
|
m_param->m_snapPoint = snapPoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return snapPoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
TPointD Primitive::getSnap(TPointD pos) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if (m_doSnap && m_param->m_foundSnap)
|
2017-08-23 00:11:38 +12:00
|
|
|
|
return m_param->m_snapPoint;
|
|
|
|
|
else
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Primitive::drawSnap and Primitive::checkGuideSnapping are below the
|
|
|
|
|
// Geometric Tool definition since they use the m_tool property of Primitive
|
|
|
|
|
// but it isn't defined yet up here.
|
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//=============================================================================
|
|
|
|
|
// Rectangle Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class RectanglePrimitive final : public Primitive {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TRectD m_selectingRect;
|
|
|
|
|
TPointD m_pos;
|
|
|
|
|
TPointD m_startPoint;
|
|
|
|
|
TPixel32 m_color;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
RectanglePrimitive(PrimitiveParam *param, GeometricTool *tool,
|
|
|
|
|
bool reasterTool)
|
|
|
|
|
: Primitive(param, tool, reasterTool) {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
std::string getName() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return "Rectangle";
|
|
|
|
|
} // W_ToolOptions_ShapeRect"; }
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
TStroke *makeStroke() const override;
|
|
|
|
|
void draw() override;
|
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void leftButtonDrag(const TPointD &realPos, const TMouseEvent &e) override;
|
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void onEnter() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Circle Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class CirclePrimitive final : public Primitive {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPointD m_centre;
|
|
|
|
|
TPointD m_pos;
|
|
|
|
|
double m_radius;
|
|
|
|
|
TPixel32 m_color;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
CirclePrimitive(PrimitiveParam *param, GeometricTool *tool, bool reasterTool)
|
|
|
|
|
: Primitive(param, tool, reasterTool) {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
std::string getName() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return "Circle";
|
|
|
|
|
} // W_ToolOptions_ShapeCircle";}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void draw() override;
|
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
TStroke *makeStroke() const override;
|
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void onEnter() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// MultiLine Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const double joinDistance = 5.0;
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
class MultiLinePrimitive : public Primitive {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
std::vector<TPointD> m_vertex;
|
|
|
|
|
TPointD m_mousePosition;
|
|
|
|
|
TPixel32 m_color;
|
|
|
|
|
bool m_closed, m_isSingleLine;
|
|
|
|
|
bool m_speedMoved; //!< True after moveSpeed(), false after addVertex()
|
|
|
|
|
bool m_beforeSpeedMoved; //!< Old value of m_speedMoved
|
|
|
|
|
bool m_ctrlDown; //!< Whether ctrl is hold down
|
|
|
|
|
MultilinePrimitiveUndo *m_undo;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
MultiLinePrimitive(PrimitiveParam *param, GeometricTool *tool,
|
|
|
|
|
bool reasterTool)
|
|
|
|
|
: Primitive(param, tool, reasterTool)
|
|
|
|
|
, m_closed(false)
|
|
|
|
|
, m_isSingleLine(false)
|
|
|
|
|
, m_speedMoved(false)
|
|
|
|
|
, m_beforeSpeedMoved(false)
|
|
|
|
|
, m_ctrlDown(false) {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
std::string getName() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return "Polyline";
|
|
|
|
|
} // W_ToolOptions_ShapePolyline";}
|
|
|
|
|
|
|
|
|
|
void addVertex(const TPointD &pos);
|
|
|
|
|
void moveSpeed(const TPointD &delta);
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void draw() override;
|
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) override;
|
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
2018-02-19 19:34:13 +13:00
|
|
|
|
bool keyDown(QKeyEvent *event) override;
|
2016-06-19 20:06:29 +12:00
|
|
|
|
TStroke *makeStroke() const override;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void endLine();
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void onActivate() override;
|
|
|
|
|
void onDeactivate() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_vertex.clear();
|
|
|
|
|
m_speedMoved = false;
|
|
|
|
|
m_beforeSpeedMoved = false;
|
|
|
|
|
}
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void onEnter() override;
|
|
|
|
|
void onImageChanged() override;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void setVertexes(const std::vector<TPointD> &vertex) { m_vertex = vertex; };
|
|
|
|
|
void setSpeedMoved(bool speedMoved) { m_speedMoved = speedMoved; };
|
2021-03-28 21:34:35 +13:00
|
|
|
|
|
|
|
|
|
// Only execute touchImage when clicking the first point of the polyline
|
|
|
|
|
bool canTouchImageOnPreLeftClick() override { return m_vertex.empty(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultilinePrimitiveUndo::undo() const {
|
|
|
|
|
m_tool->setVertexes(m_oldVertex);
|
|
|
|
|
int count = m_oldVertex.size();
|
|
|
|
|
bool speedMoved = (count != 0 && count % 4 != 1);
|
|
|
|
|
m_tool->setSpeedMoved(speedMoved);
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->getTool()->invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultilinePrimitiveUndo::redo() const {
|
|
|
|
|
m_tool->setVertexes(m_newVertex);
|
|
|
|
|
int count = m_newVertex.size();
|
|
|
|
|
bool speedMoved = (count != 0 && count % 4 != 1);
|
|
|
|
|
m_tool->setSpeedMoved(speedMoved);
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->getTool()->invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
QString MultilinePrimitiveUndo::getToolName() {
|
|
|
|
|
return QString("Geometric Tool %1")
|
|
|
|
|
.arg(QString::fromStdString(m_tool->getName()));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Line Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class LinePrimitive final : public MultiLinePrimitive {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
LinePrimitive(PrimitiveParam *param, GeometricTool *tool, bool reasterTool)
|
|
|
|
|
: MultiLinePrimitive(param, tool, reasterTool) {
|
|
|
|
|
m_isSingleLine = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
std::string getName() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return "Line";
|
|
|
|
|
} // W_ToolOptions_ShapePolyline";}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void draw() override;
|
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
|
2017-08-23 00:11:38 +12:00
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) override {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Ellipse Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class EllipsePrimitive final : public Primitive {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPointD m_pos;
|
|
|
|
|
TRectD m_selectingRect;
|
|
|
|
|
TPointD m_startPoint;
|
|
|
|
|
TPixel32 m_color;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
EllipsePrimitive(PrimitiveParam *param, GeometricTool *tool, bool reasterTool)
|
|
|
|
|
: Primitive(param, tool, reasterTool) {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
std::string getName() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return "Ellipse";
|
|
|
|
|
} // W_ToolOptions_ShapeEllipse";}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void draw() override;
|
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void leftButtonDrag(const TPointD &realPos, const TMouseEvent &e) override;
|
|
|
|
|
TStroke *makeStroke() const override;
|
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void onEnter() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
2020-07-06 17:32:52 +12:00
|
|
|
|
// Multi Arc Primitive Class Declaration
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
class MultiArcPrimitive : public Primitive {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *m_stroke;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
TStroke *m_strokeTemp;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPointD m_startPoint, m_endPoint, m_centralPoint;
|
|
|
|
|
int m_clickNumber;
|
|
|
|
|
TPixel32 m_color;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
int m_undoCount;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool m_isSingleArc;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2020-07-06 17:32:52 +12:00
|
|
|
|
MultiArcPrimitive(PrimitiveParam *param, GeometricTool *tool,
|
|
|
|
|
bool reasterTool)
|
|
|
|
|
: Primitive(param, tool, reasterTool)
|
|
|
|
|
, m_stroke(0)
|
|
|
|
|
, m_strokeTemp(0)
|
|
|
|
|
, m_clickNumber(0)
|
|
|
|
|
, m_isSingleArc(false)
|
|
|
|
|
, m_undoCount(0) {}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
~MultiArcPrimitive() { delete m_stroke; }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
std::string getName() const override { return "MultiArc"; }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
TStroke *makeStroke() const override;
|
|
|
|
|
void draw() override;
|
2021-03-29 15:11:27 +13:00
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
void leftButtonDoubleClick(const TPointD &, const TMouseEvent &e) override;
|
|
|
|
|
bool keyDown(QKeyEvent *event) override;
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void onEnter() override;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
void onDeactivate() override {
|
|
|
|
|
delete m_stroke;
|
|
|
|
|
delete m_strokeTemp;
|
|
|
|
|
m_stroke = 0;
|
|
|
|
|
m_strokeTemp = 0;
|
|
|
|
|
m_clickNumber = 0;
|
|
|
|
|
TUndoManager::manager()->popUndo(m_undoCount);
|
|
|
|
|
m_undoCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void replaceData(TStroke *stroke, TStroke *strokeTemp, TPointD startPoint,
|
|
|
|
|
TPointD endPoint, TPointD centralPoint, int clickNumber) {
|
|
|
|
|
delete m_stroke;
|
|
|
|
|
delete m_strokeTemp;
|
|
|
|
|
m_stroke = stroke;
|
|
|
|
|
m_strokeTemp = strokeTemp;
|
|
|
|
|
m_startPoint = startPoint;
|
|
|
|
|
m_endPoint = endPoint;
|
|
|
|
|
m_centralPoint = centralPoint;
|
|
|
|
|
m_clickNumber = clickNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void decreaseUndo() { --m_undoCount; }
|
|
|
|
|
|
|
|
|
|
void increaseUndo() { ++m_undoCount; }
|
2021-03-28 21:34:35 +13:00
|
|
|
|
|
|
|
|
|
// Only execute touchImage when clicking the first point of the multi arc
|
|
|
|
|
bool canTouchImageOnPreLeftClick() override { return m_clickNumber == 0; }
|
2020-07-06 17:32:52 +12:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void MultiArcPrimitiveUndoData::replace(MultiArcPrimitive *tool) const {
|
|
|
|
|
TStroke *stroke = 0;
|
|
|
|
|
TStroke *strokeTemp = 0;
|
|
|
|
|
if (m_stroke) {
|
|
|
|
|
stroke = new TStroke(*m_stroke);
|
|
|
|
|
}
|
|
|
|
|
if (m_strokeTemp) {
|
|
|
|
|
strokeTemp = new TStroke(*m_strokeTemp);
|
|
|
|
|
}
|
|
|
|
|
tool->replaceData(stroke, strokeTemp, m_startPoint, m_endPoint,
|
|
|
|
|
m_centralPoint, m_clickNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void MultiArcPrimitiveUndo::undo() const {
|
|
|
|
|
m_undo.replace(m_tool);
|
|
|
|
|
m_tool->decreaseUndo();
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->getTool()->invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void MultiArcPrimitiveUndo::redo() const {
|
|
|
|
|
m_redo->replace(m_tool);
|
|
|
|
|
m_tool->increaseUndo();
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->getTool()->invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QString MultiArcPrimitiveUndo::getToolName() {
|
|
|
|
|
return QString("Geometric Tool %1")
|
|
|
|
|
.arg(QString::fromStdString(m_tool->getName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Arc Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class ArcPrimitive final : public MultiArcPrimitive {
|
|
|
|
|
public:
|
|
|
|
|
ArcPrimitive(PrimitiveParam *param, GeometricTool *tool, bool reasterTool)
|
|
|
|
|
: MultiArcPrimitive(param, tool, reasterTool) {
|
|
|
|
|
m_isSingleArc = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string getName() const override {
|
|
|
|
|
return "Arc";
|
|
|
|
|
} // _ToolOptions_ShapeArc";}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Polygon Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class PolygonPrimitive final : public Primitive {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TPointD m_startPoint, m_centre;
|
|
|
|
|
double m_radius;
|
|
|
|
|
TPixel32 m_color;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
PolygonPrimitive(PrimitiveParam *param, GeometricTool *tool, bool reasterTool)
|
|
|
|
|
: Primitive(param, tool, reasterTool) {}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
std::string getName() const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return "Polygon";
|
|
|
|
|
} // W_ToolOptions_ShapePolygon";}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
TStroke *makeStroke() const override;
|
|
|
|
|
void draw() override;
|
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
|
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
|
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
2017-08-23 00:11:38 +12:00
|
|
|
|
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Geometric Tool
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class GeometricTool final : public TTool {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Primitive *m_primitive;
|
|
|
|
|
std::map<std::wstring, Primitive *> m_primitiveTable;
|
|
|
|
|
PrimitiveParam m_param;
|
|
|
|
|
std::wstring m_typeCode;
|
|
|
|
|
bool m_active;
|
|
|
|
|
bool m_firstTime;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
GeometricTool(int targetType)
|
|
|
|
|
: TTool("T_Geometric")
|
|
|
|
|
, m_primitive(0)
|
|
|
|
|
, m_param(targetType)
|
|
|
|
|
, m_active(false)
|
|
|
|
|
, m_firstTime(true) {
|
|
|
|
|
bind(targetType);
|
|
|
|
|
if ((targetType & TTool::RasterImage) || (targetType & TTool::ToonzImage)) {
|
|
|
|
|
addPrimitive(new RectanglePrimitive(&m_param, this, true));
|
|
|
|
|
addPrimitive(new CirclePrimitive(&m_param, this, true));
|
|
|
|
|
addPrimitive(new EllipsePrimitive(&m_param, this, true));
|
|
|
|
|
addPrimitive(new LinePrimitive(&m_param, this, true));
|
|
|
|
|
addPrimitive(new MultiLinePrimitive(&m_param, this, true));
|
|
|
|
|
addPrimitive(new ArcPrimitive(&m_param, this, true));
|
2020-07-06 17:32:52 +12:00
|
|
|
|
addPrimitive(new MultiArcPrimitive(&m_param, this, true));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
addPrimitive(new PolygonPrimitive(&m_param, this, true));
|
|
|
|
|
} else // targetType == 1
|
|
|
|
|
{
|
|
|
|
|
// vector
|
|
|
|
|
addPrimitive(m_primitive = new RectanglePrimitive(&m_param, this, false));
|
|
|
|
|
addPrimitive(new CirclePrimitive(&m_param, this, false));
|
|
|
|
|
addPrimitive(new EllipsePrimitive(&m_param, this, false));
|
|
|
|
|
addPrimitive(new LinePrimitive(&m_param, this, false));
|
|
|
|
|
addPrimitive(new MultiLinePrimitive(&m_param, this, false));
|
|
|
|
|
addPrimitive(new ArcPrimitive(&m_param, this, false));
|
2020-07-06 17:32:52 +12:00
|
|
|
|
addPrimitive(new MultiArcPrimitive(&m_param, this, false));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
addPrimitive(new PolygonPrimitive(&m_param, this, false));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~GeometricTool() {
|
|
|
|
|
std::map<std::wstring, Primitive *>::iterator it;
|
|
|
|
|
for (it = m_primitiveTable.begin(); it != m_primitiveTable.end(); ++it)
|
|
|
|
|
delete it->second;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
ToolType getToolType() const override { return TTool::LevelWriteTool; }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void updateTranslation() override { m_param.updateTranslation(); }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
void addPrimitive(Primitive *p) {
|
|
|
|
|
// TODO: aggiungere il controllo per evitare nomi ripetuti
|
|
|
|
|
std::wstring name = ::to_wstring(p->getName());
|
|
|
|
|
// wstring name = TStringTable::translate(p->getName());
|
|
|
|
|
|
|
|
|
|
m_primitiveTable[name] = p;
|
|
|
|
|
m_param.m_type.addValue(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeType(std::wstring name) {
|
|
|
|
|
std::map<std::wstring, Primitive *>::iterator it =
|
|
|
|
|
m_primitiveTable.find(name);
|
2020-07-06 17:32:52 +12:00
|
|
|
|
if (it != m_primitiveTable.end()) {
|
|
|
|
|
if (m_primitive) m_primitive->onDeactivate();
|
|
|
|
|
m_primitive = it->second;
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 11:27:03 +13:00
|
|
|
|
bool preLeftButtonDown() override {
|
|
|
|
|
if (getViewer() && getViewer()->getGuidedStrokePickerMode()) return false;
|
2021-03-28 21:34:35 +13:00
|
|
|
|
if (getApplication()->getCurrentObject()->isSpline()) return true;
|
|
|
|
|
|
|
|
|
|
// in the halfway through the drawing of Polyline / MultiArc primitive, OT
|
|
|
|
|
// should not call touchImage or the m_frameCreated / m_levelCreated flags
|
|
|
|
|
// will be reset.
|
|
|
|
|
if (m_primitive && !m_primitive->canTouchImageOnPreLeftClick()) return true;
|
|
|
|
|
// NEEDS to be done even if(m_active), due
|
|
|
|
|
// to the HORRIBLE m_frameCreated / m_levelCreated
|
|
|
|
|
// mechanism. touchImage() is the ONLY function
|
|
|
|
|
// resetting them to false... >_<
|
|
|
|
|
m_active = !!touchImage();
|
2021-03-28 11:27:03 +13:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void leftButtonDown(const TPointD &p, const TMouseEvent &e) override {
|
2019-12-25 17:04:57 +13:00
|
|
|
|
if (getViewer() && getViewer()->getGuidedStrokePickerMode()) {
|
|
|
|
|
getViewer()->doPickGuideStroke(p);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_primitive) m_primitive->leftButtonDown(p, e);
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void leftButtonDrag(const TPointD &p, const TMouseEvent &e) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (!m_active) return;
|
|
|
|
|
if (m_primitive) m_primitive->leftButtonDrag(p, e);
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void leftButtonUp(const TPointD &p, const TMouseEvent &e) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (!m_active) return;
|
|
|
|
|
if (m_primitive) m_primitive->leftButtonUp(p, e);
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void leftButtonDoubleClick(const TPointD &p, const TMouseEvent &e) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (!m_active) return;
|
|
|
|
|
if (m_primitive) m_primitive->leftButtonDoubleClick(p, e);
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 19:34:13 +13:00
|
|
|
|
bool keyDown(QKeyEvent *event) override {
|
|
|
|
|
return m_primitive->keyDown(event);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void onImageChanged() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_primitive) m_primitive->onImageChanged();
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void rightButtonDown(const TPointD &p, const TMouseEvent &e) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_primitive) m_primitive->rightButtonDown(p, e);
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void mouseMove(const TPointD &p, const TMouseEvent &e) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_primitive) m_primitive->mouseMove(p, e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void onActivate() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_firstTime) {
|
|
|
|
|
m_param.m_toolSize.setValue(GeometricSize);
|
|
|
|
|
m_param.m_rasterToolSize.setValue(GeometricRasterSize);
|
|
|
|
|
m_param.m_opacity.setValue(GeometricOpacity);
|
|
|
|
|
m_param.m_hardness.setValue(GeometricBrushHardness);
|
|
|
|
|
m_param.m_selective.setValue(GeometricSelective ? 1 : 0);
|
|
|
|
|
m_param.m_autogroup.setValue(GeometricGroupIt ? 1 : 0);
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_param.m_smooth.setValue(GeometricSmooth ? 1 : 0);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_param.m_autofill.setValue(GeometricAutofill ? 1 : 0);
|
|
|
|
|
std::wstring typeCode = ::to_wstring(GeometricType.getValue());
|
|
|
|
|
m_param.m_type.setValue(typeCode);
|
|
|
|
|
GeometricType = ::to_string(typeCode);
|
|
|
|
|
m_typeCode = typeCode;
|
|
|
|
|
changeType(typeCode);
|
|
|
|
|
m_param.m_edgeCount.setValue(GeometricEdgeCount);
|
|
|
|
|
m_param.m_pencil.setValue(GeometricPencil ? 1 : 0);
|
|
|
|
|
m_param.m_capStyle.setIndex(GeometricCapStyle);
|
|
|
|
|
m_param.m_joinStyle.setIndex(GeometricJoinStyle);
|
|
|
|
|
m_param.m_miterJoinLimit.setValue(GeometricMiterValue);
|
|
|
|
|
m_firstTime = false;
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_param.m_snap.setValue(GeometricSnap);
|
2020-09-23 15:04:03 +12:00
|
|
|
|
m_param.m_sendToBack.setValue(GeometricDrawBehind);
|
2018-04-26 21:24:25 +12:00
|
|
|
|
if (m_targetType & TTool::Vectors) {
|
|
|
|
|
m_param.m_snapSensitivity.setIndex(GeometricSnapSensitivity);
|
|
|
|
|
switch (GeometricSnapSensitivity) {
|
|
|
|
|
case 0:
|
|
|
|
|
m_param.m_minDistance2 = SNAPPING_LOW;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
m_param.m_minDistance2 = SNAPPING_MEDIUM;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
m_param.m_minDistance2 = SNAPPING_HIGH;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-08-23 00:11:38 +12:00
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_primitive->resetSnap();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*--
|
|
|
|
|
ショートカットでいきなりスタート(=onEnterを通らない場合)のとき、
|
|
|
|
|
LineToolが反応しないことがある対策 --*/
|
|
|
|
|
m_active = (getImage(false) != 0 ||
|
|
|
|
|
Preferences::instance()->isAutoCreateEnabled());
|
|
|
|
|
|
|
|
|
|
if (m_primitive) m_primitive->onActivate();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void onDeactivate() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_primitive) m_primitive->onDeactivate();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void onEnter() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_active = getImage(false) != 0;
|
|
|
|
|
if (m_active && m_primitive) m_primitive->onEnter();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
void draw() override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_primitive) m_primitive->draw();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-25 17:04:57 +13:00
|
|
|
|
int getCursorId() const override {
|
|
|
|
|
if (m_viewer && m_viewer->getGuidedStrokePickerMode())
|
|
|
|
|
return m_viewer->getGuidedStrokePickerCursor();
|
|
|
|
|
return ToolCursor::PenCursor;
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
int getColorClass() const { return 1; }
|
|
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
|
TPropertyGroup *getProperties(int idx) override {
|
|
|
|
|
return &m_param.m_prop[idx];
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
|
bool onPropertyChanged(std::string propertyName) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*--- 変更されたPropertyごとに処理を分ける。
|
|
|
|
|
注意:m_toolSizeとm_rasterToolSizeは同じName(="Size:")なので、
|
|
|
|
|
扱っている画像がラスタかどうかで区別する ---*/
|
|
|
|
|
if (propertyName == m_param.m_toolSize.getName()) {
|
|
|
|
|
TImageP img = getImage(false);
|
|
|
|
|
TToonzImageP ri(img); /*-- ラスタかどうかの判定 --*/
|
|
|
|
|
if (ri)
|
|
|
|
|
GeometricRasterSize = m_param.m_rasterToolSize.getValue();
|
|
|
|
|
else
|
|
|
|
|
GeometricSize = m_param.m_toolSize.getValue();
|
|
|
|
|
} else if (propertyName == m_param.m_type.getName()) {
|
|
|
|
|
std::wstring typeCode = m_param.m_type.getValue();
|
|
|
|
|
GeometricType = ::to_string(typeCode);
|
|
|
|
|
if (typeCode != m_typeCode) {
|
|
|
|
|
m_typeCode = typeCode;
|
|
|
|
|
changeType(typeCode);
|
2021-02-17 20:01:28 +13:00
|
|
|
|
TTool::getApplication()->refreshStatusBar();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
} else if (propertyName == m_param.m_edgeCount.getName())
|
|
|
|
|
GeometricEdgeCount = m_param.m_edgeCount.getValue();
|
|
|
|
|
else if (propertyName == m_param.m_autogroup.getName()) {
|
|
|
|
|
if (!m_param.m_autogroup.getValue()) {
|
|
|
|
|
m_param.m_autofill.setValue(false);
|
|
|
|
|
// this is ugly: it's needed to refresh the GUI of the toolbar after
|
|
|
|
|
// having set to false the autofill...
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->setTool(
|
|
|
|
|
""); // necessary, otherwise next setTool is ignored...
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->setTool(
|
|
|
|
|
QString::fromStdString(getName()));
|
|
|
|
|
}
|
|
|
|
|
GeometricGroupIt = m_param.m_autogroup.getValue();
|
|
|
|
|
} else if (propertyName == m_param.m_autofill.getName()) {
|
|
|
|
|
if (m_param.m_autofill.getValue()) {
|
|
|
|
|
m_param.m_autogroup.setValue(true);
|
|
|
|
|
// this is ugly: it's needed to refresh the GUI of the toolbar after
|
|
|
|
|
// having set to false the autofill...
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->setTool(
|
|
|
|
|
""); // necessary, otherwise next setTool is ignored...
|
|
|
|
|
TTool::getApplication()->getCurrentTool()->setTool(
|
|
|
|
|
QString::fromStdString(getName()));
|
|
|
|
|
}
|
|
|
|
|
GeometricGroupIt = m_param.m_autofill.getValue();
|
2020-07-06 17:32:52 +12:00
|
|
|
|
} else if (propertyName == m_param.m_smooth.getName()) {
|
|
|
|
|
GeometricSmooth = m_param.m_smooth.getValue();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
} else if (propertyName == m_param.m_selective.getName())
|
|
|
|
|
GeometricSelective = m_param.m_selective.getValue();
|
|
|
|
|
else if (propertyName == m_param.m_pencil.getName())
|
|
|
|
|
GeometricPencil = m_param.m_pencil.getValue();
|
|
|
|
|
else if (propertyName == m_param.m_hardness.getName())
|
|
|
|
|
GeometricBrushHardness = m_param.m_hardness.getValue();
|
|
|
|
|
else if (propertyName == m_param.m_opacity.getName())
|
|
|
|
|
GeometricOpacity = m_param.m_opacity.getValue();
|
|
|
|
|
else if (propertyName == m_param.m_capStyle.getName())
|
|
|
|
|
GeometricCapStyle = m_param.m_capStyle.getIndex();
|
|
|
|
|
else if (propertyName == m_param.m_joinStyle.getName())
|
|
|
|
|
GeometricJoinStyle = m_param.m_joinStyle.getIndex();
|
|
|
|
|
else if (propertyName == m_param.m_miterJoinLimit.getName())
|
|
|
|
|
GeometricMiterValue = m_param.m_miterJoinLimit.getValue();
|
2020-09-23 15:04:03 +12:00
|
|
|
|
else if (propertyName == m_param.m_sendToBack.getName())
|
2020-09-23 16:51:41 +12:00
|
|
|
|
GeometricDrawBehind = m_param.m_sendToBack.getValue();
|
2017-08-23 00:11:38 +12:00
|
|
|
|
else if (propertyName == m_param.m_snap.getName())
|
|
|
|
|
GeometricSnap = m_param.m_snap.getValue();
|
|
|
|
|
else if (propertyName == m_param.m_snapSensitivity.getName()) {
|
|
|
|
|
GeometricSnapSensitivity = m_param.m_snapSensitivity.getIndex();
|
|
|
|
|
switch (GeometricSnapSensitivity) {
|
|
|
|
|
case 0:
|
|
|
|
|
m_param.m_minDistance2 = SNAPPING_LOW;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
m_param.m_minDistance2 = SNAPPING_MEDIUM;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
m_param.m_minDistance2 = SNAPPING_HIGH;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addStroke() {
|
|
|
|
|
if (!m_primitive) return;
|
|
|
|
|
TStroke *stroke = m_primitive->makeStroke();
|
|
|
|
|
if (!stroke) return;
|
|
|
|
|
|
|
|
|
|
TStroke::OutlineOptions &options = stroke->outlineOptions();
|
|
|
|
|
options.m_capStyle = m_param.m_capStyle.getIndex();
|
|
|
|
|
options.m_joinStyle = m_param.m_joinStyle.getIndex();
|
|
|
|
|
options.m_miterUpper = m_param.m_miterJoinLimit.getValue();
|
|
|
|
|
|
|
|
|
|
TImage *image = getImage(true);
|
|
|
|
|
TToonzImageP ti(image);
|
|
|
|
|
TVectorImageP vi(image);
|
|
|
|
|
TRasterImageP ri(image);
|
|
|
|
|
TXshSimpleLevel *sl =
|
|
|
|
|
TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
|
|
|
|
|
TFrameId id = getCurrentFid();
|
|
|
|
|
/*-- ToonzImageの場合 --*/
|
|
|
|
|
if (ti) {
|
|
|
|
|
int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
|
|
|
|
|
bool selective = m_param.m_selective.getValue();
|
|
|
|
|
|
|
|
|
|
bool filled = false;
|
|
|
|
|
|
|
|
|
|
stroke->setStyle(styleId);
|
|
|
|
|
double hardness = m_param.m_hardness.getValue() * 0.01;
|
|
|
|
|
TRect savebox;
|
|
|
|
|
if (hardness == 1 || m_param.m_pencil.getValue()) {
|
|
|
|
|
TUndoManager::manager()->add(new UndoRasterPencil(
|
|
|
|
|
sl, id, stroke, selective, filled, !m_param.m_pencil.getValue(),
|
|
|
|
|
m_isFrameCreated, m_isLevelCreated, m_primitive->getName()));
|
|
|
|
|
savebox = ToonzImageUtils::addInkStroke(ti, stroke, styleId, selective,
|
|
|
|
|
filled, TConsts::infiniteRectD,
|
|
|
|
|
!m_param.m_pencil.getValue());
|
|
|
|
|
} else {
|
|
|
|
|
int thickness = m_param.m_rasterToolSize.getValue();
|
|
|
|
|
TUndoManager::manager()->add(new CMBluredPrimitiveUndo(
|
|
|
|
|
sl, id, stroke, thickness, hardness, selective, false,
|
|
|
|
|
m_isFrameCreated, m_isLevelCreated, m_primitive->getName()));
|
|
|
|
|
savebox = drawBluredBrush(ti, stroke, thickness, hardness, selective);
|
|
|
|
|
}
|
|
|
|
|
ToolUtils::updateSaveBox();
|
|
|
|
|
delete stroke;
|
|
|
|
|
}
|
|
|
|
|
/*-- VectorImageの場合 --*/
|
|
|
|
|
else if (vi) {
|
2020-09-23 16:51:41 +12:00
|
|
|
|
int addedStrokeIndex = -1;
|
|
|
|
|
bool isSpline = false;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (TTool::getApplication()->getCurrentObject()->isSpline()) {
|
2020-09-23 16:51:41 +12:00
|
|
|
|
isSpline = true;
|
2020-11-17 05:13:09 +13:00
|
|
|
|
// if (!ToolUtils::isJustCreatedSpline(vi.getPointer())) {
|
|
|
|
|
// m_primitive->setIsPrompting(true);
|
|
|
|
|
// QString question("Are you sure you want to replace the motion
|
|
|
|
|
// path?");
|
|
|
|
|
// int ret =
|
|
|
|
|
// DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"),
|
|
|
|
|
// 0);
|
|
|
|
|
// m_primitive->setIsPrompting(false);
|
|
|
|
|
// if (ret == 2 || ret == 0) return;
|
|
|
|
|
//}
|
2019-10-11 15:57:49 +13:00
|
|
|
|
QMutexLocker lock(vi->getMutex());
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TUndo *undo = new UndoPath(
|
|
|
|
|
getXsheet()->getStageObject(getObjectId())->getSpline());
|
|
|
|
|
while (vi->getStrokeCount() > 0) vi->deleteStroke(0);
|
|
|
|
|
vi->addStroke(stroke, false);
|
|
|
|
|
TUndoManager::manager()->add(undo);
|
|
|
|
|
} else {
|
|
|
|
|
int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
|
|
|
|
|
if (styleId >= 0) stroke->setStyle(styleId);
|
|
|
|
|
QMutexLocker lock(vi->getMutex());
|
|
|
|
|
std::vector<TFilledRegionInf> *fillInformation =
|
|
|
|
|
new std::vector<TFilledRegionInf>;
|
|
|
|
|
ImageUtils::getFillingInformationOverlappingArea(vi, *fillInformation,
|
|
|
|
|
stroke->getBBox());
|
2019-12-25 17:04:57 +13:00
|
|
|
|
|
2020-09-23 16:51:41 +12:00
|
|
|
|
addedStrokeIndex =
|
|
|
|
|
vi->addStroke(stroke, true, m_param.m_sendToBack.getValue() > 0);
|
2020-07-06 17:32:52 +12:00
|
|
|
|
|
2020-01-29 13:22:35 +13:00
|
|
|
|
TUndoManager::manager()->add(new UndoPencil(
|
2020-09-23 15:04:03 +12:00
|
|
|
|
stroke, fillInformation, sl, id, m_isFrameCreated, m_isLevelCreated,
|
|
|
|
|
m_param.m_autogroup.getValue(), m_param.m_autofill.getValue(),
|
|
|
|
|
m_param.m_sendToBack.getValue() > 0));
|
2020-01-29 13:22:35 +13:00
|
|
|
|
|
2020-01-14 21:01:17 +13:00
|
|
|
|
if ((Preferences::instance()->getGuidedDrawingType() == 1 ||
|
|
|
|
|
Preferences::instance()->getGuidedDrawingType() == 2) &&
|
2019-12-25 17:04:57 +13:00
|
|
|
|
Preferences::instance()->getGuidedAutoInbetween()) {
|
|
|
|
|
TTool *tool =
|
|
|
|
|
TTool::getTool(T_Brush, TTool::ToolTargetType::VectorImage);
|
|
|
|
|
ToonzVectorBrushTool *vbTool = (ToonzVectorBrushTool *)tool;
|
|
|
|
|
if (vbTool) {
|
|
|
|
|
vbTool->setViewer(m_viewer);
|
2020-01-29 13:22:35 +13:00
|
|
|
|
vbTool->doGuidedAutoInbetween(id, vi, stroke, false,
|
|
|
|
|
m_param.m_autogroup.getValue(),
|
2020-09-23 15:04:03 +12:00
|
|
|
|
m_param.m_autofill.getValue(), false,
|
|
|
|
|
m_param.m_sendToBack.getValue() > 0);
|
2019-12-25 17:04:57 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
if (m_param.m_autogroup.getValue() && stroke->isSelfLoop()) {
|
|
|
|
|
int index = vi->getStrokeCount() - 1;
|
2020-09-23 16:51:41 +12:00
|
|
|
|
if (m_param.m_sendToBack.getValue() > 0 && !isSpline)
|
|
|
|
|
index = addedStrokeIndex;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
vi->group(index, 1);
|
|
|
|
|
if (m_param.m_autofill.getValue()) {
|
|
|
|
|
// to avoid filling other strokes, I enter into the new stroke group
|
|
|
|
|
int currentGroup = vi->exitGroup();
|
|
|
|
|
vi->enterGroup(index);
|
|
|
|
|
vi->selectFill(stroke->getBBox().enlarge(1, 1), 0, stroke->getStyle(),
|
|
|
|
|
false, true, false);
|
|
|
|
|
if (currentGroup != -1)
|
|
|
|
|
vi->enterGroup(currentGroup);
|
|
|
|
|
else
|
|
|
|
|
vi->exitGroup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*-- RasterImageの場合 --*/
|
|
|
|
|
else if (ri) {
|
|
|
|
|
int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
|
|
|
|
|
stroke->setStyle(styleId);
|
|
|
|
|
double opacity = m_param.m_opacity.getValue() * 0.01;
|
|
|
|
|
double hardness = m_param.m_hardness.getValue() * 0.01;
|
|
|
|
|
TRect savebox;
|
|
|
|
|
if (hardness == 1) {
|
|
|
|
|
TUndoManager::manager()->add(new UndoFullColorPencil(
|
|
|
|
|
sl, id, stroke, opacity, true, m_isFrameCreated, m_isLevelCreated));
|
|
|
|
|
savebox = TRasterImageUtils::addStroke(ri, stroke, TRectD(), opacity);
|
|
|
|
|
} else {
|
|
|
|
|
int thickness = m_param.m_rasterToolSize.getValue();
|
|
|
|
|
TUndoManager::manager()->add(new FullColorBluredPrimitiveUndo(
|
|
|
|
|
sl, id, stroke, thickness, hardness, opacity, true,
|
|
|
|
|
m_isFrameCreated, m_isLevelCreated));
|
|
|
|
|
savebox = drawBluredBrush(ri, stroke, thickness, hardness, opacity);
|
|
|
|
|
}
|
|
|
|
|
ToolUtils::updateSaveBox();
|
|
|
|
|
delete stroke;
|
|
|
|
|
}
|
|
|
|
|
notifyImageChanged();
|
|
|
|
|
m_active = false;
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GeometricTool GeometricVectorTool(TTool::Vectors | TTool::EmptyTarget);
|
|
|
|
|
GeometricTool GeometricRasterTool(TTool::ToonzImage | TTool::EmptyTarget);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
GeometricTool GeometricRasterFullColorTool(TTool::RasterImage |
|
|
|
|
|
TTool::EmptyTarget);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void Primitive::drawSnap() {
|
|
|
|
|
// snapping
|
2020-10-06 03:11:08 +13:00
|
|
|
|
|
|
|
|
|
if ((m_param->m_targetType & TTool::Vectors) && m_doSnap) {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_param->m_pixelSize = m_tool->getPixelSize();
|
|
|
|
|
double thick = 6.0 * m_param->m_pixelSize;
|
|
|
|
|
if (m_param->m_foundSnap) {
|
|
|
|
|
tglColor(TPixelD(0.1, 0.9, 0.1));
|
|
|
|
|
tglDrawCircle(m_param->m_snapPoint, thick);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD Primitive::checkGuideSnapping(TPointD pos, const TMouseEvent &e) {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
if (Preferences::instance()->getVectorSnappingTarget() == 0) {
|
|
|
|
|
if (m_param->m_foundSnap)
|
|
|
|
|
return m_param->m_snapPoint;
|
|
|
|
|
else
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
2020-10-06 03:11:08 +13:00
|
|
|
|
m_doSnap = (m_param->m_snap.getValue() &&
|
|
|
|
|
!(e.isCtrlPressed() && e.isShiftPressed())) ||
|
|
|
|
|
(!m_param->m_snap.getValue() &&
|
|
|
|
|
(e.isCtrlPressed() && e.isShiftPressed()));
|
|
|
|
|
if ((m_param->m_targetType & TTool::Vectors) && m_doSnap) {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
int vGuideCount = 0, hGuideCount = 0;
|
|
|
|
|
double guideDistance = sqrt(m_param->m_minDistance2);
|
|
|
|
|
TTool::Viewer *viewer = m_tool->getViewer();
|
|
|
|
|
if (viewer) {
|
|
|
|
|
vGuideCount = viewer->getVGuideCount();
|
|
|
|
|
hGuideCount = viewer->getHGuideCount();
|
|
|
|
|
}
|
|
|
|
|
double distanceToVGuide = -1.0, distanceToHGuide = -1.0;
|
|
|
|
|
double vGuide, hGuide;
|
|
|
|
|
bool useGuides = false;
|
|
|
|
|
if (vGuideCount) {
|
|
|
|
|
for (int j = 0; j < vGuideCount; j++) {
|
|
|
|
|
double guide = viewer->getVGuide(j);
|
2020-04-12 17:19:20 +12:00
|
|
|
|
double tempDistance = std::abs(guide - pos.y);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
if (tempDistance < guideDistance &&
|
|
|
|
|
(distanceToVGuide < 0 || tempDistance < distanceToVGuide)) {
|
|
|
|
|
distanceToVGuide = tempDistance;
|
|
|
|
|
vGuide = guide;
|
|
|
|
|
useGuides = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hGuideCount) {
|
|
|
|
|
for (int j = 0; j < hGuideCount; j++) {
|
|
|
|
|
double guide = viewer->getHGuide(j);
|
2020-04-12 17:19:20 +12:00
|
|
|
|
double tempDistance = std::abs(guide - pos.x);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
if (tempDistance < guideDistance &&
|
|
|
|
|
(distanceToHGuide < 0 || tempDistance < distanceToHGuide)) {
|
|
|
|
|
distanceToHGuide = tempDistance;
|
|
|
|
|
hGuide = guide;
|
|
|
|
|
useGuides = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (useGuides && m_param->m_foundSnap) {
|
2020-04-12 17:19:20 +12:00
|
|
|
|
double currYDistance = std::abs(m_param->m_snapPoint.y - pos.y);
|
|
|
|
|
double currXDistance = std::abs(m_param->m_snapPoint.x - pos.x);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
double hypotenuse =
|
|
|
|
|
sqrt(pow(currYDistance, 2.0) + pow(currXDistance, 2.0));
|
|
|
|
|
if ((distanceToVGuide >= 0 && distanceToVGuide < hypotenuse) ||
|
|
|
|
|
(distanceToHGuide >= 0 && distanceToHGuide < hypotenuse))
|
|
|
|
|
useGuides = true;
|
|
|
|
|
else
|
|
|
|
|
useGuides = false;
|
|
|
|
|
}
|
|
|
|
|
if (useGuides) {
|
|
|
|
|
assert(distanceToHGuide >= 0 || distanceToVGuide >= 0);
|
|
|
|
|
if (distanceToHGuide < 0 ||
|
|
|
|
|
(distanceToVGuide <= distanceToHGuide && distanceToVGuide >= 0)) {
|
|
|
|
|
m_param->m_snapPoint.y = vGuide;
|
|
|
|
|
m_param->m_snapPoint.x = pos.x;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
m_param->m_snapPoint.y = pos.y;
|
|
|
|
|
m_param->m_snapPoint.x = hGuide;
|
|
|
|
|
}
|
|
|
|
|
m_param->m_foundSnap = true;
|
|
|
|
|
}
|
|
|
|
|
if (m_param->m_foundSnap)
|
|
|
|
|
return m_param->m_snapPoint;
|
|
|
|
|
else
|
|
|
|
|
return pos;
|
|
|
|
|
} else
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
|
//=============================================================================
|
|
|
|
|
// Rectangle Primitive Class Implementation
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void RectanglePrimitive::draw() {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
drawSnap();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_isEditing || m_isPrompting ||
|
|
|
|
|
areAlmostEqual(m_selectingRect.x0, m_selectingRect.x1) ||
|
|
|
|
|
areAlmostEqual(m_selectingRect.y0, m_selectingRect.y1)) {
|
|
|
|
|
tglColor(m_isEditing ? m_color : TPixel32::Green);
|
|
|
|
|
glBegin(GL_LINE_LOOP);
|
|
|
|
|
tglVertex(m_selectingRect.getP00());
|
|
|
|
|
tglVertex(m_selectingRect.getP01());
|
|
|
|
|
tglVertex(m_selectingRect.getP11());
|
|
|
|
|
tglVertex(m_selectingRect.getP10());
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void RectanglePrimitive::leftButtonDown(const TPointD &pos,
|
|
|
|
|
const TMouseEvent &) {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
m_isEditing = true;
|
|
|
|
|
} else {
|
|
|
|
|
// app->getCurrentTool()->getTool()->touchImage();
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
|
|
|
|
m_isEditing = style != 0 && style->isStrokeStyle();
|
|
|
|
|
m_color = (style) ? style->getAverageColor() : TPixel32::Black;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_isEditing) return;
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TPointD newPos = getSnap(pos);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_param->m_pencil.getValue() &&
|
|
|
|
|
(m_param->m_targetType & TTool::ToonzImage ||
|
|
|
|
|
m_param->m_targetType & TTool::RasterImage)) {
|
|
|
|
|
if (m_param->m_rasterToolSize.getValue() % 2 != 0)
|
|
|
|
|
m_startPoint = TPointD((int)pos.x, (int)pos.y);
|
|
|
|
|
else
|
|
|
|
|
m_startPoint = TPointD((int)pos.x + 0.5, (int)pos.y + 0.5);
|
|
|
|
|
} else
|
2020-09-23 15:04:03 +12:00
|
|
|
|
m_startPoint = newPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_selectingRect.x0 = m_startPoint.x;
|
|
|
|
|
m_selectingRect.y0 = m_startPoint.y;
|
|
|
|
|
m_selectingRect.x1 = m_startPoint.x;
|
|
|
|
|
m_selectingRect.y1 = m_startPoint.y;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void RectanglePrimitive::leftButtonDrag(const TPointD &realPos,
|
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
|
|
|
|
|
TPointD pos;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if (e.isShiftPressed() && !e.isCtrlPressed()) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double distance = tdistance(realPos, m_startPoint) * M_SQRT1_2;
|
|
|
|
|
pos.x = (realPos.x > m_startPoint.x) ? m_startPoint.x + distance
|
|
|
|
|
: m_startPoint.x - distance;
|
|
|
|
|
pos.y = (realPos.y > m_startPoint.y) ? m_startPoint.y + distance
|
|
|
|
|
: m_startPoint.y - distance;
|
|
|
|
|
} else {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
pos = calculateSnap(realPos, e);
|
|
|
|
|
pos = checkGuideSnapping(realPos, e);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_param->m_pencil.getValue() &&
|
|
|
|
|
(m_param->m_targetType & TTool::ToonzImage ||
|
|
|
|
|
m_param->m_targetType & TTool::RasterImage)) {
|
|
|
|
|
if (m_param->m_rasterToolSize.getValue() % 2 != 0)
|
|
|
|
|
pos = TPointD((int)pos.x, (int)pos.y);
|
|
|
|
|
else
|
|
|
|
|
pos = TPointD((int)pos.x + 0.5, (int)pos.y + 0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_selectingRect.x1 = pos.x;
|
|
|
|
|
m_selectingRect.y1 = pos.y;
|
|
|
|
|
if (!e.isAltPressed()) {
|
|
|
|
|
m_selectingRect.x0 = m_startPoint.x;
|
|
|
|
|
m_selectingRect.y0 = m_startPoint.y;
|
|
|
|
|
} else {
|
|
|
|
|
m_selectingRect.x0 = m_startPoint.x + m_startPoint.x - pos.x;
|
|
|
|
|
m_selectingRect.y0 = m_startPoint.y + m_startPoint.y - pos.y;
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *RectanglePrimitive::makeStroke() const {
|
|
|
|
|
if (areAlmostEqual(m_selectingRect.x0, m_selectingRect.x1) ||
|
|
|
|
|
areAlmostEqual(m_selectingRect.y0, m_selectingRect.y1))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
TRectD selArea;
|
|
|
|
|
selArea.x0 = std::min(m_selectingRect.x0, m_selectingRect.x1);
|
|
|
|
|
selArea.y0 = std::min(m_selectingRect.y0, m_selectingRect.y1);
|
|
|
|
|
selArea.x1 = std::max(m_selectingRect.x0, m_selectingRect.x1);
|
|
|
|
|
selArea.y1 = std::max(m_selectingRect.y0, m_selectingRect.y1);
|
|
|
|
|
|
|
|
|
|
double thick = getThickness();
|
|
|
|
|
|
|
|
|
|
TStroke *stroke = 0;
|
|
|
|
|
if (m_param->m_targetType & TTool::Vectors) {
|
|
|
|
|
std::vector<TThickPoint> points(17);
|
|
|
|
|
|
|
|
|
|
points[0] = TThickPoint(selArea.x1, selArea.y1, thick);
|
|
|
|
|
points[1] = TThickPoint(selArea.x1, selArea.y1, thick) + TPointD(-0.01, 0);
|
|
|
|
|
|
|
|
|
|
points[3] = TThickPoint(selArea.x0, selArea.y1, thick) + TPointD(0.01, 0);
|
|
|
|
|
points[4] = TThickPoint(selArea.x0, selArea.y1, thick);
|
|
|
|
|
points[5] = TThickPoint(selArea.x0, selArea.y1, thick) + TPointD(0, -0.01);
|
|
|
|
|
|
|
|
|
|
points[7] = TThickPoint(selArea.x0, selArea.y0, thick) + TPointD(0, 0.01);
|
|
|
|
|
points[8] = TThickPoint(selArea.x0, selArea.y0, thick);
|
|
|
|
|
points[9] = TThickPoint(selArea.x0, selArea.y0, thick) + TPointD(0.01, 0);
|
|
|
|
|
|
|
|
|
|
points[11] = TThickPoint(selArea.x1, selArea.y0, thick) + TPointD(-0.01, 0);
|
|
|
|
|
points[12] = TThickPoint(selArea.x1, selArea.y0, thick);
|
|
|
|
|
points[13] = TThickPoint(selArea.x1, selArea.y0, thick) + TPointD(0, 0.01);
|
|
|
|
|
|
|
|
|
|
points[15] = points[0] + TPointD(0, -0.01);
|
|
|
|
|
points[16] = points[0];
|
|
|
|
|
|
|
|
|
|
points[2] = 0.5 * (points[1] + points[3]);
|
|
|
|
|
points[6] = 0.5 * (points[5] + points[7]);
|
|
|
|
|
points[10] = 0.5 * (points[9] + points[11]);
|
|
|
|
|
points[14] = 0.5 * (points[13] + points[15]);
|
|
|
|
|
|
|
|
|
|
stroke = new TStroke(points);
|
|
|
|
|
} else if (m_param->m_targetType & TTool::ToonzImage ||
|
|
|
|
|
m_param->m_targetType & TTool::RasterImage) {
|
|
|
|
|
std::vector<TThickPoint> points(9);
|
|
|
|
|
double middleX = (selArea.x0 + selArea.x1) * 0.5;
|
|
|
|
|
double middleY = (selArea.y0 + selArea.y1) * 0.5;
|
|
|
|
|
|
|
|
|
|
points[0] = TThickPoint(selArea.x1, selArea.y1, thick);
|
|
|
|
|
points[1] = TThickPoint(middleX, selArea.y1, thick);
|
|
|
|
|
points[2] = TThickPoint(selArea.x0, selArea.y1, thick);
|
|
|
|
|
points[3] = TThickPoint(selArea.x0, middleY, thick);
|
|
|
|
|
points[4] = TThickPoint(selArea.x0, selArea.y0, thick);
|
|
|
|
|
points[5] = TThickPoint(middleX, selArea.y0, thick);
|
|
|
|
|
points[6] = TThickPoint(selArea.x1, selArea.y0, thick);
|
|
|
|
|
points[7] = TThickPoint(selArea.x1, middleY, thick);
|
|
|
|
|
points[8] = points[0];
|
|
|
|
|
stroke = new TStroke(points);
|
|
|
|
|
}
|
|
|
|
|
stroke->setSelfLoop();
|
|
|
|
|
return stroke;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void RectanglePrimitive::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_tool->addStroke();
|
2017-08-23 00:11:38 +12:00
|
|
|
|
resetSnap();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void RectanglePrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_pos = newPos;
|
|
|
|
|
m_tool->invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void RectanglePrimitive::onEnter() {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (app->getCurrentObject()->isSpline())
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
2020-09-23 15:04:03 +12:00
|
|
|
|
if (style) m_color = style->getAverageColor();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Circle Primitive Class Implementation
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void CirclePrimitive::draw() {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
drawSnap();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_isEditing || m_isPrompting) {
|
|
|
|
|
tglColor(m_isEditing ? m_color : TPixel32::Green);
|
|
|
|
|
tglDrawCircle(m_centre, m_radius);
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void CirclePrimitive::leftButtonDown(const TPointD &pos, const TMouseEvent &) {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_pos = getSnap(pos);
|
|
|
|
|
m_centre = m_pos;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
m_isEditing = true;
|
|
|
|
|
} else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
|
|
|
|
if (style) {
|
|
|
|
|
m_isEditing = style->isStrokeStyle();
|
|
|
|
|
m_color = style->getAverageColor();
|
|
|
|
|
} else {
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_color = TPixel32::Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_isEditing) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void CirclePrimitive::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
|
if (!m_isEditing) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_pos = pos;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
m_pos = calculateSnap(pos, e);
|
|
|
|
|
m_pos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_radius = tdistance(m_centre, m_pos);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *CirclePrimitive::makeStroke() const {
|
|
|
|
|
return makeEllipticStroke(getThickness(), m_centre, m_radius, m_radius);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void CirclePrimitive::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
if (isAlmostZero(m_radius)) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_tool->addStroke();
|
|
|
|
|
m_radius = 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void CirclePrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
m_pos = calculateSnap(pos, e);
|
|
|
|
|
m_pos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_tool->invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void CirclePrimitive::onEnter() {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (app->getCurrentObject()->isSpline())
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
2020-09-23 15:04:03 +12:00
|
|
|
|
if (style) m_color = style->getAverageColor();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// MultiLine Primitive Class Implementation
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::addVertex(const TPointD &pos) {
|
|
|
|
|
int count = m_vertex.size();
|
|
|
|
|
// Inserisco il primo punto
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
m_vertex.push_back(pos);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TPointD &vertex = m_vertex[count - 1];
|
|
|
|
|
|
|
|
|
|
// Caso particolare in cui inizio una curva e la chiudo subito cliccando sul
|
|
|
|
|
// punto di pertenza
|
|
|
|
|
if (count == 1 && pos == vertex) {
|
|
|
|
|
m_vertex.push_back(pos);
|
|
|
|
|
m_vertex.push_back(pos);
|
|
|
|
|
m_vertex.push_back(pos);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calcolo lo speedOut
|
|
|
|
|
TPointD speedOutPoint;
|
|
|
|
|
if (!m_speedMoved) // Se non e' stato mosso lo speedOut devo calcolarlo e
|
|
|
|
|
// inserirlo
|
|
|
|
|
{
|
|
|
|
|
speedOutPoint = vertex + computeSpeed(vertex, pos, 0.01);
|
|
|
|
|
m_vertex.push_back(speedOutPoint);
|
|
|
|
|
} else {
|
|
|
|
|
if (m_ctrlDown)
|
|
|
|
|
vertex =
|
|
|
|
|
m_vertex[count - 2] + computeSpeed(m_vertex[count - 2], pos, 0.01);
|
|
|
|
|
speedOutPoint = vertex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calcolo lo speedIn
|
|
|
|
|
TPointD speedInPoint = pos + computeSpeed(pos, speedOutPoint, 0.01);
|
|
|
|
|
// Calcolo il "punto di mezzo" e lo inserisco
|
|
|
|
|
TPointD middlePoint = 0.5 * (speedInPoint + speedOutPoint);
|
|
|
|
|
|
|
|
|
|
// Inserisco il "punto di mezzo"
|
|
|
|
|
m_vertex.push_back(middlePoint);
|
|
|
|
|
// Inserisco lo speedIn
|
|
|
|
|
m_vertex.push_back(speedInPoint);
|
|
|
|
|
// Inserisco il nuovo punto
|
|
|
|
|
m_vertex.push_back(pos);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::moveSpeed(const TPointD &delta) {
|
|
|
|
|
int count = m_vertex.size();
|
|
|
|
|
assert(count > 0);
|
|
|
|
|
TPointD lastPoint = m_vertex[count - 1];
|
|
|
|
|
TPointD newSpeedOutPoint = lastPoint - delta;
|
|
|
|
|
if (m_speedMoved)
|
|
|
|
|
m_vertex[count - 1] = newSpeedOutPoint;
|
|
|
|
|
else {
|
|
|
|
|
m_vertex.push_back(newSpeedOutPoint);
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
if (count < 5) {
|
|
|
|
|
assert(count == 2);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TPointD vertex = m_vertex[count - 2];
|
|
|
|
|
|
|
|
|
|
TPointD v(0, 0);
|
|
|
|
|
if (newSpeedOutPoint != vertex) v = normalize(newSpeedOutPoint - vertex);
|
|
|
|
|
|
|
|
|
|
double speedOut = tdistance(newSpeedOutPoint, vertex);
|
|
|
|
|
TPointD newSpeedInPoint = vertex - TPointD(speedOut * v.x, speedOut * v.y);
|
|
|
|
|
|
|
|
|
|
m_vertex[count - 3] = newSpeedInPoint;
|
|
|
|
|
if (tdistance(m_vertex[count - 5], m_vertex[count - 6]) <= 0.02)
|
|
|
|
|
// see ControlPointEditorStroke::isSpeedOutLinear() from
|
|
|
|
|
// controlpointselection.cpp
|
|
|
|
|
m_vertex[count - 5] =
|
|
|
|
|
m_vertex[count - 6] +
|
|
|
|
|
computeSpeed(m_vertex[count - 6], m_vertex[count - 3], 0.01);
|
|
|
|
|
m_vertex[count - 4] = 0.5 * (m_vertex[count - 3] + m_vertex[count - 5]);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::draw() {
|
|
|
|
|
UINT size = m_vertex.size();
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
drawSnap();
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if ((m_isEditing || m_isPrompting) && size > 0) {
|
|
|
|
|
tglColor(m_isEditing ? m_color : TPixel32::Green);
|
|
|
|
|
std::vector<TPointD> points;
|
|
|
|
|
points.assign(m_vertex.begin(), m_vertex.end());
|
|
|
|
|
int count = points.size();
|
|
|
|
|
if (count % 4 == 1) {
|
|
|
|
|
// No speedOut
|
|
|
|
|
points.push_back(points[count - 1]);
|
|
|
|
|
count++;
|
|
|
|
|
} else if (m_ctrlDown)
|
|
|
|
|
points[count - 1] = points[count - 2];
|
|
|
|
|
|
|
|
|
|
points.push_back(0.5 * (m_mousePosition + points[count - 1]));
|
|
|
|
|
points.push_back(m_mousePosition);
|
|
|
|
|
points.push_back(m_mousePosition);
|
|
|
|
|
|
|
|
|
|
double pixelSize = m_tool->getPixelSize();
|
|
|
|
|
|
|
|
|
|
TStroke *stroke = new TStroke(points);
|
|
|
|
|
drawStrokeCenterline(*stroke, pixelSize);
|
|
|
|
|
delete stroke;
|
|
|
|
|
|
|
|
|
|
if (m_vertex.size() > 1) {
|
|
|
|
|
tglColor(TPixel(79, 128, 255));
|
|
|
|
|
int index = (count < 5) ? count - 1 : count - 5;
|
|
|
|
|
// Disegno lo speedOut precedente (che e' quello corrente solo nel caso in
|
|
|
|
|
// cui count < 5)
|
|
|
|
|
TPointD p0 = m_vertex[index];
|
|
|
|
|
TPointD p1 = m_vertex[index - 1];
|
|
|
|
|
if (tdistance(p0, p1) > 0.1) {
|
|
|
|
|
tglDrawSegment(p0, p1);
|
|
|
|
|
tglDrawDisk(p0, 2 * pixelSize);
|
|
|
|
|
tglDrawDisk(p1, 4 * pixelSize);
|
|
|
|
|
}
|
|
|
|
|
// Disegno lo speedIn/Out corrente nel caso in cui count > 5
|
|
|
|
|
if (m_speedMoved && count > 5) {
|
|
|
|
|
TPointD p0 = m_vertex[count - 1];
|
|
|
|
|
TPointD p1 = m_vertex[count - 2];
|
|
|
|
|
TPointD p2 = m_vertex[count - 3];
|
|
|
|
|
tglDrawSegment(p0, p2);
|
|
|
|
|
tglDrawDisk(p0, 2 * pixelSize);
|
|
|
|
|
tglDrawDisk(p1, 4 * pixelSize);
|
|
|
|
|
tglDrawDisk(p2, 2 * pixelSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_closed)
|
|
|
|
|
tglColor(TPixel32((m_color.r + 127) % 255, m_color.g,
|
|
|
|
|
(m_color.b + 127) % 255, m_color.m));
|
|
|
|
|
else
|
|
|
|
|
tglColor(m_color);
|
|
|
|
|
tglDrawCircle(m_vertex[0], joinDistance * pixelSize);
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::leftButtonDown(const TPointD &pos,
|
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
m_isEditing = true;
|
|
|
|
|
} else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
|
|
|
|
if (style) {
|
|
|
|
|
m_isEditing = style->isStrokeStyle();
|
|
|
|
|
m_color = style->getAverageColor();
|
|
|
|
|
} else {
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_color = TPixel32::Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
|
|
|
|
|
m_undo = new MultilinePrimitiveUndo(m_vertex, this);
|
|
|
|
|
TUndoManager::manager()->add(m_undo);
|
|
|
|
|
m_mousePosition = pos;
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TPointD newPos;
|
|
|
|
|
newPos = getSnap(pos);
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
// Se clicco nell'ultimo vertice chiudo la linea.
|
2020-09-23 15:04:03 +12:00
|
|
|
|
TPointD _pos = pos;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_closed) _pos = m_vertex.front();
|
|
|
|
|
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if ((e.isShiftPressed() && !e.isCtrlPressed()) && !m_vertex.empty())
|
2016-06-15 18:43:10 +12:00
|
|
|
|
addVertex(rectify(m_vertex.back(), _pos));
|
|
|
|
|
else
|
2017-08-23 00:11:38 +12:00
|
|
|
|
addVertex(newPos);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_undo->setNewVertex(m_vertex);
|
|
|
|
|
|
|
|
|
|
m_beforeSpeedMoved = m_speedMoved;
|
|
|
|
|
m_speedMoved = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::leftButtonDrag(const TPointD &pos,
|
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
|
if (m_vertex.size() == 0 || m_isSingleLine) return;
|
2020-09-23 15:04:03 +12:00
|
|
|
|
if (m_speedMoved ||
|
|
|
|
|
tdistance2(m_vertex[m_vertex.size() - 1], pos) >
|
|
|
|
|
sq(7.0 * m_tool->getPixelSize())) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
moveSpeed(m_mousePosition - pos);
|
|
|
|
|
m_speedMoved = true;
|
|
|
|
|
m_undo->setNewVertex(m_vertex);
|
|
|
|
|
m_mousePosition = pos;
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::leftButtonDoubleClick(const TPointD &,
|
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
|
endLine();
|
2017-08-23 00:11:38 +12:00
|
|
|
|
resetSnap();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
if (m_closed) endLine();
|
2017-08-23 00:11:38 +12:00
|
|
|
|
resetSnap();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
m_ctrlDown = e.isCtrlPressed() && !e.isShiftPressed();
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TPointD newPos;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_isEditing) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if ((e.isShiftPressed() && !e.isCtrlPressed()) && !m_vertex.empty())
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_mousePosition = rectify(m_vertex.back(), newPos);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
else
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_mousePosition = newPos;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double dist = joinDistance * joinDistance;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
if (!m_vertex.empty() &&
|
|
|
|
|
(tdistance2(pos, m_vertex.front()) < dist * m_tool->getPixelSize())) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_closed = true;
|
|
|
|
|
m_mousePosition = m_vertex.front();
|
|
|
|
|
} else
|
|
|
|
|
m_closed = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
} else
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_mousePosition = newPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_tool->invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2018-02-19 19:34:13 +13:00
|
|
|
|
bool MultiLinePrimitive::keyDown(QKeyEvent *event) {
|
|
|
|
|
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
|
2017-07-25 21:28:13 +12:00
|
|
|
|
endLine();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-19 19:34:13 +13:00
|
|
|
|
if (event->key() != Qt::Key_Escape || !m_isEditing) return false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
UINT size = m_vertex.size();
|
|
|
|
|
if (size <= 1) return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (!m_isSingleLine) TUndoManager::manager()->popUndo((size - 1) / 4 + 1);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_speedMoved = false;
|
|
|
|
|
m_beforeSpeedMoved = false;
|
|
|
|
|
m_closed = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_vertex.clear();
|
|
|
|
|
return true;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *MultiLinePrimitive::makeStroke() const {
|
|
|
|
|
double thick = getThickness();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
/*---
|
|
|
|
|
* Pencilの場合は、線幅を減らす。Thickness1の線を1ピクセルにするため。(thick
|
|
|
|
|
* = 0 になる)---*/
|
|
|
|
|
if (m_param->m_pencil.getValue()) thick -= 1.0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
UINT size = m_vertex.size();
|
|
|
|
|
if (size <= 1) return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (!m_isSingleLine) TUndoManager::manager()->popUndo((size - 1) / 4 + 1);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *stroke = 0;
|
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < (int)size; i++) {
|
|
|
|
|
TPointD vertex = m_vertex[i];
|
|
|
|
|
points.push_back(TThickPoint(vertex, thick));
|
|
|
|
|
}
|
|
|
|
|
stroke = new TStroke(points);
|
|
|
|
|
if (m_closed) stroke->setSelfLoop();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return stroke;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::endLine() {
|
|
|
|
|
if (!m_isEditing) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_speedMoved = false;
|
|
|
|
|
m_beforeSpeedMoved = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (!m_isSingleLine && !m_vertex.empty() &&
|
|
|
|
|
m_vertex.size() % 4 != 1 /* && !m_rasterTool*/) {
|
|
|
|
|
m_vertex.erase(--m_vertex.end());
|
|
|
|
|
assert(m_vertex.size() == 3 || m_vertex.size() % 4 == 1);
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_tool->addStroke();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_closed) m_closed = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_vertex.clear();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::onActivate() {
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_closed = false;
|
|
|
|
|
m_vertex.clear();
|
|
|
|
|
m_speedMoved = false;
|
|
|
|
|
m_beforeSpeedMoved = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void MultiLinePrimitive::onEnter() {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (app->getCurrentObject()->isSpline())
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
2020-09-23 15:04:03 +12:00
|
|
|
|
if (style) m_color = style->getAverageColor();
|
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 MultiLinePrimitive::onImageChanged() { onActivate(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Line Primitive Class Implementation
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void LinePrimitive::draw() {
|
|
|
|
|
UINT size = m_vertex.size();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
drawSnap();
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
tglColor(TPixel32::Red);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_isEditing || m_isPrompting) {
|
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
|
tglVertex(m_vertex[0]);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
tglVertex(m_mousePosition);
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
void LinePrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_tool->invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void LinePrimitive::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
m_isEditing = true;
|
|
|
|
|
} else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
|
|
|
|
if (style) {
|
|
|
|
|
m_isEditing = style->isStrokeStyle();
|
|
|
|
|
m_color = style->getAverageColor();
|
|
|
|
|
} else {
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_color = TPixel32::Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TPointD newPos = getSnap(pos);
|
|
|
|
|
|
|
|
|
|
m_mousePosition = newPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TPointD _pos = newPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
if (m_param->m_pencil.getValue() &&
|
|
|
|
|
(m_param->m_targetType & TTool::ToonzImage ||
|
|
|
|
|
m_param->m_targetType & TTool::RasterImage)) {
|
|
|
|
|
if (m_param->m_rasterToolSize.getValue() % 2 != 0)
|
2017-08-23 00:11:38 +12:00
|
|
|
|
_pos = TPointD((int)newPos.x, (int)newPos.y);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
else
|
2017-08-23 00:11:38 +12:00
|
|
|
|
_pos = TPointD((int)newPos.x + 0.5, (int)newPos.y + 0.5);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_vertex.size() == 0)
|
|
|
|
|
addVertex(_pos);
|
|
|
|
|
else {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if ((e.isShiftPressed() && !e.isCtrlPressed()) && !m_vertex.empty())
|
2017-08-23 00:11:38 +12:00
|
|
|
|
addVertex(rectify(m_vertex.back(), pos));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
else
|
|
|
|
|
addVertex(_pos);
|
|
|
|
|
endLine();
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void LinePrimitive::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
|
|
|
|
|
if (!m_isEditing) return;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_mousePosition = newPos;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void LinePrimitive::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
// snapping
|
|
|
|
|
TPointD newPos = getSnap(pos);
|
|
|
|
|
|
|
|
|
|
m_mousePosition = newPos;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if ((e.isShiftPressed() && !e.isCtrlPressed()) && !m_vertex.empty())
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_vertex.push_back(rectify(m_vertex.back(), pos));
|
|
|
|
|
else
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_vertex.push_back(newPos);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
endLine();
|
2017-08-23 00:11:38 +12:00
|
|
|
|
|
|
|
|
|
resetSnap();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Ellipse Primitive Class Implementation
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void EllipsePrimitive::draw() {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
drawSnap();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_isEditing || m_isPrompting ||
|
|
|
|
|
areAlmostEqual(m_selectingRect.x0, m_selectingRect.x1) ||
|
|
|
|
|
areAlmostEqual(m_selectingRect.y0, m_selectingRect.y1)) {
|
|
|
|
|
tglColor(m_isEditing ? m_color : TPixel32::Green);
|
|
|
|
|
TPointD centre = TPointD((m_selectingRect.x0 + m_selectingRect.x1) * 0.5,
|
|
|
|
|
(m_selectingRect.y0 + m_selectingRect.y1) * 0.5);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
glPushMatrix();
|
|
|
|
|
tglMultMatrix(TScale(centre, m_selectingRect.x1 - m_selectingRect.x0,
|
|
|
|
|
m_selectingRect.y1 - m_selectingRect.y0));
|
|
|
|
|
tglDrawCircle(centre, 0.5);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
glPopMatrix();
|
|
|
|
|
drawRect(m_selectingRect, m_color, 0x5555, true);
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void EllipsePrimitive::leftButtonDown(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TPointD newPos = getSnap(pos);
|
|
|
|
|
m_startPoint = newPos;
|
|
|
|
|
m_selectingRect.x0 = newPos.x;
|
|
|
|
|
m_selectingRect.y0 = newPos.y;
|
|
|
|
|
m_selectingRect.x1 = newPos.x;
|
|
|
|
|
m_selectingRect.y1 = newPos.y;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_isEditing = true;
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
} else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
|
|
|
|
if (style) {
|
|
|
|
|
m_isEditing = style->isStrokeStyle();
|
|
|
|
|
m_color = style->getAverageColor();
|
|
|
|
|
} else {
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_color = TPixel32::Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_isEditing) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void EllipsePrimitive::leftButtonDrag(const TPointD &realPos,
|
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
|
|
|
|
|
TPointD pos;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if (e.isShiftPressed() && !e.isCtrlPressed()) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double distance = tdistance(realPos, m_startPoint) * M_SQRT1_2;
|
|
|
|
|
pos.x = (realPos.x > m_startPoint.x) ? m_startPoint.x + distance
|
|
|
|
|
: m_startPoint.x - distance;
|
|
|
|
|
pos.y = (realPos.y > m_startPoint.y) ? m_startPoint.y + distance
|
|
|
|
|
: m_startPoint.y - distance;
|
|
|
|
|
} else {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
pos = calculateSnap(realPos, e);
|
|
|
|
|
pos = checkGuideSnapping(realPos, e);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
m_pos = pos;
|
|
|
|
|
|
|
|
|
|
m_selectingRect.x1 = pos.x;
|
|
|
|
|
m_selectingRect.y1 = pos.y;
|
|
|
|
|
if (!e.isAltPressed()) {
|
|
|
|
|
m_selectingRect.x0 = m_startPoint.x;
|
|
|
|
|
m_selectingRect.y0 = m_startPoint.y;
|
|
|
|
|
} else {
|
|
|
|
|
m_selectingRect.x0 = m_startPoint.x + m_startPoint.x - pos.x;
|
|
|
|
|
m_selectingRect.y0 = m_startPoint.y + m_startPoint.y - pos.y;
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *EllipsePrimitive::makeStroke() const {
|
|
|
|
|
if (areAlmostEqual(m_selectingRect.x0, m_selectingRect.x1) ||
|
|
|
|
|
areAlmostEqual(m_selectingRect.y0, m_selectingRect.y1))
|
|
|
|
|
return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return makeEllipticStroke(
|
2020-09-23 15:04:03 +12:00
|
|
|
|
getThickness(), TPointD(0.5 * (m_selectingRect.x0 + m_selectingRect.x1),
|
|
|
|
|
0.5 * (m_selectingRect.y0 + m_selectingRect.y1)),
|
2016-06-15 18:43:10 +12:00
|
|
|
|
fabs(0.5 * (m_selectingRect.x1 - m_selectingRect.x0)),
|
|
|
|
|
fabs(0.5 * (m_selectingRect.y1 - m_selectingRect.y0)));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void EllipsePrimitive::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
m_isEditing = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_tool->addStroke();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void EllipsePrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
m_pos = calculateSnap(pos, e);
|
|
|
|
|
m_pos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_tool->invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void EllipsePrimitive::onEnter() {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
} else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
2020-09-23 15:04:03 +12:00
|
|
|
|
if (style) m_color = style->getAverageColor();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Arc Primitive Class Implementation
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
void MultiArcPrimitive::draw() {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
drawSnap();
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
double pixelSize = m_tool->getPixelSize();
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
switch (m_clickNumber) {
|
|
|
|
|
case 1:
|
|
|
|
|
tglColor(m_color);
|
|
|
|
|
tglDrawSegment(m_startPoint, m_endPoint);
|
2020-07-06 17:32:52 +12:00
|
|
|
|
|
|
|
|
|
if (m_stroke) {
|
|
|
|
|
drawStrokeCenterline(*m_stroke, sqrt(tglGetPixelSize2()));
|
|
|
|
|
TPointD firstPoint = m_stroke->getControlPoint(0);
|
|
|
|
|
if (firstPoint == m_endPoint) {
|
|
|
|
|
tglColor(TPixel32((m_color.r + 127) % 255, m_color.g,
|
|
|
|
|
(m_color.b + 127) % 255, m_color.m));
|
|
|
|
|
}
|
|
|
|
|
tglDrawCircle(m_stroke->getControlPoint(0), joinDistance * pixelSize);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
break;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
case 2:
|
2020-07-06 17:32:52 +12:00
|
|
|
|
tglColor(m_isPrompting ? TPixel32::Green : m_color);
|
|
|
|
|
if (!m_isPrompting) {
|
|
|
|
|
glLineStipple(1, 0x5555);
|
|
|
|
|
glEnable(GL_LINE_STIPPLE);
|
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
|
tglVertex(m_startPoint);
|
|
|
|
|
tglVertex(m_centralPoint);
|
|
|
|
|
tglVertex(m_endPoint);
|
|
|
|
|
glEnd();
|
|
|
|
|
glDisable(GL_LINE_STIPPLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_stroke) drawStrokeCenterline(*m_stroke, sqrt(tglGetPixelSize2()));
|
|
|
|
|
|
|
|
|
|
if (m_strokeTemp)
|
|
|
|
|
drawStrokeCenterline(*m_strokeTemp, sqrt(tglGetPixelSize2()));
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (m_stroke) {
|
2020-07-06 17:32:52 +12:00
|
|
|
|
TPointD firstPoint = m_stroke->getControlPoint(0);
|
|
|
|
|
if (firstPoint == m_endPoint) {
|
|
|
|
|
tglColor(TPixel32((m_color.r + 127) % 255, m_color.g,
|
|
|
|
|
(m_color.b + 127) % 255, m_color.m));
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2020-07-06 17:32:52 +12:00
|
|
|
|
tglDrawCircle(m_stroke->getControlPoint(0), joinDistance * pixelSize);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
};
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
TStroke *MultiArcPrimitive::makeStroke() const {
|
|
|
|
|
return new TStroke(*m_stroke);
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2021-03-28 21:34:35 +13:00
|
|
|
|
void MultiArcPrimitive::leftButtonDown(const TPointD &pos,
|
2021-03-29 15:11:27 +13:00
|
|
|
|
const TMouseEvent &e) {
|
2021-03-28 21:34:35 +13:00
|
|
|
|
if (m_clickNumber == 0) {
|
2021-03-29 15:11:27 +13:00
|
|
|
|
TPointD newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2021-03-28 21:34:35 +13:00
|
|
|
|
m_startPoint = newPos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
void MultiArcPrimitive::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
TPointD newPos = getSnap(pos);
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
std::vector<TThickPoint> points(9);
|
2020-07-12 15:03:15 +12:00
|
|
|
|
double thick = getThickness();
|
|
|
|
|
double dist = joinDistance * joinDistance;
|
|
|
|
|
bool strokeAdded = false;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
MultiArcPrimitiveUndo *undo =
|
|
|
|
|
new MultiArcPrimitiveUndo(this, m_stroke, m_strokeTemp, m_startPoint,
|
|
|
|
|
m_endPoint, m_centralPoint, m_clickNumber);
|
|
|
|
|
|
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_isEditing = true;
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
} else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
|
|
|
|
if (style) {
|
|
|
|
|
m_isEditing = style->isStrokeStyle();
|
|
|
|
|
m_color = style->getAverageColor();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
} else {
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_color = TPixel32::Black;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2020-07-06 17:32:52 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (m_clickNumber) {
|
|
|
|
|
case 0:
|
|
|
|
|
m_endPoint = newPos;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
|
|
|
|
|
m_clickNumber++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_centralPoint = newPos;
|
|
|
|
|
points[0] = TThickPoint(m_startPoint, thick);
|
|
|
|
|
points[8] = TThickPoint(m_endPoint, thick);
|
|
|
|
|
points[4] = TThickPoint(0.5 * (points[0] + points[8]), thick);
|
|
|
|
|
points[2] = TThickPoint(0.5 * (points[0] + points[4]), thick);
|
|
|
|
|
points[6] = TThickPoint(0.5 * (points[4] + points[8]), thick);
|
|
|
|
|
|
|
|
|
|
points[1] = TThickPoint(0.5 * (points[0] + points[2]), thick);
|
|
|
|
|
points[3] = TThickPoint(0.5 * (points[2] + points[4]), thick);
|
|
|
|
|
points[5] = TThickPoint(0.5 * (points[4] + points[6]), thick);
|
|
|
|
|
points[7] = TThickPoint(0.5 * (points[6] + points[8]), thick);
|
|
|
|
|
m_strokeTemp = new TStroke(points);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_clickNumber++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_startPoint = newPos;
|
|
|
|
|
if (!m_isSingleArc) {
|
|
|
|
|
m_clickNumber = 1;
|
|
|
|
|
if (m_stroke) {
|
|
|
|
|
TVectorImageP vi = new TVectorImage();
|
|
|
|
|
vi->addStroke(m_stroke);
|
|
|
|
|
vi->addStroke(m_strokeTemp);
|
|
|
|
|
m_strokeTemp = 0;
|
|
|
|
|
vi->joinStroke(0, 1, m_stroke->getControlPointCount() - 1, 0,
|
|
|
|
|
getSmooth());
|
|
|
|
|
|
|
|
|
|
m_stroke = new TStroke(*vi->getStroke(0));
|
|
|
|
|
int count = m_stroke->getControlPointCount();
|
|
|
|
|
TPointD firstPoint = m_stroke->getControlPoint(0);
|
|
|
|
|
TPointD lastPoint = m_stroke->getControlPoint(count - 1);
|
|
|
|
|
m_startPoint = lastPoint;
|
|
|
|
|
if (firstPoint == lastPoint) {
|
|
|
|
|
vi->joinStroke(0, 0, 0, m_stroke->getControlPointCount() - 1,
|
|
|
|
|
getSmooth());
|
|
|
|
|
delete m_stroke;
|
|
|
|
|
m_stroke = new TStroke(*vi->getStroke(0));
|
|
|
|
|
TUndoManager::manager()->popUndo(m_undoCount);
|
|
|
|
|
m_undoCount = 0;
|
|
|
|
|
m_tool->addStroke();
|
|
|
|
|
onDeactivate();
|
2020-07-12 15:03:15 +12:00
|
|
|
|
strokeAdded = true;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m_stroke = m_strokeTemp;
|
|
|
|
|
m_strokeTemp = 0;
|
|
|
|
|
m_startPoint = m_endPoint;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m_stroke = m_strokeTemp;
|
|
|
|
|
m_strokeTemp = 0;
|
|
|
|
|
TUndoManager::manager()->popUndo(m_undoCount);
|
|
|
|
|
m_undoCount = 0;
|
|
|
|
|
m_tool->addStroke();
|
|
|
|
|
onDeactivate();
|
2020-07-12 15:03:15 +12:00
|
|
|
|
strokeAdded = true;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-07-06 17:32:52 +12:00
|
|
|
|
|
2020-07-12 15:03:15 +12:00
|
|
|
|
if (strokeAdded) {
|
|
|
|
|
delete undo;
|
|
|
|
|
} else {
|
|
|
|
|
undo->setRedoData(m_stroke, m_strokeTemp, m_startPoint, m_endPoint,
|
|
|
|
|
m_centralPoint, m_clickNumber);
|
|
|
|
|
TUndoManager::manager()->add(undo);
|
|
|
|
|
++m_undoCount;
|
|
|
|
|
}
|
2020-07-06 17:32:52 +12:00
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
resetSnap();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
void MultiArcPrimitive::leftButtonDoubleClick(const TPointD &,
|
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
|
if (m_stroke) {
|
|
|
|
|
TUndoManager::manager()->popUndo(m_undoCount);
|
|
|
|
|
m_undoCount = 0;
|
|
|
|
|
m_tool->addStroke();
|
|
|
|
|
}
|
|
|
|
|
onDeactivate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
bool MultiArcPrimitive::keyDown(QKeyEvent *event) {
|
|
|
|
|
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
|
|
|
|
|
if (m_stroke) {
|
|
|
|
|
TUndoManager::manager()->popUndo(m_undoCount);
|
|
|
|
|
m_undoCount = 0;
|
|
|
|
|
m_tool->addStroke();
|
|
|
|
|
}
|
|
|
|
|
onDeactivate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void MultiArcPrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
double dist = joinDistance * joinDistance;
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
switch (m_clickNumber) {
|
2020-07-06 17:32:52 +12:00
|
|
|
|
case 0:
|
|
|
|
|
m_startPoint = newPos;
|
|
|
|
|
break;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
case 1:
|
2020-10-06 03:11:08 +13:00
|
|
|
|
if (e.isShiftPressed() && !e.isCtrlPressed())
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_endPoint = rectify(m_startPoint, pos);
|
|
|
|
|
else
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_endPoint = newPos;
|
2020-07-06 17:32:52 +12:00
|
|
|
|
|
|
|
|
|
if (m_stroke) {
|
|
|
|
|
TPointD firstPoint = m_stroke->getControlPoint(0);
|
|
|
|
|
if (tdistance2(m_endPoint, firstPoint) < dist * m_tool->getPixelSize())
|
|
|
|
|
m_endPoint = firstPoint;
|
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_centralPoint = newPos;
|
|
|
|
|
TThickQuadratic q(m_startPoint, TThickPoint(m_centralPoint, getThickness()),
|
|
|
|
|
m_endPoint);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TThickQuadratic q0, q1, q00, q01, q10, q11;
|
|
|
|
|
|
|
|
|
|
q.split(0.5, q0, q1);
|
|
|
|
|
q0.split(0.5, q00, q01);
|
|
|
|
|
q1.split(0.5, q10, q11);
|
|
|
|
|
|
|
|
|
|
assert(q00.getP2() == q01.getP0());
|
|
|
|
|
assert(q01.getP2() == q10.getP0());
|
|
|
|
|
assert(q10.getP2() == q11.getP0());
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
m_strokeTemp->setControlPoint(1, q00.getP1());
|
|
|
|
|
m_strokeTemp->setControlPoint(2, q00.getP2());
|
|
|
|
|
m_strokeTemp->setControlPoint(3, q01.getP1());
|
|
|
|
|
m_strokeTemp->setControlPoint(4, q01.getP2());
|
|
|
|
|
m_strokeTemp->setControlPoint(5, q10.getP1());
|
|
|
|
|
m_strokeTemp->setControlPoint(6, q10.getP2());
|
|
|
|
|
m_strokeTemp->setControlPoint(7, q11.getP1());
|
2016-06-15 18:43:10 +12:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_tool->invalidate();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2020-07-06 17:32:52 +12:00
|
|
|
|
void MultiArcPrimitive::onEnter() {
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (app->getCurrentObject()->isSpline())
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
2020-09-23 15:04:03 +12:00
|
|
|
|
if (style) m_color = style->getAverageColor();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Polygon Primitive Class Declaration
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void PolygonPrimitive::draw() {
|
2017-08-23 00:11:38 +12:00
|
|
|
|
drawSnap();
|
2016-06-15 18:43:10 +12:00
|
|
|
|
if (!m_isEditing && !m_isPrompting) return;
|
|
|
|
|
tglColor(m_isEditing ? m_color : TPixel32::Green);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
int edgeCount = m_param->m_edgeCount.getValue();
|
|
|
|
|
if (edgeCount == 0) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
double angleDiff = M_2PI / edgeCount;
|
|
|
|
|
double angle = (3 * M_PI + angleDiff) * 0.5;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
glBegin(GL_LINE_LOOP);
|
|
|
|
|
for (int i = 0; i < edgeCount; i++) {
|
|
|
|
|
tglVertex(m_centre + TPointD(cos(angle) * m_radius, sin(angle) * m_radius));
|
|
|
|
|
angle += angleDiff;
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void PolygonPrimitive::leftButtonDown(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
TTool::Application *app = TTool::getApplication();
|
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
|
|
if (app->getCurrentObject()->isSpline()) {
|
|
|
|
|
m_isEditing = true;
|
|
|
|
|
m_color = TPixel32::Red;
|
|
|
|
|
} else {
|
|
|
|
|
const TColorStyle *style = app->getCurrentLevelStyle();
|
|
|
|
|
if (style) {
|
|
|
|
|
m_isEditing = style->isStrokeStyle();
|
|
|
|
|
m_color = style->getAverageColor();
|
|
|
|
|
} else {
|
|
|
|
|
m_isEditing = false;
|
|
|
|
|
m_color = TPixel32::Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_centre = getSnap(pos);
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_radius = 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void PolygonPrimitive::leftButtonDrag(const TPointD &pos,
|
|
|
|
|
const TMouseEvent &e) {
|
|
|
|
|
if (!m_isEditing) return;
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2018-02-19 19:34:13 +13:00
|
|
|
|
m_radius = tdistance(m_centre, newPos);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
TStroke *PolygonPrimitive::makeStroke() const {
|
|
|
|
|
double thick = getThickness();
|
|
|
|
|
|
|
|
|
|
int edgeCount = m_param->m_edgeCount.getValue();
|
|
|
|
|
if (edgeCount == 0) return 0;
|
|
|
|
|
|
|
|
|
|
double angleDiff = M_2PI / (double)edgeCount;
|
|
|
|
|
double angle = (3 * M_PI + angleDiff) * 0.5;
|
|
|
|
|
|
|
|
|
|
TStroke *stroke = 0;
|
|
|
|
|
if (m_param->m_targetType & TTool::Vectors) {
|
|
|
|
|
std::vector<TThickPoint> points(4 * edgeCount + 1);
|
|
|
|
|
int i;
|
|
|
|
|
// Posiziono gli angoli
|
|
|
|
|
for (i = 0; i <= (int)points.size(); i += 4) {
|
|
|
|
|
points[i] = TThickPoint(
|
|
|
|
|
m_centre + TPointD(cos(angle) * m_radius, sin(angle) * m_radius),
|
|
|
|
|
thick);
|
|
|
|
|
angle += angleDiff;
|
|
|
|
|
}
|
|
|
|
|
// posiziono i punti medi e i punti per gestire la linearita'
|
|
|
|
|
for (i = 0; i < (int)points.size() - 1; i += 4) {
|
|
|
|
|
TPointD vertex = convert(points[i]);
|
|
|
|
|
TPointD nextVertex = convert(points[i + 4]);
|
|
|
|
|
TPointD speed = computeSpeed(vertex, nextVertex, 0.01);
|
|
|
|
|
TPointD speedOutPoint = vertex + speed;
|
|
|
|
|
TPointD speedInNextPoint = nextVertex - speed;
|
|
|
|
|
TPointD middlePoint = 0.5 * (speedOutPoint + speedInNextPoint);
|
|
|
|
|
points[i + 1] = TThickPoint(speedOutPoint, thick);
|
|
|
|
|
points[i + 2] = TThickPoint(middlePoint, thick);
|
|
|
|
|
points[i + 3] = TThickPoint(speedInNextPoint, thick);
|
|
|
|
|
}
|
|
|
|
|
stroke = new TStroke(points);
|
|
|
|
|
} else if (m_param->m_targetType & TTool::ToonzImage ||
|
|
|
|
|
m_param->m_targetType & TTool::RasterImage) {
|
|
|
|
|
std::vector<TThickPoint> points(edgeCount + edgeCount + 1);
|
|
|
|
|
points[0] = TThickPoint(
|
|
|
|
|
m_centre + TPointD(cos(angle) * m_radius, sin(angle) * m_radius),
|
|
|
|
|
thick);
|
|
|
|
|
for (int i = 1; i <= edgeCount; i++) {
|
|
|
|
|
angle += angleDiff;
|
|
|
|
|
points[i + i] = TThickPoint(
|
|
|
|
|
m_centre + TPointD(cos(angle) * m_radius, sin(angle) * m_radius),
|
|
|
|
|
thick);
|
|
|
|
|
points[i + i - 1] = (points[i + i - 2] + points[i + i]) * 0.5;
|
|
|
|
|
}
|
|
|
|
|
stroke = new TStroke(points);
|
|
|
|
|
}
|
|
|
|
|
stroke->setSelfLoop();
|
|
|
|
|
return stroke;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void PolygonPrimitive::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
|
|
|
|
if (!m_isEditing) return;
|
|
|
|
|
m_isEditing = false;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
m_tool->addStroke();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
2017-08-23 00:11:38 +12:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void PolygonPrimitive::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
2020-10-06 03:11:08 +13:00
|
|
|
|
TPointD newPos = calculateSnap(pos, e);
|
|
|
|
|
newPos = checkGuideSnapping(pos, e);
|
2017-08-23 00:11:38 +12:00
|
|
|
|
m_tool->invalidate();
|
2020-07-06 17:32:52 +12:00
|
|
|
|
}
|