From e8d9f59947f70aa8a45be54e570e91bf4596c470 Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Fri, 28 May 2021 18:08:04 -0700 Subject: [PATCH] Getting instancing working. --- example/lib/example_animation.dart | 2 +- lib/src/core/core.dart | 16 +++++++++++ .../generated/animation/animation_base.dart | 5 ++++ .../animation/animation_state_base.dart | 6 ++++ .../animation/blend_animation_1d_base.dart | 6 ++++ .../animation/blend_animation_base.dart | 5 ++++ .../blend_animation_direct_base.dart | 6 ++++ .../animation/blend_state_1d_base.dart | 6 ++++ .../blend_state_transition_base.dart | 6 ++++ .../animation/cubic_interpolator_base.dart | 8 ++++++ .../animation/keyed_object_base.dart | 5 ++++ .../animation/keyed_property_base.dart | 5 ++++ .../generated/animation/keyframe_base.dart | 7 +++++ .../animation/keyframe_color_base.dart | 6 ++++ .../animation/keyframe_double_base.dart | 6 ++++ .../generated/animation/keyframe_id_base.dart | 6 ++++ .../animation/linear_animation_base.dart | 12 ++++++++ .../animation/state_machine_bool_base.dart | 6 ++++ .../state_machine_component_base.dart | 5 ++++ .../animation/state_machine_number_base.dart | 6 ++++ .../animation/state_transition_base.dart | 9 ++++++ .../animation/transition_condition_base.dart | 5 ++++ .../transition_number_condition_base.dart | 6 ++++ .../transition_value_condition_base.dart | 6 ++++ lib/src/generated/artboard_base.dart | 11 ++++++++ lib/src/generated/bones/bone_base.dart | 6 ++++ .../generated/bones/cubic_weight_base.dart | 9 ++++++ lib/src/generated/bones/root_bone_base.dart | 7 +++++ lib/src/generated/bones/skin_base.dart | 11 ++++++++ lib/src/generated/bones/tendon_base.dart | 12 ++++++++ lib/src/generated/bones/weight_base.dart | 7 +++++ lib/src/generated/component_base.dart | 6 ++++ lib/src/generated/draw_rules_base.dart | 6 ++++ lib/src/generated/draw_target_base.dart | 7 +++++ lib/src/generated/drawable_base.dart | 7 +++++ lib/src/generated/node_base.dart | 7 +++++ .../generated/shapes/clipping_shape_base.dart | 8 ++++++ .../shapes/cubic_asymmetric_vertex_base.dart | 8 ++++++ .../shapes/cubic_detached_vertex_base.dart | 9 ++++++ .../shapes/cubic_mirrored_vertex_base.dart | 7 +++++ lib/src/generated/shapes/paint/fill_base.dart | 6 ++++ .../shapes/paint/gradient_stop_base.dart | 7 +++++ .../shapes/paint/linear_gradient_base.dart | 10 +++++++ .../shapes/paint/shape_paint_base.dart | 6 ++++ .../shapes/paint/solid_color_base.dart | 6 ++++ .../generated/shapes/paint/stroke_base.dart | 9 ++++++ .../shapes/paint/trim_path_base.dart | 9 ++++++ .../shapes/parametric_path_base.dart | 9 ++++++ lib/src/generated/shapes/path_base.dart | 6 ++++ .../generated/shapes/path_vertex_base.dart | 7 +++++ .../generated/shapes/points_path_base.dart | 6 ++++ lib/src/generated/shapes/polygon_base.dart | 7 +++++ lib/src/generated/shapes/rectangle_base.dart | 10 +++++++ lib/src/generated/shapes/star_base.dart | 6 ++++ .../shapes/straight_vertex_base.dart | 6 ++++ .../generated/transform_component_base.dart | 9 ++++++ lib/src/rive_core/artboard.dart | 12 ++++++++ lib/src/rive_core/shapes/polygon.dart | 6 ++-- lib/src/rive_core/shapes/shape.dart | 4 ++- lib/src/rive_core/shapes/star.dart | 11 +++++--- lib/src/runtime_artboard.dart | 28 +++++++++++++++++++ 61 files changed, 456 insertions(+), 8 deletions(-) diff --git a/example/lib/example_animation.dart b/example/lib/example_animation.dart index 38da10b..cd2eb06 100644 --- a/example/lib/example_animation.dart +++ b/example/lib/example_animation.dart @@ -35,7 +35,7 @@ class _ExampleAnimationState extends State { // The artboard is the root of the animation and gets drawn in the // Rive widget. - final artboard = file.mainArtboard; + final artboard = file.mainArtboard.instance(); // Add a controller to play back a known animation on the main/default // artboard. We store a reference to it so we can toggle playback. artboard.addController(_controller = SimpleAnimation('idle')); diff --git a/lib/src/core/core.dart b/lib/src/core/core.dart index ed8a5d1..bac4a1b 100644 --- a/lib/src/core/core.dart +++ b/lib/src/core/core.dart @@ -1,5 +1,6 @@ import 'dart:collection'; +import 'package:flutter/foundation.dart'; import 'package:rive/src/rive_core/runtime/exceptions/rive_format_error_exception.dart'; export 'package:rive/src/animation_list.dart'; export 'package:rive/src/state_machine_components.dart'; @@ -37,6 +38,21 @@ abstract class Core { bool import(ImportStack stack) => true; bool validate() => true; + + /// Make a duplicate of this core object, N.B. that all properties including + /// id's are copied. + K? clone() { + var object = context.makeCoreInstance(coreType); + object?.copy(this); + return object is K ? object : null; + } + + /// Copies property values, currently doesn't trigger change callbacks. It's + /// meant to be a helper for [clone]. + @protected + void copy(covariant Core source) { + id = source.id; + } } class InternalCoreHelper { diff --git a/lib/src/generated/animation/animation_base.dart b/lib/src/generated/animation/animation_base.dart index dc26616..7ae7609 100644 --- a/lib/src/generated/animation/animation_base.dart +++ b/lib/src/generated/animation/animation_base.dart @@ -34,4 +34,9 @@ abstract class AnimationBase extends Core { } void nameChanged(String from, String to); + + @override + void copy(AnimationBase source) { + _name = source._name; + } } diff --git a/lib/src/generated/animation/animation_state_base.dart b/lib/src/generated/animation/animation_state_base.dart index c91877e..37f9f5f 100644 --- a/lib/src/generated/animation/animation_state_base.dart +++ b/lib/src/generated/animation/animation_state_base.dart @@ -41,4 +41,10 @@ abstract class AnimationStateBase extends LayerState { } void animationIdChanged(int from, int to); + + @override + void copy(AnimationStateBase source) { + super.copy(source); + _animationId = source._animationId; + } } diff --git a/lib/src/generated/animation/blend_animation_1d_base.dart b/lib/src/generated/animation/blend_animation_1d_base.dart index 1c5a102..a11f281 100644 --- a/lib/src/generated/animation/blend_animation_1d_base.dart +++ b/lib/src/generated/animation/blend_animation_1d_base.dart @@ -34,4 +34,10 @@ abstract class BlendAnimation1DBase extends BlendAnimation { } void valueChanged(double from, double to); + + @override + void copy(BlendAnimation1DBase source) { + super.copy(source); + _value = source._value; + } } diff --git a/lib/src/generated/animation/blend_animation_base.dart b/lib/src/generated/animation/blend_animation_base.dart index 984c39b..71920a2 100644 --- a/lib/src/generated/animation/blend_animation_base.dart +++ b/lib/src/generated/animation/blend_animation_base.dart @@ -35,4 +35,9 @@ abstract class BlendAnimationBase extends Core { } void animationIdChanged(int from, int to); + + @override + void copy(BlendAnimationBase source) { + _animationId = source._animationId; + } } diff --git a/lib/src/generated/animation/blend_animation_direct_base.dart b/lib/src/generated/animation/blend_animation_direct_base.dart index 12feb5b..2272bce 100644 --- a/lib/src/generated/animation/blend_animation_direct_base.dart +++ b/lib/src/generated/animation/blend_animation_direct_base.dart @@ -36,4 +36,10 @@ abstract class BlendAnimationDirectBase extends BlendAnimation { } void inputIdChanged(int from, int to); + + @override + void copy(BlendAnimationDirectBase source) { + super.copy(source); + _inputId = source._inputId; + } } diff --git a/lib/src/generated/animation/blend_state_1d_base.dart b/lib/src/generated/animation/blend_state_1d_base.dart index c917de4..efd14a9 100644 --- a/lib/src/generated/animation/blend_state_1d_base.dart +++ b/lib/src/generated/animation/blend_state_1d_base.dart @@ -43,4 +43,10 @@ abstract class BlendState1DBase extends BlendState { } void inputIdChanged(int from, int to); + + @override + void copy(BlendState1DBase source) { + super.copy(source); + _inputId = source._inputId; + } } diff --git a/lib/src/generated/animation/blend_state_transition_base.dart b/lib/src/generated/animation/blend_state_transition_base.dart index 8d11f38..d9879e3 100644 --- a/lib/src/generated/animation/blend_state_transition_base.dart +++ b/lib/src/generated/animation/blend_state_transition_base.dart @@ -41,4 +41,10 @@ abstract class BlendStateTransitionBase extends StateTransition { } void exitBlendAnimationIdChanged(int from, int to); + + @override + void copy(BlendStateTransitionBase source) { + super.copy(source); + _exitBlendAnimationId = source._exitBlendAnimationId; + } } diff --git a/lib/src/generated/animation/cubic_interpolator_base.dart b/lib/src/generated/animation/cubic_interpolator_base.dart index f847649..d580991 100644 --- a/lib/src/generated/animation/cubic_interpolator_base.dart +++ b/lib/src/generated/animation/cubic_interpolator_base.dart @@ -98,4 +98,12 @@ abstract class CubicInterpolatorBase extends Core { } void y2Changed(double from, double to); + + @override + void copy(CubicInterpolatorBase source) { + _x1 = source._x1; + _y1 = source._y1; + _x2 = source._x2; + _y2 = source._y2; + } } diff --git a/lib/src/generated/animation/keyed_object_base.dart b/lib/src/generated/animation/keyed_object_base.dart index f2d6f45..a232de2 100644 --- a/lib/src/generated/animation/keyed_object_base.dart +++ b/lib/src/generated/animation/keyed_object_base.dart @@ -34,4 +34,9 @@ abstract class KeyedObjectBase extends Core { } void objectIdChanged(int from, int to); + + @override + void copy(KeyedObjectBase source) { + _objectId = source._objectId; + } } diff --git a/lib/src/generated/animation/keyed_property_base.dart b/lib/src/generated/animation/keyed_property_base.dart index 86e7619..8b73216 100644 --- a/lib/src/generated/animation/keyed_property_base.dart +++ b/lib/src/generated/animation/keyed_property_base.dart @@ -35,4 +35,9 @@ abstract class KeyedPropertyBase extends Core { } void propertyKeyChanged(int from, int to); + + @override + void copy(KeyedPropertyBase source) { + _propertyKey = source._propertyKey; + } } diff --git a/lib/src/generated/animation/keyframe_base.dart b/lib/src/generated/animation/keyframe_base.dart index 233b638..de547b5 100644 --- a/lib/src/generated/animation/keyframe_base.dart +++ b/lib/src/generated/animation/keyframe_base.dart @@ -85,4 +85,11 @@ abstract class KeyFrameBase extends Core { } void interpolatorIdChanged(int from, int to); + + @override + void copy(KeyFrameBase source) { + _frame = source._frame; + _interpolationType = source._interpolationType; + _interpolatorId = source._interpolatorId; + } } diff --git a/lib/src/generated/animation/keyframe_color_base.dart b/lib/src/generated/animation/keyframe_color_base.dart index d2a2e1d..dd250c1 100644 --- a/lib/src/generated/animation/keyframe_color_base.dart +++ b/lib/src/generated/animation/keyframe_color_base.dart @@ -33,4 +33,10 @@ abstract class KeyFrameColorBase extends KeyFrame { } void valueChanged(int from, int to); + + @override + void copy(KeyFrameColorBase source) { + super.copy(source); + _value = source._value; + } } diff --git a/lib/src/generated/animation/keyframe_double_base.dart b/lib/src/generated/animation/keyframe_double_base.dart index ff00757..e369bbf 100644 --- a/lib/src/generated/animation/keyframe_double_base.dart +++ b/lib/src/generated/animation/keyframe_double_base.dart @@ -33,4 +33,10 @@ abstract class KeyFrameDoubleBase extends KeyFrame { } void valueChanged(double from, double to); + + @override + void copy(KeyFrameDoubleBase source) { + super.copy(source); + _value = source._value; + } } diff --git a/lib/src/generated/animation/keyframe_id_base.dart b/lib/src/generated/animation/keyframe_id_base.dart index 79ec3b8..968da47 100644 --- a/lib/src/generated/animation/keyframe_id_base.dart +++ b/lib/src/generated/animation/keyframe_id_base.dart @@ -33,4 +33,10 @@ abstract class KeyFrameIdBase extends KeyFrame { } void valueChanged(int from, int to); + + @override + void copy(KeyFrameIdBase source) { + super.copy(source); + _value = source._value; + } } diff --git a/lib/src/generated/animation/linear_animation_base.dart b/lib/src/generated/animation/linear_animation_base.dart index 0675925..6cfd53a 100644 --- a/lib/src/generated/animation/linear_animation_base.dart +++ b/lib/src/generated/animation/linear_animation_base.dart @@ -182,4 +182,16 @@ abstract class LinearAnimationBase extends Animation { } void enableWorkAreaChanged(bool from, bool to); + + @override + void copy(LinearAnimationBase source) { + super.copy(source); + _fps = source._fps; + _duration = source._duration; + _speed = source._speed; + _loopValue = source._loopValue; + _workStart = source._workStart; + _workEnd = source._workEnd; + _enableWorkArea = source._enableWorkArea; + } } diff --git a/lib/src/generated/animation/state_machine_bool_base.dart b/lib/src/generated/animation/state_machine_bool_base.dart index b55375b..4a0e216 100644 --- a/lib/src/generated/animation/state_machine_bool_base.dart +++ b/lib/src/generated/animation/state_machine_bool_base.dart @@ -38,4 +38,10 @@ abstract class StateMachineBoolBase extends StateMachineInput { } void valueChanged(bool from, bool to); + + @override + void copy(StateMachineBoolBase source) { + super.copy(source); + _value = source._value; + } } diff --git a/lib/src/generated/animation/state_machine_component_base.dart b/lib/src/generated/animation/state_machine_component_base.dart index 1a9bce9..9d0ff22 100644 --- a/lib/src/generated/animation/state_machine_component_base.dart +++ b/lib/src/generated/animation/state_machine_component_base.dart @@ -36,4 +36,9 @@ abstract class StateMachineComponentBase } void nameChanged(String from, String to); + + @override + void copy(StateMachineComponentBase source) { + _name = source._name; + } } diff --git a/lib/src/generated/animation/state_machine_number_base.dart b/lib/src/generated/animation/state_machine_number_base.dart index e3d4592..e7b894c 100644 --- a/lib/src/generated/animation/state_machine_number_base.dart +++ b/lib/src/generated/animation/state_machine_number_base.dart @@ -38,4 +38,10 @@ abstract class StateMachineNumberBase extends StateMachineInput { } void valueChanged(double from, double to); + + @override + void copy(StateMachineNumberBase source) { + super.copy(source); + _value = source._value; + } } diff --git a/lib/src/generated/animation/state_transition_base.dart b/lib/src/generated/animation/state_transition_base.dart index eceb51a..23c71b2 100644 --- a/lib/src/generated/animation/state_transition_base.dart +++ b/lib/src/generated/animation/state_transition_base.dart @@ -109,4 +109,13 @@ abstract class StateTransitionBase extends StateMachineLayerComponent { } void exitTimeChanged(int from, int to); + + @override + void copy(StateTransitionBase source) { + super.copy(source); + _stateToId = source._stateToId; + _flags = source._flags; + _duration = source._duration; + _exitTime = source._exitTime; + } } diff --git a/lib/src/generated/animation/transition_condition_base.dart b/lib/src/generated/animation/transition_condition_base.dart index ddcefb4..352cffd 100644 --- a/lib/src/generated/animation/transition_condition_base.dart +++ b/lib/src/generated/animation/transition_condition_base.dart @@ -34,4 +34,9 @@ abstract class TransitionConditionBase extends Core { } void inputIdChanged(int from, int to); + + @override + void copy(TransitionConditionBase source) { + _inputId = source._inputId; + } } diff --git a/lib/src/generated/animation/transition_number_condition_base.dart b/lib/src/generated/animation/transition_number_condition_base.dart index 9cc38d1..bf0075f 100644 --- a/lib/src/generated/animation/transition_number_condition_base.dart +++ b/lib/src/generated/animation/transition_number_condition_base.dart @@ -38,4 +38,10 @@ abstract class TransitionNumberConditionBase extends TransitionValueCondition { } void valueChanged(double from, double to); + + @override + void copy(TransitionNumberConditionBase source) { + super.copy(source); + _value = source._value; + } } diff --git a/lib/src/generated/animation/transition_value_condition_base.dart b/lib/src/generated/animation/transition_value_condition_base.dart index 25491e9..a111917 100644 --- a/lib/src/generated/animation/transition_value_condition_base.dart +++ b/lib/src/generated/animation/transition_value_condition_base.dart @@ -36,4 +36,10 @@ abstract class TransitionValueConditionBase extends TransitionCondition { } void opValueChanged(int from, int to); + + @override + void copy(TransitionValueConditionBase source) { + super.copy(source); + _opValue = source._opValue; + } } diff --git a/lib/src/generated/artboard_base.dart b/lib/src/generated/artboard_base.dart index 1bdc565..aafa511 100644 --- a/lib/src/generated/artboard_base.dart +++ b/lib/src/generated/artboard_base.dart @@ -159,4 +159,15 @@ abstract class ArtboardBase extends ContainerComponent { } void originYChanged(double from, double to); + + @override + void copy(ArtboardBase source) { + super.copy(source); + _width = source._width; + _height = source._height; + _x = source._x; + _y = source._y; + _originX = source._originX; + _originY = source._originY; + } } diff --git a/lib/src/generated/bones/bone_base.dart b/lib/src/generated/bones/bone_base.dart index c69bacd..a7dca13 100644 --- a/lib/src/generated/bones/bone_base.dart +++ b/lib/src/generated/bones/bone_base.dart @@ -41,4 +41,10 @@ abstract class BoneBase extends SkeletalComponent { } void lengthChanged(double from, double to); + + @override + void copy(BoneBase source) { + super.copy(source); + _length = source._length; + } } diff --git a/lib/src/generated/bones/cubic_weight_base.dart b/lib/src/generated/bones/cubic_weight_base.dart index 9a4c0ac..feeaf93 100644 --- a/lib/src/generated/bones/cubic_weight_base.dart +++ b/lib/src/generated/bones/cubic_weight_base.dart @@ -100,4 +100,13 @@ abstract class CubicWeightBase extends Weight { } void outIndicesChanged(int from, int to); + + @override + void copy(CubicWeightBase source) { + super.copy(source); + _inValues = source._inValues; + _inIndices = source._inIndices; + _outValues = source._outValues; + _outIndices = source._outIndices; + } } diff --git a/lib/src/generated/bones/root_bone_base.dart b/lib/src/generated/bones/root_bone_base.dart index 5fd37af..b61b651 100644 --- a/lib/src/generated/bones/root_bone_base.dart +++ b/lib/src/generated/bones/root_bone_base.dart @@ -69,4 +69,11 @@ abstract class RootBoneBase extends Bone { } void yChanged(double from, double to); + + @override + void copy(RootBoneBase source) { + super.copy(source); + _x = source._x; + _y = source._y; + } } diff --git a/lib/src/generated/bones/skin_base.dart b/lib/src/generated/bones/skin_base.dart index 300c488..1765610 100644 --- a/lib/src/generated/bones/skin_base.dart +++ b/lib/src/generated/bones/skin_base.dart @@ -156,4 +156,15 @@ abstract class SkinBase extends ContainerComponent { } void tyChanged(double from, double to); + + @override + void copy(SkinBase source) { + super.copy(source); + _xx = source._xx; + _yx = source._yx; + _xy = source._xy; + _yy = source._yy; + _tx = source._tx; + _ty = source._ty; + } } diff --git a/lib/src/generated/bones/tendon_base.dart b/lib/src/generated/bones/tendon_base.dart index 32a419a..f58050c 100644 --- a/lib/src/generated/bones/tendon_base.dart +++ b/lib/src/generated/bones/tendon_base.dart @@ -178,4 +178,16 @@ abstract class TendonBase extends Component { } void tyChanged(double from, double to); + + @override + void copy(TendonBase source) { + super.copy(source); + _boneId = source._boneId; + _xx = source._xx; + _yx = source._yx; + _xy = source._xy; + _yy = source._yy; + _tx = source._tx; + _ty = source._ty; + } } diff --git a/lib/src/generated/bones/weight_base.dart b/lib/src/generated/bones/weight_base.dart index 60e945a..87c4aa8 100644 --- a/lib/src/generated/bones/weight_base.dart +++ b/lib/src/generated/bones/weight_base.dart @@ -54,4 +54,11 @@ abstract class WeightBase extends Component { } void indicesChanged(int from, int to); + + @override + void copy(WeightBase source) { + super.copy(source); + _values = source._values; + _indices = source._indices; + } } diff --git a/lib/src/generated/component_base.dart b/lib/src/generated/component_base.dart index 644fd68..378c108 100644 --- a/lib/src/generated/component_base.dart +++ b/lib/src/generated/component_base.dart @@ -58,4 +58,10 @@ abstract class ComponentBase extends Core { } void parentIdChanged(int from, int to); + + @override + void copy(ComponentBase source) { + _name = source._name; + _parentId = source._parentId; + } } diff --git a/lib/src/generated/draw_rules_base.dart b/lib/src/generated/draw_rules_base.dart index 73e03e5..0ccee22 100644 --- a/lib/src/generated/draw_rules_base.dart +++ b/lib/src/generated/draw_rules_base.dart @@ -40,4 +40,10 @@ abstract class DrawRulesBase extends ContainerComponent { } void drawTargetIdChanged(int from, int to); + + @override + void copy(DrawRulesBase source) { + super.copy(source); + _drawTargetId = source._drawTargetId; + } } diff --git a/lib/src/generated/draw_target_base.dart b/lib/src/generated/draw_target_base.dart index fceb4f8..55f8bff 100644 --- a/lib/src/generated/draw_target_base.dart +++ b/lib/src/generated/draw_target_base.dart @@ -59,4 +59,11 @@ abstract class DrawTargetBase extends Component { } void placementValueChanged(int from, int to); + + @override + void copy(DrawTargetBase source) { + super.copy(source); + _drawableId = source._drawableId; + _placementValue = source._placementValue; + } } diff --git a/lib/src/generated/drawable_base.dart b/lib/src/generated/drawable_base.dart index 1b8cb4e..00b60dd 100644 --- a/lib/src/generated/drawable_base.dart +++ b/lib/src/generated/drawable_base.dart @@ -65,4 +65,11 @@ abstract class DrawableBase extends Node { } void drawableFlagsChanged(int from, int to); + + @override + void copy(DrawableBase source) { + super.copy(source); + _blendModeValue = source._blendModeValue; + _drawableFlags = source._drawableFlags; + } } diff --git a/lib/src/generated/node_base.dart b/lib/src/generated/node_base.dart index 35f1fd7..ac3b20c 100644 --- a/lib/src/generated/node_base.dart +++ b/lib/src/generated/node_base.dart @@ -65,4 +65,11 @@ abstract class NodeBase extends TransformComponent { } void yChanged(double from, double to); + + @override + void copy(NodeBase source) { + super.copy(source); + _x = source._x; + _y = source._y; + } } diff --git a/lib/src/generated/shapes/clipping_shape_base.dart b/lib/src/generated/shapes/clipping_shape_base.dart index ee5a4b5..def536f 100644 --- a/lib/src/generated/shapes/clipping_shape_base.dart +++ b/lib/src/generated/shapes/clipping_shape_base.dart @@ -81,4 +81,12 @@ abstract class ClippingShapeBase extends Component { } void isVisibleChanged(bool from, bool to); + + @override + void copy(ClippingShapeBase source) { + super.copy(source); + _sourceId = source._sourceId; + _fillRule = source._fillRule; + _isVisible = source._isVisible; + } } diff --git a/lib/src/generated/shapes/cubic_asymmetric_vertex_base.dart b/lib/src/generated/shapes/cubic_asymmetric_vertex_base.dart index 35d77fb..058232e 100644 --- a/lib/src/generated/shapes/cubic_asymmetric_vertex_base.dart +++ b/lib/src/generated/shapes/cubic_asymmetric_vertex_base.dart @@ -93,4 +93,12 @@ abstract class CubicAsymmetricVertexBase extends CubicVertex { } void outDistanceChanged(double from, double to); + + @override + void copy(CubicAsymmetricVertexBase source) { + super.copy(source); + _rotation = source._rotation; + _inDistance = source._inDistance; + _outDistance = source._outDistance; + } } diff --git a/lib/src/generated/shapes/cubic_detached_vertex_base.dart b/lib/src/generated/shapes/cubic_detached_vertex_base.dart index 5467ce2..3e26edb 100644 --- a/lib/src/generated/shapes/cubic_detached_vertex_base.dart +++ b/lib/src/generated/shapes/cubic_detached_vertex_base.dart @@ -118,4 +118,13 @@ abstract class CubicDetachedVertexBase extends CubicVertex { } void outDistanceChanged(double from, double to); + + @override + void copy(CubicDetachedVertexBase source) { + super.copy(source); + _inRotation = source._inRotation; + _inDistance = source._inDistance; + _outRotation = source._outRotation; + _outDistance = source._outDistance; + } } diff --git a/lib/src/generated/shapes/cubic_mirrored_vertex_base.dart b/lib/src/generated/shapes/cubic_mirrored_vertex_base.dart index 6b8d866..bce005a 100644 --- a/lib/src/generated/shapes/cubic_mirrored_vertex_base.dart +++ b/lib/src/generated/shapes/cubic_mirrored_vertex_base.dart @@ -68,4 +68,11 @@ abstract class CubicMirroredVertexBase extends CubicVertex { } void distanceChanged(double from, double to); + + @override + void copy(CubicMirroredVertexBase source) { + super.copy(source); + _rotation = source._rotation; + _distance = source._distance; + } } diff --git a/lib/src/generated/shapes/paint/fill_base.dart b/lib/src/generated/shapes/paint/fill_base.dart index 42e7eac..1f400b8 100644 --- a/lib/src/generated/shapes/paint/fill_base.dart +++ b/lib/src/generated/shapes/paint/fill_base.dart @@ -39,4 +39,10 @@ abstract class FillBase extends ShapePaint { } void fillRuleChanged(int from, int to); + + @override + void copy(FillBase source) { + super.copy(source); + _fillRule = source._fillRule; + } } diff --git a/lib/src/generated/shapes/paint/gradient_stop_base.dart b/lib/src/generated/shapes/paint/gradient_stop_base.dart index 0eebf10..8b090db 100644 --- a/lib/src/generated/shapes/paint/gradient_stop_base.dart +++ b/lib/src/generated/shapes/paint/gradient_stop_base.dart @@ -55,4 +55,11 @@ abstract class GradientStopBase extends Component { } void positionChanged(double from, double to); + + @override + void copy(GradientStopBase source) { + super.copy(source); + _colorValue = source._colorValue; + _position = source._position; + } } diff --git a/lib/src/generated/shapes/paint/linear_gradient_base.dart b/lib/src/generated/shapes/paint/linear_gradient_base.dart index e394b12..52f4ec1 100644 --- a/lib/src/generated/shapes/paint/linear_gradient_base.dart +++ b/lib/src/generated/shapes/paint/linear_gradient_base.dart @@ -126,4 +126,14 @@ abstract class LinearGradientBase extends ContainerComponent { } void opacityChanged(double from, double to); + + @override + void copy(LinearGradientBase source) { + super.copy(source); + _startX = source._startX; + _startY = source._startY; + _endX = source._endX; + _endY = source._endY; + _opacity = source._opacity; + } } diff --git a/lib/src/generated/shapes/paint/shape_paint_base.dart b/lib/src/generated/shapes/paint/shape_paint_base.dart index 2df03c5..4837cc9 100644 --- a/lib/src/generated/shapes/paint/shape_paint_base.dart +++ b/lib/src/generated/shapes/paint/shape_paint_base.dart @@ -38,4 +38,10 @@ abstract class ShapePaintBase extends ContainerComponent { } void isVisibleChanged(bool from, bool to); + + @override + void copy(ShapePaintBase source) { + super.copy(source); + _isVisible = source._isVisible; + } } diff --git a/lib/src/generated/shapes/paint/solid_color_base.dart b/lib/src/generated/shapes/paint/solid_color_base.dart index 58ec5b9..6338af1 100644 --- a/lib/src/generated/shapes/paint/solid_color_base.dart +++ b/lib/src/generated/shapes/paint/solid_color_base.dart @@ -33,4 +33,10 @@ abstract class SolidColorBase extends Component { } void colorValueChanged(int from, int to); + + @override + void copy(SolidColorBase source) { + super.copy(source); + _colorValue = source._colorValue; + } } diff --git a/lib/src/generated/shapes/paint/stroke_base.dart b/lib/src/generated/shapes/paint/stroke_base.dart index 4998acd..7655615 100644 --- a/lib/src/generated/shapes/paint/stroke_base.dart +++ b/lib/src/generated/shapes/paint/stroke_base.dart @@ -107,4 +107,13 @@ abstract class StrokeBase extends ShapePaint { } void transformAffectsStrokeChanged(bool from, bool to); + + @override + void copy(StrokeBase source) { + super.copy(source); + _thickness = source._thickness; + _cap = source._cap; + _join = source._join; + _transformAffectsStroke = source._transformAffectsStroke; + } } diff --git a/lib/src/generated/shapes/paint/trim_path_base.dart b/lib/src/generated/shapes/paint/trim_path_base.dart index cac118c..8181e2d 100644 --- a/lib/src/generated/shapes/paint/trim_path_base.dart +++ b/lib/src/generated/shapes/paint/trim_path_base.dart @@ -99,4 +99,13 @@ abstract class TrimPathBase extends Component { } void modeValueChanged(int from, int to); + + @override + void copy(TrimPathBase source) { + super.copy(source); + _start = source._start; + _end = source._end; + _offset = source._offset; + _modeValue = source._modeValue; + } } diff --git a/lib/src/generated/shapes/parametric_path_base.dart b/lib/src/generated/shapes/parametric_path_base.dart index 070945d..a48e7cf 100644 --- a/lib/src/generated/shapes/parametric_path_base.dart +++ b/lib/src/generated/shapes/parametric_path_base.dart @@ -118,4 +118,13 @@ abstract class ParametricPathBase extends Path { } void originYChanged(double from, double to); + + @override + void copy(ParametricPathBase source) { + super.copy(source); + _width = source._width; + _height = source._height; + _originX = source._originX; + _originY = source._originY; + } } diff --git a/lib/src/generated/shapes/path_base.dart b/lib/src/generated/shapes/path_base.dart index 5277d22..ad2224e 100644 --- a/lib/src/generated/shapes/path_base.dart +++ b/lib/src/generated/shapes/path_base.dart @@ -41,4 +41,10 @@ abstract class PathBase extends Node { } void pathFlagsChanged(int from, int to); + + @override + void copy(PathBase source) { + super.copy(source); + _pathFlags = source._pathFlags; + } } diff --git a/lib/src/generated/shapes/path_vertex_base.dart b/lib/src/generated/shapes/path_vertex_base.dart index 5dc1819..9e55f93 100644 --- a/lib/src/generated/shapes/path_vertex_base.dart +++ b/lib/src/generated/shapes/path_vertex_base.dart @@ -63,4 +63,11 @@ abstract class PathVertexBase extends ContainerComponent { } void yChanged(double from, double to); + + @override + void copy(PathVertexBase source) { + super.copy(source); + _x = source._x; + _y = source._y; + } } diff --git a/lib/src/generated/shapes/points_path_base.dart b/lib/src/generated/shapes/points_path_base.dart index 20fd2ec..fab3980 100644 --- a/lib/src/generated/shapes/points_path_base.dart +++ b/lib/src/generated/shapes/points_path_base.dart @@ -46,4 +46,10 @@ abstract class PointsPathBase extends Path { } void isClosedChanged(bool from, bool to); + + @override + void copy(PointsPathBase source) { + super.copy(source); + _isClosed = source._isClosed; + } } diff --git a/lib/src/generated/shapes/polygon_base.dart b/lib/src/generated/shapes/polygon_base.dart index e2ad7a5..73d6352 100644 --- a/lib/src/generated/shapes/polygon_base.dart +++ b/lib/src/generated/shapes/polygon_base.dart @@ -72,4 +72,11 @@ abstract class PolygonBase extends ParametricPath { } void cornerRadiusChanged(double from, double to); + + @override + void copy(PolygonBase source) { + super.copy(source); + _points = source._points; + _cornerRadius = source._cornerRadius; + } } diff --git a/lib/src/generated/shapes/rectangle_base.dart b/lib/src/generated/shapes/rectangle_base.dart index 7f1300e..e6060f5 100644 --- a/lib/src/generated/shapes/rectangle_base.dart +++ b/lib/src/generated/shapes/rectangle_base.dart @@ -148,4 +148,14 @@ abstract class RectangleBase extends ParametricPath { } void cornerRadiusBRChanged(double from, double to); + + @override + void copy(RectangleBase source) { + super.copy(source); + _linkCornerRadius = source._linkCornerRadius; + _cornerRadiusTL = source._cornerRadiusTL; + _cornerRadiusTR = source._cornerRadiusTR; + _cornerRadiusBL = source._cornerRadiusBL; + _cornerRadiusBR = source._cornerRadiusBR; + } } diff --git a/lib/src/generated/shapes/star_base.dart b/lib/src/generated/shapes/star_base.dart index b5df447..888335c 100644 --- a/lib/src/generated/shapes/star_base.dart +++ b/lib/src/generated/shapes/star_base.dart @@ -50,4 +50,10 @@ abstract class StarBase extends Polygon { } void innerRadiusChanged(double from, double to); + + @override + void copy(StarBase source) { + super.copy(source); + _innerRadius = source._innerRadius; + } } diff --git a/lib/src/generated/shapes/straight_vertex_base.dart b/lib/src/generated/shapes/straight_vertex_base.dart index 636df8a..d0a294c 100644 --- a/lib/src/generated/shapes/straight_vertex_base.dart +++ b/lib/src/generated/shapes/straight_vertex_base.dart @@ -43,4 +43,10 @@ abstract class StraightVertexBase extends PathVertex { } void radiusChanged(double from, double to); + + @override + void copy(StraightVertexBase source) { + super.copy(source); + _radius = source._radius; + } } diff --git a/lib/src/generated/transform_component_base.dart b/lib/src/generated/transform_component_base.dart index c13de90..32a5c2e 100644 --- a/lib/src/generated/transform_component_base.dart +++ b/lib/src/generated/transform_component_base.dart @@ -104,4 +104,13 @@ abstract class TransformComponentBase extends ContainerComponent { } void opacityChanged(double from, double to); + + @override + void copy(TransformComponentBase source) { + super.copy(source); + _rotation = source._rotation; + _scaleX = source._scaleX; + _scaleY = source._scaleY; + _opacity = source._opacity; + } } diff --git a/lib/src/rive_core/artboard.dart b/lib/src/rive_core/artboard.dart index b9b45b5..671e917 100644 --- a/lib/src/rive_core/artboard.dart +++ b/lib/src/rive_core/artboard.dart @@ -87,6 +87,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer { } step++; } + return true; } return didUpdate; @@ -411,4 +412,15 @@ class Artboard extends ArtboardBase with ShapePaintContainer { _firstDrawable = lastDrawable; } + + /// Make a copy of the this [Artboard]. This duplicates internal objects in + /// the hierarchy but shares animations and state machines with the original + /// [Artboard] it is instanced from. Instance an [Artboard] when you want to + /// show it muliptle times on the screen in the different states. + Artboard instance() { + /// Intentionally not implemented in the editor, must be overridden in + /// runtime version of the artboard. + throw UnsupportedError( + 'Instancing the artboard in the editor isn\'t supported'); + } } diff --git a/lib/src/rive_core/shapes/polygon.dart b/lib/src/rive_core/shapes/polygon.dart index 07d7904..fae5c94 100644 --- a/lib/src/rive_core/shapes/polygon.dart +++ b/lib/src/rive_core/shapes/polygon.dart @@ -15,6 +15,8 @@ class Polygon extends PolygonBase { @override List> get vertices { + double ox = -originX * width + width / 2; + double oy = -originY * height + height / 2; var vertexList = >[]; var halfWidth = width / 2; var halfHeight = height / 2; @@ -22,8 +24,8 @@ class Polygon extends PolygonBase { var inc = 2 * pi / points; for (int i = 0; i < points; i++) { vertexList.add(StraightVertex.procedural() - ..x = cos(angle) * halfWidth - ..y = sin(angle) * halfHeight + ..x = ox + cos(angle) * halfWidth + ..y = oy + sin(angle) * halfHeight ..radius = cornerRadius); angle += inc; } diff --git a/lib/src/rive_core/shapes/shape.dart b/lib/src/rive_core/shapes/shape.dart index 59dfc45..b775f91 100644 --- a/lib/src/rive_core/shapes/shape.dart +++ b/lib/src/rive_core/shapes/shape.dart @@ -30,7 +30,9 @@ class Shape extends ShapeBase with ShapePaintContainer { bool addPath(Path path) { paintChanged(); - return paths.add(path); + var added = paths.add(path); + + return added; } void _markComposerDirty() { diff --git a/lib/src/rive_core/shapes/star.dart b/lib/src/rive_core/shapes/star.dart index 23a977c..7c69c1d 100644 --- a/lib/src/rive_core/shapes/star.dart +++ b/lib/src/rive_core/shapes/star.dart @@ -12,6 +12,9 @@ class Star extends StarBase { @override List> get vertices { + double ox = -originX * width + width / 2; + double oy = -originY * height + height / 2; + var actualPoints = points * 2; var vertexList = >[]; var halfWidth = width / 2; @@ -22,13 +25,13 @@ class Star extends StarBase { var inc = 2 * pi / actualPoints; while (vertexList.length < actualPoints) { vertexList.add(StraightVertex.procedural() - ..x = cos(angle) * halfWidth - ..y = sin(angle) * halfHeight + ..x = ox + cos(angle) * halfWidth + ..y = oy + sin(angle) * halfHeight ..radius = cornerRadius); angle += inc; vertexList.add(StraightVertex.procedural() - ..x = cos(angle) * innerHalfWidth - ..y = sin(angle) * innerHalfHeight + ..x = ox + cos(angle) * innerHalfWidth + ..y = oy + sin(angle) * innerHalfHeight ..radius = cornerRadius); angle += inc; } diff --git a/lib/src/runtime_artboard.dart b/lib/src/runtime_artboard.dart index 969d5ce..9fd8f67 100644 --- a/lib/src/runtime_artboard.dart +++ b/lib/src/runtime_artboard.dart @@ -106,4 +106,32 @@ class RuntimeArtboard extends Artboard implements CoreContext { void markNeedsAdvance() { _redraw.notify(); } + + Artboard? instance() { + var artboard = RuntimeArtboard(); + artboard.copy(this); + artboard._objects.add(artboard); + // First copy the objects ensuring onAddedDirty can later find them in the + // _objects list. + for (final object in _objects.skip(1)) { + Core? clone = object?.clone(); + artboard._objects.add(clone); + } + + // Then run the onAddedDirty loop. + for (final object in artboard.objects.skip(1)) { + if (object is Component && + object.parentId == ComponentBase.parentIdInitialValue) { + object.parent = artboard; + } + object?.onAddedDirty(); + } + for (final object in artboard.objects.toList(growable: false)) { + if (object == null) { + continue; + } + object.onAdded(); + } + artboard.clean(); + } }