mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-06-26 01:18:13 +08:00
Fixes from updated core generator in rive editor.
This commit is contained in:
@ -103,8 +103,6 @@ import 'package:rive/src/rive_core/shapes/rectangle.dart';
|
||||
import 'package:rive/src/rive_core/shapes/shape.dart';
|
||||
import 'package:rive/src/rive_core/shapes/star.dart';
|
||||
import 'package:rive/src/rive_core/shapes/straight_vertex.dart';
|
||||
import 'package:rive/src/rive_core/shapes/text.dart';
|
||||
import 'package:rive/src/rive_core/shapes/text_run.dart';
|
||||
import 'package:rive/src/rive_core/shapes/triangle.dart';
|
||||
|
||||
// ignore: avoid_classes_with_only_static_members
|
||||
@ -217,8 +215,6 @@ class RiveCoreContext {
|
||||
return CubicAsymmetricVertex();
|
||||
case MeshBase.typeKey:
|
||||
return Mesh();
|
||||
case TextRunBase.typeKey:
|
||||
return TextRun();
|
||||
case PointsPathBase.typeKey:
|
||||
return PointsPath();
|
||||
case ContourMeshVertexBase.typeKey:
|
||||
@ -239,8 +235,6 @@ class RiveCoreContext {
|
||||
return Star();
|
||||
case ImageBase.typeKey:
|
||||
return Image();
|
||||
case TextBase.typeKey:
|
||||
return Text();
|
||||
case CubicDetachedVertexBase.typeKey:
|
||||
return CubicDetachedVertex();
|
||||
case DrawRulesBase.typeKey:
|
||||
@ -825,16 +819,6 @@ class RiveCoreContext {
|
||||
object.triangleIndexBytes = value;
|
||||
}
|
||||
break;
|
||||
case TextRunBase.pointSizePropertyKey:
|
||||
if (object is TextRunBase && value is double) {
|
||||
object.pointSize = value;
|
||||
}
|
||||
break;
|
||||
case TextRunBase.textLengthPropertyKey:
|
||||
if (object is TextRunBase && value is int) {
|
||||
object.textLength = value;
|
||||
}
|
||||
break;
|
||||
case PointsPathBase.isClosedPropertyKey:
|
||||
if (object is PointsPathBase && value is bool) {
|
||||
object.isClosed = value;
|
||||
@ -930,11 +914,6 @@ class RiveCoreContext {
|
||||
object.assetId = value;
|
||||
}
|
||||
break;
|
||||
case TextBase.valuePropertyKey:
|
||||
if (object is TextBase && value is String) {
|
||||
object.value = value;
|
||||
}
|
||||
break;
|
||||
case CubicDetachedVertexBase.inRotationPropertyKey:
|
||||
if (object is CubicDetachedVertexBase && value is double) {
|
||||
object.inRotation = value;
|
||||
@ -1114,7 +1093,6 @@ class RiveCoreContext {
|
||||
case ComponentBase.namePropertyKey:
|
||||
case AnimationBase.namePropertyKey:
|
||||
case StateMachineComponentBase.namePropertyKey:
|
||||
case TextBase.valuePropertyKey:
|
||||
case AssetBase.namePropertyKey:
|
||||
return stringType;
|
||||
case ComponentBase.parentIdPropertyKey:
|
||||
@ -1163,7 +1141,6 @@ class RiveCoreContext {
|
||||
case CubicWeightBase.inIndicesPropertyKey:
|
||||
case CubicWeightBase.outValuesPropertyKey:
|
||||
case CubicWeightBase.outIndicesPropertyKey:
|
||||
case TextRunBase.textLengthPropertyKey:
|
||||
case ClippingShapeBase.sourceIdPropertyKey:
|
||||
case ClippingShapeBase.fillRulePropertyKey:
|
||||
case PolygonBase.pointsPropertyKey:
|
||||
@ -1216,7 +1193,6 @@ class RiveCoreContext {
|
||||
case CubicAsymmetricVertexBase.rotationPropertyKey:
|
||||
case CubicAsymmetricVertexBase.inDistancePropertyKey:
|
||||
case CubicAsymmetricVertexBase.outDistancePropertyKey:
|
||||
case TextRunBase.pointSizePropertyKey:
|
||||
case ParametricPathBase.widthPropertyKey:
|
||||
case ParametricPathBase.heightPropertyKey:
|
||||
case ParametricPathBase.originXPropertyKey:
|
||||
@ -1296,8 +1272,6 @@ class RiveCoreContext {
|
||||
return (object as AnimationBase).name;
|
||||
case StateMachineComponentBase.namePropertyKey:
|
||||
return (object as StateMachineComponentBase).name;
|
||||
case TextBase.valuePropertyKey:
|
||||
return (object as TextBase).value;
|
||||
case AssetBase.namePropertyKey:
|
||||
return (object as AssetBase).name;
|
||||
}
|
||||
@ -1398,8 +1372,6 @@ class RiveCoreContext {
|
||||
return (object as CubicWeightBase).outValues;
|
||||
case CubicWeightBase.outIndicesPropertyKey:
|
||||
return (object as CubicWeightBase).outIndices;
|
||||
case TextRunBase.textLengthPropertyKey:
|
||||
return (object as TextRunBase).textLength;
|
||||
case ClippingShapeBase.sourceIdPropertyKey:
|
||||
return (object as ClippingShapeBase).sourceId;
|
||||
case ClippingShapeBase.fillRulePropertyKey:
|
||||
@ -1508,8 +1480,6 @@ class RiveCoreContext {
|
||||
return (object as CubicAsymmetricVertexBase).inDistance;
|
||||
case CubicAsymmetricVertexBase.outDistancePropertyKey:
|
||||
return (object as CubicAsymmetricVertexBase).outDistance;
|
||||
case TextRunBase.pointSizePropertyKey:
|
||||
return (object as TextRunBase).pointSize;
|
||||
case ParametricPathBase.widthPropertyKey:
|
||||
return (object as ParametricPathBase).width;
|
||||
case ParametricPathBase.heightPropertyKey:
|
||||
@ -1673,11 +1643,6 @@ class RiveCoreContext {
|
||||
object.name = value;
|
||||
}
|
||||
break;
|
||||
case TextBase.valuePropertyKey:
|
||||
if (object is TextBase) {
|
||||
object.value = value;
|
||||
}
|
||||
break;
|
||||
case AssetBase.namePropertyKey:
|
||||
if (object is AssetBase) {
|
||||
object.name = value;
|
||||
@ -1918,11 +1883,6 @@ class RiveCoreContext {
|
||||
object.outIndices = value;
|
||||
}
|
||||
break;
|
||||
case TextRunBase.textLengthPropertyKey:
|
||||
if (object is TextRunBase) {
|
||||
object.textLength = value;
|
||||
}
|
||||
break;
|
||||
case ClippingShapeBase.sourceIdPropertyKey:
|
||||
if (object is ClippingShapeBase) {
|
||||
object.sourceId = value;
|
||||
@ -2183,11 +2143,6 @@ class RiveCoreContext {
|
||||
object.outDistance = value;
|
||||
}
|
||||
break;
|
||||
case TextRunBase.pointSizePropertyKey:
|
||||
if (object is TextRunBase) {
|
||||
object.pointSize = value;
|
||||
}
|
||||
break;
|
||||
case ParametricPathBase.widthPropertyKey:
|
||||
if (object is ParametricPathBase) {
|
||||
object.width = value;
|
||||
|
@ -1,53 +0,0 @@
|
||||
/// Core automatically generated lib/src/generated/shapes/text_base.dart.
|
||||
/// Do not modify manually.
|
||||
|
||||
import 'package:rive/src/generated/component_base.dart';
|
||||
import 'package:rive/src/generated/container_component_base.dart';
|
||||
import 'package:rive/src/generated/transform_component_base.dart';
|
||||
import 'package:rive/src/generated/world_transform_component_base.dart';
|
||||
import 'package:rive/src/rive_core/node.dart';
|
||||
|
||||
abstract class TextBase extends Node {
|
||||
static const int typeKey = 110;
|
||||
@override
|
||||
int get coreType => TextBase.typeKey;
|
||||
@override
|
||||
Set<int> get coreTypes => {
|
||||
TextBase.typeKey,
|
||||
NodeBase.typeKey,
|
||||
TransformComponentBase.typeKey,
|
||||
WorldTransformComponentBase.typeKey,
|
||||
ContainerComponentBase.typeKey,
|
||||
ComponentBase.typeKey
|
||||
};
|
||||
|
||||
/// --------------------------------------------------------------------------
|
||||
/// Value field with key 218.
|
||||
static const String valueInitialValue = '';
|
||||
String _value = valueInitialValue;
|
||||
static const int valuePropertyKey = 218;
|
||||
|
||||
/// The value stored in the Text object.
|
||||
String get value => _value;
|
||||
|
||||
/// Change the [_value] field value.
|
||||
/// [valueChanged] will be invoked only if the field's value has changed.
|
||||
set value(String value) {
|
||||
if (_value == value) {
|
||||
return;
|
||||
}
|
||||
String from = _value;
|
||||
_value = value;
|
||||
if (hasValidated) {
|
||||
valueChanged(from, value);
|
||||
}
|
||||
}
|
||||
|
||||
void valueChanged(String from, String to);
|
||||
|
||||
@override
|
||||
void copy(covariant TextBase source) {
|
||||
super.copy(source);
|
||||
_value = source._value;
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/// Core automatically generated lib/src/generated/shapes/text_run_base.dart.
|
||||
/// Do not modify manually.
|
||||
|
||||
import 'package:rive/src/generated/component_base.dart';
|
||||
import 'package:rive/src/generated/container_component_base.dart';
|
||||
import 'package:rive/src/generated/node_base.dart';
|
||||
import 'package:rive/src/generated/transform_component_base.dart';
|
||||
import 'package:rive/src/generated/world_transform_component_base.dart';
|
||||
import 'package:rive/src/rive_core/drawable.dart';
|
||||
|
||||
abstract class TextRunBase extends Drawable {
|
||||
static const int typeKey = 113;
|
||||
@override
|
||||
int get coreType => TextRunBase.typeKey;
|
||||
@override
|
||||
Set<int> get coreTypes => {
|
||||
TextRunBase.typeKey,
|
||||
DrawableBase.typeKey,
|
||||
NodeBase.typeKey,
|
||||
TransformComponentBase.typeKey,
|
||||
WorldTransformComponentBase.typeKey,
|
||||
ContainerComponentBase.typeKey,
|
||||
ComponentBase.typeKey
|
||||
};
|
||||
|
||||
/// --------------------------------------------------------------------------
|
||||
/// PointSize field with key 221.
|
||||
static const double pointSizeInitialValue = 16;
|
||||
double _pointSize = pointSizeInitialValue;
|
||||
static const int pointSizePropertyKey = 221;
|
||||
|
||||
/// The point size for text styled by this run.
|
||||
double get pointSize => _pointSize;
|
||||
|
||||
/// Change the [_pointSize] field value.
|
||||
/// [pointSizeChanged] will be invoked only if the field's value has changed.
|
||||
set pointSize(double value) {
|
||||
if (_pointSize == value) {
|
||||
return;
|
||||
}
|
||||
double from = _pointSize;
|
||||
_pointSize = value;
|
||||
if (hasValidated) {
|
||||
pointSizeChanged(from, value);
|
||||
}
|
||||
}
|
||||
|
||||
void pointSizeChanged(double from, double to);
|
||||
|
||||
/// --------------------------------------------------------------------------
|
||||
/// TextLength field with key 222.
|
||||
static const int textLengthInitialValue = 0;
|
||||
int _textLength = textLengthInitialValue;
|
||||
static const int textLengthPropertyKey = 222;
|
||||
|
||||
/// The length of the text styled by this run.
|
||||
int get textLength => _textLength;
|
||||
|
||||
/// Change the [_textLength] field value.
|
||||
/// [textLengthChanged] will be invoked only if the field's value has changed.
|
||||
set textLength(int value) {
|
||||
if (_textLength == value) {
|
||||
return;
|
||||
}
|
||||
int from = _textLength;
|
||||
_textLength = value;
|
||||
if (hasValidated) {
|
||||
textLengthChanged(from, value);
|
||||
}
|
||||
}
|
||||
|
||||
void textLengthChanged(int from, int to);
|
||||
|
||||
@override
|
||||
void copy(covariant TextRunBase source) {
|
||||
super.copy(source);
|
||||
_pointSize = source._pointSize;
|
||||
_textLength = source._textLength;
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import 'package:rive/src/rive_core/bones/bone.dart';
|
||||
import 'package:rive/src/rive_core/bones/skinnable.dart';
|
||||
import 'package:rive/src/rive_core/bones/tendon.dart';
|
||||
import 'package:rive/src/rive_core/component.dart';
|
||||
import 'package:rive/src/rive_core/component_dirt.dart';
|
||||
import 'package:rive/src/rive_core/math/mat2d.dart';
|
||||
import 'package:rive/src/rive_core/shapes/vertex.dart';
|
||||
|
||||
@ -22,9 +23,6 @@ class Skin extends SkinBase {
|
||||
void onDirty(int mask) {
|
||||
// When the skin is dirty the deformed skinnable will need to regenerate its
|
||||
// drawing commands.
|
||||
|
||||
// TODO: rename path to topology/surface something common between path &
|
||||
// mesh.
|
||||
(parent as Skinnable).markSkinDirty();
|
||||
}
|
||||
|
||||
@ -34,6 +32,7 @@ class Skin extends SkinBase {
|
||||
// should only be worldTransform from the bones (recursively passed down) or
|
||||
// ComponentDirt.path from the PointsPath (set explicitly).
|
||||
var size = (_tendons.length + 1) * 6;
|
||||
|
||||
if (_boneTransforms.length != size) {
|
||||
_boneTransforms = Float32List(size);
|
||||
_boneTransforms[0] = 1;
|
||||
@ -116,6 +115,8 @@ class Skin extends SkinBase {
|
||||
switch (child.coreType) {
|
||||
case TendonBase.typeKey:
|
||||
_tendons.add(child as Tendon);
|
||||
// Add dirt to recompute stored _boneTransforms
|
||||
addDirt(ComponentDirt.worldTransform);
|
||||
markRebuildDependencies();
|
||||
if (parent is Skinnable) {
|
||||
parent!.markRebuildDependencies();
|
||||
@ -133,6 +134,8 @@ class Skin extends SkinBase {
|
||||
if (_tendons.isEmpty) {
|
||||
remove();
|
||||
} else {
|
||||
// Add dirt to recompute stored _boneTransforms
|
||||
addDirt(ComponentDirt.worldTransform);
|
||||
markRebuildDependencies();
|
||||
}
|
||||
parent?.markRebuildDependencies();
|
||||
|
@ -46,7 +46,23 @@ class Mesh extends MeshBase with Skinnable<MeshVertex> {
|
||||
Drawable get drawable => parent as Drawable;
|
||||
|
||||
@override
|
||||
bool validate() => super.validate() && parent is TransformComponent;
|
||||
bool validate() =>
|
||||
super.validate() &&
|
||||
parent is TransformComponent &&
|
||||
_areTriangleIndicesValid();
|
||||
|
||||
bool _areTriangleIndicesValid() {
|
||||
var maxIndex = vertices.length;
|
||||
if (triangleIndices.length % 3 != 0) {
|
||||
return false;
|
||||
}
|
||||
for (final index in triangleIndices) {
|
||||
if (index >= maxIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
void childAdded(Component child) {
|
||||
@ -120,8 +136,8 @@ class Mesh extends MeshBase with Skinnable<MeshVertex> {
|
||||
}
|
||||
|
||||
@override
|
||||
void onAdded() {
|
||||
super.onAdded();
|
||||
void onAddedDirty() {
|
||||
super.onAddedDirty();
|
||||
|
||||
_deserializeTriangleIndices();
|
||||
}
|
||||
|
@ -1,81 +0,0 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:rive/src/generated/shapes/text_base.dart';
|
||||
import 'package:rive/src/rive_core/component_dirt.dart';
|
||||
import 'package:rive/src/rive_core/shapes/text_run.dart';
|
||||
import 'package:rive/src/rive_core/src/text/paragraph.dart' as rive;
|
||||
|
||||
export 'package:rive/src/generated/shapes/text_base.dart';
|
||||
|
||||
class Text extends TextBase with rive.Paragraph {
|
||||
List<TextRun> _textRuns = [];
|
||||
List<int> _textCodes = [];
|
||||
Text() {
|
||||
frame = const Rect.fromLTWH(0, 0, 200, 200);
|
||||
}
|
||||
@override
|
||||
List<TextRun> get textRuns => _textRuns;
|
||||
|
||||
@override
|
||||
List<int> get textCodes => _textCodes;
|
||||
|
||||
@override
|
||||
void removeRun(TextRun run, int index) {
|
||||
run.remove();
|
||||
sortChildren();
|
||||
}
|
||||
|
||||
@override
|
||||
bool validate() => super.validate() && areTextRunsValid;
|
||||
@override
|
||||
void onAddedDirty() {
|
||||
super.onAddedDirty();
|
||||
_textCodes = value.codeUnits.toList(growable: true);
|
||||
}
|
||||
|
||||
@override
|
||||
void textCodesChanged() {
|
||||
value = String.fromCharCodes(textCodes);
|
||||
markTextShapeDirty();
|
||||
}
|
||||
|
||||
@override
|
||||
void modifyRuns(int start, int end, rive.TextRunMutator mutator) {
|
||||
super.modifyRuns(start, end, mutator);
|
||||
markTextShapeDirty();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void sortChildren() {
|
||||
// Cache the runs.
|
||||
_textRuns = children.whereType<TextRun>().toList();
|
||||
markTextShapeDirty();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void valueChanged(String from, String to) {
|
||||
_textCodes = value.codeUnits.toList(growable: true);
|
||||
super.textCodesChanged();
|
||||
markTextShapeDirty();
|
||||
}
|
||||
|
||||
void markTextShapeDirty() {
|
||||
addDirt(ComponentDirt.textShape);
|
||||
}
|
||||
|
||||
@override
|
||||
void update(int dirt) {
|
||||
super.update(dirt);
|
||||
if ((dirt & ComponentDirt.textShape) != 0) {
|
||||
for (final textRun in _textRuns) {
|
||||
textRun.clearGlyphRuns();
|
||||
}
|
||||
visitGlyphs((glyphRun, start, end, originX, originY) {
|
||||
var textRun = glyphRun.textRun as TextRun;
|
||||
textRun.addGlyphRun(glyphRun, start, end, originX, originY);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:rive/src/generated/shapes/text_run_base.dart';
|
||||
import 'package:rive/src/rive_core/shapes/text.dart';
|
||||
import 'package:rive/src/rive_core/src/text/raw_path.dart' as rive;
|
||||
import 'package:rive/src/rive_core/src/text/rive_font.dart';
|
||||
import 'package:rive/src/rive_core/src/text/shape_text.dart' as rive;
|
||||
|
||||
export 'package:rive/src/generated/shapes/text_run_base.dart';
|
||||
|
||||
class _DrawableGlyphRun {
|
||||
final rive.GlyphRun run;
|
||||
final int start;
|
||||
final int end;
|
||||
final double ox;
|
||||
final double oy;
|
||||
|
||||
_DrawableGlyphRun(this.run, this.start, this.end, this.ox, this.oy);
|
||||
}
|
||||
|
||||
class TextRun extends TextRunBase implements rive.TextRun {
|
||||
@override
|
||||
RiveFont font = RiveFont.builtIn;
|
||||
final List<_DrawableGlyphRun> _glyphRuns = [];
|
||||
|
||||
void clearGlyphRuns() => _glyphRuns.clear();
|
||||
|
||||
void addGlyphRun(
|
||||
rive.GlyphRun glyphRun, int start, int end, double x, double y) {
|
||||
_glyphRuns.add(_DrawableGlyphRun(glyphRun, start, end, x, y));
|
||||
}
|
||||
|
||||
Object? attr;
|
||||
@override
|
||||
bool validate() {
|
||||
return super.validate() && parent is Text;
|
||||
}
|
||||
|
||||
Text get text => parent as Text;
|
||||
|
||||
@override
|
||||
void draw(Canvas canvas) {
|
||||
canvas.save();
|
||||
canvas.transform(text.worldTransform.mat4);
|
||||
for (final drawableRun in _glyphRuns) {
|
||||
_visitRawPaths(drawableRun.run, drawableRun.start, drawableRun.end,
|
||||
drawableRun.ox, drawableRun.oy, (rive.RawPath rp) {
|
||||
canvas.drawPath(_toPath(rp), Paint()..color = const Color(0xFFFFFFFF));
|
||||
});
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
void pointSizeChanged(double from, double to) {
|
||||
text.markTextShapeDirty();
|
||||
}
|
||||
|
||||
@override
|
||||
void textLengthChanged(int from, int to) {}
|
||||
|
||||
@override
|
||||
rive.TextRun cloneRun() {
|
||||
var cloned = super.clone();
|
||||
assert(cloned is TextRun);
|
||||
return cloned as TextRun;
|
||||
}
|
||||
}
|
||||
|
||||
// Should generalize all of this...
|
||||
Path _toPath(rive.RawPath rp) {
|
||||
Path p = Path();
|
||||
rp.sinker(p.moveTo, p.lineTo, p.quadraticBezierTo, p.cubicTo, p.close);
|
||||
return p;
|
||||
}
|
||||
|
||||
void _visitRawPaths(rive.GlyphRun run, int start, int end, double x, double y,
|
||||
Function(rive.RawPath) visitor) {
|
||||
for (int i = start; i < end; ++i) {
|
||||
final rive.RawPath? p = run.font.getRawPath(run.glyphs[i]);
|
||||
if (p != null) {
|
||||
visitor(p.scalexy(run.pointSize, run.pointSize, x + run.xpos[i], y));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user