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