|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "brushtool.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzTools includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/tooloptions.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "bluredbrush.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/imageutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tobjecthandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tcolumnhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheet.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tstageobject.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tstageobjectspline.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/rasterstrokegenerator.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/ttileset.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/toonzimageutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/palettecontroller.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/stage2.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tstream.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tregion.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstroke.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qpainter></qpainter>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace ToolUtils;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar VectorBrushMinSize("InknpaintVectorBrushMinSize", 1);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar VectorBrushMaxSize("InknpaintVectorBrushMaxSize", 5);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar VectorCapStyle("InknpaintVectorCapStyle", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar VectorJoinStyle("InknpaintVectorJoinStyle", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar VectorMiterValue("InknpaintVectorMiterValue", 4);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar RasterBrushMinSize("InknpaintRasterBrushMinSize", 1);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar RasterBrushMaxSize("InknpaintRasterBrushMaxSize", 5);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar BrushAccuracy("InknpaintBrushAccuracy", 20);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar BrushSelective("InknpaintBrushSelective", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar BrushBreakSharpAngles("InknpaintBrushBreakSharpAngles", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar RasterBrushPencilMode("InknpaintRasterBrushPencilMode", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar BrushPressureSensibility("InknpaintBrushPressureSensibility", 1);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar RasterBrushHardness("RasterBrushHardness", 100);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define ROUNDC_WSTR L"round_cap"
|
|
Toshihiro Shimizu |
890ddd |
#define BUTT_WSTR L"butt_cap"
|
|
Toshihiro Shimizu |
890ddd |
#define PROJECTING_WSTR L"projecting_cap"
|
|
Toshihiro Shimizu |
890ddd |
#define ROUNDJ_WSTR L"round_join"
|
|
Toshihiro Shimizu |
890ddd |
#define BEVEL_WSTR L"bevel_join"
|
|
Toshihiro Shimizu |
890ddd |
#define MITER_WSTR L"miter_join"
|
|
Toshihiro Shimizu |
890ddd |
#define CUSTOM_WSTR L"<custom>"</custom>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// (Da mettere in libreria) : funzioni che spezzano una stroke
|
|
Toshihiro Shimizu |
890ddd |
// nei suoi punti angolosi. Lo facciamo specialmente per limitare
|
|
Toshihiro Shimizu |
890ddd |
// i problemi di fill.
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Split a stroke in n+1 parts, according to n parameter values
|
|
Toshihiro Shimizu |
890ddd |
// Input:
|
|
Toshihiro Shimizu |
890ddd |
// stroke = stroke to split
|
|
Toshihiro Shimizu |
890ddd |
// parameterValues[] = vector of parameters where I want to split the stroke
|
|
Toshihiro Shimizu |
890ddd |
// assert: 0
|
|
Toshihiro Shimizu |
890ddd |
// Output:
|
|
Toshihiro Shimizu |
890ddd |
// strokes[] = the split strokes
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// note: stroke is unchanged
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void split(
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke,
|
|
Shinya Kitaoka |
3bfa54 |
const std::vector<double> ¶meterValues,</double>
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tstroke *=""> &strokes)</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p2;
|
|
Toshihiro Shimizu |
890ddd |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint lastPoint = stroke->getControlPoint(0);
|
|
Toshihiro Shimizu |
890ddd |
int n = parameterValues.size();
|
|
Toshihiro Shimizu |
890ddd |
int chunk;
|
|
Toshihiro Shimizu |
890ddd |
double t;
|
|
Toshihiro Shimizu |
890ddd |
int last_chunk = -1, startPoint = 0;
|
|
Toshihiro Shimizu |
890ddd |
double lastLocT = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < n; i++) {
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(lastPoint); // Add first point of the stroke
|
|
Toshihiro Shimizu |
890ddd |
double w = parameterValues[i]; // Global parameter. along the stroke 0<=w<=1
|
|
Toshihiro Shimizu |
890ddd |
stroke->getChunkAndT(w, chunk, t); // t: local parameter in the chunk-th quadratic
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (i == 0)
|
|
Toshihiro Shimizu |
890ddd |
startPoint = 1;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
int indexAfterLastT =
|
|
Toshihiro Shimizu |
890ddd |
stroke->getControlPointIndexAfterParameter(parameterValues[i - 1]);
|
|
Toshihiro Shimizu |
890ddd |
startPoint = indexAfterLastT;
|
|
Toshihiro Shimizu |
890ddd |
if ((indexAfterLastT & 1) && lastLocT != 1)
|
|
Toshihiro Shimizu |
890ddd |
startPoint++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int endPoint = 2 * chunk + 1;
|
|
Toshihiro Shimizu |
890ddd |
if (lastLocT != 1 && i > 0) {
|
|
Toshihiro Shimizu |
890ddd |
if (last_chunk != chunk || t == 1)
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(p2); // If the last local t is not an extreme
|
|
Toshihiro Shimizu |
890ddd |
// add the point p2
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int j = startPoint; j < endPoint; j++)
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(stroke->getControlPoint(j));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p, A, B, C;
|
|
Toshihiro Shimizu |
890ddd |
p = stroke->getPoint(w);
|
|
Toshihiro Shimizu |
890ddd |
C = stroke->getControlPoint(2 * chunk + 2);
|
|
Toshihiro Shimizu |
890ddd |
B = stroke->getControlPoint(2 * chunk + 1);
|
|
Toshihiro Shimizu |
890ddd |
A = stroke->getControlPoint(2 * chunk);
|
|
Toshihiro Shimizu |
890ddd |
p.thick = A.thick;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (last_chunk != chunk) {
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p1 = (1 - t) * A + t * B;
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(p1);
|
|
Toshihiro Shimizu |
890ddd |
p.thick = p1.thick;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (t != 1) {
|
|
Toshihiro Shimizu |
890ddd |
// If the i-th cut point belong to the same chunk of the (i-1)-th cut point.
|
|
Toshihiro Shimizu |
890ddd |
double tInters = lastLocT / t;
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p11 = (1 - t) * A + t * B;
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p1 = (1 - tInters) * p11 + tInters * p;
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(p1);
|
|
Toshihiro Shimizu |
890ddd |
p.thick = p1.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (t != 1)
|
|
Toshihiro Shimizu |
890ddd |
p2 = (1 - t) * B + t * C;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(points.size() & 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Add new stroke
|
|
Toshihiro Shimizu |
890ddd |
TStroke *strokeAdd = new TStroke(points);
|
|
Toshihiro Shimizu |
890ddd |
strokeAdd->setStyle(stroke->getStyle());
|
|
Toshihiro Shimizu |
890ddd |
strokeAdd->outlineOptions() = stroke->outlineOptions();
|
|
Toshihiro Shimizu |
890ddd |
strokes.push_back(strokeAdd);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
lastPoint = p;
|
|
Toshihiro Shimizu |
890ddd |
last_chunk = chunk;
|
|
Toshihiro Shimizu |
890ddd |
lastLocT = t;
|
|
Toshihiro Shimizu |
890ddd |
points.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// Add end stroke
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(lastPoint);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (lastLocT != 1)
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(p2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
startPoint = stroke->getControlPointIndexAfterParameter(parameterValues[n - 1]);
|
|
Toshihiro Shimizu |
890ddd |
if ((stroke->getControlPointIndexAfterParameter(parameterValues[n - 1]) & 1) && lastLocT != 1)
|
|
Toshihiro Shimizu |
890ddd |
startPoint++;
|
|
Toshihiro Shimizu |
890ddd |
for (int j = startPoint; j < stroke->getControlPointCount(); j++)
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(stroke->getControlPoint(j));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(points.size() & 1);
|
|
Toshihiro Shimizu |
890ddd |
TStroke *strokeAdd = new TStroke(points);
|
|
Toshihiro Shimizu |
890ddd |
strokeAdd->setStyle(stroke->getStyle());
|
|
Toshihiro Shimizu |
890ddd |
strokeAdd->outlineOptions() = stroke->outlineOptions();
|
|
Toshihiro Shimizu |
890ddd |
strokes.push_back(strokeAdd);
|
|
Toshihiro Shimizu |
890ddd |
points.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Compute Parametric Curve Curvature
|
|
Toshihiro Shimizu |
890ddd |
//By Formula:
|
|
Toshihiro Shimizu |
890ddd |
// k(t)=(|p'(t) x p''(t)|)/Norm2(p')^3
|
|
Toshihiro Shimizu |
890ddd |
// p(t) is parametric curve
|
|
Toshihiro Shimizu |
890ddd |
// Input:
|
|
Toshihiro Shimizu |
890ddd |
// dp = First Derivate.
|
|
Toshihiro Shimizu |
890ddd |
// ddp = Second Derivate
|
|
Toshihiro Shimizu |
890ddd |
// Output:
|
|
Toshihiro Shimizu |
890ddd |
// return curvature value.
|
|
Toshihiro Shimizu |
890ddd |
// Note: if the curve is a single point (that's dp=0) or it is a straight line (that's ddp=0) return 0
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double curvature(TPointD dp, TPointD ddp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (dp == TPointD(0, 0))
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return fabs(cross(dp, ddp) / pow(norm2(dp), 1.5));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Find the max curvature points of a stroke.
|
|
Toshihiro Shimizu |
890ddd |
// Input:
|
|
Toshihiro Shimizu |
890ddd |
// stroke.
|
|
Toshihiro Shimizu |
890ddd |
// angoloLim = Value (radians) of the Corner between two tangent vector.
|
|
Toshihiro Shimizu |
890ddd |
// Up this value the two corner can be considered angular.
|
|
Toshihiro Shimizu |
890ddd |
// curvMaxLim = Value of the max curvature.
|
|
Toshihiro Shimizu |
890ddd |
// Up this value the point can be considered a max curvature point.
|
|
Toshihiro Shimizu |
890ddd |
// Output:
|
|
Toshihiro Shimizu |
890ddd |
// parameterValues = vector of max curvature parameter points
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void findMaxCurvPoints(
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke,
|
|
Toshihiro Shimizu |
890ddd |
const float &angoloLim,
|
|
Toshihiro Shimizu |
890ddd |
const float &curvMaxLim,
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<double> ¶meterValues)</double>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD tg1, tg2; // Tangent vectors
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD dp, ddp; // First and Second derivate.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
parameterValues.clear();
|
|
Toshihiro Shimizu |
890ddd |
int cpn = stroke ? stroke->getControlPointCount() : 0;
|
|
Toshihiro Shimizu |
890ddd |
for (int j = 2; j < cpn; j += 2) {
|
|
Toshihiro Shimizu |
890ddd |
TPointD p0 = stroke->getControlPoint(j - 2);
|
|
Toshihiro Shimizu |
890ddd |
TPointD p1 = stroke->getControlPoint(j - 1);
|
|
Toshihiro Shimizu |
890ddd |
TPointD p2 = stroke->getControlPoint(j);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD q = p1 - (p0 + p2) * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Search corner point
|
|
Toshihiro Shimizu |
890ddd |
if (j > 2) {
|
|
Toshihiro Shimizu |
890ddd |
tg2 = -p0 + p2 + 2 * q; // Tangent vector to this chunk at t=0
|
|
Toshihiro Shimizu |
890ddd |
double prod_scal = tg2 * tg1; // Inner product between tangent vectors at t=0.
|
|
Toshihiro Shimizu |
890ddd |
assert(tg1 != TPointD(0, 0) || tg2 != TPointD(0, 0));
|
|
Toshihiro Shimizu |
890ddd |
// Compute corner between two tangent vectors
|
|
Toshihiro Shimizu |
890ddd |
double angolo = acos(prod_scal / (pow(norm2(tg2), 0.5) * pow(norm2(tg1), 0.5)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Add corner point
|
|
Toshihiro Shimizu |
890ddd |
if (angolo > angoloLim) {
|
|
Toshihiro Shimizu |
890ddd |
double w = getWfromChunkAndT(stroke, (UINT)(0.5 * (j - 2)), 0); // transform lacal t to global t
|
|
Toshihiro Shimizu |
890ddd |
parameterValues.push_back(w);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
tg1 = -p0 + p2 - 2 * q; // Tangent vector to this chunk at t=1
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// End search corner point
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Search max curvature point
|
|
Toshihiro Shimizu |
890ddd |
// Value of t where the curvature function has got an extreme.
|
|
Toshihiro Shimizu |
890ddd |
// (Point where first derivate is null)
|
|
Toshihiro Shimizu |
890ddd |
double estremo_int = 0;
|
|
Toshihiro Shimizu |
890ddd |
double t = -1;
|
|
Toshihiro Shimizu |
890ddd |
if (q != TPointD(0, 0)) {
|
|
Toshihiro Shimizu |
890ddd |
t = 0.25 * (2 * q.x * q.x + 2 * q.y * q.y - q.x * p0.x + q.x * p2.x - q.y * p0.y + q.y * p2.y) / (q.x * q.x + q.y * q.y);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
dp = -p0 + p2 + 2 * q - 4 * t * q; // First derivate of the curve
|
|
Toshihiro Shimizu |
890ddd |
ddp = -4 * q; // Second derivate of the curve
|
|
Toshihiro Shimizu |
890ddd |
estremo_int = curvature(dp, ddp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double h = 0.01;
|
|
Toshihiro Shimizu |
890ddd |
dp = -p0 + p2 + 2 * q - 4 * (t + h) * q;
|
|
Toshihiro Shimizu |
890ddd |
double c_dx = curvature(dp, ddp);
|
|
Toshihiro Shimizu |
890ddd |
dp = -p0 + p2 + 2 * q - 4 * (t - h) * q;
|
|
Toshihiro Shimizu |
890ddd |
double c_sx = curvature(dp, ddp);
|
|
Toshihiro Shimizu |
890ddd |
// Check the point is a max and not a minimum
|
|
Toshihiro Shimizu |
890ddd |
if (estremo_int < c_dx && estremo_int < c_sx) {
|
|
Toshihiro Shimizu |
890ddd |
estremo_int = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
double curv_max = estremo_int;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Compute curvature at the extreme of interval [0,1]
|
|
Toshihiro Shimizu |
890ddd |
//Compute curvature at t=0 (Left extreme)
|
|
Toshihiro Shimizu |
890ddd |
dp = -p0 + p2 + 2 * q;
|
|
Toshihiro Shimizu |
890ddd |
double estremo_sx = curvature(dp, ddp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Compute curvature at t=1 (Right extreme)
|
|
Toshihiro Shimizu |
890ddd |
dp = -p0 + p2 - 2 * q;
|
|
Toshihiro Shimizu |
890ddd |
double estremo_dx = curvature(dp, ddp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Compare curvature at the extreme of interval [0,1] with the internal value
|
|
Toshihiro Shimizu |
890ddd |
double t_ext;
|
|
Toshihiro Shimizu |
890ddd |
if (estremo_sx >= estremo_dx)
|
|
Toshihiro Shimizu |
890ddd |
t_ext = 0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
t_ext = 1;
|
|
Toshihiro Shimizu |
890ddd |
double maxEstremi = tmax(estremo_dx, estremo_sx);
|
|
Toshihiro Shimizu |
890ddd |
if (maxEstremi > estremo_int) {
|
|
Toshihiro Shimizu |
890ddd |
t = t_ext;
|
|
Toshihiro Shimizu |
890ddd |
curv_max = maxEstremi;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Add max curvature point
|
|
Toshihiro Shimizu |
890ddd |
if (t >= 0 && t <= 1 && curv_max > curvMaxLim) {
|
|
Toshihiro Shimizu |
890ddd |
double w = getWfromChunkAndT(stroke, (UINT)(0.5 * (j - 2)), t); // transform local t to global t
|
|
Toshihiro Shimizu |
890ddd |
parameterValues.push_back(w);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// End search max curvature point
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// Delete duplicate of parameterValues
|
|
Toshihiro Shimizu |
890ddd |
// Because some max cuvature point can coincide with the corner point
|
|
Toshihiro Shimizu |
890ddd |
if ((int)parameterValues.size() > 1) {
|
|
Toshihiro Shimizu |
890ddd |
std::sort(parameterValues.begin(), parameterValues.end());
|
|
Toshihiro Shimizu |
890ddd |
parameterValues.erase(std::unique(parameterValues.begin(), parameterValues.end()), parameterValues.end());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addStroke(TTool::Application *application, const TVectorImageP &vi, TStroke *stroke, bool breakAngles,
|
|
Toshihiro Shimizu |
890ddd |
bool frameCreated, bool levelCreated)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker lock(vi->getMutex());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (application->getCurrentObject()->isSpline()) {
|
|
Toshihiro Shimizu |
890ddd |
application->getCurrentXsheet()->notifyXsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::vector<double> corners;</double>
|
|
Toshihiro Shimizu |
890ddd |
std::vector<tstroke *=""> strokes;</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const float angoloLim = 1; // Value (radians) of the Corner between two tangent vector.
|
|
Toshihiro Shimizu |
890ddd |
// Up this value the two corner can be considered angular.
|
|
Toshihiro Shimizu |
890ddd |
const float curvMaxLim = 0.8; // Value of the max curvature.
|
|
Toshihiro Shimizu |
890ddd |
// Up this value the point can be considered a max curvature point.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
findMaxCurvPoints(stroke, angoloLim, curvMaxLim, corners);
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *sl = application->getCurrentLevel()->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
TFrameId id = application->getCurrentTool()->getTool()->getCurrentFid();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!corners.empty()) {
|
|
Toshihiro Shimizu |
890ddd |
if (breakAngles)
|
|
Toshihiro Shimizu |
890ddd |
split(stroke, corners, strokes);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
strokes.push_back(new TStroke(*stroke));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int n = strokes.size();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->beginBlock();
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < n; i++) {
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tfilledregioninf> *fillInformation = new std::vector<tfilledregioninf>;</tfilledregioninf></tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
ImageUtils::getFillingInformationOverlappingArea(vi, *fillInformation, stroke->getBBox());
|
|
Toshihiro Shimizu |
890ddd |
TStroke *str = new TStroke(*strokes[i]);
|
|
Toshihiro Shimizu |
890ddd |
vi->addStroke(str);
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(new UndoPencil(str, fillInformation, sl, id, frameCreated, levelCreated));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->endBlock();
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tfilledregioninf> *fillInformation = new std::vector<tfilledregioninf>;</tfilledregioninf></tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
ImageUtils::getFillingInformationOverlappingArea(vi, *fillInformation, stroke->getBBox());
|
|
Toshihiro Shimizu |
890ddd |
TStroke *str = new TStroke(*stroke);
|
|
Toshihiro Shimizu |
890ddd |
vi->addStroke(str);
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(new UndoPencil(str, fillInformation, sl, id, frameCreated, levelCreated));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < (int)strokes.size(); k++)
|
|
Toshihiro Shimizu |
890ddd |
delete strokes[k];
|
|
Toshihiro Shimizu |
890ddd |
strokes.clear();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
application->getCurrentTool()->getTool()->notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Gennaro: end
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Helper functions and classes
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addStrokeToImage(TTool::Application *application, const TVectorImageP &vi, TStroke *stroke, bool breakAngles,
|
|
Toshihiro Shimizu |
890ddd |
bool frameCreated, bool levelCreated)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker lock(vi->getMutex());
|
|
Toshihiro Shimizu |
890ddd |
addStroke(application, vi.getPointer(), stroke, breakAngles, frameCreated, levelCreated);
|
|
Toshihiro Shimizu |
890ddd |
//la notifica viene gia fatta da addStroke!
|
|
Toshihiro Shimizu |
890ddd |
//getApplication()->getCurrentTool()->getTool()->notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class RasterBrushUndo : public TRasterUndo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> m_points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
int m_styleId;
|
|
Toshihiro Shimizu |
890ddd |
bool m_selective;
|
|
Toshihiro Shimizu |
890ddd |
bool m_isPencil;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
RasterBrushUndo(TTileSetCM32 *tileSet,
|
|
Shinya Kitaoka |
3bfa54 |
const std::vector<tthickpoint> &points,</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
int styleId, bool selective,
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *level, const TFrameId &frameId, bool isPencil,
|
|
Toshihiro Shimizu |
890ddd |
bool isFrameCreated, bool isLevelCreated)
|
|
Toshihiro Shimizu |
890ddd |
: TRasterUndo(tileSet, level, frameId, isFrameCreated, isLevelCreated, 0), m_points(points), m_styleId(styleId), m_selective(selective), m_isPencil(isPencil)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void redo() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
insertLevelAndFrameIfNeeded();
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP image = getImage();
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P ras = image->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
RasterStrokeGenerator m_rasterTrack(ras, BRUSH, NONE, m_styleId, m_points[0], m_selective, 0, !m_isPencil);
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack.setPointsSequence(m_points);
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack.generateStroke(m_isPencil);
|
|
Toshihiro Shimizu |
890ddd |
image->setSavebox(image->getSavebox() + m_rasterTrack.getBBox(m_rasterTrack.getPointsSequence()));
|
|
Toshihiro Shimizu |
890ddd |
ToolUtils::updateSaveBox();
|
|
Toshihiro Shimizu |
890ddd |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getSize() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return sizeof(*this) + TRasterUndo::getSize();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
QString getToolName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QString("Brush Tool");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int getHistoryType()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return HistoryType::BrushTool;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class RasterBluredBrushUndo : public TRasterUndo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> m_points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
int m_styleId;
|
|
Toshihiro Shimizu |
890ddd |
bool m_selective;
|
|
Toshihiro Shimizu |
890ddd |
int m_maxThick;
|
|
Toshihiro Shimizu |
890ddd |
double m_hardness;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
3bfa54 |
RasterBluredBrushUndo(TTileSetCM32 *tileSet, const std::vector<tthickpoint> &points,</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
int styleId, bool selective, TXshSimpleLevel *level, const TFrameId &frameId,
|
|
Toshihiro Shimizu |
890ddd |
int maxThick, double hardness, bool isFrameCreated, bool isLevelCreated)
|
|
Toshihiro Shimizu |
890ddd |
: TRasterUndo(tileSet, level, frameId, isFrameCreated, isLevelCreated, 0), m_points(points), m_styleId(styleId), m_selective(selective), m_maxThick(maxThick), m_hardness(hardness)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void redo() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_points.size() == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
insertLevelAndFrameIfNeeded();
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP image = getImage();
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P ras = image->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P backupRas = ras->clone();
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P workRaster(ras->getSize());
|
|
Toshihiro Shimizu |
890ddd |
QRadialGradient brushPad = ToolUtils::getBrushPad(m_maxThick, m_hardness);
|
|
Toshihiro Shimizu |
890ddd |
workRaster->clear();
|
|
Toshihiro Shimizu |
890ddd |
BluredBrush brush(workRaster, m_maxThick, brushPad, false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[0]);
|
|
Toshihiro Shimizu |
890ddd |
TRect bbox = brush.getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
brush.addPoint(m_points[0], 1);
|
|
Toshihiro Shimizu |
890ddd |
brush.updateDrawing(ras, ras, bbox, m_styleId, m_selective);
|
|
Toshihiro Shimizu |
890ddd |
if (m_points.size() > 1) {
|
|
Toshihiro Shimizu |
890ddd |
points.clear();
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[0]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[1]);
|
|
Toshihiro Shimizu |
890ddd |
bbox = brush.getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
brush.addArc(m_points[0], (m_points[1] + m_points[0]) * 0.5, m_points[1], 1, 1);
|
|
Toshihiro Shimizu |
890ddd |
brush.updateDrawing(ras, backupRas, bbox, m_styleId, m_selective);
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 1; i + 2 < (int)m_points.size(); i = i + 2) {
|
|
Toshihiro Shimizu |
890ddd |
points.clear();
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[i]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[i + 1]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[i + 2]);
|
|
Toshihiro Shimizu |
890ddd |
bbox = brush.getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
brush.addArc(m_points[i], m_points[i + 1], m_points[i + 2], 1, 1);
|
|
Toshihiro Shimizu |
890ddd |
brush.updateDrawing(ras, backupRas, bbox, m_styleId, m_selective);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
ToolUtils::updateSaveBox();
|
|
Toshihiro Shimizu |
890ddd |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getSize() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return sizeof(*this) + TRasterUndo::getSize();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual QString getToolName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QString("Brush Tool");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int getHistoryType()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return HistoryType::BrushTool;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double computeThickness(int pressure, const TDoublePairProperty &property, bool isPath)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isPath)
|
|
Toshihiro Shimizu |
890ddd |
return 0.0;
|
|
Toshihiro Shimizu |
890ddd |
double p = pressure / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
double t = p * p * p;
|
|
Toshihiro Shimizu |
890ddd |
double thick0 = property.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
double thick1 = property.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
if (thick1 < 0.0001)
|
|
Toshihiro Shimizu |
890ddd |
thick0 = thick1 = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
return (thick0 + (thick1 - thick0) * t) * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int computeThickness(int pressure, const TIntPairProperty &property, bool isPath)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isPath)
|
|
Toshihiro Shimizu |
890ddd |
return 0.0;
|
|
Toshihiro Shimizu |
890ddd |
double p = pressure / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
double t = p * p * p;
|
|
Toshihiro Shimizu |
890ddd |
int thick0 = property.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
int thick1 = property.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
return tround(thick0 + (thick1 - thick0) * t);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// BrushTool
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
BrushTool::BrushTool(std::string name, int targetType)
|
|
Toshihiro Shimizu |
890ddd |
: TTool(name), m_thickness("Size", 0, 100, 0, 5), m_rasThickness("Size", 1, 100, 1, 5), m_accuracy("Accuracy:", 1, 100, 20), m_hardness("Hardness:", 0, 100, 100), m_preset("Preset:"), m_selective("Selective", false), m_breakAngles("Break", true), m_pencil("Pencil", false), m_pressure("Pressure", true), m_capStyle("Cap"), m_joinStyle("Join"), m_miterJoinLimit("Miter:", 0, 100, 4), m_rasterTrack(0), m_styleId(0), m_modifiedRegion(), m_bluredBrush(0), m_active(false), m_enabled(false), m_isPrompting(false), m_firstTime(true), m_presetsLoaded(false), m_workingFrameId(TFrameId())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bind(targetType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (targetType & TTool::Vectors) {
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_thickness);
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_accuracy);
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_breakAngles);
|
|
Toshihiro Shimizu |
890ddd |
m_breakAngles.setId("BreakSharpAngles");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (targetType & TTool::ToonzImage) {
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_rasThickness);
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_hardness);
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_selective);
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_pencil);
|
|
Toshihiro Shimizu |
890ddd |
m_pencil.setId("PencilMode");
|
|
Toshihiro Shimizu |
890ddd |
m_selective.setId("Selective");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_pressure);
|
|
Toshihiro Shimizu |
890ddd |
#ifndef STUDENT
|
|
Toshihiro Shimizu |
890ddd |
m_prop[0].bind(m_preset);
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setId("BrushPreset");
|
|
shun_iwasawa |
a50847 |
m_preset.addValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setId("PressureSensibility");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_capStyle.addValue(BUTT_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
m_capStyle.addValue(ROUNDC_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
m_capStyle.addValue(PROJECTING_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
m_capStyle.setId("Cap");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_joinStyle.addValue(MITER_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
m_joinStyle.addValue(ROUNDJ_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
m_joinStyle.addValue(BEVEL_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
m_joinStyle.setId("Join");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_miterJoinLimit.setId("Miter");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (targetType & TTool::Vectors) {
|
|
Toshihiro Shimizu |
890ddd |
m_prop[1].bind(m_capStyle);
|
|
Toshihiro Shimizu |
890ddd |
m_prop[1].bind(m_joinStyle);
|
|
Toshihiro Shimizu |
890ddd |
m_prop[1].bind(m_miterJoinLimit);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ToolOptionsBox *BrushTool::createOptionsBox()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPaletteHandle *currPalette = TTool::getApplication()->getPaletteController()->getCurrentLevelPalette();
|
|
Toshihiro Shimizu |
890ddd |
ToolHandle *currTool = TTool::getApplication()->getCurrentTool();
|
|
Toshihiro Shimizu |
890ddd |
return new BrushToolOptionsBox(0, this, currPalette, currTool);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::drawLine(const TPointD &point, const TPointD ¢re, bool horizontal, bool isDecimal)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!isDecimal) {
|
|
Toshihiro Shimizu |
890ddd |
if (horizontal) {
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 1.5, point.y + 0.5) + centre, TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y - 0.5, -point.x + 1.5) + centre, TPointD(point.y - 0.5, -point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y + 0.5) + centre, TPointD(-point.x - 0.5, -point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre, TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y - 0.5, point.x + 0.5) + centre, TPointD(point.y - 0.5, point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 0.5, -point.y + 0.5) + centre, TPointD(point.x - 1.5, -point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre, TPointD(-point.y - 0.5, -point.x + 1.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x - 0.5, point.y + 0.5) + centre, TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 1.5, point.y + 1.5) + centre, TPointD(point.x - 1.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 1.5, point.y + 0.5) + centre, TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 1.5) + centre, TPointD(point.y - 0.5, -point.x + 1.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y - 0.5, -point.x + 1.5) + centre, TPointD(point.y - 0.5, -point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 0.5) + centre, TPointD(-point.x + 0.5, -point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y + 0.5) + centre, TPointD(-point.x - 0.5, -point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 1.5, point.x - 0.5) + centre, TPointD(-point.y - 0.5, point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre, TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre, TPointD(point.y - 0.5, point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y - 0.5, point.x - 0.5) + centre, TPointD(point.y - 0.5, point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 1.5, -point.y - 0.5) + centre, TPointD(point.x - 1.5, -point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 1.5, -point.y + 0.5) + centre, TPointD(point.x - 0.5, -point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 1.5, -point.x + 1.5) + centre, TPointD(-point.y - 0.5, -point.x + 1.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 1.5) + centre, TPointD(-point.y - 0.5, -point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 1.5) + centre, TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre, TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (horizontal) {
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 0.5, point.y + 0.5) + centre, TPointD(point.x + 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre, TPointD(point.y + 0.5, point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 0.5) + centre, TPointD(point.y + 0.5, -point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x + 0.5, -point.y - 0.5) + centre, TPointD(point.x - 0.5, -point.y - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x - 0.5, -point.y - 0.5) + centre, TPointD(-point.x + 0.5, -point.y - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre, TPointD(-point.y - 0.5, -point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre, TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre, TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 0.5, point.y + 1.5) + centre, TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 0.5, point.y + 0.5) + centre, TPointD(point.x + 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 1.5, point.x - 0.5) + centre, TPointD(point.y + 0.5, point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre, TPointD(point.y + 0.5, point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 1.5, -point.x + 0.5) + centre, TPointD(point.y + 0.5, -point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 0.5) + centre, TPointD(point.y + 0.5, -point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 0.5, -point.y - 1.5) + centre, TPointD(point.x - 0.5, -point.y - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(point.x - 0.5, -point.y - 0.5) + centre, TPointD(point.x + 0.5, -point.y - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 1.5) + centre, TPointD(-point.x + 0.5, -point.y - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 0.5) + centre, TPointD(-point.x - 0.5, -point.y - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 1.5, -point.x + 0.5) + centre, TPointD(-point.y - 0.5, -point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre, TPointD(-point.y - 0.5, -point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 1.5, point.x - 0.5) + centre, TPointD(-point.y - 0.5, point.x - 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre, TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 1.5) + centre, TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre, TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::drawEmptyCircle(TPointD pos, int thick, bool isLxEven, bool isLyEven, bool isPencil)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isLxEven)
|
|
Toshihiro Shimizu |
890ddd |
pos.x += 0.5;
|
|
Toshihiro Shimizu |
890ddd |
if (isLyEven)
|
|
Toshihiro Shimizu |
890ddd |
pos.y += 0.5;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!isPencil)
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(pos, (thick + 1) * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
int x = 0, y = tround((thick * 0.5) - 0.5);
|
|
Toshihiro Shimizu |
890ddd |
int d = 3 - 2 * (int)(thick * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
bool horizontal = true, isDecimal = thick % 2 != 0;
|
|
Toshihiro Shimizu |
890ddd |
drawLine(TPointD(x, y), pos, horizontal, isDecimal);
|
|
Toshihiro Shimizu |
890ddd |
while (y > x) {
|
|
Toshihiro Shimizu |
890ddd |
if (d < 0) {
|
|
Toshihiro Shimizu |
890ddd |
d = d + 4 * x + 6;
|
|
Toshihiro Shimizu |
890ddd |
horizontal = true;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
d = d + 4 * (x - y) + 10;
|
|
Toshihiro Shimizu |
890ddd |
horizontal = false;
|
|
Toshihiro Shimizu |
890ddd |
y--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
x++;
|
|
Toshihiro Shimizu |
890ddd |
drawLine(TPointD(x, y), pos, horizontal, isDecimal);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::updateTranslation()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_thickness.setQStringName(tr("Size"));
|
|
Toshihiro Shimizu |
890ddd |
m_rasThickness.setQStringName(tr("Size"));
|
|
Toshihiro Shimizu |
890ddd |
m_hardness.setQStringName(tr("Hardness:"));
|
|
Toshihiro Shimizu |
890ddd |
m_accuracy.setQStringName(tr("Accuracy:"));
|
|
Toshihiro Shimizu |
890ddd |
m_selective.setQStringName(tr("Selective"));
|
|
Toshihiro Shimizu |
890ddd |
//m_filled.setQStringName(tr("Filled"));
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setQStringName(tr("Preset:"));
|
|
Toshihiro Shimizu |
890ddd |
m_breakAngles.setQStringName(tr("Break"));
|
|
Toshihiro Shimizu |
890ddd |
m_pencil.setQStringName(tr("Pencil"));
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setQStringName(tr("Pressure"));
|
|
Toshihiro Shimizu |
890ddd |
m_capStyle.setQStringName(tr("Cap"));
|
|
Toshihiro Shimizu |
890ddd |
m_joinStyle.setQStringName(tr("Join"));
|
|
Toshihiro Shimizu |
890ddd |
m_miterJoinLimit.setQStringName(tr("Miter:"));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::updateWorkAndBackupRasters(const TRect &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = TImageP(getImage(false, 1));
|
|
Toshihiro Shimizu |
890ddd |
if (!ti)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P ras = ti->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect _rect = rect * ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
TRect _lastRect = m_lastRect * ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (_rect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_lastRect.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
m_workRas->extract(_rect)->clear();
|
|
Toshihiro Shimizu |
890ddd |
m_backupRas->extract(_rect)->copy(ras->extract(_rect));
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QList<trect> rects = ToolUtils::splitRect(_rect, _lastRect);</trect>
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < rects.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_workRas->extract(rects[i])->clear();
|
|
Toshihiro Shimizu |
890ddd |
m_backupRas->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::onActivate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_firstTime) {
|
|
Toshihiro Shimizu |
890ddd |
m_thickness.setValue(TDoublePairProperty::Value(VectorBrushMinSize, VectorBrushMaxSize));
|
|
Toshihiro Shimizu |
890ddd |
m_rasThickness.setValue(TDoublePairProperty::Value(RasterBrushMinSize, RasterBrushMaxSize));
|
|
Toshihiro Shimizu |
890ddd |
m_capStyle.setIndex(VectorCapStyle);
|
|
Toshihiro Shimizu |
890ddd |
m_joinStyle.setIndex(VectorJoinStyle);
|
|
Toshihiro Shimizu |
890ddd |
m_miterJoinLimit.setValue(VectorMiterValue);
|
|
Toshihiro Shimizu |
890ddd |
m_selective.setValue(BrushSelective ? 1 : 0);
|
|
Toshihiro Shimizu |
890ddd |
m_breakAngles.setValue(BrushBreakSharpAngles ? 1 : 0);
|
|
Toshihiro Shimizu |
890ddd |
m_pencil.setValue(RasterBrushPencilMode ? 1 : 0);
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setValue(BrushPressureSensibility ? 1 : 0);
|
|
Toshihiro Shimizu |
890ddd |
m_firstTime = false;
|
|
Toshihiro Shimizu |
890ddd |
m_accuracy.setValue(BrushAccuracy);
|
|
Toshihiro Shimizu |
890ddd |
m_hardness.setValue(RasterBrushHardness);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (m_targetType & TTool::ToonzImage) {
|
|
Toshihiro Shimizu |
890ddd |
m_brushPad = ToolUtils::getBrushPad(m_rasThickness.getValue().second, m_hardness.getValue() * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//TODO:app->editImageOrSpline();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::onDeactivate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*--- ドラッグ中にツールが切り替わった場合に備え、onDeactivateにもMouseReleaseと同じ処理を行う ---*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_tileSaver && !m_isPath) {
|
|
Toshihiro Shimizu |
890ddd |
bool isValid = m_enabled && m_active;
|
|
Toshihiro Shimizu |
890ddd |
m_enabled = false;
|
|
Toshihiro Shimizu |
890ddd |
if (isValid) {
|
|
Toshihiro Shimizu |
890ddd |
TImageP image = getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
if (TToonzImageP ti = image)
|
|
Toshihiro Shimizu |
890ddd |
finishRasterBrush(m_mousePos, 1); /*-- 最後のストロークの筆圧は1とする --*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_workRas = TRaster32P();
|
|
Toshihiro Shimizu |
890ddd |
m_backupRas = TRasterCM32P();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool BrushTool::preLeftButtonDown()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
touchImage();
|
|
Toshihiro Shimizu |
890ddd |
if (m_isFrameCreated)
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = TTool::getApplication();
|
|
Toshihiro Shimizu |
890ddd |
if (!app)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int col = app->getCurrentColumn()->getColumnIndex();
|
|
Toshihiro Shimizu |
890ddd |
m_isPath = app->getCurrentObject()->isSpline();
|
|
Toshihiro Shimizu |
890ddd |
m_enabled = col >= 0 || m_isPath;
|
|
Toshihiro Shimizu |
890ddd |
// todo: gestire autoenable
|
|
Toshihiro Shimizu |
890ddd |
if (!m_enabled)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (!m_isPath) {
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = TPixel32::Black;
|
|
Toshihiro Shimizu |
890ddd |
m_active = !!getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
if (!m_active) {
|
|
Toshihiro Shimizu |
890ddd |
m_active = !!touchImage();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (!m_active)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_active) {
|
|
Toshihiro Shimizu |
890ddd |
// nel caso che il colore corrente sia un cleanup/studiopalette color
|
|
Toshihiro Shimizu |
890ddd |
// oppure il colore di un colorfield
|
|
Toshihiro Shimizu |
890ddd |
m_styleId = app->getCurrentLevelStyleIndex();
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle *cs = app->getCurrentLevelStyle();
|
|
Toshihiro Shimizu |
890ddd |
if (cs) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterStyleFx *rfx = cs ? cs->getRasterStyleFx() : 0;
|
|
Toshihiro Shimizu |
890ddd |
m_active = cs != 0 && (cs->isStrokeStyle() || (rfx && rfx->isInkStyle()));
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = cs->getAverageColor();
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor.m = 255;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_styleId = 1;
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = TPixel32::Black;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = TPixel32::Red;
|
|
Toshihiro Shimizu |
890ddd |
m_active = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//assert(0<=m_styleId && m_styleId<2);
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ri(img);
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterCM32P ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
if (ras) {
|
|
Toshihiro Shimizu |
890ddd |
TPointD rasCenter = ras->getCenterD();
|
|
Toshihiro Shimizu |
890ddd |
m_tileSet = new TTileSetCM32(ras->getSize());
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver = new TTileSaverCM32(ras, m_tileSet);
|
|
Toshihiro Shimizu |
890ddd |
double maxThick = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2 : maxThick;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_pressure.getValue() && e.m_pressure == 255)
|
|
Toshihiro Shimizu |
890ddd |
thickness = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
TRectD invalidateRect(pos - halfThick, pos + halfThick);
|
|
Toshihiro Shimizu |
890ddd |
if (m_hardness.getValue() == 100 || m_pencil.getValue()) {
|
|
Toshihiro Shimizu |
890ddd |
/*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/
|
|
Toshihiro Shimizu |
890ddd |
if (!m_pencil.getValue())
|
|
Toshihiro Shimizu |
890ddd |
thickness -= 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack = new RasterStrokeGenerator(ras, BRUSH, NONE, m_styleId,
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint(pos + convert(ras->getCenter()), thickness),
|
|
Toshihiro Shimizu |
890ddd |
m_selective.getValue(), 0, !m_pencil.getValue());
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(m_rasterTrack->getLastRect());
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_points.clear();
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point(pos + rasCenter, thickness);
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(point);
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush = new BluredBrush(m_workRas, maxThick, m_brushPad, false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect = m_bluredBrush->getBoundFromPoints(m_points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(m_strokeRect);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(m_strokeRect);
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush->addPoint(point, 1);
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, m_styleId, m_selective.getValue());
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect = m_strokeRect;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*-- 作業中のFidを登録 --*/
|
|
Toshihiro Shimizu |
890ddd |
m_workingFrameId = getFrameId();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
invalidate(invalidateRect);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_track.clear();
|
|
Toshihiro Shimizu |
890ddd |
double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_thickness, m_isPath) : m_thickness.getValue().second * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_pressure.getValue() && e.m_pressure == 255)
|
|
Toshihiro Shimizu |
890ddd |
thickness = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_track.add(TThickPoint(pos, thickness), getPixelSize() * getPixelSize());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_brushPos = m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_enabled || !m_active)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isAdded;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (TToonzImageP ti = TImageP(getImage(true))) {
|
|
Toshihiro Shimizu |
890ddd |
TPointD rasCenter = ti->getRaster()->getCenterD();
|
|
Toshihiro Shimizu |
890ddd |
int maxThickness = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2 : maxThickness;
|
|
Toshihiro Shimizu |
890ddd |
TRectD invalidateRect;
|
|
Toshihiro Shimizu |
890ddd |
if (m_rasterTrack && (m_hardness.getValue() == 100 || m_pencil.getValue())) {
|
|
Toshihiro Shimizu |
890ddd |
/*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/
|
|
Toshihiro Shimizu |
890ddd |
if (!m_pencil.getValue())
|
|
Toshihiro Shimizu |
890ddd |
thickness -= 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
isAdded = m_rasterTrack->add(TThickPoint(pos + rasCenter, thickness));
|
|
Toshihiro Shimizu |
890ddd |
if (isAdded) {
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(m_rasterTrack->getLastRect());
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> brushPoints = m_rasterTrack->getPointsSequence();</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
int m = (int)brushPoints.size();
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
if (m == 3) {
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[0]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[1]);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[m - 4]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[m - 3]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[m - 2]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
//antialiased brush
|
|
Toshihiro Shimizu |
890ddd |
assert(m_workRas.getPointer() && m_backupRas.getPointer());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint old = m_points.back();
|
|
Toshihiro Shimizu |
890ddd |
if (norm2(pos - old) < 4)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point(pos + rasCenter, thickness);
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(mid);
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(point);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRect bbox;
|
|
Toshihiro Shimizu |
890ddd |
int m = (int)m_points.size();
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
if (m == 3) {
|
|
Toshihiro Shimizu |
890ddd |
// ho appena cominciato. devo disegnare un segmento
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint pa = m_points.front();
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(pa);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(mid);
|
|
Toshihiro Shimizu |
890ddd |
bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 4]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(old);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(mid);
|
|
Toshihiro Shimizu |
890ddd |
bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1);
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, m_styleId, m_selective.getValue());
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
invalidate(invalidateRect.enlarge(2));
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_thickness, m_isPath) : m_thickness.getValue().second * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
m_track.add(TThickPoint(pos, thickness), getPixelSize() * getPixelSize());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool isValid = m_enabled && m_active;
|
|
Toshihiro Shimizu |
890ddd |
m_enabled = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!isValid)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_isPath) {
|
|
Toshihiro Shimizu |
890ddd |
double error = 20.0 * getPixelSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke = m_track.makeStroke(error);
|
|
Toshihiro Shimizu |
890ddd |
int points = stroke->getControlPointCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (TVectorImageP vi = getImage(true)) {
|
|
Toshihiro Shimizu |
890ddd |
struct Cleanup {
|
|
Toshihiro Shimizu |
890ddd |
BrushTool *m_this;
|
|
Toshihiro Shimizu |
890ddd |
~Cleanup() { m_this->m_track.clear(), m_this->invalidate(); }
|
|
Toshihiro Shimizu |
890ddd |
} cleanup = {this};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!isJustCreatedSpline(vi.getPointer())) {
|
|
Toshihiro Shimizu |
890ddd |
m_isPrompting = true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString question("Are you sure you want to replace the motion path?");
|
|
Toshihiro Shimizu |
890ddd |
int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"), 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_isPrompting = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ret == 2 || ret == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker lock(vi->getMutex());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUndo *undo = new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (vi->getStrokeCount() > 0)
|
|
Toshihiro Shimizu |
890ddd |
vi->deleteStroke(0);
|
|
Toshihiro Shimizu |
890ddd |
vi->addStroke(stroke, false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP image = getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
if (TVectorImageP vi = image) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_track.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
m_styleId = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_track.clear();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_track.filterPoints();
|
|
Toshihiro Shimizu |
890ddd |
double error = 30.0 / (1 + 0.5 * m_accuracy.getValue());
|
|
Toshihiro Shimizu |
890ddd |
error *= getPixelSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke = m_track.makeStroke(error);
|
|
Toshihiro Shimizu |
890ddd |
stroke->setStyle(m_styleId);
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TStroke::OutlineOptions &options = stroke->outlineOptions();
|
|
Toshihiro Shimizu |
890ddd |
options.m_capStyle = m_capStyle.getIndex();
|
|
Toshihiro Shimizu |
890ddd |
options.m_joinStyle = m_joinStyle.getIndex();
|
|
Toshihiro Shimizu |
890ddd |
options.m_miterUpper = m_miterJoinLimit.getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_styleId = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker lock(vi->getMutex());
|
|
Toshihiro Shimizu |
890ddd |
if (stroke->getControlPointCount() == 3 && stroke->getControlPoint(0) != stroke->getControlPoint(2)) // gli stroke con solo 1 chunk vengono fatti dal tape tool...e devono venir riconosciuti come speciali di autoclose proprio dal fatto che hanno 1 solo chunk.
|
|
Toshihiro Shimizu |
890ddd |
stroke->insertControlPoints(0.5);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
addStrokeToImage(getApplication(), vi, stroke, m_breakAngles.getValue(), m_isFrameCreated, m_isLevelCreated);
|
|
Toshihiro Shimizu |
890ddd |
TRectD bbox = stroke->getBBox().enlarge(2) + m_track.getModifiedRegion();
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
assert(stroke);
|
|
Toshihiro Shimizu |
890ddd |
m_track.clear();
|
|
Toshihiro Shimizu |
890ddd |
} else if (TToonzImageP ti = image) {
|
|
Toshihiro Shimizu |
890ddd |
finishRasterBrush(pos, e.m_pressure);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! ドラッグ中にツールが切り替わった場合に備え、onDeactivate時とMouseRelease時にと同じ終了処理を行う
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::finishRasterBrush(const TPointD &pos, int pressureVal)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageP image = getImage(true);
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = image;
|
|
Toshihiro Shimizu |
890ddd |
if (!ti)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD rasCenter = ti->getRaster()->getCenterD();
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = TTool::getApplication();
|
|
Toshihiro Shimizu |
890ddd |
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- 描画中にカレントフレームが変わっても、描画開始時のFidに対してUndoを記録する --*/
|
|
Toshihiro Shimizu |
890ddd |
TFrameId frameId = m_workingFrameId.isEmptyFrame() ? getCurrentFid() : m_workingFrameId;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_rasterTrack && (m_hardness.getValue() == 100 || m_pencil.getValue())) {
|
|
Toshihiro Shimizu |
890ddd |
double thickness = m_pressure.getValue() ? computeThickness(pressureVal, m_rasThickness, m_isPath) : m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_pressure.getValue() && pressureVal == 255)
|
|
Toshihiro Shimizu |
890ddd |
thickness = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/
|
|
Toshihiro Shimizu |
890ddd |
if (!m_pencil.getValue())
|
|
Toshihiro Shimizu |
890ddd |
thickness -= 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isAdded = m_rasterTrack->add(TThickPoint(pos + convert(ti->getRaster()->getCenter()), thickness));
|
|
Toshihiro Shimizu |
890ddd |
if (isAdded) {
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(m_rasterTrack->getLastRect());
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue(), true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> brushPoints = m_rasterTrack->getPointsSequence();</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
int m = (int)brushPoints.size();
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
if (m == 3) {
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[0]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[1]);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[m - 4]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[m - 3]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(brushPoints[m - 2]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int maxThickness = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
invalidate(ToolUtils::getBounds(points, maxThickness).enlarge(2) - rasCenter);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_tileSet->getTileCount() > 0) {
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(new RasterBrushUndo(m_tileSet,
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack->getPointsSequence(),
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack->getStyleId(),
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack->isSelective(),
|
|
Toshihiro Shimizu |
890ddd |
simLevel.getPointer(),
|
|
Toshihiro Shimizu |
890ddd |
frameId, m_pencil.getValue(),
|
|
Toshihiro Shimizu |
890ddd |
m_isFrameCreated,
|
|
Toshihiro Shimizu |
890ddd |
m_isLevelCreated));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
delete m_rasterTrack;
|
|
Toshihiro Shimizu |
890ddd |
m_rasterTrack = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (m_points.size() != 1) {
|
|
Toshihiro Shimizu |
890ddd |
double maxThickness = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(pressureVal, m_rasThickness, m_isPath)
|
|
Toshihiro Shimizu |
890ddd |
: maxThickness;
|
|
Toshihiro Shimizu |
890ddd |
TPointD rasCenter = ti->getRaster()->getCenterD();
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point(pos + rasCenter, thickness);
|
|
Toshihiro Shimizu |
890ddd |
m_points.push_back(point);
|
|
Toshihiro Shimizu |
890ddd |
int m = m_points.size();
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 3]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 2]);
|
|
Toshihiro Shimizu |
890ddd |
points.push_back(m_points[m - 1]);
|
|
Toshihiro Shimizu |
890ddd |
TRect bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
Toshihiro Shimizu |
890ddd |
updateWorkAndBackupRasters(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver->save(bbox);
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush->addArc(points[0], points[1], points[2], 1, 1);
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, m_styleId, m_selective.getValue());
|
|
Toshihiro Shimizu |
890ddd |
TRectD invalidateRect = ToolUtils::getBounds(points, maxThickness);
|
|
Toshihiro Shimizu |
890ddd |
invalidate(invalidateRect.enlarge(2) - rasCenter);
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect += bbox;
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
delete m_bluredBrush;
|
|
Toshihiro Shimizu |
890ddd |
m_bluredBrush = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_tileSet->getTileCount() > 0) {
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(new RasterBluredBrushUndo(m_tileSet,
|
|
Toshihiro Shimizu |
890ddd |
m_points,
|
|
Toshihiro Shimizu |
890ddd |
m_styleId,
|
|
Toshihiro Shimizu |
890ddd |
m_selective.getValue(),
|
|
Toshihiro Shimizu |
890ddd |
simLevel.getPointer(),
|
|
Toshihiro Shimizu |
890ddd |
frameId,
|
|
Toshihiro Shimizu |
890ddd |
m_rasThickness.getValue().second,
|
|
Toshihiro Shimizu |
890ddd |
m_hardness.getValue() * 0.01,
|
|
Toshihiro Shimizu |
890ddd |
m_isFrameCreated,
|
|
Toshihiro Shimizu |
890ddd |
m_isLevelCreated));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
delete m_tileSaver;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_tileSaver = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- FIdを指定して、描画中にフレームが動いても、
|
|
Toshihiro Shimizu |
890ddd |
描画開始時のFidのサムネイルが更新されるようにする。--*/
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged(frameId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ToolUtils::updateSaveBox();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- 作業中のフレームをリセット --*/
|
|
Toshihiro Shimizu |
890ddd |
m_workingFrameId = TFrameId();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct Locals {
|
|
Toshihiro Shimizu |
890ddd |
BrushTool *m_this;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setValue(TDoublePairProperty &prop, const TDoublePairProperty::Value &value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
prop.setValue(value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_this->onPropertyChanged(prop.getName());
|
|
Toshihiro Shimizu |
890ddd |
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void addMinMax(TDoublePairProperty &prop, double add)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
shun_iwasawa |
a50847 |
if (add == 0.0)
|
|
shun_iwasawa |
a50847 |
return;
|
|
Toshihiro Shimizu |
890ddd |
const TDoublePairProperty::Range &range = prop.getRange();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TDoublePairProperty::Value value = prop.getValue();
|
|
Toshihiro Shimizu |
890ddd |
value.first = tcrop(value.first + add, range.first, range.second);
|
|
Toshihiro Shimizu |
890ddd |
value.second = tcrop(value.second + add, range.first, range.second);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
setValue(prop, value);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} locals = {this};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (e.getModifiersMask()) {
|
|
Toshihiro Shimizu |
890ddd |
/*-- Altキー+マウス移動で、ブラシサイズ(Min/Maxとも)を変える(CtrlやShiftでは誤操作の恐れがある) --*/
|
|
Toshihiro Shimizu |
890ddd |
case TMouseEvent::ALT_KEY: {
|
|
Toshihiro Shimizu |
890ddd |
// User wants to alter the minimum brush size
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &diff = pos - m_mousePos;
|
|
Toshihiro Shimizu |
890ddd |
double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
locals.addMinMax(TToonzImageP(getImage(false, 1)) ? m_rasThickness : m_thickness, add);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
m_brushPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_minThick == 0 && m_maxThick == 0) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_targetType & TTool::ToonzImage) {
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::draw()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*--ショートカットでのツール切り替え時に赤点が描かれるのを防止する--*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_minThick == 0 && m_maxThick == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = getImage(false, 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Draw track
|
|
Toshihiro Shimizu |
890ddd |
tglColor(m_isPrompting ? TPixel32::Green : m_currentColor);
|
|
Toshihiro Shimizu |
890ddd |
m_track.drawAllFragments();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (getApplication()->getCurrentObject()->isSpline())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Draw the brush outline - change color when the Ink / Paint check is activated
|
|
Toshihiro Shimizu |
890ddd |
if ((ToonzCheck::instance()->getChecks() & ToonzCheck::eInk) || (ToonzCheck::instance()->getChecks() & ToonzCheck::ePaint) || (ToonzCheck::instance()->getChecks() & ToonzCheck::eInk1))
|
|
Toshihiro Shimizu |
890ddd |
glColor3d(0.5, 0.8, 0.8);
|
|
Toshihiro Shimizu |
890ddd |
//normally draw in red
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
glColor3d(1.0, 0.0, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (TToonzImageP ti = img) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ti->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
int lx = ras->getLx();
|
|
Toshihiro Shimizu |
890ddd |
int ly = ras->getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
drawEmptyCircle(m_brushPos, tround(m_minThick), lx % 2 == 0, ly % 2 == 0, m_pencil.getValue());
|
|
Toshihiro Shimizu |
890ddd |
drawEmptyCircle(m_brushPos, tround(m_maxThick), lx % 2 == 0, ly % 2 == 0, m_pencil.getValue());
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(m_brushPos, 0.5 * m_minThick);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(m_brushPos, 0.5 * m_maxThick);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::onEnter()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = getImage(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (TToonzImageP(img)) {
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Application *app = getApplication();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_styleId = app->getCurrentLevelStyleIndex();
|
|
Toshihiro Shimizu |
890ddd |
TColorStyle *cs = app->getCurrentLevelStyle();
|
|
Toshihiro Shimizu |
890ddd |
if (cs) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterStyleFx *rfx = cs->getRasterStyleFx();
|
|
Toshihiro Shimizu |
890ddd |
m_active = cs->isStrokeStyle() || (rfx && rfx->isInkStyle());
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = cs->getAverageColor();
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor.m = 255;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_currentColor = TPixel32::Black;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_active = img;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::onLeave()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup *BrushTool::getProperties(int idx)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_presetsLoaded)
|
|
Toshihiro Shimizu |
890ddd |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return &m_prop[idx];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::onImageChanged()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = (TToonzImageP)getImage(false, 1);
|
|
Toshihiro Shimizu |
890ddd |
if (!ti || !isEnabled())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::setWorkAndBackupImages()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = (TToonzImageP)getImage(false, 1);
|
|
Toshihiro Shimizu |
890ddd |
if (!ti)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterP ras = ti->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TDimension dim = ras->getSize();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double hardness = m_hardness.getValue() * 0.01;
|
|
Toshihiro Shimizu |
890ddd |
if (hardness == 1.0 && ras->getPixelSize() == 4) {
|
|
Toshihiro Shimizu |
890ddd |
m_workRas = TRaster32P();
|
|
Toshihiro Shimizu |
890ddd |
m_backupRas = TRasterCM32P();
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (!m_workRas || m_workRas->getLx() > dim.lx || m_workRas->getLy() > dim.ly)
|
|
Toshihiro Shimizu |
890ddd |
m_workRas = TRaster32P(dim);
|
|
Toshihiro Shimizu |
890ddd |
if (!m_backupRas || m_backupRas->getLx() > dim.lx || m_backupRas->getLy() > dim.ly)
|
|
Toshihiro Shimizu |
890ddd |
m_backupRas = TRasterCM32P(dim);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokeRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
m_lastRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
bool BrushTool::onPropertyChanged(std::string propertyName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//Set the following to true whenever a different piece of interface must
|
|
Toshihiro Shimizu |
890ddd |
//be refreshed - done once at the end.
|
|
Toshihiro Shimizu |
890ddd |
bool notifyTool = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--- 変更されたPropertyに合わせて処理を分ける ---*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--- m_thicknessとm_rasThicknessは同じName(="Size:")なので、
|
|
Toshihiro Shimizu |
890ddd |
扱っている画像がラスタかどうかで区別する---*/
|
|
Toshihiro Shimizu |
890ddd |
if (propertyName == m_thickness.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = getImage(false);
|
|
Toshihiro Shimizu |
890ddd |
if (TToonzImageP(img)) //raster
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
RasterBrushMinSize = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
RasterBrushMaxSize = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
} else //vector
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
VectorBrushMinSize = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
VectorBrushMaxSize = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_minThick = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
m_maxThick = m_thickness.getValue().second;
|
|
shun_iwasawa |
b5d548 |
}
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_accuracy.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
BrushAccuracy = m_accuracy.getValue();
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_preset.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
loadPreset();
|
|
Toshihiro Shimizu |
890ddd |
notifyTool = true;
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_selective.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
BrushSelective = m_selective.getValue();
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_breakAngles.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
BrushBreakSharpAngles = m_breakAngles.getValue();
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_pencil.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
RasterBrushPencilMode = m_pencil.getValue();
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_pressure.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
BrushPressureSensibility = m_pressure.getValue();
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_capStyle.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
VectorCapStyle = m_capStyle.getIndex();
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_joinStyle.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
VectorJoinStyle = m_joinStyle.getIndex();
|
|
Toshihiro Shimizu |
890ddd |
} else if (propertyName == m_miterJoinLimit.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
VectorMiterValue = m_miterJoinLimit.getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_targetType & TTool::Vectors) {
|
|
Toshihiro Shimizu |
890ddd |
if (propertyName == m_joinStyle.getName())
|
|
Toshihiro Shimizu |
890ddd |
notifyTool = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (m_targetType & TTool::ToonzImage) {
|
|
Toshihiro Shimizu |
890ddd |
if (propertyName == m_hardness.getName())
|
|
Toshihiro Shimizu |
890ddd |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
if (propertyName == m_hardness.getName() || propertyName == m_thickness.getName()) {
|
|
Toshihiro Shimizu |
890ddd |
m_brushPad = getBrushPad(m_rasThickness.getValue().second, m_hardness.getValue() * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
TRectD rect(m_mousePos - TPointD(m_maxThick + 2, m_maxThick + 2),
|
|
Toshihiro Shimizu |
890ddd |
m_mousePos + TPointD(m_maxThick + 2, m_maxThick + 2));
|
|
Toshihiro Shimizu |
890ddd |
invalidate(rect);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
b5d548 |
if (propertyName != m_preset.getName() && m_preset.getValue() != CUSTOM_WSTR) {
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
notifyTool = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (notifyTool)
|
|
Toshihiro Shimizu |
890ddd |
getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::initPresets()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_presetsLoaded) {
|
|
Toshihiro Shimizu |
890ddd |
//If necessary, load the presets from file
|
|
Toshihiro Shimizu |
890ddd |
m_presetsLoaded = true;
|
|
Toshihiro Shimizu |
890ddd |
if (getTargetType() & TTool::Vectors)
|
|
Toshihiro Shimizu |
890ddd |
m_presetsManager.load(TEnv::getConfigDir() + "brush_vector.txt");
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_presetsManager.load(TEnv::getConfigDir() + "brush_toonzraster.txt");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Rebuild the presets property entries
|
|
Toshihiro Shimizu |
890ddd |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_preset.deleteAllValues();
|
|
Toshihiro Shimizu |
890ddd |
m_preset.addValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::set<brushdata>::const_iterator it, end = presets.end();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
for (it = presets.begin(); it != end; ++it)
|
|
Toshihiro Shimizu |
890ddd |
m_preset.addValue(it->m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::loadPreset()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
std::set<brushdata>::const_iterator it;</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
it = presets.find(BrushData(m_preset.getValue()));
|
|
Toshihiro Shimizu |
890ddd |
if (it == presets.end())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const BrushData &preset = *it;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
try //Don't bother with RangeErrors
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (getTargetType() & TTool::Vectors) {
|
|
Toshihiro Shimizu |
890ddd |
m_thickness.setValue(TDoublePairProperty::Value(preset.m_min, preset.m_max));
|
|
Toshihiro Shimizu |
890ddd |
m_accuracy.setValue(preset.m_acc, true);
|
|
Toshihiro Shimizu |
890ddd |
m_breakAngles.setValue(preset.m_breakAngles);
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setValue(preset.m_pressure);
|
|
Toshihiro Shimizu |
890ddd |
m_capStyle.setIndex(preset.m_cap);
|
|
Toshihiro Shimizu |
890ddd |
m_joinStyle.setIndex(preset.m_join);
|
|
Toshihiro Shimizu |
890ddd |
m_miterJoinLimit.setValue(preset.m_miter);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_rasThickness.setValue(TDoublePairProperty::Value(tmax(preset.m_min, 1.0), preset.m_max));
|
|
Toshihiro Shimizu |
890ddd |
m_brushPad = ToolUtils::getBrushPad(preset.m_max, preset.m_hardness * 0.01);
|
|
Toshihiro Shimizu |
890ddd |
m_hardness.setValue(preset.m_hardness, true);
|
|
Toshihiro Shimizu |
890ddd |
m_selective.setValue(preset.m_selective);
|
|
Toshihiro Shimizu |
890ddd |
m_pencil.setValue(preset.m_pencil);
|
|
Toshihiro Shimizu |
890ddd |
m_pressure.setValue(preset.m_pressure);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::addPreset(QString name)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//Build the preset
|
|
Toshihiro Shimizu |
890ddd |
BrushData preset(name.toStdWString());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (getTargetType() & TTool::Vectors) {
|
|
Toshihiro Shimizu |
890ddd |
preset.m_min = m_thickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
preset.m_max = m_thickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
preset.m_min = m_rasThickness.getValue().first;
|
|
Toshihiro Shimizu |
890ddd |
preset.m_max = m_rasThickness.getValue().second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
preset.m_acc = m_accuracy.getValue();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_hardness = m_hardness.getValue();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_selective = m_selective.getValue();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_pencil = m_pencil.getValue();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_breakAngles = m_breakAngles.getValue();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_pressure = m_pressure.getValue();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_cap = m_capStyle.getIndex();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_join = m_joinStyle.getIndex();
|
|
Toshihiro Shimizu |
890ddd |
preset.m_miter = m_miterJoinLimit.getValue();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Pass the preset to the manager
|
|
Toshihiro Shimizu |
890ddd |
m_presetsManager.addPreset(preset);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Reinitialize the associated preset enum
|
|
Toshihiro Shimizu |
890ddd |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Set the value to the specified one
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setValue(preset.m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushTool::removePreset()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring name(m_preset.getValue());
|
|
Toshihiro Shimizu |
890ddd |
if (name == CUSTOM_WSTR)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_presetsManager.removePreset(name);
|
|
Toshihiro Shimizu |
890ddd |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//No parameter change, and set the preset value to custom
|
|
Toshihiro Shimizu |
890ddd |
m_preset.setValue(CUSTOM_WSTR);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Brush、PaintBrush、EraserToolがPencilModeのときにTrueを返す
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
bool BrushTool::isPencilModeActive()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return getTargetType() == TTool::ToonzImage && m_pencil.getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Tools instantiation
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BrushTool vectorPencil("T_Brush", TTool::Vectors | TTool::EmptyTarget);
|
|
Toshihiro Shimizu |
890ddd |
BrushTool toonzPencil("T_Brush", TTool::ToonzImage | TTool::EmptyTarget);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Brush Data implementation
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BrushData::BrushData()
|
|
Toshihiro Shimizu |
890ddd |
: m_name(), m_min(0.0), m_max(0.0), m_acc(0.0), m_hardness(0.0), m_opacityMin(0.0), m_opacityMax(0.0), m_selective(false), m_pencil(false), m_breakAngles(false), m_pressure(false), m_cap(0), m_join(0), m_miter(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BrushData::BrushData(const std::wstring &name)
|
|
Toshihiro Shimizu |
890ddd |
: m_name(name), m_min(0.0), m_max(0.0), m_acc(0.0), m_hardness(0.0), m_opacityMin(0.0), m_opacityMax(0.0), m_selective(false), m_pencil(false), m_breakAngles(false), m_pressure(false), m_cap(0), m_join(0), m_miter(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushData::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Name");
|
|
Toshihiro Shimizu |
890ddd |
os << m_name;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Thickness");
|
|
Toshihiro Shimizu |
890ddd |
os << m_min << m_max;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Accuracy");
|
|
Toshihiro Shimizu |
890ddd |
os << m_acc;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Hardness");
|
|
Toshihiro Shimizu |
890ddd |
os << m_hardness;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Opacity");
|
|
Toshihiro Shimizu |
890ddd |
os << m_opacityMin << m_opacityMax;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Selective");
|
|
Toshihiro Shimizu |
890ddd |
os << (int)m_selective;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Pencil");
|
|
Toshihiro Shimizu |
890ddd |
os << (int)m_pencil;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Break_Sharp_Angles");
|
|
Toshihiro Shimizu |
890ddd |
os << (int)m_breakAngles;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Pressure_Sensitivity");
|
|
Toshihiro Shimizu |
890ddd |
os << (int)m_pressure;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Cap");
|
|
Toshihiro Shimizu |
890ddd |
os << m_cap;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Join");
|
|
Toshihiro Shimizu |
890ddd |
os << m_join;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("Miter");
|
|
Toshihiro Shimizu |
890ddd |
os << m_miter;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushData::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::string tagName;
|
|
Toshihiro Shimizu |
890ddd |
int val;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (is.matchTag(tagName)) {
|
|
Toshihiro Shimizu |
890ddd |
if (tagName == "Name")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_name, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Thickness")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_min >> m_max, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Accuracy")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_acc, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Hardness")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_hardness, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Opacity")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_opacityMin >> m_opacityMax, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Selective")
|
|
Toshihiro Shimizu |
890ddd |
is >> val, m_selective = val, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Pencil")
|
|
Toshihiro Shimizu |
890ddd |
is >> val, m_pencil = val, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Break_Sharp_Angles")
|
|
Toshihiro Shimizu |
890ddd |
is >> val, m_breakAngles = val, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Pressure_Sensitivity")
|
|
Toshihiro Shimizu |
890ddd |
is >> val, m_pressure = val, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Cap")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_cap, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Join")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_join, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else if (tagName == "Miter")
|
|
Toshihiro Shimizu |
890ddd |
is >> m_miter, is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
is.skipCurrentTag();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
PERSIST_IDENTIFIER(BrushData, "BrushData");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Brush Preset Manager implementation
|
|
Toshihiro Shimizu |
890ddd |
//*******************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushPresetManager::load(const TFilePath &fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_fp = fp;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::string tagName;
|
|
Toshihiro Shimizu |
890ddd |
BrushData data;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TIStream is(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
while (is.matchTag(tagName)) {
|
|
Toshihiro Shimizu |
890ddd |
if (tagName == "version") {
|
|
Toshihiro Shimizu |
890ddd |
VersionNumber version;
|
|
Toshihiro Shimizu |
890ddd |
is >> version.first >> version.second;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
is.setVersion(version);
|
|
Toshihiro Shimizu |
890ddd |
is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
} else if (tagName == "brushes") {
|
|
Toshihiro Shimizu |
890ddd |
while (is.matchTag(tagName)) {
|
|
Toshihiro Shimizu |
890ddd |
if (tagName == "brush") {
|
|
Toshihiro Shimizu |
890ddd |
is >> data, m_presets.insert(data);
|
|
Toshihiro Shimizu |
890ddd |
is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
is.skipCurrentTag();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
is.matchEndTag();
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
is.skipCurrentTag();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushPresetManager::save()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TOStream os(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("version");
|
|
Toshihiro Shimizu |
890ddd |
os << 1 << 19;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("brushes");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::set<brushdata>::iterator it, end = m_presets.end();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
for (it = m_presets.begin(); it != end; ++it) {
|
|
Toshihiro Shimizu |
890ddd |
os.openChild("brush");
|
|
Toshihiro Shimizu |
890ddd |
os << (TPersist &)*it;
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void BrushPresetManager::addPreset(const BrushData &data)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_presets.erase(data); //Overwriting insertion
|
|
Toshihiro Shimizu |
890ddd |
m_presets.insert(data);
|
|
Toshihiro Shimizu |
890ddd |
save();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void BrushPresetManager::removePreset(const std::wstring &name)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_presets.erase(BrushData(name));
|
|
Toshihiro Shimizu |
890ddd |
save();
|
|
Toshihiro Shimizu |
890ddd |
}
|