Skip to content

Commit 9ce4db4

Browse files
committed
feat: for some effects the paths were drawn on top of the effect, fixed now.
1 parent 0c5a4cd commit 9ce4db4

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

packages/demo/lib/examples/advanced/animated_connections.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AnimationDemoStore {
9696
set particleType(String value) =>
9797
runInAction(() => _particleType.value = value);
9898

99-
final Observable<String> _particleCharacter = Observable('');
99+
final Observable<String> _particleCharacter = Observable('📦');
100100

101101
String get particleCharacter => _particleCharacter.value;
102102

packages/vyuh_node_flow/lib/connections/animation/gradient_flow_effect.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,7 @@ class GradientFlowEffect implements ConnectionAnimationEffect {
119119
(i) => i / (gradientColors.length - 1),
120120
);
121121

122-
// Create linear gradient shader along the path segment
123-
final shader = Gradient.linear(
124-
startTangent.position,
125-
endTangent.position,
126-
gradientColors,
127-
colorStops,
128-
);
129-
130-
// Draw the gradient segment
131-
final gradientPaint = Paint()
132-
..shader = shader
133-
..strokeWidth = basePaint.strokeWidth
134-
..style = PaintingStyle.stroke
135-
..strokeCap = basePaint.strokeCap
136-
..strokeJoin = basePaint.strokeJoin;
137-
138-
canvas.drawPath(gradientPath, gradientPaint);
139-
140-
// Draw the rest of the path with configured opacity
122+
// Draw the rest of the path first (underneath) with configured opacity
141123
if (connectionOpacity > 0) {
142124
final basePaintWithOpacity = Paint()
143125
..color = basePaint.color.withValues(alpha: connectionOpacity)
@@ -156,6 +138,24 @@ class GradientFlowEffect implements ConnectionAnimationEffect {
156138
canvas.drawPath(afterPath, basePaintWithOpacity);
157139
}
158140
}
141+
142+
// Create linear gradient shader along the path segment
143+
final shader = Gradient.linear(
144+
startTangent.position,
145+
endTangent.position,
146+
gradientColors,
147+
colorStops,
148+
);
149+
150+
// Draw the gradient segment on top
151+
final gradientPaint = Paint()
152+
..shader = shader
153+
..strokeWidth = basePaint.strokeWidth
154+
..style = PaintingStyle.stroke
155+
..strokeCap = basePaint.strokeCap
156+
..strokeJoin = basePaint.strokeJoin;
157+
158+
canvas.drawPath(gradientPath, gradientPaint);
159159
}
160160
}
161161
}

packages/vyuh_node_flow/lib/connections/animation/particle_effect.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ class ParticleEffect implements ConnectionAnimationEffect {
6969

7070
@override
7171
void paint(Canvas canvas, Path path, Paint basePaint, double animationValue) {
72+
// Draw the static path first (underneath the particles) with configured opacity
73+
if (connectionOpacity > 0) {
74+
final pathPaint = Paint()
75+
..color = basePaint.color.withValues(alpha: connectionOpacity)
76+
..strokeWidth = basePaint.strokeWidth
77+
..style = PaintingStyle.stroke
78+
..strokeCap = basePaint.strokeCap
79+
..strokeJoin = basePaint.strokeJoin;
80+
81+
canvas.drawPath(path, pathPaint);
82+
}
83+
84+
// Draw particles on top
7285
final pathMetrics = path.computeMetrics();
7386

7487
for (final metric in pathMetrics) {
@@ -91,17 +104,5 @@ class ParticleEffect implements ConnectionAnimationEffect {
91104
particlePainter.paint(canvas, tangent.position, tangent, basePaint);
92105
}
93106
}
94-
95-
// Draw the static path underneath the particles with configured opacity
96-
if (connectionOpacity > 0) {
97-
final pathPaint = Paint()
98-
..color = basePaint.color.withValues(alpha: connectionOpacity)
99-
..strokeWidth = basePaint.strokeWidth
100-
..style = PaintingStyle.stroke
101-
..strokeCap = basePaint.strokeCap
102-
..strokeJoin = basePaint.strokeJoin;
103-
104-
canvas.drawPath(path, pathPaint);
105-
}
106107
}
107108
}

0 commit comments

Comments
 (0)