OpenToonz - An open-source full-featured 2D animation creation software
C
The brush is now centered for any combination of odd and even canvas x and y sizes. Also renamed variables to be clearer.
Martin van Zijle9b9007e2653
diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cppindex 0bd862793..ec896b966 100644--- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp+++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp@@ -1017,6 +1017,23 @@ void ToonzRasterBrushTool::drawEmptyCircle(TPointD pos, int thick,//-------------------------------------------------------------------------------------------------------+TPointD ToonzRasterBrushTool::getCenteredCursorPos(const TPointD &originalCursorPos) {+ TDimension resolution = m_application->getCurrentLevel()->getSimpleLevel()->getProperties()->getImageRes();+ bool xEven = (resolution.lx % 2 == 0);+ bool yEven = (resolution.ly % 2 == 0);++ TPointD centeredCursorPos = originalCursorPos;++ if (xEven)+ centeredCursorPos.x -= 0.5;+ if (yEven)+ centeredCursorPos.y -= 0.5;++ return centeredCursorPos;+}++//-------------------------------------------------------------------------------------------------------+void ToonzRasterBrushTool::updateTranslation() {m_rasThickness.setQStringName(tr("Size"));m_hardness.setQStringName(tr("Hardness:"));@@ -1184,9 +1201,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,// todo: gestire autoenableif (!m_enabled) return;- TPointD modifiedPos = pos;- modifiedPos.x -= 0.5;- modifiedPos.y -= 0.5;+ TPointD centeredPos = getCenteredCursorPos(pos);m_currentColor = TPixel32::Black;m_active = !!getImage(true);@@ -1230,7 +1245,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,thickness = m_rasThickness.getValue().first;TPointD halfThick(maxThick * 0.5, maxThick * 0.5);- TRectD invalidateRect(modifiedPos - halfThick, modifiedPos + halfThick);+ TRectD invalidateRect(centeredPos - halfThick, centeredPos + halfThick);TPointD dpi;ri->getDpi(dpi.x, dpi.y);TRectD previousTipRect(m_brushPos - halfThick, m_brushPos + halfThick);@@ -1248,7 +1263,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,// mypaint brush caseif (m_isMyPaintStyleSelected) {- TPointD point(modifiedPos + rasCenter);+ TPointD point(centeredPos + rasCenter);double pressure =m_pressure.getValue() && e.isTablet() ? e.m_pressure : 0.5;updateCurrentStyle();@@ -1280,7 +1295,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);invalidateRect = convert(m_strokeSegmentRect) - rasCenter;- invalidateRect += TRectD(modifiedPos - thickOffset, modifiedPos + thickOffset);+ invalidateRect += TRectD(centeredPos - thickOffset, centeredPos + thickOffset);invalidateRect +=TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);} else if (m_hardness.getValue() == 100 || m_pencil.getValue()) {@@ -1288,7 +1303,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,* --*/if (!m_pencil.getValue()) thickness -= 1.0;- TThickPoint thickPoint(modifiedPos + convert(ras->getCenter()), thickness);+ TThickPoint thickPoint(centeredPos + convert(ras->getCenter()), thickness);m_rasterTrack = new RasterStrokeGenerator(ras, BRUSH, NONE, m_styleId, thickPoint, drawOrder != OverAll, 0,!m_pencil.getValue(), drawOrder == PaletteOrder);@@ -1309,7 +1324,7 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,}} else {m_points.clear();- TThickPoint point(modifiedPos + rasCenter, thickness);+ TThickPoint point(centeredPos + rasCenter, thickness);m_points.push_back(point);m_bluredBrush = new BluredBrush(m_workRas, maxThick, m_brushPad, false);@@ -1339,9 +1354,8 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,invalidate(invalidateRect.enlarge(2));}// updating m_brushPos is needed to refresh viewer properly- m_brushPos = m_mousePos = pos;- m_brushPos.x -= 0.5;- m_brushPos.y -= 0.5;+ m_mousePos = pos;+ m_brushPos = getCenteredCursorPos(pos);}//-------------------------------------------------------------------------------------------------------------@@ -1349,15 +1363,12 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos,void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,const TMouseEvent &e) {if (!m_enabled || !m_active) {- m_brushPos = m_mousePos = pos;- m_brushPos.x -= 0.5;- m_brushPos.y -= 0.5;+ m_mousePos = pos;+ m_brushPos = getCenteredCursorPos(pos);return;}- TPointD modifiedPos = pos;- modifiedPos.x -= 0.5;- modifiedPos.y -= 0.5;+ TPointD centeredPos = getCenteredCursorPos(pos);TToonzImageP ti = TImageP(getImage(true));TPointD rasCenter = ti->getRaster()->getCenterD();@@ -1368,7 +1379,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,TRectD invalidateRect;if (m_isMyPaintStyleSelected) {TRasterP ras = ti->getRaster();- TPointD point(modifiedPos + rasCenter);+ TPointD point(centeredPos + rasCenter);double pressure =m_pressure.getValue() && e.isTablet() ? e.m_pressure : 0.5;@@ -1384,7 +1395,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);invalidateRect = convert(m_strokeSegmentRect) - rasCenter;- invalidateRect += TRectD(modifiedPos - thickOffset, modifiedPos + thickOffset);+ invalidateRect += TRectD(centeredPos - thickOffset, centeredPos + thickOffset);invalidateRect +=TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);} else if (m_rasterTrack &&@@ -1393,7 +1404,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,* --*/if (!m_pencil.getValue()) thickness -= 1.0;- TThickPoint thickPoint(modifiedPos + rasCenter, thickness);+ TThickPoint thickPoint(centeredPos + rasCenter, thickness);std::vector<TThickPoint> pts;if (m_smooth.getValue() == 0) {pts.push_back(thickPoint);@@ -1422,7 +1433,7 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,} else {// antialiased brushassert(m_workRas.getPointer() && m_backupRas.getPointer());- TThickPoint thickPoint(modifiedPos + rasCenter, thickness);+ TThickPoint thickPoint(centeredPos + rasCenter, thickness);std::vector<TThickPoint> pts;if (m_smooth.getValue() == 0) {pts.push_back(thickPoint);@@ -1473,12 +1484,11 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,if (m_smooth.getValue() != 0) {TPointD halfThick(m_maxThick * 0.5, m_maxThick * 0.5);invalidateRect += TRectD(m_brushPos - halfThick, m_brushPos + halfThick);- invalidateRect += TRectD(modifiedPos - halfThick, modifiedPos + halfThick);+ invalidateRect += TRectD(centeredPos - halfThick, centeredPos + halfThick);}- m_brushPos = m_mousePos = pos;- m_brushPos.x -= 0.5;- m_brushPos.y -= 0.5;+ m_mousePos = pos;+ m_brushPos = getCenteredCursorPos(pos);invalidate(invalidateRect.enlarge(2));}@@ -1493,11 +1503,9 @@ void ToonzRasterBrushTool::leftButtonUp(const TPointD &pos,if (!isValid) {return;}- TPointD modifiedPos = pos;- modifiedPos.x -= 0.5;- modifiedPos.y -= 0.5;+ TPointD centeredPos = getCenteredCursorPos(pos);double pressure = m_pressure.getValue() && e.isTablet() ? e.m_pressure : 0.5;- finishRasterBrush(modifiedPos, pressure);+ finishRasterBrush(centeredPos, pressure);}//---------------------------------------------------------------------------------------------------------------@@ -1783,9 +1791,7 @@ void ToonzRasterBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {} else {m_mousePos = pos;- m_brushPos = pos;- m_brushPos.x -= 0.5;- m_brushPos.y -= 0.5;+ m_brushPos = getCenteredCursorPos(pos);invalidateRect += TRectD(pos - halfThick, pos + halfThick);}diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.h b/toonz/sources/tnztools/toonzrasterbrushtool.hindex 16d1a34c0..9b5829783 100644--- a/toonz/sources/tnztools/toonzrasterbrushtool.h+++ b/toonz/sources/tnztools/toonzrasterbrushtool.h@@ -226,6 +226,8 @@ protected:bool horizontal, bool isDecimal);static void drawEmptyCircle(TPointD point, int thick, bool isLxEven,bool isLyEven, bool isPencil);++ static TPointD getCenteredCursorPos(const TPointD &originalCursorPos);};//------------------------------------------------------------