shun-iwasawa 0842da
#include "controlpointeditortool.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tthreadmessage.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "drawutil.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
pojienie 286724
#include "toonz/strokegenerator.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobject.h"
Toshihiro Shimizu 890ddd
shun_iwasawa d51821
#include <qkeyevent></qkeyevent>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToolUtils;
Toshihiro Shimizu 890ddd
pojienie 286724
TEnv::StringVar CPSelectionType("ControlPointEditorToolSelectionType",
pojienie 286724
                                "Rectangular");
Toshihiro Shimizu 890ddd
TEnv::IntVar AutoSelectDrawing("ControlPointEditorToolAutoSelectDrawing", 1);
pojienie 2979a2
TEnv::IntVar Snap("ControlPointEditorToolSnap", 0);
pojienie 2979a2
TEnv::IntVar SnapSensitivity("ControlPointEditorToolSnapSensitivity", 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
pojienie c7106f
pojienie c7106f
#define LOW_WSTR L"Low"
pojienie c7106f
#define MEDIUM_WSTR L"Medium"
pojienie c7106f
#define HIGH_WSTR L"High"
pojienie c7106f
pojienie 286724
#define RECTANGULAR_WSTR L"Rectangular"
pojienie 286724
#define FREEHAND_WSTR L"Freehand"
pojienie 286724
pojienie c6cb30
const double SNAPPING_LOW    = 5.0;
pojienie c6cb30
const double SNAPPING_MEDIUM = 25.0;
pojienie c6cb30
const double SNAPPING_HIGH   = 100.0;
pojienie c6cb30
pojienie c7106f
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
/*! Restituisce i parametri riferiti allo stroke della curva che si vuole
Shinya Kitaoka 120a6e
   muovere.
Shinya Kitaoka 120a6e
    I parametri dipendono da come sono i punti in \b beforeIndex, \b nextIndex
Shinya Kitaoka 120a6e
   (cuspidi, lineari).
Shinya Kitaoka 120a6e
    Puo' restituire due range nei casi in cui lo stroke e' selfLoop e la curva
Shinya Kitaoka 120a6e
   e' a cavallo del punto di chiusura.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void getSegmentParameter(ControlPointEditorStroke *cpEditor, int beforeIndex,
Shinya Kitaoka 120a6e
                         int nextIndex, double &w0, double &w1, double &q0,
Shinya Kitaoka 120a6e
                         double &q1) {
Shinya Kitaoka 120a6e
  TStroke *stroke = cpEditor->getStroke();
Shinya Kitaoka 120a6e
  if (!stroke) return;
Shinya Kitaoka 120a6e
  q0 = q1 = w0 = w1 = -1;
Shinya Kitaoka 120a6e
  int cpCount       = cpEditor->getControlPointCount();
Shinya Kitaoka 120a6e
  // Il punto di controllo precedente non e' lincato
Shinya Kitaoka 120a6e
  if (cpEditor->isSpeedOutLinear(beforeIndex) ||
Shinya Kitaoka 120a6e
      cpEditor->isSpeedInLinear(beforeIndex) || cpEditor->isCusp(beforeIndex)) {
Shinya Kitaoka 120a6e
    if (cpEditor->isSelfLoop() && beforeIndex == 0 &&
Shinya Kitaoka 120a6e
        nextIndex == cpCount - 1)  // Nel caso selfLoop si invertono i valori
Shinya Kitaoka 120a6e
      w1 = 1;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      w0 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
          cpEditor->getIndexPointInStroke(beforeIndex));
Shinya Kitaoka 120a6e
  } else  // Punto di controllo precedente lincato
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    if (!cpEditor->isSelfLoop() || beforeIndex != 0)
Shinya Kitaoka 120a6e
      w0 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
          cpEditor->getIndexPointInStroke(beforeIndex) - 4);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      if (nextIndex == 1)  // Primo chunk
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        w0 = 0;
Shinya Kitaoka 120a6e
        q0 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
            cpEditor->getIndexPointInStroke(cpCount - 1));
Shinya Kitaoka 120a6e
        q1 = 1;
Shinya Kitaoka 120a6e
      } else if (nextIndex == cpCount - 1)  // Ultimo chunk
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        w1 = 1;
Shinya Kitaoka 120a6e
        q0 = 0;
Shinya Kitaoka 120a6e
        q1 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
            cpEditor->getIndexPointInStroke(1));
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        assert(0);
Shinya Kitaoka 120a6e
      }  // Non dovrebbe mai accadere
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // Il punto di controllo successivo non e' lincato
Shinya Kitaoka 120a6e
  if (cpEditor->isSpeedInLinear(nextIndex) ||
Shinya Kitaoka 120a6e
      cpEditor->isSpeedOutLinear(nextIndex) || cpEditor->isCusp(nextIndex)) {
Shinya Kitaoka 120a6e
    if (cpEditor->isSelfLoop() && beforeIndex == 0 &&
Shinya Kitaoka 120a6e
        nextIndex == cpCount - 1)  // Nel caso selfLoop si invertono i valori
Shinya Kitaoka 120a6e
      w0 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
          cpEditor->getIndexPointInStroke(nextIndex));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      w1 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
          cpEditor->getIndexPointInStroke(nextIndex));
Shinya Kitaoka 120a6e
  } else  // Punto di controllo successivo lincato
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    if (!cpEditor->isSelfLoop() || nextIndex != cpCount - 1 || beforeIndex != 0)
Shinya Kitaoka 120a6e
      w1 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
          cpEditor->getIndexPointInStroke(nextIndex) + 4);
Shinya Kitaoka 120a6e
    else if (nextIndex == cpCount - 1)  // Ultimo chunk
Shinya Kitaoka 120a6e
      w0 = stroke->getParameterAtControlPoint(
Shinya Kitaoka 120a6e
          cpEditor->getIndexPointInStroke(nextIndex) - 4);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      assert(0);
Shinya Kitaoka 120a6e
    }  // Non dovrebbe mai accadere, i vari casi dovrebbero essere gestiti sopra
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
pojienie 59b772
//-----------------------------------------------------------------------------
pojienie 59b772
pojienie 59b772
TPointD ControlPointEditorTool::calculateSnap(TPointD pos) {
pojienie 59b772
  m_foundSnap = false;
pojienie 59b772
  TVectorImageP vi(TTool::getImage(false));
pojienie 59b772
  TPointD snapPoint = pos;
pojienie 59b772
  if (vi && m_snap.getValue()) {
pojienie 028bea
    double minDistance = m_snapMinDistance;
pojienie 59b772
pojienie 59b772
    int i, strokeNumber = vi->getStrokeCount();
pojienie 59b772
pojienie 59b772
    TStroke *selfStroke = m_controlPointEditorStroke.getStroke();
pojienie 59b772
    TStroke *stroke;
pojienie 59b772
    double distance, outW, w;
pojienie 59b772
pojienie 59b772
    for (i = 0; i < strokeNumber; i++) {
pojienie 59b772
      stroke = vi->getStroke(i);
pojienie 028bea
      if (stroke != selfStroke) {
pojienie 59b772
        if (stroke->getNearestW(pos, outW, distance) &&
pojienie 59b772
            distance < minDistance) {
pojienie 59b772
          minDistance = distance;
pojienie 59b772
          if (areAlmostEqual(outW, 0.0, 1e-3))
pojienie 59b772
            w = 0.0;
pojienie 59b772
          else if (areAlmostEqual(outW, 1.0, 1e-3))
pojienie 59b772
            w = 1.0;
pojienie 59b772
          else
pojienie 59b772
            w = outW;
pojienie 59b772
          TThickPoint point = stroke->getPoint(w);
pojienie 028bea
          snapPoint         = TPointD(point.x, point.y);
pojienie 028bea
          m_foundSnap       = true;
pojienie 028bea
          m_snapPoint       = snapPoint;
pojienie 59b772
        }
pojienie 59b772
      }
pojienie 59b772
    }
pojienie 59b772
  }
pojienie 59b772
  return snapPoint;
pojienie 59b772
}
pojienie 59b772
pojienie 59b772
void ControlPointEditorTool::drawSnap() {
pojienie 028bea
  double thick = 6.0;
pojienie 028bea
  if (m_foundSnap) {
pojienie 028bea
    tglColor(TPixelD(0.1, 0.9, 0.1));
pojienie 028bea
    tglDrawCircle(m_snapPoint, thick);
pojienie 028bea
  }
pojienie 59b772
}
pojienie 59b772
pojienie 028bea
TPointD ControlPointEditorTool::getSnap(TPointD pos) {
pojienie 59b772
  if (m_foundSnap)
pojienie 59b772
    return m_snapPoint;
pojienie 59b772
  else
pojienie 59b772
    return pos;
pojienie 59b772
}
pojienie 59b772
pojienie 028bea
void ControlPointEditorTool::resetSnap() { m_foundSnap = false; }
pojienie 59b772
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Spline Editor Tool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ControlPointEditorTool::ControlPointEditorTool()
Shinya Kitaoka 120a6e
    : TTool("T_ControlPointEditor")
Shinya Kitaoka 120a6e
    , m_draw(false)
Shinya Kitaoka 120a6e
    , m_lastPointSelected(-1)
Shinya Kitaoka 120a6e
    , m_isImageChanged(false)
Shinya Kitaoka 120a6e
    , m_selectingRect(TRectD())
Shinya Kitaoka 120a6e
    , m_autoSelectDrawing("Auto Select Drawing", true)
pojienie c7106f
    , m_snap("snap", false)
pojienie c7106f
    , m_snapSensitivity("Sensitivity:")
pojienie 286724
    , m_selectType("Type:")
Shinya Kitaoka 120a6e
    , m_action(NONE)
Shinya Kitaoka 120a6e
    , m_cursorType(NORMAL)
Shinya Kitaoka 120a6e
    , m_undo(0)
Shinya Kitaoka 120a6e
    , m_isMenuViewed(false)
Shinya Kitaoka 120a6e
    , m_moveControlPointEditorStroke()
Shinya Kitaoka 120a6e
    , m_moveSegmentLimitation() {
Shinya Kitaoka 120a6e
  bind(TTool::Vectors);
pojienie 286724
  m_prop.bind(m_selectType);
Shinya Kitaoka 120a6e
  m_prop.bind(m_autoSelectDrawing);
pojienie 64f16d
  m_prop.bind(m_snap);
pojienie c7106f
  m_prop.bind(m_snapSensitivity);
Shinya Kitaoka 120a6e
  m_selection.setControlPointEditorStroke(&m_controlPointEditorStroke);
Shinya Kitaoka 120a6e
pojienie 286724
  m_selectType.addValue(RECTANGULAR_WSTR);
pojienie 286724
  m_selectType.addValue(FREEHAND_WSTR);
pojienie 286724
  m_selectType.setId("Type");
pojienie 286724
Shinya Kitaoka 120a6e
  m_autoSelectDrawing.setId("AutoSelectDrawing");
pojienie 64f16d
  m_snap.setId("Snap");
pojienie c7106f
  m_snapSensitivity.addValue(LOW_WSTR);
pojienie c7106f
  m_snapSensitivity.addValue(MEDIUM_WSTR);
pojienie c7106f
  m_snapSensitivity.addValue(HIGH_WSTR);
pojienie c7106f
  m_snapSensitivity.setId("SnapSensitivity");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::updateTranslation() {
Shinya Kitaoka 120a6e
  m_autoSelectDrawing.setQStringName(tr("Auto Select Drawing"));
pojienie 64f16d
  m_snap.setQStringName(tr("Snap"));
pojienie 286724
  m_selectType.setQStringName(tr("Type:"));
pojienie 286724
  m_selectType.setItemUIName(RECTANGULAR_WSTR, tr("Rectangular"));
pojienie 286724
  m_selectType.setItemUIName(FREEHAND_WSTR, tr("Freehand"));
pojienie 286724
pojienie c7106f
  m_snapSensitivity.setQStringName(tr(""));
pojienie 286724
  m_snapSensitivity.setItemUIName(LOW_WSTR, tr("Low"));
pojienie 286724
  m_snapSensitivity.setItemUIName(MEDIUM_WSTR, tr("Med"));
pojienie 286724
  m_snapSensitivity.setItemUIName(HIGH_WSTR, tr("High"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::initUndo() {
Shinya Kitaoka 120a6e
  if (TTool::getApplication()->getCurrentObject()->isSpline()) {
Shinya Kitaoka 120a6e
    m_undo =
Shinya Kitaoka 120a6e
        new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(false));
Shinya Kitaoka 120a6e
  if (!vi) return;
Shinya Kitaoka 120a6e
  TXshSimpleLevel *level =
Shinya Kitaoka 120a6e
      TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
Shinya Kitaoka 120a6e
  UndoControlPointEditor *undo =
Shinya Kitaoka 120a6e
      new UndoControlPointEditor(level, getCurrentFid());
Shinya Kitaoka 120a6e
  int index = m_controlPointEditorStroke.getStrokeIndex();
Shinya Kitaoka 120a6e
  if (index > -1) undo->addOldStroke(index, vi->getVIStroke(index));
Shinya Kitaoka 120a6e
  m_undo = undo;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::getNearestStrokeColumnIndexes(
Shinya Kitaoka 120a6e
    std::vector<int> &indexes, TPointD pos) {</int>
Shinya Kitaoka 120a6e
  TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
  TXsheet *xsh            = app->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
  int currentFrame        = app->getCurrentFrame()->getFrameIndex();
Shinya Kitaoka 120a6e
  std::vector<int> newIndexes;</int>
Shinya Kitaoka 120a6e
  TAffine aff = getMatrix();
Shinya Kitaoka 120a6e
  int i       = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)indexes.size(); i++) {
Shinya Kitaoka 120a6e
    if (xsh->getColumn(i)->isLocked()) continue;
Shinya Kitaoka 120a6e
    int index        = indexes[i];
Shinya Kitaoka 120a6e
    TVectorImageP vi = xsh->getCell(currentFrame, index).getImage(false);
Shinya Kitaoka 120a6e
    if (!vi) continue;
Shinya Kitaoka 120a6e
    double dist2, t = 0;
Shinya Kitaoka 120a6e
    UINT strokeIndex = -1;
Shinya Kitaoka 120a6e
    TPointD p        = getColumnMatrix(index).inv() * getMatrix() * pos;
Shinya Kitaoka 120a6e
    if (vi->getNearestStroke(p, t, strokeIndex, dist2) &&
Shinya Kitaoka 120a6e
        dist2 < 25 * getPixelSize() * getPixelSize())
Shinya Kitaoka 120a6e
      newIndexes.push_back(index);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  indexes.clear();
Shinya Kitaoka 120a6e
  indexes = newIndexes;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::drawMovingSegment() {
Shinya Kitaoka 120a6e
  int beforeIndex = m_moveSegmentLimitation.first;
Shinya Kitaoka 120a6e
  int nextIndex   = m_moveSegmentLimitation.second;
pojienie 286724
  if (m_action != SEGMENT_MOVEMENT || beforeIndex == -1 || nextIndex == -1 ||
Shinya Kitaoka 120a6e
      !m_moveControlPointEditorStroke.getStroke())
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  tglColor(TPixel::Green);
Shinya Kitaoka 120a6e
  double w0, w1;
Shinya Kitaoka 120a6e
  double q0, q1;
Shinya Kitaoka 120a6e
  getSegmentParameter(&m_moveControlPointEditorStroke, beforeIndex, nextIndex,
Shinya Kitaoka 120a6e
                      w0, w1, q0, q1);
Shinya Kitaoka 120a6e
  if (w0 != -1 && w1 != -1)  // Dovrebbero essere sempre diversi...
Shinya Kitaoka 120a6e
    drawStrokeCenterline(*m_moveControlPointEditorStroke.getStroke(),
Shinya Kitaoka 120a6e
                         getPixelSize(), w0, w1);
Shinya Kitaoka 120a6e
  if (q0 != -1 && q1 != -1)
Shinya Kitaoka 120a6e
    drawStrokeCenterline(*m_moveControlPointEditorStroke.getStroke(),
Shinya Kitaoka 120a6e
                         getPixelSize(), q0, q1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::drawControlPoint() {
Shinya Kitaoka 120a6e
  TPixel color1         = TPixel(79, 128, 255);
Shinya Kitaoka 120a6e
  TPixel color2         = TPixel::White;
Shinya Kitaoka 120a6e
  TPixel color_handle   = TPixel(96, 64, 201);
Shinya Kitaoka 120a6e
  int controlPointCount = m_controlPointEditorStroke.getControlPointCount();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double pix    = getPixelSize() * 2.0f;
Shinya Kitaoka 120a6e
  double pix1_5 = 1.5 * pix, pix2 = pix + pix, pix2_5 = pix1_5 + pix,
Shinya Kitaoka 120a6e
         pix3 = pix2 + pix, pix3_5 = pix2_5 + pix, pix4 = pix3 + pix;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double maxDist2 = sq(5.0 * pix);
Shinya Kitaoka 120a6e
  double dist2    = 0;
Shinya Kitaoka 120a6e
  int pointIndex;
Shinya Kitaoka 120a6e
  ControlPointEditorStroke::PointType pointType =
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.getPointTypeAt(m_pos, maxDist2, pointIndex);
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < controlPointCount; i++) {
Shinya Kitaoka 120a6e
    TThickPoint point = m_controlPointEditorStroke.getControlPoint(i);
Shinya Kitaoka 120a6e
    TPointD pa        = m_controlPointEditorStroke.getSpeedInPoint(i);
Shinya Kitaoka 120a6e
    TPointD pb        = m_controlPointEditorStroke.getSpeedOutPoint(i);
Shinya Kitaoka 120a6e
    tglColor(color_handle);
Shinya Kitaoka 120a6e
    tglDrawSegment(pa, point);
Shinya Kitaoka 120a6e
    if (i == pointIndex && pointType == ControlPointEditorStroke::SPEED_IN)
Shinya Kitaoka 120a6e
      tglFillRect(pa.x - pix2_5, pa.y - pix2_5, pa.x + pix2_5, pa.y + pix2_5);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      tglFillRect(pa.x - pix1_5, pa.y - pix1_5, pa.x + pix1_5, pa.y + pix1_5);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    tglDrawSegment(pb, point);
Shinya Kitaoka 120a6e
    if (i == pointIndex && pointType == ControlPointEditorStroke::SPEED_OUT)
Shinya Kitaoka 120a6e
      tglFillRect(pb.x - pix2_5, pb.y - pix2_5, pb.x + pix2_5, pb.y + pix2_5);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      tglFillRect(pb.x - pix1_5, pb.y - pix1_5, pb.x + pix1_5, pb.y + pix1_5);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    tglColor(color1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (i == pointIndex &&
Shinya Kitaoka 120a6e
        pointType == ControlPointEditorStroke::CONTROL_POINT) {
Shinya Kitaoka 120a6e
      tglFillRect(point.x - pix3_5, point.y - pix3_5, point.x + pix3_5,
Shinya Kitaoka 120a6e
                  point.y + pix3_5);
Shinya Kitaoka 120a6e
      if (!m_selection.isSelected(i)) {
Shinya Kitaoka 120a6e
        tglColor(color2);
Shinya Kitaoka 120a6e
        tglFillRect(point.x - pix2_5, point.y - pix2_5, point.x + pix2_5,
Shinya Kitaoka 120a6e
                    point.y + pix2_5);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      tglFillRect(point.x - pix2, point.y - pix2, point.x + pix2,
Shinya Kitaoka 120a6e
                  point.y + pix2);
Shinya Kitaoka 120a6e
      if (!m_selection.isSelected(i)) {
Shinya Kitaoka 120a6e
        tglColor(color2);
Shinya Kitaoka 120a6e
        tglFillRect(point.x - pix, point.y - pix, point.x + pix, point.y + pix);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::draw() {
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(false));
Shinya Kitaoka 120a6e
  if (!m_draw) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int currentStroke = m_controlPointEditorStroke.getStrokeIndex();
Shinya Kitaoka 120a6e
  if (!vi || currentStroke == -1 ||
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.getControlPointCount() == 0 ||
Shinya Kitaoka 120a6e
      vi->getStrokeCount() == 0 || (int)vi->getStrokeCount() <= currentStroke) {
Shinya Kitaoka 120a6e
    m_controlPointEditorStroke.setStroke((TVectorImage *)0, -1);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPixel color1, color2;
Shinya Kitaoka 120a6e
  if (m_action == RECT_SELECTION)  // Disegna il rettangolo per la selezione
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    color1 = TPixel32::
Shinya Kitaoka 120a6e
        Black;  // TransparencyCheck::instance()->isEnabled()?TPixel32::White:TPixel32::Black;
Shinya Kitaoka 120a6e
    drawRect(m_selectingRect, color1, 0x3F33, true);
pojienie 286724
  } else if (m_action == FREEHAND_SELECTION && !m_track.isEmpty()) {
pojienie 286724
    TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
pojienie 286724
                       ? TPixel32::White
pojienie 286724
                       : TPixel32::Black;
pojienie 286724
    tglColor(color);
pojienie 286724
    m_track.drawAllFragments();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_controlPointEditorStroke.getControlPointCount() <= 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  color1          = TPixel(79, 128, 255);
Shinya Kitaoka 120a6e
  color2          = TPixel::White;
Shinya Kitaoka 120a6e
  TStroke *stroke = m_controlPointEditorStroke.getStroke();
Shinya Kitaoka 120a6e
  tglColor(color1);
Shinya Kitaoka 120a6e
  drawStrokeCenterline(*stroke, getPixelSize());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  drawControlPoint();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  drawMovingSegment();
pojienie 59b772
pojienie 59b772
  drawSnap();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::mouseMove(const TPointD &pos,
Shinya Kitaoka 120a6e
                                       const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  // Scelgo il cursore in base alla distanza del mouse dalla curva e dai punti
Shinya Kitaoka 120a6e
  // di controllo
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(false));
Shinya Kitaoka 120a6e
  if (!vi) {
Shinya Kitaoka 120a6e
    m_controlPointEditorStroke.setStroke((TVectorImage *)0, -1);
Shinya Kitaoka 120a6e
    m_cursorType = NO_ACTIVE;
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    m_cursorType = NORMAL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_pos = pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_draw || m_controlPointEditorStroke.getStrokeIndex() == -1) return;
Shinya Kitaoka 120a6e
  if (e.isAltPressed())
Shinya Kitaoka 120a6e
    m_cursorType = EDIT_SPEED;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    double maxDist  = 5 * getPixelSize();
Shinya Kitaoka 120a6e
    double maxDist2 = maxDist * maxDist;
Shinya Kitaoka 120a6e
    int pointIndexCP;
Shinya Kitaoka 120a6e
    ControlPointEditorStroke::PointType pointType =
Shinya Kitaoka 120a6e
        m_controlPointEditorStroke.getPointTypeAt(pos, maxDist2, pointIndexCP);
Shinya Kitaoka 120a6e
    if (pointType == ControlPointEditorStroke::SEGMENT && e.isCtrlPressed())
Shinya Kitaoka 120a6e
      m_cursorType = ADD;
Shinya Kitaoka 120a6e
    // else if(pointType == ControlPointEditorStroke::SEGMENT)
Shinya Kitaoka 120a6e
    // m_cursorType=EDIT_SEGMENT;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_cursorType = NORMAL;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::leftButtonDown(const TPointD &pos,
Shinya Kitaoka 120a6e
                                            const TMouseEvent &e) {
manongjohn 40a40e
  if (getViewer() && getViewer()->getGuidedStrokePickerMode()) {
manongjohn 40a40e
    getViewer()->doPickGuideStroke(pos);
manongjohn 40a40e
    return;
manongjohn 40a40e
  }
manongjohn 40a40e
Shinya Kitaoka 120a6e
  m_pos           = pos;
Martin van Zijl a07bd0
  double pix      = getPixelSize() * 2.0f;
Martin van Zijl a07bd0
  double maxDist  = 5 * pix;
Shinya Kitaoka 120a6e
  double maxDist2 = maxDist * maxDist;
Shinya Kitaoka 120a6e
  double dist2    = 0;
Shinya Kitaoka 120a6e
  int pointIndex;
Shinya Kitaoka 120a6e
  ControlPointEditorStroke::PointType pointType =
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.getPointTypeAt(pos, maxDist2, pointIndex);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (pointType == ControlPointEditorStroke::NONE) {
Shinya Kitaoka 120a6e
    // ho cliccato lontano dalla curva corrente
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    if (m_autoSelectDrawing.getValue()) {
Shinya Kitaoka 120a6e
      // Non sono in nessun gadget
Shinya Kitaoka 120a6e
      std::vector<int> columnIndexes;</int>
shun-iwasawa 2d0135
      getViewer()->posToColumnIndexes(e.m_pos, columnIndexes, 5.0, false);
Shinya Kitaoka 120a6e
      getNearestStrokeColumnIndexes(columnIndexes, pos);
Shinya Kitaoka 120a6e
      if (!columnIndexes.empty()) {
Shinya Kitaoka 120a6e
        int currentColumnIndex = app->getCurrentColumn()->getColumnIndex();
Shinya Kitaoka 120a6e
        int columnIndex;
Shinya Kitaoka 120a6e
        if (columnIndexes.size() == 1)
Shinya Kitaoka 120a6e
          columnIndex = columnIndexes[0];
Shinya Kitaoka 120a6e
        else {
Shinya Kitaoka 120a6e
          ToolUtils::ColumChooserMenu *menu = new ToolUtils::ColumChooserMenu(
Shinya Kitaoka 120a6e
              app->getCurrentXsheet()->getXsheet(), columnIndexes);
Shinya Kitaoka 120a6e
          m_isMenuViewed = true;
Shinya Kitaoka 120a6e
          columnIndex    = menu->execute();
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        TXshColumn *column =
Shinya Kitaoka 120a6e
            app->getCurrentXsheet()->getXsheet()->getColumn(columnIndex);
Shinya Kitaoka 120a6e
        if (columnIndex >= 0 && columnIndex != currentColumnIndex && column &&
Shinya Kitaoka 120a6e
            !column->isLocked()) {
Shinya Kitaoka 120a6e
          TAffine aff = getMatrix();
Shinya Kitaoka 120a6e
          app->getCurrentColumn()->setColumnIndex(columnIndex);
Shinya Kitaoka 120a6e
          updateMatrix();
Shinya Kitaoka 120a6e
          currentColumnIndex = columnIndex;
Shinya Kitaoka 120a6e
          m_pos              = getMatrix().inv() * aff * pos;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TVectorImageP vi = getImage(false);
Shinya Kitaoka 120a6e
    if (!vi) return;
Shinya Kitaoka 120a6e
    double dist2, t = 0;
Shinya Kitaoka 120a6e
    UINT index = -1;
Shinya Kitaoka 120a6e
    if (vi->getNearestStroke(m_pos, t, index, dist2) &&
Shinya Kitaoka 120a6e
        dist2 < 25 * getPixelSize() * getPixelSize()) {
Shinya Kitaoka 120a6e
      // ho cliccato vicino alla curva index-esima
Shinya Kitaoka 120a6e
      assert(0 <= index && index < vi->getStrokeCount());
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.setStroke(vi, index);
Shinya Kitaoka 120a6e
      m_action = NONE;
Shinya Kitaoka 120a6e
      m_selection.makeCurrent();
Shinya Kitaoka 120a6e
    } else {
pojienie 286724
      if (m_selectType.getValue() == RECTANGULAR_WSTR) {
pojienie 286724
        m_action        = RECT_SELECTION;
pojienie 286724
        m_selectingRect = TRectD(m_pos.x, m_pos.y, m_pos.x + 1, m_pos.y + 1);
pojienie 286724
        if (m_selectingRect.x0 > m_selectingRect.x1)
pojienie 286724
          std::swap(m_selectingRect.x1, m_selectingRect.x0);
pojienie 286724
        if (m_selectingRect.y0 > m_selectingRect.y1)
pojienie 286724
          std::swap(m_selectingRect.y1, m_selectingRect.y0);
pojienie 286724
pojienie 286724
      } else if (m_selectType.getValue() == FREEHAND_WSTR) {
pojienie 286724
        m_action = FREEHAND_SELECTION;
pojienie 286724
        startFreehand(pos);
pojienie 286724
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_selection.selectNone();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TVectorImageP vi = getImage(true);
Shinya Kitaoka 120a6e
  if (!vi) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (pointType == ControlPointEditorStroke::SPEED_IN ||
Shinya Kitaoka 120a6e
      pointType == ControlPointEditorStroke::SPEED_OUT) {
Shinya Kitaoka 120a6e
    bool isIn = pointType == ControlPointEditorStroke::SPEED_IN;
Shinya Kitaoka 120a6e
    m_selection.selectNone();
Shinya Kitaoka 120a6e
    m_selection.select(pointIndex);
Shinya Kitaoka 120a6e
    m_action = isIn ? IN_SPEED_MOVEMENT : OUT_SPEED_MOVEMENT;
Shinya Kitaoka 120a6e
    if (e.isAltPressed()) {
Shinya Kitaoka 120a6e
      initUndo();
Shinya Kitaoka 120a6e
      if (m_controlPointEditorStroke.isCusp(pointIndex))
Shinya Kitaoka 120a6e
        linkSpeedInOut(pointIndex);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        unlinkSpeedInOut(pointIndex);
Shinya Kitaoka 120a6e
      TUndoManager::manager()->add(m_undo);
Shinya Kitaoka 120a6e
      m_undo = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_selection.makeCurrent();
Shinya Kitaoka 120a6e
  } else if (pointType == ControlPointEditorStroke::CONTROL_POINT) {
Shinya Kitaoka 120a6e
    if (e.isAltPressed()) {
pojienie ecfe73
      m_action = NONE;
Shinya Kitaoka 120a6e
      m_selection.selectNone();
Shinya Kitaoka 120a6e
      m_selection.select(pointIndex);
Shinya Kitaoka 120a6e
      initUndo();
Shinya Kitaoka 120a6e
      bool isSpeedIn  = m_controlPointEditorStroke.isSpeedInLinear(pointIndex);
Shinya Kitaoka 120a6e
      bool isSpeedOut = m_controlPointEditorStroke.isSpeedOutLinear(pointIndex);
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.setLinear(pointIndex,
Shinya Kitaoka 120a6e
                                           !isSpeedIn && !isSpeedOut);
Shinya Kitaoka 120a6e
      TUndoManager::manager()->add(m_undo);
Shinya Kitaoka 120a6e
      m_undo = 0;
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (e.isCtrlPressed()) {
Shinya Kitaoka 120a6e
      if (m_selection.isSelected(pointIndex))
Shinya Kitaoka 120a6e
        m_selection.unselect(pointIndex);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_selection.select(pointIndex);
Shinya Kitaoka 120a6e
    } else if (m_selection.isEmpty() || !m_selection.isSelected(pointIndex)) {
Shinya Kitaoka 120a6e
      m_selection.selectNone();
Shinya Kitaoka 120a6e
      m_selection.select(pointIndex);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_lastPointSelected = pointIndex;
Shinya Kitaoka 120a6e
    m_action            = CP_MOVEMENT;
Shinya Kitaoka 120a6e
    m_selection.makeCurrent();
Shinya Kitaoka 120a6e
  } else if (pointType == ControlPointEditorStroke::SEGMENT &&
Shinya Kitaoka 120a6e
             !e.isAltPressed()) {
Shinya Kitaoka 120a6e
    m_selection.selectNone();
Shinya Kitaoka 120a6e
    if (e.isCtrlPressed()) {
Shinya Kitaoka 120a6e
      // Aggiungo un punto
Shinya Kitaoka 120a6e
      initUndo();
Shinya Kitaoka 120a6e
      pointIndex = m_controlPointEditorStroke.addControlPoint(pos);
Shinya Kitaoka 120a6e
      m_selection.select(pointIndex);
Shinya Kitaoka 120a6e
      m_action = CP_MOVEMENT;
Shinya Kitaoka 120a6e
      TUndoManager::manager()->add(m_undo);
Shinya Kitaoka 120a6e
      m_lastPointSelected = -1;
Shinya Kitaoka 120a6e
      notifyImageChanged();
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      // Inizio a muovere la curva
Shinya Kitaoka 120a6e
      int precPointIndex, nextPointIndex;
Shinya Kitaoka 120a6e
      precPointIndex = pointIndex;
Shinya Kitaoka 120a6e
      nextPointIndex =
Shinya Kitaoka 120a6e
          (m_controlPointEditorStroke.isSelfLoop() &&
Shinya Kitaoka 120a6e
           precPointIndex ==
Shinya Kitaoka 120a6e
               m_controlPointEditorStroke.getControlPointCount() - 1)
Shinya Kitaoka 120a6e
              ? 0
Shinya Kitaoka 120a6e
              : precPointIndex + 1;
Shinya Kitaoka 120a6e
      if (precPointIndex > -1 && nextPointIndex > -1) {
Shinya Kitaoka 120a6e
        if (precPointIndex > nextPointIndex)
otakuto ed7dcd
          std::swap(precPointIndex, nextPointIndex);
Shinya Kitaoka 120a6e
        m_moveSegmentLimitation.first  = precPointIndex;
Shinya Kitaoka 120a6e
        m_moveSegmentLimitation.second = nextPointIndex;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      m_moveControlPointEditorStroke = *m_controlPointEditorStroke.clone();
Shinya Kitaoka 120a6e
      // Se e' premuto shift setto a cusp i due punti di controllo che
Shinya Kitaoka 120a6e
      // delimitano il segmento.
Shinya Kitaoka 120a6e
      if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
        if (!m_controlPointEditorStroke.isCusp(precPointIndex)) {
Shinya Kitaoka 120a6e
          m_controlPointEditorStroke.setCusp(precPointIndex, true, false);
Shinya Kitaoka 120a6e
          m_moveControlPointEditorStroke.setCusp(precPointIndex, true, false);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        if (!m_controlPointEditorStroke.isCusp(nextPointIndex)) {
Shinya Kitaoka 120a6e
          m_controlPointEditorStroke.setCusp(nextPointIndex, true, true);
Shinya Kitaoka 120a6e
          m_moveControlPointEditorStroke.setCusp(nextPointIndex, true, true);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      m_action = SEGMENT_MOVEMENT;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_selection.makeCurrent();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int currentStroke = m_controlPointEditorStroke.getStrokeIndex();
Shinya Kitaoka 120a6e
  if (currentStroke != -1) initUndo();
Shinya Kitaoka 120a6e
  invalidate();
Shinya Kitaoka 120a6e
  m_isImageChanged = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::rightButtonDown(const TPointD &pos,
Shinya Kitaoka 120a6e
                                             const TMouseEvent &) {
Shinya Kitaoka 120a6e
  TVectorImageP vi = getImage(true);
Shinya Kitaoka 120a6e
  if (!vi) return;
Shinya Kitaoka 120a6e
  double maxDist  = 5 * getPixelSize();
Shinya Kitaoka 120a6e
  double maxDist2 = maxDist * maxDist;
Shinya Kitaoka 120a6e
  double dist2    = 0;
Shinya Kitaoka 120a6e
  int pointIndex;
Shinya Kitaoka 120a6e
  ControlPointEditorStroke::PointType pointType =
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.getPointTypeAt(pos, maxDist2, pointIndex);
Shinya Kitaoka 120a6e
  if (pointType != ControlPointEditorStroke::CONTROL_POINT) return;
Shinya Kitaoka 120a6e
  m_selection.select(pointIndex);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::moveControlPoints(const TPointD &delta) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  int cpCount = m_controlPointEditorStroke.getControlPointCount();
Shinya Kitaoka 120a6e
  for (i = 0; i < cpCount; i++)
Shinya Kitaoka 120a6e
    if (m_selection.isSelected(i))
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.moveControlPoint(i, delta);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::moveSpeed(const TPointD &delta, bool isIn) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_controlPointEditorStroke.getControlPointCount(); i++)
Shinya Kitaoka 120a6e
    if (m_selection.isSelected(i))
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.moveSpeed(i, delta, isIn, 4 * getPixelSize());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::moveSegment(const TPointD &delta, bool dragging,
Shinya Kitaoka 120a6e
                                         bool isShiftPressed) {
Shinya Kitaoka 120a6e
  int beforeIndex = m_moveSegmentLimitation.first;
Shinya Kitaoka 120a6e
  int nextIndex   = m_moveSegmentLimitation.second;
Shinya Kitaoka 120a6e
  // Se e' premuto shift setto a cusp i due punti di controllo che delimitano il
Shinya Kitaoka 120a6e
  // segmento.
Shinya Kitaoka 120a6e
  if (isShiftPressed) {
Shinya Kitaoka 120a6e
    if (!m_controlPointEditorStroke.isCusp(beforeIndex)) {
Shinya Kitaoka 120a6e
      if (dragging)
Shinya Kitaoka 120a6e
        m_moveControlPointEditorStroke.setCusp(beforeIndex, true, false);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_controlPointEditorStroke.setCusp(beforeIndex, true, false);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (!m_controlPointEditorStroke.isCusp(nextIndex)) {
Shinya Kitaoka 120a6e
      if (dragging)
Shinya Kitaoka 120a6e
        m_moveControlPointEditorStroke.setCusp(nextIndex, true, true);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_controlPointEditorStroke.setCusp(nextIndex, true, true);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (dragging)
Shinya Kitaoka 120a6e
    m_moveControlPointEditorStroke.moveSegment(beforeIndex, nextIndex, delta,
Shinya Kitaoka 120a6e
                                               m_pos);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_controlPointEditorStroke.moveSegment(beforeIndex, nextIndex, delta,
Shinya Kitaoka 120a6e
                                           m_pos);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::leftButtonDrag(const TPointD &pos,
Shinya Kitaoka 120a6e
                                            const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(true));
Shinya Kitaoka 120a6e
  int currentStroke = m_controlPointEditorStroke.getStrokeIndex();
Shinya Kitaoka 120a6e
  if (!vi || currentStroke == -1 || m_action == NONE) return;
Shinya Kitaoka 120a6e
  QMutexLocker lock(vi->getMutex());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD delta = pos - m_pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_action == CP_MOVEMENT) {
Shinya Kitaoka 120a6e
    if (!m_selection.isSelected(m_lastPointSelected) && e.isCtrlPressed())
Shinya Kitaoka 120a6e
      m_selection.select(m_lastPointSelected);  // Controllo che non venga
Shinya Kitaoka 120a6e
                                                // deselezionata l'ultima
Shinya Kitaoka 120a6e
                                                // selezione nel movimento
pojienie 59b772
pojienie 3379cf
    if (m_lastPointSelected >= 0) {
pojienie 3379cf
      TThickPoint cp;
pojienie 3379cf
      TPointD controlPoint;
pojienie 3379cf
      TPointD newPos;
pojienie 3379cf
pojienie 3379cf
      cp = m_controlPointEditorStroke.getControlPoint(m_lastPointSelected);
pojienie 3379cf
      controlPoint = TPointD(cp.x, cp.y);
pojienie 3379cf
      newPos       = calculateSnap(pos);
pojienie 3379cf
      delta        = newPos - m_pos + (m_pos - controlPoint);
pojienie 3379cf
    }
pojienie 59b772
pojienie 59b772
    m_pos = pos;
pojienie 59b772
Shinya Kitaoka 120a6e
    moveControlPoints(delta);
Shinya Kitaoka 120a6e
    m_isImageChanged = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_action == SEGMENT_MOVEMENT) {
Shinya Kitaoka 120a6e
    m_moveControlPointEditorStroke = *m_controlPointEditorStroke.clone();
Shinya Kitaoka 120a6e
    moveSegment(delta, true, e.isShiftPressed());
Shinya Kitaoka 120a6e
    m_isImageChanged = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_action == OUT_SPEED_MOVEMENT || m_action == IN_SPEED_MOVEMENT) {
Shinya Kitaoka 120a6e
    m_pos = pos;
Shinya Kitaoka 120a6e
    moveSpeed(delta, m_action == IN_SPEED_MOVEMENT);
Shinya Kitaoka 120a6e
    m_isImageChanged = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_action == RECT_SELECTION) {
Shinya Kitaoka 120a6e
    int cpCount        = m_controlPointEditorStroke.getControlPointCount();
Shinya Kitaoka 120a6e
    m_selectingRect.x0 = m_pos.x;
Shinya Kitaoka 120a6e
    m_selectingRect.y0 = m_pos.y;
Shinya Kitaoka 120a6e
    m_selectingRect.x1 = pos.x;
Shinya Kitaoka 120a6e
    m_selectingRect.y1 = pos.y;
Shinya Kitaoka 120a6e
    if (m_selectingRect.x0 > m_selectingRect.x1)
otakuto ed7dcd
      std::swap(m_selectingRect.x1, m_selectingRect.x0);
Shinya Kitaoka 120a6e
    if (m_selectingRect.y0 > m_selectingRect.y1)
otakuto ed7dcd
      std::swap(m_selectingRect.y1, m_selectingRect.y0);
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    m_selection.selectNone();
Shinya Kitaoka 120a6e
    for (i = 0; i < cpCount; i++)
Shinya Kitaoka 120a6e
      if (m_selectingRect.contains(
Shinya Kitaoka 120a6e
              m_controlPointEditorStroke.getControlPoint(i)))
Shinya Kitaoka 120a6e
        m_selection.select(i);
pojienie 286724
  } else if (m_action == FREEHAND_SELECTION) {
pojienie 286724
    freehandDrag(pos);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
pojienie 286724
void ControlPointEditorTool::selectRegion(TStroke *stroke) {
pojienie 286724
  int cpCount = m_controlPointEditorStroke.getControlPointCount();
pojienie 286724
pojienie 286724
  TVectorImage img;
pojienie 286724
  img.addStroke(stroke);
pojienie 286724
  img.findRegions();
pojienie 286724
  for (int rI = 0; rI < (int)img.getRegionCount(); rI++) {
pojienie 286724
    TRegion *region = img.getRegion(rI);
pojienie 286724
    for (int i = 0; i < cpCount; i++) {
pojienie 286724
      if (region->contains(m_controlPointEditorStroke.getControlPoint(i))) {
pojienie 286724
        m_selection.select(i);
pojienie 286724
      }
pojienie 286724
    }
pojienie 286724
  }
pojienie 286724
}
pojienie 286724
pojienie 286724
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
pojienie 59b772
void ControlPointEditorTool::leftButtonUp(const TPointD &realPos,
Shinya Kitaoka 120a6e
                                          const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(true));
Shinya Kitaoka 120a6e
  int currentStroke = m_controlPointEditorStroke.getStrokeIndex();
Shinya Kitaoka 120a6e
  if (!vi || currentStroke == -1) return;
Shinya Kitaoka 120a6e
  QMutexLocker lock(vi->getMutex());
Shinya Kitaoka 120a6e
pojienie 59b772
  TPointD pos;
pojienie 59b772
  pos = getSnap(realPos);
pojienie 59b772
  resetSnap();
pojienie 59b772
pojienie 286724
  if (m_action == SEGMENT_MOVEMENT) {
Shinya Kitaoka 120a6e
    m_moveControlPointEditorStroke.setStroke((TVectorImage *)0, -1);
Shinya Kitaoka 120a6e
    TPointD delta = pos - m_pos;
Shinya Kitaoka 120a6e
    moveSegment(delta, false, e.isShiftPressed());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
pojienie 286724
  if (m_action == RECT_SELECTION || m_action == FREEHAND_SELECTION) {
pojienie 286724
    if (m_action == FREEHAND_SELECTION) {
pojienie 286724
      closeFreehand(pos);
pojienie 286724
      selectRegion(m_stroke);
pojienie 286724
      m_track.clear();
pojienie 286724
    }
pojienie 286724
Shinya Kitaoka 120a6e
    if (m_selection.isEmpty()) {
Shinya Kitaoka 120a6e
      // Non ho selezionato nulla
Shinya Kitaoka 120a6e
      if (!TTool::getApplication()
Shinya Kitaoka 120a6e
               ->getCurrentObject()
Shinya Kitaoka 120a6e
               ->isSpline())  // se non e' una spline deseleziono
Shinya Kitaoka 120a6e
        m_controlPointEditorStroke.setStroke((TVectorImage *)0, -1);
Shinya Kitaoka 120a6e
      m_action         = NONE;
Shinya Kitaoka 120a6e
      m_isImageChanged = false;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_action = CP_MOVEMENT;
Shinya Kitaoka 120a6e
      m_selection.makeCurrent();
Shinya Kitaoka 120a6e
      m_isImageChanged = false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_action == NONE || !m_isImageChanged) {
Shinya Kitaoka 120a6e
    m_undo = 0;
Shinya Kitaoka 120a6e
    invalidate();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  notifyImageChanged();
Shinya Kitaoka 120a6e
  invalidate();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Registro l'UNDO
Shinya Kitaoka 120a6e
  if (m_undo) {
Shinya Kitaoka 120a6e
    TUndoManager::manager()->add(m_undo);
Shinya Kitaoka 120a6e
    m_undo = 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::addContextMenuItems(QMenu *menu) {
Shinya Kitaoka 120a6e
  m_isMenuViewed = true;
Shinya Kitaoka 120a6e
  m_selection.addMenuItems(menu);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::linkSpeedInOut(int index) {
Shinya Kitaoka 120a6e
  if ((index == 0 ||
Shinya Kitaoka 120a6e
       index == m_controlPointEditorStroke.getControlPointCount() - 1) &&
Shinya Kitaoka 120a6e
      !m_controlPointEditorStroke.isSelfLoop())
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  if (m_action == IN_SPEED_MOVEMENT || m_action == CP_MOVEMENT)
Shinya Kitaoka 120a6e
    m_controlPointEditorStroke.setCusp(index, false, true);
Shinya Kitaoka 120a6e
  if (m_action == OUT_SPEED_MOVEMENT)
Shinya Kitaoka 120a6e
    m_controlPointEditorStroke.setCusp(index, false, false);
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::unlinkSpeedInOut(int pointIndex) {
Shinya Kitaoka 120a6e
  m_controlPointEditorStroke.setCusp(pointIndex, true, true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 7f1e30
bool ControlPointEditorTool::keyDown(QKeyEvent *event) {
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(true));
Shinya Kitaoka 120a6e
  if (!vi || (vi && m_selection.isEmpty())) return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD delta;
shun-iwasawa 7f1e30
  switch (event->key()) {
shun-iwasawa 7f1e30
  case Qt::Key_Up:
Shinya Kitaoka 120a6e
    delta.y = 1;
shun-iwasawa 7f1e30
    break;
shun-iwasawa 7f1e30
  case Qt::Key_Down:
Shinya Kitaoka 120a6e
    delta.y = -1;
shun-iwasawa 7f1e30
    break;
shun-iwasawa 7f1e30
  case Qt::Key_Left:
Shinya Kitaoka 120a6e
    delta.x = -1;
shun-iwasawa 7f1e30
    break;
shun-iwasawa 7f1e30
  case Qt::Key_Right:
Shinya Kitaoka 120a6e
    delta.x = 1;
shun-iwasawa 7f1e30
    break;
shun-iwasawa 7f1e30
  default:
Shinya Kitaoka 120a6e
    return false;
shun-iwasawa 7f1e30
    break;
shun-iwasawa 7f1e30
  }
shun-iwasawa 0842da
  // Inizializzo l'UNDO
shun-iwasawa 0842da
  initUndo();
shun-iwasawa 0842da
Shinya Kitaoka 120a6e
  moveControlPoints(delta);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  invalidate();
Shinya Kitaoka 120a6e
  // Registro l'UNDO
Shinya Kitaoka 120a6e
  TUndoManager::manager()->add(m_undo);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::onEnter() {
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(false));
Shinya Kitaoka 120a6e
  int currentStroke = m_controlPointEditorStroke.getStrokeIndex();
Shinya Kitaoka 120a6e
  if (m_isMenuViewed) {
Shinya Kitaoka 120a6e
    m_isMenuViewed = false;
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*m_draw=true;
Shinya Kitaoka 120a6e
  if(currentStroke==-1 || !vi)
Shinya Kitaoka 120a6e
          return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_controlPointEditorStroke.setStroke((TVectorImage*)0, -1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
if(TTool::getApplication()->getCurrentObject()->isSpline())
Shinya Kitaoka 120a6e
          m_controlPointEditorStroke.setStroke(vi, 0);*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::onLeave() {
Shinya Kitaoka 120a6e
  if (m_isMenuViewed) return;
Shinya Kitaoka 120a6e
  // m_draw=false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ControlPointEditorTool::onPropertyChanged(std::string propertyName) {
pojienie 286724
  CPSelectionType   = ::to_string(m_selectType.getValue());
Shinya Kitaoka 120a6e
  AutoSelectDrawing = (int)(m_autoSelectDrawing.getValue());
pojienie 028bea
  Snap              = (int)(m_snap.getValue());
pojienie 028bea
  SnapSensitivity   = (int)(m_snapSensitivity.getIndex());
pojienie c6cb30
  switch (SnapSensitivity) {
pojienie c6cb30
  case 0:
pojienie c6cb30
    m_snapMinDistance = SNAPPING_LOW;
pojienie c6cb30
    break;
pojienie c6cb30
  case 1:
pojienie c6cb30
    m_snapMinDistance = SNAPPING_MEDIUM;
pojienie c6cb30
    break;
pojienie c6cb30
  case 2:
pojienie c6cb30
    m_snapMinDistance = SNAPPING_HIGH;
pojienie c6cb30
    break;
pojienie c6cb30
  }
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::onActivate() {
Shinya Kitaoka 120a6e
  // TODO: getApplication()->editImageOrSpline();
pojienie 286724
  m_selectType.setValue(::to_wstring(CPSelectionType.getValue()));
Shinya Kitaoka 120a6e
  m_autoSelectDrawing.setValue(AutoSelectDrawing ? 1 : 0);
pojienie 2979a2
  m_snap.setValue(Snap ? 1 : 0);
pojienie 2979a2
  m_snapSensitivity.setIndex(SnapSensitivity);
pojienie c6cb30
  switch (SnapSensitivity) {
pojienie c6cb30
  case 0:
pojienie c6cb30
    m_snapMinDistance = SNAPPING_LOW;
pojienie c6cb30
    break;
pojienie c6cb30
  case 1:
pojienie c6cb30
    m_snapMinDistance = SNAPPING_MEDIUM;
pojienie c6cb30
    break;
pojienie c6cb30
  case 2:
pojienie c6cb30
    m_snapMinDistance = SNAPPING_HIGH;
pojienie c6cb30
    break;
pojienie c6cb30
  }
Shinya Kitaoka 120a6e
  m_controlPointEditorStroke.setStroke((TVectorImage *)0, -1);
Shinya Kitaoka 120a6e
  m_draw = true;
pojienie 59b772
  resetSnap();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::onDeactivate() { m_draw = false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ControlPointEditorTool::onImageChanged() {
Shinya Kitaoka 120a6e
  TVectorImageP vi(getImage(false));
Shinya Kitaoka 120a6e
  if (!vi) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int currentStroke = m_controlPointEditorStroke.getStrokeIndex();
Shinya Kitaoka 120a6e
  if (!vi || currentStroke == -1 ||
Shinya Kitaoka 120a6e
      m_controlPointEditorStroke.getControlPointCount() == 0 ||
Shinya Kitaoka 120a6e
      vi->getStrokeCount() == 0 || (int)vi->getStrokeCount() <= currentStroke) {
Shinya Kitaoka 120a6e
    m_controlPointEditorStroke.setStroke((TVectorImage *)0, -1);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else {
shun-iwasawa 0842da
    if (m_controlPointEditorStroke.setStroke(vi, currentStroke))
shun-iwasawa 0842da
      m_selection.selectNone();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int ControlPointEditorTool::getCursorId() const {
manongjohn 40a40e
  if (m_viewer && m_viewer->getGuidedStrokePickerMode())
manongjohn 40a40e
    return m_viewer->getGuidedStrokePickerCursor();
manongjohn 40a40e
Shinya Kitaoka 120a6e
  switch (m_cursorType) {
Shinya Kitaoka 120a6e
  case NORMAL:
Shinya Kitaoka 120a6e
    return ToolCursor::SplineEditorCursor;
Shinya Kitaoka 120a6e
  case ADD:
Shinya Kitaoka 120a6e
    return ToolCursor::SplineEditorCursorAdd;
Shinya Kitaoka 120a6e
  case EDIT_SPEED:
Shinya Kitaoka 120a6e
    return ToolCursor::SplineEditorCursorSelect;
Shinya Kitaoka 120a6e
  case EDIT_SEGMENT:
Shinya Kitaoka 120a6e
    return ToolCursor::PinchCursor;
Shinya Kitaoka 120a6e
  case NO_ACTIVE:
Shinya Kitaoka 120a6e
    return ToolCursor::CURSOR_NO;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    return ToolCursor::SplineEditorCursor;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun_iwasawa d51821
//-----------------------------------------------------------------------------
shun_iwasawa d51821
shun_iwasawa d51821
// returns true if the pressed key is recognized and processed in the tool
shun_iwasawa d51821
// instead of triggering the shortcut command.
shun_iwasawa d51821
bool ControlPointEditorTool::isEventAcceptable(QEvent *e) {
shun_iwasawa d51821
  if (!isEnabled()) return false;
shun_iwasawa d51821
  TVectorImageP vi(getImage(false));
shun_iwasawa d51821
  if (!vi || (vi && m_selection.isEmpty())) return false;
shun_iwasawa d51821
  // arrow keys will be used for moving the selected points
shun_iwasawa d51821
  QKeyEvent *keyEvent = static_cast<qkeyevent *="">(e);</qkeyevent>
shun_iwasawa d51821
  // shift + arrow will not be recognized for now
shun_iwasawa d51821
  if (keyEvent->modifiers() & Qt::ShiftModifier) return false;
shun_iwasawa d51821
  int key = keyEvent->key();
shun_iwasawa d51821
  return (key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Left ||
shun_iwasawa d51821
          key == Qt::Key_Right);
shun_iwasawa d51821
}
shun_iwasawa d51821
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// TTool *getSplineEditorTool() {return &controlPointEditorTool;}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
pojienie 286724
pojienie 286724
void ControlPointEditorTool::startFreehand(const TPointD &pos) {
pojienie 286724
  m_track.clear();
pojienie 286724
  m_firstPos       = pos;
pojienie 286724
  double pixelSize = getPixelSize();
pojienie 286724
  m_track.add(TThickPoint(pos, 0), pixelSize * pixelSize);
pojienie 286724
}
pojienie 286724
pojienie 286724
//-----------------------------------------------------------------------------
pojienie 286724
pojienie 286724
void ControlPointEditorTool::freehandDrag(const TPointD &pos) {
pojienie 286724
  double pixelSize = getPixelSize();
pojienie 286724
  m_track.add(TThickPoint(pos, 0), pixelSize * pixelSize);
pojienie 286724
}
pojienie 286724
pojienie 286724
//-----------------------------------------------------------------------------
pojienie 286724
void ControlPointEditorTool::closeFreehand(const TPointD &pos) {
pojienie 286724
  if (m_track.isEmpty()) return;
pojienie 286724
  double pixelSize = getPixelSize();
pojienie 286724
  m_track.add(TThickPoint(m_firstPos, 0), pixelSize * pixelSize);
pojienie 286724
  m_track.filterPoints();
pojienie 286724
  double error = (30.0 / 11) * pixelSize;
pojienie 286724
  m_stroke     = m_track.makeStroke(error);
pojienie 286724
  m_stroke->setStyle(1);
pojienie 286724
}
shun-iwasawa 0842da
shun-iwasawa 0842da
ControlPointEditorTool controlPointEditorTool;