|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
#include "toonzrasterbrushtool.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"
|
|
Jeremy Bullock |
7f2044 |
#include "toonz/preferences.h"
|
|
shun-iwasawa |
98926d |
#include "toonz/tpalettehandle.h"
|
|
shun-iwasawa |
98926d |
#include "toonz/mypaintbrushstyle.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"
|
|
Jeremy Bullock |
cd00fd |
#include "tinbetween.h"
|
|
Jeremy Bullock |
cd00fd |
|
|
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 RasterBrushMinSize("InknpaintRasterBrushMinSize", 1);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar RasterBrushMaxSize("InknpaintRasterBrushMaxSize", 5);
|
|
walkerka |
2e244a |
TEnv::DoubleVar BrushSmooth("InknpaintBrushSmooth", 0);
|
|
shun-iwasawa |
975eb1 |
TEnv::IntVar BrushDrawOrder("InknpaintBrushDrawOrder", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar RasterBrushPencilMode("InknpaintRasterBrushPencilMode", 0);
|
|
Campbell Barton |
f49389 |
TEnv::IntVar BrushPressureSensitivity("InknpaintBrushPressureSensitivity", 1);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar RasterBrushHardness("RasterBrushHardness", 100);
|
|
shun-iwasawa |
98926d |
TEnv::DoubleVar RasterBrushModifierSize("RasterBrushModifierSize", 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
#define CUSTOM_WSTR L"<custom>"</custom>
|
|
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
|
|
Shinya Kitaoka |
120a6e |
// parameterValues[] = vector of parameters where I want to split the
|
|
Shinya Kitaoka |
120a6e |
// 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 |
|
|
Campbell Barton |
8c6c57 |
static void split(TStroke *stroke, const std::vector<double> ¶meterValues,</double>
|
|
Campbell Barton |
8c6c57 |
std::vector<tstroke *=""> &strokes) {</tstroke>
|
|
Shinya Kitaoka |
120a6e |
TThickPoint p2;
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
TThickPoint lastPoint = stroke->getControlPoint(0);
|
|
Shinya Kitaoka |
120a6e |
int n = parameterValues.size();
|
|
Shinya Kitaoka |
120a6e |
int chunk;
|
|
Shinya Kitaoka |
120a6e |
double t;
|
|
Shinya Kitaoka |
120a6e |
int last_chunk = -1, startPoint = 0;
|
|
Shinya Kitaoka |
120a6e |
double lastLocT = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < n; i++) {
|
|
Shinya Kitaoka |
120a6e |
points.push_back(lastPoint); // Add first point of the stroke
|
|
Shinya Kitaoka |
120a6e |
double w =
|
|
Shinya Kitaoka |
120a6e |
parameterValues[i]; // Global parameter. along the stroke 0<=w<=1
|
|
Shinya Kitaoka |
120a6e |
stroke->getChunkAndT(w, chunk,
|
|
Shinya Kitaoka |
120a6e |
t); // t: local parameter in the chunk-th quadratic
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (i == 0)
|
|
Shinya Kitaoka |
120a6e |
startPoint = 1;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
int indexAfterLastT =
|
|
Shinya Kitaoka |
120a6e |
stroke->getControlPointIndexAfterParameter(parameterValues[i - 1]);
|
|
Shinya Kitaoka |
120a6e |
startPoint = indexAfterLastT;
|
|
Shinya Kitaoka |
120a6e |
if ((indexAfterLastT & 1) && lastLocT != 1) startPoint++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
int endPoint = 2 * chunk + 1;
|
|
Shinya Kitaoka |
120a6e |
if (lastLocT != 1 && i > 0) {
|
|
Shinya Kitaoka |
120a6e |
if (last_chunk != chunk || t == 1)
|
|
Shinya Kitaoka |
120a6e |
points.push_back(p2); // If the last local t is not an extreme
|
|
Shinya Kitaoka |
120a6e |
// add the point p2
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (int j = startPoint; j < endPoint; j++)
|
|
Shinya Kitaoka |
120a6e |
points.push_back(stroke->getControlPoint(j));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TThickPoint p, A, B, C;
|
|
Shinya Kitaoka |
120a6e |
p = stroke->getPoint(w);
|
|
Shinya Kitaoka |
120a6e |
C = stroke->getControlPoint(2 * chunk + 2);
|
|
Shinya Kitaoka |
120a6e |
B = stroke->getControlPoint(2 * chunk + 1);
|
|
Shinya Kitaoka |
120a6e |
A = stroke->getControlPoint(2 * chunk);
|
|
Shinya Kitaoka |
120a6e |
p.thick = A.thick;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (last_chunk != chunk) {
|
|
Shinya Kitaoka |
120a6e |
TThickPoint p1 = (1 - t) * A + t * B;
|
|
Shinya Kitaoka |
120a6e |
points.push_back(p1);
|
|
Shinya Kitaoka |
120a6e |
p.thick = p1.thick;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (t != 1) {
|
|
Shinya Kitaoka |
120a6e |
// If the i-th cut point belong to the same chunk of the (i-1)-th cut
|
|
Shinya Kitaoka |
120a6e |
// point.
|
|
Shinya Kitaoka |
120a6e |
double tInters = lastLocT / t;
|
|
Shinya Kitaoka |
120a6e |
TThickPoint p11 = (1 - t) * A + t * B;
|
|
Shinya Kitaoka |
120a6e |
TThickPoint p1 = (1 - tInters) * p11 + tInters * p;
|
|
Shinya Kitaoka |
120a6e |
points.push_back(p1);
|
|
Shinya Kitaoka |
120a6e |
p.thick = p1.thick;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
points.push_back(p);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (t != 1) p2 = (1 - t) * B + t * C;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
assert(points.size() & 1);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Add new stroke
|
|
Shinya Kitaoka |
120a6e |
TStroke *strokeAdd = new TStroke(points);
|
|
Shinya Kitaoka |
120a6e |
strokeAdd->setStyle(stroke->getStyle());
|
|
Shinya Kitaoka |
120a6e |
strokeAdd->outlineOptions() = stroke->outlineOptions();
|
|
Shinya Kitaoka |
120a6e |
strokes.push_back(strokeAdd);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
lastPoint = p;
|
|
Shinya Kitaoka |
120a6e |
last_chunk = chunk;
|
|
Shinya Kitaoka |
120a6e |
lastLocT = t;
|
|
Shinya Kitaoka |
120a6e |
points.clear();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// Add end stroke
|
|
Shinya Kitaoka |
120a6e |
points.push_back(lastPoint);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (lastLocT != 1) points.push_back(p2);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
startPoint =
|
|
Shinya Kitaoka |
120a6e |
stroke->getControlPointIndexAfterParameter(parameterValues[n - 1]);
|
|
Shinya Kitaoka |
120a6e |
if ((stroke->getControlPointIndexAfterParameter(parameterValues[n - 1]) &
|
|
Shinya Kitaoka |
120a6e |
1) &&
|
|
Shinya Kitaoka |
120a6e |
lastLocT != 1)
|
|
Shinya Kitaoka |
120a6e |
startPoint++;
|
|
Shinya Kitaoka |
120a6e |
for (int j = startPoint; j < stroke->getControlPointCount(); j++)
|
|
Shinya Kitaoka |
120a6e |
points.push_back(stroke->getControlPoint(j));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
assert(points.size() & 1);
|
|
Shinya Kitaoka |
120a6e |
TStroke *strokeAdd = new TStroke(points);
|
|
Shinya Kitaoka |
120a6e |
strokeAdd->setStyle(stroke->getStyle());
|
|
Shinya Kitaoka |
120a6e |
strokeAdd->outlineOptions() = stroke->outlineOptions();
|
|
Shinya Kitaoka |
120a6e |
strokes.push_back(strokeAdd);
|
|
Shinya Kitaoka |
120a6e |
points.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Compute Parametric Curve Curvature
|
|
Shinya Kitaoka |
120a6e |
// 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.
|
|
Shinya Kitaoka |
120a6e |
// Note: if the curve is a single point (that's dp=0) or it is a straight
|
|
Shinya Kitaoka |
120a6e |
// line (that's ddp=0) return 0
|
|
Shinya Kitaoka |
120a6e |
|
|
Campbell Barton |
8c6c57 |
static double curvature(TPointD dp, TPointD ddp) {
|
|
Shinya Kitaoka |
120a6e |
if (dp == TPointD(0, 0))
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
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.
|
|
Shinya Kitaoka |
120a6e |
// Up this value the point can be considered a max curvature
|
|
Shinya Kitaoka |
120a6e |
// point.
|
|
Toshihiro Shimizu |
890ddd |
// Output:
|
|
Toshihiro Shimizu |
890ddd |
// parameterValues = vector of max curvature parameter points
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void findMaxCurvPoints(TStroke *stroke, const float &angoloLim,
|
|
Campbell Barton |
8c6c57 |
const float &curvMaxLim,
|
|
Campbell Barton |
8c6c57 |
std::vector<double> ¶meterValues) {</double>
|
|
Shinya Kitaoka |
120a6e |
TPointD tg1, tg2; // Tangent vectors
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPointD dp, ddp; // First and Second derivate.
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
parameterValues.clear();
|
|
Shinya Kitaoka |
120a6e |
int cpn = stroke ? stroke->getControlPointCount() : 0;
|
|
Shinya Kitaoka |
120a6e |
for (int j = 2; j < cpn; j += 2) {
|
|
Shinya Kitaoka |
120a6e |
TPointD p0 = stroke->getControlPoint(j - 2);
|
|
Shinya Kitaoka |
120a6e |
TPointD p1 = stroke->getControlPoint(j - 1);
|
|
Shinya Kitaoka |
120a6e |
TPointD p2 = stroke->getControlPoint(j);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPointD q = p1 - (p0 + p2) * 0.5;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Search corner point
|
|
Shinya Kitaoka |
120a6e |
if (j > 2) {
|
|
Shinya Kitaoka |
120a6e |
tg2 = -p0 + p2 + 2 * q; // Tangent vector to this chunk at t=0
|
|
Shinya Kitaoka |
120a6e |
double prod_scal =
|
|
Shinya Kitaoka |
120a6e |
tg2 * tg1; // Inner product between tangent vectors at t=0.
|
|
Shinya Kitaoka |
120a6e |
assert(tg1 != TPointD(0, 0) || tg2 != TPointD(0, 0));
|
|
Shinya Kitaoka |
120a6e |
// Compute corner between two tangent vectors
|
|
Shinya Kitaoka |
120a6e |
double angolo =
|
|
Shinya Kitaoka |
120a6e |
acos(prod_scal / (pow(norm2(tg2), 0.5) * pow(norm2(tg1), 0.5)));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Add corner point
|
|
Shinya Kitaoka |
120a6e |
if (angolo > angoloLim) {
|
|
Shinya Kitaoka |
120a6e |
double w = getWfromChunkAndT(stroke, (UINT)(0.5 * (j - 2)),
|
|
Shinya Kitaoka |
120a6e |
0); // transform lacal t to global t
|
|
Shinya Kitaoka |
120a6e |
parameterValues.push_back(w);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
tg1 = -p0 + p2 - 2 * q; // Tangent vector to this chunk at t=1
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// End search corner point
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Search max curvature point
|
|
Shinya Kitaoka |
120a6e |
// Value of t where the curvature function has got an extreme.
|
|
Shinya Kitaoka |
120a6e |
// (Point where first derivate is null)
|
|
Shinya Kitaoka |
120a6e |
double estremo_int = 0;
|
|
Shinya Kitaoka |
120a6e |
double t = -1;
|
|
Shinya Kitaoka |
120a6e |
if (q != TPointD(0, 0)) {
|
|
Shinya Kitaoka |
120a6e |
t = 0.25 * (2 * q.x * q.x + 2 * q.y * q.y - q.x * p0.x + q.x * p2.x -
|
|
Shinya Kitaoka |
120a6e |
q.y * p0.y + q.y * p2.y) /
|
|
Shinya Kitaoka |
120a6e |
(q.x * q.x + q.y * q.y);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
dp = -p0 + p2 + 2 * q - 4 * t * q; // First derivate of the curve
|
|
Shinya Kitaoka |
120a6e |
ddp = -4 * q; // Second derivate of the curve
|
|
Shinya Kitaoka |
120a6e |
estremo_int = curvature(dp, ddp);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double h = 0.01;
|
|
Shinya Kitaoka |
120a6e |
dp = -p0 + p2 + 2 * q - 4 * (t + h) * q;
|
|
Shinya Kitaoka |
120a6e |
double c_dx = curvature(dp, ddp);
|
|
Shinya Kitaoka |
120a6e |
dp = -p0 + p2 + 2 * q - 4 * (t - h) * q;
|
|
Shinya Kitaoka |
120a6e |
double c_sx = curvature(dp, ddp);
|
|
Shinya Kitaoka |
120a6e |
// Check the point is a max and not a minimum
|
|
Shinya Kitaoka |
120a6e |
if (estremo_int < c_dx && estremo_int < c_sx) {
|
|
Shinya Kitaoka |
120a6e |
estremo_int = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
double curv_max = estremo_int;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Compute curvature at the extreme of interval [0,1]
|
|
Shinya Kitaoka |
120a6e |
// Compute curvature at t=0 (Left extreme)
|
|
Shinya Kitaoka |
120a6e |
dp = -p0 + p2 + 2 * q;
|
|
Shinya Kitaoka |
120a6e |
double estremo_sx = curvature(dp, ddp);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Compute curvature at t=1 (Right extreme)
|
|
Shinya Kitaoka |
120a6e |
dp = -p0 + p2 - 2 * q;
|
|
Shinya Kitaoka |
120a6e |
double estremo_dx = curvature(dp, ddp);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Compare curvature at the extreme of interval [0,1] with the internal
|
|
Shinya Kitaoka |
120a6e |
// value
|
|
Shinya Kitaoka |
120a6e |
double t_ext;
|
|
Shinya Kitaoka |
120a6e |
if (estremo_sx >= estremo_dx)
|
|
Shinya Kitaoka |
120a6e |
t_ext = 0;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
t_ext = 1;
|
|
Shinya Kitaoka |
120a6e |
double maxEstremi = std::max(estremo_dx, estremo_sx);
|
|
Shinya Kitaoka |
120a6e |
if (maxEstremi > estremo_int) {
|
|
Shinya Kitaoka |
120a6e |
t = t_ext;
|
|
Shinya Kitaoka |
120a6e |
curv_max = maxEstremi;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Add max curvature point
|
|
Shinya Kitaoka |
120a6e |
if (t >= 0 && t <= 1 && curv_max > curvMaxLim) {
|
|
Shinya Kitaoka |
120a6e |
double w = getWfromChunkAndT(stroke, (UINT)(0.5 * (j - 2)),
|
|
Shinya Kitaoka |
120a6e |
t); // transform local t to global t
|
|
Shinya Kitaoka |
120a6e |
parameterValues.push_back(w);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// End search max curvature point
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// Delete duplicate of parameterValues
|
|
Shinya Kitaoka |
120a6e |
// Because some max cuvature point can coincide with the corner point
|
|
Shinya Kitaoka |
120a6e |
if ((int)parameterValues.size() > 1) {
|
|
Shinya Kitaoka |
120a6e |
std::sort(parameterValues.begin(), parameterValues.end());
|
|
Shinya Kitaoka |
120a6e |
parameterValues.erase(
|
|
Shinya Kitaoka |
120a6e |
std::unique(parameterValues.begin(), parameterValues.end()),
|
|
Shinya Kitaoka |
120a6e |
parameterValues.end());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static void addStroke(TTool::Application *application, const TVectorImageP &vi,
|
|
Campbell Barton |
8c6c57 |
TStroke *stroke, bool breakAngles, bool frameCreated,
|
|
Jeremy Bullock |
129805 |
bool levelCreated, TXshSimpleLevel *sLevel = NULL,
|
|
Jeremy Bullock |
129805 |
TFrameId fid = TFrameId::NO_FRAME) {
|
|
Shinya Kitaoka |
120a6e |
QMutexLocker lock(vi->getMutex());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (application->getCurrentObject()->isSpline()) {
|
|
Shinya Kitaoka |
120a6e |
application->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<double> corners;</double>
|
|
Shinya Kitaoka |
120a6e |
std::vector<tstroke *=""> strokes;</tstroke>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
const float angoloLim =
|
|
Shinya Kitaoka |
120a6e |
1; // Value (radians) of the Corner between two tangent vector.
|
|
Shinya Kitaoka |
120a6e |
// Up this value the two corner can be considered angular.
|
|
Shinya Kitaoka |
120a6e |
const float curvMaxLim = 0.8; // Value of the max curvature.
|
|
Shinya Kitaoka |
120a6e |
// Up this value the point can be considered a max curvature point.
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
findMaxCurvPoints(stroke, angoloLim, curvMaxLim, corners);
|
|
Jeremy Bullock |
129805 |
TXshSimpleLevel *sl;
|
|
Jeremy Bullock |
129805 |
if (!sLevel) {
|
|
Jeremy Bullock |
129805 |
sl = application->getCurrentLevel()->getSimpleLevel();
|
|
Jeremy Bullock |
129805 |
} else {
|
|
Jeremy Bullock |
129805 |
sl = sLevel;
|
|
Jeremy Bullock |
129805 |
}
|
|
Shinya Kitaoka |
120a6e |
TFrameId id = application->getCurrentTool()->getTool()->getCurrentFid();
|
|
Jeremy Bullock |
129805 |
if (id == TFrameId::NO_FRAME && fid != TFrameId::NO_FRAME) id = fid;
|
|
Shinya Kitaoka |
120a6e |
if (!corners.empty()) {
|
|
Shinya Kitaoka |
120a6e |
if (breakAngles)
|
|
Shinya Kitaoka |
120a6e |
split(stroke, corners, strokes);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
strokes.push_back(new TStroke(*stroke));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int n = strokes.size();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->beginBlock();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < n; i++) {
|
|
Shinya Kitaoka |
120a6e |
std::vector<tfilledregioninf> *fillInformation =</tfilledregioninf>
|
|
Shinya Kitaoka |
120a6e |
new std::vector<tfilledregioninf>;</tfilledregioninf>
|
|
Shinya Kitaoka |
120a6e |
ImageUtils::getFillingInformationOverlappingArea(vi, *fillInformation,
|
|
Shinya Kitaoka |
120a6e |
stroke->getBBox());
|
|
Shinya Kitaoka |
120a6e |
TStroke *str = new TStroke(*strokes[i]);
|
|
Shinya Kitaoka |
120a6e |
vi->addStroke(str);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new UndoPencil(str, fillInformation, sl, id,
|
|
Shinya Kitaoka |
120a6e |
frameCreated, levelCreated));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->endBlock();
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
std::vector<tfilledregioninf> *fillInformation =</tfilledregioninf>
|
|
Shinya Kitaoka |
120a6e |
new std::vector<tfilledregioninf>;</tfilledregioninf>
|
|
Shinya Kitaoka |
120a6e |
ImageUtils::getFillingInformationOverlappingArea(vi, *fillInformation,
|
|
Shinya Kitaoka |
120a6e |
stroke->getBBox());
|
|
Shinya Kitaoka |
120a6e |
TStroke *str = new TStroke(*stroke);
|
|
Shinya Kitaoka |
120a6e |
vi->addStroke(str);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new UndoPencil(str, fillInformation, sl, id,
|
|
Shinya Kitaoka |
120a6e |
frameCreated, levelCreated));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
597034 |
// Update regions. It will call roundStroke() in
|
|
shun_iwasawa |
597034 |
// TVectorImage::Imp::findIntersections().
|
|
shun_iwasawa |
597034 |
// roundStroke() will slightly modify all the stroke positions.
|
|
shun_iwasawa |
597034 |
// It is needed to update information for Fill Check.
|
|
shun_iwasawa |
597034 |
vi->findRegions();
|
|
shun_iwasawa |
597034 |
|
|
Shinya Kitaoka |
120a6e |
for (int k = 0; k < (int)strokes.size(); k++) delete strokes[k];
|
|
Shinya Kitaoka |
120a6e |
strokes.clear();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void addStrokeToImage(TTool::Application *application, const TVectorImageP &vi,
|
|
Shinya Kitaoka |
120a6e |
TStroke *stroke, bool breakAngles, bool frameCreated,
|
|
Jeremy Bullock |
129805 |
bool levelCreated, TXshSimpleLevel *sLevel = NULL,
|
|
Jeremy Bullock |
129805 |
TFrameId id = TFrameId::NO_FRAME) {
|
|
Shinya Kitaoka |
120a6e |
QMutexLocker lock(vi->getMutex());
|
|
Shinya Kitaoka |
120a6e |
addStroke(application, vi.getPointer(), stroke, breakAngles, frameCreated,
|
|
Jeremy Bullock |
129805 |
levelCreated, sLevel, id);
|
|
Shinya Kitaoka |
120a6e |
// la notifica viene gia fatta da addStroke!
|
|
Shinya Kitaoka |
120a6e |
// getApplication()->getCurrentTool()->getTool()->notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
975eb1 |
//---------------------------------------------------------------------------------------------------------
|
|
shun-iwasawa |
975eb1 |
|
|
shun-iwasawa |
975eb1 |
enum DrawOrder { OverAll = 0, UnderAll, PaletteOrder };
|
|
shun-iwasawa |
975eb1 |
|
|
shun-iwasawa |
975eb1 |
void getAboveStyleIdSet(int styleId, TPaletteP palette,
|
|
shun-iwasawa |
975eb1 |
QSet<int> &aboveStyles) {</int>
|
|
shun-iwasawa |
975eb1 |
if (!palette) return;
|
|
shun-iwasawa |
975eb1 |
for (int p = 0; p < palette->getPageCount(); p++) {
|
|
shun-iwasawa |
975eb1 |
TPalette::Page *page = palette->getPage(p);
|
|
shun-iwasawa |
975eb1 |
for (int s = 0; s < page->getStyleCount(); s++) {
|
|
shun-iwasawa |
975eb1 |
int tmpId = page->getStyleId(s);
|
|
shun-iwasawa |
975eb1 |
if (tmpId == styleId) return;
|
|
shun-iwasawa |
975eb1 |
if (tmpId != 0) aboveStyles.insert(tmpId);
|
|
shun-iwasawa |
975eb1 |
}
|
|
shun-iwasawa |
975eb1 |
}
|
|
shun-iwasawa |
975eb1 |
}
|
|
shun-iwasawa |
975eb1 |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class RasterBrushUndo final : public TRasterUndo {
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint> m_points;</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
int m_styleId;
|
|
Shinya Kitaoka |
120a6e |
bool m_selective;
|
|
shun-iwasawa |
975eb1 |
bool m_isPaletteOrder;
|
|
Shinya Kitaoka |
120a6e |
bool m_isPencil;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RasterBrushUndo(TTileSetCM32 *tileSet, const std::vector<tthickpoint> &points,</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
int styleId, bool selective, TXshSimpleLevel *level,
|
|
Shinya Kitaoka |
120a6e |
const TFrameId &frameId, bool isPencil, bool isFrameCreated,
|
|
shun-iwasawa |
975eb1 |
bool isLevelCreated, bool isPaletteOrder)
|
|
Shinya Kitaoka |
120a6e |
: TRasterUndo(tileSet, level, frameId, isFrameCreated, isLevelCreated, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_points(points)
|
|
Shinya Kitaoka |
120a6e |
, m_styleId(styleId)
|
|
Shinya Kitaoka |
120a6e |
, m_selective(selective)
|
|
shun-iwasawa |
975eb1 |
, m_isPencil(isPencil)
|
|
shun-iwasawa |
975eb1 |
, m_isPaletteOrder(isPaletteOrder) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
insertLevelAndFrameIfNeeded();
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP image = getImage();
|
|
Shinya Kitaoka |
120a6e |
TRasterCM32P ras = image->getRaster();
|
|
shun-iwasawa |
975eb1 |
RasterStrokeGenerator m_rasterTrack(ras, BRUSH, NONE, m_styleId,
|
|
shun-iwasawa |
975eb1 |
m_points[0], m_selective, 0,
|
|
shun-iwasawa |
975eb1 |
!m_isPencil, m_isPaletteOrder);
|
|
shun-iwasawa |
975eb1 |
if (m_isPaletteOrder) {
|
|
shun-iwasawa |
975eb1 |
QSet<int> aboveStyleIds;</int>
|
|
shun-iwasawa |
975eb1 |
getAboveStyleIdSet(m_styleId, image->getPalette(), aboveStyleIds);
|
|
shun-iwasawa |
975eb1 |
m_rasterTrack.setAboveStyleIds(aboveStyleIds);
|
|
shun-iwasawa |
975eb1 |
}
|
|
Shinya Kitaoka |
120a6e |
m_rasterTrack.setPointsSequence(m_points);
|
|
Shinya Kitaoka |
120a6e |
m_rasterTrack.generateStroke(m_isPencil);
|
|
Shinya Kitaoka |
120a6e |
image->setSavebox(image->getSavebox() +
|
|
Shinya Kitaoka |
120a6e |
m_rasterTrack.getBBox(m_rasterTrack.getPointsSequence()));
|
|
Shinya Kitaoka |
120a6e |
ToolUtils::updateSaveBox();
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
38fd86 |
int getSize() const override {
|
|
Shinya Kitaoka |
38fd86 |
return sizeof(*this) + TRasterUndo::getSize();
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Shinya Kitaoka |
473e70 |
QString getToolName() override { return QString("Brush Tool"); }
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::BrushTool; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class RasterBluredBrushUndo final : public TRasterUndo {
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint> m_points;</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
int m_styleId;
|
|
shun-iwasawa |
975eb1 |
DrawOrder m_drawOrder;
|
|
Shinya Kitaoka |
120a6e |
int m_maxThick;
|
|
Shinya Kitaoka |
120a6e |
double m_hardness;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
RasterBluredBrushUndo(TTileSetCM32 *tileSet,
|
|
Shinya Kitaoka |
120a6e |
const std::vector<tthickpoint> &points, int styleId,</tthickpoint>
|
|
shun-iwasawa |
975eb1 |
DrawOrder drawOrder, TXshSimpleLevel *level,
|
|
Shinya Kitaoka |
120a6e |
const TFrameId &frameId, int maxThick, double hardness,
|
|
Shinya Kitaoka |
120a6e |
bool isFrameCreated, bool isLevelCreated)
|
|
Shinya Kitaoka |
120a6e |
: TRasterUndo(tileSet, level, frameId, isFrameCreated, isLevelCreated, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_points(points)
|
|
Shinya Kitaoka |
120a6e |
, m_styleId(styleId)
|
|
shun-iwasawa |
975eb1 |
, m_drawOrder(drawOrder)
|
|
Shinya Kitaoka |
120a6e |
, m_maxThick(maxThick)
|
|
Shinya Kitaoka |
120a6e |
, m_hardness(hardness) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
if (m_points.size() == 0) return;
|
|
Shinya Kitaoka |
120a6e |
insertLevelAndFrameIfNeeded();
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP image = getImage();
|
|
Shinya Kitaoka |
120a6e |
TRasterCM32P ras = image->getRaster();
|
|
Shinya Kitaoka |
120a6e |
TRasterCM32P backupRas = ras->clone();
|
|
Shinya Kitaoka |
120a6e |
TRaster32P workRaster(ras->getSize());
|
|
Shinya Kitaoka |
120a6e |
QRadialGradient brushPad = ToolUtils::getBrushPad(m_maxThick, m_hardness);
|
|
Shinya Kitaoka |
120a6e |
workRaster->clear();
|
|
Shinya Kitaoka |
120a6e |
BluredBrush brush(workRaster, m_maxThick, brushPad, false);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
975eb1 |
if (m_drawOrder == PaletteOrder) {
|
|
shun-iwasawa |
975eb1 |
QSet<int> aboveStyleIds;</int>
|
|
shun-iwasawa |
975eb1 |
getAboveStyleIdSet(m_styleId, image->getPalette(), aboveStyleIds);
|
|
shun-iwasawa |
975eb1 |
brush.setAboveStyleIds(aboveStyleIds);
|
|
shun-iwasawa |
975eb1 |
}
|
|
shun-iwasawa |
975eb1 |
|
|
Shinya Kitaoka |
120a6e |
std::vector<tthickpoint> points;</tthickpoint>
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[0]);
|
|
Shinya Kitaoka |
120a6e |
TRect bbox = brush.getBoundFromPoints(points);
|
|
Shinya Kitaoka |
120a6e |
brush.addPoint(m_points[0], 1);
|
|
shun-iwasawa |
975eb1 |
brush.updateDrawing(ras, ras, bbox, m_styleId, (int)m_drawOrder);
|
|
Shinya Kitaoka |
120a6e |
if (m_points.size() > 1) {
|
|
Shinya Kitaoka |
120a6e |
points.clear();
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[0]);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[1]);
|
|
Shinya Kitaoka |
120a6e |
bbox = brush.getBoundFromPoints(points);
|
|
Shinya Kitaoka |
120a6e |
brush.addArc(m_points[0], (m_points[1] + m_points[0]) * 0.5, m_points[1],
|
|
Shinya Kitaoka |
120a6e |
1, 1);
|
|
shun-iwasawa |
975eb1 |
brush.updateDrawing(ras, backupRas, bbox, m_styleId, (int)m_drawOrder);
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 1; i + 2 < (int)m_points.size(); i = i + 2) {
|
|
Shinya Kitaoka |
120a6e |
points.clear();
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[i]);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[i + 1]);
|
|
Shinya Kitaoka |
120a6e |
points.push_back(m_points[i + 2]);
|
|
Shinya Kitaoka |
120a6e |
bbox = brush.getBoundFromPoints(points);
|
|
Shinya Kitaoka |
120a6e |
brush.addArc(m_points[i], m_points[i + 1], m_points[i + 2], 1, 1);
|
|
shun-iwasawa |
975eb1 |
brush.updateDrawing(ras, backupRas, bbox, m_styleId, (int)m_drawOrder);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
ToolUtils::updateSaveBox();
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
38fd86 |
int getSize() const override {
|
|
Shinya Kitaoka |
38fd86 |
return sizeof(*this) + TRasterUndo::getSize();
|
|
Shinya Kitaoka |
38fd86 |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
QString getToolName() override { return QString("Brush Tool"); }
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::BrushTool; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
class MyPaintBrushUndo final : public TRasterUndo {
|
|
shun-iwasawa |
98926d |
TPoint m_offset;
|
|
shun-iwasawa |
98926d |
QString m_id;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
public:
|
|
shun-iwasawa |
98926d |
MyPaintBrushUndo(TTileSetCM32 *tileSet, TXshSimpleLevel *level,
|
|
shun-iwasawa |
98926d |
const TFrameId &frameId, bool isFrameCreated,
|
|
shun-iwasawa |
98926d |
bool isLevelCreated, const TRasterCM32P &ras,
|
|
shun-iwasawa |
98926d |
const TPoint &offset)
|
|
shun-iwasawa |
98926d |
: TRasterUndo(tileSet, level, frameId, isFrameCreated, isLevelCreated, 0)
|
|
shun-iwasawa |
98926d |
, m_offset(offset) {
|
|
shun-iwasawa |
98926d |
static int counter = 0;
|
|
shun-iwasawa |
98926d |
m_id = QString("MyPaintBrushUndo") + QString::number(counter++);
|
|
shun-iwasawa |
98926d |
TImageCache::instance()->add(m_id.toStdString(),
|
|
shun-iwasawa |
98926d |
TToonzImageP(ras, TRect(ras->getSize())));
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
~MyPaintBrushUndo() { TImageCache::instance()->remove(m_id); }
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
void redo() const override {
|
|
shun-iwasawa |
98926d |
insertLevelAndFrameIfNeeded();
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
TToonzImageP image = getImage();
|
|
shun-iwasawa |
98926d |
TRasterCM32P ras = image->getRaster();
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
TImageP srcImg =
|
|
shun-iwasawa |
98926d |
TImageCache::instance()->get(m_id.toStdString(), false)->cloneImage();
|
|
shun-iwasawa |
98926d |
TToonzImageP tSrcImg = srcImg;
|
|
shun-iwasawa |
98926d |
assert(tSrcImg);
|
|
shun-iwasawa |
98926d |
ras->copy(tSrcImg->getRaster(), m_offset);
|
|
shun-iwasawa |
98926d |
ToolUtils::updateSaveBox();
|
|
shun-iwasawa |
98926d |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
shun-iwasawa |
98926d |
notifyImageChanged();
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
int getSize() const override {
|
|
shun-iwasawa |
98926d |
return sizeof(*this) + TRasterUndo::getSize();
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
QString getToolName() override { return QString("Brush Tool"); }
|
|
shun-iwasawa |
98926d |
int getHistoryType() override { return HistoryType::BrushTool; }
|
|
shun-iwasawa |
98926d |
};
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
//=========================================================================================================
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
double computeThickness(double pressure, const TDoublePairProperty &property) {
|
|
shun-iwasawa |
600da6 |
double t = pressure * pressure * pressure;
|
|
Shinya Kitaoka |
120a6e |
double thick0 = property.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
double thick1 = property.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
if (thick1 < 0.0001) thick0 = thick1 = 0.0;
|
|
Shinya Kitaoka |
120a6e |
return (thick0 + (thick1 - thick0) * t) * 0.5;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
int computeThickness(double pressure, const TIntPairProperty &property) {
|
|
shun-iwasawa |
600da6 |
double t = pressure * pressure * pressure;
|
|
Shinya Kitaoka |
120a6e |
int thick0 = property.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
int thick1 = property.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
return tround(thick0 + (thick1 - thick0) * t);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
walkerka |
57fb3c |
//--------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
static void CatmullRomInterpolate(const TThickPoint &P0, const TThickPoint &P1,
|
|
walkerka |
22f456 |
const TThickPoint &P2, const TThickPoint &P3,
|
|
walkerka |
22f456 |
int samples,
|
|
walkerka |
22f456 |
std::vector<tthickpoint> &points) {</tthickpoint>
|
|
walkerka |
22f456 |
double x0 = P1.x;
|
|
walkerka |
22f456 |
double x1 = (-P0.x + P2.x) * 0.5f;
|
|
walkerka |
22f456 |
double x2 = P0.x - 2.5f * P1.x + 2.0f * P2.x - 0.5f * P3.x;
|
|
walkerka |
22f456 |
double x3 = -0.5f * P0.x + 1.5f * P1.x - 1.5f * P2.x + 0.5f * P3.x;
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
double y0 = P1.y;
|
|
walkerka |
22f456 |
double y1 = (-P0.y + P2.y) * 0.5f;
|
|
walkerka |
22f456 |
double y2 = P0.y - 2.5f * P1.y + 2.0f * P2.y - 0.5f * P3.y;
|
|
walkerka |
22f456 |
double y3 = -0.5f * P0.y + 1.5f * P1.y - 1.5f * P2.y + 0.5f * P3.y;
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
double z0 = P1.thick;
|
|
walkerka |
22f456 |
double z1 = (-P0.thick + P2.thick) * 0.5f;
|
|
walkerka |
22f456 |
double z2 = P0.thick - 2.5f * P1.thick + 2.0f * P2.thick - 0.5f * P3.thick;
|
|
walkerka |
22f456 |
double z3 =
|
|
walkerka |
22f456 |
-0.5f * P0.thick + 1.5f * P1.thick - 1.5f * P2.thick + 0.5f * P3.thick;
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
for (int i = 1; i <= samples; ++i) {
|
|
walkerka |
22f456 |
double t = i / (double)(samples + 1);
|
|
walkerka |
22f456 |
double t2 = t * t;
|
|
walkerka |
22f456 |
double t3 = t2 * t;
|
|
walkerka |
22f456 |
TThickPoint p;
|
|
walkerka |
22f456 |
p.x = x0 + x1 * t + x2 * t2 + x3 * t3;
|
|
walkerka |
22f456 |
p.y = y0 + y1 * t + y2 * t2 + y3 * t3;
|
|
walkerka |
22f456 |
p.thick = z0 + z1 * t + z2 * t2 + z3 * t3;
|
|
walkerka |
22f456 |
points.push_back(p);
|
|
walkerka |
22f456 |
}
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
57fb3c |
//--------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
static void Smooth(std::vector<tthickpoint> &points, int radius) {</tthickpoint>
|
|
walkerka |
22f456 |
int n = (int)points.size();
|
|
walkerka |
22f456 |
if (radius < 1 || n < 3) {
|
|
walkerka |
22f456 |
return;
|
|
walkerka |
22f456 |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
std::vector<tthickpoint> result;</tthickpoint>
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
float d = 1.0f / (radius * 2 + 1);
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
for (int i = 1; i < n - 1; ++i) {
|
|
walkerka |
22f456 |
int lower = i - radius;
|
|
walkerka |
22f456 |
int upper = i + radius;
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
TThickPoint total;
|
|
walkerka |
22f456 |
total.x = 0;
|
|
walkerka |
22f456 |
total.y = 0;
|
|
walkerka |
22f456 |
total.thick = 0;
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
for (int j = lower; j <= upper; ++j) {
|
|
walkerka |
22f456 |
int idx = j;
|
|
walkerka |
22f456 |
if (idx < 0) {
|
|
walkerka |
22f456 |
idx = 0;
|
|
walkerka |
22f456 |
} else if (idx >= n) {
|
|
walkerka |
22f456 |
idx = n - 1;
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
total.x += points[idx].x;
|
|
walkerka |
22f456 |
total.y += points[idx].y;
|
|
walkerka |
22f456 |
total.thick += points[idx].thick;
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
total.x *= d;
|
|
walkerka |
22f456 |
total.y *= d;
|
|
walkerka |
22f456 |
total.thick *= d;
|
|
walkerka |
22f456 |
result.push_back(total);
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
for (int i = 1; i < n - 1; ++i) {
|
|
walkerka |
22f456 |
points[i].x = result[i - 1].x;
|
|
walkerka |
22f456 |
points[i].y = result[i - 1].y;
|
|
walkerka |
22f456 |
points[i].thick = result[i - 1].thick;
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
if (points.size() >= 3) {
|
|
walkerka |
22f456 |
std::vector<tthickpoint> pts;</tthickpoint>
|
|
walkerka |
22f456 |
CatmullRomInterpolate(points[0], points[0], points[1], points[2], 10, pts);
|
|
walkerka |
22f456 |
std::vector<tthickpoint>::iterator it = points.begin();</tthickpoint>
|
|
walkerka |
22f456 |
points.insert(it, pts.begin(), pts.end());
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
pts.clear();
|
|
walkerka |
22f456 |
CatmullRomInterpolate(points[n - 3], points[n - 2], points[n - 1],
|
|
walkerka |
22f456 |
points[n - 1], 10, pts);
|
|
walkerka |
22f456 |
it = points.begin();
|
|
walkerka |
22f456 |
it += n - 1;
|
|
walkerka |
22f456 |
points.insert(it, pts.begin(), pts.end());
|
|
walkerka |
22f456 |
}
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
57fb3c |
//--------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
void SmoothStroke::beginStroke(int smooth) {
|
|
walkerka |
22f456 |
m_smooth = smooth;
|
|
walkerka |
22f456 |
m_outputIndex = 0;
|
|
walkerka |
22f456 |
m_readIndex = -1;
|
|
walkerka |
22f456 |
m_rawPoints.clear();
|
|
walkerka |
22f456 |
m_outputPoints.clear();
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
57fb3c |
//--------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
void SmoothStroke::addPoint(const TThickPoint &point) {
|
|
walkerka |
22f456 |
if (m_rawPoints.size() > 0 && m_rawPoints.back().x == point.x &&
|
|
walkerka |
22f456 |
m_rawPoints.back().y == point.y) {
|
|
walkerka |
22f456 |
return;
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
m_rawPoints.push_back(point);
|
|
walkerka |
22f456 |
generatePoints();
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
57fb3c |
//--------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
void SmoothStroke::endStroke() {
|
|
walkerka |
22f456 |
generatePoints();
|
|
walkerka |
22f456 |
// force enable the output all segments
|
|
walkerka |
22f456 |
m_outputIndex = m_outputPoints.size() - 1;
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
57fb3c |
//--------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
Jeremy Bullock |
7f2044 |
void SmoothStroke::clearPoints() {
|
|
Jeremy Bullock |
7f2044 |
m_outputIndex = 0;
|
|
Jeremy Bullock |
7f2044 |
m_readIndex = -1;
|
|
Jeremy Bullock |
7f2044 |
m_outputPoints.clear();
|
|
Jeremy Bullock |
7f2044 |
m_rawPoints.clear();
|
|
Jeremy Bullock |
7f2044 |
}
|
|
Jeremy Bullock |
7f2044 |
|
|
Jeremy Bullock |
7f2044 |
//--------------------------------------------------------------------------------------------------
|
|
Jeremy Bullock |
7f2044 |
|
|
walkerka |
22f456 |
void SmoothStroke::getSmoothPoints(std::vector<tthickpoint> &smoothPoints) {</tthickpoint>
|
|
walkerka |
22f456 |
int n = m_outputPoints.size();
|
|
walkerka |
22f456 |
for (int i = m_readIndex + 1; i <= m_outputIndex && i < n; ++i) {
|
|
walkerka |
22f456 |
smoothPoints.push_back(m_outputPoints[i]);
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
m_readIndex = m_outputIndex;
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
walkerka |
57fb3c |
//--------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
walkerka |
22f456 |
void SmoothStroke::generatePoints() {
|
|
walkerka |
22f456 |
int n = (int)m_rawPoints.size();
|
|
walkerka |
22f456 |
if (n == 0) {
|
|
walkerka |
22f456 |
return;
|
|
walkerka |
22f456 |
}
|
|
shun-iwasawa |
d6e799 |
|
|
shun-iwasawa |
d6e799 |
// if m_smooth = 0, then skip whole smoothing process
|
|
shun-iwasawa |
d6e799 |
if (m_smooth == 0) {
|
|
shun-iwasawa |
d6e799 |
for (int i = m_outputIndex; i < (int)m_outputPoints.size(); ++i) {
|
|
shun-iwasawa |
d6e799 |
if (m_outputPoints[i] != m_rawPoints[i]) {
|
|
shun-iwasawa |
d6e799 |
break;
|
|
shun-iwasawa |
d6e799 |
}
|
|
shun-iwasawa |
d6e799 |
++m_outputIndex;
|
|
shun-iwasawa |
d6e799 |
}
|
|
shun-iwasawa |
d6e799 |
m_outputPoints = m_rawPoints;
|
|
shun-iwasawa |
d6e799 |
return;
|
|
shun-iwasawa |
d6e799 |
}
|
|
shun-iwasawa |
d6e799 |
|
|
walkerka |
22f456 |
std::vector<tthickpoint> smoothedPoints;</tthickpoint>
|
|
walkerka |
22f456 |
// Add more stroke samples before applying the smoothing
|
|
walkerka |
22f456 |
// This is because the raw inputs points are too few to support smooth result,
|
|
walkerka |
22f456 |
// especially on stroke ends
|
|
walkerka |
22f456 |
smoothedPoints.push_back(m_rawPoints.front());
|
|
walkerka |
22f456 |
for (int i = 1; i < n; ++i) {
|
|
walkerka |
22f456 |
const TThickPoint &p1 = m_rawPoints[i - 1];
|
|
walkerka |
22f456 |
const TThickPoint &p2 = m_rawPoints[i];
|
|
walkerka |
22f456 |
const TThickPoint &p0 = i - 2 >= 0 ? m_rawPoints[i - 2] : p1;
|
|
walkerka |
22f456 |
const TThickPoint &p3 = i + 1 < n ? m_rawPoints[i + 1] : p2;
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
int samples = 8;
|
|
walkerka |
22f456 |
CatmullRomInterpolate(p0, p1, p2, p3, samples, smoothedPoints);
|
|
walkerka |
22f456 |
smoothedPoints.push_back(p2);
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
// Apply the 1D box filter
|
|
walkerka |
22f456 |
// Multiple passes result in better quality and fix the stroke ends break
|
|
walkerka |
22f456 |
// issue
|
|
walkerka |
22f456 |
for (int i = 0; i < 3; ++i) {
|
|
walkerka |
22f456 |
Smooth(smoothedPoints, m_smooth);
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
// Compare the new smoothed stroke with old one
|
|
walkerka |
22f456 |
// Enable the output for unchanged parts
|
|
walkerka |
22f456 |
int outputNum = (int)m_outputPoints.size();
|
|
walkerka |
22f456 |
for (int i = m_outputIndex; i < outputNum; ++i) {
|
|
walkerka |
22f456 |
if (m_outputPoints[i] != smoothedPoints[i]) {
|
|
walkerka |
22f456 |
break;
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
22f456 |
++m_outputIndex;
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
m_outputPoints = smoothedPoints;
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
shun-iwasawa |
98926d |
// ToonzRasterBrushTool
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
ToonzRasterBrushTool::ToonzRasterBrushTool(std::string name, int targetType)
|
|
Shinya Kitaoka |
120a6e |
: TTool(name)
|
|
Shinya Kitaoka |
120a6e |
, m_rasThickness("Size", 1, 100, 1, 5)
|
|
walkerka |
bb91cd |
, m_smooth("Smooth:", 0, 50, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_hardness("Hardness:", 0, 100, 100)
|
|
Shinya Kitaoka |
120a6e |
, m_preset("Preset:")
|
|
shun-iwasawa |
975eb1 |
, m_drawOrder("Draw Order:")
|
|
Shinya Kitaoka |
120a6e |
, m_pencil("Pencil", false)
|
|
Shinya Kitaoka |
120a6e |
, m_pressure("Pressure", true)
|
|
shun-iwasawa |
98926d |
, m_modifierSize("ModifierSize", -3, 3, 0, true)
|
|
Shinya Kitaoka |
120a6e |
, m_rasterTrack(0)
|
|
Shinya Kitaoka |
120a6e |
, m_styleId(0)
|
|
Shinya Kitaoka |
120a6e |
, m_bluredBrush(0)
|
|
Shinya Kitaoka |
120a6e |
, m_active(false)
|
|
Shinya Kitaoka |
120a6e |
, m_enabled(false)
|
|
Shinya Kitaoka |
120a6e |
, m_isPrompting(false)
|
|
Shinya Kitaoka |
120a6e |
, m_firstTime(true)
|
|
Shinya Kitaoka |
120a6e |
, m_presetsLoaded(false)
|
|
Jeremy Bullock |
cd00fd |
, m_targetType(targetType)
|
|
shun-iwasawa |
98926d |
, m_workingFrameId(TFrameId())
|
|
shun-iwasawa |
98926d |
, m_notifier(0) {
|
|
Shinya Kitaoka |
120a6e |
bind(targetType);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
m_prop[0].bind(m_rasThickness);
|
|
shun-iwasawa |
98926d |
m_prop[0].bind(m_hardness);
|
|
shun-iwasawa |
98926d |
m_prop[0].bind(m_smooth);
|
|
shun-iwasawa |
98926d |
m_prop[0].bind(m_drawOrder);
|
|
shun-iwasawa |
98926d |
m_prop[0].bind(m_modifierSize);
|
|
shun-iwasawa |
98926d |
m_prop[0].bind(m_pencil);
|
|
shun-iwasawa |
98926d |
m_pencil.setId("PencilMode");
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
m_drawOrder.addValue(L"Over All");
|
|
shun-iwasawa |
98926d |
m_drawOrder.addValue(L"Under All");
|
|
shun-iwasawa |
98926d |
m_drawOrder.addValue(L"Palette Order");
|
|
shun-iwasawa |
98926d |
m_drawOrder.setId("DrawOrder");
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_prop[0].bind(m_pressure);
|
|
Jeremy Bullock |
cd00fd |
|
|
Shinya Kitaoka |
120a6e |
m_prop[0].bind(m_preset);
|
|
Shinya Kitaoka |
120a6e |
m_preset.setId("BrushPreset");
|
|
Shinya Kitaoka |
120a6e |
m_preset.addValue(CUSTOM_WSTR);
|
|
Campbell Barton |
f49389 |
m_pressure.setId("PressureSensitivity");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
ToolOptionsBox *ToonzRasterBrushTool::createOptionsBox() {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *currPalette =
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getPaletteController()->getCurrentLevelPalette();
|
|
Shinya Kitaoka |
120a6e |
ToolHandle *currTool = TTool::getApplication()->getCurrentTool();
|
|
Shinya Kitaoka |
120a6e |
return new BrushToolOptionsBox(0, this, currPalette, currTool);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::drawLine(const TPointD &point, const TPointD ¢re,
|
|
shun-iwasawa |
98926d |
bool horizontal, bool isDecimal) {
|
|
Shinya Kitaoka |
120a6e |
if (!isDecimal) {
|
|
Shinya Kitaoka |
120a6e |
if (horizontal) {
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 1.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y - 0.5, -point.x + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y - 0.5, -point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x - 0.5, -point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y - 0.5, point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y - 0.5, point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 0.5, -point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 1.5, -point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, -point.x + 1.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x - 0.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 1.5, point.y + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 1.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 1.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y - 0.5, -point.x + 1.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y - 0.5, -point.x + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y - 0.5, -point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x + 0.5, -point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x - 0.5, -point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 1.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y - 0.5, point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y - 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y - 0.5, point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 1.5, -point.y - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 1.5, -point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 1.5, -point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 0.5, -point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 1.5, -point.x + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, -point.x + 1.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, -point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (horizontal) {
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 0.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x + 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y + 0.5, point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y + 0.5, -point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x + 0.5, -point.y - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 0.5, -point.y - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x - 0.5, -point.y - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x + 0.5, -point.y - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, -point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 0.5, point.y + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 0.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x + 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 1.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y + 0.5, point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y + 0.5, point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 1.5, -point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y + 0.5, -point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.y + 0.5, -point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.y + 0.5, -point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 0.5, -point.y - 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x - 0.5, -point.y - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(point.x - 0.5, -point.y - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(point.x + 0.5, -point.y - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x + 0.5, -point.y - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, -point.y - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x - 0.5, -point.y - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 1.5, -point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, -point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, -point.x + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, -point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 1.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, point.x - 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.y - 0.5, point.x - 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.y - 0.5, point.x + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 1.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x + 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
tglDrawSegment(TPointD(-point.x + 0.5, point.y + 0.5) + centre,
|
|
Shinya Kitaoka |
120a6e |
TPointD(-point.x - 0.5, point.y + 0.5) + centre);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::drawEmptyCircle(TPointD pos, int thick,
|
|
shun-iwasawa |
98926d |
bool isLxEven, bool isLyEven,
|
|
shun-iwasawa |
98926d |
bool isPencil) {
|
|
Shinya Kitaoka |
120a6e |
if (isLxEven) pos.x += 0.5;
|
|
Shinya Kitaoka |
120a6e |
if (isLyEven) pos.y += 0.5;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!isPencil)
|
|
Shinya Kitaoka |
120a6e |
tglDrawCircle(pos, (thick + 1) * 0.5);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
int x = 0, y = tround((thick * 0.5) - 0.5);
|
|
Shinya Kitaoka |
120a6e |
int d = 3 - 2 * (int)(thick * 0.5);
|
|
Shinya Kitaoka |
120a6e |
bool horizontal = true, isDecimal = thick % 2 != 0;
|
|
Shinya Kitaoka |
120a6e |
drawLine(TPointD(x, y), pos, horizontal, isDecimal);
|
|
Shinya Kitaoka |
120a6e |
while (y > x) {
|
|
Shinya Kitaoka |
120a6e |
if (d < 0) {
|
|
Shinya Kitaoka |
120a6e |
d = d + 4 * x + 6;
|
|
Shinya Kitaoka |
120a6e |
horizontal = true;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
d = d + 4 * (x - y) + 10;
|
|
Shinya Kitaoka |
120a6e |
horizontal = false;
|
|
Shinya Kitaoka |
120a6e |
y--;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
x++;
|
|
Shinya Kitaoka |
120a6e |
drawLine(TPointD(x, y), pos, horizontal, isDecimal);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
manongjohn |
603264 |
TPointD ToonzRasterBrushTool::getCenteredCursorPos(
|
|
manongjohn |
603264 |
const TPointD &originalCursorPos) {
|
|
manongjohn |
fe8e5c |
if (m_isMyPaintStyleSelected) return originalCursorPos;
|
|
manongjohn |
603264 |
TXshLevelHandle *levelHandle = m_application->getCurrentLevel();
|
|
manongjohn |
603264 |
TXshSimpleLevel *level = levelHandle ? levelHandle->getSimpleLevel() : 0;
|
|
manongjohn |
603264 |
TDimension resolution =
|
|
manongjohn |
603264 |
level ? level->getProperties()->getImageRes() : TDimension(0, 0);
|
|
manongjohn |
603264 |
|
|
Martin van Zijl |
e9b900 |
bool xEven = (resolution.lx % 2 == 0);
|
|
Martin van Zijl |
e9b900 |
bool yEven = (resolution.ly % 2 == 0);
|
|
Martin van Zijl |
e9b900 |
|
|
Martin van Zijl |
e9b900 |
TPointD centeredCursorPos = originalCursorPos;
|
|
Martin van Zijl |
e9b900 |
|
|
manongjohn |
603264 |
if (xEven) centeredCursorPos.x -= 0.5;
|
|
manongjohn |
603264 |
if (yEven) centeredCursorPos.y -= 0.5;
|
|
Martin van Zijl |
e9b900 |
|
|
Martin van Zijl |
e9b900 |
return centeredCursorPos;
|
|
Martin van Zijl |
e9b900 |
}
|
|
Martin van Zijl |
e9b900 |
|
|
Martin van Zijl |
e9b900 |
//-------------------------------------------------------------------------------------------------------
|
|
Martin van Zijl |
e9b900 |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::updateTranslation() {
|
|
Shinya Kitaoka |
120a6e |
m_rasThickness.setQStringName(tr("Size"));
|
|
Shinya Kitaoka |
120a6e |
m_hardness.setQStringName(tr("Hardness:"));
|
|
walkerka |
bb91cd |
m_smooth.setQStringName(tr("Smooth:"));
|
|
shun-iwasawa |
975eb1 |
m_drawOrder.setQStringName(tr("Draw Order:"));
|
|
shun-iwasawa |
98926d |
m_drawOrder.setItemUIName(L"Over All", tr("Over All"));
|
|
shun-iwasawa |
98926d |
m_drawOrder.setItemUIName(L"Under All", tr("Under All"));
|
|
shun-iwasawa |
98926d |
m_drawOrder.setItemUIName(L"Palette Order", tr("Palette Order"));
|
|
shun-iwasawa |
98926d |
m_modifierSize.setQStringName(tr("Size"));
|
|
shun-iwasawa |
98926d |
|
|
Shinya Kitaoka |
120a6e |
// m_filled.setQStringName(tr("Filled"));
|
|
Shinya Kitaoka |
120a6e |
m_preset.setQStringName(tr("Preset:"));
|
|
shun-iwasawa |
df7bb0 |
m_preset.setItemUIName(CUSTOM_WSTR, tr("<custom>"));</custom>
|
|
Shinya Kitaoka |
120a6e |
m_pencil.setQStringName(tr("Pencil"));
|
|
Shinya Kitaoka |
120a6e |
m_pressure.setQStringName(tr("Pressure"));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::updateWorkAndBackupRasters(const TRect &rect) {
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = TImageP(getImage(false, 1));
|
|
Shinya Kitaoka |
120a6e |
if (!ti) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterCM32P ras = ti->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
if (m_isMyPaintStyleSelected) {
|
|
shun-iwasawa |
98926d |
const int denominator = 8;
|
|
shun-iwasawa |
98926d |
TRect enlargedRect = rect + m_lastRect;
|
|
shun-iwasawa |
98926d |
int dx = (enlargedRect.getLx() - 1) / denominator + 1;
|
|
shun-iwasawa |
98926d |
int dy = (enlargedRect.getLy() - 1) / denominator + 1;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
if (m_lastRect.isEmpty()) {
|
|
shun-iwasawa |
98926d |
enlargedRect.x0 -= dx;
|
|
shun-iwasawa |
98926d |
enlargedRect.y0 -= dy;
|
|
shun-iwasawa |
98926d |
enlargedRect.x1 += dx;
|
|
shun-iwasawa |
98926d |
enlargedRect.y1 += dy;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
TRect _rect = enlargedRect * ras->getBounds();
|
|
shun-iwasawa |
98926d |
if (_rect.isEmpty()) return;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_workRas->extract(_rect)->copy(ras->extract(_rect));
|
|
shun-iwasawa |
98926d |
m_backupRas->extract(_rect)->copy(ras->extract(_rect));
|
|
shun-iwasawa |
98926d |
} else {
|
|
shun-iwasawa |
98926d |
if (enlargedRect.x0 < m_lastRect.x0) enlargedRect.x0 -= dx;
|
|
shun-iwasawa |
98926d |
if (enlargedRect.y0 < m_lastRect.y0) enlargedRect.y0 -= dy;
|
|
shun-iwasawa |
98926d |
if (enlargedRect.x1 > m_lastRect.x1) enlargedRect.x1 += dx;
|
|
shun-iwasawa |
98926d |
if (enlargedRect.y1 > m_lastRect.y1) enlargedRect.y1 += dy;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
TRect _rect = enlargedRect * ras->getBounds();
|
|
shun-iwasawa |
98926d |
if (_rect.isEmpty()) return;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
TRect _lastRect = m_lastRect * ras->getBounds();
|
|
shun-iwasawa |
98926d |
QList<trect> rects = ToolUtils::splitRect(_rect, _lastRect);</trect>
|
|
shun-iwasawa |
98926d |
for (int i = 0; i < rects.size(); i++) {
|
|
shun-iwasawa |
98926d |
m_workRas->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
shun-iwasawa |
98926d |
m_backupRas->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_lastRect = enlargedRect;
|
|
shun-iwasawa |
98926d |
return;
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
Shinya Kitaoka |
120a6e |
TRect _rect = rect * ras->getBounds();
|
|
Shinya Kitaoka |
120a6e |
TRect _lastRect = m_lastRect * ras->getBounds();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (_rect.isEmpty()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_lastRect.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
m_workRas->extract(_rect)->clear();
|
|
Shinya Kitaoka |
120a6e |
m_backupRas->extract(_rect)->copy(ras->extract(_rect));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QList<trect> rects = ToolUtils::splitRect(_rect, _lastRect);</trect>
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < rects.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
m_workRas->extract(rects[i])->clear();
|
|
Shinya Kitaoka |
120a6e |
m_backupRas->extract(rects[i])->copy(ras->extract(rects[i]));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::onActivate() {
|
|
shun-iwasawa |
98926d |
if (!m_notifier) m_notifier = new ToonzRasterBrushToolNotifier(this);
|
|
shun-iwasawa |
98926d |
|
|
Shinya Kitaoka |
120a6e |
if (m_firstTime) {
|
|
Shinya Kitaoka |
120a6e |
m_rasThickness.setValue(
|
|
Shinya Kitaoka |
120a6e |
TDoublePairProperty::Value(RasterBrushMinSize, RasterBrushMaxSize));
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_drawOrder.setIndex(BrushDrawOrder);
|
|
shun-iwasawa |
98926d |
m_pencil.setValue(RasterBrushPencilMode ? 1 : 0);
|
|
shun-iwasawa |
98926d |
m_hardness.setValue(RasterBrushHardness);
|
|
shun-iwasawa |
98926d |
|
|
Campbell Barton |
f49389 |
m_pressure.setValue(BrushPressureSensitivity ? 1 : 0);
|
|
Shinya Kitaoka |
120a6e |
m_firstTime = false;
|
|
walkerka |
bb91cd |
m_smooth.setValue(BrushSmooth);
|
|
shun-iwasawa |
98926d |
m_modifierSize.setValue(RasterBrushModifierSize);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
98926d |
m_brushPad = ToolUtils::getBrushPad(m_rasThickness.getValue().second,
|
|
shun-iwasawa |
98926d |
m_hardness.getValue() * 0.01);
|
|
shun-iwasawa |
98926d |
setWorkAndBackupImages();
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_brushTimer.start();
|
|
Shinya Kitaoka |
120a6e |
// TODO:app->editImageOrSpline();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::onDeactivate() {
|
|
Shinya Kitaoka |
120a6e |
/*---
|
|
Shinya Kitaoka |
120a6e |
* ドラッグ中にツールが切り替わった場合に備え、onDeactivateにもMouseReleaseと同じ処理を行う
|
|
Shinya Kitaoka |
120a6e |
* ---*/
|
|
shun-iwasawa |
98926d |
if (m_tileSaver) {
|
|
Shinya Kitaoka |
120a6e |
bool isValid = m_enabled && m_active;
|
|
Shinya Kitaoka |
120a6e |
m_enabled = false;
|
|
manongjohn |
482ab4 |
m_active = false;
|
|
Shinya Kitaoka |
120a6e |
if (isValid) {
|
|
shun-iwasawa |
98926d |
finishRasterBrush(m_mousePos,
|
|
shun-iwasawa |
98926d |
1); /*-- 最後のストロークの筆圧は1とする --*/
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_workRas = TRaster32P();
|
|
Shinya Kitaoka |
120a6e |
m_backupRas = TRasterCM32P();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
bool ToonzRasterBrushTool::askRead(const TRect &rect) { return askWrite(rect); }
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
//--------------------------------------------------------------------------------------------------
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
bool ToonzRasterBrushTool::askWrite(const TRect &rect) {
|
|
shun-iwasawa |
98926d |
if (rect.isEmpty()) return true;
|
|
shun-iwasawa |
98926d |
m_strokeRect += rect;
|
|
shun-iwasawa |
98926d |
m_strokeSegmentRect += rect;
|
|
shun-iwasawa |
98926d |
updateWorkAndBackupRasters(rect);
|
|
shun-iwasawa |
98926d |
m_tileSaver->save(rect);
|
|
shun-iwasawa |
98926d |
return true;
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
//--------------------------------------------------------------------------------------------------
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
bool ToonzRasterBrushTool::preLeftButtonDown() {
|
|
Shinya Kitaoka |
120a6e |
touchImage();
|
|
shun-iwasawa |
85f3fb |
if (m_isFrameCreated) {
|
|
shun-iwasawa |
85f3fb |
setWorkAndBackupImages();
|
|
shun-iwasawa |
85f3fb |
// When the xsheet frame is selected, whole viewer will be updated from
|
|
shun-iwasawa |
85f3fb |
// SceneViewer::onXsheetChanged() on adding a new frame.
|
|
shun-iwasawa |
85f3fb |
// We need to take care of a case when the level frame is selected.
|
|
shun-iwasawa |
85f3fb |
if (m_application->getCurrentFrame()->isEditingLevel()) invalidate();
|
|
shun-iwasawa |
85f3fb |
}
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,
|
|
shun-iwasawa |
98926d |
const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
TTool::Application *app = TTool::getApplication();
|
|
Shinya Kitaoka |
120a6e |
if (!app) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int col = app->getCurrentColumn()->getColumnIndex();
|
|
shun-iwasawa |
98926d |
m_enabled = col >= 0;
|
|
Shinya Kitaoka |
120a6e |
// todo: gestire autoenable
|
|
Shinya Kitaoka |
120a6e |
if (!m_enabled) return;
|
|
shun-iwasawa |
98926d |
|
|
Martin van Zijl |
e9b900 |
TPointD centeredPos = getCenteredCursorPos(pos);
|
|
Martin van Zijl |
8b0f8d |
|
|
shun-iwasawa |
98926d |
m_currentColor = TPixel32::Black;
|
|
shun-iwasawa |
98926d |
m_active = !!getImage(true);
|
|
shun-iwasawa |
98926d |
if (!m_active) {
|
|
shun-iwasawa |
98926d |
m_active = !!touchImage();
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
if (!m_active) return;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
if (m_active) {
|
|
shun-iwasawa |
98926d |
// nel caso che il colore corrente sia un cleanup/studiopalette color
|
|
shun-iwasawa |
98926d |
// oppure il colore di un colorfield
|
|
shun-iwasawa |
98926d |
m_styleId = app->getCurrentLevelStyleIndex();
|
|
shun-iwasawa |
98926d |
TColorStyle *cs = app->getCurrentLevelStyle();
|
|
shun-iwasawa |
98926d |
if (cs) {
|
|
shun-iwasawa |
98926d |
TRasterStyleFx *rfx = cs ? cs->getRasterStyleFx() : 0;
|
|
shun-iwasawa |
98926d |
m_active = cs != 0 && (cs->isStrokeStyle() || (rfx && rfx->isInkStyle()));
|
|
shun-iwasawa |
98926d |
m_currentColor = cs->getAverageColor();
|
|
shun-iwasawa |
98926d |
m_currentColor.m = 255;
|
|
shun-iwasawa |
98926d |
} else {
|
|
shun-iwasawa |
98926d |
m_styleId = 1;
|
|
shun-iwasawa |
98926d |
m_currentColor = TPixel32::Black;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
98926d |
|
|
Shinya Kitaoka |
120a6e |
// assert(0<=m_styleId && m_styleId<2);
|
|
Shinya Kitaoka |
120a6e |
TImageP img = getImage(true);
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ri(img);
|
|
shun-iwasawa |
98926d |
TRasterCM32P ras = ri->getRaster();
|
|
shun-iwasawa |
98926d |
if (ras) {
|
|
shun-iwasawa |
98926d |
TPointD rasCenter = ras->getCenterD();
|
|
shun-iwasawa |
98926d |
m_tileSet = new TTileSetCM32(ras->getSize());
|
|
shun-iwasawa |
98926d |
m_tileSaver = new TTileSaverCM32(ras, m_tileSet);
|
|
shun-iwasawa |
98926d |
double maxThick = m_rasThickness.getValue().second;
|
|
shun-iwasawa |
98926d |
double thickness = (m_pressure.getValue())
|
|
shun-iwasawa |
98926d |
? computeThickness(e.m_pressure, m_rasThickness) * 2
|
|
shun-iwasawa |
98926d |
: maxThick;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
/*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する
|
|
shun-iwasawa |
98926d |
* ---*/
|
|
shun-iwasawa |
98926d |
if (m_pressure.getValue() && e.m_pressure == 1.0)
|
|
shun-iwasawa |
98926d |
thickness = m_rasThickness.getValue().first;
|
|
walkerka |
22f456 |
|
|
shun-iwasawa |
98926d |
TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
|
|
Martin van Zijl |
e9b900 |
TRectD invalidateRect(centeredPos - halfThick, centeredPos + halfThick);
|
|
shun-iwasawa |
98926d |
TPointD dpi;
|
|
shun-iwasawa |
98926d |
ri->getDpi(dpi.x, dpi.y);
|
|
shun-iwasawa |
98926d |
TRectD previousTipRect(m_brushPos - halfThick, m_brushPos + halfThick);
|
|
shun-iwasawa |
98926d |
if (dpi.x > Stage::inch || dpi.y > Stage::inch)
|
|
shun-iwasawa |
98926d |
previousTipRect *= dpi.x / Stage::inch;
|
|
shun-iwasawa |
98926d |
invalidateRect += previousTipRect;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
// if the drawOrder mode = "Palette Order",
|
|
shun-iwasawa |
98926d |
// get styleId list which is above the current style in the palette
|
|
shun-iwasawa |
98926d |
DrawOrder drawOrder = (DrawOrder)m_drawOrder.getIndex();
|
|
shun-iwasawa |
98926d |
QSet<int> aboveStyleIds;</int>
|
|
shun-iwasawa |
98926d |
if (drawOrder == PaletteOrder) {
|
|
shun-iwasawa |
98926d |
getAboveStyleIdSet(m_styleId, ri->getPalette(), aboveStyleIds);
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
// mypaint brush case
|
|
shun-iwasawa |
98926d |
if (m_isMyPaintStyleSelected) {
|
|
Martin van Zijl |
e9b900 |
TPointD point(centeredPos + rasCenter);
|
|
shun-iwasawa |
98926d |
double pressure =
|
|
shun-iwasawa |
98926d |
m_pressure.getValue() && e.isTablet() ? e.m_pressure : 0.5;
|
|
shun-iwasawa |
98926d |
updateCurrentStyle();
|
|
shun-iwasawa |
98926d |
if (!(m_workRas && m_backupRas)) setWorkAndBackupImages();
|
|
shun-iwasawa |
98926d |
m_workRas->lock();
|
|
shun-iwasawa |
98926d |
mypaint::Brush mypaintBrush;
|
|
shun-iwasawa |
98926d |
TMyPaintBrushStyle *mypaintStyle =
|
|
shun-iwasawa |
98926d |
dynamic_cast<tmypaintbrushstyle *="">(app->getCurrentLevelStyle());</tmypaintbrushstyle>
|
|
shun-iwasawa |
98926d |
{ // applyToonzBrushSettings
|
|
shun-iwasawa |
98926d |
mypaintBrush.fromBrush(mypaintStyle->getBrush());
|
|
shun-iwasawa |
98926d |
double modifierSize = m_modifierSize.getValue() * log(2.0);
|
|
shun-iwasawa |
98926d |
float baseSize =
|
|
shun-iwasawa |
98926d |
mypaintBrush.getBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC);
|
|
shun-iwasawa |
98926d |
mypaintBrush.setBaseValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC,
|
|
shun-iwasawa |
98926d |
baseSize + modifierSize);
|
|
walkerka |
22f456 |
}
|
|
shun-iwasawa |
98926d |
m_toonz_brush = new MyPaintToonzBrush(m_workRas, *this, mypaintBrush);
|
|
shun-iwasawa |
98926d |
m_strokeRect.empty();
|
|
shun-iwasawa |
98926d |
m_strokeSegmentRect.empty();
|
|
shun-iwasawa |
98926d |
m_toonz_brush->beginStroke();
|
|
shun-iwasawa |
98926d |
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
|
|
shun-iwasawa |
98926d |
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
|
|
shun-iwasawa |
98926d |
if (!updateRect.isEmpty()) {
|
|
shun-iwasawa |
98926d |
// ras->extract(updateRect)->copy(m_workRas->extract(updateRect));
|
|
shun-iwasawa |
98926d |
m_toonz_brush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect,
|
|
shun-iwasawa |
98926d |
m_styleId);
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
m_lastRect = m_strokeRect;
|
|
shun-iwasawa |
97f86c |
|
|
shun-iwasawa |
98926d |
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
|
|
shun-iwasawa |
98926d |
invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
|
|
manongjohn |
603264 |
invalidateRect +=
|
|
manongjohn |
603264 |
TRectD(centeredPos - thickOffset, centeredPos + thickOffset);
|
|
shun-iwasawa |
98926d |
invalidateRect +=
|
|
shun-iwasawa |
98926d |
TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
|
|
shun-iwasawa |
98926d |
} else if (m_hardness.getValue() == 100 || m_pencil.getValue()) {
|
|
shun-iwasawa |
98926d |
/*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる
|
|
shun-iwasawa |
98926d |
* --*/
|
|
shun-iwasawa |
98926d |
if (!m_pencil.getValue()) thickness -= 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
manongjohn |
603264 |
TThickPoint thickPoint(centeredPos + convert(ras->getCenter()),
|
|
manongjohn |
603264 |
thickness);
|
|
shun-iwasawa |
98926d |
m_rasterTrack = new RasterStrokeGenerator(
|
|
shun-iwasawa |
98926d |
ras, BRUSH, NONE, m_styleId, thickPoint, drawOrder != OverAll, 0,
|
|
shun-iwasawa |
98926d |
!m_pencil.getValue(), drawOrder == PaletteOrder);
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
if (drawOrder == PaletteOrder)
|
|
shun-iwasawa |
98926d |
m_rasterTrack->setAboveStyleIds(aboveStyleIds);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
m_tileSaver->save(m_rasterTrack->getLastRect());
|
|
shun-iwasawa |
98926d |
m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
std::vector<tthickpoint> pts;</tthickpoint>
|
|
Jeremy Bullock |
6c7e54 |
if (m_smooth.getValue() == 0) {
|
|
Jeremy Bullock |
6c7e54 |
pts.push_back(thickPoint);
|
|
Jeremy Bullock |
6c7e54 |
} else {
|
|
shun-iwasawa |
98926d |
m_smoothStroke.beginStroke(m_smooth.getValue());
|
|
Jeremy Bullock |
6c7e54 |
m_smoothStroke.addPoint(thickPoint);
|
|
Jeremy Bullock |
6c7e54 |
m_smoothStroke.getSmoothPoints(pts);
|
|
Jeremy Bullock |
6c7e54 |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
shun-iwasawa |
98926d |
m_points.clear();
|
|
Martin van Zijl |
e9b900 |
TThickPoint point(centeredPos + rasCenter, thickness);
|
|
shun-iwasawa |
98926d |
m_points.push_back(point);
|
|
shun-iwasawa |
98926d |
m_bluredBrush = new BluredBrush(m_workRas, maxThick, m_brushPad, false);
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
if (drawOrder == PaletteOrder)
|
|
shun-iwasawa |
98926d |
m_bluredBrush->setAboveStyleIds(aboveStyleIds);
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_strokeRect = m_bluredBrush->getBoundFromPoints(m_points);
|
|
shun-iwasawa |
98926d |
updateWorkAndBackupRasters(m_strokeRect);
|
|
shun-iwasawa |
98926d |
m_tileSaver->save(m_strokeRect);
|
|
shun-iwasawa |
98926d |
m_bluredBrush->addPoint(point, 1);
|
|
shun-iwasawa |
98926d |
m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect,
|
|
shun-iwasawa |
98926d |
m_styleId, drawOrder);
|
|
shun-iwasawa |
98926d |
m_lastRect = m_strokeRect;
|
|
shun-iwasawa |
98926d |
|
|
walkerka |
22f456 |
std::vector<tthickpoint> pts;</tthickpoint>
|
|
Jeremy Bullock |
6c7e54 |
if (m_smooth.getValue() == 0) {
|
|
shun-iwasawa |
98926d |
pts.push_back(point);
|
|
Jeremy Bullock |
6c7e54 |
} else {
|
|
shun-iwasawa |
98926d |
m_smoothStroke.beginStroke(m_smooth.getValue());
|
|
shun-iwasawa |
98926d |
m_smoothStroke.addPoint(point);
|
|
Jeremy Bullock |
6c7e54 |
m_smoothStroke.getSmoothPoints(pts);
|
|
Jeremy Bullock |
6c7e54 |
}
|
|
shun-iwasawa |
97f86c |
}
|
|
shun-iwasawa |
98926d |
/*-- 作業中のFidを登録 --*/
|
|
shun-iwasawa |
98926d |
m_workingFrameId = getFrameId();
|
|
shun-iwasawa |
cd7d6a |
|
|
walkerka |
22f456 |
invalidate(invalidateRect.enlarge(2));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
98926d |
// updating m_brushPos is needed to refresh viewer properly
|
|
Martin van Zijl |
e9b900 |
m_mousePos = pos;
|
|
Martin van Zijl |
e9b900 |
m_brushPos = getCenteredCursorPos(pos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
//-------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,
|
|
shun-iwasawa |
98926d |
const TMouseEvent &e) {
|
|
shun-iwasawa |
98926d |
if (!m_enabled || !m_active) {
|
|
Martin van Zijl |
e9b900 |
m_mousePos = pos;
|
|
Martin van Zijl |
e9b900 |
m_brushPos = getCenteredCursorPos(pos);
|
|
shun-iwasawa |
cd7d6a |
return;
|
|
shun-iwasawa |
cd7d6a |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Martin van Zijl |
e9b900 |
TPointD centeredPos = getCenteredCursorPos(pos);
|
|
Martin van Zijl |
8b0f8d |
|
|
shun-iwasawa |
98926d |
TToonzImageP ti = TImageP(getImage(true));
|
|
shun-iwasawa |
98926d |
TPointD rasCenter = ti->getRaster()->getCenterD();
|
|
shun-iwasawa |
98926d |
int maxThickness = m_rasThickness.getValue().second;
|
|
shun-iwasawa |
98926d |
double thickness = (m_pressure.getValue())
|
|
shun-iwasawa |
98926d |
? computeThickness(e.m_pressure, m_rasThickness) * 2
|
|
shun-iwasawa |
98926d |
: maxThickness;
|
|
shun-iwasawa |
98926d |
TRectD invalidateRect;
|
|
shun-iwasawa |
98926d |
if (m_isMyPaintStyleSelected) {
|
|
shun-iwasawa |
98926d |
TRasterP ras = ti->getRaster();
|
|
Martin van Zijl |
e9b900 |
TPointD point(centeredPos + rasCenter);
|
|
shun-iwasawa |
98926d |
double pressure =
|
|
shun-iwasawa |
98926d |
m_pressure.getValue() && e.isTablet() ? e.m_pressure : 0.5;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_strokeSegmentRect.empty();
|
|
shun-iwasawa |
98926d |
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
|
|
shun-iwasawa |
98926d |
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
|
|
shun-iwasawa |
98926d |
if (!updateRect.isEmpty()) {
|
|
shun-iwasawa |
98926d |
// ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
|
|
shun-iwasawa |
98926d |
m_toonz_brush->updateDrawing(ras, m_backupRas, m_strokeSegmentRect,
|
|
shun-iwasawa |
98926d |
m_styleId);
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
m_lastRect = m_strokeRect;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
|
|
shun-iwasawa |
98926d |
invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
|
|
manongjohn |
603264 |
invalidateRect +=
|
|
manongjohn |
603264 |
TRectD(centeredPos - thickOffset, centeredPos + thickOffset);
|
|
shun-iwasawa |
98926d |
invalidateRect +=
|
|
shun-iwasawa |
98926d |
TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
|
|
shun-iwasawa |
98926d |
} else if (m_rasterTrack &&
|
|
shun-iwasawa |
98926d |
(m_hardness.getValue() == 100 || m_pencil.getValue())) {
|
|
shun-iwasawa |
98926d |
/*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる
|
|
shun-iwasawa |
98926d |
* --*/
|
|
shun-iwasawa |
98926d |
if (!m_pencil.getValue()) thickness -= 1.0;
|
|
Jeremy Bullock |
7f2044 |
|
|
Martin van Zijl |
e9b900 |
TThickPoint thickPoint(centeredPos + rasCenter, thickness);
|
|
shun-iwasawa |
98926d |
std::vector<tthickpoint> pts;</tthickpoint>
|
|
shun-iwasawa |
98926d |
if (m_smooth.getValue() == 0) {
|
|
shun-iwasawa |
98926d |
pts.push_back(thickPoint);
|
|
Jeremy Bullock |
7f2044 |
} else {
|
|
shun-iwasawa |
98926d |
m_smoothStroke.addPoint(thickPoint);
|
|
shun-iwasawa |
98926d |
m_smoothStroke.getSmoothPoints(pts);
|
|
Jeremy Bullock |
7f2044 |
}
|
|
shun-iwasawa |
98926d |
for (size_t i = 0; i < pts.size(); ++i) {
|
|
shun-iwasawa |
98926d |
const TThickPoint &thickPoint = pts[i];
|
|
shun-iwasawa |
98926d |
m_rasterTrack->add(thickPoint);
|
|
shun-iwasawa |
98926d |
m_tileSaver->save(m_rasterTrack->getLastRect());
|
|
shun-iwasawa |
98926d |
m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());
|
|
shun-iwasawa |
98926d |
std::vector<tthickpoint> brushPoints = m_rasterTrack->getPointsSequence();</tthickpoint>
|
|
shun-iwasawa |
98926d |
int m = (int)brushPoints.size();
|
|
shun-iwasawa |
98926d |
std::vector<tthickpoint> points;</tthickpoint>
|
|
shun-iwasawa |
98926d |
if (m == 3) {
|
|
shun-iwasawa |
98926d |
points.push_back(brushPoints[0]);
|
|
shun-iwasawa |
98926d |
points.push_back(brushPoints[1]);
|
|
shun-iwasawa |
98926d |
} else {
|
|
shun-iwasawa |
98926d |
points.push_back(brushPoints[m - 4]);
|
|
shun-iwasawa |
98926d |
points.push_back(brushPoints[m - 3]);
|
|
shun-iwasawa |
98926d |
points.push_back(brushPoints[m - 2]);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
98926d |
invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;
|
|
Jeremy Bullock |
cd00fd |
}
|
|
shun-iwasawa |
98926d |
} else {
|
|
shun-iwasawa |
98926d |
// antialiased brush
|
|
shun-iwasawa |
98926d |
assert(m_workRas.getPointer() && m_backupRas.getPointer());
|
|
Martin van Zijl |
e9b900 |
TThickPoint thickPoint(centeredPos + rasCenter, thickness);
|
|
shun-iwasawa |
98926d |
std::vector<tthickpoint> pts;</tthickpoint>
|
|
shun-iwasawa |
98926d |
if (m_smooth.getValue() == 0) {
|
|
shun-iwasawa |
98926d |
pts.push_back(thickPoint);
|
|
Jeremy Bullock |
7f2044 |
} else {
|
|
shun-iwasawa |
98926d |
m_smoothStroke.addPoint(thickPoint);
|
|
shun-iwasawa |
98926d |
m_smoothStroke.getSmoothPoints(pts);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
98926d |
for (size_t i = 0; i < pts.size(); ++i) {
|
|
shun-iwasawa |
98926d |
TThickPoint old = m_points.back();
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
const TThickPoint &point = pts[i];
|
|
shun-iwasawa |
98926d |
TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
|
|
shun-iwasawa |
98926d |
m_points.push_back(mid);
|
|
shun-iwasawa |
98926d |
m_points.push_back(point);
|
|
Jeremy Bullock |
cd00fd |
|
|
shun-iwasawa |
98926d |
TRect bbox;
|
|
shun-iwasawa |
98926d |
int m = (int)m_points.size();
|
|
shun-iwasawa |
98926d |
std::vector<tthickpoint> points;</tthickpoint>
|
|
shun-iwasawa |
98926d |
if (m == 3) {
|
|
shun-iwasawa |
98926d |
// ho appena cominciato. devo disegnare un segmento
|
|
shun-iwasawa |
98926d |
TThickPoint pa = m_points.front();
|
|
shun-iwasawa |
98926d |
points.push_back(pa);
|
|
shun-iwasawa |
98926d |
points.push_back(mid);
|
|
shun-iwasawa |
98926d |
bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
shun-iwasawa |
98926d |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
shun-iwasawa |
98926d |
m_tileSaver->save(bbox);
|
|
shun-iwasawa |
98926d |
m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);
|
|
shun-iwasawa |
98926d |
m_lastRect += bbox;
|
|
shun-iwasawa |
98926d |
} else {
|
|
shun-iwasawa |
98926d |
points.push_back(m_points[m - 4]);
|
|
shun-iwasawa |
98926d |
points.push_back(old);
|
|
shun-iwasawa |
98926d |
points.push_back(mid);
|
|
shun-iwasawa |
98926d |
bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
shun-iwasawa |
98926d |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
shun-iwasawa |
98926d |
m_tileSaver->save(bbox);
|
|
shun-iwasawa |
98926d |
m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1);
|
|
shun-iwasawa |
98926d |
m_lastRect += bbox;
|
|
Jeremy Bullock |
75c9c5 |
}
|
|
shun-iwasawa |
98926d |
invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;
|
|
Jeremy Bullock |
cd00fd |
|
|
shun-iwasawa |
98926d |
m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox,
|
|
shun-iwasawa |
98926d |
m_styleId, m_drawOrder.getIndex());
|
|
shun-iwasawa |
98926d |
m_strokeRect += bbox;
|
|
Jeremy Bullock |
cd00fd |
}
|
|
shun-iwasawa |
98926d |
}
|
|
Jeremy Bullock |
cd00fd |
|
|
shun-iwasawa |
98926d |
// clear & draw brush tip when drawing smooth stroke
|
|
shun-iwasawa |
98926d |
if (m_smooth.getValue() != 0) {
|
|
shun-iwasawa |
98926d |
TPointD halfThick(m_maxThick * 0.5, m_maxThick * 0.5);
|
|
shun-iwasawa |
98926d |
invalidateRect += TRectD(m_brushPos - halfThick, m_brushPos + halfThick);
|
|
Martin van Zijl |
e9b900 |
invalidateRect += TRectD(centeredPos - halfThick, centeredPos + halfThick);
|
|
Jeremy Bullock |
cd00fd |
}
|
|
Jeremy Bullock |
cd00fd |
|
|
Martin van Zijl |
e9b900 |
m_mousePos = pos;
|
|
Martin van Zijl |
e9b900 |
m_brushPos = getCenteredCursorPos(pos);
|
|
Jeremy Bullock |
cd00fd |
|
|
shun-iwasawa |
98926d |
invalidate(invalidateRect.enlarge(2));
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
shun-iwasawa |
98926d |
//---------------------------------------------------------------------------------------------------------------
|
|
walkerka |
57fb3c |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::leftButtonUp(const TPointD &pos,
|
|
shun-iwasawa |
98926d |
const TMouseEvent &e) {
|
|
shun-iwasawa |
98926d |
bool isValid = m_enabled && m_active;
|
|
shun-iwasawa |
98926d |
m_enabled = false;
|
|
manongjohn |
482ab4 |
m_active = false;
|
|
shun-iwasawa |
98926d |
if (!isValid) {
|
|
shun-iwasawa |
98926d |
return;
|
|
walkerka |
22f456 |
}
|
|
Martin van Zijl |
e9b900 |
TPointD centeredPos = getCenteredCursorPos(pos);
|
|
shun-iwasawa |
0568f4 |
double pressure = m_pressure.getValue() && e.isTablet() ? e.m_pressure : 0.5;
|
|
Martin van Zijl |
e9b900 |
finishRasterBrush(centeredPos, pressure);
|
|
walkerka |
57fb3c |
}
|
|
walkerka |
57fb3c |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
* ドラッグ中にツールが切り替わった場合に備え、onDeactivate時とMouseRelease時にと同じ終了処理を行う
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos,
|
|
shun-iwasawa |
98926d |
double pressureVal) {
|
|
shun-iwasawa |
98926d |
TToonzImageP ti = TImageP(getImage(true));
|
|
Shinya Kitaoka |
120a6e |
|
|
manongjohn |
482ab4 |
if (!ti) return;
|
|
manongjohn |
482ab4 |
|
|
Shinya Kitaoka |
120a6e |
TPointD rasCenter = ti->getRaster()->getCenterD();
|
|
Shinya Kitaoka |
120a6e |
TTool::Application *app = TTool::getApplication();
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *level = app->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
TXshSimpleLevelP simLevel = level->getSimpleLevel();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*--
|
|
Shinya Kitaoka |
120a6e |
* 描画中にカレントフレームが変わっても、描画開始時のFidに対してUndoを記録する
|
|
Shinya Kitaoka |
120a6e |
* --*/
|
|
Shinya Kitaoka |
120a6e |
TFrameId frameId =
|
|
Shinya Kitaoka |
120a6e |
m_workingFrameId.isEmptyFrame() ? getCurrentFid() : m_workingFrameId;
|
|
shun-iwasawa |
98926d |
if (m_isMyPaintStyleSelected) {
|
|
shun-iwasawa |
98926d |
TRasterCM32P ras = ti->getRaster();
|
|
shun-iwasawa |
98926d |
TPointD point(pos + rasCenter);
|
|
shun-iwasawa |
98926d |
double pressure = m_pressure.getValue() ? pressureVal : 0.5;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_strokeSegmentRect.empty();
|
|
shun-iwasawa |
98926d |
m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
|
|
shun-iwasawa |
98926d |
m_toonz_brush->endStroke();
|
|
shun-iwasawa |
98926d |
TRect updateRect = m_strokeSegmentRect * ras->getBounds();
|
|
shun-iwasawa |
98926d |
if (!updateRect.isEmpty()) {
|
|
shun-iwasawa |
98926d |
// ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
|
|
shun-iwasawa |
98926d |
m_toonz_brush->updateDrawing(ras, m_backupRas, m_strokeSegmentRect,
|
|
shun-iwasawa |
98926d |
m_styleId);
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
TPointD thickOffset(m_maxCursorThick * 0.5,
|
|
shun-iwasawa |
98926d |
m_maxCursorThick * 0.5); // TODO
|
|
shun-iwasawa |
98926d |
TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
|
|
shun-iwasawa |
98926d |
invalidateRect += TRectD(pos - thickOffset, pos + thickOffset);
|
|
shun-iwasawa |
98926d |
invalidate(invalidateRect.enlarge(2.0));
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
if (m_toonz_brush) {
|
|
shun-iwasawa |
98926d |
delete m_toonz_brush;
|
|
shun-iwasawa |
98926d |
m_toonz_brush = 0;
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_lastRect.empty();
|
|
shun-iwasawa |
98926d |
m_workRas->unlock();
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
if (m_tileSet->getTileCount() > 0) {
|
|
shun-iwasawa |
98926d |
TRasterCM32P subras = ras->extract(m_strokeRect)->clone();
|
|
shun-iwasawa |
98926d |
TUndoManager::manager()->add(new MyPaintBrushUndo(
|
|
shun-iwasawa |
98926d |
m_tileSet, simLevel.getPointer(), frameId, m_isFrameCreated,
|
|
shun-iwasawa |
98926d |
m_isLevelCreated, subras, m_strokeRect.getP00()));
|
|
shun-iwasawa |
98926d |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
} else if (m_rasterTrack &&
|
|
shun-iwasawa |
98926d |
(m_hardness.getValue() == 100 || m_pencil.getValue())) {
|
|
shun-iwasawa |
98926d |
double thickness = m_pressure.getValue()
|
|
shun-iwasawa |
98926d |
? computeThickness(pressureVal, m_rasThickness)
|
|
shun-iwasawa |
98926d |
: m_rasThickness.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/
|
|
shun-iwasawa |
600da6 |
if (m_pressure.getValue() && pressureVal == 1.0)
|
|
Shinya Kitaoka |
120a6e |
thickness = m_rasThickness.getValue().first;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/
|
|
Shinya Kitaoka |
120a6e |
if (!m_pencil.getValue()) thickness -= 1.0;
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
TRectD invalidateRect;
|
|
walkerka |
22f456 |
TThickPoint thickPoint(pos + rasCenter, thickness);
|
|
walkerka |
22f456 |
std::vector<tthickpoint> pts;</tthickpoint>
|
|
Jeremy Bullock |
6c7e54 |
if (m_smooth.getValue() == 0) {
|
|
Jeremy Bullock |
6c7e54 |
pts.push_back(thickPoint);
|
|
Jeremy Bullock |
6c7e54 |
} else {
|
|
Jeremy Bullock |
6c7e54 |
m_smoothStroke.addPoint(thickPoint);
|
|
Jeremy Bullock |
6c7e54 |
m_smoothStroke.endStroke();
|
|
Jeremy Bullock |
6c7e54 |
m_smoothStroke.getSmoothPoints(pts);
|
|
Jeremy Bullock |
6c7e54 |
}
|
|
walkerka |
22f456 |
for (size_t i = 0; i < pts.size(); ++i) {
|
|
walkerka |
22f456 |
const TThickPoint &thickPoint = pts[i];
|
|
shun-iwasawa |
cd7d6a |
m_rasterTrack->add(thickPoint);
|
|
shun-iwasawa |
cd7d6a |
m_tileSaver->save(m_rasterTrack->getLastRect());
|
|
shun-iwasawa |
cd7d6a |
m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue(), true);
|
|
shun-iwasawa |
cd7d6a |
|
|
shun-iwasawa |
cd7d6a |
std::vector<tthickpoint> brushPoints = m_rasterTrack->getPointsSequence();</tthickpoint>
|
|
shun-iwasawa |
cd7d6a |
int m = (int)brushPoints.size();
|
|
shun-iwasawa |
cd7d6a |
std::vector<tthickpoint> points;</tthickpoint>
|
|
shun-iwasawa |
cd7d6a |
if (m == 3) {
|
|
shun-iwasawa |
cd7d6a |
points.push_back(brushPoints[0]);
|
|
shun-iwasawa |
cd7d6a |
points.push_back(brushPoints[1]);
|
|
shun-iwasawa |
cd7d6a |
} else {
|
|
shun-iwasawa |
cd7d6a |
points.push_back(brushPoints[m - 4]);
|
|
shun-iwasawa |
cd7d6a |
points.push_back(brushPoints[m - 3]);
|
|
shun-iwasawa |
cd7d6a |
points.push_back(brushPoints[m - 2]);
|
|
walkerka |
22f456 |
}
|
|
shun-iwasawa |
cd7d6a |
int maxThickness = m_rasThickness.getValue().second;
|
|
shun-iwasawa |
cd7d6a |
invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
invalidate(invalidateRect.enlarge(2));
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
if (m_tileSet->getTileCount() > 0) {
|
|
walkerka |
22f456 |
TUndoManager::manager()->add(new RasterBrushUndo(
|
|
walkerka |
22f456 |
m_tileSet, m_rasterTrack->getPointsSequence(),
|
|
walkerka |
22f456 |
m_rasterTrack->getStyleId(), m_rasterTrack->isSelective(),
|
|
walkerka |
22f456 |
simLevel.getPointer(), frameId, m_pencil.getValue(), m_isFrameCreated,
|
|
shun-iwasawa |
975eb1 |
m_isLevelCreated, m_rasterTrack->isPaletteOrder()));
|
|
walkerka |
22f456 |
}
|
|
walkerka |
22f456 |
delete m_rasterTrack;
|
|
walkerka |
22f456 |
m_rasterTrack = 0;
|
|
walkerka |
22f456 |
} else {
|
|
shun-iwasawa |
cd7d6a |
double maxThickness = m_rasThickness.getValue().second;
|
|
shun-iwasawa |
98926d |
double thickness = (m_pressure.getValue())
|
|
shun-iwasawa |
98926d |
? computeThickness(pressureVal, m_rasThickness)
|
|
shun-iwasawa |
98926d |
: maxThickness;
|
|
shun-iwasawa |
cd7d6a |
TPointD rasCenter = ti->getRaster()->getCenterD();
|
|
shun-iwasawa |
cd7d6a |
TRectD invalidateRect;
|
|
shun-iwasawa |
cd7d6a |
TThickPoint thickPoint(pos + rasCenter, thickness);
|
|
shun-iwasawa |
cd7d6a |
std::vector<tthickpoint> pts;</tthickpoint>
|
|
shun-iwasawa |
cd7d6a |
if (m_smooth.getValue() == 0) {
|
|
shun-iwasawa |
cd7d6a |
pts.push_back(thickPoint);
|
|
shun-iwasawa |
cd7d6a |
} else {
|
|
shun-iwasawa |
cd7d6a |
m_smoothStroke.addPoint(thickPoint);
|
|
shun-iwasawa |
cd7d6a |
m_smoothStroke.endStroke();
|
|
shun-iwasawa |
cd7d6a |
m_smoothStroke.getSmoothPoints(pts);
|
|
shun-iwasawa |
cd7d6a |
}
|
|
shun-iwasawa |
cd7d6a |
// we need to skip the for-loop here if pts.size() == 0 or else
|
|
shun-iwasawa |
cd7d6a |
// (pts.size() - 1) becomes ULLONG_MAX since size_t is unsigned
|
|
shun-iwasawa |
cd7d6a |
if (pts.size() > 0) {
|
|
walkerka |
22f456 |
for (size_t i = 0; i < pts.size() - 1; ++i) {
|
|
walkerka |
22f456 |
TThickPoint old = m_points.back();
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
const TThickPoint &point = pts[i];
|
|
walkerka |
22f456 |
TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
|
|
walkerka |
22f456 |
m_points.push_back(mid);
|
|
walkerka |
22f456 |
m_points.push_back(point);
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
TRect bbox;
|
|
walkerka |
22f456 |
int m = (int)m_points.size();
|
|
walkerka |
22f456 |
std::vector<tthickpoint> points;</tthickpoint>
|
|
walkerka |
22f456 |
if (m == 3) {
|
|
walkerka |
22f456 |
// ho appena cominciato. devo disegnare un segmento
|
|
walkerka |
22f456 |
TThickPoint pa = m_points.front();
|
|
walkerka |
22f456 |
points.push_back(pa);
|
|
walkerka |
22f456 |
points.push_back(mid);
|
|
walkerka |
22f456 |
bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
walkerka |
22f456 |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
walkerka |
22f456 |
m_tileSaver->save(bbox);
|
|
walkerka |
22f456 |
m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);
|
|
walkerka |
22f456 |
m_lastRect += bbox;
|
|
walkerka |
22f456 |
} else {
|
|
walkerka |
22f456 |
points.push_back(m_points[m - 4]);
|
|
walkerka |
22f456 |
points.push_back(old);
|
|
walkerka |
22f456 |
points.push_back(mid);
|
|
walkerka |
22f456 |
bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
walkerka |
22f456 |
updateWorkAndBackupRasters(bbox + m_lastRect);
|
|
walkerka |
22f456 |
m_tileSaver->save(bbox);
|
|
walkerka |
22f456 |
m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1);
|
|
walkerka |
22f456 |
m_lastRect += bbox;
|
|
walkerka |
22f456 |
}
|
|
shun-iwasawa |
cd7d6a |
|
|
shun-iwasawa |
cd7d6a |
invalidateRect +=
|
|
shun-iwasawa |
cd7d6a |
ToolUtils::getBounds(points, maxThickness) - rasCenter;
|
|
walkerka |
22f456 |
|
|
walkerka |
22f456 |
m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox,
|
|
shun-iwasawa |
975eb1 |
m_styleId, m_drawOrder.getIndex());
|
|
walkerka |
22f456 |
m_strokeRect += bbox;
|
|
walkerka |
22f456 |
}
|
|
shun-iwasawa |
cd7d6a |
TThickPoint point = pts.back();
|
|
shun-iwasawa |
cd7d6a |
m_points.push_back(point);
|
|
shun-iwasawa |
cd7d6a |
int m = m_points.size();
|
|
shun-iwasawa |
cd7d6a |
std::vector<tthickpoint> points;</tthickpoint>
|
|
shun-iwasawa |
cd7d6a |
points.push_back(m_points[m - 3]);
|
|
shun-iwasawa |
cd7d6a |
points.push_back(m_points[m - 2]);
|
|
shun-iwasawa |
cd7d6a |
points.push_back(m_points[m - 1]);
|
|
shun-iwasawa |
cd7d6a |
TRect bbox = m_bluredBrush->getBoundFromPoints(points);
|
|
shun-iwasawa |
cd7d6a |
updateWorkAndBackupRasters(bbox);
|
|
shun-iwasawa |
cd7d6a |
m_tileSaver->save(bbox);
|
|
shun-iwasawa |
cd7d6a |
m_bluredBrush->addArc(points[0], points[1], points[2], 1, 1);
|
|
shun-iwasawa |
cd7d6a |
m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox,
|
|
shun-iwasawa |
cd7d6a |
m_styleId, m_drawOrder.getIndex());
|
|
shun-iwasawa |
cd7d6a |
|
|
shun-iwasawa |
cd7d6a |
invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;
|
|
shun-iwasawa |
cd7d6a |
|
|
shun-iwasawa |
cd7d6a |
m_lastRect += bbox;
|
|
shun-iwasawa |
cd7d6a |
m_strokeRect += bbox;
|
|
walkerka |
22f456 |
}
|
|
shun-iwasawa |
cd7d6a |
if (!invalidateRect.isEmpty()) invalidate(invalidateRect.enlarge(2));
|
|
shun-iwasawa |
cd7d6a |
m_lastRect.empty();
|
|
shun-iwasawa |
cd7d6a |
|
|
walkerka |
22f456 |
delete m_bluredBrush;
|
|
walkerka |
22f456 |
m_bluredBrush = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_tileSet->getTileCount() > 0) {
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(new RasterBluredBrushUndo(
|
|
shun-iwasawa |
975eb1 |
m_tileSet, m_points, m_styleId, (DrawOrder)m_drawOrder.getIndex(),
|
|
Shinya Kitaoka |
120a6e |
simLevel.getPointer(), frameId, m_rasThickness.getValue().second,
|
|
Shinya Kitaoka |
120a6e |
m_hardness.getValue() * 0.01, m_isFrameCreated, m_isLevelCreated));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
delete m_tileSaver;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_tileSaver = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*-- FIdを指定して、描画中にフレームが動いても、
|
|
Shinya Kitaoka |
120a6e |
描画開始時のFidのサムネイルが更新されるようにする。--*/
|
|
Shinya Kitaoka |
120a6e |
notifyImageChanged(frameId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_strokeRect.empty();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
ToolUtils::updateSaveBox();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*-- 作業中のフレームをリセット --*/
|
|
Shinya Kitaoka |
120a6e |
m_workingFrameId = TFrameId();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------------------
|
|
shun-iwasawa |
98926d |
// 明日はここをMyPaintのときにカーソルを消せるように修正する!!!!!!
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
struct Locals {
|
|
shun-iwasawa |
98926d |
ToonzRasterBrushTool *m_this;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setValue(TDoublePairProperty &prop,
|
|
Shinya Kitaoka |
120a6e |
const TDoublePairProperty::Value &value) {
|
|
Shinya Kitaoka |
120a6e |
prop.setValue(value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_this->onPropertyChanged(prop.getName());
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void addMinMax(TDoublePairProperty &prop, double add) {
|
|
Shinya Kitaoka |
120a6e |
if (add == 0.0) return;
|
|
Shinya Kitaoka |
120a6e |
const TDoublePairProperty::Range &range = prop.getRange();
|
|
Shinya Kitaoka |
d4642c |
|
|
Shinya Kitaoka |
120a6e |
TDoublePairProperty::Value value = prop.getValue();
|
|
Shinya Kitaoka |
120a6e |
value.first = tcrop(value.first + add, range.first, range.second);
|
|
Shinya Kitaoka |
120a6e |
value.second = tcrop(value.second + add, range.first, range.second);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setValue(prop, value);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jeremy Bullock |
01e454 |
void addMinMaxSeparate(TDoublePairProperty &prop, double min, double max) {
|
|
Jeremy Bullock |
01e454 |
if (min == 0.0 && max == 0.0) return;
|
|
Jeremy Bullock |
01e454 |
const TDoublePairProperty::Range &range = prop.getRange();
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
01e454 |
TDoublePairProperty::Value value = prop.getValue();
|
|
Jeremy Bullock |
01e454 |
value.first += min;
|
|
Jeremy Bullock |
01e454 |
value.second += max;
|
|
Jeremy Bullock |
01e454 |
if (value.first > value.second) value.first = value.second;
|
|
Jeremy Bullock |
01e454 |
value.first = tcrop(value.first, range.first, range.second);
|
|
Jeremy Bullock |
01e454 |
value.second = tcrop(value.second, range.first, range.second);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
01e454 |
setValue(prop, value);
|
|
Jeremy Bullock |
01e454 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
01e454 |
} locals = {this};
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
01e454 |
// if (e.isAltPressed() && !e.isCtrlPressed()) {
|
|
Jeremy Bullock |
01e454 |
// const TPointD &diff = pos - m_mousePos;
|
|
Jeremy Bullock |
01e454 |
// double add = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
|
|
Jeremy Bullock |
01e454 |
|
|
Jeremy Bullock |
01e454 |
// locals.addMinMax(
|
|
Jeremy Bullock |
01e454 |
// TToonzImageP(getImage(false, 1)) ? m_rasThickness : m_thickness, add);
|
|
Jeremy Bullock |
01e454 |
//} else
|
|
shun-iwasawa |
97f86c |
|
|
shun-iwasawa |
98926d |
double thickness =
|
|
shun-iwasawa |
98926d |
(m_isMyPaintStyleSelected) ? (double)(m_maxCursorThick + 1) : m_maxThick;
|
|
shun-iwasawa |
98926d |
TPointD halfThick(thickness * 0.5, thickness * 0.5);
|
|
shun-iwasawa |
97f86c |
TRectD invalidateRect(m_brushPos - halfThick, m_brushPos + halfThick);
|
|
shun-iwasawa |
97f86c |
|
|
Jeremy Bullock |
0b92f5 |
if (e.isCtrlPressed() && e.isAltPressed() && !e.isShiftPressed()) {
|
|
Jeremy Bullock |
01e454 |
const TPointD &diff = pos - m_mousePos;
|
|
Jeremy Bullock |
01e454 |
double max = diff.x / 2;
|
|
Jeremy Bullock |
01e454 |
double min = diff.y / 2;
|
|
Jeremy Bullock |
01e454 |
|
|
shun-iwasawa |
98926d |
locals.addMinMaxSeparate(m_rasThickness, min, max);
|
|
shun-iwasawa |
97f86c |
|
|
shun-iwasawa |
98926d |
double radius = m_rasThickness.getValue().second * 0.5;
|
|
shun-iwasawa |
97f86c |
invalidateRect += TRectD(m_brushPos - TPointD(radius, radius),
|
|
shun-iwasawa |
97f86c |
m_brushPos + TPointD(radius, radius));
|
|
shun-iwasawa |
97f86c |
|
|
Jeremy Bullock |
01e454 |
} else {
|
|
shun-iwasawa |
d6e799 |
m_mousePos = pos;
|
|
Martin van Zijl |
e9b900 |
m_brushPos = getCenteredCursorPos(pos);
|
|
Jeremy Bullock |
cd00fd |
|
|
shun-iwasawa |
97f86c |
invalidateRect += TRectD(pos - halfThick, pos + halfThick);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
97f86c |
|
|
shun-iwasawa |
97f86c |
invalidate(invalidateRect.enlarge(2));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_minThick == 0 && m_maxThick == 0) {
|
|
shun-iwasawa |
98926d |
m_minThick = m_rasThickness.getValue().first;
|
|
shun-iwasawa |
98926d |
m_maxThick = m_rasThickness.getValue().second;
|
|
Jeremy Bullock |
cd00fd |
}
|
|
Jeremy Bullock |
cd00fd |
}
|
|
Jeremy Bullock |
cd00fd |
|
|
Jeremy Bullock |
cd00fd |
//-------------------------------------------------------------------------------------------------------------
|
|
Jeremy Bullock |
cd00fd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::draw() {
|
|
Shinya Kitaoka |
120a6e |
/*--ショートカットでのツール切り替え時に赤点が描かれるのを防止する--*/
|
|
Jeremy Bullock |
7f2044 |
if (m_minThick == 0 && m_maxThick == 0 &&
|
|
Jeremy Bullock |
7f2044 |
!Preferences::instance()->getShow0ThickLines())
|
|
Jeremy Bullock |
7f2044 |
return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TImageP img = getImage(false, 1);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (getApplication()->getCurrentObject()->isSpline()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
manongjohn |
75da26 |
// If toggled off, don't draw brush outline
|
|
manongjohn |
75da26 |
if (!Preferences::instance()->isCursorOutlineEnabled()) return;
|
|
manongjohn |
75da26 |
|
|
Shinya Kitaoka |
120a6e |
// Draw the brush outline - change color when the Ink / Paint check is
|
|
Shinya Kitaoka |
120a6e |
// activated
|
|
Shinya Kitaoka |
120a6e |
if ((ToonzCheck::instance()->getChecks() & ToonzCheck::eInk) ||
|
|
Shinya Kitaoka |
120a6e |
(ToonzCheck::instance()->getChecks() & ToonzCheck::ePaint) ||
|
|
Shinya Kitaoka |
120a6e |
(ToonzCheck::instance()->getChecks() & ToonzCheck::eInk1))
|
|
Shinya Kitaoka |
120a6e |
glColor3d(0.5, 0.8, 0.8);
|
|
Shinya Kitaoka |
120a6e |
// normally draw in red
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
glColor3d(1.0, 0.0, 0.0);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
if (m_isMyPaintStyleSelected) {
|
|
shun-iwasawa |
98926d |
tglDrawCircle(m_brushPos, (m_minCursorThick + 1) * 0.5);
|
|
shun-iwasawa |
98926d |
tglDrawCircle(m_brushPos, (m_maxCursorThick + 1) * 0.5);
|
|
shun-iwasawa |
98926d |
return;
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
Shinya Kitaoka |
120a6e |
if (TToonzImageP ti = img) {
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = ti->getRaster();
|
|
Shinya Kitaoka |
120a6e |
int lx = ras->getLx();
|
|
Shinya Kitaoka |
120a6e |
int ly = ras->getLy();
|
|
Shinya Kitaoka |
120a6e |
drawEmptyCircle(m_brushPos, tround(m_minThick), lx % 2 == 0, ly % 2 == 0,
|
|
Shinya Kitaoka |
120a6e |
m_pencil.getValue());
|
|
Shinya Kitaoka |
120a6e |
drawEmptyCircle(m_brushPos, tround(m_maxThick), lx % 2 == 0, ly % 2 == 0,
|
|
Shinya Kitaoka |
120a6e |
m_pencil.getValue());
|
|
shun-iwasawa |
98926d |
} else {
|
|
shun-iwasawa |
97f86c |
drawEmptyCircle(m_brushPos, tround(m_minThick), true, true,
|
|
shun-iwasawa |
97f86c |
m_pencil.getValue());
|
|
shun-iwasawa |
97f86c |
drawEmptyCircle(m_brushPos, tround(m_maxThick), true, true,
|
|
shun-iwasawa |
97f86c |
m_pencil.getValue());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::onEnter() {
|
|
Shinya Kitaoka |
120a6e |
TImageP img = getImage(false);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
m_minThick = m_rasThickness.getValue().first;
|
|
shun-iwasawa |
98926d |
m_maxThick = m_rasThickness.getValue().second;
|
|
shun-iwasawa |
98926d |
updateCurrentStyle();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Application *app = getApplication();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_styleId = app->getCurrentLevelStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = app->getCurrentLevelStyle();
|
|
Shinya Kitaoka |
120a6e |
if (cs) {
|
|
Shinya Kitaoka |
120a6e |
TRasterStyleFx *rfx = cs->getRasterStyleFx();
|
|
Shinya Kitaoka |
120a6e |
m_active = cs->isStrokeStyle() || (rfx && rfx->isInkStyle());
|
|
Shinya Kitaoka |
120a6e |
m_currentColor = cs->getAverageColor();
|
|
Shinya Kitaoka |
120a6e |
m_currentColor.m = 255;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_currentColor = TPixel32::Black;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_active = img;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::onLeave() {
|
|
shun-iwasawa |
98926d |
m_minThick = 0;
|
|
shun-iwasawa |
98926d |
m_maxThick = 0;
|
|
shun-iwasawa |
98926d |
m_minCursorThick = 0;
|
|
shun-iwasawa |
98926d |
m_maxCursorThick = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
TPropertyGroup *ToonzRasterBrushTool::getProperties(int idx) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_presetsLoaded) initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return &m_prop[idx];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::onImageChanged() {
|
|
shun-iwasawa |
98926d |
if (!isEnabled()) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setWorkAndBackupImages();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::setWorkAndBackupImages() {
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP ti = (TToonzImageP)getImage(false, 1);
|
|
Shinya Kitaoka |
120a6e |
if (!ti) return;
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = ti->getRaster();
|
|
Shinya Kitaoka |
120a6e |
TDimension dim = ras->getSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double hardness = m_hardness.getValue() * 0.01;
|
|
shun-iwasawa |
98926d |
if (!m_isMyPaintStyleSelected && hardness == 1.0 &&
|
|
shun-iwasawa |
98926d |
ras->getPixelSize() == 4) {
|
|
Shinya Kitaoka |
120a6e |
m_workRas = TRaster32P();
|
|
Shinya Kitaoka |
120a6e |
m_backupRas = TRasterCM32P();
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (!m_workRas || m_workRas->getLx() > dim.lx ||
|
|
Shinya Kitaoka |
120a6e |
m_workRas->getLy() > dim.ly)
|
|
Shinya Kitaoka |
120a6e |
m_workRas = TRaster32P(dim);
|
|
Shinya Kitaoka |
120a6e |
if (!m_backupRas || m_backupRas->getLx() > dim.lx ||
|
|
Shinya Kitaoka |
120a6e |
m_backupRas->getLy() > dim.ly)
|
|
Shinya Kitaoka |
120a6e |
m_backupRas = TRasterCM32P(dim);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_strokeRect.empty();
|
|
Shinya Kitaoka |
120a6e |
m_lastRect.empty();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
bool ToonzRasterBrushTool::onPropertyChanged(std::string propertyName) {
|
|
Shinya Kitaoka |
120a6e |
// Set the following to true whenever a different piece of interface must
|
|
Shinya Kitaoka |
120a6e |
// be refreshed - done once at the end.
|
|
Shinya Kitaoka |
120a6e |
bool notifyTool = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*--- 変更されたPropertyに合わせて処理を分ける ---*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
97f86c |
/*--- determine which type of brush to be modified ---*/
|
|
shun-iwasawa |
98926d |
if (propertyName == m_rasThickness.getName()) {
|
|
shun-iwasawa |
98926d |
RasterBrushMinSize = m_rasThickness.getValue().first;
|
|
shun-iwasawa |
98926d |
RasterBrushMaxSize = m_rasThickness.getValue().second;
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
m_minThick = m_rasThickness.getValue().first;
|
|
shun-iwasawa |
98926d |
m_maxThick = m_rasThickness.getValue().second;
|
|
walkerka |
bb91cd |
} else if (propertyName == m_smooth.getName()) {
|
|
walkerka |
bb91cd |
BrushSmooth = m_smooth.getValue();
|
|
Shinya Kitaoka |
120a6e |
} else if (propertyName == m_preset.getName()) {
|
|
Shinya Kitaoka |
120a6e |
loadPreset();
|
|
Shinya Kitaoka |
120a6e |
notifyTool = true;
|
|
shun-iwasawa |
975eb1 |
} else if (propertyName == m_drawOrder.getName()) {
|
|
shun-iwasawa |
975eb1 |
BrushDrawOrder = m_drawOrder.getIndex();
|
|
Shinya Kitaoka |
120a6e |
} else if (propertyName == m_pencil.getName()) {
|
|
Shinya Kitaoka |
120a6e |
RasterBrushPencilMode = m_pencil.getValue();
|
|
Shinya Kitaoka |
120a6e |
} else if (propertyName == m_pressure.getName()) {
|
|
Campbell Barton |
f49389 |
BrushPressureSensitivity = m_pressure.getValue();
|
|
shun-iwasawa |
98926d |
} else if (propertyName == m_hardness.getName())
|
|
shun-iwasawa |
98926d |
setWorkAndBackupImages();
|
|
shun-iwasawa |
98926d |
else if (propertyName == m_modifierSize.getName())
|
|
shun-iwasawa |
98926d |
RasterBrushModifierSize = m_modifierSize.getValue();
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
if (propertyName == m_hardness.getName() ||
|
|
shun-iwasawa |
98926d |
propertyName == m_rasThickness.getName()) {
|
|
shun-iwasawa |
98926d |
m_brushPad = getBrushPad(m_rasThickness.getValue().second,
|
|
shun-iwasawa |
98926d |
m_hardness.getValue() * 0.01);
|
|
shun-iwasawa |
98926d |
TRectD rect(m_mousePos - TPointD(m_maxThick + 2, m_maxThick + 2),
|
|
shun-iwasawa |
98926d |
m_mousePos + TPointD(m_maxThick + 2, m_maxThick + 2));
|
|
shun-iwasawa |
98926d |
invalidate(rect);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (propertyName != m_preset.getName() &&
|
|
Shinya Kitaoka |
120a6e |
m_preset.getValue() != CUSTOM_WSTR) {
|
|
Shinya Kitaoka |
120a6e |
m_preset.setValue(CUSTOM_WSTR);
|
|
Shinya Kitaoka |
120a6e |
notifyTool = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (notifyTool) getApplication()->getCurrentTool()->notifyToolChanged();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::initPresets() {
|
|
Shinya Kitaoka |
120a6e |
if (!m_presetsLoaded) {
|
|
Shinya Kitaoka |
120a6e |
// If necessary, load the presets from file
|
|
Shinya Kitaoka |
120a6e |
m_presetsLoaded = true;
|
|
shun-iwasawa |
98926d |
m_presetsManager.load(TEnv::getConfigDir() + "brush_toonzraster.txt");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Rebuild the presets property entries
|
|
Shinya Kitaoka |
120a6e |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_preset.deleteAllValues();
|
|
Shinya Kitaoka |
120a6e |
m_preset.addValue(CUSTOM_WSTR);
|
|
shun-iwasawa |
e87e08 |
m_preset.setItemUIName(CUSTOM_WSTR, tr("<custom>"));</custom>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::set<brushdata>::const_iterator it, end = presets.end();</brushdata>
|
|
Shinya Kitaoka |
120a6e |
for (it = presets.begin(); it != end; ++it) m_preset.addValue(it->m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::loadPreset() {
|
|
Shinya Kitaoka |
120a6e |
const std::set<brushdata> &presets = m_presetsManager.presets();</brushdata>
|
|
Shinya Kitaoka |
120a6e |
std::set<brushdata>::const_iterator it;</brushdata>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
it = presets.find(BrushData(m_preset.getValue()));
|
|
Shinya Kitaoka |
120a6e |
if (it == presets.end()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
const BrushData &preset = *it;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
try // Don't bother with RangeErrors
|
|
Shinya Kitaoka |
120a6e |
{
|
|
shun-iwasawa |
98926d |
m_rasThickness.setValue(
|
|
shun-iwasawa |
98926d |
TDoublePairProperty::Value(std::max(preset.m_min, 1.0), preset.m_max));
|
|
shun-iwasawa |
98926d |
m_brushPad = ToolUtils::getBrushPad(preset.m_max, preset.m_hardness * 0.01);
|
|
shun-iwasawa |
98926d |
m_smooth.setValue(preset.m_smooth, true);
|
|
shun-iwasawa |
98926d |
m_hardness.setValue(preset.m_hardness, true);
|
|
shun-iwasawa |
98926d |
m_drawOrder.setIndex(preset.m_drawOrder);
|
|
shun-iwasawa |
98926d |
m_pencil.setValue(preset.m_pencil);
|
|
shun-iwasawa |
98926d |
m_pressure.setValue(preset.m_pressure);
|
|
shun-iwasawa |
98926d |
m_modifierSize.setValue(preset.m_modifierSize);
|
|
shun-iwasawa |
98926d |
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::addPreset(QString name) {
|
|
Shinya Kitaoka |
120a6e |
// Build the preset
|
|
Shinya Kitaoka |
120a6e |
BrushData preset(name.toStdWString());
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
preset.m_min = m_rasThickness.getValue().first;
|
|
shun-iwasawa |
98926d |
preset.m_max = m_rasThickness.getValue().second;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
98926d |
preset.m_smooth = m_smooth.getValue();
|
|
shun-iwasawa |
98926d |
preset.m_hardness = m_hardness.getValue();
|
|
shun-iwasawa |
98926d |
preset.m_drawOrder = m_drawOrder.getIndex();
|
|
shun-iwasawa |
98926d |
preset.m_pencil = m_pencil.getValue();
|
|
shun-iwasawa |
98926d |
preset.m_pressure = m_pressure.getValue();
|
|
shun-iwasawa |
98926d |
preset.m_modifierSize = m_modifierSize.getValue();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Pass the preset to the manager
|
|
Shinya Kitaoka |
120a6e |
m_presetsManager.addPreset(preset);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Reinitialize the associated preset enum
|
|
Shinya Kitaoka |
120a6e |
initPresets();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Set the value to the specified one
|
|
Shinya Kitaoka |
120a6e |
m_preset.setValue(preset.m_name);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::removePreset() {
|
|
Shinya Kitaoka |
120a6e |
std::wstring name(m_preset.getValue());
|
|
Shinya Kitaoka |
120a6e |
if (name == CUSTOM_WSTR) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_presetsManager.removePreset(name);
|
|
Shinya Kitaoka |
120a6e |
initPresets();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// No parameter change, and set the preset value to custom
|
|
Shinya Kitaoka |
120a6e |
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 |
*/
|
|
shun-iwasawa |
98926d |
bool ToonzRasterBrushTool::isPencilModeActive() {
|
|
Shinya Kitaoka |
120a6e |
return getTargetType() == TTool::ToonzImage && m_pencil.getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
//------------------------------------------------------------------
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::onColorStyleChanged() {
|
|
shun-iwasawa |
98926d |
// in case the style switched while drawing
|
|
shun-iwasawa |
98926d |
if (m_tileSaver) {
|
|
shun-iwasawa |
98926d |
bool isValid = m_enabled && m_active;
|
|
shun-iwasawa |
98926d |
m_enabled = false;
|
|
shun-iwasawa |
98926d |
if (isValid) {
|
|
shun-iwasawa |
98926d |
finishRasterBrush(m_mousePos, 1);
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
TTool::Application *app = getApplication();
|
|
shun-iwasawa |
98926d |
TMyPaintBrushStyle *mpbs =
|
|
shun-iwasawa |
98926d |
dynamic_cast<tmypaintbrushstyle *="">(app->getCurrentLevelStyle());</tmypaintbrushstyle>
|
|
shun-iwasawa |
98926d |
m_isMyPaintStyleSelected = (mpbs) ? true : false;
|
|
shun-iwasawa |
98926d |
setWorkAndBackupImages();
|
|
shun-iwasawa |
98926d |
getApplication()->getCurrentTool()->notifyToolChanged();
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
//------------------------------------------------------------------
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
double ToonzRasterBrushTool::restartBrushTimer() {
|
|
shun-iwasawa |
98926d |
double dtime = m_brushTimer.nsecsElapsed() * 1e-9;
|
|
shun-iwasawa |
98926d |
m_brushTimer.restart();
|
|
shun-iwasawa |
98926d |
return dtime;
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
//------------------------------------------------------------------
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
void ToonzRasterBrushTool::updateCurrentStyle() {
|
|
shun-iwasawa |
98926d |
if (m_isMyPaintStyleSelected) {
|
|
shun-iwasawa |
98926d |
TTool::Application *app = TTool::getApplication();
|
|
shun-iwasawa |
98926d |
TMyPaintBrushStyle *brushStyle =
|
|
shun-iwasawa |
98926d |
dynamic_cast<tmypaintbrushstyle *="">(app->getCurrentLevelStyle());</tmypaintbrushstyle>
|
|
manongjohn |
b5dd39 |
if (!brushStyle) {
|
|
manongjohn |
b5dd39 |
// brush changed to normal abnormally. Complete color style change.
|
|
manongjohn |
b5dd39 |
onColorStyleChanged();
|
|
manongjohn |
b5dd39 |
return;
|
|
manongjohn |
b5dd39 |
}
|
|
shun-iwasawa |
98926d |
double radiusLog = brushStyle->getBrush().getBaseValue(
|
|
shun-iwasawa |
98926d |
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC) +
|
|
shun-iwasawa |
98926d |
m_modifierSize.getValue() * log(2.0);
|
|
shun-iwasawa |
98926d |
double radius = exp(radiusLog);
|
|
shun-iwasawa |
98926d |
m_minCursorThick = m_maxCursorThick = (int)std::round(2.0 * radius);
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
//==========================================================================================================
|
|
shun-iwasawa |
98926d |
|
|
shun-iwasawa |
98926d |
ToonzRasterBrushToolNotifier::ToonzRasterBrushToolNotifier(
|
|
shun-iwasawa |
98926d |
ToonzRasterBrushTool *tool)
|
|
shun-iwasawa |
98926d |
: m_tool(tool) {
|
|
shun-iwasawa |
98926d |
if (TTool::Application *app = m_tool->getApplication()) {
|
|
shun-iwasawa |
98926d |
if (TPaletteHandle *paletteHandle = app->getCurrentPalette()) {
|
|
shun-iwasawa |
98926d |
bool ret;
|
|
shun-iwasawa |
98926d |
ret = connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
|
|
shun-iwasawa |
98926d |
SLOT(onColorStyleChanged()));
|
|
shun-iwasawa |
e93284 |
ret = ret && connect(paletteHandle, SIGNAL(colorStyleSwitched()), this,
|
|
shun-iwasawa |
e93284 |
SLOT(onColorStyleChanged()));
|
|
shun-iwasawa |
e93284 |
ret = ret && connect(paletteHandle, SIGNAL(paletteSwitched()), this,
|
|
shun-iwasawa |
e93284 |
SLOT(onColorStyleChanged()));
|
|
shun-iwasawa |
98926d |
assert(ret);
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
onColorStyleChanged();
|
|
shun-iwasawa |
98926d |
}
|
|
shun-iwasawa |
98926d |
|
|
Toshihiro Shimizu |
890ddd |
//==========================================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Tools instantiation
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
98926d |
ToonzRasterBrushTool toonzPencil("T_Brush",
|
|
shun-iwasawa |
98926d |
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()
|
|
Shinya Kitaoka |
120a6e |
: m_name()
|
|
Shinya Kitaoka |
120a6e |
, m_min(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_max(0.0)
|
|
walkerka |
bb91cd |
, m_smooth(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_hardness(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_opacityMin(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_opacityMax(0.0)
|
|
shun-iwasawa |
975eb1 |
, m_drawOrder(0)
|
|
Shinya Kitaoka |
120a6e |
, m_pencil(false)
|
|
Shinya Kitaoka |
120a6e |
, m_pressure(false)
|
|
|
bf1d82 |
, m_modifierSize(0.0)
|
|
|
572ed1 |
, m_modifierOpacity(0.0)
|
|
|
572ed1 |
, m_modifierEraser(0.0)
|
|
|
572ed1 |
, m_modifierLockAlpha(0.0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BrushData::BrushData(const std::wstring &name)
|
|
Shinya Kitaoka |
120a6e |
: m_name(name)
|
|
Shinya Kitaoka |
120a6e |
, m_min(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_max(0.0)
|
|
walkerka |
bb91cd |
, m_smooth(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_hardness(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_opacityMin(0.0)
|
|
Shinya Kitaoka |
120a6e |
, m_opacityMax(0.0)
|
|
shun-iwasawa |
975eb1 |
, m_drawOrder(0)
|
|
Shinya Kitaoka |
120a6e |
, m_pencil(false)
|
|
Shinya Kitaoka |
120a6e |
, m_pressure(false)
|
|
|
bf1d82 |
, m_modifierSize(0.0)
|
|
|
572ed1 |
, m_modifierOpacity(0.0)
|
|
|
572ed1 |
, m_modifierEraser(0.0)
|
|
|
572ed1 |
, m_modifierLockAlpha(0.0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrushData::saveData(TOStream &os) {
|
|
Shinya Kitaoka |
120a6e |
os.openChild("Name");
|
|
Shinya Kitaoka |
120a6e |
os << m_name;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
Shinya Kitaoka |
120a6e |
os.openChild("Thickness");
|
|
Shinya Kitaoka |
120a6e |
os << m_min << m_max;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
walkerka |
bb91cd |
os.openChild("Smooth");
|
|
walkerka |
bb91cd |
os << m_smooth;
|
|
walkerka |
bb91cd |
os.closeChild();
|
|
Shinya Kitaoka |
120a6e |
os.openChild("Hardness");
|
|
Shinya Kitaoka |
120a6e |
os << m_hardness;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
Shinya Kitaoka |
120a6e |
os.openChild("Opacity");
|
|
Shinya Kitaoka |
120a6e |
os << m_opacityMin << m_opacityMax;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
shun-iwasawa |
975eb1 |
os.openChild("Draw_Order");
|
|
shun-iwasawa |
975eb1 |
os << m_drawOrder;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
Shinya Kitaoka |
120a6e |
os.openChild("Pencil");
|
|
Shinya Kitaoka |
120a6e |
os << (int)m_pencil;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
Shinya Kitaoka |
120a6e |
os.openChild("Pressure_Sensitivity");
|
|
Shinya Kitaoka |
120a6e |
os << (int)m_pressure;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
|
bf1d82 |
os.openChild("Modifier_Size");
|
|
|
bf1d82 |
os << m_modifierSize;
|
|
|
bf1d82 |
os.closeChild();
|
|
|
bf1d82 |
os.openChild("Modifier_Opacity");
|
|
|
bf1d82 |
os << m_modifierOpacity;
|
|
|
bf1d82 |
os.closeChild();
|
|
|
572ed1 |
os.openChild("Modifier_Eraser");
|
|
|
572ed1 |
os << (int)m_modifierEraser;
|
|
|
572ed1 |
os.closeChild();
|
|
|
572ed1 |
os.openChild("Modifier_LockAlpha");
|
|
|
572ed1 |
os << (int)m_modifierLockAlpha;
|
|
|
572ed1 |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrushData::loadData(TIStream &is) {
|
|
Shinya Kitaoka |
120a6e |
std::string tagName;
|
|
Shinya Kitaoka |
120a6e |
int val;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
while (is.matchTag(tagName)) {
|
|
Shinya Kitaoka |
120a6e |
if (tagName == "Name")
|
|
Shinya Kitaoka |
120a6e |
is >> m_name, is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
else if (tagName == "Thickness")
|
|
Shinya Kitaoka |
120a6e |
is >> m_min >> m_max, is.matchEndTag();
|
|
walkerka |
bb91cd |
else if (tagName == "Smooth")
|
|
walkerka |
bb91cd |
is >> m_smooth, is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
else if (tagName == "Hardness")
|
|
Shinya Kitaoka |
120a6e |
is >> m_hardness, is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
else if (tagName == "Opacity")
|
|
Shinya Kitaoka |
120a6e |
is >> m_opacityMin >> m_opacityMax, is.matchEndTag();
|
|
shun-iwasawa |
975eb1 |
else if (tagName == "Selective" ||
|
|
shun-iwasawa |
975eb1 |
tagName == "Draw_Order") // "Selective" is left to keep backward
|
|
shun-iwasawa |
975eb1 |
// compatibility
|
|
shun-iwasawa |
975eb1 |
is >> m_drawOrder, is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
else if (tagName == "Pencil")
|
|
Shinya Kitaoka |
120a6e |
is >> val, m_pencil = val, is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
else if (tagName == "Pressure_Sensitivity")
|
|
Shinya Kitaoka |
120a6e |
is >> val, m_pressure = val, is.matchEndTag();
|
|
|
bf1d82 |
else if (tagName == "Modifier_Size")
|
|
|
bf1d82 |
is >> m_modifierSize, is.matchEndTag();
|
|
|
bf1d82 |
else if (tagName == "Modifier_Opacity")
|
|
|
bf1d82 |
is >> m_modifierOpacity, is.matchEndTag();
|
|
|
572ed1 |
else if (tagName == "Modifier_Eraser")
|
|
|
572ed1 |
is >> val, m_modifierEraser = val, is.matchEndTag();
|
|
|
572ed1 |
else if (tagName == "Modifier_LockAlpha")
|
|
|
572ed1 |
is >> val, m_modifierLockAlpha = val, is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
is.skipCurrentTag();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
void BrushPresetManager::load(const TFilePath &fp) {
|
|
Shinya Kitaoka |
120a6e |
m_fp = fp;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::string tagName;
|
|
Shinya Kitaoka |
120a6e |
BrushData data;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TIStream is(m_fp);
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
while (is.matchTag(tagName)) {
|
|
Shinya Kitaoka |
120a6e |
if (tagName == "version") {
|
|
Shinya Kitaoka |
120a6e |
VersionNumber version;
|
|
Shinya Kitaoka |
120a6e |
is >> version.first >> version.second;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
is.setVersion(version);
|
|
Shinya Kitaoka |
120a6e |
is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
} else if (tagName == "brushes") {
|
|
Shinya Kitaoka |
120a6e |
while (is.matchTag(tagName)) {
|
|
Shinya Kitaoka |
120a6e |
if (tagName == "brush") {
|
|
Shinya Kitaoka |
120a6e |
is >> data, m_presets.insert(data);
|
|
Shinya Kitaoka |
120a6e |
is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
is.skipCurrentTag();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
is.matchEndTag();
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
is.skipCurrentTag();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrushPresetManager::save() {
|
|
Shinya Kitaoka |
120a6e |
TOStream os(m_fp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
os.openChild("version");
|
|
Shinya Kitaoka |
120a6e |
os << 1 << 19;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
os.openChild("brushes");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::set<brushdata>::iterator it, end = m_presets.end();</brushdata>
|
|
Shinya Kitaoka |
120a6e |
for (it = m_presets.begin(); it != end; ++it) {
|
|
Shinya Kitaoka |
120a6e |
os.openChild("brush");
|
|
Shinya Kitaoka |
120a6e |
os << (TPersist &)*it;
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
os.closeChild();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrushPresetManager::addPreset(const BrushData &data) {
|
|
Shinya Kitaoka |
120a6e |
m_presets.erase(data); // Overwriting insertion
|
|
Shinya Kitaoka |
120a6e |
m_presets.insert(data);
|
|
Shinya Kitaoka |
120a6e |
save();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void BrushPresetManager::removePreset(const std::wstring &name) {
|
|
Shinya Kitaoka |
120a6e |
m_presets.erase(BrushData(name));
|
|
Shinya Kitaoka |
120a6e |
save();
|
|
Toshihiro Shimizu |
890ddd |
}
|