diff --git a/CHANGELOG.md b/CHANGELOG.md index a84809d..bf70b6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.6.0] - 2020-09-28 16:22:43 + +- Adding a ToC to files indicating included core properties and their backing field types so that they may be skipped by runtimes that do not understand those properties. This will allow newer minor version files to be read by older minor version runtimes. +- New clipping system allowing for recursive shapes to be included as sources by selecting a node for clipping. +- New draw order system using draw targets. + ## [0.5.2] - 2020-08-28 18:24:45 - Adding trim paths. diff --git a/example/assets/off_road_car.riv b/example/assets/off_road_car.riv new file mode 100644 index 0000000..3e9d9bb Binary files /dev/null and b/example/assets/off_road_car.riv differ diff --git a/example/lib/main.dart b/example/lib/main.dart index 6b8fd0f..945493b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -44,7 +44,7 @@ class _MyHomePageState extends State { // Load the animation file from the bundle, note that you could also // download this. The RiveFile just expects a list of bytes. - rootBundle.load('assets/teeny_tiny.riv').then( + rootBundle.load('assets/off_road_car.riv').then( (data) async { var file = RiveFile(); // Load the RiveFile from the binary data. diff --git a/example/pubspec.lock b/example/pubspec.lock index cb16ca4..22d6b07 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety" + version: "2.5.0-nullsafety.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.0-nullsafety.1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.2" + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.0-nullsafety.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.2" + version: "1.15.0-nullsafety.3" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.2.0-nullsafety.1" flutter: dependency: "direct main" description: flutter @@ -73,21 +73,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.3.0-nullsafety.3" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety" + version: "1.8.0-nullsafety.1" rive: dependency: "direct main" description: @@ -106,55 +106,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety" + version: "1.8.0-nullsafety.2" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.0-nullsafety.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety" + version: "0.2.19-nullsafety.2" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.3.0-nullsafety.3" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.2" + version: "2.1.0-nullsafety.3" sdks: - dart: ">=2.10.0-0.0.dev <2.10.0" + dart: ">=2.10.0-110 <2.11.0" diff --git a/lib/src/core/core.dart b/lib/src/core/core.dart index 458bc50..91c7921 100644 --- a/lib/src/core/core.dart +++ b/lib/src/core/core.dart @@ -1,14 +1,11 @@ -export 'package:rive/src/fractional/fractional.dart'; export 'package:rive/src/animation_list.dart'; export 'package:rive/src/container_children.dart'; export 'package:rive/src/runtime_artboard.dart'; export 'package:rive/src/generated/rive_core_context.dart'; - typedef PropertyChangeCallback = void Function(dynamic from, dynamic to); typedef BatchAddCallback = void Function(); - abstract class Core { covariant T context; int get coreType; @@ -20,7 +17,7 @@ abstract class Core { void onRemoved(); } -abstract class CoreContext{ +abstract class CoreContext { Core makeCoreInstance(int typeKey); T resolve(int id); void markDependencyOrderDirty(); diff --git a/lib/src/fractional/fractional.dart b/lib/src/fractional/fractional.dart deleted file mode 100644 index 687fe5c..0000000 --- a/lib/src/fractional/fractional.dart +++ /dev/null @@ -1,239 +0,0 @@ -import 'dart:collection'; - -const _minIndex = FractionalIndex.min(); -const _maxIndex = FractionalIndex.max(); - -abstract class FractionallyIndexedList extends ListBase { - final List _values; - FractionalIndex orderOf(T value); - List get values => _values; - - @override - int get length => _values.length; - - @override - set length(int value) => _values.length = value; - - @override - T operator [](int index) => _values[index]; - - @override - void operator []=(int index, T value) => _values[index] = value; - - FractionallyIndexedList({ - List values, - bool initOrder = true, - }) : _values = values ?? [] { - if (_values.isEmpty || !initOrder) { - return; - } - // Otherwise spread them evenly across our range using 1/2 as the midpoint. - int mid = _values.length ~/ 2; - var midIndex = const FractionalIndex(1, 2); - setOrderOf(_values[mid], midIndex); - - var lastIndex = midIndex; - for (int i = mid + 1; i < _values.length; i++) { - var index = FractionalIndex.between(lastIndex, _maxIndex); - setOrderOf(_values[i], index); - lastIndex = index; - } - - lastIndex = midIndex; - for (int i = mid - 1; i >= 0; i--) { - var index = FractionalIndex.between(_minIndex, lastIndex); - setOrderOf(_values[i], index); - lastIndex = index; - } - } - - FractionallyIndexedList.raw(List values) : _values = values ?? []; - - void setOrderOf(T value, FractionalIndex order); - - /// Set the fractional indices to match the current order of the items. This - /// is a pretty heavy operation as it could change the fractional index of - /// every item in the list. Should be used sparingly for cases that really - /// require it. - void setFractionalIndices() { - var previousIndex = _minIndex; - for (final item in _values) { - var index = FractionalIndex.between(previousIndex, _maxIndex); - setOrderOf(item, index); - previousIndex = index; - } - } - - int _compareIndex(T a, T b) { - return orderOf(a).compareTo(orderOf(b)); - } - - void sortFractional() => _values.sort(_compareIndex); - - bool validateFractional([FractionalIndex minimum]) { - var previousIndex = minimum ?? _minIndex; - - bool wasValid = true; - for (final item in _values) { - var order = orderOf(item); - if (order == null) { - wasValid = false; - continue; - } - if (order.compareTo(previousIndex) > 0) { - previousIndex = order; - } - } - if (wasValid) { - return true; - } - - for (final item in _values) { - if (orderOf(item) == null) { - var index = FractionalIndex.between(previousIndex, _maxIndex); - setOrderOf(item, index); - previousIndex = index; - } - } - return false; - } - - @override - void add(T item) { - assert(!contains(item)); - _values.add(item); - } - - @override - bool remove(Object element) => _values.remove(element); - - void append(T item) { - assert(!contains(item)); - var previousIndex = _values.isEmpty ? _minIndex : orderOf(_values.last); - setOrderOf(item, FractionalIndex.between(previousIndex, _maxIndex)); - _values.add(item); - } - - /// Gets the next fractional index safely, most of the other methods here - /// assume the index list is valid, this one does not. It'll find the best - /// next index. It's meant to be used to help implementations patch up their - /// lists as necessary. - FractionalIndex get nextFractionalIndex { - var previousIndex = _minIndex; - for (final item in _values) { - var order = orderOf(item); - if (order == null) { - continue; - } - if (order.compareTo(previousIndex) > 0) { - previousIndex = order; - } - } - return FractionalIndex.between(previousIndex, _maxIndex); - } - - void prepend(T item) { - assert(!contains(item)); - var firstIndex = _values.isEmpty ? _maxIndex : orderOf(_values.first); - setOrderOf(item, FractionalIndex.between(_minIndex, firstIndex)); - _values.add(item); - } - - void moveToEnd(T item) { - var previousIndex = _values.isEmpty ? _minIndex : orderOf(_values.last); - setOrderOf(item, FractionalIndex.between(previousIndex, _maxIndex)); - } - - void moveToStart(T item) { - var firstIndex = _values.isEmpty ? _maxIndex : orderOf(_values.first); - setOrderOf(item, FractionalIndex.between(_minIndex, firstIndex)); - } - - void move(T item, {T before, T after}) { - setOrderOf( - item, - FractionalIndex.between(before != null ? orderOf(before) : _minIndex, - after != null ? orderOf(after) : _maxIndex)); - } - - void reverse() { - var indices = []; - for (final item in _values) { - indices.add(orderOf(item)); - } - - var length = _values.length; - for (int i = 0; i < length; i++) { - setOrderOf(_values[i], indices[length - 1 - i]); - } - sortFractional(); - } -} - -class FractionalIndex { - final int numerator; - final int denominator; - - const FractionalIndex(this.numerator, this.denominator) - : assert(numerator < denominator); - - const FractionalIndex.min() - : numerator = 0, - denominator = 1; - const FractionalIndex.max() - : numerator = 1, - denominator = 1; - - int compareTo(FractionalIndex other) { - return numerator * other.denominator - denominator * other.numerator; - } - - FractionalIndex combine(FractionalIndex other) { - return FractionalIndex( - numerator + other.numerator, denominator + other.denominator); - } - - factory FractionalIndex.between(FractionalIndex a, FractionalIndex b) { - return FractionalIndex( - a.numerator + b.numerator, a.denominator + b.denominator) - .reduce(); - } - - FractionalIndex reduce() { - int x = numerator, y = denominator; - while (y != 0) { - int t = y; - y = x % y; - x = t; - } - return FractionalIndex(numerator ~/ x, denominator ~/ x); - } - - bool operator <(FractionalIndex other) { - return compareTo(other) < 0; - } - - bool operator >(FractionalIndex other) { - return compareTo(other) > 0; - } - - @override - bool operator ==(Object other) => - other is FractionalIndex && - other.numerator == numerator && - other.denominator == denominator; - - @override - int get hashCode => szudzik(numerator, denominator); - - @override - String toString() => '$numerator/$denominator'; -} - -/// Szudzik's function for hashing two ints together -int szudzik(int a, int b) { - // a and b must be >= 0 - int x = a.abs(); - int y = b.abs(); - return x >= y ? x * x + x + y : x + y * y; -} diff --git a/lib/src/utilities/dependency_sorter.dart b/lib/src/utilities/dependency_sorter.dart index 8137fe9..6625eec 100644 --- a/lib/src/utilities/dependency_sorter.dart +++ b/lib/src/utilities/dependency_sorter.dart @@ -15,7 +15,7 @@ class DependencySorter> { HashSet _perm; HashSet _temp; List _order; - List get order => _order; + List get order => _order.reversed.toList(); DependencySorter() { _perm = HashSet(); @@ -27,7 +27,7 @@ class DependencySorter> { if (!visit(root)) { return null; } - return _order; + return _order.reversed.toList(); } void reset() { @@ -54,7 +54,11 @@ class DependencySorter> { } } _perm.add(n); - _order.insert(0, n); + + // Note that we're adding in reverse order intentionally so we don't have to + // keep inserting at the start and re-alloc-ing the whole list...It does + // mean we need to reverse the list afterwards. + _order.add(n); return true; } @@ -89,7 +93,7 @@ class TarjansDependencySorter> visit(root); } - return _order; + return _order.reversed.toList(); } HashSet findCycles(T n) { diff --git a/pubspec.lock b/pubspec.lock index 768db6a..6af7cad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety" + version: "2.5.0-nullsafety.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.0-nullsafety.1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.2" + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.0-nullsafety.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.2" + version: "1.15.0-nullsafety.3" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.2.0-nullsafety.1" flutter: dependency: "direct main" description: flutter @@ -73,21 +73,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety" + version: "0.12.10-nullsafety.1" meta: dependency: "direct main" description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.3.0-nullsafety.3" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety" + version: "1.8.0-nullsafety.1" sky_engine: dependency: transitive description: flutter @@ -99,55 +99,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety" + version: "1.8.0-nullsafety.2" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.0-nullsafety.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety" + version: "0.2.19-nullsafety.2" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.3.0-nullsafety.3" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.2" + version: "2.1.0-nullsafety.3" sdks: - dart: ">=2.10.0-0.0.dev <2.10.0" + dart: ">=2.10.0-110 <2.11.0" diff --git a/pubspec.yaml b/pubspec.yaml index 9a8eaab..3c72cf2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rive description: Rive 2 Flutter Runtime -version: 0.5.2 +version: 0.6.0 repository: https://github.com/rive-app/rive-flutter homepage: https://rive.app