Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

brush enhancement (#1877)

shun-iwasawad6e799055608
diff --git a/toonz/sources/tnztools/brushtool.cpp b/toonz/sources/tnztools/brushtool.cpp
index fea6f9ef9..b5fa171d1 100644
--- a/toonz/sources/tnztools/brushtool.cpp
+++ b/toonz/sources/tnztools/brushtool.cpp
@@ -752,6 +752,19 @@ void SmoothStroke::generatePoints() {
if (n == 0) {
return;
}
+
+ // if m_smooth = 0, then skip whole smoothing process
+ if (m_smooth == 0) {
+ for (int i = m_outputIndex; i < (int)m_outputPoints.size(); ++i) {
+ if (m_outputPoints[i] != m_rawPoints[i]) {
+ break;
+ }
+ ++m_outputIndex;
+ }
+ m_outputPoints = m_rawPoints;
+ 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,
@@ -869,21 +882,20 @@ BrushTool::BrushTool(std::string name, int targetType)
m_preset.addValue(CUSTOM_WSTR);
m_pressure.setId("PressureSensitivity");
- 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_capStyle.addValue(BUTT_WSTR);
+ m_capStyle.addValue(ROUNDC_WSTR);
+ m_capStyle.addValue(PROJECTING_WSTR);
+ m_capStyle.setId("Cap");
m_prop[1].bind(m_capStyle);
+
+ m_joinStyle.addValue(MITER_WSTR);
+ m_joinStyle.addValue(ROUNDJ_WSTR);
+ m_joinStyle.addValue(BEVEL_WSTR);
+ m_joinStyle.setId("Join");
m_prop[1].bind(m_joinStyle);
+
+ m_miterJoinLimit.setId("Miter");
m_prop[1].bind(m_miterJoinLimit);
}
}
@@ -1096,17 +1108,21 @@ void BrushTool::onActivate() {
TDoublePairProperty::Value(VectorBrushMinSize, VectorBrushMaxSize));
m_rasThickness.setValue(
TDoublePairProperty::Value(RasterBrushMinSize, RasterBrushMaxSize));
- m_capStyle.setIndex(VectorCapStyle);
- m_joinStyle.setIndex(VectorJoinStyle);
- m_miterJoinLimit.setValue(VectorMiterValue);
- if (m_targetType & TTool::ToonzImage) m_drawOrder.setIndex(BrushDrawOrder);
- m_breakAngles.setValue(BrushBreakSharpAngles ? 1 : 0);
- m_pencil.setValue(RasterBrushPencilMode ? 1 : 0);
+ if (m_targetType & TTool::Vectors) {
+ m_capStyle.setIndex(VectorCapStyle);
+ m_joinStyle.setIndex(VectorJoinStyle);
+ m_miterJoinLimit.setValue(VectorMiterValue);
+ m_breakAngles.setValue(BrushBreakSharpAngles ? 1 : 0);
+ m_accuracy.setValue(BrushAccuracy);
+ }
+ if (m_targetType & TTool::ToonzImage) {
+ m_drawOrder.setIndex(BrushDrawOrder);
+ m_pencil.setValue(RasterBrushPencilMode ? 1 : 0);
+ m_hardness.setValue(RasterBrushHardness);
+ }
m_pressure.setValue(BrushPressureSensitivity ? 1 : 0);
m_firstTime = false;
- m_accuracy.setValue(BrushAccuracy);
m_smooth.setValue(BrushSmooth);
- m_hardness.setValue(RasterBrushHardness);
if (m_targetType & TTool::Vectors) {
m_frameRange.setIndex(VectorBrushFrameRange);
m_snap.setValue(VectorBrushSnap);
@@ -2000,16 +2016,19 @@ void BrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
(m_targetType & TTool::ToonzImage) ? m_rasThickness : m_thickness, min,
max);
} else {
+ m_mousePos = pos;
m_brushPos = pos;
- m_mousePos = pos;
- m_firstSnapPoint = pos;
- m_foundFirstSnap = false;
+ if (m_targetType & TTool::Vectors) {
+ m_firstSnapPoint = pos;
+ m_foundFirstSnap = false;
- checkStrokeSnapping(true);
- checkGuideSnapping(true);
- m_brushPos = m_firstSnapPoint;
+ checkStrokeSnapping(true);
+ checkGuideSnapping(true);
+ m_brushPos = m_firstSnapPoint;
+ }
}
+ // TODO: this can be partial update for toonz raster brush
invalidate();
if (m_minThick == 0 && m_maxThick == 0) {
@@ -2157,34 +2176,36 @@ void BrushTool::draw() {
// snapping
TVectorImageP vi = img;
- if ((m_targetType & TTool::Vectors) && m_snap.getValue()) {
- m_pixelSize = getPixelSize();
- double thick = 6.0 * m_pixelSize;
- if (m_foundFirstSnap) {
- tglColor(TPixelD(0.1, 0.9, 0.1));
- tglDrawCircle(m_firstSnapPoint, thick);
- }
+ if (m_targetType & TTool::Vectors) {
+ if (m_snap.getValue()) {
+ m_pixelSize = getPixelSize();
+ double thick = 6.0 * m_pixelSize;
+ if (m_foundFirstSnap) {
+ tglColor(TPixelD(0.1, 0.9, 0.1));
+ tglDrawCircle(m_firstSnapPoint, thick);
+ }
- TThickPoint point2;
+ TThickPoint point2;
- if (m_foundLastSnap) {
- tglColor(TPixelD(0.1, 0.9, 0.1));
- tglDrawCircle(m_lastSnapPoint, thick);
+ if (m_foundLastSnap) {
+ tglColor(TPixelD(0.1, 0.9, 0.1));
+ tglDrawCircle(m_lastSnapPoint, thick);
+ }
}
- }
- // frame range
- if (m_firstStroke) {
- glColor3d(1.0, 0.0, 0.0);
- m_rangeTrack.drawAllFragments();
- glColor3d(0.0, 0.6, 0.0);
- TPointD firstPoint = m_rangeTrack.getFirstPoint();
- TPointD topLeftCorner = TPointD(firstPoint.x - 5, firstPoint.y - 5);
- TPointD topRightCorner = TPointD(firstPoint.x + 5, firstPoint.y - 5);
- TPointD bottomLeftCorner = TPointD(firstPoint.x - 5, firstPoint.y + 5);
- TPointD bottomRightCorner = TPointD(firstPoint.x + 5, firstPoint.y + 5);
- tglDrawSegment(topLeftCorner, bottomRightCorner);
- tglDrawSegment(topRightCorner, bottomLeftCorner);
+ // frame range
+ if (m_firstStroke) {
+ glColor3d(1.0, 0.0, 0.0);
+ m_rangeTrack.drawAllFragments();
+ glColor3d(0.0, 0.6, 0.0);
+ TPointD firstPoint = m_rangeTrack.getFirstPoint();
+ TPointD topLeftCorner = TPointD(firstPoint.x - 5, firstPoint.y - 5);
+ TPointD topRightCorner = TPointD(firstPoint.x + 5, firstPoint.y - 5);
+ TPointD bottomLeftCorner = TPointD(firstPoint.x - 5, firstPoint.y + 5);
+ TPointD bottomRightCorner = TPointD(firstPoint.x + 5, firstPoint.y + 5);
+ tglDrawSegment(topLeftCorner, bottomRightCorner);
+ tglDrawSegment(topRightCorner, bottomLeftCorner);
+ }
}
if (getApplication()->getCurrentObject()->isSpline()) return;
diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
index add8483a2..d3355458d 100644
--- a/toonz/sources/toonz/sceneviewer.cpp
+++ b/toonz/sources/toonz/sceneviewer.cpp
@@ -352,7 +352,7 @@ public:
//-----------------------------------------------------------------------------
/*! emphasize lines with style#1 regardless of the current style
-*/
+ */
class Ink1CheckToggleCommand final : public MenuItemHandler {
public:
Ink1CheckToggleCommand() : MenuItemHandler("MI_Ink1Check") {}
@@ -507,6 +507,8 @@ SceneViewer::SceneViewer(ImageUtils::FullScreenWidget *parent)
grabGesture(Qt::PanGesture);
grabGesture(Qt::PinchGesture);
+ setUpdateBehavior(QOpenGLWidget::PartialUpdate);
+
if (Preferences::instance()->isColorCalibrationEnabled())
m_lutCalibrator = new LutCalibrator();
}
@@ -1357,11 +1359,13 @@ static void drawFpsGraph(int t0, int t1) {
//#define FPS_HISTOGRAM
void SceneViewer::paintGL() {
+#ifdef _DEBUG
if (!check_framebuffer_status()) {
/* QGLWidget の widget 生成/削除のタイミングで(platform によって?)
* GL_FRAMEBUFFER_UNDEFINED の状態で paintGL() が呼ばれてしまうようだ */
return;
}
+#endif
#ifdef MACOSX
// followin lines are necessary to solve a problem on iMac20
// It seems that for some errors in the openGl implementation, buffers are not
@@ -1419,19 +1423,14 @@ void SceneViewer::paintGL() {
drawBuildVars();
- check_framebuffer_status();
- copyFrontBufferToBackBuffer();
+ // This seems not to be necessary for now.
+ // copyFrontBufferToBackBuffer();
- check_framebuffer_status();
drawEnableScissor();
- check_framebuffer_status();
drawBackground();
- check_framebuffer_status();
if (m_previewMode != FULL_PREVIEW) {
- check_framebuffer_status();
drawCameraStand();
- check_framebuffer_status();
}
if (isPreviewEnabled()) drawPreview();
@@ -1694,7 +1693,7 @@ void SceneViewer::invalidateAll() {
//-----------------------------------------------------------------------------
/*! Pan the viewer by using "navigator" (red rectangle) in level strip
-*/
+ */
void SceneViewer::navigatorPan(const QPoint &delta) {
panQt(delta);
m_pos += delta;
@@ -1714,7 +1713,6 @@ void SceneViewer::GLInvalidateAll() {
void SceneViewer::GLInvalidateRect(const TRectD &rect) {
m_clipRect = rect;
update();
- m_clipRect.empty();
if (m_vRuler) m_vRuler->update();
if (m_hRuler) m_hRuler->update();
}
@@ -1803,7 +1801,7 @@ void SceneViewer::zoomQt(bool forward, bool reset) {
//-----------------------------------------------------------------------------
/*! a factor for getting pixel-based zoom ratio
-*/
+ */
double SceneViewer::getDpiFactor() {
// When the current unit is "pixels", always use a standard dpi
if (Preferences::instance()->getPixelsOnly()) {
@@ -2133,7 +2131,7 @@ void SceneViewer::onLevelChanged() {
//-----------------------------------------------------------------------------
/*! when level is switched, update m_dpiScale in order to show white background
* for Ink&Paint work properly
-*/
+ */
void SceneViewer::onLevelSwitched() {
TApp *app = TApp::instance();
TTool *tool = app->getCurrentTool()->getTool();
@@ -2188,7 +2186,7 @@ void SceneViewer::onFrameSwitched() {
//-----------------------------------------------------------------------------
/*! when tool options are changed, update tooltip immediately
-*/
+ */
void SceneViewer::onToolChanged() {
TTool *tool = TApp::instance()->getCurrentTool()->getTool();
if (tool) setToolCursor(this, tool->getCursorId());
@@ -2540,7 +2538,7 @@ TRectD SceneViewer::getGeometry() const {
//-----------------------------------------------------------------------------
/*! delete preview - subcamera executed from context menu
-*/
+ */
void SceneViewer::doDeleteSubCamera() {
PreviewSubCameraManager::instance()->deleteSubCamera(this);
}