diff --git a/lib/rive_math.dart b/lib/rive_math.dart new file mode 100644 index 0000000..a0ef6af --- /dev/null +++ b/lib/rive_math.dart @@ -0,0 +1,4 @@ +library rive; + +export 'package:rive/src/rive_core/math/mat2d.dart'; +export 'package:rive/src/rive_core/math/vec2d.dart'; diff --git a/lib/src/rive_core/artboard.dart b/lib/src/rive_core/artboard.dart index 19295c7..3cb763a 100644 --- a/lib/src/rive_core/artboard.dart +++ b/lib/src/rive_core/artboard.dart @@ -21,6 +21,27 @@ import 'package:rive/src/utilities/dependency_sorter.dart'; export 'package:rive/src/generated/artboard_base.dart'; class Artboard extends ArtboardBase with ShapePaintContainer { + bool _frameOrigin = true; + + /// Returns true when the artboard will shift the origin from the top left to + /// the relative width/height of the artboard itself. This is what the editor + /// does visually when you change the origin value to give context as to where + /// the origin lies within the framed bounds. + bool get frameOrigin => _frameOrigin; + + /// When composing multiple artboards together in a common world-space, it may + /// be desireable to have them share the same space regardless of origin + /// offset from the bounding artboard. Set frameOrigin to false to move the + /// bounds relative to the origin instead of the origin relative to the + /// bounds. + set frameOrigin(bool value) { + if (_frameOrigin == value) { + return; + } + _frameOrigin = value; + addDirt(ComponentDirt.paint); + } + /// Should antialiasing be used when drawing? bool _antialiasing = true; @@ -73,9 +94,20 @@ class Artboard extends ArtboardBase with ShapePaintContainer { int _dirtDepth = 0; int _dirt = 255; + /// Iterate each component and call callback for it. void forEachComponent(void Function(Component) callback) => _components.forEach(callback); + /// Find a component of a specific type with a specific name. + T? component(String name) { + for (final component in _components) { + if (component is T && component.name == name) { + return component as T; + } + } + return null; + } + @override Artboard get artboard => this; @@ -254,7 +286,12 @@ class Artboard extends ArtboardBase with ShapePaintContainer { void draw(Canvas canvas) { canvas.save(); if (clip) { - canvas.clipRect(Rect.fromLTWH(0, 0, width, height)); + if (_frameOrigin) { + canvas.clipRect(Rect.fromLTWH(0, 0, width, height)); + } else { + canvas.clipRect( + Rect.fromLTWH(-width * originX, -height * originY, width, height)); + } } // Get into artboard's world space. This is because the artboard draws // components in the artboard's space (in component lingo we call this world @@ -266,7 +303,9 @@ class Artboard extends ArtboardBase with ShapePaintContainer { // rename those to artboardTransform and worldTransform is only reserved for // stageItems? The other option is to stick with 'worldTransform' in // components and use 'editor or stageTransform' for stageItems. - canvas.translate(width * originX, height * originY); + if (_frameOrigin) { + canvas.translate(width * originX, height * originY); + } for (final fill in fills) { fill.draw(canvas, path); } diff --git a/lib/src/rive_core/asset.dart b/lib/src/rive_core/asset.dart index 56cc3c3..02fc999 100644 --- a/lib/src/rive_core/asset.dart +++ b/lib/src/rive_core/asset.dart @@ -1,4 +1,3 @@ -import 'package:rive/src/core/core.dart'; import 'package:rive/src/generated/asset_base.dart'; import 'package:rive/src/rive_core/backboard.dart'; @@ -17,9 +16,4 @@ class Asset extends AssetBase { @override void onAddedDirty() {} - - @override - bool import(ImportStack stack) { - return super.import(stack); - } }