mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-06-23 07:18:17 +08:00
Fixing origin
This commit is contained in:
@ -250,8 +250,10 @@ class StateMachineController extends RiveAnimationController<CoreContext> {
|
|||||||
late List<_HitShape> hitShapes;
|
late List<_HitShape> hitShapes;
|
||||||
late List<NestedArtboard> hitNestedArtboards;
|
late List<NestedArtboard> hitNestedArtboards;
|
||||||
|
|
||||||
|
Artboard? _artboard;
|
||||||
|
|
||||||
/// The artboard that this state machine controller is manipulating.
|
/// The artboard that this state machine controller is manipulating.
|
||||||
Artboard? get artboard => stateMachine.artboard;
|
Artboard? get artboard => _artboard;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool init(CoreContext core) {
|
bool init(CoreContext core) {
|
||||||
@ -292,14 +294,16 @@ class StateMachineController extends RiveAnimationController<CoreContext> {
|
|||||||
}
|
}
|
||||||
hitShapes = hitShapeLookup.values.toList();
|
hitShapes = hitShapeLookup.values.toList();
|
||||||
|
|
||||||
var artboard = core as RuntimeArtboard;
|
_artboard = core as RuntimeArtboard;
|
||||||
|
|
||||||
List<NestedArtboard> nestedArtboards = [];
|
List<NestedArtboard> nestedArtboards = [];
|
||||||
for (final nestedArtboard in artboard.activeNestedArtboards) {
|
if (_artboard != null) {
|
||||||
|
for (final nestedArtboard in _artboard!.activeNestedArtboards) {
|
||||||
if (nestedArtboard.hasNestedStateMachine) {
|
if (nestedArtboard.hasNestedStateMachine) {
|
||||||
nestedArtboards.add(nestedArtboard);
|
nestedArtboards.add(nestedArtboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
hitNestedArtboards = nestedArtboards;
|
hitNestedArtboards = nestedArtboards;
|
||||||
return super.init(core);
|
return super.init(core);
|
||||||
}
|
}
|
||||||
@ -338,6 +342,18 @@ class StateMachineController extends RiveAnimationController<CoreContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _processEvent(Vec2D position, {EventType? hitEvent}) {
|
void _processEvent(Vec2D position, {EventType? hitEvent}) {
|
||||||
|
var artboard = this.artboard;
|
||||||
|
if (artboard == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (artboard.frameOrigin) {
|
||||||
|
// ignore: parameter_assignments
|
||||||
|
position = position -
|
||||||
|
Vec2D.fromValues(
|
||||||
|
artboard.width * artboard.originX,
|
||||||
|
artboard.height * artboard.originY,
|
||||||
|
);
|
||||||
|
}
|
||||||
const hitRadius = 2;
|
const hitRadius = 2;
|
||||||
var hitArea = IAABB(
|
var hitArea = IAABB(
|
||||||
(position.x - hitRadius).round(),
|
(position.x - hitRadius).round(),
|
||||||
|
@ -129,6 +129,7 @@ class RuntimeNestedStateMachineInstance extends NestedStateMachineInstance {
|
|||||||
class RuntimeMountedArtboard extends MountedArtboard {
|
class RuntimeMountedArtboard extends MountedArtboard {
|
||||||
final RuntimeArtboard artboardInstance;
|
final RuntimeArtboard artboardInstance;
|
||||||
RuntimeMountedArtboard(this.artboardInstance) {
|
RuntimeMountedArtboard(this.artboardInstance) {
|
||||||
|
artboardInstance.frameOrigin = false;
|
||||||
artboardInstance.advance(0, nested: true);
|
artboardInstance.advance(0, nested: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,8 +143,6 @@ class RuntimeMountedArtboard extends MountedArtboard {
|
|||||||
void draw(Canvas canvas) {
|
void draw(Canvas canvas) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.transform(worldTransform.mat4);
|
canvas.transform(worldTransform.mat4);
|
||||||
canvas.translate(-artboardInstance.originX * artboardInstance.width,
|
|
||||||
-artboardInstance.originY * artboardInstance.height);
|
|
||||||
artboardInstance.draw(canvas);
|
artboardInstance.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
@ -169,10 +168,4 @@ class RuntimeMountedArtboard extends MountedArtboard {
|
|||||||
@override
|
@override
|
||||||
bool advance(double seconds) =>
|
bool advance(double seconds) =>
|
||||||
artboardInstance.advance(seconds, nested: true);
|
artboardInstance.advance(seconds, nested: true);
|
||||||
|
|
||||||
@override
|
|
||||||
Mat2D get originTransform => Mat2D.fromTranslate(
|
|
||||||
artboardInstance.width * -artboardInstance.originX,
|
|
||||||
artboardInstance.height * -artboardInstance.originY,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -189,18 +189,17 @@ class _RiveAnimationState extends State<RiveAnimation> {
|
|||||||
}
|
}
|
||||||
var globalCoordinates = renderObject.localToGlobal(local);
|
var globalCoordinates = renderObject.localToGlobal(local);
|
||||||
|
|
||||||
var artboardCoord = riveRenderer!.globalToArtboard(globalCoordinates);
|
return riveRenderer!.globalToArtboard(globalCoordinates);
|
||||||
|
|
||||||
return artboardCoord -
|
|
||||||
Vec2D.fromValues(_artboard!.originX * _artboard!.width,
|
|
||||||
_artboard!.originY * _artboard!.height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _optionalHitTester(BuildContext context, Widget child) {
|
Widget _optionalHitTester(BuildContext context, Widget child) {
|
||||||
assert(_artboard != null);
|
assert(_artboard != null);
|
||||||
var hasHitTesting = _artboard!.animationControllers.any((controller) =>
|
var hasHitTesting = _artboard!.animationControllers.any(
|
||||||
|
(controller) =>
|
||||||
controller is StateMachineController &&
|
controller is StateMachineController &&
|
||||||
controller.hitShapes.isNotEmpty);
|
(controller.hitShapes.isNotEmpty ||
|
||||||
|
controller.hitNestedArtboards.isNotEmpty),
|
||||||
|
);
|
||||||
|
|
||||||
if (hasHitTesting) {
|
if (hasHitTesting) {
|
||||||
void hitHelper(PointerEvent event,
|
void hitHelper(PointerEvent event,
|
||||||
|
Reference in New Issue
Block a user