Fixes issue with nested artboard opacity not updating in sync with the artboard.

This commit is contained in:
Luigi Rosso
2021-10-26 17:39:36 -07:00
committed by Luigi Rosso
parent 75ccbd0a0b
commit 61b5a1b363
5 changed files with 24 additions and 14 deletions

View File

@ -92,7 +92,6 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
bool get hasAnimations => _animations.isNotEmpty; bool get hasAnimations => _animations.isNotEmpty;
int _dirtDepth = 0; int _dirtDepth = 0;
int _dirt = 255;
/// Iterate each component and call callback for it. /// Iterate each component and call callback for it.
void forEachComponent(void Function(Component) callback) => void forEachComponent(void Function(Component) callback) =>
@ -120,17 +119,17 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
bool updateComponents() { bool updateComponents() {
bool didUpdate = false; bool didUpdate = false;
if ((_dirt & ComponentDirt.drawOrder) != 0) { if ((dirt & ComponentDirt.drawOrder) != 0) {
sortDrawOrder(); sortDrawOrder();
_dirt &= ~ComponentDirt.drawOrder; dirt &= ~ComponentDirt.drawOrder;
didUpdate = true; didUpdate = true;
} }
if ((_dirt & ComponentDirt.components) != 0) { if ((dirt & ComponentDirt.components) != 0) {
const int maxSteps = 100; const int maxSteps = 100;
int step = 0; int step = 0;
int count = _dependencyOrder.length; int count = _dependencyOrder.length;
while ((_dirt & ComponentDirt.components) != 0 && step < maxSteps) { while ((dirt & ComponentDirt.components) != 0 && step < maxSteps) {
_dirt &= ~ComponentDirt.components; dirt &= ~ComponentDirt.components;
// Track dirt depth here so that if something else marks // Track dirt depth here so that if something else marks
// dirty, we restart. // dirty, we restart.
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -164,6 +163,9 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
didUpdate = true; didUpdate = true;
} }
} }
if (updateComponents() || didUpdate) {
didUpdate = true;
}
if (nested) { if (nested) {
var active = _activeNestedArtboards.toList(growable: false); var active = _activeNestedArtboards.toList(growable: false);
@ -172,10 +174,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
} }
} }
if (updateComponents() || didUpdate) { return didUpdate;
return true;
}
return false;
} }
@override @override
@ -187,7 +186,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
void onComponentDirty(Component component) { void onComponentDirty(Component component) {
if ((dirt & ComponentDirt.components) == 0) { if ((dirt & ComponentDirt.components) == 0) {
context.markNeedsAdvance(); context.markNeedsAdvance();
_dirt |= ComponentDirt.components; dirt |= ComponentDirt.components;
} }
/// If the order of the component is less than the current dirt depth, /// 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; // component.dirt = 255;
} }
_dirt |= ComponentDirt.components; dirt |= ComponentDirt.components;
} }
@override @override
@ -228,6 +227,13 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
Rect.fromLTWH(width * -originX, height * -originY, width, height); Rect.fromLTWH(width * -originX, height * -originY, width, height);
path.reset(); path.reset();
path.addRect(rect); 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() { void markDrawOrderDirty() {
if ((dirt & ComponentDirt.drawOrder) == 0) { if ((dirt & ComponentDirt.drawOrder) == 0) {
context.markNeedsAdvance(); context.markNeedsAdvance();
_dirt |= ComponentDirt.drawOrder; dirt |= ComponentDirt.drawOrder;
} }
} }

View File

@ -33,4 +33,5 @@ abstract class TargetedConstraint extends TargetedConstraintBase {
super.onAddedDirty(); super.onAddedDirty();
target = context.resolve(targetId); target = context.resolve(targetId);
} }
} }

View File

@ -12,6 +12,7 @@ abstract class NestedAnimation<T extends Animation>
@override @override
void animationIdChanged(int from, int to) {} void animationIdChanged(int from, int to) {}
bool get isEnabled; bool get isEnabled;
void advance(double elapsedSeconds, MountedArtboard mountedArtboard); void advance(double elapsedSeconds, MountedArtboard mountedArtboard);

View File

@ -39,12 +39,14 @@ class NestedArtboard extends NestedArtboardBase {
_mountedArtboard = value; _mountedArtboard = value;
_mountedArtboard?.worldTransform = worldTransform; _mountedArtboard?.worldTransform = worldTransform;
_mountedArtboard?.renderOpacity = renderOpacity; _mountedArtboard?.renderOpacity = renderOpacity;
_mountedArtboard?.advance(0);
addDirt(ComponentDirt.paint); addDirt(ComponentDirt.paint);
} }
@override @override
void artboardIdChanged(int from, int to) {} void artboardIdChanged(int from, int to) {}
@override @override
void childAdded(Component child) { void childAdded(Component child) {
super.childAdded(child); super.childAdded(child);

View File

@ -34,7 +34,7 @@ abstract class TransformComponent extends TransformComponentBase {
final List<Constraint> _constraints = []; final List<Constraint> _constraints = [];
Iterable<Constraint> get constraints => _constraints; Iterable<Constraint> get constraints => _constraints;
double _renderOpacity = 0; double _renderOpacity = 1;
double get renderOpacity => _renderOpacity; double get renderOpacity => _renderOpacity;
final Mat2D transform = Mat2D(); final Mat2D transform = Mat2D();