Nested artboard playback fixes.

This commit is contained in:
Luigi Rosso
2021-10-05 14:44:27 -07:00
committed by Luigi Rosso
parent 3a84f6ae89
commit 365910c4a0
5 changed files with 43 additions and 10 deletions

View File

@ -469,17 +469,15 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
@override
void clipChanged(bool from, bool to) => addDirt(ComponentDirt.paint);
@override
void opacityChanged(double from, double to) => markWorldTransformDirty;
@override
bool import(ImportStack stack) {
var backboardImporter =
stack.latest<BackboardImporter>(BackboardBase.typeKey);
if (backboardImporter == null) {
return false;
if (backboardImporter != null) {
// Backboard isn't strictly required (editor doesn't always export a
// backboard when serializing for the clipboard, for example).
backboardImporter.addArtboard(this);
}
backboardImporter.addArtboard(this);
return super.import(stack);
}

View File

@ -20,6 +20,8 @@ abstract class MountedArtboard {
Mat2D get worldTransform;
set worldTransform(Mat2D value);
AABB get bounds;
double get renderOpacity;
set renderOpacity(double value);
}
class NestedArtboard extends NestedArtboardBase {
@ -35,6 +37,7 @@ class NestedArtboard extends NestedArtboardBase {
}
_mountedArtboard = value;
_mountedArtboard?.worldTransform = worldTransform;
_mountedArtboard?.renderOpacity = renderOpacity;
addDirt(ComponentDirt.paint);
}
@ -83,16 +86,33 @@ class NestedArtboard extends NestedArtboardBase {
}
@override
void draw(Canvas canvas) => mountedArtboard?.draw(canvas);
void update(int dirt) {
super.update(dirt);
// RenderOpacity gets updated with the worldTransform (accumulates through
// hierarchy), so if we see worldTransform is dirty, update our internal
// render opacities.
if (dirt & ComponentDirt.worldTransform != 0) {
mountedArtboard?.renderOpacity = renderOpacity;
}
}
@override
void draw(Canvas canvas) {
bool clipped = clip(canvas);
mountedArtboard?.draw(canvas);
if (clipped) {
canvas.restore();
}
}
@override
bool import(ImportStack stack) {
var backboardImporter =
stack.latest<BackboardImporter>(BackboardBase.typeKey);
if (backboardImporter == null) {
return false;
if (backboardImporter != null) {
backboardImporter.addNestedArtboard(this);
}
backboardImporter.addNestedArtboard(this);
return super.import(stack);
}

View File

@ -145,6 +145,8 @@ abstract class TransformComponent extends TransformComponentBase {
@override
void opacityChanged(double from, double to) {
// Intentionally doesn't call super as this will call
// markWorldTransformDirty if necessary.
markTransformDirty();
}

View File

@ -11,4 +11,9 @@ abstract class WorldTransformComponent extends WorldTransformComponentBase {
void markWorldTransformDirty() =>
addDirt(ComponentDirt.worldTransform, recurse: true);
@override
void opacityChanged(double from, double to) {
markWorldTransformDirty();
}
}

View File

@ -108,4 +108,12 @@ class RuntimeMountedArtboard extends MountedArtboard {
var y = -artboardInstance.originY * height;
return AABB.fromValues(x, y, x + width, y + height);
}
@override
double get renderOpacity => artboardInstance.opacity;
@override
set renderOpacity(double value) {
artboardInstance.opacity = value;
}
}