OpenToonz - An open-source full-featured 2D animation creation software
C
Merge branch 'master' of https://github.com/opentoonz/opentoonz
walkerkabb91cdfce52c
diff --cc toonz/sources/tnztools/brushtool.cppindex e822b61a5,2f9e23fad..2a7d30f88--- a/toonz/sources/tnztools/brushtool.cpp+++ b/toonz/sources/tnztools/brushtool.cpp@@@ -530,208 -527,18 +528,207 @@@ double computeThickness(int pressure, c//---------------------------------------------------------------------------------------------------------- int computeThickness(int pressure, const TIntPairProperty &property, bool isPath)- {- if (isPath)- return 0.0;- double p = pressure / 255.0;- double t = p * p * p;- int thick0 = property.getValue().first;- int thick1 = property.getValue().second;- return tround(thick0 + (thick1 - thick0) * t);+ int computeThickness(int pressure, const TIntPairProperty &property,+ bool isPath) {+ if (isPath) return 0.0;+ double p = pressure / 255.0;+ double t = p * p * p;+ int thick0 = property.getValue().first;+ int thick1 = property.getValue().second;+ return tround(thick0 + (thick1 - thick0) * t);}- } // namespace+ } // namespace+//--------------------------------------------------------------------------------------------------++static void CatmullRomInterpolate(const TThickPoint& P0, const TThickPoint& P1, const TThickPoint& P2, const TThickPoint& P3, int samples, std::vector<TThickPoint>& points)+{+ double x0 = P1.x;+ double x1 = (-P0.x + P2.x) * 0.5f;+ double x2 = P0.x - 2.5f * P1.x + 2.0f * P2.x - 0.5f * P3.x;+ double x3 = -0.5f * P0.x + 1.5f * P1.x - 1.5f * P2.x + 0.5f * P3.x;++ double y0 = P1.y;+ double y1 = (-P0.y + P2.y) * 0.5f;+ double y2 = P0.y - 2.5f * P1.y + 2.0f * P2.y - 0.5f * P3.y;+ double y3 = -0.5f * P0.y + 1.5f * P1.y - 1.5f * P2.y + 0.5f * P3.y;++ double z0 = P1.thick;+ double z1 = (-P0.thick + P2.thick) * 0.5f;+ double z2 = P0.thick - 2.5f * P1.thick + 2.0f * P2.thick - 0.5f * P3.thick;+ double z3 = -0.5f * P0.thick + 1.5f * P1.thick - 1.5f * P2.thick + 0.5f * P3.thick;++ for (int i = 1; i <= samples; ++i)+ {+ double t = i / (double)(samples + 1);+ double t2 = t * t;+ double t3 = t2 * t;+ TThickPoint p;+ p.x = x0 + x1 * t + x2 * t2 + x3 * t3;+ p.y = y0 + y1 * t + y2 * t2 + y3 * t3;+ p.thick = z0 + z1 * t + z2 * t2 + z3 * t3;+ points.push_back(p);+ }+}++//--------------------------------------------------------------------------------------------------++static void Smooth(std::vector<TThickPoint>& points, int radius)+{+ int n = (int)points.size();+ if (radius < 1 || n < 3)+ {+ return;+ }++ std::vector<TThickPoint> result;++ float d = 1.0f / (radius * 2 + 1);++ for (int i = 1; i < n - 1; ++i)+ {+ int lower = i - radius;+ int upper = i + radius;++ TThickPoint total;+ total.x = 0;+ total.y = 0;+ total.thick = 0;++ for (int j = lower; j <= upper; ++j)+ {+ int idx = j;+ if (idx < 0)+ {+ idx = 0;+ }+ else if (idx >= n)+ {+ idx = n - 1;+ }+ total.x += points[idx].x;+ total.y += points[idx].y;+ total.thick += points[idx].thick;+ }++ total.x *= d;+ total.y *= d;+ total.thick *= d;+ result.push_back(total);+ }++ for (int i = 1; i < n - 1; ++i)+ {+ points[i].x = result[i - 1].x;+ points[i].y = result[i - 1].y;+ points[i].thick = result[i - 1].thick;+ }++ if (points.size() >= 3)+ {+ std::vector<TThickPoint> pts;+ CatmullRomInterpolate(points[0], points[0], points[1], points[2], 10, pts);+ std::vector<TThickPoint>::iterator it = points.begin();+ points.insert(it, pts.begin(), pts.end());++ pts.clear();+ CatmullRomInterpolate(points[n - 3], points[n - 2], points[n - 1], points[n - 1], 10, pts);+ it = points.begin();+ it += n - 1;+ points.insert(it, pts.begin(), pts.end());+ }+}++//--------------------------------------------------------------------------------------------------++void SmoothStroke::beginStroke(int smooth)+{+ m_smooth = smooth;+ m_outputIndex = 0;+ m_readIndex = -1;+ m_rawPoints.clear();+ m_outputPoints.clear();+}++//--------------------------------------------------------------------------------------------------++void SmoothStroke::addPoint(const TThickPoint& point)+{+ if (m_rawPoints.size() > 0 && m_rawPoints.back().x == point.x && m_rawPoints.back().y == point.y)+ {+ return;+ }+ m_rawPoints.push_back(point);+ generatePoints();+}++//--------------------------------------------------------------------------------------------------++void SmoothStroke::endStroke()+{+ generatePoints();+ // force enable the output all segments+ m_outputIndex = m_outputPoints.size() - 1;+}++//--------------------------------------------------------------------------------------------------++void SmoothStroke::getSmoothPoints(std::vector<TThickPoint>& smoothPoints)+{+ int n = m_outputPoints.size();+ for (int i = m_readIndex + 1; i <= m_outputIndex && i < n; ++i)+ {+ smoothPoints.push_back(m_outputPoints[i]);+ }+ m_readIndex = m_outputIndex;+}++//--------------------------------------------------------------------------------------------------++void SmoothStroke::generatePoints()+{+ int n = (int)m_rawPoints.size();+ if (n == 0)+ {+ return;+ }+ std::vector<TThickPoint> smoothedPoints;+ // Add more stroke samples before applying the smoothing+ // This is because the raw inputs points are too few to support smooth result, especially on stroke ends+ smoothedPoints.push_back(m_rawPoints.front());+ for (int i = 1; i < n; ++i)+ {+ const TThickPoint& p1 = m_rawPoints[i - 1];+ const TThickPoint& p2 = m_rawPoints[i];+ const TThickPoint& p0 = i - 2 >= 0 ? m_rawPoints[i - 2] : p1;+ const TThickPoint& p3 = i + 1 < n ? m_rawPoints[i + 1] : p2;++ int samples = 8;+ CatmullRomInterpolate(p0, p1, p2, p3, samples, smoothedPoints);+ smoothedPoints.push_back(p2);+ }+ // Apply the 1D box filter+ // Multiple passes result in better quality and fix the stroke ends break issue+ for (int i = 0; i < 3; ++i)+ {+ Smooth(smoothedPoints, m_smooth);+ }+ // Compare the new smoothed stroke with old one+ // Enable the output for unchanged parts+ int outputNum = (int)m_outputPoints.size();+ for (int i = m_outputIndex; i < outputNum; ++i)+ {+ if (m_outputPoints[i] != smoothedPoints[i])+ {+ break;+ }+ ++m_outputIndex;+ }+ m_outputPoints = smoothedPoints;+}++//===================================================================//// BrushTool@@@ -739,51 -546,70 +736,73 @@@//-----------------------------------------------------------------------------BrushTool::BrushTool(std::string name, int targetType)- : TTool(name), m_thickness("Size", 0, 100, 0, 5), m_rasThickness("Size", 1, 100, 1, 5), m_accuracy("Accuracy:", 1, 100, 20), m_smooth("Smooth:", 0, 50, 0), m_hardness("Hardness:", 0, 100, 100), m_preset("Preset:"), m_selective("Selective", false), m_breakAngles("Break", true), m_pencil("Pencil", false), m_pressure("Pressure", true), m_capStyle("Cap"), m_joinStyle("Join"), m_miterJoinLimit("Miter:", 0, 100, 4), m_rasterTrack(0), m_styleId(0), m_modifiedRegion(), m_bluredBrush(0), m_active(false), m_enabled(false), m_isPrompting(false), m_firstTime(true), m_presetsLoaded(false), m_workingFrameId(TFrameId())- {- bind(targetType);-- if (targetType & TTool::Vectors) {- m_prop[0].bind(m_thickness);- m_prop[0].bind(m_accuracy);- m_prop[0].bind(m_smooth);- m_prop[0].bind(m_breakAngles);- m_breakAngles.setId("BreakSharpAngles");- }-- if (targetType & TTool::ToonzImage) {- m_prop[0].bind(m_rasThickness);- m_prop[0].bind(m_smooth);- m_prop[0].bind(m_hardness);- m_prop[0].bind(m_selective);- m_prop[0].bind(m_pencil);- m_pencil.setId("PencilMode");- m_selective.setId("Selective");- }-- m_prop[0].bind(m_pressure);- m_prop[0].bind(m_preset);- m_preset.setId("BrushPreset");- m_preset.addValue(CUSTOM_WSTR);- m_pressure.setId("PressureSensibility");-- m_capStyle.addValue(BUTT_WSTR);- m_capStyle.addValue(ROUNDC_WSTR);- m_capStyle.addValue(PROJECTING_WSTR);- m_capStyle.setId("Cap");-- m_joinStyle.addValue(MITER_WSTR);- m_joinStyle.addValue(ROUNDJ_WSTR);- m_joinStyle.addValue(BEVEL_WSTR);- m_joinStyle.setId("Join");-- m_miterJoinLimit.setId("Miter");-- if (targetType & TTool::Vectors) {- m_prop[1].bind(m_capStyle);- m_prop[1].bind(m_joinStyle);- m_prop[1].bind(m_miterJoinLimit);- }+ : TTool(name)+ , m_thickness("Size", 0, 100, 0, 5)+ , m_rasThickness("Size", 1, 100, 1, 5)+ , m_accuracy("Accuracy:", 1, 100, 20)++ , m_smooth("Smooth:", 0, 50, 0)+ , m_hardness("Hardness:", 0, 100, 100)+ , m_preset("Preset:")+ , m_selective("Selective", false)+ , m_breakAngles("Break", true)+ , m_pencil("Pencil", false)+ , m_pressure("Pressure", true)+ , m_capStyle("Cap")+ , m_joinStyle("Join")+ , m_miterJoinLimit("Miter:", 0, 100, 4)+ , m_rasterTrack(0)+ , m_styleId(0)+ , m_modifiedRegion()+ , m_bluredBrush(0)+ , m_active(false)+ , m_enabled(false)+ , m_isPrompting(false)+ , m_firstTime(true)+ , m_presetsLoaded(false)+ , m_workingFrameId(TFrameId()) {+ bind(targetType);++ if (targetType & TTool::Vectors) {+ m_prop[0].bind(m_thickness);+ m_prop[0].bind(m_accuracy);++ m_prop[0].bind(m_smooth);+ m_prop[0].bind(m_breakAngles);+ m_breakAngles.setId("BreakSharpAngles");+ }++ if (targetType & TTool::ToonzImage) {+ m_prop[0].bind(m_rasThickness);+ m_prop[0].bind(m_hardness);++ m_prop[0].bind(m_smooth);+ m_prop[0].bind(m_selective);+ m_prop[0].bind(m_pencil);+ m_pencil.setId("PencilMode");+ m_selective.setId("Selective");+ }++ m_prop[0].bind(m_pressure);+ m_prop[0].bind(m_preset);+ m_preset.setId("BrushPreset");+ m_preset.addValue(CUSTOM_WSTR);+ m_pressure.setId("PressureSensibility");++ m_capStyle.addValue(BUTT_WSTR);+ m_capStyle.addValue(ROUNDC_WSTR);+ m_capStyle.addValue(PROJECTING_WSTR);+ m_capStyle.setId("Cap");++ m_joinStyle.addValue(MITER_WSTR);+ m_joinStyle.addValue(ROUNDJ_WSTR);+ m_joinStyle.addValue(BEVEL_WSTR);+ m_joinStyle.setId("Join");++ m_miterJoinLimit.setId("Miter");++ if (targetType & TTool::Vectors) {+ m_prop[1].bind(m_capStyle);+ m_prop[1].bind(m_joinStyle);+ m_prop[1].bind(m_miterJoinLimit);+ }}//-------------------------------------------------------------------------------------------------------@@@ -894,22 -766,20 +959,21 @@@ void BrushTool::drawEmptyCircle(TPoint//-------------------------------------------------------------------------------------------------------- void BrushTool::updateTranslation()- {- m_thickness.setQStringName(tr("Size"));- m_rasThickness.setQStringName(tr("Size"));- m_hardness.setQStringName(tr("Hardness:"));- m_accuracy.setQStringName(tr("Accuracy:"));- m_smooth.setQStringName(tr("Smooth:"));- m_selective.setQStringName(tr("Selective"));- //m_filled.setQStringName(tr("Filled"));- m_preset.setQStringName(tr("Preset:"));- m_breakAngles.setQStringName(tr("Break"));- m_pencil.setQStringName(tr("Pencil"));- m_pressure.setQStringName(tr("Pressure"));- m_capStyle.setQStringName(tr("Cap"));- m_joinStyle.setQStringName(tr("Join"));- m_miterJoinLimit.setQStringName(tr("Miter:"));+ void BrushTool::updateTranslation() {+ m_thickness.setQStringName(tr("Size"));+ m_rasThickness.setQStringName(tr("Size"));+ m_hardness.setQStringName(tr("Hardness:"));+ m_accuracy.setQStringName(tr("Accuracy:"));++ m_smooth.setQStringName(tr("Smooth:"));+ m_selective.setQStringName(tr("Selective"));+ // m_filled.setQStringName(tr("Filled"));+ m_preset.setQStringName(tr("Preset:"));+ m_breakAngles.setQStringName(tr("Break"));+ m_pencil.setQStringName(tr("Pencil"));+ m_pressure.setQStringName(tr("Pressure"));+ m_capStyle.setQStringName(tr("Cap"));+ m_joinStyle.setQStringName(tr("Join"));+ m_miterJoinLimit.setQStringName(tr("Miter:"));}//---------------------------------------------------------------------------------------------------@@@ -943,28 -810,29 +1004,30 @@@ void BrushTool::updateWorkAndBackupRast//---------------------------------------------------------------------------------------------------- void BrushTool::onActivate()- {- if (m_firstTime) {- m_thickness.setValue(TDoublePairProperty::Value(VectorBrushMinSize, VectorBrushMaxSize));- m_rasThickness.setValue(TDoublePairProperty::Value(RasterBrushMinSize, RasterBrushMaxSize));- m_capStyle.setIndex(VectorCapStyle);- m_joinStyle.setIndex(VectorJoinStyle);- m_miterJoinLimit.setValue(VectorMiterValue);- m_selective.setValue(BrushSelective ? 1 : 0);- m_breakAngles.setValue(BrushBreakSharpAngles ? 1 : 0);- m_pencil.setValue(RasterBrushPencilMode ? 1 : 0);- m_pressure.setValue(BrushPressureSensibility ? 1 : 0);- m_firstTime = false;- m_accuracy.setValue(BrushAccuracy);- m_smooth.setValue(BrushSmooth);- m_hardness.setValue(RasterBrushHardness);- }- if (m_targetType & TTool::ToonzImage) {- m_brushPad = ToolUtils::getBrushPad(m_rasThickness.getValue().second, m_hardness.getValue() * 0.01);- setWorkAndBackupImages();- }- //TODO:app->editImageOrSpline();+ void BrushTool::onActivate() {+ if (m_firstTime) {+ m_thickness.setValue(+ TDoublePairProperty::Value(VectorBrushMinSize, VectorBrushMaxSize));+ m_rasThickness.setValue(+ TDoublePairProperty::Value(RasterBrushMinSize, RasterBrushMaxSize));+ m_capStyle.setIndex(VectorCapStyle);+ m_joinStyle.setIndex(VectorJoinStyle);+ m_miterJoinLimit.setValue(VectorMiterValue);+ m_selective.setValue(BrushSelective ? 1 : 0);+ m_breakAngles.setValue(BrushBreakSharpAngles ? 1 : 0);+ m_pencil.setValue(RasterBrushPencilMode ? 1 : 0);+ m_pressure.setValue(BrushPressureSensibility ? 1 : 0);+ m_firstTime = false;+ m_accuracy.setValue(BrushAccuracy);++ m_smooth.setValue(BrushSmooth);+ m_hardness.setValue(RasterBrushHardness);+ }+ if (m_targetType & TTool::ToonzImage) {+ m_brushPad = ToolUtils::getBrushPad(m_rasThickness.getValue().second,+ m_hardness.getValue() * 0.01);+ setWorkAndBackupImages();+ }+ // TODO:app->editImageOrSpline();}//--------------------------------------------------------------------------------------------------@@@ -997,547 -865,406 +1060,556 @@@ bool BrushTool::preLeftButtonDown()//--------------------------------------------------------------------------------------------------- void BrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e)- {- TTool::Application *app = TTool::getApplication();- if (!app)- return;-- int col = app->getCurrentColumn()->getColumnIndex();- m_isPath = app->getCurrentObject()->isSpline();- m_enabled = col >= 0 || m_isPath;- // todo: gestire autoenable- if (!m_enabled)- return;- if (!m_isPath) {- m_currentColor = TPixel32::Black;- m_active = !!getImage(true);- if (!m_active) {- m_active = !!touchImage();- }- if (!m_active)- return;-- if (m_active) {- // nel caso che il colore corrente sia un cleanup/studiopalette color- // oppure il colore di un colorfield- m_styleId = app->getCurrentLevelStyleIndex();- TColorStyle *cs = app->getCurrentLevelStyle();- if (cs) {- TRasterStyleFx *rfx = cs ? cs->getRasterStyleFx() : 0;- m_active = cs != 0 && (cs->isStrokeStyle() || (rfx && rfx->isInkStyle()));- m_currentColor = cs->getAverageColor();- m_currentColor.m = 255;- } else {- m_styleId = 1;- m_currentColor = TPixel32::Black;- }- }- } else {- m_currentColor = TPixel32::Red;- m_active = true;- }- //assert(0<=m_styleId && m_styleId<2);- TImageP img = getImage(true);- TToonzImageP ri(img);- if (ri) {- TRasterCM32P ras = ri->getRaster();- if (ras) {- TPointD rasCenter = ras->getCenterD();- m_tileSet = new TTileSetCM32(ras->getSize());- m_tileSaver = new TTileSaverCM32(ras, m_tileSet);- double maxThick = m_rasThickness.getValue().second;- double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2 : maxThick;-- /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/- if (m_pressure.getValue() && e.m_pressure == 255)- thickness = m_rasThickness.getValue().first;-- TPointD halfThick(maxThick * 0.5, maxThick * 0.5);- TRectD invalidateRect(pos - halfThick, pos + halfThick);- if (m_hardness.getValue() == 100 || m_pencil.getValue()) {- /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/- if (!m_pencil.getValue())- thickness -= 1.0;+ void BrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {+ TTool::Application *app = TTool::getApplication();+ if (!app) return;++ int col = app->getCurrentColumn()->getColumnIndex();+ m_isPath = app->getCurrentObject()->isSpline();+ m_enabled = col >= 0 || m_isPath;+ // todo: gestire autoenable+ if (!m_enabled) return;+ if (!m_isPath) {+ m_currentColor = TPixel32::Black;+ m_active = !!getImage(true);+ if (!m_active) {+ m_active = !!touchImage();+ }+ if (!m_active) return;++ if (m_active) {+ // nel caso che il colore corrente sia un cleanup/studiopalette color+ // oppure il colore di un colorfield+ m_styleId = app->getCurrentLevelStyleIndex();+ TColorStyle *cs = app->getCurrentLevelStyle();+ if (cs) {+ TRasterStyleFx *rfx = cs ? cs->getRasterStyleFx() : 0;+ m_active =+ cs != 0 && (cs->isStrokeStyle() || (rfx && rfx->isInkStyle()));+ m_currentColor = cs->getAverageColor();+ m_currentColor.m = 255;+ } else {+ m_styleId = 1;+ m_currentColor = TPixel32::Black;+ }+ }+ } else {+ m_currentColor = TPixel32::Red;+ m_active = true;+ }+ // assert(0<=m_styleId && m_styleId<2);+ TImageP img = getImage(true);+ TToonzImageP ri(img);+ if (ri) {+ TRasterCM32P ras = ri->getRaster();+ if (ras) {+ TPointD rasCenter = ras->getCenterD();+ m_tileSet = new TTileSetCM32(ras->getSize());+ m_tileSaver = new TTileSaverCM32(ras, m_tileSet);+ double maxThick = m_rasThickness.getValue().second;+ double thickness =+ (m_pressure.getValue() || m_isPath)+ ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2+ : maxThick;++ /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する+ * ---*/+ if (m_pressure.getValue() && e.m_pressure == 255)+ thickness = m_rasThickness.getValue().first;++ TPointD halfThick(maxThick * 0.5, maxThick * 0.5);+ TRectD invalidateRect(pos - halfThick, pos + halfThick);+ if (m_hardness.getValue() == 100 || m_pencil.getValue()) {+ /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる+ * --*/+ if (!m_pencil.getValue()) thickness -= 1.0;-- m_rasterTrack = new RasterStrokeGenerator(- ras, BRUSH, NONE, m_styleId,- TThickPoint(pos + convert(ras->getCenter()), thickness),- m_selective.getValue(), 0, !m_pencil.getValue());- m_tileSaver->save(m_rasterTrack->getLastRect());- m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());- } else {- m_points.clear();- TThickPoint point(pos + rasCenter, thickness);- m_points.push_back(point);- m_bluredBrush = new BluredBrush(m_workRas, maxThick, m_brushPad, false);-- m_strokeRect = m_bluredBrush->getBoundFromPoints(m_points);- updateWorkAndBackupRasters(m_strokeRect);- m_tileSaver->save(m_strokeRect);- m_bluredBrush->addPoint(point, 1);- m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect,- m_styleId, m_selective.getValue());- m_lastRect = m_strokeRect;- }- /*-- 作業中のFidを登録 --*/- m_workingFrameId = getFrameId();++ TThickPoint thickPoint(pos + convert(ras->getCenter()), thickness);- m_rasterTrack = new RasterStrokeGenerator(ras, BRUSH, NONE, m_styleId,- thickPoint,- m_selective.getValue(), 0, !m_pencil.getValue());- m_tileSaver->save(m_rasterTrack->getLastRect());- m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());++ m_rasterTrack = new RasterStrokeGenerator(ras, BRUSH, NONE, m_styleId,++ thickPoint,++ m_selective.getValue(), 0, !m_pencil.getValue());++ m_tileSaver->save(m_rasterTrack->getLastRect());++ m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());++ m_smoothStroke.beginStroke(m_smooth.getValue());+ m_smoothStroke.addPoint(thickPoint);+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);// skip first point because it has been outputted- } else {- m_points.clear();- TThickPoint point(pos + rasCenter, thickness);- m_points.push_back(point);- m_bluredBrush = new BluredBrush(m_workRas, maxThick, m_brushPad, false);-- m_strokeRect = m_bluredBrush->getBoundFromPoints(m_points);- updateWorkAndBackupRasters(m_strokeRect);- m_tileSaver->save(m_strokeRect);- m_bluredBrush->addPoint(point, 1);- m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, m_styleId, m_selective.getValue());- m_lastRect = m_strokeRect;++ } else {++ m_points.clear();++ TThickPoint point(pos + rasCenter, thickness);++ m_points.push_back(point);++ m_bluredBrush = new BluredBrush(m_workRas, maxThick, m_brushPad, false);++++ m_strokeRect = m_bluredBrush->getBoundFromPoints(m_points);++ updateWorkAndBackupRasters(m_strokeRect);++ m_tileSaver->save(m_strokeRect);++ m_bluredBrush->addPoint(point, 1);++ m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, m_styleId, m_selective.getValue());++ m_lastRect = m_strokeRect;++ m_smoothStroke.beginStroke(m_smooth.getValue());+ m_smoothStroke.addPoint(point);+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);// skip first point because it has been outputted- }- /*-- 作業中のFidを登録 --*/- m_workingFrameId = getFrameId();-- invalidate(invalidateRect);- }- } else {- m_track.clear();- double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_thickness, m_isPath) : m_thickness.getValue().second * 0.5;-- /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/- if (m_pressure.getValue() && e.m_pressure == 255)- thickness = m_rasThickness.getValue().first;++ }++ /*-- 作業中のFidを登録 --*/++ m_workingFrameId = getFrameId();- m_smoothStroke.beginStroke(m_smooth.getValue());- addTrackPoint(TThickPoint(pos, thickness), getPixelSize() * getPixelSize());+ invalidate(invalidateRect);+ }+ } else {+ m_track.clear();+ double thickness =+ (m_pressure.getValue() || m_isPath)+ ? computeThickness(e.m_pressure, m_thickness, m_isPath)+ : m_thickness.getValue().second * 0.5;++ /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/+ if (m_pressure.getValue() && e.m_pressure == 255)+ thickness = m_rasThickness.getValue().first;+- m_track.add(TThickPoint(pos, thickness), getPixelSize() * getPixelSize());- }++ m_smoothStroke.beginStroke(m_smooth.getValue());++ addTrackPoint(TThickPoint(pos, thickness), getPixelSize() * getPixelSize());+ }}//-------------------------------------------------------------------------------------------------------------- void BrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)- {- m_brushPos = m_mousePos = pos;-- if (!m_enabled || !m_active)- return;-- bool isAdded;-- if (TToonzImageP ti = TImageP(getImage(true))) {- TPointD rasCenter = ti->getRaster()->getCenterD();- int maxThickness = m_rasThickness.getValue().second;- double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2 : maxThickness;- TRectD invalidateRect;- if (m_rasterTrack && (m_hardness.getValue() == 100 || m_pencil.getValue())) {- /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/- if (!m_pencil.getValue())- thickness -= 1.0;+ void BrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {+ m_brushPos = m_mousePos = pos;++ if (!m_enabled || !m_active) return;++ bool isAdded;++ if (TToonzImageP ti = TImageP(getImage(true))) {+ TPointD rasCenter = ti->getRaster()->getCenterD();+ int maxThickness = m_rasThickness.getValue().second;+ double thickness =+ (m_pressure.getValue() || m_isPath)+ ? computeThickness(e.m_pressure, m_rasThickness, m_isPath) * 2+ : maxThickness;+ TRectD invalidateRect;+ if (m_rasterTrack &&+ (m_hardness.getValue() == 100 || m_pencil.getValue())) {+ /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる+ * --*/+ if (!m_pencil.getValue()) thickness -= 1.0;-- isAdded = m_rasterTrack->add(TThickPoint(pos + rasCenter, thickness));- if (isAdded) {- m_tileSaver->save(m_rasterTrack->getLastRect());- m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());- std::vector<TThickPoint> brushPoints =- m_rasterTrack->getPointsSequence();- int m = (int)brushPoints.size();- std::vector<TThickPoint> points;- if (m == 3) {- points.push_back(brushPoints[0]);- points.push_back(brushPoints[1]);++ TThickPoint thickPoint(pos + rasCenter, thickness);+ m_smoothStroke.addPoint(thickPoint);+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);+ for (size_t i = 0; i < pts.size(); ++i)+ {+ const TThickPoint& thickPoint = pts[i];+ isAdded = m_rasterTrack->add(thickPoint);+ if (isAdded) {+ m_tileSaver->save(m_rasterTrack->getLastRect());+ m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue());+ std::vector<TThickPoint> brushPoints = m_rasterTrack->getPointsSequence();+ int m = (int)brushPoints.size();+ std::vector<TThickPoint> points;+ if (m == 3) {+ points.push_back(brushPoints[0]);+ points.push_back(brushPoints[1]);+ }+ else {+ points.push_back(brushPoints[m - 4]);+ points.push_back(brushPoints[m - 3]);+ points.push_back(brushPoints[m - 2]);+ }+ if (i == 0)+ {+ invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }+ else+ {+ invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }+ }+ }- } else {- //antialiased brush- assert(m_workRas.getPointer() && m_backupRas.getPointer());+ } else {- points.push_back(brushPoints[m - 4]);- points.push_back(brushPoints[m - 3]);- points.push_back(brushPoints[m - 2]);++ //antialiased brush++ assert(m_workRas.getPointer() && m_backupRas.getPointer());+ TThickPoint thickPoint(pos + rasCenter, thickness);+ m_smoothStroke.addPoint(thickPoint);+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);+ bool rectUpdated = false;+ for (size_t i = 0; i < pts.size(); ++i)+ {+ TThickPoint old = m_points.back();+ if (norm2(pos - old) < 4)+ continue;++ const TThickPoint& point = pts[i];+ TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);+ m_points.push_back(mid);+ m_points.push_back(point);++ TRect bbox;+ int m = (int)m_points.size();+ std::vector<TThickPoint> points;+ if (m == 3) {+ // ho appena cominciato. devo disegnare un segmento+ TThickPoint pa = m_points.front();+ points.push_back(pa);+ points.push_back(mid);+ bbox = m_bluredBrush->getBoundFromPoints(points);+ updateWorkAndBackupRasters(bbox + m_lastRect);+ m_tileSaver->save(bbox);+ m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);+ m_lastRect += bbox;+ }+ else {+ points.push_back(m_points[m - 4]);+ points.push_back(old);+ points.push_back(mid);+ bbox = m_bluredBrush->getBoundFromPoints(points);+ updateWorkAndBackupRasters(bbox + m_lastRect);+ m_tileSaver->save(bbox);+ m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1);+ m_lastRect += bbox;+ }+ if (!rectUpdated)+ {+ invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;+ rectUpdated = true;+ }+ else+ {+ invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }++ m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, m_styleId, m_selective.getValue());+ m_strokeRect += bbox;+ }- }- invalidate(invalidateRect.enlarge(2));- } else {- double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_thickness, m_isPath) : m_thickness.getValue().second * 0.5;+ }- invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;- }++ invalidate(invalidateRect.enlarge(2));+ } else {- // antialiased brush- assert(m_workRas.getPointer() && m_backupRas.getPointer());-- TThickPoint old = m_points.back();- if (norm2(pos - old) < 4) return;-- TThickPoint point(pos + rasCenter, thickness);- TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);- m_points.push_back(mid);- m_points.push_back(point);-- TRect bbox;- int m = (int)m_points.size();- std::vector<TThickPoint> points;- if (m == 3) {- // ho appena cominciato. devo disegnare un segmento- TThickPoint pa = m_points.front();- points.push_back(pa);- points.push_back(mid);- bbox = m_bluredBrush->getBoundFromPoints(points);- updateWorkAndBackupRasters(bbox + m_lastRect);- m_tileSaver->save(bbox);- m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);- m_lastRect += bbox;- } else {- points.push_back(m_points[m - 4]);- points.push_back(old);- points.push_back(mid);- bbox = m_bluredBrush->getBoundFromPoints(points);- updateWorkAndBackupRasters(bbox + m_lastRect);- m_tileSaver->save(bbox);- m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1);- m_lastRect += bbox;- }- invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;- m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox,- m_styleId, m_selective.getValue());- m_strokeRect += bbox;- }- invalidate(invalidateRect.enlarge(2));- } else {- double thickness =- (m_pressure.getValue() || m_isPath)- ? computeThickness(e.m_pressure, m_thickness, m_isPath)- : m_thickness.getValue().second * 0.5;- m_track.add(TThickPoint(pos, thickness), getPixelSize() * getPixelSize());-++ double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(e.m_pressure, m_thickness, m_isPath) : m_thickness.getValue().second * 0.5;+ addTrackPoint(TThickPoint(pos, thickness), getPixelSize() * getPixelSize());- invalidate();- }+ invalidate();+ }}//---------------------------------------------------------------------------------------------------------------- void BrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)- {- bool isValid = m_enabled && m_active;- m_enabled = false;+ void BrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {+ bool isValid = m_enabled && m_active;+ m_enabled = false;- if (!isValid)- return;+ if (!isValid) return;- if (m_isPath) {- double error = 20.0 * getPixelSize();+ if (m_isPath) {+ double error = 20.0 * getPixelSize();-+ flushTrackPoint();- TStroke *stroke = m_track.makeStroke(error);- int points = stroke->getControlPointCount();+ TStroke *stroke = m_track.makeStroke(error);+ int points = stroke->getControlPointCount();- if (TVectorImageP vi = getImage(true)) {- struct Cleanup {- BrushTool *m_this;- ~Cleanup() { m_this->m_track.clear(), m_this->invalidate(); }- } cleanup = {this};+ if (TVectorImageP vi = getImage(true)) {+ struct Cleanup {+ BrushTool *m_this;+ ~Cleanup() { m_this->m_track.clear(), m_this->invalidate(); }+ } cleanup = {this};- if (!isJustCreatedSpline(vi.getPointer())) {- m_isPrompting = true;+ if (!isJustCreatedSpline(vi.getPointer())) {+ m_isPrompting = true;- QString question("Are you sure you want to replace the motion path?");- int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"), 0);+ QString question("Are you sure you want to replace the motion path?");+ int ret =+ DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"), 0);- m_isPrompting = false;+ m_isPrompting = false;- if (ret == 2 || ret == 0)- return;- }+ if (ret == 2 || ret == 0) return;+ }- QMutexLocker lock(vi->getMutex());+ QMutexLocker lock(vi->getMutex());- TUndo *undo = new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());+ TUndo *undo =+ new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());- while (vi->getStrokeCount() > 0)- vi->deleteStroke(0);- vi->addStroke(stroke, false);+ while (vi->getStrokeCount() > 0) vi->deleteStroke(0);+ vi->addStroke(stroke, false);- notifyImageChanged();- TUndoManager::manager()->add(undo);- }+ notifyImageChanged();+ TUndoManager::manager()->add(undo);+ }- return;- }+ return;+ }- TImageP image = getImage(true);- if (TVectorImageP vi = image) {- if (m_track.isEmpty()) {- m_styleId = 0;- m_track.clear();- return;- }- m_track.filterPoints();- double error = 30.0 / (1 + 0.5 * m_accuracy.getValue());- error *= getPixelSize();+ TImageP image = getImage(true);+ if (TVectorImageP vi = image) {+ if (m_track.isEmpty()) {+ m_styleId = 0;+ m_track.clear();+ return;+ }+ m_track.filterPoints();+ double error = 30.0 / (1 + 0.5 * m_accuracy.getValue());+ error *= getPixelSize();- flushTrackPoint();- TStroke *stroke = m_track.makeStroke(error);- stroke->setStyle(m_styleId);- {- TStroke::OutlineOptions &options = stroke->outlineOptions();- options.m_capStyle = m_capStyle.getIndex();- options.m_joinStyle = m_joinStyle.getIndex();- options.m_miterUpper = m_miterJoinLimit.getValue();- }- m_styleId = 0;-- QMutexLocker lock(vi->getMutex());- if (stroke->getControlPointCount() == 3 && stroke->getControlPoint(0) != stroke->getControlPoint(2)) // gli stroke con solo 1 chunk vengono fatti dal tape tool...e devono venir riconosciuti come speciali di autoclose proprio dal fatto che hanno 1 solo chunk.- stroke->insertControlPoints(0.5);-- addStrokeToImage(getApplication(), vi, stroke, m_breakAngles.getValue(), m_isFrameCreated, m_isLevelCreated);- TRectD bbox = stroke->getBBox().enlarge(2) + m_track.getModifiedRegion();- invalidate();- assert(stroke);- m_track.clear();- } else if (TToonzImageP ti = image) {- finishRasterBrush(pos, e.m_pressure);- }++ flushTrackPoint();+ TStroke *stroke = m_track.makeStroke(error);+ stroke->setStyle(m_styleId);+ {+ TStroke::OutlineOptions &options = stroke->outlineOptions();+ options.m_capStyle = m_capStyle.getIndex();+ options.m_joinStyle = m_joinStyle.getIndex();+ options.m_miterUpper = m_miterJoinLimit.getValue();+ }+ m_styleId = 0;++ QMutexLocker lock(vi->getMutex());+ if (stroke->getControlPointCount() == 3 &&+ stroke->getControlPoint(0) !=+ stroke->getControlPoint(2)) // gli stroke con solo 1 chunk vengono+ // fatti dal tape tool...e devono venir+ // riconosciuti come speciali di+ // autoclose proprio dal fatto che+ // hanno 1 solo chunk.+ stroke->insertControlPoints(0.5);++ addStrokeToImage(getApplication(), vi, stroke, m_breakAngles.getValue(),+ m_isFrameCreated, m_isLevelCreated);+ TRectD bbox = stroke->getBBox().enlarge(2) + m_track.getModifiedRegion();+ invalidate();+ assert(stroke);+ m_track.clear();+ } else if (TToonzImageP ti = image) {+ finishRasterBrush(pos, e.m_pressure);+ }}+//--------------------------------------------------------------------------------------------------++void BrushTool::addTrackPoint(const TThickPoint& point, double pixelSize2)+{+ m_smoothStroke.addPoint(point);+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);+ for (size_t i = 0; i < pts.size(); ++i)+ {+ m_track.add(pts[i], pixelSize2);+ }+}++//--------------------------------------------------------------------------------------------------++void BrushTool::flushTrackPoint()+{+ m_smoothStroke.endStroke();+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);+ double pixelSize2 = getPixelSize() * getPixelSize();+ for (size_t i = 0; i < pts.size(); ++i)+ {+ m_track.add(pts[i], pixelSize2);+ }+}+//---------------------------------------------------------------------------------------------------------------- /*! ドラッグ中にツールが切り替わった場合に備え、onDeactivate時とMouseRelease時にと同じ終了処理を行う+ /*!+ * ドラッグ中にツールが切り替わった場合に備え、onDeactivate時とMouseRelease時にと同じ終了処理を行う*/- void BrushTool::finishRasterBrush(const TPointD &pos, int pressureVal)- {- TImageP image = getImage(true);- TToonzImageP ti = image;- if (!ti)- return;-- TPointD rasCenter = ti->getRaster()->getCenterD();- TTool::Application *app = TTool::getApplication();- TXshLevel *level = app->getCurrentLevel()->getLevel();- TXshSimpleLevelP simLevel = level->getSimpleLevel();-- /*-- 描画中にカレントフレームが変わっても、描画開始時のFidに対してUndoを記録する --*/- TFrameId frameId = m_workingFrameId.isEmptyFrame() ? getCurrentFid() : m_workingFrameId;-- if (m_rasterTrack && (m_hardness.getValue() == 100 || m_pencil.getValue())) {- double thickness = m_pressure.getValue() ? computeThickness(pressureVal, m_rasThickness, m_isPath) : m_rasThickness.getValue().second;-- /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/- if (m_pressure.getValue() && pressureVal == 255)- thickness = m_rasThickness.getValue().first;-- /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/- if (!m_pencil.getValue())- thickness -= 1.0;+ void BrushTool::finishRasterBrush(const TPointD &pos, int pressureVal) {+ TImageP image = getImage(true);+ TToonzImageP ti = image;+ if (!ti) return;++ TPointD rasCenter = ti->getRaster()->getCenterD();+ TTool::Application *app = TTool::getApplication();+ TXshLevel *level = app->getCurrentLevel()->getLevel();+ TXshSimpleLevelP simLevel = level->getSimpleLevel();++ /*--+ * 描画中にカレントフレームが変わっても、描画開始時のFidに対してUndoを記録する+ * --*/+ TFrameId frameId =+ m_workingFrameId.isEmptyFrame() ? getCurrentFid() : m_workingFrameId;++ if (m_rasterTrack && (m_hardness.getValue() == 100 || m_pencil.getValue())) {+ double thickness =+ m_pressure.getValue()+ ? computeThickness(pressureVal, m_rasThickness, m_isPath)+ : m_rasThickness.getValue().second;++ /*--- ストロークの最初にMaxサイズの円が描かれてしまう不具合を防止する ---*/+ if (m_pressure.getValue() && pressureVal == 255)+ thickness = m_rasThickness.getValue().first;++ /*-- Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる --*/+ if (!m_pencil.getValue()) thickness -= 1.0;-- bool isAdded = m_rasterTrack->add(- TThickPoint(pos + convert(ti->getRaster()->getCenter()), thickness));- if (isAdded) {- m_tileSaver->save(m_rasterTrack->getLastRect());- m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue(), true);-- std::vector<TThickPoint> brushPoints = m_rasterTrack->getPointsSequence();- int m = (int)brushPoints.size();- std::vector<TThickPoint> points;- if (m == 3) {- points.push_back(brushPoints[0]);- points.push_back(brushPoints[1]);- } else {- points.push_back(brushPoints[m - 4]);- points.push_back(brushPoints[m - 3]);- points.push_back(brushPoints[m - 2]);- }- int maxThickness = m_rasThickness.getValue().second;- invalidate(ToolUtils::getBounds(points, maxThickness).enlarge(2) -- rasCenter);- }-- if (m_tileSet->getTileCount() > 0) {- TUndoManager::manager()->add(new RasterBrushUndo(- m_tileSet, m_rasterTrack->getPointsSequence(),- m_rasterTrack->getStyleId(), m_rasterTrack->isSelective(),- simLevel.getPointer(), frameId, m_pencil.getValue(), m_isFrameCreated,- m_isLevelCreated));- }- delete m_rasterTrack;- m_rasterTrack = 0;- } else {- if (m_points.size() != 1) {- double maxThickness = m_rasThickness.getValue().second;- double thickness =- (m_pressure.getValue() || m_isPath)- ? computeThickness(pressureVal, m_rasThickness, m_isPath)- : maxThickness;- TPointD rasCenter = ti->getRaster()->getCenterD();- TThickPoint point(pos + rasCenter, thickness);- m_points.push_back(point);- int m = m_points.size();- std::vector<TThickPoint> points;- points.push_back(m_points[m - 3]);- points.push_back(m_points[m - 2]);- points.push_back(m_points[m - 1]);- TRect bbox = m_bluredBrush->getBoundFromPoints(points);- updateWorkAndBackupRasters(bbox);- m_tileSaver->save(bbox);- m_bluredBrush->addArc(points[0], points[1], points[2], 1, 1);- m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox,- m_styleId, m_selective.getValue());- TRectD invalidateRect = ToolUtils::getBounds(points, maxThickness);- invalidate(invalidateRect.enlarge(2) - rasCenter);- m_strokeRect += bbox;- m_lastRect.empty();- }- delete m_bluredBrush;- m_bluredBrush = 0;++ TRectD invalidateRect;+ TThickPoint thickPoint(pos + rasCenter, thickness);+ m_smoothStroke.addPoint(thickPoint);+ m_smoothStroke.endStroke();+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);+ for (size_t i = 0; i < pts.size(); ++i)+ {+ const TThickPoint& thickPoint = pts[i];+ bool isAdded = m_rasterTrack->add(thickPoint);+ if (isAdded) {+ m_tileSaver->save(m_rasterTrack->getLastRect());+ m_rasterTrack->generateLastPieceOfStroke(m_pencil.getValue(), true);++ std::vector<TThickPoint> brushPoints = m_rasterTrack->getPointsSequence();+ int m = (int)brushPoints.size();+ std::vector<TThickPoint> points;+ if (m == 3) {+ points.push_back(brushPoints[0]);+ points.push_back(brushPoints[1]);+ }+ else {+ points.push_back(brushPoints[m - 4]);+ points.push_back(brushPoints[m - 3]);+ points.push_back(brushPoints[m - 2]);+ }+ int maxThickness = m_rasThickness.getValue().second;+ if (i == 0)+ {+ invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }+ else+ {+ invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }+ }+ }+ invalidate(invalidateRect.enlarge(2));+- if (m_tileSet->getTileCount() > 0) {- TUndoManager::manager()->add(new RasterBrushUndo(m_tileSet,- m_rasterTrack->getPointsSequence(),- m_rasterTrack->getStyleId(),- m_rasterTrack->isSelective(),- simLevel.getPointer(),- frameId, m_pencil.getValue(),- m_isFrameCreated,- m_isLevelCreated));- }- delete m_rasterTrack;- m_rasterTrack = 0;- } else {- if (m_points.size() != 1) {- double maxThickness = m_rasThickness.getValue().second;- double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(pressureVal, m_rasThickness, m_isPath)- : maxThickness;- TPointD rasCenter = ti->getRaster()->getCenterD();++ if (m_tileSet->getTileCount() > 0) {++ TUndoManager::manager()->add(new RasterBrushUndo(m_tileSet,++ m_rasterTrack->getPointsSequence(),++ m_rasterTrack->getStyleId(),++ m_rasterTrack->isSelective(),++ simLevel.getPointer(),++ frameId, m_pencil.getValue(),++ m_isFrameCreated,++ m_isLevelCreated));++ }++ delete m_rasterTrack;++ m_rasterTrack = 0;++ } else {++ if (m_points.size() != 1) {++ double maxThickness = m_rasThickness.getValue().second;++ double thickness = (m_pressure.getValue() || m_isPath) ? computeThickness(pressureVal, m_rasThickness, m_isPath)++ : maxThickness;++ TPointD rasCenter = ti->getRaster()->getCenterD();+ TRectD invalidateRect;+ bool rectUpdated = false;+ TThickPoint thickPoint(pos + rasCenter, thickness);+ m_smoothStroke.addPoint(thickPoint);+ m_smoothStroke.endStroke();+ std::vector<TThickPoint> pts;+ m_smoothStroke.getSmoothPoints(pts);+ for (size_t i = 0; i < pts.size() - 1; ++i)+ {+ TThickPoint old = m_points.back();+ if (norm2(pos - old) < 4)+ continue;++ const TThickPoint& point = pts[i];+ TThickPoint mid((old + point) * 0.5, (point.thick + old.thick) * 0.5);+ m_points.push_back(mid);+ m_points.push_back(point);++ TRect bbox;+ int m = (int)m_points.size();+ std::vector<TThickPoint> points;+ if (m == 3) {+ // ho appena cominciato. devo disegnare un segmento+ TThickPoint pa = m_points.front();+ points.push_back(pa);+ points.push_back(mid);+ bbox = m_bluredBrush->getBoundFromPoints(points);+ updateWorkAndBackupRasters(bbox + m_lastRect);+ m_tileSaver->save(bbox);+ m_bluredBrush->addArc(pa, (mid + pa) * 0.5, mid, 1, 1);+ m_lastRect += bbox;+ }+ else {+ points.push_back(m_points[m - 4]);+ points.push_back(old);+ points.push_back(mid);+ bbox = m_bluredBrush->getBoundFromPoints(points);+ updateWorkAndBackupRasters(bbox + m_lastRect);+ m_tileSaver->save(bbox);+ m_bluredBrush->addArc(m_points[m - 4], old, mid, 1, 1);+ m_lastRect += bbox;+ }+ if (!rectUpdated)+ {+ invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;+ rectUpdated = true;+ }+ else+ {+ invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }++ m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, m_styleId, m_selective.getValue());+ m_strokeRect += bbox;+ }+ if (pts.size() > 0)+ {+ TThickPoint point = pts.back();+ m_points.push_back(point);+ int m = m_points.size();+ std::vector<TThickPoint> points;+ points.push_back(m_points[m - 3]);+ points.push_back(m_points[m - 2]);+ points.push_back(m_points[m - 1]);+ TRect bbox = m_bluredBrush->getBoundFromPoints(points);+ updateWorkAndBackupRasters(bbox);+ m_tileSaver->save(bbox);+ m_bluredBrush->addArc(points[0], points[1], points[2], 1, 1);+ m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, m_styleId, m_selective.getValue());++ if (!rectUpdated)+ {+ invalidateRect = ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }+ else+ {+ invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter;+ }+ m_lastRect += bbox;+ m_strokeRect += bbox;+ }- invalidate(invalidateRect.enlarge(2));- m_lastRect.empty();- }- delete m_bluredBrush;- m_bluredBrush = 0;-- if (m_tileSet->getTileCount() > 0) {- TUndoManager::manager()->add(new RasterBluredBrushUndo(m_tileSet,- m_points,- m_styleId,- m_selective.getValue(),- simLevel.getPointer(),- frameId,- m_rasThickness.getValue().second,- m_hardness.getValue() * 0.01,- m_isFrameCreated,- m_isLevelCreated));- }- }- delete m_tileSaver;++ invalidate(invalidateRect.enlarge(2));++ m_lastRect.empty();++ }++ delete m_bluredBrush;++ m_bluredBrush = 0;++ if (m_tileSet->getTileCount() > 0) {+ TUndoManager::manager()->add(new RasterBluredBrushUndo(+ m_tileSet, m_points, m_styleId, m_selective.getValue(),+ simLevel.getPointer(), frameId, m_rasThickness.getValue().second,+ m_hardness.getValue() * 0.01, m_isFrameCreated, m_isLevelCreated));+ }+ }+ delete m_tileSaver;- m_tileSaver = 0;+ m_tileSaver = 0;- /*-- FIdを指定して、描画中にフレームが動いても、- 描画開始時のFidのサムネイルが更新されるようにする。--*/- notifyImageChanged(frameId);+ /*-- FIdを指定して、描画中にフレームが動いても、+ 描画開始時のFidのサムネイルが更新されるようにする。--*/+ notifyImageChanged(frameId);- m_strokeRect.empty();+ m_strokeRect.empty();- ToolUtils::updateSaveBox();+ ToolUtils::updateSaveBox();- /*-- 作業中のフレームをリセット --*/- m_workingFrameId = TFrameId();+ /*-- 作業中のフレームをリセット --*/+ m_workingFrameId = TFrameId();}//---------------------------------------------------------------------------------------------------------------@@@ -1725,80 -1448,77 +1793,79 @@@ void BrushTool::setWorkAndBackupImages(//------------------------------------------------------------------- bool BrushTool::onPropertyChanged(std::string propertyName)- {- //Set the following to true whenever a different piece of interface must- //be refreshed - done once at the end.- bool notifyTool = false;-- /*--- 変更されたPropertyに合わせて処理を分ける ---*/-- /*--- m_thicknessとm_rasThicknessは同じName(="Size:")なので、- 扱っている画像がラスタかどうかで区別する---*/- if (propertyName == m_thickness.getName()) {- TImageP img = getImage(false);- if (TToonzImageP(img)) //raster- {- RasterBrushMinSize = m_rasThickness.getValue().first;- RasterBrushMaxSize = m_rasThickness.getValue().second;-- m_minThick = m_rasThickness.getValue().first;- m_maxThick = m_rasThickness.getValue().second;- } else //vector- {- VectorBrushMinSize = m_thickness.getValue().first;- VectorBrushMaxSize = m_thickness.getValue().second;-- m_minThick = m_thickness.getValue().first;- m_maxThick = m_thickness.getValue().second;- }- } else if (propertyName == m_accuracy.getName()) {- BrushAccuracy = m_accuracy.getValue();- } else if (propertyName == m_smooth.getName()) {- BrushSmooth = m_smooth.getValue();- } else if (propertyName == m_preset.getName()) {- loadPreset();- notifyTool = true;- } else if (propertyName == m_selective.getName()) {- BrushSelective = m_selective.getValue();- } else if (propertyName == m_breakAngles.getName()) {- BrushBreakSharpAngles = m_breakAngles.getValue();- } else if (propertyName == m_pencil.getName()) {- RasterBrushPencilMode = m_pencil.getValue();- } else if (propertyName == m_pressure.getName()) {- BrushPressureSensibility = m_pressure.getValue();- } else if (propertyName == m_capStyle.getName()) {- VectorCapStyle = m_capStyle.getIndex();- } else if (propertyName == m_joinStyle.getName()) {- VectorJoinStyle = m_joinStyle.getIndex();- } else if (propertyName == m_miterJoinLimit.getName()) {- VectorMiterValue = m_miterJoinLimit.getValue();- }+ bool BrushTool::onPropertyChanged(std::string propertyName) {+ // Set the following to true whenever a different piece of interface must+ // be refreshed - done once at the end.+ bool notifyTool = false;- if (m_targetType & TTool::Vectors) {- if (propertyName == m_joinStyle.getName())- notifyTool = true;- }- if (m_targetType & TTool::ToonzImage) {- if (propertyName == m_hardness.getName())- setWorkAndBackupImages();- if (propertyName == m_hardness.getName() || propertyName == m_thickness.getName()) {- m_brushPad = getBrushPad(m_rasThickness.getValue().second, m_hardness.getValue() * 0.01);- TRectD rect(m_mousePos - TPointD(m_maxThick + 2, m_maxThick + 2),- m_mousePos + TPointD(m_maxThick + 2, m_maxThick + 2));- invalidate(rect);- }- }+ /*--- 変更されたPropertyに合わせて処理を分ける ---*/- if (propertyName != m_preset.getName() && m_preset.getValue() != CUSTOM_WSTR) {- m_preset.setValue(CUSTOM_WSTR);- notifyTool = true;- }+ /*--- m_thicknessとm_rasThicknessは同じName(="Size:")なので、+ 扱っている画像がラスタかどうかで区別する---*/+ if (propertyName == m_thickness.getName()) {+ TImageP img = getImage(false);+ if (TToonzImageP(img)) // raster+ {+ RasterBrushMinSize = m_rasThickness.getValue().first;+ RasterBrushMaxSize = m_rasThickness.getValue().second;- if (notifyTool)- getApplication()->getCurrentTool()->notifyToolChanged();+ m_minThick = m_rasThickness.getValue().first;+ m_maxThick = m_rasThickness.getValue().second;+ } else // vector+ {+ VectorBrushMinSize = m_thickness.getValue().first;+ VectorBrushMaxSize = m_thickness.getValue().second;- return true;+ m_minThick = m_thickness.getValue().first;+ m_maxThick = m_thickness.getValue().second;+ }+ } else if (propertyName == m_accuracy.getName()) {+ BrushAccuracy = m_accuracy.getValue();++ } else if (propertyName == m_smooth.getName()) {++ BrushSmooth = m_smooth.getValue();+ } else if (propertyName == m_preset.getName()) {+ loadPreset();+ notifyTool = true;+ } else if (propertyName == m_selective.getName()) {+ BrushSelective = m_selective.getValue();+ } else if (propertyName == m_breakAngles.getName()) {+ BrushBreakSharpAngles = m_breakAngles.getValue();+ } else if (propertyName == m_pencil.getName()) {+ RasterBrushPencilMode = m_pencil.getValue();+ } else if (propertyName == m_pressure.getName()) {+ BrushPressureSensibility = m_pressure.getValue();+ } else if (propertyName == m_capStyle.getName()) {+ VectorCapStyle = m_capStyle.getIndex();+ } else if (propertyName == m_joinStyle.getName()) {+ VectorJoinStyle = m_joinStyle.getIndex();+ } else if (propertyName == m_miterJoinLimit.getName()) {+ VectorMiterValue = m_miterJoinLimit.getValue();+ }++ if (m_targetType & TTool::Vectors) {+ if (propertyName == m_joinStyle.getName()) notifyTool = true;+ }+ if (m_targetType & TTool::ToonzImage) {+ if (propertyName == m_hardness.getName()) setWorkAndBackupImages();+ if (propertyName == m_hardness.getName() ||+ propertyName == m_thickness.getName()) {+ m_brushPad = getBrushPad(m_rasThickness.getValue().second,+ m_hardness.getValue() * 0.01);+ TRectD rect(m_mousePos - TPointD(m_maxThick + 2, m_maxThick + 2),+ m_mousePos + TPointD(m_maxThick + 2, m_maxThick + 2));+ invalidate(rect);+ }+ }++ if (propertyName != m_preset.getName() &&+ m_preset.getValue() != CUSTOM_WSTR) {+ m_preset.setValue(CUSTOM_WSTR);+ notifyTool = true;+ }++ if (notifyTool) getApplication()->getCurrentTool()->notifyToolChanged();++ return true;}//------------------------------------------------------------------@@@ -1827,75 -1545,72 +1892,75 @@@ void BrushTool::initPresets()//----------------------------------------------------------------------------------------------------------- void BrushTool::loadPreset()- {- const std::set<BrushData> &presets = m_presetsManager.presets();- std::set<BrushData>::const_iterator it;-- it = presets.find(BrushData(m_preset.getValue()));- if (it == presets.end())- return;-- const BrushData &preset = *it;-- try //Don't bother with RangeErrors- {- if (getTargetType() & TTool::Vectors) {- m_thickness.setValue(TDoublePairProperty::Value(preset.m_min, preset.m_max));- m_accuracy.setValue(preset.m_acc, true);- m_smooth.setValue(preset.m_smooth, true);- m_breakAngles.setValue(preset.m_breakAngles);- m_pressure.setValue(preset.m_pressure);- m_capStyle.setIndex(preset.m_cap);- m_joinStyle.setIndex(preset.m_join);- m_miterJoinLimit.setValue(preset.m_miter);- } else {- m_rasThickness.setValue(TDoublePairProperty::Value(std::max(preset.m_min, 1.0), preset.m_max));- m_brushPad = ToolUtils::getBrushPad(preset.m_max, preset.m_hardness * 0.01);- m_smooth.setValue(preset.m_smooth, true);- m_hardness.setValue(preset.m_hardness, true);- m_selective.setValue(preset.m_selective);- m_pencil.setValue(preset.m_pencil);- m_pressure.setValue(preset.m_pressure);- }- } catch (...) {- }+ void BrushTool::loadPreset() {+ const std::set<BrushData> &presets = m_presetsManager.presets();+ std::set<BrushData>::const_iterator it;++ it = presets.find(BrushData(m_preset.getValue()));+ if (it == presets.end()) return;++ const BrushData &preset = *it;++ try // Don't bother with RangeErrors+ {+ if (getTargetType() & TTool::Vectors) {+ m_thickness.setValue(+ TDoublePairProperty::Value(preset.m_min, preset.m_max));+ m_accuracy.setValue(preset.m_acc, true);++ m_smooth.setValue(preset.m_smooth, true);+ m_breakAngles.setValue(preset.m_breakAngles);+ m_pressure.setValue(preset.m_pressure);+ m_capStyle.setIndex(preset.m_cap);+ m_joinStyle.setIndex(preset.m_join);+ m_miterJoinLimit.setValue(preset.m_miter);+ } else {+ m_rasThickness.setValue(TDoublePairProperty::Value(+ std::max(preset.m_min, 1.0), preset.m_max));+ m_brushPad =+ ToolUtils::getBrushPad(preset.m_max, preset.m_hardness * 0.01);++ m_smooth.setValue(preset.m_smooth, true);+ m_hardness.setValue(preset.m_hardness, true);+ m_selective.setValue(preset.m_selective);+ m_pencil.setValue(preset.m_pencil);+ m_pressure.setValue(preset.m_pressure);+ }+ } catch (...) {+ }}//------------------------------------------------------------------- void BrushTool::addPreset(QString name)- {- //Build the preset- BrushData preset(name.toStdWString());-- if (getTargetType() & TTool::Vectors) {- preset.m_min = m_thickness.getValue().first;- preset.m_max = m_thickness.getValue().second;- } else {- preset.m_min = m_rasThickness.getValue().first;- preset.m_max = m_rasThickness.getValue().second;- }-- preset.m_acc = m_accuracy.getValue();- preset.m_smooth = m_smooth.getValue();- preset.m_hardness = m_hardness.getValue();- preset.m_selective = m_selective.getValue();- preset.m_pencil = m_pencil.getValue();- preset.m_breakAngles = m_breakAngles.getValue();- preset.m_pressure = m_pressure.getValue();- preset.m_cap = m_capStyle.getIndex();- preset.m_join = m_joinStyle.getIndex();- preset.m_miter = m_miterJoinLimit.getValue();-- //Pass the preset to the manager- m_presetsManager.addPreset(preset);-- //Reinitialize the associated preset enum- initPresets();-- //Set the value to the specified one- m_preset.setValue(preset.m_name);+ void BrushTool::addPreset(QString name) {+ // Build the preset+ BrushData preset(name.toStdWString());++ if (getTargetType() & TTool::Vectors) {+ preset.m_min = m_thickness.getValue().first;+ preset.m_max = m_thickness.getValue().second;+ } else {+ preset.m_min = m_rasThickness.getValue().first;+ preset.m_max = m_rasThickness.getValue().second;+ }++ preset.m_acc = m_accuracy.getValue();++ preset.m_smooth = m_smooth.getValue()+ preset.m_hardness = m_hardness.getValue();+ preset.m_selective = m_selective.getValue();+ preset.m_pencil = m_pencil.getValue();+ preset.m_breakAngles = m_breakAngles.getValue();+ preset.m_pressure = m_pressure.getValue();+ preset.m_cap = m_capStyle.getIndex();+ preset.m_join = m_joinStyle.getIndex();+ preset.m_miter = m_miterJoinLimit.getValue();++ // Pass the preset to the manager+ m_presetsManager.addPreset(preset);++ // Reinitialize the associated preset enum+ initPresets();++ // Set the value to the specified one+ m_preset.setValue(preset.m_name);}//------------------------------------------------------------------@@@ -1933,99 -1645,114 +1995,121 @@@ BrushTool toonzPencil("T_Brush", TTool://*******************************************************************************BrushData::BrushData()- : m_name(), m_min(0.0), m_max(0.0), m_acc(0.0), m_smooth(0.0), m_hardness(0.0), m_opacityMin(0.0), m_opacityMax(0.0), m_selective(false), m_pencil(false), m_breakAngles(false), m_pressure(false), m_cap(0), m_join(0), m_miter(0)- {- }+ : m_name()+ , m_min(0.0)+ , m_max(0.0)+ , m_acc(0.0)++ , m_smooth(0.0)+ , m_hardness(0.0)+ , m_opacityMin(0.0)+ , m_opacityMax(0.0)+ , m_selective(false)+ , m_pencil(false)+ , m_breakAngles(false)+ , m_pressure(false)+ , m_cap(0)+ , m_join(0)+ , m_miter(0) {}//----------------------------------------------------------------------------------------------------------BrushData::BrushData(const std::wstring &name)- : m_name(name), m_min(0.0), m_max(0.0), m_acc(0.0), m_smooth(0.0), m_hardness(0.0), m_opacityMin(0.0), m_opacityMax(0.0), m_selective(false), m_pencil(false), m_breakAngles(false), m_pressure(false), m_cap(0), m_join(0), m_miter(0)- {- }+ : m_name(name)+ , m_min(0.0)+ , m_max(0.0)+ , m_acc(0.0)++ , m_smooth(0.0)+ , m_hardness(0.0)+ , m_opacityMin(0.0)+ , m_opacityMax(0.0)+ , m_selective(false)+ , m_pencil(false)+ , m_breakAngles(false)+ , m_pressure(false)+ , m_cap(0)+ , m_join(0)+ , m_miter(0) {}//----------------------------------------------------------------------------------------------------------- void BrushData::saveData(TOStream &os)- {- os.openChild("Name");- os << m_name;- os.closeChild();- os.openChild("Thickness");- os << m_min << m_max;- os.closeChild();- os.openChild("Accuracy");- os << m_acc;- os.closeChild();- os.openChild("Smooth");- os << m_smooth;- os.closeChild();- os.openChild("Hardness");- os << m_hardness;- os.closeChild();- os.openChild("Opacity");- os << m_opacityMin << m_opacityMax;- os.closeChild();- os.openChild("Selective");- os << (int)m_selective;- os.closeChild();- os.openChild("Pencil");- os << (int)m_pencil;- os.closeChild();- os.openChild("Break_Sharp_Angles");- os << (int)m_breakAngles;- os.closeChild();- os.openChild("Pressure_Sensitivity");- os << (int)m_pressure;- os.closeChild();- os.openChild("Cap");- os << m_cap;- os.closeChild();- os.openChild("Join");- os << m_join;- os.closeChild();- os.openChild("Miter");- os << m_miter;- os.closeChild();+ void BrushData::saveData(TOStream &os) {+ os.openChild("Name");+ os << m_name;+ os.closeChild();+ os.openChild("Thickness");+ os << m_min << m_max;+ os.closeChild();+ os.openChild("Accuracy");+ os << m_acc;+ os.closeChild();++ os.openChild("Smooth");++ os << m_smooth;++ os.closeChild();+ os.openChild("Hardness");+ os << m_hardness;+ os.closeChild();+ os.openChild("Opacity");+ os << m_opacityMin << m_opacityMax;+ os.closeChild();+ os.openChild("Selective");+ os << (int)m_selective;+ os.closeChild();+ os.openChild("Pencil");+ os << (int)m_pencil;+ os.closeChild();+ os.openChild("Break_Sharp_Angles");+ os << (int)m_breakAngles;+ os.closeChild();+ os.openChild("Pressure_Sensitivity");+ os << (int)m_pressure;+ os.closeChild();+ os.openChild("Cap");+ os << m_cap;+ os.closeChild();+ os.openChild("Join");+ os << m_join;+ os.closeChild();+ os.openChild("Miter");+ os << m_miter;+ os.closeChild();}//----------------------------------------------------------------------------------------------------------- void BrushData::loadData(TIStream &is)- {- std::string tagName;- int val;-- while (is.matchTag(tagName)) {- if (tagName == "Name")- is >> m_name, is.matchEndTag();- else if (tagName == "Thickness")- is >> m_min >> m_max, is.matchEndTag();- else if (tagName == "Accuracy")- is >> m_acc, is.matchEndTag();- else if (tagName == "Smooth")- is >> m_smooth, is.matchEndTag();- else if (tagName == "Hardness")- is >> m_hardness, is.matchEndTag();- else if (tagName == "Opacity")- is >> m_opacityMin >> m_opacityMax, is.matchEndTag();- else if (tagName == "Selective")- is >> val, m_selective = val, is.matchEndTag();- else if (tagName == "Pencil")- is >> val, m_pencil = val, is.matchEndTag();- else if (tagName == "Break_Sharp_Angles")- is >> val, m_breakAngles = val, is.matchEndTag();- else if (tagName == "Pressure_Sensitivity")- is >> val, m_pressure = val, is.matchEndTag();- else if (tagName == "Cap")- is >> m_cap, is.matchEndTag();- else if (tagName == "Join")- is >> m_join, is.matchEndTag();- else if (tagName == "Miter")- is >> m_miter, is.matchEndTag();- else- is.skipCurrentTag();- }+ void BrushData::loadData(TIStream &is) {+ std::string tagName;+ int val;++ while (is.matchTag(tagName)) {+ if (tagName == "Name")+ is >> m_name, is.matchEndTag();+ else if (tagName == "Thickness")+ is >> m_min >> m_max, is.matchEndTag();+ else if (tagName == "Accuracy")+ is >> m_acc, is.matchEndTag();++ else if (tagName == "Smooth")++ is >> m_smooth, is.matchEndTag();+ else if (tagName == "Hardness")+ is >> m_hardness, is.matchEndTag();+ else if (tagName == "Opacity")+ is >> m_opacityMin >> m_opacityMax, is.matchEndTag();+ else if (tagName == "Selective")+ is >> val, m_selective = val, is.matchEndTag();+ else if (tagName == "Pencil")+ is >> val, m_pencil = val, is.matchEndTag();+ else if (tagName == "Break_Sharp_Angles")+ is >> val, m_breakAngles = val, is.matchEndTag();+ else if (tagName == "Pressure_Sensitivity")+ is >> val, m_pressure = val, is.matchEndTag();+ else if (tagName == "Cap")+ is >> m_cap, is.matchEndTag();+ else if (tagName == "Join")+ is >> m_join, is.matchEndTag();+ else if (tagName == "Miter")+ is >> m_miter, is.matchEndTag();+ else+ is.skipCurrentTag();+ }}//----------------------------------------------------------------------------------------------------------diff --cc toonz/sources/tnztools/brushtool.hindex 1b2cff484,695ec82a1..5d5cedd6c--- a/toonz/sources/tnztools/brushtool.h+++ b/toonz/sources/tnztools/brushtool.h@@@ -32,188 -32,150 +32,190 @@@ class BluredBrush//************************************************************************struct BrushData : public TPersist {- PERSIST_DECLARATION(BrushData)+ PERSIST_DECLARATION(BrushData)- std::wstring m_name;- double m_min, m_max, m_acc, m_smooth, m_hardness, m_opacityMin, m_opacityMax;- bool m_selective, m_pencil, m_breakAngles, m_pressure;- int m_cap, m_join, m_miter;++ double m_min, m_max, m_acc, m_smooth, m_hardness, m_opacityMin, m_opacityMax;+ std::wstring m_name;+ double m_min, m_max, m_acc, m_hardness, m_opacityMin, m_opacityMax;+ bool m_selective, m_pencil, m_breakAngles, m_pressure;+ int m_cap, m_join, m_miter;- BrushData();- BrushData(const std::wstring &name);+ BrushData();+ BrushData(const std::wstring &name);- bool operator<(const BrushData &other) const { return m_name < other.m_name; }+ bool operator<(const BrushData &other) const { return m_name < other.m_name; }- void saveData(TOStream &os);- void loadData(TIStream &is);+ void saveData(TOStream &os);+ void loadData(TIStream &is);};//************************************************************************// Brush Preset Manager declaration//************************************************************************- class BrushPresetManager- {- TFilePath m_fp; //!< Presets file path- std::set<BrushData> m_presets; //!< Current presets container+ class BrushPresetManager {+ TFilePath m_fp; //!< Presets file path+ std::set<BrushData> m_presets; //!< Current presets containerpublic:- BrushPresetManager() {}+ BrushPresetManager() {}- void load(const TFilePath &fp);- void save();+ void load(const TFilePath &fp);+ void save();- const TFilePath &path() { return m_fp; };- const std::set<BrushData> &presets() const { return m_presets; }+ const TFilePath &path() { return m_fp; };+ const std::set<BrushData> &presets() const { return m_presets; }- void addPreset(const BrushData &data);- void removePreset(const std::wstring &name);+ void addPreset(const BrushData &data);+ void removePreset(const std::wstring &name);};+//************************************************************************+// Smooth Stroke declaration+// Brush stroke smoothing buffer.+//************************************************************************+class SmoothStroke+{+public:+ SmoothStroke() {}+ ~SmoothStroke() {}++ // begin stroke+ // smooth is smooth strength, from 0 to 100+ void beginStroke(int smooth);+ // add stroke point+ void addPoint(const TThickPoint& point);+ // end stroke+ void endStroke();+ // Get generated stroke points which has been smoothed.+ // Both addPoint() and endStroke() generate new smoothed points.+ // This method will removed generated points+ void getSmoothPoints(std::vector<TThickPoint>& smoothPoints);++private:+ void generatePoints();++private:+ int m_smooth;+ int m_outputIndex;+ int m_readIndex;+ std::vector<TThickPoint> m_rawPoints;+ std::vector<TThickPoint> m_outputPoints;+};//************************************************************************// Brush Tool declaration//************************************************************************- class BrushTool : public TTool- {- Q_DECLARE_TR_FUNCTIONS(BrushTool)+ class BrushTool : public TTool {+ Q_DECLARE_TR_FUNCTIONS(BrushTool)public:- BrushTool(std::string name, int targetType);+ BrushTool(std::string name, int targetType);- ToolType getToolType() const { return TTool::LevelWriteTool; }+ ToolType getToolType() const { return TTool::LevelWriteTool; }- ToolOptionsBox *createOptionsBox();+ ToolOptionsBox *createOptionsBox();- void updateTranslation();+ void updateTranslation();- void onActivate();- void onDeactivate();+ void onActivate();+ void onDeactivate();- bool preLeftButtonDown();- void leftButtonDown(const TPointD &pos, const TMouseEvent &e);- void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);- void leftButtonUp(const TPointD &pos, const TMouseEvent &e);- void mouseMove(const TPointD &pos, const TMouseEvent &e);+ bool preLeftButtonDown();+ void leftButtonDown(const TPointD &pos, const TMouseEvent &e);+ void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);+ void leftButtonUp(const TPointD &pos, const TMouseEvent &e);+ void mouseMove(const TPointD &pos, const TMouseEvent &e);- void draw();+ void draw();- void onEnter();- void onLeave();+ void onEnter();+ void onLeave();- int getCursorId() const { return ToolCursor::PenCursor; }+ int getCursorId() const { return ToolCursor::PenCursor; }- TPropertyGroup *getProperties(int targetType);- bool onPropertyChanged(std::string propertyName);+ TPropertyGroup *getProperties(int targetType);+ bool onPropertyChanged(std::string propertyName);- void onImageChanged();- void setWorkAndBackupImages();- void updateWorkAndBackupRasters(const TRect &rect);+ void onImageChanged();+ void setWorkAndBackupImages();+ void updateWorkAndBackupRasters(const TRect &rect);- void initPresets();- void loadPreset();- void addPreset(QString name);- void removePreset();+ void initPresets();+ void loadPreset();+ void addPreset(QString name);+ void removePreset();- void finishRasterBrush(const TPointD &pos, int pressureVal);- //return true if the pencil mode is active in the Brush / PaintBrush / Eraser Tools.- bool isPencilModeActive();+ void finishRasterBrush(const TPointD &pos, int pressureVal);+ // return true if the pencil mode is active in the Brush / PaintBrush / Eraser+ // Tools.+ bool isPencilModeActive();+ void addTrackPoint(const TThickPoint& point, double pixelSize2);+ void flushTrackPoint();+protected:- TPropertyGroup m_prop[2];-- TDoublePairProperty m_thickness;- TDoublePairProperty m_rasThickness;- TDoubleProperty m_accuracy;- TDoubleProperty m_smooth;- TDoubleProperty m_hardness;- TEnumProperty m_preset;- TBoolProperty m_selective;- TBoolProperty m_breakAngles;- TBoolProperty m_pencil;- TBoolProperty m_pressure;- TEnumProperty m_capStyle;- TEnumProperty m_joinStyle;- TIntProperty m_miterJoinLimit;-- StrokeGenerator m_track;- RasterStrokeGenerator *m_rasterTrack;-- TTileSetCM32 *m_tileSet;- TTileSaverCM32 *m_tileSaver;-- TPixel32 m_currentColor;- int m_styleId;- double m_minThick, m_maxThick;-- TRectD m_modifiedRegion;- TPointD m_dpiScale,- m_mousePos, //!< Current mouse position, in world coordinates.- m_brushPos; //!< World position the brush will be painted at.-- BluredBrush *m_bluredBrush;- QRadialGradient m_brushPad;-- TRasterCM32P m_backupRas;- TRaster32P m_workRas;-- std::vector<TThickPoint> m_points;- TRect m_strokeRect,- m_lastRect;-- SmoothStroke m_smoothStroke;-- BrushPresetManager m_presetsManager; //!< Manager for presets of this tool instance-- bool m_active,- m_enabled,- m_isPrompting, //!< Whether the tool is prompting for spline substitution.- m_firstTime,- m_isPath,- m_presetsLoaded;-- /*--- 作業中のFrameIdをクリック時に保存し、マウスリリース時(Undoの登録時)に別のフレームに- 移動していたときの不具合を修正する。---*/- TFrameId m_workingFrameId;+ TPropertyGroup m_prop[2];++++ TDoublePairProperty m_thickness;+ TDoublePairProperty m_rasThickness;+ TDoubleProperty m_accuracy;++ TDoubleProperty m_smooth;+ TDoubleProperty m_hardness;+ TEnumProperty m_preset;+ TBoolProperty m_selective;+ TBoolProperty m_breakAngles;+ TBoolProperty m_pencil;+ TBoolProperty m_pressure;+ TEnumProperty m_capStyle;+ TEnumProperty m_joinStyle;+ TIntProperty m_miterJoinLimit;++ StrokeGenerator m_track;+ RasterStrokeGenerator *m_rasterTrack;++ TTileSetCM32 *m_tileSet;+ TTileSaverCM32 *m_tileSaver;++ TPixel32 m_currentColor;+ int m_styleId;+ double m_minThick, m_maxThick;++ TRectD m_modifiedRegion;+ TPointD m_dpiScale,+ m_mousePos, //!< Current mouse position, in world coordinates.+ m_brushPos; //!< World position the brush will be painted at.++ BluredBrush *m_bluredBrush;+ QRadialGradient m_brushPad;++ TRasterCM32P m_backupRas;+ TRaster32P m_workRas;++ std::vector<TThickPoint> m_points;+ TRect m_strokeRect, m_lastRect;+++ SmoothStroke m_smoothStroke;+++ BrushPresetManager+ m_presetsManager; //!< Manager for presets of this tool instance++ bool m_active, m_enabled,+ m_isPrompting, //!< Whether the tool is prompting for spline+ //!substitution.+ m_firstTime, m_isPath, m_presetsLoaded;++ /*---+ 作業中のFrameIdをクリック時に保存し、マウスリリース時(Undoの登録時)に別のフレームに+ 移動していたときの不具合を修正する。---*/+ TFrameId m_workingFrameId;protected:- static void drawLine(const TPointD &point, const TPointD ¢re, bool horizontal, bool isDecimal);- static void drawEmptyCircle(TPointD point, int thick, bool isLxEven, bool isLyEven, bool isPencil);+ static void drawLine(const TPointD &point, const TPointD ¢re,+ bool horizontal, bool isDecimal);+ static void drawEmptyCircle(TPointD point, int thick, bool isLxEven,+ bool isLyEven, bool isPencil);};- #endif //BRUSHTOOL_H+ #endif // BRUSHTOOL_H