From 61b5a1b36375d41d170616042b6b0623ef1d85b8 Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Tue, 26 Oct 2021 17:39:36 -0700 Subject: [PATCH] Fixes issue with nested artboard opacity not updating in sync with the artboard. --- lib/src/rive_core/artboard.dart | 32 +++++++++++-------- .../constraints/targeted_constraint.dart | 1 + lib/src/rive_core/nested_animation.dart | 1 + lib/src/rive_core/nested_artboard.dart | 2 ++ lib/src/rive_core/transform_component.dart | 2 +- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/src/rive_core/artboard.dart b/lib/src/rive_core/artboard.dart index 3cb763a..948ddb8 100644 --- a/lib/src/rive_core/artboard.dart +++ b/lib/src/rive_core/artboard.dart @@ -92,7 +92,6 @@ class Artboard extends ArtboardBase with ShapePaintContainer { bool get hasAnimations => _animations.isNotEmpty; int _dirtDepth = 0; - int _dirt = 255; /// Iterate each component and call callback for it. void forEachComponent(void Function(Component) callback) => @@ -120,17 +119,17 @@ class Artboard extends ArtboardBase with ShapePaintContainer { bool updateComponents() { bool didUpdate = false; - if ((_dirt & ComponentDirt.drawOrder) != 0) { + if ((dirt & ComponentDirt.drawOrder) != 0) { sortDrawOrder(); - _dirt &= ~ComponentDirt.drawOrder; + dirt &= ~ComponentDirt.drawOrder; didUpdate = true; } - if ((_dirt & ComponentDirt.components) != 0) { + if ((dirt & ComponentDirt.components) != 0) { const int maxSteps = 100; int step = 0; int count = _dependencyOrder.length; - while ((_dirt & ComponentDirt.components) != 0 && step < maxSteps) { - _dirt &= ~ComponentDirt.components; + while ((dirt & ComponentDirt.components) != 0 && step < maxSteps) { + dirt &= ~ComponentDirt.components; // Track dirt depth here so that if something else marks // dirty, we restart. for (int i = 0; i < count; i++) { @@ -164,6 +163,9 @@ class Artboard extends ArtboardBase with ShapePaintContainer { didUpdate = true; } } + if (updateComponents() || didUpdate) { + didUpdate = true; + } if (nested) { var active = _activeNestedArtboards.toList(growable: false); @@ -172,10 +174,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer { } } - if (updateComponents() || didUpdate) { - return true; - } - return false; + return didUpdate; } @override @@ -187,7 +186,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer { void onComponentDirty(Component component) { if ((dirt & ComponentDirt.components) == 0) { context.markNeedsAdvance(); - _dirt |= ComponentDirt.components; + dirt |= ComponentDirt.components; } /// If the order of the component is less than the current dirt depth, @@ -218,7 +217,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer { // component.dirt = 255; } - _dirt |= ComponentDirt.components; + dirt |= ComponentDirt.components; } @override @@ -228,6 +227,13 @@ class Artboard extends ArtboardBase with ShapePaintContainer { Rect.fromLTWH(width * -originX, height * -originY, width, height); path.reset(); path.addRect(rect); + + for (final fill in fills) { + fill.renderOpacity = opacity; + } + for (final stroke in strokes) { + stroke.renderOpacity = opacity; + } } } @@ -278,7 +284,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer { void markDrawOrderDirty() { if ((dirt & ComponentDirt.drawOrder) == 0) { context.markNeedsAdvance(); - _dirt |= ComponentDirt.drawOrder; + dirt |= ComponentDirt.drawOrder; } } diff --git a/lib/src/rive_core/constraints/targeted_constraint.dart b/lib/src/rive_core/constraints/targeted_constraint.dart index ac7a962..2159d06 100644 --- a/lib/src/rive_core/constraints/targeted_constraint.dart +++ b/lib/src/rive_core/constraints/targeted_constraint.dart @@ -33,4 +33,5 @@ abstract class TargetedConstraint extends TargetedConstraintBase { super.onAddedDirty(); target = context.resolve(targetId); } + } diff --git a/lib/src/rive_core/nested_animation.dart b/lib/src/rive_core/nested_animation.dart index f4a91c8..417d9bd 100644 --- a/lib/src/rive_core/nested_animation.dart +++ b/lib/src/rive_core/nested_animation.dart @@ -12,6 +12,7 @@ abstract class NestedAnimation @override void animationIdChanged(int from, int to) {} + bool get isEnabled; void advance(double elapsedSeconds, MountedArtboard mountedArtboard); diff --git a/lib/src/rive_core/nested_artboard.dart b/lib/src/rive_core/nested_artboard.dart index a7ecb63..fd7081e 100644 --- a/lib/src/rive_core/nested_artboard.dart +++ b/lib/src/rive_core/nested_artboard.dart @@ -39,12 +39,14 @@ class NestedArtboard extends NestedArtboardBase { _mountedArtboard = value; _mountedArtboard?.worldTransform = worldTransform; _mountedArtboard?.renderOpacity = renderOpacity; + _mountedArtboard?.advance(0); addDirt(ComponentDirt.paint); } @override void artboardIdChanged(int from, int to) {} + @override void childAdded(Component child) { super.childAdded(child); diff --git a/lib/src/rive_core/transform_component.dart b/lib/src/rive_core/transform_component.dart index 58a9eca..3fa26c1 100644 --- a/lib/src/rive_core/transform_component.dart +++ b/lib/src/rive_core/transform_component.dart @@ -34,7 +34,7 @@ abstract class TransformComponent extends TransformComponentBase { final List _constraints = []; Iterable get constraints => _constraints; - double _renderOpacity = 0; + double _renderOpacity = 1; double get renderOpacity => _renderOpacity; final Mat2D transform = Mat2D();