From a203c41a953f28f2adfaa23182834731339e7ce8 Mon Sep 17 00:00:00 2001
From: Ivan Mahonin <bh@icystar.com>
Date: Aug 26 2023 14:51:24 +0000
Subject: #assistants: fix deafult pressure


---

diff --git a/toonz/sources/include/tools/inputmanager.h b/toonz/sources/include/tools/inputmanager.h
index 323dba1..3dfcc51 100644
--- a/toonz/sources/include/tools/inputmanager.h
+++ b/toonz/sources/include/tools/inputmanager.h
@@ -231,8 +231,10 @@ public:
     TInputState::DeviceId deviceId,
     TInputState::TouchId touchId,
     const TPointD &position,
-    const double *pressure,
-    const TPointD *tilt,
+    const double pressure,
+    const TPointD &tilt,
+    bool hasPressure,
+    bool hasTilt,
     bool final,
     TTimerTicks ticks );
   bool keyEvent(
diff --git a/toonz/sources/tnztools/fullcolorbrushtool.cpp b/toonz/sources/tnztools/fullcolorbrushtool.cpp
index 91b0aad..d764b82 100644
--- a/toonz/sources/tnztools/fullcolorbrushtool.cpp
+++ b/toonz/sources/tnztools/fullcolorbrushtool.cpp
@@ -363,9 +363,14 @@ void FullColorBrushTool::handleMouseEvent(MouseEventType type,
     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);
+    bool   isMyPaint   = getApplication()->getCurrentLevelStyle()->getTagId() == 4001;
+    int    deviceId    = e.isTablet() ? 1 : 0;
+    double defPressure = isMyPaint ? 0.5 : 1.0;
+    bool   hasPressure = e.isTablet();
+    double pressure    = hasPressure ? e.m_pressure : defPressure;
+    bool   final       = type == ME_UP;
+    m_inputmanager.trackEvent(
+      deviceId, 0, pos, pressure, TPointD(), hasPressure, false, final, t);
     m_inputmanager.processTracks();
   }
 }
@@ -529,10 +534,14 @@ void FullColorBrushTool::inputPaintTrackPoint(const TTrackPoint &point,
   handler = dynamic_cast<TrackHandler *>(track.handler.getPointer());
   if (!handler) return;
 
+  bool   isMyPaint   = getApplication()->getCurrentLevelStyle()->getTagId() == 4001;
+  double defPressure = isMyPaint ? 0.5 : 1.0;
+  double pressure    = m_enabledPressure ? point.pressure : defPressure;
+  
   // paint stroke
   m_strokeSegmentRect.empty();
   handler->brush.strokeTo(point.position + rasCenter,
-                          m_enabledPressure ? point.pressure : 0.5, point.tilt,
+                          pressure, point.tilt,
                           point.time - track.previous().time);
   if (track.pointsAdded == 1 && track.finished()) handler->brush.endStroke();
 
diff --git a/toonz/sources/tnztools/inputmanager.cpp b/toonz/sources/tnztools/inputmanager.cpp
index 8e05e3b..ee5c10c 100644
--- a/toonz/sources/tnztools/inputmanager.cpp
+++ b/toonz/sources/tnztools/inputmanager.cpp
@@ -486,21 +486,23 @@ TInputManager::trackEvent(
   TInputState::DeviceId deviceId,
   TInputState::TouchId touchId,
   const TPointD &position,
-  const double *pressure,
-  const TPointD *tilt,
+  const double pressure,
+  const TPointD &tilt,
+  bool hasPressure,
+  bool hasTilt,
   bool final,
   TTimerTicks ticks )
 {
   ticks = fixTicks(ticks);
-  TTrackP track = getTrack(deviceId, touchId, ticks, (bool)pressure, (bool)tilt);
+  TTrackP track = getTrack(deviceId, touchId, ticks, hasPressure, hasTilt);
   if (!track->finished()) {
     ticks = fixTicks(ticks);
     double time = (double)(ticks - track->ticks())*TToolTimer::step - track->rootTimeOffset;
     addTrackPoint(
       track,
       position,
-      pressure ? *pressure : 0.5,
-      tilt ? *tilt : TPointD(),
+      pressure,
+      tilt,
       time,
       final );
   }
diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp
index c3935bc..b4ba5d5 100644
--- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp
+++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp
@@ -1099,9 +1099,13 @@ void ToonzRasterBrushTool::handleMouseEvent(MouseEventType type,
     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);
+    int    deviceId    = e.isTablet() ? 1 : 0;
+    double defPressure = m_isMyPaintStyleSelected ? 0.5 : 1.0;
+    bool   hasPressure = e.isTablet();
+    double pressure    = hasPressure ? e.m_pressure : defPressure;
+    bool   final       = type == ME_UP;
+    m_inputmanager.trackEvent(
+      deviceId, 0, pos, pressure, TPointD(), hasPressure, false, final, t);
     m_inputmanager.processTracks();
   }
 }
@@ -1269,6 +1273,9 @@ void ToonzRasterBrushTool::inputPaintTrackPoint(const TTrackPoint &point, const 
   if (firstPoint != !track.handler)
     return;
   
+  double defPressure = m_painting.myPaint.isActive ? 0.5 : 1.0;
+  double pressure    = m_pressure.getValue() ? point.pressure : defPressure;
+  
   if (m_painting.myPaint.isActive) {
     // mypaint case
     
@@ -1284,7 +1291,7 @@ void ToonzRasterBrushTool::inputPaintTrackPoint(const TTrackPoint &point, const 
     
     // paint stroke
     m_painting.myPaint.strokeSegmentRect.empty();
-    handler->brush.strokeTo( fixedPosition + rasCenter, point.pressure,
+    handler->brush.strokeTo( fixedPosition + rasCenter, pressure,
                              point.tilt, point.time - track.previous().time );
     if (lastPoint)
       handler->brush.endStroke();
@@ -1303,7 +1310,7 @@ void ToonzRasterBrushTool::inputPaintTrackPoint(const TTrackPoint &point, const 
     // pencil case
     
     // Pencilモードでなく、Hardness=100 の場合のブラシサイズを1段階下げる
-    double thickness = computeThickness(point.pressure, m_rasThickness)*2;
+    double thickness = computeThickness(pressure, m_rasThickness)*2;
     //if (!m_painting.pencil.realPencil && !m_modifierLine->getManager())
     //  thickness -= 1.0;
     TThickPoint thickPoint(fixedPosition + rasCenter, thickness);
@@ -1364,7 +1371,7 @@ void ToonzRasterBrushTool::inputPaintTrackPoint(const TTrackPoint &point, const 
     if (!handler) return;
 
     // paint stroke
-    double radius = computeThickness(point.pressure, m_rasThickness);
+    double radius = computeThickness(pressure, m_rasThickness);
     TThickPoint thickPoint(fixedPosition + rasCenter, radius*2);
     TRect strokeRect( tfloor(thickPoint.x - maxThick - 0.999),
                       tfloor(thickPoint.y - maxThick - 0.999),
diff --git a/toonz/sources/tnztools/toonzvectorbrushtool.cpp b/toonz/sources/tnztools/toonzvectorbrushtool.cpp
index 11645f6..dade32a 100644
--- a/toonz/sources/tnztools/toonzvectorbrushtool.cpp
+++ b/toonz/sources/tnztools/toonzvectorbrushtool.cpp
@@ -1075,9 +1075,12 @@ void ToonzVectorBrushTool::handleMouseEvent(MouseEventType type,
   if (pickerMode) {
     if (type == ME_DOWN) getViewer()->doPickGuideStroke(snappedPos);
   } else {
-    m_inputmanager.trackEvent(e.isTablet(), 0, snappedPos,
-                              &e.m_pressure, nullptr,
-                              type == ME_UP, t);
+    int    deviceId    = e.isTablet() ? 1 : 0;
+    bool   hasPressure = e.isTablet();
+    double pressure    = hasPressure ? e.m_pressure : 1.0;
+    bool   final       = type == ME_UP;
+    m_inputmanager.trackEvent(
+      deviceId, 0, snappedPos, pressure, TPointD(), hasPressure, false, final, t);
     m_inputmanager.processTracks();
   }
 }