Skip to content

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

C

#assistants: merge with master

Ivan Mahonin145ef44b8731
diff --cc toonz/sources/tnztools/fullcolorbrushtool.cpp
index 0204fe08d,eda00f43c..8675b4a95
--- a/toonz/sources/tnztools/fullcolorbrushtool.cpp
+++ b/toonz/sources/tnztools/fullcolorbrushtool.cpp
@@@ -312,50 -303,219 +312,50 @@@ bool FullColorBrushTool::preLeftButtonD
//---------------------------------------------------------------------------------------------------
-void FullColorBrushTool::leftButtonDown(const TPointD &pos,
- const TMouseEvent &e) {
- TPointD previousBrushPos = m_brushPos;
- m_brushPos = m_mousePos = pos;
- m_mousePressed = true;
- m_mouseEvent = e;
- Viewer *viewer = getViewer();
- if (!viewer) return;
-
- TRasterImageP ri = (TRasterImageP)getImage(true);
- if (!ri) ri = (TRasterImageP)touchImage();
-
- if (!ri) return;
-
- // Modifier to do straight line
- if (e.isShiftPressed()) {
- m_isStraight = true;
- m_firstPoint = pos;
- m_lastPoint = pos;
+void FullColorBrushTool::handleMouseEvent(MouseEventType type, const TPointD &pos, const TMouseEvent &e) {
+ TTimerTicks t = TToolTimer::ticks();
+ bool alt = e.getModifiersMask() & TMouseEvent::ALT_KEY;
+ bool shift = e.getModifiersMask() & TMouseEvent::SHIFT_KEY;
+ bool control = e.getModifiersMask() & TMouseEvent::CTRL_KEY;
+
- if ((control || shift) && type == ME_DOWN && e.button() == Qt::LeftButton && !m_started) {
++ if (shift && type == ME_DOWN && e.button() == Qt::LeftButton && !m_started) {
+ m_modifierAssistants->drawOnly = true;
+ m_inputmanager.clearModifiers();
+ m_inputmanager.addModifier( TInputModifierP(m_modifierLine.getPointer()) );
+ m_inputmanager.addModifier( TInputModifierP(m_modifierAssistants.getPointer()) );
+ m_inputmanager.addModifier( TInputModifierP(m_modifierSegmentation.getPointer()) );
+ m_inputmanager.drawPreview = true;
}
-
- /* update color here since the current style might be switched with numpad
- * shortcut keys */
- updateCurrentStyle();
-
- TRasterP ras = ri->getRaster();
-
- if (!(m_workRaster && m_backUpRas)) setWorkAndBackupImages();
-
- m_workRaster->lock();
-
- TPointD rasCenter = ras->getCenterD();
- TPointD point(pos + rasCenter);
-
- double pressure;
- if (getApplication()->getCurrentLevelStyle()->getTagId() ==
- 4001) // mypaint brush case
- pressure = m_enabledPressure && e.isTablet() ? e.m_pressure : 0.5;
- else
- pressure = m_enabledPressure ? e.m_pressure : 1.0;
-
- m_tileSet = new TTileSetFullColor(ras->getSize());
- m_tileSaver = new TTileSaverFullColor(ras, m_tileSet);
-
- mypaint::Brush mypaintBrush;
- applyToonzBrushSettings(mypaintBrush);
- m_toonz_brush = new MyPaintToonzBrush(m_workRaster, *this, mypaintBrush);
-
- m_strokeRect.empty();
- m_strokeSegmentRect.empty();
- m_toonz_brush->beginStroke();
- m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
- TRect updateRect = m_strokeSegmentRect * ras->getBounds();
- if (!updateRect.isEmpty())
- ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
-
- TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
- TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
- invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
- invalidateRect +=
- TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
- invalidate(invalidateRect.enlarge(2.0));
-}
-
-//-------------------------------------------------------------------------------------------------------------
-
-void FullColorBrushTool::leftButtonDrag(const TPointD &pos,
- const TMouseEvent &e) {
- TRectD invalidateRect;
- m_lastPoint = pos;
-
- TPointD previousBrushPos = m_brushPos;
- m_brushPos = m_mousePos = pos;
- m_mouseEvent = e;
- TRasterImageP ri = (TRasterImageP)getImage(true);
- if (!ri) return;
-
- if (!m_toonz_brush) return;
-
- TRasterP ras = ri->getRaster();
- TPointD rasCenter = ras->getCenterD();
- TPointD point(pos + rasCenter);
- double pressure;
- if (getApplication()->getCurrentLevelStyle()->getTagId() ==
- 4001) // mypaint brush case
- pressure = m_enabledPressure && e.isTablet() ? e.m_pressure : 0.5;
- else
- pressure = m_enabledPressure ? e.m_pressure : 1.0;
-
- if (m_maxPressure < pressure) m_maxPressure = pressure;
-
- if (m_isStraight) {
- invalidateRect = TRectD(m_firstPoint, m_lastPoint).enlarge(2);
- if (e.isCtrlPressed()) {
- double distance = (m_brushPos.x - m_maxCursorThick + 1) * 0.5;
- TRectD brushRect =
- TRectD(TPointD(m_brushPos.x - distance, m_brushPos.y - distance),
- TPointD(m_brushPos.x + distance, m_brushPos.y + distance));
- invalidateRect += (brushRect);
- double denominator = m_lastPoint.x - m_firstPoint.x;
- if (denominator == 0) denominator = 0.001;
- double slope = ((m_lastPoint.y - m_firstPoint.y) / denominator);
- double angle = std::atan(slope) * (180 / 3.14159);
- if (abs(angle) > 67.5)
- m_lastPoint.x = m_firstPoint.x;
- else if (abs(angle) < 22.5)
- m_lastPoint.y = m_firstPoint.y;
- else {
- double xDistance = m_lastPoint.x - m_firstPoint.x;
- double yDistance = m_lastPoint.y - m_firstPoint.y;
- if (abs(xDistance) > abs(yDistance)) {
- if (abs(yDistance) == yDistance)
- m_lastPoint.y = m_firstPoint.y + abs(xDistance);
- else
- m_lastPoint.y = m_firstPoint.y - abs(xDistance);
- } else {
- if (abs(xDistance) == xDistance)
- m_lastPoint.x = m_firstPoint.x + abs(yDistance);
- else
- m_lastPoint.x = m_firstPoint.x - abs(yDistance);
- }
- }
- }
- m_mousePos = pos;
- m_brushPos = pos;
- invalidate(invalidateRect);
- return;
+
+ if (alt != m_inputmanager.state.isKeyPressed(TKey::alt))
+ m_inputmanager.keyEvent(alt, TKey::alt, t, nullptr);
+ if (shift != m_inputmanager.state.isKeyPressed(TKey::shift))
+ m_inputmanager.keyEvent(shift, TKey::shift, t, nullptr);
+ if (control != m_inputmanager.state.isKeyPressed(TKey::control))
+ m_inputmanager.keyEvent(control, TKey::control, t, nullptr);
+
+ if (type == ME_MOVE) {
+ THoverList hovers(1, pos);
+ m_inputmanager.hoverEvent(hovers);
+ } else {
+ m_inputmanager.trackEvent(
+ e.isTablet(), 0, pos,
+ e.isTablet() ? &e.m_pressure : nullptr, nullptr,
+ type == ME_UP, t );
+ m_inputmanager.processTracks();
}
-
- m_strokeSegmentRect.empty();
- m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
- TRect updateRect = m_strokeSegmentRect * ras->getBounds();
- if (!updateRect.isEmpty())
- ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
-
- TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
- invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
- invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
- invalidateRect +=
- TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
- invalidate(invalidateRect.enlarge(2.0));
}
-//---------------------------------------------------------------------------------------------------------------
-
-void FullColorBrushTool::leftButtonUp(const TPointD &pos,
- const TMouseEvent &e) {
- TPointD previousBrushPos = m_brushPos;
- m_brushPos = m_mousePos = pos;
-
- TRasterImageP ri = (TRasterImageP)getImage(true);
- if (!ri) return;
-
- if (!m_toonz_brush) return;
-
- TRasterP ras = ri->getRaster();
- TPointD rasCenter = ras->getCenterD();
- TPointD point;
- if (m_isStraight)
- point = TPointD(m_lastPoint + rasCenter);
- else
- point = TPointD(pos + rasCenter);
- double pressure;
- if (getApplication()->getCurrentLevelStyle()->getTagId() ==
- 4001) // mypaint brush case
- pressure = m_enabledPressure && e.isTablet() ? e.m_pressure : 0.5;
- else
- pressure = m_enabledPressure ? e.m_pressure : 1.0;
-
- if (m_isStraight && m_maxPressure > 0.0) {
- pressure = m_maxPressure;
- }
-
- m_strokeSegmentRect.empty();
- m_toonz_brush->strokeTo(point, pressure, restartBrushTimer());
- m_toonz_brush->endStroke();
- TRect updateRect = m_strokeSegmentRect * ras->getBounds();
- if (!updateRect.isEmpty())
- ras->extract(updateRect)->copy(m_workRaster->extract(updateRect));
-
- TPointD thickOffset(m_maxCursorThick * 0.5, m_maxCursorThick * 0.5);
- TRectD invalidateRect = convert(m_strokeSegmentRect) - rasCenter;
- invalidateRect += TRectD(m_brushPos - thickOffset, m_brushPos + thickOffset);
- invalidateRect +=
- TRectD(previousBrushPos - thickOffset, previousBrushPos + thickOffset);
- invalidate(invalidateRect.enlarge(2.0));
+//---------------------------------------------------------------------------------------------------
- if (m_toonz_brush) {
- delete m_toonz_brush;
- m_toonz_brush = 0;
- }
-
- m_lastRect.empty();
- m_workRaster->unlock();
-
- if (m_tileSet->getTileCount() > 0) {
- delete m_tileSaver;
- TTool::Application *app = TTool::getApplication();
- TXshLevel *level = app->getCurrentLevel()->getLevel();
- TXshSimpleLevelP simLevel = level->getSimpleLevel();
- TFrameId frameId = getCurrentFid();
- TRasterP subras = ras->extract(m_strokeRect)->clone();
- TUndoManager::manager()->add(new FullColorBrushUndo(
- m_tileSet, simLevel.getPointer(), frameId, m_isFrameCreated, subras,
- m_strokeRect.getP00()));
- }
-
- notifyImageChanged();
- m_strokeRect.empty();
- m_mousePressed = false;
- m_isStraight = false;
- m_maxPressure = -1.0;
-}
+void FullColorBrushTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e)
+ { handleMouseEvent(ME_DOWN, pos, e); }
+void FullColorBrushTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
+ { handleMouseEvent(ME_DRAG, pos, e); }
+void FullColorBrushTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)
+ { handleMouseEvent(ME_UP, pos, e); }
+void FullColorBrushTool::mouseMove(const TPointD &pos, const TMouseEvent &e)
+ { handleMouseEvent(ME_MOVE, pos, e); }
//---------------------------------------------------------------------------------------------------------------