Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "brushtool.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzTools includes
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "tools/tooloptions.h"
Toshihiro Shimizu 890ddd
#include "bluredbrush.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/imageutils.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobject.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectspline.h"
Toshihiro Shimizu 890ddd
#include "toonz/rasterstrokegenerator.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttileset.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzimageutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/palettecontroller.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Jeremy Bullock 7f2044
#include "toonz/preferences.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 VectorBrushMinSize("InknpaintVectorBrushMinSize", 1);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar VectorBrushMaxSize("InknpaintVectorBrushMaxSize", 5);
Jeremy Bullock 9ec2d1
TEnv::IntVar VectorCapStyle("InknpaintVectorCapStyle", 1);
Jeremy Bullock f7993a
TEnv::IntVar VectorJoinStyle("InknpaintVectorJoinStyle", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar VectorMiterValue("InknpaintVectorMiterValue", 4);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar RasterBrushMinSize("InknpaintRasterBrushMinSize", 1);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar RasterBrushMaxSize("InknpaintRasterBrushMaxSize", 5);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar BrushAccuracy("InknpaintBrushAccuracy", 20);
walkerka 2e244a
TEnv::DoubleVar BrushSmooth("InknpaintBrushSmooth", 0);
shun-iwasawa 975eb1
TEnv::IntVar BrushDrawOrder("InknpaintBrushDrawOrder", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar BrushBreakSharpAngles("InknpaintBrushBreakSharpAngles", 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);
Jeremy Bullock cd00fd
TEnv::IntVar VectorBrushFrameRange("VectorBrushFrameRange", 0);
Jeremy Bullock cd00fd
TEnv::IntVar VectorBrushSnap("VectorBrushSnap", 0);
Jeremy Bullock cd00fd
TEnv::IntVar VectorBrushSnapSensitivity("VectorBrushSnapSensitivity", 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define ROUNDC_WSTR L"round_cap"
Toshihiro Shimizu 890ddd
#define BUTT_WSTR L"butt_cap"
Toshihiro Shimizu 890ddd
#define PROJECTING_WSTR L"projecting_cap"
Toshihiro Shimizu 890ddd
#define ROUNDJ_WSTR L"round_join"
Toshihiro Shimizu 890ddd
#define BEVEL_WSTR L"bevel_join"
Toshihiro Shimizu 890ddd
#define MITER_WSTR L"miter_join"
Toshihiro Shimizu 890ddd
#define CUSTOM_WSTR L"<custom>"</custom>
Toshihiro Shimizu 890ddd
Jeremy Bullock cd00fd
#define LINEAR_WSTR L"Linear"
Jeremy Bullock cd00fd
#define EASEIN_WSTR L"In"
Jeremy Bullock cd00fd
#define EASEOUT_WSTR L"Out"
Jeremy Bullock cd00fd
#define EASEINOUT_WSTR L"In&Out"
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
#define LOW_WSTR L"Low"
Jeremy Bullock cd00fd
#define MEDIUM_WSTR L"Med"
Jeremy Bullock cd00fd
#define HIGH_WSTR L"High"
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
const double SNAPPING_LOW    = 5.0;
Jeremy Bullock cd00fd
const double SNAPPING_MEDIUM = 25.0;
Jeremy Bullock cd00fd
const double SNAPPING_HIGH   = 100.0;
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 600da6
double computeThickness(double pressure, const TDoublePairProperty &property,
Shinya Kitaoka 120a6e
                        bool isPath) {
Shinya Kitaoka 120a6e
  if (isPath) return 0.0;
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 600da6
int computeThickness(double pressure, const TIntPairProperty &property,
Shinya Kitaoka 120a6e
                     bool isPath) {
Shinya Kitaoka 120a6e
  if (isPath) return 0.0;
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
//
Toshihiro Shimizu 890ddd
// BrushTool
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
BrushTool::BrushTool(std::string name, int targetType)
Shinya Kitaoka 120a6e
    : TTool(name)
Shinya Kitaoka 120a6e
    , m_thickness("Size", 0, 100, 0, 5)
Shinya Kitaoka 120a6e
    , m_rasThickness("Size", 1, 100, 1, 5)
Shinya Kitaoka 120a6e
    , m_accuracy("Accuracy:", 1, 100, 20)
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_breakAngles("Break", true)
Shinya Kitaoka 120a6e
    , m_pencil("Pencil", false)
Shinya Kitaoka 120a6e
    , m_pressure("Pressure", true)
Shinya Kitaoka 120a6e
    , m_capStyle("Cap")
Shinya Kitaoka 120a6e
    , m_joinStyle("Join")
Shinya Kitaoka 120a6e
    , m_miterJoinLimit("Miter:", 0, 100, 4)
Shinya Kitaoka 120a6e
    , m_rasterTrack(0)
Shinya Kitaoka 120a6e
    , m_styleId(0)
Shinya Kitaoka 120a6e
    , m_modifiedRegion()
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)
Jeremy Bullock cd00fd
    , m_firstFrameRange(true)
Shinya Kitaoka 120a6e
    , m_presetsLoaded(false)
Jeremy Bullock cd00fd
    , m_frameRange("Range:")
Jeremy Bullock cd00fd
    , m_snap("Snap", false)
Jeremy Bullock cd00fd
    , m_snapSensitivity("Sensitivity:")
Jeremy Bullock cd00fd
    , m_targetType(targetType)
Shinya Kitaoka 120a6e
    , m_workingFrameId(TFrameId()) {
Shinya Kitaoka 120a6e
  bind(targetType);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (targetType & TTool::Vectors) {
Shinya Kitaoka 120a6e
    m_prop[0].bind(m_thickness);
Shinya Kitaoka 120a6e
    m_prop[0].bind(m_accuracy);
walkerka bb91cd
    m_prop[0].bind(m_smooth);
Shinya Kitaoka 120a6e
    m_prop[0].bind(m_breakAngles);
Shinya Kitaoka 120a6e
    m_breakAngles.setId("BreakSharpAngles");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (targetType & TTool::ToonzImage) {
Shinya Kitaoka 120a6e
    m_prop[0].bind(m_rasThickness);
Shinya Kitaoka 120a6e
    m_prop[0].bind(m_hardness);
walkerka bb91cd
    m_prop[0].bind(m_smooth);
shun-iwasawa 975eb1
    m_prop[0].bind(m_drawOrder);
Shinya Kitaoka 120a6e
    m_prop[0].bind(m_pencil);
Shinya Kitaoka 120a6e
    m_pencil.setId("PencilMode");
shun-iwasawa 975eb1
shun-iwasawa df7bb0
    m_drawOrder.addValue(L"Over All");
shun-iwasawa df7bb0
    m_drawOrder.addValue(L"Under All");
shun-iwasawa df7bb0
    m_drawOrder.addValue(L"Palette Order");
shun-iwasawa 975eb1
    m_drawOrder.setId("DrawOrder");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_prop[0].bind(m_pressure);
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
  if (targetType & TTool::Vectors) {
Jeremy Bullock cd00fd
    m_frameRange.addValue(L"Off");
Jeremy Bullock cd00fd
    m_frameRange.addValue(LINEAR_WSTR);
Jeremy Bullock cd00fd
    m_frameRange.addValue(EASEIN_WSTR);
Jeremy Bullock cd00fd
    m_frameRange.addValue(EASEOUT_WSTR);
Jeremy Bullock cd00fd
    m_frameRange.addValue(EASEINOUT_WSTR);
Jeremy Bullock cd00fd
    m_prop[0].bind(m_frameRange);
Jeremy Bullock cd00fd
    m_frameRange.setId("FrameRange");
Jeremy Bullock cd00fd
    m_prop[0].bind(m_snap);
Jeremy Bullock cd00fd
    m_snap.setId("Snap");
Jeremy Bullock cd00fd
    m_snapSensitivity.addValue(LOW_WSTR);
Jeremy Bullock cd00fd
    m_snapSensitivity.addValue(MEDIUM_WSTR);
Jeremy Bullock cd00fd
    m_snapSensitivity.addValue(HIGH_WSTR);
Jeremy Bullock cd00fd
    m_prop[0].bind(m_snapSensitivity);
Jeremy Bullock cd00fd
    m_snapSensitivity.setId("SnapSensitivity");
Jeremy Bullock cd00fd
  }
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");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (targetType & TTool::Vectors) {
shun-iwasawa df7bb0
    m_capStyle.addValue(BUTT_WSTR, QString::fromStdWString(BUTT_WSTR));
shun-iwasawa df7bb0
    m_capStyle.addValue(ROUNDC_WSTR, QString::fromStdWString(ROUNDC_WSTR));
shun-iwasawa df7bb0
    m_capStyle.addValue(PROJECTING_WSTR,
shun-iwasawa df7bb0
                        QString::fromStdWString(PROJECTING_WSTR));
shun-iwasawa d6e799
    m_capStyle.setId("Cap");
Shinya Kitaoka 120a6e
    m_prop[1].bind(m_capStyle);
shun-iwasawa d6e799
shun-iwasawa df7bb0
    m_joinStyle.addValue(MITER_WSTR, QString::fromStdWString(MITER_WSTR));
shun-iwasawa df7bb0
    m_joinStyle.addValue(ROUNDJ_WSTR, QString::fromStdWString(ROUNDJ_WSTR));
shun-iwasawa df7bb0
    m_joinStyle.addValue(BEVEL_WSTR, QString::fromStdWString(BEVEL_WSTR));
shun-iwasawa d6e799
    m_joinStyle.setId("Join");
Shinya Kitaoka 120a6e
    m_prop[1].bind(m_joinStyle);
shun-iwasawa d6e799
shun-iwasawa d6e799
    m_miterJoinLimit.setId("Miter");
Shinya Kitaoka 120a6e
    m_prop[1].bind(m_miterJoinLimit);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ToolOptionsBox *BrushTool::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
Shinya Kitaoka 120a6e
void BrushTool::drawLine(const TPointD &point, const TPointD ¢re,
Shinya Kitaoka 120a6e
                         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
Shinya Kitaoka 120a6e
void BrushTool::drawEmptyCircle(TPointD pos, int thick, bool isLxEven,
Shinya Kitaoka 120a6e
                                bool isLyEven, 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
Shinya Kitaoka 120a6e
void BrushTool::updateTranslation() {
Shinya Kitaoka 120a6e
  m_thickness.setQStringName(tr("Size"));
Shinya Kitaoka 120a6e
  m_rasThickness.setQStringName(tr("Size"));
Shinya Kitaoka 120a6e
  m_hardness.setQStringName(tr("Hardness:"));
Shinya Kitaoka 120a6e
  m_accuracy.setQStringName(tr("Accuracy:"));
walkerka bb91cd
  m_smooth.setQStringName(tr("Smooth:"));
shun-iwasawa 975eb1
  m_drawOrder.setQStringName(tr("Draw Order:"));
shun-iwasawa df7bb0
  if (m_targetType & TTool::ToonzImage) {
shun-iwasawa df7bb0
    m_drawOrder.setItemUIName(L"Over All", tr("Over All"));
shun-iwasawa df7bb0
    m_drawOrder.setItemUIName(L"Under All", tr("Under All"));
shun-iwasawa df7bb0
    m_drawOrder.setItemUIName(L"Palette Order", tr("Palette Order"));
shun-iwasawa df7bb0
  }
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_breakAngles.setQStringName(tr("Break"));
Shinya Kitaoka 120a6e
  m_pencil.setQStringName(tr("Pencil"));
Shinya Kitaoka 120a6e
  m_pressure.setQStringName(tr("Pressure"));
Shinya Kitaoka 120a6e
  m_capStyle.setQStringName(tr("Cap"));
Shinya Kitaoka 120a6e
  m_joinStyle.setQStringName(tr("Join"));
Shinya Kitaoka 120a6e
  m_miterJoinLimit.setQStringName(tr("Miter:"));
Yu Chen da5534
  m_frameRange.setQStringName(tr("Range:"));
Yu Chen da5534
  m_snap.setQStringName(tr("Snap"));
Jeremy Bullock cd00fd
  m_snapSensitivity.setQStringName("");
shun-iwasawa df7bb0
  if (m_targetType & TTool::Vectors) {
shun-iwasawa df7bb0
    m_frameRange.setItemUIName(L"Off", tr("Off"));
shun-iwasawa df7bb0
    m_frameRange.setItemUIName(LINEAR_WSTR, tr("Linear"));
shun-iwasawa df7bb0
    m_frameRange.setItemUIName(EASEIN_WSTR, tr("In"));
shun-iwasawa df7bb0
    m_frameRange.setItemUIName(EASEOUT_WSTR, tr("Out"));
shun-iwasawa df7bb0
    m_frameRange.setItemUIName(EASEINOUT_WSTR, tr("In&Out"));
shun-iwasawa df7bb0
    m_snapSensitivity.setItemUIName(LOW_WSTR, tr("Low"));
shun-iwasawa df7bb0
    m_snapSensitivity.setItemUIName(MEDIUM_WSTR, tr("Med"));
shun-iwasawa df7bb0
    m_snapSensitivity.setItemUIName(HIGH_WSTR, tr("High"));
shun-iwasawa df7bb0
    m_capStyle.setItemUIName(BUTT_WSTR, tr("Butt cap"));
shun-iwasawa df7bb0
    m_capStyle.setItemUIName(ROUNDC_WSTR, tr("Round cap"));
shun-iwasawa df7bb0
    m_capStyle.setItemUIName(PROJECTING_WSTR, tr("Projecting cap"));
shun-iwasawa df7bb0
    m_joinStyle.setItemUIName(MITER_WSTR, tr("Miter join"));
shun-iwasawa df7bb0
    m_joinStyle.setItemUIName(ROUNDJ_WSTR, tr("Round join"));
shun-iwasawa df7bb0
    m_joinStyle.setItemUIName(BEVEL_WSTR, tr("Bevel join"));
shun-iwasawa df7bb0
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::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
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
Shinya Kitaoka 120a6e
void BrushTool::onActivate() {
Shinya Kitaoka 120a6e
  if (m_firstTime) {
Shinya Kitaoka 120a6e
    m_thickness.setValue(
Shinya Kitaoka 120a6e
        TDoublePairProperty::Value(VectorBrushMinSize, VectorBrushMaxSize));
Shinya Kitaoka 120a6e
    m_rasThickness.setValue(
Shinya Kitaoka 120a6e
        TDoublePairProperty::Value(RasterBrushMinSize, RasterBrushMaxSize));
shun-iwasawa d6e799
    if (m_targetType & TTool::Vectors) {
shun-iwasawa d6e799
      m_capStyle.setIndex(VectorCapStyle);
shun-iwasawa d6e799
      m_joinStyle.setIndex(VectorJoinStyle);
shun-iwasawa d6e799
      m_miterJoinLimit.setValue(VectorMiterValue);
shun-iwasawa d6e799
      m_breakAngles.setValue(BrushBreakSharpAngles ? 1 : 0);
shun-iwasawa d6e799
      m_accuracy.setValue(BrushAccuracy);
shun-iwasawa d6e799
    }
shun-iwasawa d6e799
    if (m_targetType & TTool::ToonzImage) {
shun-iwasawa d6e799
      m_drawOrder.setIndex(BrushDrawOrder);
shun-iwasawa d6e799
      m_pencil.setValue(RasterBrushPencilMode ? 1 : 0);
shun-iwasawa d6e799
      m_hardness.setValue(RasterBrushHardness);
shun-iwasawa d6e799
    }
Campbell Barton f49389
    m_pressure.setValue(BrushPressureSensitivity ? 1 : 0);
Shinya Kitaoka 120a6e
    m_firstTime = false;
walkerka bb91cd
    m_smooth.setValue(BrushSmooth);
Jeremy Bullock cd00fd
    if (m_targetType & TTool::Vectors) {
Jeremy Bullock cd00fd
      m_frameRange.setIndex(VectorBrushFrameRange);
Jeremy Bullock cd00fd
      m_snap.setValue(VectorBrushSnap);
Jeremy Bullock cd00fd
      m_snapSensitivity.setIndex(VectorBrushSnapSensitivity);
Jeremy Bullock cd00fd
      switch (VectorBrushSnapSensitivity) {
Jeremy Bullock cd00fd
      case 0:
Jeremy Bullock cd00fd
        m_minDistance2 = SNAPPING_LOW;
Jeremy Bullock cd00fd
        break;
Jeremy Bullock cd00fd
      case 1:
Jeremy Bullock cd00fd
        m_minDistance2 = SNAPPING_MEDIUM;
Jeremy Bullock cd00fd
        break;
Jeremy Bullock cd00fd
      case 2:
Jeremy Bullock cd00fd
        m_minDistance2 = SNAPPING_HIGH;
Jeremy Bullock cd00fd
        break;
Jeremy Bullock cd00fd
      }
Jeremy Bullock cd00fd
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_targetType & TTool::ToonzImage) {
Shinya Kitaoka 120a6e
    m_brushPad = ToolUtils::getBrushPad(m_rasThickness.getValue().second,
Shinya Kitaoka 120a6e
                                        m_hardness.getValue() * 0.01);
Shinya Kitaoka 120a6e
    setWorkAndBackupImages();
Shinya Kitaoka 120a6e
  }
Jeremy Bullock cd00fd
  resetFrameRange();
Shinya Kitaoka 120a6e
  // TODO:app->editImageOrSpline();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::onDeactivate() {
Shinya Kitaoka 120a6e
  /*---
Shinya Kitaoka 120a6e
   * ドラッグ中にツールが切り替わった場合に備え、onDeactivateにもMouseReleaseと同じ処理を行う
Shinya Kitaoka 120a6e
   * ---*/
Shinya Kitaoka 120a6e
  if (m_tileSaver && !m_isPath) {
Shinya Kitaoka 120a6e
    bool isValid = m_enabled && m_active;
Shinya Kitaoka 120a6e
    m_enabled    = false;
Shinya Kitaoka 120a6e
    if (isValid) {
Shinya Kitaoka 120a6e
      TImageP image = getImage(true);
Shinya Kitaoka 120a6e
      if (TToonzImageP ti = image)
Shinya Kitaoka 120a6e
        finishRasterBrush(m_mousePos,
Shinya Kitaoka 120a6e
                          1); /*-- 最後のストロークの筆圧は1とする --*/
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_workRas   = TRaster32P();
Shinya Kitaoka 120a6e
  m_backupRas = TRasterCM32P();
Jeremy Bullock cd00fd
  resetFrameRange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool BrushTool::preLeftButtonDown() {
Shinya Kitaoka 120a6e
  touchImage();
Shinya Kitaoka 120a6e
  if (m_isFrameCreated) setWorkAndBackupImages();
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::leftButtonDown(const TPointD &pos, 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();
Shinya Kitaoka 120a6e
  m_isPath  = app->getCurrentObject()->isSpline();
Shinya Kitaoka 120a6e
  m_enabled = col >= 0 || m_isPath;
Shinya Kitaoka 120a6e
  // todo: gestire autoenable
Shinya Kitaoka 120a6e
  if (!m_enabled) return;
Shinya Kitaoka 120a6e
  if (!m_isPath) {
Shinya Kitaoka 120a6e
    m_currentColor = TPixel32::Black;
Shinya Kitaoka 120a6e
    m_active       = !!getImage(true);
Shinya Kitaoka 120a6e
    if (!m_active) {
Shinya Kitaoka 120a6e
      m_active = !!touchImage();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (!m_active) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_active) {
Shinya Kitaoka 120a6e
      // nel caso che il colore corrente sia un cleanup/studiopalette color
Shinya Kitaoka 120a6e
      // oppure il colore di un colorfield
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 ? cs->getRasterStyleFx() : 0;
Shinya Kitaoka 120a6e
        m_active =
Shinya Kitaoka 120a6e
            cs != 0 && (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_styleId      = 1;
Shinya Kitaoka 120a6e
        m_currentColor = TPixel32::Black;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_currentColor = TPixel32::Red;
Shinya Kitaoka 120a6e
    m_active       = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // assert(0<=m_styleId && m_styleId<2);
Shinya Kitaoka 120a6e
  TImageP img = getImage(true);
Shinya Kitaoka 120a6e
  TToonzImageP ri(img);
Shinya Kitaoka 120a6e
  if (ri) {
Shinya Kitaoka 120a6e
    TRasterCM32P ras = ri->getRaster();
Shinya Kitaoka 120a6e
    if (ras) {
Shinya Kitaoka 120a6e
      TPointD rasCenter = ras->getCenterD();
Shinya Kitaoka 120a6e
      m_tileSet         = new TTileSetCM32(ras->getSize());
Shinya Kitaoka 120a6e
      m_tileSaver       = new TTileSaverCM32(ras, m_tileSet);
Shinya Kitaoka 120a6e
      double maxThick   = m_rasThickness.getValue().second;
Shinya Kitaoka 120a6e
      double thickness =
Shinya Kitaoka 120a6e
          (m_pressure.getValue() || m_isPath)
Shinya Kitaoka 120a6e
              ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2
Shinya Kitaoka 120a6e
              : maxThick;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する
Shinya Kitaoka 120a6e
       * ---*/
shun-iwasawa 600da6
      if (m_pressure.getValue() && e.m_pressure == 1.0)
Shinya Kitaoka 120a6e
        thickness = m_rasThickness.getValue().first;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
Shinya Kitaoka 120a6e
      TRectD invalidateRect(pos - halfThick, pos + halfThick);
shun-iwasawa 975eb1
shun-iwasawa 975eb1
      // if the drawOrder mode = "Palette Order",
shun-iwasawa 975eb1
      // get styleId list which is above the current style in the palette
shun-iwasawa 975eb1
      DrawOrder drawOrder = (DrawOrder)m_drawOrder.getIndex();
shun-iwasawa 975eb1
      QSet<int> aboveStyleIds;</int>
shun-iwasawa 975eb1
      if (drawOrder == PaletteOrder) {
shun-iwasawa 975eb1
        getAboveStyleIdSet(m_styleId, ri->getPalette(), aboveStyleIds);
shun-iwasawa 975eb1
      }
shun-iwasawa 975eb1
Shinya Kitaoka 120a6e
      if (m_hardness.getValue() == 100 || m_pencil.getValue()) {
Shinya Kitaoka 120a6e
        /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる
Shinya Kitaoka 120a6e
         * --*/
Shinya Kitaoka 120a6e
        if (!m_pencil.getValue()) thickness -= 1.0;
walkerka 22f456
walkerka 22f456
        TThickPoint thickPoint(pos + convert(ras->getCenter()), thickness);
walkerka 22f456
        m_rasterTrack = new RasterStrokeGenerator(
shun-iwasawa 975eb1
            ras, BRUSH, NONE, m_styleId, thickPoint, drawOrder != OverAll, 0,
shun-iwasawa 975eb1
            !m_pencil.getValue(), drawOrder == PaletteOrder);
shun-iwasawa 975eb1
shun-iwasawa 975eb1
        if (drawOrder == PaletteOrder)
shun-iwasawa 975eb1
          m_rasterTrack->setAboveStyleIds(aboveStyleIds);
shun-iwasawa 975eb1
walkerka 22f456
        m_tileSaver->save(m_rasterTrack->getLastRect());
walkerka 22f456
        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 {
Jeremy Bullock 6c7e54
          m_smoothStroke.beginStroke(m_smooth.getValue());
Jeremy Bullock 6c7e54
          m_smoothStroke.addPoint(thickPoint);
Jeremy Bullock 6c7e54
          m_smoothStroke.getSmoothPoints(pts);
Jeremy Bullock 6c7e54
        }
walkerka 22f456
      } else {
walkerka 22f456
        m_points.clear();
walkerka 22f456
        TThickPoint point(pos + rasCenter, thickness);
walkerka 22f456
        m_points.push_back(point);
walkerka 22f456
        m_bluredBrush = new BluredBrush(m_workRas, maxThick, m_brushPad, false);
walkerka 22f456
shun-iwasawa 975eb1
        if (drawOrder == PaletteOrder)
shun-iwasawa 975eb1
          m_bluredBrush->setAboveStyleIds(aboveStyleIds);
shun-iwasawa 975eb1
walkerka 22f456
        m_strokeRect = m_bluredBrush->getBoundFromPoints(m_points);
walkerka 22f456
        updateWorkAndBackupRasters(m_strokeRect);
walkerka 22f456
        m_tileSaver->save(m_strokeRect);
walkerka 22f456
        m_bluredBrush->addPoint(point, 1);
walkerka 22f456
        m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect,
shun-iwasawa 975eb1
                                     m_styleId, drawOrder);
walkerka 22f456
        m_lastRect = m_strokeRect;
walkerka 22f456
walkerka 22f456
        std::vector<tthickpoint> pts;</tthickpoint>
Jeremy Bullock 6c7e54
        if (m_smooth.getValue() == 0) {
Jeremy Bullock 6c7e54
          pts.push_back(point);
Jeremy Bullock 6c7e54
        } else {
Jeremy Bullock 6c7e54
          m_smoothStroke.beginStroke(m_smooth.getValue());
Jeremy Bullock 6c7e54
          m_smoothStroke.addPoint(point);
Jeremy Bullock 6c7e54
          m_smoothStroke.getSmoothPoints(pts);
Jeremy Bullock 6c7e54
        }
walkerka 22f456
      }
walkerka 22f456
      /*-- 作業中のFidを登録 --*/
walkerka 22f456
      m_workingFrameId = getFrameId();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      invalidate(invalidateRect);
Shinya Kitaoka 120a6e
    }
Jeremy Bullock cd00fd
  } else {  // vector happens here
Shinya Kitaoka 120a6e
    m_track.clear();
Shinya Kitaoka 120a6e
    double thickness =
Shinya Kitaoka 120a6e
        (m_pressure.getValue() || m_isPath)
Shinya Kitaoka 120a6e
            ? computeThickness(e.m_pressure, m_thickness, m_isPath)
Shinya Kitaoka 120a6e
            : m_thickness.getValue().second * 0.5;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/
shun-iwasawa 600da6
    if (m_pressure.getValue() && e.m_pressure == 1.0)
Jeremy Bullock cd00fd
      thickness     = m_rasThickness.getValue().first;
Jeremy Bullock cd00fd
    m_currThickness = thickness;
walkerka bb91cd
    m_smoothStroke.beginStroke(m_smooth.getValue());
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    if ((m_targetType & TTool::Vectors) && m_foundFirstSnap) {
Jeremy Bullock cd00fd
      addTrackPoint(TThickPoint(m_firstSnapPoint, thickness),
Jeremy Bullock cd00fd
                    getPixelSize() * getPixelSize());
Jeremy Bullock cd00fd
    } else
Jeremy Bullock cd00fd
      addTrackPoint(TThickPoint(pos, thickness),
Jeremy Bullock cd00fd
                    getPixelSize() * getPixelSize());
walkerka 22f456
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  m_brushPos = m_mousePos = pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_enabled || !m_active) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isAdded;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (TToonzImageP ti = TImageP(getImage(true))) {
Shinya Kitaoka 120a6e
    TPointD rasCenter = ti->getRaster()->getCenterD();
Shinya Kitaoka 120a6e
    int maxThickness  = m_rasThickness.getValue().second;
Shinya Kitaoka 120a6e
    double thickness =
Shinya Kitaoka 120a6e
        (m_pressure.getValue() || m_isPath)
Shinya Kitaoka 120a6e
            ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2
Shinya Kitaoka 120a6e
            : maxThickness;
Shinya Kitaoka 120a6e
    TRectD invalidateRect;
Shinya Kitaoka 120a6e
    if (m_rasterTrack &&
Shinya Kitaoka 120a6e
        (m_hardness.getValue() == 100 || m_pencil.getValue())) {
Shinya Kitaoka 120a6e
      /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる
Shinya Kitaoka 120a6e
       * --*/
Shinya Kitaoka 120a6e
      if (!m_pencil.getValue()) thickness -= 1.0;
walkerka 22f456
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.getSmoothPoints(pts);
Jeremy Bullock 6c7e54
      }
walkerka 22f456
      for (size_t i = 0; i < pts.size(); ++i) {
walkerka 22f456
        const TThickPoint &thickPoint = pts[i];
walkerka 22f456
        isAdded                       = m_rasterTrack->add(thickPoint);
walkerka 22f456
        if (isAdded) {
walkerka 22f456
          m_tileSaver->save(m_rasterTrack->getLastRect());
walkerka 22f456
          m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());
walkerka 22f456
          std::vector<tthickpoint> brushPoints =</tthickpoint>
walkerka 22f456
              m_rasterTrack->getPointsSequence();
walkerka 22f456
          int m = (int)brushPoints.size();
walkerka 22f456
          std::vector<tthickpoint> points;</tthickpoint>
walkerka 22f456
          if (m == 3) {
walkerka 22f456
            points.push_back(brushPoints[0]);
walkerka 22f456
            points.push_back(brushPoints[1]);
walkerka 22f456
          } else {
walkerka 22f456
            points.push_back(brushPoints[m - 4]);
walkerka 22f456
            points.push_back(brushPoints[m - 3]);
walkerka 22f456
            points.push_back(brushPoints[m - 2]);
walkerka 22f456
          }
walkerka 22f456
          if (i == 0) {
walkerka 22f456
            invalidateRect =
walkerka 22f456
                ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
          } else {
walkerka 22f456
            invalidateRect +=
walkerka 22f456
                ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
          }
Shinya Kitaoka 120a6e
        }
walkerka 22f456
      }
Shinya Kitaoka 120a6e
    } else {
walkerka 22f456
      // antialiased brush
walkerka 22f456
      assert(m_workRas.getPointer() && m_backupRas.getPointer());
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.getSmoothPoints(pts);
Jeremy Bullock 6c7e54
      }
walkerka 22f456
      bool rectUpdated = false;
walkerka 22f456
      for (size_t i = 0; i < pts.size(); ++i) {
walkerka 22f456
        TThickPoint old = m_points.back();
walkerka 22f456
        if (norm2(pos - old) < 4) continue;
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
        }
walkerka 22f456
        if (!rectUpdated) {
walkerka 22f456
          invalidateRect =
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
          rectUpdated = true;
walkerka 22f456
        } else {
walkerka 22f456
          invalidateRect +=
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
        }
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
      }
walkerka 22f456
    }
walkerka 22f456
    invalidate(invalidateRect.enlarge(2));
walkerka 22f456
  } else {
walkerka 22f456
    double thickness =
walkerka 22f456
        (m_pressure.getValue() || m_isPath)
walkerka 22f456
            ? computeThickness(e.m_pressure, m_thickness, m_isPath)
walkerka 22f456
            : m_thickness.getValue().second * 0.5;
Jeremy Bullock 7f2044
Jeremy Bullock cd00fd
    m_currThickness = thickness;
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    m_mousePos      = pos;
Jeremy Bullock cd00fd
    m_lastSnapPoint = pos;
Jeremy Bullock cd00fd
    m_foundLastSnap = false;
Jeremy Bullock cd00fd
    checkStrokeSnapping(false);
Jeremy Bullock cd00fd
    checkGuideSnapping(false);
Jeremy Bullock cd00fd
    m_brushPos = m_lastSnapPoint;
Jeremy Bullock cd00fd
Jeremy Bullock 7f2044
    if (e.isShiftPressed()) {
Jeremy Bullock 7f2044
      m_smoothStroke.clearPoints();
Jeremy Bullock cd00fd
      m_track.add(TThickPoint(m_brushPos, thickness),
Jeremy Bullock cd00fd
                  getPixelSize() * getPixelSize());
Jeremy Bullock 7f2044
      m_track.removeMiddlePoints();
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    else if (m_dragDraw)
Jeremy Bullock 7f2044
      addTrackPoint(TThickPoint(pos, thickness),
Jeremy Bullock 7f2044
                    getPixelSize() * getPixelSize());
Jeremy Bullock cd00fd
Shinya Kitaoka 120a6e
    invalidate();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  bool isValid = m_enabled && m_active;
Shinya Kitaoka 120a6e
  m_enabled    = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!isValid) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_isPath) {
Shinya Kitaoka 120a6e
    double error = 20.0 * getPixelSize();
Jeremy Bullock 7f2044
Jeremy Bullock 7f2044
    TStroke *stroke;
Jeremy Bullock 7f2044
    if (e.isShiftPressed()) {
Jeremy Bullock 7f2044
      m_track.removeMiddlePoints();
Jeremy Bullock 7f2044
      stroke = m_track.makeStroke(0);
Jeremy Bullock 7f2044
    } else {
Jeremy Bullock 7f2044
      flushTrackPoint();
Jeremy Bullock 7f2044
      stroke = m_track.makeStroke(error);
Jeremy Bullock 7f2044
    }
Jeremy Bullock 7f2044
    int points = stroke->getControlPointCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (TVectorImageP vi = getImage(true)) {
Shinya Kitaoka 120a6e
      struct Cleanup {
Shinya Kitaoka 120a6e
        BrushTool *m_this;
Shinya Kitaoka 120a6e
        ~Cleanup() { m_this->m_track.clear(), m_this->invalidate(); }
Shinya Kitaoka 120a6e
      } cleanup = {this};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (!isJustCreatedSpline(vi.getPointer())) {
Shinya Kitaoka 120a6e
        m_isPrompting = true;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        QString question("Are you sure you want to replace the motion path?");
Shinya Kitaoka 120a6e
        int ret =
Shinya Kitaoka 120a6e
            DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"), 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        m_isPrompting = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        if (ret == 2 || ret == 0) return;
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      QMutexLocker lock(vi->getMutex());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TUndo *undo =
Shinya Kitaoka 120a6e
          new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      while (vi->getStrokeCount() > 0) vi->deleteStroke(0);
Shinya Kitaoka 120a6e
      vi->addStroke(stroke, false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      notifyImageChanged();
Shinya Kitaoka 120a6e
      TUndoManager::manager()->add(undo);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TImageP image = getImage(true);
Shinya Kitaoka 120a6e
  if (TVectorImageP vi = image) {
Shinya Kitaoka 120a6e
    if (m_track.isEmpty()) {
Shinya Kitaoka 120a6e
      m_styleId = 0;
Shinya Kitaoka 120a6e
      m_track.clear();
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    if (vi && m_snap.getValue() && m_foundLastSnap) {
Jeremy Bullock cd00fd
      addTrackPoint(TThickPoint(m_lastSnapPoint, m_currThickness),
Jeremy Bullock cd00fd
                    getPixelSize() * getPixelSize());
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
    m_strokeIndex1   = -1;
Jeremy Bullock cd00fd
    m_strokeIndex2   = -1;
Jeremy Bullock cd00fd
    m_w1             = -1;
Jeremy Bullock cd00fd
    m_w2             = -2;
Jeremy Bullock cd00fd
    m_foundFirstSnap = false;
Jeremy Bullock cd00fd
    m_foundLastSnap  = false;
Jeremy Bullock cd00fd
Shinya Kitaoka 120a6e
    m_track.filterPoints();
Shinya Kitaoka 120a6e
    double error = 30.0 / (1 + 0.5 * m_accuracy.getValue());
Shinya Kitaoka 120a6e
    error *= getPixelSize();
Toshihiro Shimizu 890ddd
Jeremy Bullock 7f2044
    TStroke *stroke;
Jeremy Bullock 7f2044
    if (e.isShiftPressed()) {
Jeremy Bullock 7f2044
      m_track.removeMiddlePoints();
Jeremy Bullock 7f2044
      stroke = m_track.makeStroke(0);
Jeremy Bullock 7f2044
    } else {
Jeremy Bullock 7f2044
      flushTrackPoint();
Jeremy Bullock 7f2044
      stroke = m_track.makeStroke(error);
Jeremy Bullock 7f2044
    }
Shinya Kitaoka 120a6e
    stroke->setStyle(m_styleId);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      TStroke::OutlineOptions &options = stroke->outlineOptions();
Shinya Kitaoka 120a6e
      options.m_capStyle               = m_capStyle.getIndex();
Shinya Kitaoka 120a6e
      options.m_joinStyle              = m_joinStyle.getIndex();
Shinya Kitaoka 120a6e
      options.m_miterUpper             = m_miterJoinLimit.getValue();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_styleId = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QMutexLocker lock(vi->getMutex());
Shinya Kitaoka 120a6e
    if (stroke->getControlPointCount() == 3 &&
Shinya Kitaoka 120a6e
        stroke->getControlPoint(0) !=
Shinya Kitaoka 120a6e
            stroke->getControlPoint(2))  // gli stroke con solo 1 chunk vengono
Shinya Kitaoka 120a6e
                                         // fatti dal tape tool...e devono venir
Shinya Kitaoka 120a6e
                                         // riconosciuti come speciali di
Shinya Kitaoka 120a6e
                                         // autoclose proprio dal fatto che
Shinya Kitaoka 120a6e
                                         // hanno 1 solo chunk.
Shinya Kitaoka 120a6e
      stroke->insertControlPoints(0.5);
Jeremy Bullock cd00fd
    if (m_frameRange.getIndex()) {
Jeremy Bullock cd00fd
      if (m_firstFrameId == -1) {
Jeremy Bullock cd00fd
        m_firstStroke                   = new TStroke(*stroke);
Jeremy Bullock cd00fd
        m_firstFrameId                  = getFrameId();
Jeremy Bullock cd00fd
        TTool::Application *application = TTool::getApplication();
Jeremy Bullock cd00fd
        if (application) {
Jeremy Bullock cd00fd
          m_col        = application->getCurrentColumn()->getColumnIndex();
Jeremy Bullock cd00fd
          m_firstFrame = application->getCurrentFrame()->getFrame();
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
        m_rangeTrack = m_track;
Jeremy Bullock cd00fd
        if (m_firstFrameRange) {
Jeremy Bullock cd00fd
          m_veryFirstCol     = m_col;
Jeremy Bullock cd00fd
          m_veryFirstFrame   = m_firstFrame;
Jeremy Bullock cd00fd
          m_veryFirstFrameId = m_firstFrameId;
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
      } else if (m_firstFrameId == getFrameId()) {
Jeremy Bullock cd00fd
        if (m_firstStroke) {
Jeremy Bullock cd00fd
          delete m_firstStroke;
Jeremy Bullock cd00fd
          m_firstStroke = 0;
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
        m_firstStroke = new TStroke(*stroke);
Jeremy Bullock cd00fd
        m_rangeTrack  = m_track;
Jeremy Bullock cd00fd
      } else {
Jeremy Bullock cd00fd
        TFrameId currentId = getFrameId();
Jeremy Bullock cd00fd
        int curCol = 0, curFrame = 0;
Jeremy Bullock cd00fd
        TTool::Application *application = TTool::getApplication();
Jeremy Bullock cd00fd
        if (application) {
Jeremy Bullock cd00fd
          curCol   = application->getCurrentColumn()->getColumnIndex();
Jeremy Bullock cd00fd
          curFrame = application->getCurrentFrame()->getFrame();
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
        bool success =
Jeremy Bullock cd00fd
            doFrameRangeStrokes(m_firstFrameId, m_firstStroke, getFrameId(),
Jeremy Bullock cd00fd
                                stroke, m_firstFrameRange);
Jeremy Bullock cd00fd
        if (e.isCtrlPressed()) {
Jeremy Bullock cd00fd
          if (application) {
Jeremy Bullock cd00fd
            if (m_firstFrameId > currentId) {
Jeremy Bullock cd00fd
              if (application->getCurrentFrame()->isEditingScene()) {
Jeremy Bullock cd00fd
                application->getCurrentColumn()->setColumnIndex(curCol);
Jeremy Bullock cd00fd
                application->getCurrentFrame()->setFrame(curFrame);
Jeremy Bullock cd00fd
              } else
Jeremy Bullock cd00fd
                application->getCurrentFrame()->setFid(currentId);
Jeremy Bullock cd00fd
            }
Jeremy Bullock cd00fd
          }
Jeremy Bullock cd00fd
          resetFrameRange();
Jeremy Bullock cd00fd
          m_firstStroke     = new TStroke(*stroke);
Jeremy Bullock cd00fd
          m_rangeTrack      = m_track;
Jeremy Bullock cd00fd
          m_firstFrameId    = currentId;
Jeremy Bullock cd00fd
          m_firstFrameRange = false;
Jeremy Bullock cd00fd
        }
Shinya Kitaoka 120a6e
Jeremy Bullock cd00fd
        if (application && !e.isCtrlPressed()) {
Jeremy Bullock cd00fd
          if (application->getCurrentFrame()->isEditingScene()) {
Jeremy Bullock cd00fd
            application->getCurrentColumn()->setColumnIndex(m_veryFirstCol);
Jeremy Bullock cd00fd
            application->getCurrentFrame()->setFrame(m_veryFirstFrame);
Jeremy Bullock cd00fd
          } else
Jeremy Bullock cd00fd
            application->getCurrentFrame()->setFid(m_veryFirstFrameId);
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
        if (!e.isCtrlPressed()) {
Jeremy Bullock cd00fd
          resetFrameRange();
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
      }
Jeremy Bullock cd00fd
    } else {
Jeremy Bullock cd00fd
      addStrokeToImage(getApplication(), vi, stroke, m_breakAngles.getValue(),
Jeremy Bullock cd00fd
                       m_isFrameCreated, m_isLevelCreated);
Jeremy Bullock cd00fd
      TRectD bbox = stroke->getBBox().enlarge(2) + m_track.getModifiedRegion();
Jeremy Bullock cd00fd
      invalidate();
Jeremy Bullock cd00fd
    }
Shinya Kitaoka 120a6e
    assert(stroke);
Shinya Kitaoka 120a6e
    m_track.clear();
Jeremy Bullock cd00fd
Shinya Kitaoka 120a6e
  } else if (TToonzImageP ti = image) {
Shinya Kitaoka 120a6e
    finishRasterBrush(pos, e.m_pressure);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
walkerka 57fb3c
//--------------------------------------------------------------------------------------------------
walkerka 57fb3c
shun-iwasawa 7f1e30
bool BrushTool::keyDown(QKeyEvent *event) {
shun-iwasawa 7f1e30
  if (event->key() == Qt::Key_Escape) {
Jeremy Bullock cd00fd
    resetFrameRange();
Jeremy Bullock cd00fd
  }
Jeremy Bullock 78b876
  return false;
Jeremy Bullock cd00fd
}
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
//--------------------------------------------------------------------------------------------------
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
bool BrushTool::doFrameRangeStrokes(TFrameId firstFrameId, TStroke *firstStroke,
Jeremy Bullock cd00fd
                                    TFrameId lastFrameId, TStroke *lastStroke,
Jeremy Bullock cd00fd
                                    bool drawFirstStroke) {
Jeremy Bullock cd00fd
  TXshSimpleLevel *sl =
Jeremy Bullock cd00fd
      TTool::getApplication()->getCurrentLevel()->getLevel()->getSimpleLevel();
Jeremy Bullock cd00fd
  TStroke *first           = new TStroke();
Jeremy Bullock cd00fd
  TStroke *last            = new TStroke();
Jeremy Bullock cd00fd
  TVectorImageP firstImage = new TVectorImage();
Jeremy Bullock cd00fd
  TVectorImageP lastImage  = new TVectorImage();
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
  *first       = *firstStroke;
Jeremy Bullock cd00fd
  *last        = *lastStroke;
Jeremy Bullock cd00fd
  bool swapped = false;
Jeremy Bullock cd00fd
  if (firstFrameId > lastFrameId) {
Jeremy Bullock cd00fd
    tswap(firstFrameId, lastFrameId);
Jeremy Bullock cd00fd
    *first  = *lastStroke;
Jeremy Bullock cd00fd
    *last   = *firstStroke;
Jeremy Bullock cd00fd
    swapped = true;
Jeremy Bullock cd00fd
  }
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
  firstImage->addStroke(first);
Jeremy Bullock cd00fd
  lastImage->addStroke(last);
Jeremy Bullock cd00fd
  assert(firstFrameId <= lastFrameId);
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
  std::vector<tframeid> allFids;</tframeid>
Jeremy Bullock cd00fd
  sl->getFids(allFids);
Jeremy Bullock cd00fd
  std::vector<tframeid>::iterator i0 = allFids.begin();</tframeid>
Jeremy Bullock cd00fd
  while (i0 != allFids.end() && *i0 < firstFrameId) i0++;
Jeremy Bullock cd00fd
  if (i0 == allFids.end()) return false;
Jeremy Bullock cd00fd
  std::vector<tframeid>::iterator i1 = i0;</tframeid>
Jeremy Bullock cd00fd
  while (i1 != allFids.end() && *i1 <= lastFrameId) i1++;
Jeremy Bullock cd00fd
  assert(i0 < i1);
Jeremy Bullock cd00fd
  std::vector<tframeid> fids(i0, i1);</tframeid>
Jeremy Bullock cd00fd
  int m = fids.size();
Jeremy Bullock cd00fd
  assert(m > 0);
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
  TUndoManager::manager()->beginBlock();
Jeremy Bullock cd00fd
  for (int i = 0; i < m; ++i) {
Jeremy Bullock cd00fd
    TFrameId fid = fids[i];
Jeremy Bullock cd00fd
    assert(firstFrameId <= fid && fid <= lastFrameId);
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    // This is an attempt to divide the tween evenly
Jeremy Bullock cd00fd
    double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;
Jeremy Bullock cd00fd
    double s = t;
Jeremy Bullock cd00fd
    switch (m_frameRange.getIndex()) {
Jeremy Bullock cd00fd
    case 1:  // LINEAR_WSTR
Jeremy Bullock cd00fd
      break;
Jeremy Bullock cd00fd
    case 2:  // EASEIN_WSTR
Jeremy Bullock cd00fd
      s = t * t;
Jeremy Bullock cd00fd
      break;  // s'(0) = 0
Jeremy Bullock cd00fd
    case 3:   // EASEOUT_WSTR
Jeremy Bullock cd00fd
      s = t * (2 - t);
Jeremy Bullock cd00fd
      break;  // s'(1) = 0
Jeremy Bullock cd00fd
    case 4:   // EASEINOUT_WSTR:
Jeremy Bullock cd00fd
      s = t * t * (3 - 2 * t);
Jeremy Bullock cd00fd
      break;  // s'(0) = s'(1) = 0
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    TTool::Application *app = TTool::getApplication();
Jeremy Bullock cd00fd
    if (app) {
Jeremy Bullock cd00fd
      if (app->getCurrentFrame()->isEditingScene())
Jeremy Bullock cd00fd
        app->getCurrentFrame()->setFrame(fid.getNumber() - 1);
Jeremy Bullock cd00fd
      else
Jeremy Bullock cd00fd
        app->getCurrentFrame()->setFid(fid);
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    TVectorImageP img = sl->getFrame(fid, true);
Jeremy Bullock cd00fd
    if (t == 0) {
Jeremy Bullock cd00fd
      if (!swapped && !drawFirstStroke) {
Jeremy Bullock cd00fd
      } else
Jeremy Bullock cd00fd
        addStrokeToImage(getApplication(), img, firstImage->getStroke(0),
Jeremy Bullock cd00fd
                         m_breakAngles.getValue(), m_isFrameCreated,
Jeremy Bullock 129805
                         m_isLevelCreated, sl, fid);
Jeremy Bullock cd00fd
    } else if (t == 1) {
Jeremy Bullock cd00fd
      if (swapped && !drawFirstStroke) {
Jeremy Bullock cd00fd
      } else
Jeremy Bullock cd00fd
        addStrokeToImage(getApplication(), img, lastImage->getStroke(0),
Jeremy Bullock cd00fd
                         m_breakAngles.getValue(), m_isFrameCreated,
Jeremy Bullock 129805
                         m_isLevelCreated, sl, fid);
Jeremy Bullock cd00fd
    } else {
Jeremy Bullock cd00fd
      assert(firstImage->getStrokeCount() == 1);
Jeremy Bullock cd00fd
      assert(lastImage->getStrokeCount() == 1);
Jeremy Bullock cd00fd
      TVectorImageP vi = TInbetween(firstImage, lastImage).tween(s);
Jeremy Bullock cd00fd
      assert(vi->getStrokeCount() == 1);
Jeremy Bullock cd00fd
      addStrokeToImage(getApplication(), img, vi->getStroke(0),
Jeremy Bullock cd00fd
                       m_breakAngles.getValue(), m_isFrameCreated,
Jeremy Bullock 129805
                       m_isLevelCreated, sl, fid);
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
  }
Jeremy Bullock cd00fd
  TUndoManager::manager()->endBlock();
Jeremy Bullock cd00fd
  notifyImageChanged();
Jeremy Bullock cd00fd
  return true;
Jeremy Bullock cd00fd
}
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
//--------------------------------------------------------------------------------------------------
Jeremy Bullock cd00fd
walkerka 22f456
void BrushTool::addTrackPoint(const TThickPoint &point, double pixelSize2) {
walkerka 22f456
  m_smoothStroke.addPoint(point);
walkerka 22f456
  std::vector<tthickpoint> pts;</tthickpoint>
walkerka 22f456
  m_smoothStroke.getSmoothPoints(pts);
walkerka 22f456
  for (size_t i = 0; i < pts.size(); ++i) {
walkerka 22f456
    m_track.add(pts[i], pixelSize2);
walkerka 22f456
  }
walkerka 57fb3c
}
walkerka 57fb3c
walkerka 57fb3c
//--------------------------------------------------------------------------------------------------
walkerka 57fb3c
walkerka 22f456
void BrushTool::flushTrackPoint() {
walkerka 22f456
  m_smoothStroke.endStroke();
walkerka 22f456
  std::vector<tthickpoint> pts;</tthickpoint>
walkerka 22f456
  m_smoothStroke.getSmoothPoints(pts);
walkerka 22f456
  double pixelSize2 = getPixelSize() * getPixelSize();
walkerka 22f456
  for (size_t i = 0; i < pts.size(); ++i) {
walkerka 22f456
    m_track.add(pts[i], pixelSize2);
walkerka 22f456
  }
walkerka 57fb3c
}
walkerka 57fb3c
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*!
Shinya Kitaoka 120a6e
 * ドラッグ中にツールが切り替わった場合に備え、onDeactivate時とMouseRelease時にと同じ終了処理を行う
Toshihiro Shimizu 890ddd
*/
shun-iwasawa 600da6
void BrushTool::finishRasterBrush(const TPointD &pos, double pressureVal) {
Shinya Kitaoka 120a6e
  TImageP image   = getImage(true);
Shinya Kitaoka 120a6e
  TToonzImageP ti = image;
Shinya Kitaoka 120a6e
  if (!ti) return;
Shinya Kitaoka 120a6e
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;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_rasterTrack && (m_hardness.getValue() == 100 || m_pencil.getValue())) {
Shinya Kitaoka 120a6e
    double thickness =
Shinya Kitaoka 120a6e
        m_pressure.getValue()
Shinya Kitaoka 120a6e
            ? computeThickness(pressureVal, m_rasThickness, m_isPath)
Shinya Kitaoka 120a6e
            : 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];
walkerka 22f456
      bool isAdded                  = m_rasterTrack->add(thickPoint);
walkerka 22f456
      if (isAdded) {
walkerka 22f456
        m_tileSaver->save(m_rasterTrack->getLastRect());
walkerka 22f456
        m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue(), true);
walkerka 22f456
walkerka 22f456
        std::vector<tthickpoint> brushPoints =</tthickpoint>
walkerka 22f456
            m_rasterTrack->getPointsSequence();
walkerka 22f456
        int m = (int)brushPoints.size();
walkerka 22f456
        std::vector<tthickpoint> points;</tthickpoint>
walkerka 22f456
        if (m == 3) {
walkerka 22f456
          points.push_back(brushPoints[0]);
walkerka 22f456
          points.push_back(brushPoints[1]);
walkerka 22f456
        } else {
walkerka 22f456
          points.push_back(brushPoints[m - 4]);
walkerka 22f456
          points.push_back(brushPoints[m - 3]);
walkerka 22f456
          points.push_back(brushPoints[m - 2]);
walkerka 611fd3
        }
walkerka 22f456
        int maxThickness = m_rasThickness.getValue().second;
walkerka 22f456
        if (i == 0) {
walkerka 22f456
          invalidateRect =
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
        } else {
walkerka 22f456
          invalidateRect +=
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka bb91cd
        }
walkerka 22f456
      }
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 {
walkerka 22f456
    if (m_points.size() != 1) {
walkerka 22f456
      double maxThickness = m_rasThickness.getValue().second;
walkerka 22f456
      double thickness =
walkerka 22f456
          (m_pressure.getValue() || m_isPath)
walkerka 22f456
              ? computeThickness(pressureVal, m_rasThickness, m_isPath)
walkerka 22f456
              : maxThickness;
walkerka 22f456
      TPointD rasCenter = ti->getRaster()->getCenterD();
walkerka 22f456
      TRectD invalidateRect;
walkerka 22f456
      bool rectUpdated = false;
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() - 1; ++i) {
walkerka 22f456
        TThickPoint old = m_points.back();
walkerka 22f456
        if (norm2(pos - old) < 4) continue;
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
        }
walkerka 22f456
        if (!rectUpdated) {
walkerka 22f456
          invalidateRect =
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
          rectUpdated = true;
walkerka 22f456
        } else {
walkerka 22f456
          invalidateRect +=
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka bb91cd
        }
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
      }
walkerka 22f456
      if (pts.size() > 0) {
walkerka 22f456
        TThickPoint point = pts.back();
walkerka 22f456
        m_points.push_back(point);
walkerka 22f456
        int m = m_points.size();
walkerka 22f456
        std::vector<tthickpoint> points;</tthickpoint>
walkerka 22f456
        points.push_back(m_points[m - 3]);
walkerka 22f456
        points.push_back(m_points[m - 2]);
walkerka 22f456
        points.push_back(m_points[m - 1]);
walkerka 22f456
        TRect bbox = m_bluredBrush->getBoundFromPoints(points);
walkerka 22f456
        updateWorkAndBackupRasters(bbox);
walkerka 22f456
        m_tileSaver->save(bbox);
walkerka 22f456
        m_bluredBrush->addArc(points[0], points[1], points[2], 1, 1);
walkerka 22f456
        m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox,
shun-iwasawa 975eb1
                                     m_styleId, m_drawOrder.getIndex());
walkerka 22f456
walkerka 22f456
        if (!rectUpdated) {
walkerka 22f456
          invalidateRect =
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
        } else {
walkerka 22f456
          invalidateRect +=
walkerka 22f456
              ToolUtils::getBounds(points, maxThickness) - rasCenter;
walkerka 22f456
        }
walkerka 22f456
        m_lastRect += bbox;
walkerka 22f456
        m_strokeRect += bbox;
walkerka 22f456
      }
walkerka 22f456
      invalidate(invalidateRect.enlarge(2));
walkerka 22f456
      m_lastRect.empty();
walkerka 22f456
    }
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
//---------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  struct Locals {
Shinya Kitaoka 120a6e
    BrushTool *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
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
Jeremy Bullock 01e454
    locals.addMinMaxSeparate(
Jeremy Bullock 01e454
        (m_targetType & TTool::ToonzImage) ? m_rasThickness : m_thickness, min,
Jeremy Bullock 01e454
        max);
Jeremy Bullock 01e454
  } else {
shun-iwasawa d6e799
    m_mousePos = pos;
Shinya Kitaoka 120a6e
    m_brushPos = pos;
Jeremy Bullock cd00fd
shun-iwasawa d6e799
    if (m_targetType & TTool::Vectors) {
shun-iwasawa d6e799
      m_firstSnapPoint = pos;
shun-iwasawa d6e799
      m_foundFirstSnap = false;
Jeremy Bullock cd00fd
shun-iwasawa d6e799
      checkStrokeSnapping(true);
shun-iwasawa d6e799
      checkGuideSnapping(true);
shun-iwasawa d6e799
      m_brushPos = m_firstSnapPoint;
shun-iwasawa d6e799
    }
Shinya Kitaoka 120a6e
  }
shun-iwasawa d6e799
  // TODO: this can be partial update for toonz raster brush
Shinya Kitaoka 120a6e
  invalidate();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_minThick == 0 && m_maxThick == 0) {
Shinya Kitaoka 120a6e
    if (m_targetType & TTool::ToonzImage) {
Shinya Kitaoka 120a6e
      m_minThick = m_rasThickness.getValue().first;
Shinya Kitaoka 120a6e
      m_maxThick = m_rasThickness.getValue().second;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_minThick = m_thickness.getValue().first;
Shinya Kitaoka 120a6e
      m_maxThick = m_thickness.getValue().second;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock cd00fd
void BrushTool::checkStrokeSnapping(bool beforeMousePress) {
Jeremy Bullock cd00fd
  if (Preferences::instance()->getVectorSnappingTarget() == 1) return;
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
  TVectorImageP vi(getImage(false));
Jeremy Bullock cd00fd
  if (vi && m_snap.getValue()) {
Jeremy Bullock cd00fd
    m_dragDraw          = true;
Jeremy Bullock cd00fd
    double minDistance2 = m_minDistance2;
Jeremy Bullock cd00fd
    if (beforeMousePress)
Jeremy Bullock cd00fd
      m_strokeIndex1 = -1;
Jeremy Bullock cd00fd
    else
Jeremy Bullock cd00fd
      m_strokeIndex2 = -1;
Jeremy Bullock cd00fd
    int i, strokeNumber = vi->getStrokeCount();
Jeremy Bullock cd00fd
    TStroke *stroke;
Jeremy Bullock cd00fd
    double distance2, outW;
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
    for (i = 0; i < strokeNumber; i++) {
Jeremy Bullock cd00fd
      stroke = vi->getStroke(i);
Jeremy Bullock cd00fd
      if (stroke->getNearestW(m_mousePos, outW, distance2) &&
Jeremy Bullock cd00fd
          distance2 < minDistance2) {
Jeremy Bullock cd00fd
        minDistance2                      = distance2;
Jeremy Bullock cd00fd
        beforeMousePress ? m_strokeIndex1 = i : m_strokeIndex2 = i;
Jeremy Bullock cd00fd
        if (areAlmostEqual(outW, 0.0, 1e-3))
Jeremy Bullock cd00fd
          beforeMousePress ? m_w1 = 0.0 : m_w2 = 0.0;
Jeremy Bullock cd00fd
        else if (areAlmostEqual(outW, 1.0, 1e-3))
Jeremy Bullock cd00fd
          beforeMousePress ? m_w1 = 1.0 : m_w2 = 1.0;
Jeremy Bullock cd00fd
        else
Jeremy Bullock cd00fd
          beforeMousePress ? m_w1 = outW : m_w2 = outW;
Jeremy Bullock cd00fd
        TThickPoint point1;
Jeremy Bullock cd00fd
        beforeMousePress ? point1 = stroke->getPoint(m_w1)
Jeremy Bullock cd00fd
                         : point1 = stroke->getPoint(m_w2);
Jeremy Bullock cd00fd
        if (beforeMousePress) {
Jeremy Bullock cd00fd
          m_firstSnapPoint = TPointD(point1.x, point1.y);
Jeremy Bullock cd00fd
          m_foundFirstSnap = true;
Jeremy Bullock cd00fd
        } else {
Jeremy Bullock cd00fd
          m_lastSnapPoint                 = TPointD(point1.x, point1.y);
Jeremy Bullock cd00fd
          m_foundLastSnap                 = true;
Jeremy Bullock cd00fd
          if (distance2 < 2.0) m_dragDraw = false;
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
      }
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
  }
Jeremy Bullock cd00fd
}
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
//-------------------------------------------------------------------------------------------------------------
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
void BrushTool::checkGuideSnapping(bool beforeMousePress) {
Jeremy Bullock cd00fd
  if (Preferences::instance()->getVectorSnappingTarget() == 0) return;
Jeremy Bullock cd00fd
  bool foundSnap;
Jeremy Bullock cd00fd
  TPointD snapPoint;
Jeremy Bullock cd00fd
  beforeMousePress ? foundSnap = m_foundFirstSnap : foundSnap = m_foundLastSnap;
Jeremy Bullock cd00fd
  beforeMousePress ? snapPoint = m_firstSnapPoint : snapPoint = m_lastSnapPoint;
Jeremy Bullock cd00fd
  if ((m_targetType & TTool::Vectors) && m_snap.getValue()) {
Jeremy Bullock cd00fd
    // check guide snapping
Jeremy Bullock cd00fd
    int vGuideCount = 0, hGuideCount = 0;
Jeremy Bullock cd00fd
    double guideDistance  = sqrt(m_minDistance2);
Jeremy Bullock cd00fd
    TTool::Viewer *viewer = getViewer();
Jeremy Bullock cd00fd
    if (viewer) {
Jeremy Bullock cd00fd
      vGuideCount = viewer->getVGuideCount();
Jeremy Bullock cd00fd
      hGuideCount = viewer->getHGuideCount();
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
    double distanceToVGuide = -1.0, distanceToHGuide = -1.0;
Jeremy Bullock cd00fd
    double vGuide, hGuide;
Jeremy Bullock cd00fd
    bool useGuides = false;
Jeremy Bullock cd00fd
    if (vGuideCount) {
Jeremy Bullock cd00fd
      for (int j = 0; j < vGuideCount; j++) {
Jeremy Bullock cd00fd
        double guide        = viewer->getVGuide(j);
Jeremy Bullock cd00fd
        double tempDistance = abs(guide - m_mousePos.y);
Jeremy Bullock cd00fd
        if (tempDistance < guideDistance &&
Jeremy Bullock cd00fd
            (distanceToVGuide < 0 || tempDistance < distanceToVGuide)) {
Jeremy Bullock cd00fd
          distanceToVGuide = tempDistance;
Jeremy Bullock cd00fd
          vGuide           = guide;
Jeremy Bullock cd00fd
          useGuides        = true;
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
      }
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
    if (hGuideCount) {
Jeremy Bullock cd00fd
      for (int j = 0; j < hGuideCount; j++) {
Jeremy Bullock cd00fd
        double guide        = viewer->getHGuide(j);
Jeremy Bullock cd00fd
        double tempDistance = abs(guide - m_mousePos.x);
Jeremy Bullock cd00fd
        if (tempDistance < guideDistance &&
Jeremy Bullock cd00fd
            (distanceToHGuide < 0 || tempDistance < distanceToHGuide)) {
Jeremy Bullock cd00fd
          distanceToHGuide = tempDistance;
Jeremy Bullock cd00fd
          hGuide           = guide;
Jeremy Bullock cd00fd
          useGuides        = true;
Jeremy Bullock cd00fd
        }
Jeremy Bullock cd00fd
      }
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
    if (useGuides && foundSnap) {
Jeremy Bullock cd00fd
      double currYDistance = abs(snapPoint.y - m_mousePos.y);
Jeremy Bullock cd00fd
      double currXDistance = abs(snapPoint.x - m_mousePos.x);
Jeremy Bullock cd00fd
      double hypotenuse =
Jeremy Bullock cd00fd
          sqrt(pow(currYDistance, 2.0) + pow(currXDistance, 2.0));
Jeremy Bullock cd00fd
      if ((distanceToVGuide >= 0 && distanceToVGuide < hypotenuse) ||
Jeremy Bullock cd00fd
          (distanceToHGuide >= 0 && distanceToHGuide < hypotenuse))
Jeremy Bullock cd00fd
        useGuides = true;
Jeremy Bullock cd00fd
      else
Jeremy Bullock cd00fd
        useGuides = false;
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
    if (useGuides) {
Jeremy Bullock cd00fd
      assert(distanceToHGuide >= 0 || distanceToVGuide >= 0);
Jeremy Bullock cd00fd
      if (distanceToHGuide < 0 ||
Jeremy Bullock cd00fd
          (distanceToVGuide <= distanceToHGuide && distanceToVGuide >= 0)) {
Jeremy Bullock cd00fd
        snapPoint.y = vGuide;
Jeremy Bullock cd00fd
        snapPoint.x = m_mousePos.x;
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
      } else {
Jeremy Bullock cd00fd
        snapPoint.y = m_mousePos.y;
Jeremy Bullock cd00fd
        snapPoint.x = hGuide;
Jeremy Bullock cd00fd
      }
Jeremy Bullock cd00fd
      beforeMousePress ? m_foundFirstSnap = true : m_foundLastSnap = true;
Jeremy Bullock 6c7e54
      beforeMousePress ? m_firstSnapPoint = snapPoint : m_lastSnapPoint =
Jeremy Bullock 6c7e54
                                                            snapPoint;
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
  }
Jeremy Bullock cd00fd
}
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
//-------------------------------------------------------------------------------------------------------------
Jeremy Bullock cd00fd
Shinya Kitaoka 120a6e
void BrushTool::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
  // Draw track
Shinya Kitaoka 120a6e
  tglColor(m_isPrompting ? TPixel32::Green : m_currentColor);
Shinya Kitaoka 120a6e
  m_track.drawAllFragments();
Shinya Kitaoka 120a6e
Jeremy Bullock cd00fd
  // snapping
Jeremy Bullock cd00fd
  TVectorImageP vi = img;
shun-iwasawa d6e799
  if (m_targetType & TTool::Vectors) {
shun-iwasawa d6e799
    if (m_snap.getValue()) {
shun-iwasawa d6e799
      m_pixelSize  = getPixelSize();
shun-iwasawa d6e799
      double thick = 6.0 * m_pixelSize;
shun-iwasawa d6e799
      if (m_foundFirstSnap) {
shun-iwasawa d6e799
        tglColor(TPixelD(0.1, 0.9, 0.1));
shun-iwasawa d6e799
        tglDrawCircle(m_firstSnapPoint, thick);
shun-iwasawa d6e799
      }
Jeremy Bullock cd00fd
shun-iwasawa d6e799
      TThickPoint point2;
Jeremy Bullock cd00fd
shun-iwasawa d6e799
      if (m_foundLastSnap) {
shun-iwasawa d6e799
        tglColor(TPixelD(0.1, 0.9, 0.1));
shun-iwasawa d6e799
        tglDrawCircle(m_lastSnapPoint, thick);
shun-iwasawa d6e799
      }
Jeremy Bullock cd00fd
    }
Jeremy Bullock cd00fd
shun-iwasawa d6e799
    // frame range
shun-iwasawa d6e799
    if (m_firstStroke) {
shun-iwasawa d6e799
      glColor3d(1.0, 0.0, 0.0);
shun-iwasawa d6e799
      m_rangeTrack.drawAllFragments();
shun-iwasawa d6e799
      glColor3d(0.0, 0.6, 0.0);
shun-iwasawa d6e799
      TPointD firstPoint        = m_rangeTrack.getFirstPoint();
shun-iwasawa d6e799
      TPointD topLeftCorner     = TPointD(firstPoint.x - 5, firstPoint.y - 5);
shun-iwasawa d6e799
      TPointD topRightCorner    = TPointD(firstPoint.x + 5, firstPoint.y - 5);
shun-iwasawa d6e799
      TPointD bottomLeftCorner  = TPointD(firstPoint.x - 5, firstPoint.y + 5);
shun-iwasawa d6e799
      TPointD bottomRightCorner = TPointD(firstPoint.x + 5, firstPoint.y + 5);
shun-iwasawa d6e799
      tglDrawSegment(topLeftCorner, bottomRightCorner);
shun-iwasawa d6e799
      tglDrawSegment(topRightCorner, bottomLeftCorner);
shun-iwasawa d6e799
    }
Jeremy Bullock cd00fd
  }
Jeremy Bullock cd00fd
Shinya Kitaoka 120a6e
  if (getApplication()->getCurrentObject()->isSpline()) return;
Shinya Kitaoka 120a6e
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
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
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());
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    tglDrawCircle(m_brushPos, 0.5 * m_minThick);
Shinya Kitaoka 120a6e
    tglDrawCircle(m_brushPos, 0.5 * m_maxThick);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::onEnter() {
Shinya Kitaoka 120a6e
  TImageP img = getImage(false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (TToonzImageP(img)) {
Shinya Kitaoka 120a6e
    m_minThick = m_rasThickness.getValue().first;
Shinya Kitaoka 120a6e
    m_maxThick = m_rasThickness.getValue().second;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_minThick = m_thickness.getValue().first;
Shinya Kitaoka 120a6e
    m_maxThick = m_thickness.getValue().second;
Shinya Kitaoka 120a6e
  }
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
Shinya Kitaoka 120a6e
void BrushTool::onLeave() {
Shinya Kitaoka 120a6e
  m_minThick = 0;
Shinya Kitaoka 120a6e
  m_maxThick = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPropertyGroup *BrushTool::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
Shinya Kitaoka 120a6e
void BrushTool::onImageChanged() {
Shinya Kitaoka 120a6e
  TToonzImageP ti = (TToonzImageP)getImage(false, 1);
Shinya Kitaoka 120a6e
  if (!ti || !isEnabled()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setWorkAndBackupImages();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void BrushTool::setWorkAndBackupImages() {
Shinya Kitaoka 120a6e
  TToonzImageP ti = (TToonzImageP)getImage(false, 1);
Shinya Kitaoka 120a6e
  if (!ti) return;
Shinya Kitaoka 120a6e
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;
Shinya Kitaoka 120a6e
  if (hardness == 1.0 && 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
Jeremy Bullock cd00fd
void BrushTool::resetFrameRange() {
Jeremy Bullock cd00fd
  m_rangeTrack.clear();
Jeremy Bullock cd00fd
  m_firstFrameId = -1;
Jeremy Bullock cd00fd
  if (m_firstStroke) {
Jeremy Bullock cd00fd
    delete m_firstStroke;
Jeremy Bullock cd00fd
    m_firstStroke = 0;
Jeremy Bullock cd00fd
  }
Jeremy Bullock cd00fd
  m_firstFrameRange = true;
Jeremy Bullock cd00fd
}
Jeremy Bullock cd00fd
Jeremy Bullock cd00fd
//------------------------------------------------------------------
Jeremy Bullock cd00fd
Shinya Kitaoka 120a6e
bool BrushTool::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
Shinya Kitaoka 120a6e
  /*--- m_thicknessとm_rasThicknessは同じName(="Size:")なので、
Shinya Kitaoka 120a6e
          扱っている画像がラスタかどうかで区別する---*/
Shinya Kitaoka 120a6e
  if (propertyName == m_thickness.getName()) {
Shinya Kitaoka 120a6e
    TImageP img = getImage(false);
Shinya Kitaoka 120a6e
    if (TToonzImageP(img))  // raster
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      RasterBrushMinSize = m_rasThickness.getValue().first;
Shinya Kitaoka 120a6e
      RasterBrushMaxSize = m_rasThickness.getValue().second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      m_minThick = m_rasThickness.getValue().first;
Shinya Kitaoka 120a6e
      m_maxThick = m_rasThickness.getValue().second;
Shinya Kitaoka 120a6e
    } else  // vector
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      VectorBrushMinSize = m_thickness.getValue().first;
Shinya Kitaoka 120a6e
      VectorBrushMaxSize = m_thickness.getValue().second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      m_minThick = m_thickness.getValue().first;
Shinya Kitaoka 120a6e
      m_maxThick = m_thickness.getValue().second;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else if (propertyName == m_accuracy.getName()) {
Shinya Kitaoka 120a6e
    BrushAccuracy = m_accuracy.getValue();
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_breakAngles.getName()) {
Shinya Kitaoka 120a6e
    BrushBreakSharpAngles = m_breakAngles.getValue();
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();
Shinya Kitaoka 120a6e
  } else if (propertyName == m_capStyle.getName()) {
Shinya Kitaoka 120a6e
    VectorCapStyle = m_capStyle.getIndex();
Shinya Kitaoka 120a6e
  } else if (propertyName == m_joinStyle.getName()) {
Shinya Kitaoka 120a6e
    VectorJoinStyle = m_joinStyle.getIndex();
Shinya Kitaoka 120a6e
  } else if (propertyName == m_miterJoinLimit.getName()) {
Shinya Kitaoka 120a6e
    VectorMiterValue = m_miterJoinLimit.getValue();
Jeremy Bullock cd00fd
  } else if (propertyName == m_frameRange.getName()) {
Jeremy Bullock cd00fd
    int index             = m_frameRange.getIndex();
Jeremy Bullock cd00fd
    VectorBrushFrameRange = index;
Jeremy Bullock cd00fd
    if (index == 0) resetFrameRange();
Jeremy Bullock cd00fd
  } else if (propertyName == m_snap.getName()) {
Jeremy Bullock cd00fd
    VectorBrushSnap = m_snap.getValue();
Jeremy Bullock cd00fd
  } else if (propertyName == m_snapSensitivity.getName()) {
Jeremy Bullock cd00fd
    int index                  = m_snapSensitivity.getIndex();
Jeremy Bullock cd00fd
    VectorBrushSnapSensitivity = index;
Jeremy Bullock cd00fd
    switch (index) {
Jeremy Bullock cd00fd
    case 0:
Jeremy Bullock cd00fd
      m_minDistance2 = SNAPPING_LOW;
Jeremy Bullock cd00fd
      break;
Jeremy Bullock cd00fd
    case 1:
Jeremy Bullock cd00fd
      m_minDistance2 = SNAPPING_MEDIUM;
Jeremy Bullock cd00fd
      break;
Jeremy Bullock cd00fd
    case 2:
Jeremy Bullock cd00fd
      m_minDistance2 = SNAPPING_HIGH;
Jeremy Bullock cd00fd
      break;
Jeremy Bullock cd00fd
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_targetType & TTool::Vectors) {
Shinya Kitaoka 120a6e
    if (propertyName == m_joinStyle.getName()) notifyTool = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_targetType & TTool::ToonzImage) {
Shinya Kitaoka 120a6e
    if (propertyName == m_hardness.getName()) setWorkAndBackupImages();
Shinya Kitaoka 120a6e
    if (propertyName == m_hardness.getName() ||
Shinya Kitaoka 120a6e
        propertyName == m_thickness.getName()) {
Shinya Kitaoka 120a6e
      m_brushPad = getBrushPad(m_rasThickness.getValue().second,
Shinya Kitaoka 120a6e
                               m_hardness.getValue() * 0.01);
Shinya Kitaoka 120a6e
      TRectD rect(m_mousePos - TPointD(m_maxThick + 2, m_maxThick + 2),
Shinya Kitaoka 120a6e
                  m_mousePos + TPointD(m_maxThick + 2, m_maxThick + 2));
Shinya Kitaoka 120a6e
      invalidate(rect);
Shinya Kitaoka 120a6e
    }
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
Shinya Kitaoka 120a6e
void BrushTool::initPresets() {
Shinya Kitaoka 120a6e
  if (!m_presetsLoaded) {
Shinya Kitaoka 120a6e
    // If necessary, load the presets from file
Shinya Kitaoka 120a6e
    m_presetsLoaded = true;
Shinya Kitaoka 120a6e
    if (getTargetType() & TTool::Vectors)
Shinya Kitaoka 120a6e
      m_presetsManager.load(TEnv::getConfigDir() + "brush_vector.txt");
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      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);
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
Shinya Kitaoka 120a6e
void BrushTool::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
  {
Shinya Kitaoka 120a6e
    if (getTargetType() & TTool::Vectors) {
Shinya Kitaoka 120a6e
      m_thickness.setValue(
Shinya Kitaoka 120a6e
          TDoublePairProperty::Value(preset.m_min, preset.m_max));
Shinya Kitaoka 120a6e
      m_accuracy.setValue(preset.m_acc, true);
walkerka bb91cd
      m_smooth.setValue(preset.m_smooth, true);
Shinya Kitaoka 120a6e
      m_breakAngles.setValue(preset.m_breakAngles);
Shinya Kitaoka 120a6e
      m_pressure.setValue(preset.m_pressure);
Shinya Kitaoka 120a6e
      m_capStyle.setIndex(preset.m_cap);
Shinya Kitaoka 120a6e
      m_joinStyle.setIndex(preset.m_join);
Shinya Kitaoka 120a6e
      m_miterJoinLimit.setValue(preset.m_miter);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_rasThickness.setValue(TDoublePairProperty::Value(
Shinya Kitaoka 120a6e
          std::max(preset.m_min, 1.0), preset.m_max));
Shinya Kitaoka 120a6e
      m_brushPad =
Shinya Kitaoka 120a6e
          ToolUtils::getBrushPad(preset.m_max, preset.m_hardness * 0.01);
walkerka bb91cd
      m_smooth.setValue(preset.m_smooth, true);
Shinya Kitaoka 120a6e
      m_hardness.setValue(preset.m_hardness, true);
shun-iwasawa 975eb1
      m_drawOrder.setIndex(preset.m_drawOrder);
Shinya Kitaoka 120a6e
      m_pencil.setValue(preset.m_pencil);
Shinya Kitaoka 120a6e
      m_pressure.setValue(preset.m_pressure);
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 BrushTool::addPreset(QString name) {
Shinya Kitaoka 120a6e
  // Build the preset
Shinya Kitaoka 120a6e
  BrushData preset(name.toStdWString());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (getTargetType() & TTool::Vectors) {
Shinya Kitaoka 120a6e
    preset.m_min = m_thickness.getValue().first;
Shinya Kitaoka 120a6e
    preset.m_max = m_thickness.getValue().second;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    preset.m_min = m_rasThickness.getValue().first;
Shinya Kitaoka 120a6e
    preset.m_max = m_rasThickness.getValue().second;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Jeremy Bullock 129805
  preset.m_acc         = m_accuracy.getValue();
Jeremy Bullock 129805
  preset.m_smooth      = m_smooth.getValue();
Jeremy Bullock 129805
  preset.m_hardness    = m_hardness.getValue();
shun-iwasawa 975eb1
  preset.m_drawOrder   = m_drawOrder.getIndex();
Jeremy Bullock 129805
  preset.m_pencil      = m_pencil.getValue();
Jeremy Bullock 129805
  preset.m_breakAngles = m_breakAngles.getValue();
Jeremy Bullock 129805
  preset.m_pressure    = m_pressure.getValue();
Jeremy Bullock 129805
  preset.m_cap         = m_capStyle.getIndex();
Jeremy Bullock 129805
  preset.m_join        = m_joinStyle.getIndex();
Jeremy Bullock 129805
  preset.m_miter       = m_miterJoinLimit.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
Shinya Kitaoka 120a6e
void BrushTool::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
*/
Shinya Kitaoka 120a6e
bool BrushTool::isPencilModeActive() {
Shinya Kitaoka 120a6e
  return getTargetType() == TTool::ToonzImage && m_pencil.getValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Tools instantiation
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
BrushTool vectorPencil("T_Brush", TTool::Vectors | TTool::EmptyTarget);
Toshihiro Shimizu 890ddd
BrushTool toonzPencil("T_Brush", TTool::ToonzImage | TTool::EmptyTarget);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
//    Brush Data implementation
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
BrushData::BrushData()
Shinya Kitaoka 120a6e
    : m_name()
Shinya Kitaoka 120a6e
    , m_min(0.0)
Shinya Kitaoka 120a6e
    , m_max(0.0)
Shinya Kitaoka 120a6e
    , m_acc(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_breakAngles(false)
Shinya Kitaoka 120a6e
    , m_pressure(false)
Shinya Kitaoka 120a6e
    , m_cap(0)
Shinya Kitaoka 120a6e
    , m_join(0)
bf1d82
    , m_miter(0)
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)
Shinya Kitaoka 120a6e
    , m_acc(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_breakAngles(false)
Shinya Kitaoka 120a6e
    , m_pressure(false)
Shinya Kitaoka 120a6e
    , m_cap(0)
Shinya Kitaoka 120a6e
    , m_join(0)
bf1d82
    , m_miter(0)
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();
Shinya Kitaoka 120a6e
  os.openChild("Accuracy");
Shinya Kitaoka 120a6e
  os << m_acc;
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("Break_Sharp_Angles");
Shinya Kitaoka 120a6e
  os << (int)m_breakAngles;
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("Pressure_Sensitivity");
Shinya Kitaoka 120a6e
  os << (int)m_pressure;
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("Cap");
Shinya Kitaoka 120a6e
  os << m_cap;
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("Join");
Shinya Kitaoka 120a6e
  os << m_join;
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("Miter");
Shinya Kitaoka 120a6e
  os << m_miter;
Jeremy Bullock c6d53a
  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();
Shinya Kitaoka 120a6e
    else if (tagName == "Accuracy")
Shinya Kitaoka 120a6e
      is >> m_acc, 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 == "Break_Sharp_Angles")
Shinya Kitaoka 120a6e
      is >> val, m_breakAngles = val, is.matchEndTag();
Shinya Kitaoka 120a6e
    else if (tagName == "Pressure_Sensitivity")
Shinya Kitaoka 120a6e
      is >> val, m_pressure = val, is.matchEndTag();
Shinya Kitaoka 120a6e
    else if (tagName == "Cap")
Shinya Kitaoka 120a6e
      is >> m_cap, is.matchEndTag();
Shinya Kitaoka 120a6e
    else if (tagName == "Join")
Shinya Kitaoka 120a6e
      is >> m_join, is.matchEndTag();
Shinya Kitaoka 120a6e
    else if (tagName == "Miter")
Shinya Kitaoka 120a6e
      is >> m_miter, 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
}