Merge pull request #42 from rive-app/visibility_toggles

Adding visibility toggles and prepping for 0.6.5.
This commit is contained in:
Matt Sullivan
2020-12-22 17:02:42 -08:00
committed by GitHub
17 changed files with 131 additions and 12 deletions

View File

@ -1,3 +1,9 @@
## [0.6.5] - 2020-12-22 16:49:39
- Fixing issue with older minor versions crashing when newer minor files included objects with unknown keys. The runtime can now read beyond those.
- Shapes and paths hidden in the editor will not show up at runtime.
- Runtime header now exposes Rive project id.
## [0.6.4] - 2020-12-11 15:43:01
- Adding support for parametric polygon and star shapes.

View File

@ -39,4 +39,24 @@ abstract class DrawableBase extends Node {
}
void blendModeValueChanged(int from, int to);
/// --------------------------------------------------------------------------
/// DrawableFlags field with key 129.
int _drawableFlags = 0;
static const int drawableFlagsPropertyKey = 129;
int get drawableFlags => _drawableFlags;
/// Change the [_drawableFlags] field value.
/// [drawableFlagsChanged] will be invoked only if the field's value has
/// changed.
set drawableFlags(int value) {
if (_drawableFlags == value) {
return;
}
int from = _drawableFlags;
_drawableFlags = value;
drawableFlagsChanged(from, value);
}
void drawableFlagsChanged(int from, int to);
}

View File

@ -41,6 +41,7 @@ import 'package:rive/src/generated/shapes/paint/solid_color_base.dart';
import 'package:rive/src/generated/shapes/paint/stroke_base.dart';
import 'package:rive/src/generated/shapes/paint/trim_path_base.dart';
import 'package:rive/src/generated/shapes/parametric_path_base.dart';
import 'package:rive/src/generated/shapes/path_base.dart';
import 'package:rive/src/generated/shapes/path_composer_base.dart';
import 'package:rive/src/generated/shapes/path_vertex_base.dart';
import 'package:rive/src/generated/shapes/points_path_base.dart';
@ -428,11 +429,21 @@ class RiveCoreContext {
object.y = value;
}
break;
case PathBase.pathFlagsPropertyKey:
if (object is PathBase && value is int) {
object.pathFlags = value;
}
break;
case DrawableBase.blendModeValuePropertyKey:
if (object is DrawableBase && value is int) {
object.blendModeValue = value;
}
break;
case DrawableBase.drawableFlagsPropertyKey:
if (object is DrawableBase && value is int) {
object.drawableFlags = value;
}
break;
case PathVertexBase.xPropertyKey:
if (object is PathVertexBase && value is double) {
object.x = value;
@ -729,7 +740,9 @@ class RiveCoreContext {
case StrokeBase.joinPropertyKey:
case TrimPathBase.modeValuePropertyKey:
case FillBase.fillRulePropertyKey:
case PathBase.pathFlagsPropertyKey:
case DrawableBase.blendModeValuePropertyKey:
case DrawableBase.drawableFlagsPropertyKey:
case WeightBase.valuesPropertyKey:
case WeightBase.indicesPropertyKey:
case CubicWeightBase.inValuesPropertyKey:
@ -868,8 +881,12 @@ class RiveCoreContext {
return (object as TrimPathBase).modeValue;
case FillBase.fillRulePropertyKey:
return (object as FillBase).fillRule;
case PathBase.pathFlagsPropertyKey:
return (object as PathBase).pathFlags;
case DrawableBase.blendModeValuePropertyKey:
return (object as DrawableBase).blendModeValue;
case DrawableBase.drawableFlagsPropertyKey:
return (object as DrawableBase).drawableFlags;
case WeightBase.valuesPropertyKey:
return (object as WeightBase).values;
case WeightBase.indicesPropertyKey:
@ -1121,9 +1138,15 @@ class RiveCoreContext {
case FillBase.fillRulePropertyKey:
(object as FillBase).fillRule = value;
break;
case PathBase.pathFlagsPropertyKey:
(object as PathBase).pathFlags = value;
break;
case DrawableBase.blendModeValuePropertyKey:
(object as DrawableBase).blendModeValue = value;
break;
case DrawableBase.drawableFlagsPropertyKey:
(object as DrawableBase).drawableFlags = value;
break;
case WeightBase.valuesPropertyKey:
(object as WeightBase).values = value;
break;

View File

@ -19,4 +19,23 @@ abstract class PathBase extends Node {
ContainerComponentBase.typeKey,
ComponentBase.typeKey
};
/// --------------------------------------------------------------------------
/// PathFlags field with key 128.
int _pathFlags = 0;
static const int pathFlagsPropertyKey = 128;
int get pathFlags => _pathFlags;
/// Change the [_pathFlags] field value.
/// [pathFlagsChanged] will be invoked only if the field's value has changed.
set pathFlags(int value) {
if (_pathFlags == value) {
return;
}
int from = _pathFlags;
_pathFlags = value;
pathFlagsChanged(from, value);
}
void pathFlagsChanged(int from, int to);
}

View File

@ -172,6 +172,9 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
for (var drawable = _firstDrawable;
drawable != null;
drawable = drawable.prev) {
if (drawable.isHidden) {
continue;
}
drawable.draw(canvas);
}
canvas.restore();

View File

@ -0,0 +1,4 @@
class ComponentFlags {
static const int hidden = 1 << 0;
static const int locked = 1 << 1;
}

View File

@ -1,5 +1,6 @@
import 'dart:ui';
import 'package:rive/src/rive_core/component_dirt.dart';
import 'package:rive/src/rive_core/component_flags.dart';
import 'package:rive/src/rive_core/container_component.dart';
import 'package:rive/src/rive_core/draw_rules.dart';
import 'package:rive/src/rive_core/shapes/clipping_shape.dart';
@ -60,4 +61,8 @@ abstract class Drawable extends DrawableBase {
_clippingShapes = clippingShapes.isEmpty ? null : clippingShapes;
}
}
@override
void drawableFlagsChanged(int from, int to) => addDirt(ComponentDirt.paint);
bool get isHidden => (drawableFlags & ComponentFlags.hidden) != 0;
}

View File

@ -44,7 +44,18 @@ class AABB {
-double.maxFinite
]);
}
double get area => width * height;
factory AABB.expand(AABB from, double amount) {
var aabb = AABB.clone(from);
if (aabb.width < amount) {
aabb[0] -= amount / 2;
aabb[2] += amount / 2;
}
if (aabb.height < amount) {
aabb[1] -= amount / 2;
aabb[3] += amount / 2;
}
return aabb;
}
bool get isEmpty => !AABB.isValid(this);
Vec2D includePoint(Vec2D point, Mat2D transform) {
var transformedPoint = transform == null

View File

@ -1,5 +1,6 @@
import 'dart:math';
import 'dart:typed_data';
import 'package:rive/src/utilities/utilities.dart';
import 'mat2d.dart';
class Vec2D {
@ -163,7 +164,13 @@ class Vec2D {
@override
String toString() {
String v = _buffer[0].toString() + ", ";
String v = _buffer[0].toString() + ', ';
return v + _buffer[1].toString();
}
@override
bool operator ==(Object o) =>
o is Vec2D && _buffer[0] == o[0] && _buffer[1] == o[1];
@override
int get hashCode => szudzik(_buffer[0].hashCode, _buffer[1].hashCode);
}

View File

@ -15,11 +15,11 @@ const riveVersion = RuntimeVersion(6, 3);
class RuntimeHeader {
static const String fingerprint = 'RIVE';
final RuntimeVersion version;
final int ownerId;
final int projectId;
final int fileId;
final HashMap<int, int> propertyToFieldIndex;
RuntimeHeader(
{@required this.ownerId,
{@required this.projectId,
@required this.fileId,
@required this.version,
this.propertyToFieldIndex});
@ -36,7 +36,7 @@ class RuntimeHeader {
throw RiveUnsupportedVersionException(riveVersion.major,
riveVersion.minor, readMajorVersion, readMinorVersion);
}
int ownerId = reader.readVarUint();
int projectId = reader.readVarUint();
int fileId = reader.readVarUint();
var propertyFields = HashMap<int, int>();
var propertyKeys = <int>[];
@ -57,7 +57,7 @@ class RuntimeHeader {
currentBit += 2;
}
return RuntimeHeader(
ownerId: ownerId,
projectId: projectId,
fileId: fileId,
version: RuntimeVersion(readMajorVersion, readMinorVersion),
propertyToFieldIndex: propertyFields);

View File

@ -2,6 +2,7 @@ import 'dart:math';
import 'dart:ui' as ui;
import 'package:rive/src/rive_core/component.dart';
import 'package:rive/src/rive_core/component_dirt.dart';
import 'package:rive/src/rive_core/component_flags.dart';
import 'package:rive/src/rive_core/math/circle_constant.dart';
import 'package:rive/src/rive_core/math/mat2d.dart';
import 'package:rive/src/rive_core/math/vec2d.dart';
@ -215,6 +216,10 @@ abstract class Path extends PathBase {
}
return true;
}
@override
void pathFlagsChanged(int from, int to) => markPathDirty();
bool get isHidden => (pathFlags & ComponentFlags.hidden) != 0;
}
class RenderPath {

View File

@ -32,6 +32,9 @@ class PathComposer extends PathComposerBase {
Mat2D inverseWorld = Mat2D();
if (Mat2D.invert(inverseWorld, world)) {
for (final path in _shape.paths) {
if (path.isHidden) {
continue;
}
Mat2D localTransform;
var transform = path.pathTransform;
if (transform != null) {
@ -46,6 +49,9 @@ class PathComposer extends PathComposerBase {
if (buildWorldPath) {
worldPath.reset();
for (final path in _shape.paths) {
if (path.isHidden) {
continue;
}
worldPath.addPath(path.uiPath, ui.Offset.zero,
matrix4: path.pathTransform?.mat4);
}

View File

@ -12,7 +12,7 @@ class Polygon extends PolygonBase {
void pointsChanged(int from, int to) => markPathDirty();
@override
List<PathVertex<Weight>> get vertices {
var vertexList = List<StraightVertex>(points);
var vertexList = List<StraightVertex>.filled(points, null);
var halfWidth = width / 2;
var halfHeight = height / 2;
var angle = -pi / 2;

View File

@ -11,7 +11,8 @@ class Star extends StarBase {
@override
List<PathVertex<Weight>> get vertices {
var actualPoints = points * 2;
var vertexList = List<StraightVertex>(actualPoints);
var vertexList =
List<StraightVertex>.filled(actualPoints, null, growable: false);
var halfWidth = width / 2;
var halfHeight = height / 2;
var innerHalfWidth = width * innerRadius / 2;

View File

@ -100,7 +100,7 @@ class RiveFile {
animation.artboard = artboard;
if (animation is LinearAnimation) {
var numKeyedObjects = reader.readVarUint();
var keyedObjects = List<KeyedObject>(numKeyedObjects);
var keyedObjects = List<KeyedObject>.filled(numKeyedObjects, null);
for (int j = 0; j < numKeyedObjects; j++) {
var keyedObject =
_readRuntimeObject<KeyedObject>(reader, propertyToField);

View File

@ -0,0 +1,9 @@
/// Szudzik's function for hashing two ints together
int szudzik(int a, int b) {
assert(a != null && b != null);
// a and b must be >= 0
int x = a.abs();
int y = b.abs();
return x >= y ? x * x + x + y : x + y * y;
}

View File

@ -1,6 +1,6 @@
name: rive
description: Rive 2 Flutter Runtime. This package provides runtime functionality for playing back and interacting with animations built with the Rive editor available at https://rive.app.
version: 0.6.4
version: 0.6.5
repository: https://github.com/rive-app/rive-flutter
homepage: https://rive.app