Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "toonz/autoclose.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzimageutils.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/ttileset.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "toonz/strokegenerator.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "drawutil.h"
Toshihiro Shimizu 890ddd
#include "tinbetween.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// For Qt translation support
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToolUtils;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::StringVar AutocloseVectorType("InknpaintAutocloseVectorType", "Normal");
Toshihiro Shimizu 890ddd
TEnv::DoubleVar AutocloseDistance("InknpaintAutocloseDistance", 10.0);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar AutocloseAngle("InknpaintAutocloseAngle", 60.0);
Toshihiro Shimizu 890ddd
TEnv::IntVar AutocloseRange("InknpaintAutocloseRange", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar AutocloseOpacity("InknpaintAutocloseOpacity", 1);
Toshihiro Shimizu 890ddd
#define NORMAL_CLOSE L"Normal"
Toshihiro Shimizu 890ddd
#define RECT_CLOSE L"Rectangular"
Toshihiro Shimizu 890ddd
#define FREEHAND_CLOSE L"Freehand"
Toshihiro Shimizu 890ddd
#define POLYLINE_CLOSE L"Polyline"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class AutocloseParameters {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  int m_closingDistance, m_inkIndex, m_opacity;
Shinya Kitaoka 120a6e
  double m_spotAngle;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  AutocloseParameters()
Shinya Kitaoka 120a6e
      : m_closingDistance(0), m_inkIndex(0), m_spotAngle(0), m_opacity(1) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterAutocloseUndo final : public TRasterUndo {
Shinya Kitaoka 120a6e
  AutocloseParameters m_params;
Shinya Kitaoka 120a6e
  std::vector<tautocloser::segment> m_segments;</tautocloser::segment>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterAutocloseUndo(TTileSetCM32 *tileSet, const AutocloseParameters ¶ms,
Shinya Kitaoka 120a6e
                      const std::vector<tautocloser::segment> &segments,</tautocloser::segment>
Shinya Kitaoka 120a6e
                      TXshSimpleLevel *level, const TFrameId &frameId)
Shinya Kitaoka 120a6e
      : TRasterUndo(tileSet, level, frameId, false, false, 0)
Shinya Kitaoka 120a6e
      , m_segments(segments)
Shinya Kitaoka 120a6e
      , m_params(params) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void redo() const override {
Shinya Kitaoka 120a6e
    TToonzImageP image = getImage();
Shinya Kitaoka 120a6e
    if (!image) return;
Shinya Kitaoka 120a6e
    TAutocloser ac(image->getRaster(), m_params.m_closingDistance,
Shinya Kitaoka 120a6e
                   m_params.m_spotAngle, m_params.m_inkIndex,
Shinya Kitaoka 120a6e
                   m_params.m_opacity);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ac.draw(m_segments);
Shinya Kitaoka 120a6e
    ToolUtils::updateSaveBox();
Shinya Kitaoka 120a6e
    /*-- Viewerを更新させるため --*/
Shinya Kitaoka 120a6e
    TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
    notifyImageChanged();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
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 120a6e
Shinya Kitaoka 473e70
  QString getToolName() override { return QString("Autoclose Tool"); }
Shinya Kitaoka 473e70
  int getHistoryType() override { return HistoryType::AutocloseTool; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RasterTapeTool final : public TTool {
Shinya Kitaoka 120a6e
  Q_DECLARE_TR_FUNCTIONS(RasterTapeTool)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool m_selecting;
Shinya Kitaoka 120a6e
  TRectD m_selectingRect;
Shinya Kitaoka 120a6e
  TRectD m_firstRect;
Shinya Kitaoka 120a6e
  TPointD m_firstPoint;
Shinya Kitaoka 120a6e
  bool m_firstFrameSelected;
Shinya Kitaoka 120a6e
  TXshSimpleLevelP m_level;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // TBoolProperty  m_isRect;
Shinya Kitaoka 120a6e
  TEnumProperty m_closeType;
Shinya Kitaoka 120a6e
  TDoubleProperty m_distance;
Shinya Kitaoka 120a6e
  TDoubleProperty m_angle;
Shinya Kitaoka 120a6e
  TStyleIndexProperty m_inkIndex;
Shinya Kitaoka 120a6e
  TIntProperty m_opacity;
Shinya Kitaoka 120a6e
  TPropertyGroup m_prop;
Shinya Kitaoka 120a6e
  TBoolProperty m_multi;
Shinya Kitaoka 120a6e
  TFrameId m_firstFrameId, m_veryFirstFrameId;
Shinya Kitaoka 120a6e
  bool m_isXsheetCell;
Shinya Kitaoka 120a6e
  std::pair<int, int=""> m_currCell;</int,>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Aggiunte per disegnare il lazzo a la polyline
Shinya Kitaoka 120a6e
  StrokeGenerator m_track;
Shinya Kitaoka 120a6e
  TPointD m_firstPos;
Shinya Kitaoka 120a6e
  TPointD m_mousePosition;
Shinya Kitaoka 120a6e
  double m_thick;
Shinya Kitaoka 120a6e
  TStroke *m_stroke;
Shinya Kitaoka 120a6e
  TStroke *m_firstStroke;
Shinya Kitaoka 120a6e
  std::vector<tpointd> m_polyline;</tpointd>
Shinya Kitaoka 120a6e
  bool m_firstTime;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterTapeTool()
Shinya Kitaoka 120a6e
      : TTool("T_Tape")
Shinya Kitaoka 120a6e
      , m_closeType("Type:")                    // W_ToolOptions_CloseType
Shinya Kitaoka 120a6e
      , m_distance("Distance:", 1, 100, 10)     // W_ToolOptions_Distance
Shinya Kitaoka 120a6e
      , m_angle("Angle:", 1, 180, 60)           // W_ToolOptions_Angle
Shinya Kitaoka 120a6e
      , m_inkIndex("Style Index:", L"current")  // W_ToolOptions_InkIndex
Shinya Kitaoka 120a6e
      , m_opacity("Opacity:", 1, 255, 255)
Shinya Kitaoka 120a6e
      , m_multi("Frame Range", false)  // W_ToolOptions_FrameRange
Shinya Kitaoka 120a6e
      , m_selecting(false)
Shinya Kitaoka 120a6e
      , m_selectingRect()
Shinya Kitaoka 120a6e
      , m_firstRect()
Shinya Kitaoka 120a6e
      , m_level(0)
Shinya Kitaoka 120a6e
      , m_firstFrameSelected(false)
Shinya Kitaoka 120a6e
      , m_isXsheetCell(false)
Shinya Kitaoka 120a6e
      , m_currCell(-1, -1)
Shinya Kitaoka 120a6e
      , m_firstPos()
Shinya Kitaoka 120a6e
      , m_mousePosition()
Shinya Kitaoka 120a6e
      , m_thick(0.5)
Shinya Kitaoka 120a6e
      , m_stroke(0)
Shinya Kitaoka 120a6e
      , m_firstStroke(0)
Shinya Kitaoka 120a6e
      , m_firstTime(true) {
Shinya Kitaoka 120a6e
    bind(TTool::ToonzImage);
Shinya Kitaoka 120a6e
    m_prop.bind(m_closeType);
Shinya Kitaoka 120a6e
    m_closeType.addValue(NORMAL_CLOSE);
Shinya Kitaoka 120a6e
    m_closeType.addValue(RECT_CLOSE);
Shinya Kitaoka 120a6e
    m_closeType.addValue(FREEHAND_CLOSE);
Shinya Kitaoka 120a6e
    m_closeType.addValue(POLYLINE_CLOSE);
Shinya Kitaoka 120a6e
    m_prop.bind(m_multi);
Shinya Kitaoka 120a6e
    m_prop.bind(m_distance);
Shinya Kitaoka 120a6e
    m_prop.bind(m_angle);
Shinya Kitaoka 120a6e
    m_prop.bind(m_inkIndex);
Shinya Kitaoka 120a6e
    m_prop.bind(m_opacity);
Shinya Kitaoka 120a6e
    m_multi.setId("FrameRange");
Shinya Kitaoka 120a6e
    m_closeType.setId("Type");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  ToolType getToolType() const override { return TTool::LevelWriteTool; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void updateTranslation() override {
Shinya Kitaoka 120a6e
    m_closeType.setQStringName(tr("Type:"));
Shinya Kitaoka 120a6e
    m_distance.setQStringName(tr("Distance:"));
Shinya Kitaoka 120a6e
    m_inkIndex.setQStringName(tr("Style Index:"));
Shinya Kitaoka 120a6e
    m_opacity.setQStringName(tr("Opacity:"));
Shinya Kitaoka 120a6e
    m_multi.setQStringName(tr("Frame Range"));
Shinya Kitaoka 120a6e
    m_angle.setQStringName(tr("Angle:"));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == RECT_CLOSE) {
Shinya Kitaoka 120a6e
      if (!m_selecting) return;
Shinya Kitaoka 120a6e
      m_selectingRect.x1 = pos.x;
Shinya Kitaoka 120a6e
      m_selectingRect.y1 = pos.y;
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
    } else if (m_closeType.getValue() == FREEHAND_CLOSE) {
Shinya Kitaoka 120a6e
      freehandDrag(pos);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
  /*--  AutoCloseが実行されたらtrue,実行されなければfalseを返す --*/
Shinya Kitaoka 120a6e
  bool applyAutoclose(const TToonzImageP &ti, const TRectD &selRect = TRectD(),
Shinya Kitaoka 120a6e
                      TStroke *stroke = 0) {
Shinya Kitaoka 120a6e
    if (!ti) return false;
Shinya Kitaoka 120a6e
    // inizializzo gli AutocloseParameters
Shinya Kitaoka 120a6e
    AutocloseParameters params;
Shinya Kitaoka 120a6e
    params.m_closingDistance = (int)(m_distance.getValue());
Shinya Kitaoka 120a6e
    params.m_spotAngle       = (int)(m_angle.getValue());
Shinya Kitaoka 120a6e
    params.m_opacity         = m_opacity.getValue();
Shinya Kitaoka 120a6e
    std::string inkString    = ::to_string(m_inkIndex.getValue());
Shinya Kitaoka 120a6e
    int inkIndex =
Shinya Kitaoka 120a6e
        TTool::getApplication()
Shinya Kitaoka 120a6e
            ->getCurrentLevelStyleIndex();  // TApp::instance()->getCurrentPalette()->getStyleIndex();
Shinya Kitaoka 120a6e
    if (isInt(inkString)) inkIndex = std::stoi(inkString);
Shinya Kitaoka 120a6e
    params.m_inkIndex              = inkIndex;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPoint delta;
Shinya Kitaoka 120a6e
    TRasterCM32P ras, raux = ti->getRaster();
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == RECT_CLOSE && raux && !selRect.isEmpty()) {
Shinya Kitaoka 120a6e
      TRectD selArea = selRect;
Shinya Kitaoka 120a6e
      if (selRect.x0 > selRect.x1) {
Shinya Kitaoka 120a6e
        selArea.x1 = selRect.x0;
Shinya Kitaoka 120a6e
        selArea.x0 = selRect.x1;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (selRect.y0 > selRect.y1) {
Shinya Kitaoka 120a6e
        selArea.y1 = selRect.y0;
Shinya Kitaoka 120a6e
        selArea.y0 = selRect.y1;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      TRect myRect(ToonzImageUtils::convertWorldToRaster(selArea, ti));
Shinya Kitaoka 120a6e
      ras   = raux->extract(myRect);
Shinya Kitaoka 120a6e
      delta = myRect.getP00();
Shinya Kitaoka 120a6e
    } else if ((m_closeType.getValue() == FREEHAND_CLOSE ||
Shinya Kitaoka 120a6e
                m_closeType.getValue() == POLYLINE_CLOSE) &&
Shinya Kitaoka 120a6e
               stroke) {
Shinya Kitaoka 120a6e
      TRectD selArea = stroke->getBBox();
Shinya Kitaoka 120a6e
      TRect myRect(ToonzImageUtils::convertWorldToRaster(selArea, ti));
Shinya Kitaoka 120a6e
      ras   = raux->extract(myRect);
Shinya Kitaoka 120a6e
      delta = myRect.getP00();
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      ras = raux;
Shinya Kitaoka 120a6e
    if (!ras) return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TAutocloser ac(ras, params.m_closingDistance, params.m_spotAngle,
Shinya Kitaoka 120a6e
                   params.m_inkIndex, params.m_opacity);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    std::vector<tautocloser::segment> segments;</tautocloser::segment>
Shinya Kitaoka 120a6e
    ac.compute(segments);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if ((m_closeType.getValue() == FREEHAND_CLOSE ||
Shinya Kitaoka 120a6e
         m_closeType.getValue() == POLYLINE_CLOSE) &&
Shinya Kitaoka 120a6e
        stroke)
Shinya Kitaoka 120a6e
      checkSegments(segments, stroke, raux, delta);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    std::vector<tautocloser::segment> segments2(segments);</tautocloser::segment>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*-- segmentが取得できなければfalseを返す --*/
Shinya Kitaoka 120a6e
    if (segments2.empty()) return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    if (delta != TPoint(0, 0))
Shinya Kitaoka 120a6e
      for (i = 0; i < (int)segments2.size(); i++) {
Shinya Kitaoka 120a6e
        segments2[i].first += delta;
Shinya Kitaoka 120a6e
        segments2[i].second += delta;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTileSetCM32 *tileSet = new TTileSetCM32(raux->getSize());
Shinya Kitaoka 120a6e
    for (i = 0; i < (int)segments2.size(); i++) {
Shinya Kitaoka 120a6e
      TRect bbox(segments2[i].first, segments2[i].second);
Shinya Kitaoka 120a6e
      bbox = bbox.enlarge(2);
Shinya Kitaoka 120a6e
      tileSet->add(raux, bbox);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TXshSimpleLevel *sl =
Shinya Kitaoka 120a6e
        TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
Shinya Kitaoka 120a6e
    TFrameId id = getCurrentFid();
Shinya Kitaoka 120a6e
    TUndoManager::manager()->add(
Shinya Kitaoka 120a6e
        new RasterAutocloseUndo(tileSet, params, segments2, sl, id));
Shinya Kitaoka 120a6e
    ac.draw(segments);
Shinya Kitaoka 120a6e
    ToolUtils::updateSaveBox();
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  inline TRectD interpolateRect(const TRectD &r1, const TRectD &r2, double t) {
Shinya Kitaoka 120a6e
    return TRectD(r1.x0 + (r2.x0 - r1.x0) * t, r1.y0 + (r2.y0 - r1.y0) * t,
Shinya Kitaoka 120a6e
                  r1.x1 + (r2.x1 - r1.x1) * t, r1.y1 + (r2.y1 - r1.y1) * t);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //============================================================
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void multiApplyAutoclose(TFrameId firstFid, TFrameId lastFid,
Shinya Kitaoka 120a6e
                           TRectD firstRect, TRectD lastRect,
Shinya Kitaoka 120a6e
                           TStroke *firstStroke = 0, TStroke *lastStroke = 0) {
Shinya Kitaoka 120a6e
    bool backward = false;
Shinya Kitaoka 120a6e
    if (firstFid > lastFid) {
Shinya Kitaoka 120a6e
      tswap(firstFid, lastFid);
Shinya Kitaoka 120a6e
      backward = true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    assert(firstFid <= lastFid);
Shinya Kitaoka 120a6e
    std::vector<tframeid> allFids;</tframeid>
Shinya Kitaoka 120a6e
    m_level->getFids(allFids);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    std::vector<tframeid>::iterator i0 = allFids.begin();</tframeid>
Shinya Kitaoka 120a6e
    while (i0 != allFids.end() && *i0 < firstFid) i0++;
Shinya Kitaoka 120a6e
    if (i0 == allFids.end()) return;
Shinya Kitaoka 120a6e
    std::vector<tframeid>::iterator i1 = i0;</tframeid>
Shinya Kitaoka 120a6e
    while (i1 != allFids.end() && *i1 <= lastFid) i1++;
Shinya Kitaoka 120a6e
    assert(i0 < i1);
Shinya Kitaoka 120a6e
    std::vector<tframeid> fids(i0, i1);</tframeid>
Shinya Kitaoka 120a6e
    int m = fids.size();
Shinya Kitaoka 120a6e
    assert(m > 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TVectorImageP firstImage;
Shinya Kitaoka 120a6e
    TVectorImageP lastImage;
Shinya Kitaoka 120a6e
    if ((m_closeType.getValue() == FREEHAND_CLOSE ||
Shinya Kitaoka 120a6e
         m_closeType.getValue() == POLYLINE_CLOSE) &&
Shinya Kitaoka 120a6e
        firstStroke && lastStroke) {
Shinya Kitaoka 120a6e
      TStroke *first = new TStroke(*firstStroke);
Shinya Kitaoka 120a6e
      TStroke *last  = new TStroke(*lastStroke);
Shinya Kitaoka 120a6e
      firstImage     = new TVectorImage();
Shinya Kitaoka 120a6e
      lastImage      = new TVectorImage();
Shinya Kitaoka 120a6e
      firstImage->addStroke(first);
Shinya Kitaoka 120a6e
      lastImage->addStroke(last);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TUndoManager::manager()->beginBlock();
Shinya Kitaoka 120a6e
    for (int i = 0; i < m; ++i) {
Shinya Kitaoka 120a6e
      TFrameId fid     = fids[i];
Shinya Kitaoka 120a6e
      TToonzImageP img = (TToonzImageP)m_level->getFrame(fid, true);
Shinya Kitaoka 120a6e
      if (!img) continue;
Shinya Kitaoka 120a6e
      double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;
Shinya Kitaoka 120a6e
      if (m_closeType.getValue() == RECT_CLOSE)
Shinya Kitaoka 120a6e
        applyAutoclose(img, interpolateRect(firstRect, lastRect, t));
Shinya Kitaoka 120a6e
      else if ((m_closeType.getValue() == FREEHAND_CLOSE ||
Shinya Kitaoka 120a6e
                m_closeType.getValue() == POLYLINE_CLOSE) &&
Shinya Kitaoka 120a6e
               firstStroke && lastStroke)
Shinya Kitaoka 120a6e
        doClose(t, img, firstImage, lastImage);
Shinya Kitaoka 120a6e
      m_level->getProperties()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    //		TNotifier::instance()->notify(TLevelChange());
Shinya Kitaoka 120a6e
    //		TNotifier::instance()->notify(TStageChange());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void multiApplyAutoclose(TFrameId firstFrameId, TFrameId lastFrameId) {
Shinya Kitaoka 120a6e
    int r0 = firstFrameId.getNumber();
Shinya Kitaoka 120a6e
    int r1 = lastFrameId.getNumber();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (r0 > r1) {
Shinya Kitaoka 120a6e
      tswap(r0, r1);
Shinya Kitaoka 120a6e
      tswap(firstFrameId, lastFrameId);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if ((r1 - r0) < 2) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TUndoManager::manager()->beginBlock();
Shinya Kitaoka 120a6e
    for (int i = r0; i <= r1; ++i) {
Shinya Kitaoka 120a6e
      TFrameId fid(i);
Shinya Kitaoka 120a6e
      TImageP img = m_level->getFrame(fid, true);
Shinya Kitaoka 120a6e
      applyAutoclose(img);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    //		TNotifier::instance()->notify(TLevelChange());
Shinya Kitaoka 120a6e
    //		TNotifier::instance()->notify(TStageChange());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    TToonzImageP ti = TToonzImageP(getImage(true));
Shinya Kitaoka 120a6e
    if (!ti) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*-- Rectの座標の向きを揃える --*/
Shinya Kitaoka 120a6e
    if (m_selectingRect.x0 > m_selectingRect.x1)
Shinya Kitaoka 120a6e
      tswap(m_selectingRect.x1, m_selectingRect.x0);
Shinya Kitaoka 120a6e
    if (m_selectingRect.y0 > m_selectingRect.y1)
Shinya Kitaoka 120a6e
      tswap(m_selectingRect.y1, m_selectingRect.y0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_selecting = false;
Shinya Kitaoka 120a6e
    TRasterCM32P ras;
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == RECT_CLOSE) {
Shinya Kitaoka 120a6e
      if (m_multi.getValue()) {
Shinya Kitaoka 120a6e
        if (m_firstFrameSelected) {
Shinya Kitaoka 120a6e
          multiApplyAutoclose(m_firstFrameId, getFrameId(), m_firstRect,
Shinya Kitaoka 120a6e
                              m_selectingRect);
Shinya Kitaoka 120a6e
          invalidate(m_selectingRect.enlarge(2));
Shinya Kitaoka 120a6e
          if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
            m_firstRect    = m_selectingRect;
Shinya Kitaoka 120a6e
            m_firstFrameId = getFrameId();
Shinya Kitaoka 120a6e
          } else {
Shinya Kitaoka 120a6e
            if (m_isXsheetCell) {
Shinya Kitaoka 120a6e
              app->getCurrentColumn()->setColumnIndex(m_currCell.first);
Shinya Kitaoka 120a6e
              app->getCurrentFrame()->setFrame(m_currCell.second);
Shinya Kitaoka 120a6e
            } else
Shinya Kitaoka 120a6e
              app->getCurrentFrame()->setFid(m_veryFirstFrameId);
Shinya Kitaoka 120a6e
            resetMulti();
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Shinya Kitaoka 120a6e
          // if (m_isXsheetCell)
Shinya Kitaoka 120a6e
          m_currCell = std::pair<int, int="">(getColumnIndex(), this->getFrame());</int,>
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      /*-- AutoCloseが実行されたか判定する --*/
Shinya Kitaoka 120a6e
      if (!applyAutoclose(ti, m_selectingRect)) {
Shinya Kitaoka 120a6e
        if (m_stroke) {
Shinya Kitaoka 120a6e
          delete m_stroke;
Shinya Kitaoka 120a6e
          m_stroke = 0;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        invalidate();
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
      notifyImageChanged();
Shinya Kitaoka 120a6e
    } else if (m_closeType.getValue() == FREEHAND_CLOSE) {
Shinya Kitaoka 120a6e
      closeFreehand(pos);
Shinya Kitaoka 120a6e
      if (m_multi.getValue())
Shinya Kitaoka 120a6e
        multiAutocloseRegion(m_stroke, e);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        applyAutoclose(ti, TRectD(), m_stroke);
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (m_stroke) {
Shinya Kitaoka 120a6e
      delete m_stroke;
Shinya Kitaoka 120a6e
      m_stroke = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void draw() override {
Shinya Kitaoka 120a6e
    double pixelSize2 = getPixelSize() * getPixelSize();
Shinya Kitaoka 120a6e
    m_thick           = sqrt(pixelSize2) / 2.0;
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == RECT_CLOSE) {
Shinya Kitaoka 120a6e
      TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
Shinya Kitaoka 120a6e
                         ? TPixel32::White
Shinya Kitaoka 120a6e
                         : TPixel32::Black;
Shinya Kitaoka 120a6e
      if (m_multi.getValue() && m_firstFrameSelected)
Shinya Kitaoka 120a6e
        drawRect(m_firstRect, color, 0x3F33, true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (m_selecting || (m_multi.getValue() && !m_firstFrameSelected))
Shinya Kitaoka 120a6e
        drawRect(m_selectingRect, color, 0x3F33, true);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if ((m_closeType.getValue() == FREEHAND_CLOSE ||
Shinya Kitaoka 120a6e
         m_closeType.getValue() == POLYLINE_CLOSE) &&
Shinya Kitaoka 120a6e
        m_multi.getValue() && m_firstStroke) {
Shinya Kitaoka 120a6e
      TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
Shinya Kitaoka 120a6e
                         ? TPixel32::White
Shinya Kitaoka 120a6e
                         : TPixel32::Black;
Shinya Kitaoka 120a6e
      tglColor(color);
Shinya Kitaoka 120a6e
      drawStrokeCenterline(*m_firstStroke, 1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == POLYLINE_CLOSE && !m_polyline.empty()) {
Shinya Kitaoka 120a6e
      TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
Shinya Kitaoka 120a6e
                         ? TPixel32::White
Shinya Kitaoka 120a6e
                         : TPixel32::Black;
Shinya Kitaoka 120a6e
      tglColor(color);
Shinya Kitaoka 120a6e
      tglDrawCircle(m_polyline[0], 2);
Shinya Kitaoka 120a6e
      glBegin(GL_LINE_STRIP);
Shinya Kitaoka 120a6e
      for (UINT i = 0; i < m_polyline.size(); i++) tglVertex(m_polyline[i]);
Shinya Kitaoka 120a6e
      tglVertex(m_mousePosition);
Shinya Kitaoka 120a6e
      glEnd();
Shinya Kitaoka 120a6e
    } else if (m_multi.getValue() && m_firstFrameSelected)
Shinya Kitaoka 120a6e
      drawCross(m_firstPoint, 5);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool onPropertyChanged(std::string propertyName) override {
Shinya Kitaoka 120a6e
    if (propertyName == m_closeType.getName()) {
Shinya Kitaoka 120a6e
      AutocloseVectorType = ::to_string(m_closeType.getValue());
Shinya Kitaoka 120a6e
      resetMulti();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    else if (propertyName == m_distance.getName())
Shinya Kitaoka 120a6e
      AutocloseDistance = m_distance.getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    else if (propertyName == m_angle.getName())
Shinya Kitaoka 120a6e
      AutocloseAngle = m_angle.getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    else if (propertyName == m_inkIndex.getName()) {
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    else if (propertyName == m_opacity.getName())
Shinya Kitaoka 120a6e
      AutocloseOpacity = m_opacity.getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    else if (propertyName == m_multi.getName()) {
Shinya Kitaoka 120a6e
      AutocloseRange = (int)((m_multi.getValue()));
Shinya Kitaoka 120a6e
      resetMulti();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (ToonzCheck::instance()->getChecks() & ToonzCheck::eAutoclose)
Shinya Kitaoka 120a6e
      notifyImageChanged();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void resetMulti() {
Shinya Kitaoka 120a6e
    m_firstFrameSelected = false;
Shinya Kitaoka 120a6e
    m_firstRect.empty();
Shinya Kitaoka 120a6e
    m_firstPoint = TPointD();
Shinya Kitaoka 120a6e
    m_selectingRect.empty();
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    m_level                 = app->getCurrentLevel()->getLevel()
Shinya Kitaoka 120a6e
                  ? app->getCurrentLevel()->getSimpleLevel()
Shinya Kitaoka 120a6e
                  : 0;
Shinya Kitaoka 120a6e
    m_firstFrameId = m_veryFirstFrameId = getFrameId();
Shinya Kitaoka 120a6e
    m_firstStroke                       = 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void onImageChanged() override {
Shinya Kitaoka 120a6e
    if (!m_multi.getValue()) return;
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    TXshSimpleLevel *xshl   = 0;
Shinya Kitaoka 120a6e
    if (app->getCurrentLevel()->getLevel())
Shinya Kitaoka 120a6e
      xshl = app->getCurrentLevel()->getSimpleLevel();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!xshl || m_level.getPointer() != xshl ||
Shinya Kitaoka 120a6e
        (m_closeType.getValue() == RECT_CLOSE && m_selectingRect.isEmpty()) ||
Shinya Kitaoka 120a6e
        ((m_closeType.getValue() == FREEHAND_CLOSE ||
Shinya Kitaoka 120a6e
          m_closeType.getValue() == POLYLINE_CLOSE) &&
Shinya Kitaoka 120a6e
         !m_firstStroke))
Shinya Kitaoka 120a6e
      resetMulti();
Shinya Kitaoka 120a6e
    else if (m_firstFrameId == getFrameId())
Shinya Kitaoka 120a6e
      m_firstFrameSelected = false;  // nel caso sono passato allo stato 1 e
Shinya Kitaoka 120a6e
                                     // torno all'immagine iniziale, torno allo
Shinya Kitaoka 120a6e
                                     // stato iniziale
Shinya Kitaoka 38fd86
    else {                           // cambio stato.
Shinya Kitaoka 120a6e
      m_firstFrameSelected = true;
Shinya Kitaoka 120a6e
      if (m_closeType.getValue() == RECT_CLOSE) {
Shinya Kitaoka 120a6e
        assert(!m_selectingRect.isEmpty());
Shinya Kitaoka 120a6e
        m_firstRect = m_selectingRect;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &) override {
Shinya Kitaoka 120a6e
    TToonzImageP ti = TToonzImageP(getImage(true));
Shinya Kitaoka 120a6e
    if (!ti) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == RECT_CLOSE) {
Shinya Kitaoka 120a6e
      m_selecting        = true;
Shinya Kitaoka 120a6e
      m_selectingRect.x0 = pos.x;
Shinya Kitaoka 120a6e
      m_selectingRect.y0 = pos.y;
Shinya Kitaoka 120a6e
      m_selectingRect.x1 = pos.x + 1;
Shinya Kitaoka 120a6e
      m_selectingRect.y1 = pos.y + 1;
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    } else if (m_closeType.getValue() == FREEHAND_CLOSE) {
Shinya Kitaoka 120a6e
      startFreehand(pos);
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    } else if (m_closeType.getValue() == POLYLINE_CLOSE) {
Shinya Kitaoka 120a6e
      addPointPolyline(pos);
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    } else if (m_closeType.getValue() == NORMAL_CLOSE) {
Shinya Kitaoka 120a6e
      if (m_multi.getValue()) {
Shinya Kitaoka 120a6e
        TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
        if (m_firstFrameSelected) {
Shinya Kitaoka 120a6e
          multiApplyAutoclose(m_firstFrameId, getFrameId());
Shinya Kitaoka 120a6e
          invalidate();
Shinya Kitaoka 120a6e
          if (m_isXsheetCell) {
Shinya Kitaoka 120a6e
            app->getCurrentColumn()->setColumnIndex(m_currCell.first);
Shinya Kitaoka 120a6e
            app->getCurrentFrame()->setFrame(m_currCell.second);
Shinya Kitaoka 120a6e
          } else
Shinya Kitaoka 120a6e
            app->getCurrentFrame()->setFid(m_veryFirstFrameId);
Shinya Kitaoka 120a6e
          resetMulti();
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Shinya Kitaoka 120a6e
          // if (m_isXsheetCell)
Shinya Kitaoka 120a6e
          m_currCell = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Shinya Kitaoka 120a6e
          m_firstFrameSelected = true;
Shinya Kitaoka 120a6e
          m_firstPoint         = pos;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        invalidate();
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      m_selecting = false;
Shinya Kitaoka 120a6e
      applyAutoclose(ti);
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
      notifyImageChanged();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  void leftButtonDoubleClick(const TPointD &pos,
Shinya Kitaoka 38fd86
                             const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    TToonzImageP ti = TToonzImageP(getImage(true));
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == POLYLINE_CLOSE && ti) {
Shinya Kitaoka 120a6e
      closePolyline(pos);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      std::vector<tthickpoint> strokePoints;</tthickpoint>
Shinya Kitaoka 120a6e
      for (UINT i = 0; i < m_polyline.size() - 1; i++) {
Shinya Kitaoka 120a6e
        strokePoints.push_back(TThickPoint(m_polyline[i], 1));
Shinya Kitaoka 120a6e
        strokePoints.push_back(
Shinya Kitaoka 120a6e
            TThickPoint(0.5 * (m_polyline[i] + m_polyline[i + 1]), 1));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      strokePoints.push_back(TThickPoint(m_polyline.back(), 1));
Shinya Kitaoka 120a6e
      m_polyline.clear();
Shinya Kitaoka 120a6e
      m_stroke = new TStroke(strokePoints);
Shinya Kitaoka 120a6e
      assert(m_stroke->getPoint(0) == m_stroke->getPoint(1));
Shinya Kitaoka 120a6e
      if (m_multi.getValue())
Shinya Kitaoka 120a6e
        multiAutocloseRegion(m_stroke, e);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        applyAutoclose(ti, TRectD(), m_stroke);
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (m_stroke) {
Shinya Kitaoka 120a6e
      delete m_stroke;
Shinya Kitaoka 120a6e
      m_stroke = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void mouseMove(const TPointD &pos, const TMouseEvent &e) override {
Shinya Kitaoka 120a6e
    if (m_closeType.getValue() == POLYLINE_CLOSE) {
Shinya Kitaoka 120a6e
      m_mousePosition = pos;
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void onEnter() override {
Shinya Kitaoka 120a6e
    //      getApplication()->editImage();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void onActivate() override {
Shinya Kitaoka 120a6e
    if (m_firstTime) {
Shinya Kitaoka 120a6e
      m_closeType.setValue(::to_wstring(AutocloseVectorType.getValue()));
Shinya Kitaoka 120a6e
      m_distance.setValue(AutocloseDistance);
Shinya Kitaoka 120a6e
      m_angle.setValue(AutocloseAngle);
Shinya Kitaoka 120a6e
      m_opacity.setValue(AutocloseOpacity);
Shinya Kitaoka 120a6e
      m_multi.setValue(AutocloseRange ? 1 : 0);
Shinya Kitaoka 120a6e
      m_firstTime = false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    //			getApplication()->editImage();
Shinya Kitaoka 120a6e
    resetMulti();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void onDeactivate() override {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getCursorId() const override {
Shinya Kitaoka 120a6e
    if (ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg)
Shinya Kitaoka 120a6e
      return ToolCursor::TapeCursorWhite;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return ToolCursor::TapeCursor;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Viene aggiunto \b pos a \b m_track e disegnato il primo pezzetto del
Shinya Kitaoka 120a6e
  //! lazzo. Viene inizializzato \b m_firstPos
Shinya Kitaoka 120a6e
  void startFreehand(const TPointD &pos) {
Shinya Kitaoka 120a6e
    m_track.clear();
Shinya Kitaoka 120a6e
    m_firstPos        = pos;
Shinya Kitaoka 120a6e
    double pixelSize2 = getPixelSize() * getPixelSize();
Shinya Kitaoka 120a6e
    m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Shinya Kitaoka 120a6e
    TPointD dpiScale = m_viewer->getDpiScale();
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Shinya Kitaoka 120a6e
// getViewer()->prepareForegroundDrawing();
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    //			getViewer()->makeCurrent();
Shinya Kitaoka 120a6e
    TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
Shinya Kitaoka 120a6e
                       ? TPixel32::White
Shinya Kitaoka 120a6e
                       : TPixel32::Black;
Shinya Kitaoka 120a6e
    tglColor(color);
Shinya Kitaoka 120a6e
    m_viewer->startForegroundDrawing();
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    glScaled(dpiScale.x, dpiScale.y, 1);
Shinya Kitaoka 120a6e
    m_track.drawLastFragments();
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
    getViewer()->endForegroundDrawing();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Viene aggiunto \b pos a \b m_track e disegnato un altro pezzetto del
Shinya Kitaoka 120a6e
  //! lazzo.
Shinya Kitaoka 120a6e
  void freehandDrag(const TPointD &pos) {
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Shinya Kitaoka 120a6e
// getViewer()->enableRedraw(false);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    getViewer()->startForegroundDrawing();
Shinya Kitaoka 120a6e
    TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
Shinya Kitaoka 120a6e
                       ? TPixel32::White
Shinya Kitaoka 120a6e
                       : TPixel32::Black;
Shinya Kitaoka 120a6e
    tglColor(color);
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    tglMultMatrix(getMatrix());
Shinya Kitaoka 120a6e
    TPointD dpiScale = m_viewer->getDpiScale();
Shinya Kitaoka 120a6e
    glScaled(dpiScale.x, dpiScale.y, 1);
Shinya Kitaoka 120a6e
    double pixelSize2 = getPixelSize() * getPixelSize();
Shinya Kitaoka 120a6e
    m_track.add(TThickPoint(pos, m_thick), pixelSize2);
Shinya Kitaoka 120a6e
    m_track.drawLastFragments();
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
    getViewer()->endForegroundDrawing();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Viene chiuso il lazzo (si aggiunge l'ultimo punto ad m_track) e viene
Shinya Kitaoka 120a6e
  //! creato lo stroke rappresentante il lazzo.
Shinya Kitaoka 120a6e
  void closeFreehand(const TPointD &pos) {
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Shinya Kitaoka 120a6e
// getViewer()->enableRedraw(true);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    if (m_track.isEmpty()) return;
Shinya Kitaoka 120a6e
    double pixelSize2 = getPixelSize() * getPixelSize();
Shinya Kitaoka 120a6e
    m_track.add(TThickPoint(m_firstPos, m_thick), pixelSize2);
Shinya Kitaoka 120a6e
    m_track.filterPoints();
Shinya Kitaoka 120a6e
    double error = (30.0 / 11) * sqrt(pixelSize2);
Shinya Kitaoka 120a6e
    m_stroke     = m_track.makeStroke(error);
Shinya Kitaoka 120a6e
    m_stroke->setStyle(1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Viene aggiunto un punto al vettore m_polyline.
Shinya Kitaoka 120a6e
  void addPointPolyline(const TPointD &pos) {
Shinya Kitaoka 120a6e
    m_firstPos = pos;
Shinya Kitaoka 120a6e
    // m_mousePosition = pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TPointD dpiScale = m_viewer->getDpiScale();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Shinya Kitaoka 120a6e
// getViewer()->prepareForegroundDrawing();
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    //				getViewer()->makeCurrent();
Shinya Kitaoka 120a6e
    TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
Shinya Kitaoka 120a6e
                       ? TPixel32::White
Shinya Kitaoka 120a6e
                       : TPixel32::Black;
Shinya Kitaoka 120a6e
    tglColor(color);
Shinya Kitaoka 120a6e
    getViewer()->startForegroundDrawing();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(MACOSX)
Shinya Kitaoka 120a6e
// getViewer()->enableRedraw(m_closeType.getValue() == POLYLINE_CLOSE);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    glPushMatrix();
Shinya Kitaoka 120a6e
    glScaled(dpiScale.x, dpiScale.y, 1);
Shinya Kitaoka 120a6e
    m_polyline.push_back(pos);
Shinya Kitaoka 120a6e
    glPopMatrix();
Shinya Kitaoka 120a6e
    getViewer()->endForegroundDrawing();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Agginge l'ultimo pos a \b m_polyline e chiude la spezzata (aggiunge \b
Shinya Kitaoka 120a6e
  //! m_polyline.front() alla fine del vettore)
Shinya Kitaoka 120a6e
  void closePolyline(const TPointD &pos) {
Shinya Kitaoka 120a6e
    if (m_polyline.size() <= 1) return;
Shinya Kitaoka 120a6e
    if (m_polyline.back() != pos) m_polyline.push_back(pos);
Shinya Kitaoka 120a6e
    if (m_polyline.back() != m_polyline.front())
Shinya Kitaoka 120a6e
      m_polyline.push_back(m_polyline.front());
Shinya Kitaoka 120a6e
    invalidate();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Elimina i segmenti che non sono contenuti all'interno dello stroke!!!
Shinya Kitaoka 120a6e
  void checkSegments(std::vector<tautocloser::segment> &segments,</tautocloser::segment>
Shinya Kitaoka 120a6e
                     TStroke *stroke, const TRasterCM32P &ras,
Shinya Kitaoka 120a6e
                     const TPoint &delta) {
Shinya Kitaoka 120a6e
    TVectorImage vi;
Shinya Kitaoka 120a6e
    TStroke *app = new TStroke();
Shinya Kitaoka 120a6e
    *app         = *stroke;
Shinya Kitaoka 120a6e
    app->transform(TTranslation(convert(ras->getCenter())));
Shinya Kitaoka 120a6e
    vi.addStroke(app);
Shinya Kitaoka 120a6e
    vi.findRegions();
Shinya Kitaoka 120a6e
    std::vector<tautocloser::segment>::iterator it = segments.begin();</tautocloser::segment>
Shinya Kitaoka 120a6e
    for (; it < segments.end(); it++) {
Shinya Kitaoka 120a6e
      if (it == segments.end()) break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      bool isContained = false;
Shinya Kitaoka 120a6e
      for (i = 0; i < (int)vi.getRegionCount(); i++) {
Shinya Kitaoka 120a6e
        TRegion *reg = vi.getRegion(i);
Shinya Kitaoka 120a6e
        if (reg->contains(convert(it->first + delta)) &&
Shinya Kitaoka 120a6e
            reg->contains(convert(it->second + delta))) {
Shinya Kitaoka 120a6e
          isContained = true;
Shinya Kitaoka 120a6e
          break;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (!isContained) {
Shinya Kitaoka 120a6e
        it = segments.erase(it);
Shinya Kitaoka 120a6e
        if (it != segments.end() && it != segments.begin())
Shinya Kitaoka 120a6e
          it--;
Shinya Kitaoka 120a6e
        else if (it == segments.end())
Shinya Kitaoka 120a6e
          break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void multiAutocloseRegion(TStroke *stroke, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    if (m_firstStroke) {
Shinya Kitaoka 120a6e
      multiApplyAutoclose(m_firstFrameId, getFrameId(), TRectD(), TRectD(),
Shinya Kitaoka 120a6e
                          m_firstStroke, stroke);
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
      if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
        delete m_firstStroke;
Shinya Kitaoka 120a6e
        m_firstStroke  = new TStroke(*stroke);
Shinya Kitaoka 120a6e
        m_firstFrameId = getFrameId();
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        if (m_isXsheetCell) {
Shinya Kitaoka 120a6e
          app->getCurrentColumn()->setColumnIndex(m_currCell.first);
Shinya Kitaoka 120a6e
          app->getCurrentFrame()->setFrame(m_currCell.second);
Shinya Kitaoka 120a6e
        } else
Shinya Kitaoka 120a6e
          app->getCurrentFrame()->setFid(m_veryFirstFrameId);
Shinya Kitaoka 120a6e
        resetMulti();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Shinya Kitaoka 120a6e
      // if (m_isXsheetCell)
Shinya Kitaoka 120a6e
      m_currCell    = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Shinya Kitaoka 120a6e
      m_firstStroke = new TStroke(*stroke);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void doClose(double t, const TImageP &img, const TVectorImageP &firstImage,
Shinya Kitaoka 120a6e
               const TVectorImageP &lastImage) {
Shinya Kitaoka 120a6e
    if (t == 0)
Shinya Kitaoka 120a6e
      applyAutoclose(img, TRectD(), firstImage->getStroke(0));
Shinya Kitaoka 120a6e
    else if (t == 1)
Shinya Kitaoka 120a6e
      applyAutoclose(img, TRectD(), lastImage->getStroke(0));
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      assert(firstImage->getStrokeCount() == 1);
Shinya Kitaoka 120a6e
      assert(lastImage->getStrokeCount() == 1);
Shinya Kitaoka 120a6e
      TVectorImageP vi = TInbetween(firstImage, lastImage).tween(t);
Shinya Kitaoka 120a6e
      assert(vi->getStrokeCount() == 1);
Shinya Kitaoka 120a6e
      applyAutoclose(img, TRectD(), vi->getStroke(0));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} rasterTapeTool;