Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzTools includes
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "tools/toolcommandids.h"
Toshihiro Shimizu 890ddd
#include "tools/toolutils.h"
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "historytypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttileset.h"
Toshihiro Shimizu 890ddd
#include "toonz/ttilesaver.h"
Toshihiro Shimizu 890ddd
#include "toonz/trasterimageutils.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/strokegenerator.h"
manongjohn 75da26
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "bluredbrush.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "drawutil.h"
Toshihiro Shimizu 890ddd
#include "tinbetween.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToolUtils;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define NORMALERASE L"Normal"
Toshihiro Shimizu 890ddd
#define RECTERASE L"Rectangular"
Toshihiro Shimizu 890ddd
#define FREEHANDERASE L"Freehand"
Toshihiro Shimizu 890ddd
#define POLYLINEERASE L"Polyline"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::DoubleVar FullcolorEraseSize("FullcolorEraseSize", 5);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar FullcolorEraseHardness("FullcolorEraseHardness", 100);
Toshihiro Shimizu 890ddd
TEnv::DoubleVar FullcolorEraserOpacity("FullcolorEraserOpacity", 100);
Toshihiro Shimizu 890ddd
TEnv::StringVar FullcolorEraserType("FullcolorEraseType", "Normal");
Toshihiro Shimizu 890ddd
TEnv::IntVar FullcolorEraserInvert("FullcolorEraseInvert", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FullcolorEraserRange("FullcolorEraseRange", 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace  stuff
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int computeThickness(int pressure, const TIntPairProperty &property) {
Shinya Kitaoka 120a6e
  double p   = pressure / 255.0;
Shinya Kitaoka 120a6e
  double t   = p * p * p;
Shinya Kitaoka 120a6e
  int thick0 = property.getValue().first;
Shinya Kitaoka 120a6e
  int thick1 = property.getValue().second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return tround(thick0 + (thick1 - thick0) * t);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void eraseImage(const TRasterImageP &ri, const TRaster32P &image,
Shinya Kitaoka 120a6e
                const TPoint &pos, bool invert) {
Shinya Kitaoka 120a6e
  TRect rasBounds   = ri->getRaster()->getBounds();
Shinya Kitaoka 120a6e
  TRect imageBounds = image->getBounds() + pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (invert) {
Shinya Kitaoka 120a6e
    TRect rect(imageBounds.x0, rasBounds.y0, rasBounds.x1, imageBounds.y0 - 1);
Shinya Kitaoka 120a6e
    TRasterImageUtils::eraseRect(
Shinya Kitaoka 120a6e
        ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    rect =
Shinya Kitaoka 120a6e
        TRect(imageBounds.x1 + 1, imageBounds.y0, rasBounds.x1, rasBounds.y1);
Shinya Kitaoka 120a6e
    TRasterImageUtils::eraseRect(
Shinya Kitaoka 120a6e
        ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    rect =
Shinya Kitaoka 120a6e
        TRect(rasBounds.x0, imageBounds.y1 + 1, imageBounds.x1, rasBounds.y1);
Shinya Kitaoka 120a6e
    TRasterImageUtils::eraseRect(
Shinya Kitaoka 120a6e
        ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    rect =
Shinya Kitaoka 120a6e
        TRect(rasBounds.x0, rasBounds.y0, imageBounds.x0 - 1, imageBounds.y1);
Shinya Kitaoka 120a6e
    TRasterImageUtils::eraseRect(
Shinya Kitaoka 120a6e
        ri, TRasterImageUtils::convertRasterToWorld(rect, ri));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P workRas;
Shinya Kitaoka 120a6e
  if (TRasterGR8P ras = ri->getRaster()) {
Shinya Kitaoka 120a6e
    workRas = TRaster32P(imageBounds.getSize());
Shinya Kitaoka 120a6e
    TRop::convert(workRas, ras->extract(imageBounds));
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    workRas = ri->getRaster()->extract(imageBounds);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int y;
Shinya Kitaoka 120a6e
  for (y = 0; y < workRas->getLy(); y++) {
Shinya Kitaoka 120a6e
    TPixel32 *outPix    = workRas->pixels(y);
Shinya Kitaoka 120a6e
    TPixel32 *outEndPix = outPix + workRas->getLx();
Shinya Kitaoka 120a6e
    TPixel32 *inPix     = image->pixels(y);
Rozhuk Ivan 823a31
    for (; outPix != outEndPix; outPix++, inPix++) {
Shinya Kitaoka 120a6e
      if (outPix->m == 0) continue;
Shinya Kitaoka 120a6e
      TPixel32 pix = depremultiply(*outPix);
Shinya Kitaoka 120a6e
      pix.m =
Shinya Kitaoka 120a6e
          invert ? pix.m * (inPix->m) / 255 : pix.m * (255 - inPix->m) / 255;
Shinya Kitaoka 120a6e
      *outPix = premultiply(pix);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (TRasterGR8P ras = ri->getRaster()) {
Shinya Kitaoka 120a6e
    TRop::addBackground(workRas, TPixel32::White);
Shinya Kitaoka 120a6e
    TRop::over(ras, workRas, pos);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class RectFullColorUndo final : public TFullColorRasterUndo {
Shinya Kitaoka 120a6e
  TRectD m_modifyArea;
Shinya Kitaoka 120a6e
  TStroke *m_stroke;
Shinya Kitaoka 120a6e
  std::wstring m_eraseType;
Shinya Kitaoka 120a6e
  bool m_invert;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RectFullColorUndo(TTileSetFullColor *tileSet, const TRectD &modifyArea,
Shinya Kitaoka 120a6e
                    TStroke stroke, std::wstring eraseType,
Shinya Kitaoka 120a6e
                    TXshSimpleLevel *level, bool invert,
Shinya Kitaoka 120a6e
                    const TFrameId &frameId)
Shinya Kitaoka 120a6e
      : TFullColorRasterUndo(tileSet, level, frameId, false, false, 0)
Shinya Kitaoka 120a6e
      , m_modifyArea(modifyArea)
Shinya Kitaoka 120a6e
      , m_eraseType(eraseType)
Shinya Kitaoka 120a6e
      , m_invert(invert) {
Shinya Kitaoka 120a6e
    m_stroke = new TStroke(stroke);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~RectFullColorUndo() { delete m_stroke; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void redo() const override {
Shinya Kitaoka 120a6e
    TRasterImageP ri = getImage();
Shinya Kitaoka 120a6e
    if (!ri) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_eraseType == RECTERASE)
Shinya Kitaoka 120a6e
      TRect rect = TRasterImageUtils::eraseRect(ri, m_modifyArea);
Shinya Kitaoka 120a6e
    else if (m_eraseType == FREEHANDERASE || m_eraseType == POLYLINEERASE) {
Shinya Kitaoka 120a6e
      TPoint pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TRaster32P image =
Shinya Kitaoka 120a6e
          convertStrokeToImage(m_stroke, ri->getRaster()->getBounds(), pos);
Shinya Kitaoka 120a6e
      if (!image) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      eraseImage(ri, image, pos, m_invert);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
    notifyImageChanged();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getSize() const override {
Shinya Kitaoka 120a6e
    return TFullColorRasterUndo::getSize() +
Shinya Kitaoka 120a6e
           m_stroke->getControlPointCount() * sizeof(TThickPoint) + 100 +
Shinya Kitaoka 120a6e
           sizeof(this);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  QString getToolName() override {
Shinya Kitaoka 38fd86
    return QString("Raster Eraser Tool (Rect)");
Shinya Kitaoka 38fd86
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getHistoryType() override { return HistoryType::EraserTool; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FullColorEraserUndo final : public TFullColorRasterUndo {
Shinya Kitaoka 120a6e
  std::vector<tthickpoint> m_points;</tthickpoint>
Shinya Kitaoka 120a6e
  int m_size;
Shinya Kitaoka 120a6e
  double m_hardness;
Shinya Kitaoka 120a6e
  double m_opacity;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FullColorEraserUndo(TTileSetFullColor *tileSet,
Shinya Kitaoka 120a6e
                      const std::vector<tthickpoint> &points,</tthickpoint>
Shinya Kitaoka 120a6e
                      TXshSimpleLevel *level, const TFrameId &frameId, int size,
Shinya Kitaoka 120a6e
                      double hardness, double opacity)
Shinya Kitaoka 120a6e
      : TFullColorRasterUndo(tileSet, level, frameId, false, false, 0)
Shinya Kitaoka 120a6e
      , m_points(points)
Shinya Kitaoka 120a6e
      , m_size(size)
Shinya Kitaoka 120a6e
      , m_hardness(hardness)
Shinya Kitaoka 120a6e
      , m_opacity(opacity) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void redo() const override {
Shinya Kitaoka 120a6e
    if (m_points.size() == 0) return;
Shinya Kitaoka 120a6e
    TRasterImageP image      = getImage();
Shinya Kitaoka 120a6e
    TRasterP ras             = image->getRaster();
Shinya Kitaoka 120a6e
    QRadialGradient brushPad = getBrushPad(m_size, m_hardness);
Shinya Kitaoka 120a6e
    TRaster32P workRaster    = TRaster32P(ras->getSize());
Shinya Kitaoka 120a6e
    TRasterP backUpRas       = ras->clone();
Shinya Kitaoka 120a6e
    workRaster->clear();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    BluredBrush brush(workRaster, m_size, brushPad, false);
Shinya Kitaoka 120a6e
    std::vector<tthickpoint> points;</tthickpoint>
Shinya Kitaoka 120a6e
    points.push_back(m_points[0]);
Shinya Kitaoka 120a6e
    TRect bbox = brush.getBoundFromPoints(points);
Shinya Kitaoka 120a6e
    brush.addPoint(m_points[0], 1);
Shinya Kitaoka 120a6e
    brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
Shinya Kitaoka 120a6e
    if (m_points.size() > 1) {
Shinya Kitaoka 120a6e
      points.clear();
Shinya Kitaoka 120a6e
      points.push_back(m_points[0]);
Shinya Kitaoka 120a6e
      points.push_back(m_points[1]);
Shinya Kitaoka 120a6e
      bbox = brush.getBoundFromPoints(points);
Shinya Kitaoka 120a6e
      brush.addArc(m_points[0], (m_points[1] + m_points[0]) * 0.5, m_points[1],
Shinya Kitaoka 120a6e
                   1, 1);
Shinya Kitaoka 120a6e
      brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      for (i = 1; i + 2 < (int)m_points.size(); i = i + 2) {
Shinya Kitaoka 120a6e
        points.clear();
Shinya Kitaoka 120a6e
        points.push_back(m_points[i]);
Shinya Kitaoka 120a6e
        points.push_back(m_points[i + 1]);
Shinya Kitaoka 120a6e
        points.push_back(m_points[i + 2]);
Shinya Kitaoka 120a6e
        bbox = brush.getBoundFromPoints(points);
Shinya Kitaoka 120a6e
        brush.addArc(m_points[i], m_points[i + 1], m_points[i + 2], 1, 1);
Shinya Kitaoka 120a6e
        brush.eraseDrawing(ras, backUpRas, bbox, m_opacity);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
    notifyImageChanged();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  int getSize() const override {
Shinya Kitaoka 120a6e
    return sizeof(*this) + TFullColorRasterUndo::getSize();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  QString getToolName() override { return QString("Raster Eraser Tool"); }
Shinya Kitaoka 473e70
  int getHistoryType() override { return HistoryType::EraserTool; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void eraseStroke(const TRasterImageP &ri, TStroke *stroke,
Shinya Kitaoka 120a6e
                 std::wstring eraseType, bool invert,
Shinya Kitaoka 120a6e
                 const TXshSimpleLevelP &level, const TFrameId &frameId) {
Shinya Kitaoka 120a6e
  assert(stroke);
Shinya Kitaoka 120a6e
  TPoint pos;
Shinya Kitaoka 120a6e
  TRasterP ras = ri->getRaster();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P image = convertStrokeToImage(stroke, ras->getBounds(), pos);
Shinya Kitaoka 120a6e
  if (!image) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRect rasterErasedArea = image->getBounds() + pos;
Shinya Kitaoka 120a6e
  TRect area;
Shinya Kitaoka 120a6e
  if (!invert)
Shinya Kitaoka 120a6e
    area = rasterErasedArea.enlarge(2);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    area = ras->getBounds();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TTileSetFullColor *tileSet = new TTileSetFullColor(ras->getSize());
Shinya Kitaoka 120a6e
  tileSet->add(ras, area);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUndoManager::manager()->add(
Shinya Kitaoka 120a6e
      new RectFullColorUndo(tileSet, convert(area), *stroke, eraseType,
Shinya Kitaoka 120a6e
                            level.getPointer(), invert, frameId));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  eraseImage(ri, image, pos, invert);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    FullColorEraserTool  definition
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FullColorEraserTool final : public TTool {
Shinya Kitaoka 120a6e
  Q_DECLARE_TR_FUNCTIONS(FullColorEraserTool)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FullColorEraserTool(std::string name);
Shinya Kitaoka 120a6e
  ~FullColorEraserTool();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  ToolType getToolType() const override { return TTool::LevelWriteTool; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void updateTranslation() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void onActivate() override;
Shinya Kitaoka 473e70
  void onDeactivate() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonUp(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e) override;
Shinya Kitaoka 473e70
  void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void draw() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  int getCursorId() const override { return ToolCursor::PenCursor; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool onPropertyChanged(std::string propertyName) override;
Shinya Kitaoka 473e70
  void onImageChanged() override;
Shinya Kitaoka 473e70
  void onEnter() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void update(const TRasterImageP &ri, TRectD selArea,
Shinya Kitaoka 120a6e
              const TXshSimpleLevelP &level, bool multi = false,
Shinya Kitaoka 120a6e
              const TFrameId &frameId = -1);
Shinya Kitaoka 120a6e
  void multiUpdate(const TRectD firstRect, const TRectD lastRect);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void multiAreaEraser(TFrameId &firstFid, TFrameId &lastFid,
Shinya Kitaoka 120a6e
                       TStroke *firstStroke, TStroke *lastStroke);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void doMultiEraser(const TImageP &img, double t, const TFrameId &fid,
Shinya Kitaoka 120a6e
                     const TVectorImageP &firstImage,
Shinya Kitaoka 120a6e
                     const TVectorImageP &lastImage);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void resetMulti();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  TPropertyGroup m_prop;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TIntProperty m_size;
Shinya Kitaoka 120a6e
  TDoubleProperty m_opacity;
Shinya Kitaoka 120a6e
  TDoubleProperty m_hardness;
Shinya Kitaoka 120a6e
  TEnumProperty m_eraseType;
Shinya Kitaoka 120a6e
  TBoolProperty m_invertOption;
Shinya Kitaoka 120a6e
  TBoolProperty m_multi;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TXshSimpleLevelP m_level;
Shinya Kitaoka 120a6e
  std::pair<int, int=""> m_currCell;</int,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFrameId m_firstFrameId, m_veryFirstFrameId;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P m_workRaster;
Shinya Kitaoka 120a6e
  TRasterP m_backUpRas;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QRadialGradient m_brushPad;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<tthickpoint> m_points;</tthickpoint>
Shinya Kitaoka 120a6e
  BluredBrush *m_brush;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TTileSetFullColor *m_tileSet;
Shinya Kitaoka 120a6e
  TTileSaverFullColor *m_tileSaver;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  StrokeGenerator m_track;
Shinya Kitaoka 120a6e
  std::vector<tpointd> m_polyline;</tpointd>
Shinya Kitaoka 120a6e
  TStroke *m_firstStroke;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRectD m_selectingRect, m_firstRect;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPointD m_mousePos, m_brushPos, m_firstPos;
Jeremy Bullock 5af997
  TMouseEvent m_mouseEvent;
Shinya Kitaoka 120a6e
  double m_thick;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_firstTime, m_selecting, m_firstFrameSelected, m_isXsheetCell;
Jeremy Bullock 5af997
  bool m_mousePressed = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
} fullColorEraser(T_Eraser);  // Tools are statically instantiated
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
FullColorEraserTool::FullColorEraserTool(std::string name)
Shinya Kitaoka 120a6e
    : TTool(name)
shun-iwasawa 76d093
    , m_size("Size:", 1, 1000, 5, false)
Shinya Kitaoka 120a6e
    , m_opacity("Opacity:", 0, 100, 100)
Shinya Kitaoka 120a6e
    , m_hardness("Hardness:", 0, 100, 100)
Shinya Kitaoka 120a6e
    , m_eraseType("Type:")
Shinya Kitaoka 120a6e
    , m_invertOption("Invert", false)
Shinya Kitaoka 120a6e
    , m_multi("Frame Range", false)
Shinya Kitaoka 120a6e
    , m_currCell(-1, -1)
Shinya Kitaoka 120a6e
    , m_brush(0)
Shinya Kitaoka 120a6e
    , m_tileSet(0)
Shinya Kitaoka 120a6e
    , m_tileSaver(0)
Shinya Kitaoka 120a6e
    , m_thick(0.5)
Shinya Kitaoka 120a6e
    , m_firstTime(true)
Shinya Kitaoka 120a6e
    , m_selecting(false)
Shinya Kitaoka 120a6e
    , m_firstFrameSelected(false)
Shinya Kitaoka 120a6e
    , m_isXsheetCell(false) {
Shinya Kitaoka 120a6e
  bind(TTool::RasterImage);
Shinya Kitaoka 120a6e
shun-iwasawa 76d093
  m_size.setNonLinearSlider();
shun-iwasawa 76d093
Shinya Kitaoka 120a6e
  m_prop.bind(m_size);
Shinya Kitaoka 120a6e
  m_prop.bind(m_hardness);
Shinya Kitaoka 120a6e
  m_prop.bind(m_opacity);
Shinya Kitaoka 120a6e
  m_prop.bind(m_eraseType);
Shinya Kitaoka 120a6e
  m_prop.bind(m_invertOption);
Shinya Kitaoka 120a6e
  m_prop.bind(m_multi);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_eraseType.addValue(NORMALERASE);
Shinya Kitaoka 120a6e
  m_eraseType.addValue(RECTERASE);
Shinya Kitaoka 120a6e
  m_eraseType.addValue(FREEHANDERASE);
Shinya Kitaoka 120a6e
  m_eraseType.addValue(POLYLINEERASE);
Martin van Zijl 01831a
Martin van Zijl 01831a
  m_eraseType.setId("Type");
Martin van Zijl 01831a
  m_invertOption.setId("Invert");
Martin van Zijl 01831a
  m_multi.setId("FrameRange");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FullColorEraserTool::~FullColorEraserTool() { delete m_firstStroke; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::updateTranslation() {
Shinya Kitaoka 120a6e
  m_size.setQStringName(tr("Size:"));
Shinya Kitaoka 120a6e
  m_opacity.setQStringName(tr("Opacity:"));
Shinya Kitaoka 120a6e
  m_hardness.setQStringName(tr("Hardness:"));
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  m_eraseType.setQStringName(tr("Type:"));
shun-iwasawa df7bb0
  m_eraseType.setItemUIName(NORMALERASE, tr("Normal"));
shun-iwasawa df7bb0
  m_eraseType.setItemUIName(RECTERASE, tr("Rectangular"));
shun-iwasawa df7bb0
  m_eraseType.setItemUIName(FREEHANDERASE, tr("Freehand"));
shun-iwasawa df7bb0
  m_eraseType.setItemUIName(POLYLINEERASE, tr("Polyline"));
shun-iwasawa df7bb0
Shinya Kitaoka 120a6e
  m_invertOption.setQStringName(tr("Invert"));
Shinya Kitaoka 120a6e
  m_multi.setQStringName(tr("Frame Range"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::onActivate() {
Shinya Kitaoka 120a6e
  if (m_firstTime) {
Shinya Kitaoka 120a6e
    m_firstTime = false;
Shinya Kitaoka 120a6e
    m_size.setValue(FullcolorEraseSize);
Shinya Kitaoka 120a6e
    m_opacity.setValue(FullcolorEraserOpacity);
Shinya Kitaoka 120a6e
    m_hardness.setValue(FullcolorEraseHardness);
Shinya Kitaoka 120a6e
    m_eraseType.setValue(::to_wstring(FullcolorEraserType.getValue()));
Shinya Kitaoka 120a6e
    m_invertOption.setValue((bool)FullcolorEraserInvert);
Shinya Kitaoka 120a6e
    m_multi.setValue((bool)FullcolorEraserRange);
Shinya Kitaoka 120a6e
    m_firstTime = false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_brushPad = getBrushPad(m_size.getValue(), m_hardness.getValue() * 0.01);
shun-iwasawa 67f182
shun-iwasawa 67f182
  // setting m_level in resetMulti() will take care when the tool is switched
shun-iwasawa 67f182
  // via shortcut ( i.e. the case skipping onEnter() )
shun-iwasawa 67f182
  resetMulti();
shun-iwasawa 67f182
  // clear previous polyline when the tool is activated
shun-iwasawa 67f182
  m_polyline.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock 5af997
void FullColorEraserTool::onDeactivate() {
Jeremy Bullock 5af997
  if (m_mousePressed) leftButtonUp(m_mousePos, m_mouseEvent);
Jeremy Bullock 5af997
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::leftButtonDown(const TPointD &pos,
Shinya Kitaoka 120a6e
                                         const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  m_brushPos = m_mousePos = pos;
Jeremy Bullock 5af997
  m_mouseEvent            = e;
Jeremy Bullock 5af997
  m_mousePressed          = true;
Jeremy Bullock 5af997
  TRasterImageP ri        = (TRasterImageP)getImage(true);
Shinya Kitaoka 120a6e
  if (!ri) return;
Shinya Kitaoka 120a6e
  TRectD invalidateRect;
Shinya Kitaoka 120a6e
  TRasterP ras = ri->getRaster();
Shinya Kitaoka 120a6e
  if (m_eraseType.getValue() == NORMALERASE) {
Shinya Kitaoka 120a6e
    TDimension dim  = ras->getSize();
Shinya Kitaoka 120a6e
    double opacity  = m_opacity.getValue() * 0.01;
Shinya Kitaoka 120a6e
    double hardness = m_hardness.getValue() * 0.01;
Shinya Kitaoka 120a6e
    m_workRaster    = TRaster32P(dim);
Shinya Kitaoka 120a6e
    m_workRaster->clear();
Shinya Kitaoka 120a6e
    m_backUpRas = ras->clone();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int maxThick      = m_size.getValue();
Shinya Kitaoka 120a6e
    TPointD rasCenter = ras->getCenterD();
Shinya Kitaoka 120a6e
    TThickPoint point(pos + rasCenter, maxThick);
Shinya Kitaoka 120a6e
    TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
Shinya Kitaoka 120a6e
    invalidateRect = TRectD(pos - halfThick, pos + halfThick);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_points.clear();
Shinya Kitaoka 120a6e
    m_points.push_back(point);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_tileSet   = new TTileSetFullColor(ras->getSize());
Shinya Kitaoka 120a6e
    m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
Shinya Kitaoka 120a6e
    m_brush =
Shinya Kitaoka 120a6e
        new BluredBrush(m_workRaster, m_size.getValue(), m_brushPad, false);
Shinya Kitaoka 120a6e
    TRect bbox = m_brush->getBoundFromPoints(m_points);
Shinya Kitaoka 120a6e
    m_tileSaver->save(bbox);
Shinya Kitaoka 120a6e
    m_brush->addPoint(point, 1);
Shinya Kitaoka 120a6e
    m_brush->eraseDrawing(ras, m_backUpRas, bbox, opacity);
Shinya Kitaoka 120a6e
  } else if (m_eraseType.getValue() == RECTERASE) {
Shinya Kitaoka 120a6e
    if (m_multi.getValue() && m_firstRect.isEmpty()) {
Shinya Kitaoka 120a6e
      invalidateRect = m_selectingRect;
Shinya Kitaoka 120a6e
      m_selectingRect.empty();
Shinya Kitaoka 120a6e
      invalidate(invalidateRect.enlarge(2));
Shinya Kitaoka 120a6e
    }
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
    invalidateRect     = m_selectingRect;
Shinya Kitaoka 120a6e
  } else if (m_eraseType.getValue() == FREEHANDERASE ||
Shinya Kitaoka 120a6e
             m_eraseType.getValue() == POLYLINEERASE) {
Shinya Kitaoka 120a6e
    if (m_multi.getValue() && m_firstStroke && !m_firstFrameSelected) {
Shinya Kitaoka 120a6e
      invalidateRect = m_firstStroke->getBBox();
Shinya Kitaoka 120a6e
      delete m_firstStroke;
Shinya Kitaoka 120a6e
      m_firstStroke = 0;
Shinya Kitaoka 120a6e
      invalidate(invalidateRect.enlarge(2));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
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
Shinya Kitaoka 120a6e
    if (m_eraseType.getValue() == POLYLINEERASE) {
Shinya Kitaoka 120a6e
      if (m_polyline.empty() || m_polyline.back() != pos)
Shinya Kitaoka 120a6e
        m_polyline.push_back(pos);
shun-iwasawa c189d1
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int maxThick = 2 * m_thick;
Shinya Kitaoka 120a6e
    TPointD halfThick(maxThick * 0.5, maxThick * 0.5);
Shinya Kitaoka 120a6e
    invalidateRect = TRectD(pos - halfThick, pos + halfThick);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  invalidate(invalidateRect.enlarge(2));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::leftButtonDrag(const TPointD &pos,
Shinya Kitaoka 120a6e
                                         const TMouseEvent &e) {
manongjohn 1e1817
  if (!m_mousePressed) return;
manongjohn 1e1817
Shinya Kitaoka 120a6e
  m_brushPos = m_mousePos = pos;
Jeremy Bullock 5af997
  m_mouseEvent            = e;
Jeremy Bullock 5af997
  double pixelSize2       = getPixelSize() * getPixelSize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterImageP ri = (TRasterImageP)getImage(true);
Shinya Kitaoka 120a6e
  if (!ri) return;
Shinya Kitaoka 120a6e
  if (m_eraseType.getValue() == NORMALERASE) {
Shinya Kitaoka 120a6e
    double thickness  = m_size.getValue();
Shinya Kitaoka 120a6e
    TDimension size   = m_workRaster->getSize();
Shinya Kitaoka 120a6e
    TPointD rasCenter = ri->getRaster()->getCenterD();
Shinya Kitaoka 120a6e
    TThickPoint point(pos + rasCenter, thickness);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TThickPoint old = m_points.back();
Shinya Kitaoka 120a6e
    if (norm2(point - old) < 4) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);
Shinya Kitaoka 120a6e
    m_points.push_back(mid);
Shinya Kitaoka 120a6e
    m_points.push_back(point);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int m          = m_points.size();
Shinya Kitaoka 120a6e
    double opacity = m_opacity.getValue() * 0.01;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TThickPoint pa = m_points.front();
Shinya Kitaoka 120a6e
    std::vector<tthickpoint> points;</tthickpoint>
Shinya Kitaoka 120a6e
    points.push_back(pa);
Shinya Kitaoka 120a6e
    points.push_back(mid);
Shinya Kitaoka 120a6e
    TRect bbox;
Shinya Kitaoka 120a6e
    TRectD invalidateRect;
Shinya Kitaoka 120a6e
    if (m == 3) {
Shinya Kitaoka 120a6e
      TThickPoint pa = m_points.front();
Shinya Kitaoka 120a6e
      std::vector<tthickpoint> points;</tthickpoint>
Shinya Kitaoka 120a6e
      points.push_back(pa);
Shinya Kitaoka 120a6e
      points.push_back(mid);
Shinya Kitaoka 120a6e
      invalidateRect = ToolUtils::getBounds(points, thickness);
Shinya Kitaoka 120a6e
      bbox           = m_brush->getBoundFromPoints(points);
Shinya Kitaoka 120a6e
      m_tileSaver->save(bbox);
Shinya Kitaoka 120a6e
      m_brush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      std::vector<tthickpoint> points;</tthickpoint>
Shinya Kitaoka 120a6e
      points.push_back(m_points[m - 4]);
Shinya Kitaoka 120a6e
      points.push_back(old);
Shinya Kitaoka 120a6e
      points.push_back(mid);
Shinya Kitaoka 120a6e
      invalidateRect = ToolUtils::getBounds(points, thickness);
Shinya Kitaoka 120a6e
      bbox           = m_brush->getBoundFromPoints(points);
Shinya Kitaoka 120a6e
      m_tileSaver->save(bbox);
Shinya Kitaoka 120a6e
      m_brush->addArc(m_points[m - 4], old, mid, 1, 1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_brush->eraseDrawing(ri->getRaster(), m_backUpRas, bbox, opacity);
Shinya Kitaoka 120a6e
    invalidate(invalidateRect.enlarge(2) - rasCenter);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_eraseType.getValue() == RECTERASE) {
Shinya Kitaoka 120a6e
    assert(m_selecting);
Shinya Kitaoka 120a6e
    TRectD oldRect = m_selectingRect;
otakuto ed7dcd
    if (oldRect.x0 > oldRect.x1) std::swap(oldRect.x1, oldRect.x0);
otakuto ed7dcd
    if (oldRect.y0 > oldRect.y1) std::swap(oldRect.y1, oldRect.y0);
Shinya Kitaoka 120a6e
    m_selectingRect.x1 = pos.x;
Shinya Kitaoka 120a6e
    m_selectingRect.y1 = pos.y;
Shinya Kitaoka 120a6e
    TRectD invalidateRect(m_selectingRect);
Shinya Kitaoka 120a6e
    if (invalidateRect.x0 > invalidateRect.x1)
otakuto ed7dcd
      std::swap(invalidateRect.x1, invalidateRect.x0);
Shinya Kitaoka 120a6e
    if (invalidateRect.y0 > invalidateRect.y1)
otakuto ed7dcd
      std::swap(invalidateRect.y1, invalidateRect.y0);
Shinya Kitaoka 120a6e
    invalidateRect += oldRect;
Shinya Kitaoka 120a6e
    invalidate(invalidateRect.enlarge(2));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_eraseType.getValue() == FREEHANDERASE) {
Shinya Kitaoka 120a6e
    m_track.add(TThickPoint(pos, m_thick), pixelSize2);
shun-iwasawa c189d1
    invalidate(m_track.getModifiedRegion());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::leftButtonUp(const TPointD &pos,
Shinya Kitaoka 120a6e
                                       const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  m_brushPos = m_mousePos = pos;
Shinya Kitaoka 120a6e
  TRasterImageP ri        = (TRasterImageP)getImage(true);
Shinya Kitaoka 120a6e
  if (!ri) return;
Shinya Kitaoka 120a6e
  if (m_eraseType.getValue() == NORMALERASE) {
Shinya Kitaoka 120a6e
    if (m_points.size() != 1) {
Shinya Kitaoka 120a6e
      TPointD rasCenter = ri->getRaster()->getCenterD();
Shinya Kitaoka 120a6e
      TThickPoint point(pos + rasCenter, m_size.getValue());
Shinya Kitaoka 120a6e
      m_points.push_back(point);
Shinya Kitaoka 120a6e
      int m = m_points.size();
Shinya Kitaoka 120a6e
      std::vector<tthickpoint> points;</tthickpoint>
Shinya Kitaoka 120a6e
      points.push_back(m_points[m - 3]);
Shinya Kitaoka 120a6e
      points.push_back(m_points[m - 2]);
Shinya Kitaoka 120a6e
      points.push_back(m_points[m - 1]);
Shinya Kitaoka 120a6e
      TRect bbox = m_brush->getBoundFromPoints(points);
Shinya Kitaoka 120a6e
      m_tileSaver->save(bbox);
Shinya Kitaoka 120a6e
      m_brush->addArc(points[0], points[1], points[2], 1, 1);
Shinya Kitaoka 120a6e
      double opacity = m_opacity.getValue() * 0.01;
Shinya Kitaoka 120a6e
      m_brush->eraseDrawing(ri->getRaster(), m_backUpRas, bbox, opacity);
Shinya Kitaoka 120a6e
      TRectD invalidateRect = ToolUtils::getBounds(points, m_size.getValue());
Shinya Kitaoka 120a6e
      invalidate(invalidateRect.enlarge(2) - rasCenter);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_brush) {
Shinya Kitaoka 120a6e
      delete m_brush;
Shinya Kitaoka 120a6e
      m_brush = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_workRaster->unlock();
Shinya Kitaoka 120a6e
    double opacity  = m_opacity.getValue() * 0.01;
Shinya Kitaoka 120a6e
    double hardness = m_hardness.getValue() * 0.01;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_workRaster = TRaster32P();
Shinya Kitaoka 120a6e
    m_backUpRas  = TRaster32P();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    delete m_tileSaver;
Shinya Kitaoka 120a6e
    TTool::Application *app   = TTool::getApplication();
Shinya Kitaoka 120a6e
    TXshLevel *level          = app->getCurrentLevel()->getLevel();
Shinya Kitaoka 120a6e
    TXshSimpleLevelP simLevel = level->getSimpleLevel();
Shinya Kitaoka 120a6e
    TFrameId frameId          = getCurrentFid();
Shinya Kitaoka 120a6e
    TUndoManager::manager()->add(new FullColorEraserUndo(
Shinya Kitaoka 120a6e
        m_tileSet, m_points, simLevel.getPointer(), frameId, m_size.getValue(),
Shinya Kitaoka 120a6e
        m_hardness.getValue() * 0.01, opacity));
Shinya Kitaoka 120a6e
    notifyImageChanged();
Shinya Kitaoka 120a6e
  } else if (m_eraseType.getValue() == RECTERASE) {
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
Shinya Kitaoka 120a6e
    if (m_multi.getValue()) {
Shinya Kitaoka 120a6e
      TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
      if (m_firstFrameSelected) {
Shinya Kitaoka 120a6e
        multiUpdate(m_firstRect, m_selectingRect);
Shinya Kitaoka 120a6e
        notifyImageChanged();
Shinya Kitaoka 120a6e
        if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
          m_firstRect    = m_selectingRect;
Shinya Kitaoka 120a6e
          m_firstFrameId = getFrameId();
Shinya Kitaoka 120a6e
          invalidate();
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
        m_currCell     = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      TTool::Application *app   = TTool::getApplication();
Shinya Kitaoka 120a6e
      TXshLevel *level          = app->getCurrentLevel()->getLevel();
Shinya Kitaoka 120a6e
      TXshSimpleLevelP simLevel = level->getSimpleLevel();
Shinya Kitaoka 120a6e
      TFrameId frameId          = getCurrentFid();
Shinya Kitaoka 120a6e
      if (m_invertOption.getValue()) {
Shinya Kitaoka 120a6e
        TUndoManager::manager()->beginBlock();
Shinya Kitaoka 120a6e
        TRect rect =
Shinya Kitaoka 120a6e
            TRasterImageUtils::convertWorldToRaster(m_selectingRect, ri);
Shinya Kitaoka 120a6e
        rect *= ri->getSavebox();
Shinya Kitaoka 120a6e
        TDimension dim = ri->getRaster()->getSize();
Shinya Kitaoka 120a6e
        TRectD rect01 =
Shinya Kitaoka 120a6e
            TRectD(TPointD(0., 0.), TPointD((double)rect.x0, (double)dim.ly));
Shinya Kitaoka 120a6e
        if (rect01.getLx() > 0 && rect01.getLy() > 0) {
Shinya Kitaoka 120a6e
          rect01 = TRasterImageUtils::convertRasterToWorld(convert(rect01), ri);
Shinya Kitaoka 120a6e
          update(ri, rect01, simLevel, false, frameId);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        TRectD rect02 = TRectD(convert(rect.getP01()),
Shinya Kitaoka 120a6e
                               TPointD((double)rect.x1, (double)dim.ly));
Shinya Kitaoka 120a6e
        if (rect02.getLx() > 0 && rect02.getLy() > 0) {
Shinya Kitaoka 120a6e
          rect02 = TRasterImageUtils::convertRasterToWorld(convert(rect02), ri);
Shinya Kitaoka 120a6e
          update(ri, rect02, simLevel, false, frameId);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        TRectD rect03 =
Shinya Kitaoka 120a6e
            TRectD(TPointD((double)rect.x0, 0.), convert(rect.getP10()));
Shinya Kitaoka 120a6e
        if (rect03.getLx() > 0 && rect03.getLy() > 0) {
Shinya Kitaoka 120a6e
          rect03 = TRasterImageUtils::convertRasterToWorld(convert(rect03), ri);
Shinya Kitaoka 120a6e
          update(ri, rect03, simLevel, false, frameId);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        TRectD rect04 = TRectD(TPointD((double)rect.x1, 0.),
Shinya Kitaoka 120a6e
                               TPointD((double)dim.lx, (double)dim.ly));
Shinya Kitaoka 120a6e
        if (rect04.getLx() > 0 && rect04.getLy() > 0) {
Shinya Kitaoka 120a6e
          rect04 = TRasterImageUtils::convertRasterToWorld(convert(rect04), ri);
Shinya Kitaoka 120a6e
          update(ri, rect04, simLevel, false, frameId);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
        invalidate();
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        update(ri, m_selectingRect, simLevel, false, frameId);
Shinya Kitaoka 120a6e
        invalidate(m_selectingRect.enlarge(2));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      m_selectingRect.empty();
Shinya Kitaoka 120a6e
      TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
      m_selecting = false;
Shinya Kitaoka 120a6e
      notifyImageChanged();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else if (m_eraseType.getValue() == FREEHANDERASE) {
Shinya Kitaoka 120a6e
    if (m_track.isEmpty()) return;
Shinya Kitaoka 120a6e
    double pixelSize2 = getPixelSize() * getPixelSize();
Shinya Kitaoka 120a6e
    m_track.add(TThickPoint(pos, m_thick), pixelSize2);
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
    TStroke *stroke = m_track.makeStroke(error);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    stroke->setStyle(1);
Shinya Kitaoka 120a6e
    m_track.clear();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
    if (m_multi.getValue())  // stroke multi
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      if (m_firstFrameSelected) {
Shinya Kitaoka 120a6e
        TFrameId tmp = getCurrentFid();
Shinya Kitaoka 120a6e
        if (m_firstStroke && stroke)
Shinya Kitaoka 120a6e
          multiAreaEraser(m_firstFrameId, tmp, m_firstStroke, stroke);
Shinya Kitaoka 120a6e
        notifyImageChanged();
Shinya Kitaoka 120a6e
        if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
          TRectD invalidateRect = m_firstStroke->getBBox();
Shinya Kitaoka 120a6e
          delete m_firstStroke;
Shinya Kitaoka 120a6e
          m_firstStroke = 0;
Shinya Kitaoka 120a6e
          invalidate(invalidateRect.enlarge(2));
Shinya Kitaoka 120a6e
          m_firstStroke  = stroke;
Shinya Kitaoka 120a6e
          invalidateRect = m_firstStroke->getBBox();
Shinya Kitaoka 120a6e
          invalidate(invalidateRect.enlarge(2));
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
          delete stroke;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      } else  // primo frame
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        m_firstStroke  = stroke;
Shinya Kitaoka 120a6e
        m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Shinya Kitaoka 120a6e
        m_currCell     = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Shinya Kitaoka 120a6e
        invalidate(m_firstStroke->getBBox().enlarge(2));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else  // stroke non multi
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      if (!getImage(true)) return;
Shinya Kitaoka 120a6e
      TFrameId frameId = getCurrentFid();
Shinya Kitaoka 120a6e
      eraseStroke(ri, stroke, m_eraseType.getValue(), m_invertOption.getValue(),
Shinya Kitaoka 120a6e
                  /*m_multi.getValue(),*/ m_level, frameId);
Shinya Kitaoka 120a6e
      notifyImageChanged();
Shinya Kitaoka 120a6e
      if (m_invertOption.getValue())
Shinya Kitaoka 120a6e
        invalidate();
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        invalidate(stroke->getBBox().enlarge(2));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Jeremy Bullock 5af997
  m_mousePressed = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::leftButtonDoubleClick(const TPointD &pos,
Shinya Kitaoka 120a6e
                                                const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  TRasterImageP ri(getImage(true));
Shinya Kitaoka 120a6e
  if (!ri) return;
Shinya Kitaoka 120a6e
  TStroke *stroke;
Shinya Kitaoka 120a6e
  TTool::Application *app = TTool::getApplication();
Shinya Kitaoka 120a6e
  if (m_polyline.size() <= 1) {
Shinya Kitaoka 120a6e
    resetMulti();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
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
  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
  stroke = new TStroke(strokePoints);
Shinya Kitaoka 120a6e
  assert(stroke->getPoint(0) == stroke->getPoint(1));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_multi.getValue())  // stroke multi
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    if (m_firstFrameSelected) {
Shinya Kitaoka 120a6e
      TFrameId tmp = getFrameId();
Shinya Kitaoka 120a6e
      if (m_firstStroke && stroke)
Shinya Kitaoka 120a6e
        multiAreaEraser(m_firstFrameId, tmp, m_firstStroke, stroke);
Shinya Kitaoka 120a6e
      if (e.isShiftPressed()) {
Shinya Kitaoka 120a6e
        TRectD invalidateRect = m_firstStroke->getBBox();
Shinya Kitaoka 120a6e
        delete m_firstStroke;
Shinya Kitaoka 120a6e
        m_firstStroke = 0;
Shinya Kitaoka 120a6e
        invalidate(invalidateRect.enlarge(2));
Shinya Kitaoka 120a6e
        m_firstStroke  = stroke;
Shinya Kitaoka 120a6e
        invalidateRect = m_firstStroke->getBBox();
Shinya Kitaoka 120a6e
        invalidate(invalidateRect.enlarge(2));
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
        delete stroke;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else  // primo frame
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      m_firstStroke  = stroke;
Shinya Kitaoka 120a6e
      m_isXsheetCell = app->getCurrentFrame()->isEditingScene();
Shinya Kitaoka 120a6e
      m_currCell     = std::pair<int, int="">(getColumnIndex(), getFrame());</int,>
Shinya Kitaoka 120a6e
      invalidate(m_firstStroke->getBBox().enlarge(2));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (!getImage(true)) return;
Shinya Kitaoka 120a6e
    TXshLevel *level          = app->getCurrentLevel()->getLevel();
Shinya Kitaoka 120a6e
    TXshSimpleLevelP simLevel = level->getSimpleLevel();
Shinya Kitaoka 120a6e
    TFrameId frameId          = getFrameId();
Shinya Kitaoka 120a6e
    eraseStroke(ri, stroke, m_eraseType.getValue(), m_invertOption.getValue(),
Shinya Kitaoka 120a6e
                /*m_multi.getValue(),*/ m_level, frameId);
Shinya Kitaoka 120a6e
    notifyImageChanged();
Shinya Kitaoka 120a6e
    if (m_invertOption.getValue())
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      invalidate(stroke->getBBox().enlarge(2));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
Shinya Kitaoka 120a6e
  struct Locals {
Shinya Kitaoka 120a6e
    FullColorEraserTool *m_this;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    void setValue(TIntProperty &prop, int value) {
Shinya Kitaoka 120a6e
      prop.setValue(value);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      m_this->onPropertyChanged(prop.getName());
Shinya Kitaoka 120a6e
      TTool::getApplication()->getCurrentTool()->notifyToolChanged();
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    void addValue(TIntProperty &prop, double add) {
Shinya Kitaoka 120a6e
      const TIntProperty::Range &range = prop.getRange();
Shinya Kitaoka 120a6e
      setValue(prop,
Shinya Kitaoka 120a6e
               tcrop<double>(prop.getValue() + add, range.first, range.second));</double>
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  } locals = {this};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  switch (e.getModifiersMask()) {
Shinya Kitaoka 120a6e
  case TMouseEvent::ALT_KEY: {
Shinya Kitaoka 120a6e
    // User wants to alter the maximum brush size
Shinya Kitaoka 120a6e
    const TPointD &diff = pos - m_mousePos;
Shinya Kitaoka 120a6e
    double add          = (fabs(diff.x) > fabs(diff.y)) ? diff.x : diff.y;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    locals.addValue(m_size, add);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    m_brushPos = pos;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_mousePos = pos;
Shinya Kitaoka 120a6e
  invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::draw() {
Shinya Kitaoka 120a6e
  double pixelSize2 = getPixelSize() * getPixelSize();
Shinya Kitaoka 120a6e
  m_thick           = sqrt(pixelSize2) / 2.0;
Shinya Kitaoka 120a6e
  TRasterImageP img = (TRasterImageP)getImage(false);
Shinya Kitaoka 120a6e
  if (!img) return;
Shinya Kitaoka 120a6e
  if (m_eraseType.getValue() == NORMALERASE) {
manongjohn 75da26
    // If toggled off, don't draw brush outline
manongjohn 75da26
    if (!Preferences::instance()->isCursorOutlineEnabled()) return;
manongjohn 75da26
Shinya Kitaoka 120a6e
    glColor3d(1.0, 0.0, 0.0);
Shinya Kitaoka 120a6e
    tglDrawCircle(m_brushPos, (m_size.getValue() + 1) * 0.5);
Shinya Kitaoka 120a6e
  } else if (m_eraseType.getValue() == RECTERASE) {
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_eraseType.getValue() == FREEHANDERASE ||
Shinya Kitaoka 120a6e
       m_eraseType.getValue() == POLYLINEERASE) &&
Shinya Kitaoka 120a6e
      m_multi.getValue()) {
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
    if (m_firstStroke) drawStrokeCenterline(*m_firstStroke, 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_eraseType.getValue() == POLYLINEERASE && !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 * m_thick);
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_mousePos);
Shinya Kitaoka 120a6e
    glEnd();
shun-iwasawa c189d1
  } else if (m_eraseType.getValue() == FREEHANDERASE && !m_track.isEmpty()) {
shun-iwasawa c189d1
    TPixel color = ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg
shun-iwasawa c189d1
                       ? TPixel32::White
shun-iwasawa c189d1
                       : TPixel32::Black;
shun-iwasawa c189d1
    tglColor(color);
shun-iwasawa c189d1
    m_track.drawAllFragments();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FullColorEraserTool::onPropertyChanged(std::string propertyName) {
Shinya Kitaoka 120a6e
  FullcolorEraseSize     = m_size.getValue();
Shinya Kitaoka 120a6e
  FullcolorEraseHardness = m_hardness.getValue();
Shinya Kitaoka 120a6e
  FullcolorEraserOpacity = m_opacity.getValue();
Shinya Kitaoka 120a6e
  FullcolorEraserType    = ::to_string(m_eraseType.getValue());
Shinya Kitaoka 120a6e
  FullcolorEraserInvert  = (int)m_invertOption.getValue();
Shinya Kitaoka 120a6e
  FullcolorEraserRange   = (int)m_multi.getValue();
Shinya Kitaoka 120a6e
  if (propertyName == "Hardness:" || propertyName == "Size:") {
Shinya Kitaoka 120a6e
    m_brushPad = getBrushPad(m_size.getValue(), m_hardness.getValue() * 0.01);
Shinya Kitaoka 120a6e
    TRectD rect(
Shinya Kitaoka 120a6e
        m_brushPos - TPointD(FullcolorEraseSize + 2, FullcolorEraseSize + 2),
Shinya Kitaoka 120a6e
        m_brushPos + TPointD(FullcolorEraseSize + 2, FullcolorEraseSize + 2));
Shinya Kitaoka 120a6e
    invalidate(rect);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::update(const TRasterImageP &ri, TRectD selArea,
Shinya Kitaoka 120a6e
                                 const TXshSimpleLevelP &level, bool multi,
Shinya Kitaoka 120a6e
                                 const TFrameId &frameId) {
Shinya Kitaoka 120a6e
  if (m_selectingRect.x0 > m_selectingRect.x1) {
Shinya Kitaoka 120a6e
    selArea.x1 = m_selectingRect.x0;
Shinya Kitaoka 120a6e
    selArea.x0 = m_selectingRect.x1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_selectingRect.y0 > m_selectingRect.y1) {
Shinya Kitaoka 120a6e
    selArea.y1 = m_selectingRect.y0;
Shinya Kitaoka 120a6e
    selArea.y0 = m_selectingRect.y1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (selArea.getLx() < 1 || selArea.getLy() < 1) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterP raster            = ri->getRaster();
Shinya Kitaoka 120a6e
  TTileSetFullColor *tileSet = new TTileSetFullColor(raster->getSize());
Shinya Kitaoka 120a6e
  tileSet->add(raster, TRasterImageUtils::convertWorldToRaster(selArea, ri));
Shinya Kitaoka 120a6e
  TUndo *undo;
Shinya Kitaoka 120a6e
shun-iwasawa 76d093
  undo       = new RectFullColorUndo(tileSet, selArea, TStroke(),
Shinya Kitaoka 120a6e
                               m_eraseType.getValue(), level.getPointer(),
Shinya Kitaoka 120a6e
                               m_invertOption.getValue(), frameId);
Shinya Kitaoka 120a6e
  TRect rect = TRasterImageUtils::eraseRect(ri, selArea);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::resetMulti() {
Shinya Kitaoka 120a6e
  m_isXsheetCell       = false;
Shinya Kitaoka 120a6e
  m_firstFrameSelected = false;
Shinya Kitaoka 120a6e
  m_firstRect.empty();
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 = getCurrentFid();
Shinya Kitaoka 120a6e
  if (m_firstStroke) {
Shinya Kitaoka 120a6e
    delete m_firstStroke;
Shinya Kitaoka 120a6e
    m_firstStroke = 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::onImageChanged() {
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_selectingRect.isEmpty() && !m_firstStroke))
Shinya Kitaoka 120a6e
    resetMulti();
Shinya Kitaoka 120a6e
  else if (m_firstFrameId == getCurrentFid())
Shinya Kitaoka 120a6e
    m_firstFrameSelected = false;  // nel caso sono passato allo stato 1 e torno
Shinya Kitaoka 120a6e
                                   // all'immagine iniziale, torno allo stato
Shinya Kitaoka 120a6e
                                   // iniziale
Shinya Kitaoka 38fd86
  else {                           // cambio stato.
Shinya Kitaoka 120a6e
    m_firstFrameSelected = true;
Shinya Kitaoka 120a6e
    if (m_eraseType.getValue() != FREEHANDERASE &&
Shinya Kitaoka 120a6e
        m_eraseType.getValue() != POLYLINEERASE) {
Shinya Kitaoka 120a6e
      assert(!m_selectingRect.isEmpty());
Shinya Kitaoka 120a6e
      m_firstRect = m_selectingRect;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::multiUpdate(const TRectD firstRect,
Shinya Kitaoka 120a6e
                                      const TRectD lastRect) {
Shinya Kitaoka 120a6e
  bool backward     = false;
Shinya Kitaoka 120a6e
  TFrameId firstFid = m_firstFrameId;
Shinya Kitaoka 120a6e
  TFrameId lastFid  = getCurrentFid();
Shinya Kitaoka 120a6e
  if (firstFid > lastFid) {
otakuto ed7dcd
    std::swap(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
  TUndoManager::manager()->beginBlock();
Shinya Kitaoka 120a6e
  for (int i = 0; i < m; ++i) {
Shinya Kitaoka 120a6e
    TFrameId fid = fids[i];
Shinya Kitaoka 120a6e
    assert(firstFid <= fid && fid <= lastFid);
Shinya Kitaoka 120a6e
    TRasterImageP ri = m_level->getFrame(fid, true);
Shinya Kitaoka 120a6e
    assert(ri);
Shinya Kitaoka 120a6e
    double t    = m > 1 ? (double)i / (double)(m - 1) : 0.5;
Shinya Kitaoka 120a6e
    TRectD rect = interpolateRect(firstRect, lastRect, backward ? 1 - t : t);
Shinya Kitaoka 120a6e
    if (m_invertOption.getValue()) {
Shinya Kitaoka 120a6e
      TRectD rect01 =
Shinya Kitaoka 120a6e
          TRectD(TPointD(-100000., -100000.), TPointD(rect.x0, 100000.));
Shinya Kitaoka 120a6e
      update(ri, rect01, m_level, true, fid);
Shinya Kitaoka 120a6e
      TRectD rect02 = TRectD(rect.getP01(), TPointD(rect.x1, 100000.));
Shinya Kitaoka 120a6e
      update(ri, rect02, m_level, true, fid);
Shinya Kitaoka 120a6e
      TRectD rect03 = TRectD(TPointD(rect.x0, -100000.), rect.getP10());
Shinya Kitaoka 120a6e
      update(ri, rect03, m_level, true, fid);
Shinya Kitaoka 120a6e
      TRectD rect04 =
Shinya Kitaoka 120a6e
          TRectD(TPointD(rect.x1, -100000.), TPointD(100000., 100000.));
Shinya Kitaoka 120a6e
      update(ri, rect04, m_level, true, fid);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      update(ri, rect, m_level, true, fid);
Shinya Kitaoka 120a6e
    m_level->getProperties()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
    notifyImageChanged(fid);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorEraserTool::onEnter() {
Shinya Kitaoka 120a6e
  TRasterImageP ti(getImage(false));
Shinya Kitaoka 120a6e
  if (!ti) return;
Toshihiro Shimizu 890ddd
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;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::multiAreaEraser(TFrameId &firstFid, TFrameId &lastFid,
Shinya Kitaoka 120a6e
                                          TStroke *firstStroke,
Shinya Kitaoka 120a6e
                                          TStroke *lastStroke) {
Shinya Kitaoka 120a6e
  TStroke *first           = new TStroke();
Shinya Kitaoka 120a6e
  TStroke *last            = new TStroke();
Shinya Kitaoka 120a6e
  *first                   = *firstStroke;
Shinya Kitaoka 120a6e
  *last                    = *lastStroke;
Shinya Kitaoka 120a6e
  TVectorImageP firstImage = new TVectorImage();
Shinya Kitaoka 120a6e
  TVectorImageP lastImage  = new TVectorImage();
Shinya Kitaoka 120a6e
  firstImage->addStroke(first);
Shinya Kitaoka 120a6e
  lastImage->addStroke(last);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool backward = false;
Shinya Kitaoka 120a6e
  if (firstFid > lastFid) {
otakuto ed7dcd
    std::swap(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
  TUndoManager::manager()->beginBlock();
Shinya Kitaoka 120a6e
  for (int i = 0; i < m; ++i) {
Shinya Kitaoka 120a6e
    TFrameId fid = fids[i];
Shinya Kitaoka 120a6e
    assert(firstFid <= fid && fid <= lastFid);
Shinya Kitaoka 120a6e
    TImageP img = m_level->getFrame(fid, true);
Shinya Kitaoka 120a6e
    double t    = m > 1 ? (double)i / (double)(m - 1) : 0.5;
Shinya Kitaoka 120a6e
    doMultiEraser(img, backward ? 1 - t : t, fid, firstImage, lastImage);
Shinya Kitaoka 120a6e
    m_level->getProperties()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
    notifyImageChanged(fid);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FullColorEraserTool::doMultiEraser(const TImageP &img, double t,
Shinya Kitaoka 120a6e
                                        const TFrameId &fid,
Shinya Kitaoka 120a6e
                                        const TVectorImageP &firstImage,
Shinya Kitaoka 120a6e
                                        const TVectorImageP &lastImage) {
Shinya Kitaoka 120a6e
  int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();
Shinya Kitaoka 120a6e
  if (t == 0)
Shinya Kitaoka 120a6e
    eraseStroke(img, firstImage->getStroke(0), m_eraseType.getValue(),
Shinya Kitaoka 120a6e
                m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level,
Shinya Kitaoka 120a6e
                fid);
Shinya Kitaoka 120a6e
  else if (t == 1)
Shinya Kitaoka 120a6e
    eraseStroke(img, lastImage->getStroke(0), m_eraseType.getValue(),
Shinya Kitaoka 120a6e
                m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level,
Shinya Kitaoka 120a6e
                fid);
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
    eraseStroke(img, vi->getStroke(0), m_eraseType.getValue(),
Shinya Kitaoka 120a6e
                m_invertOption.getValue(), /*m_multi.getValue(),*/ m_level,
Shinya Kitaoka 120a6e
                fid);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}