perf(editor): integrate native preview and prioritize timeline interaction
Gitea CI / Check code and tests (pull_request) Failing after 7m0s
Gitea CI / Gitea CI passed (pull_request) Failing after 5s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Check code and tests (pull_request) Failing after 7m0s
Gitea CI / Gitea CI passed (pull_request) Failing after 5s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
This commit is contained in:
1 parent
0ecf920669
commit
4f746be301
34 files changed
+3278
-145
No files matched your search
@@ -0,0 +1,138 @@
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_sdk/timeline/layout.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
/// Real playhead gesture input, quantized to physical pixels like desktop input.
|
||||
class BenchPlayheadDrag {
|
||||
BenchPlayheadDrag({
|
||||
required this.view,
|
||||
required this.ruler,
|
||||
required this.viewport,
|
||||
required this.scale,
|
||||
required this.clock,
|
||||
required this.pointer,
|
||||
required this.warmFrame,
|
||||
required this.fps,
|
||||
}) : camera = view.camera;
|
||||
final TimelineViewController view;
|
||||
final RenderBox ruler;
|
||||
final TimelineViewportRect viewport;
|
||||
final TimelineCamera camera;
|
||||
final double scale;
|
||||
final Stopwatch clock;
|
||||
final int pointer, warmFrame, fps;
|
||||
Offset _position = Offset.zero, _origin = Offset.zero;
|
||||
bool _active = false;
|
||||
|
||||
int tick(int frame) =>
|
||||
TimelineClock.standard.toTicks(RationalTime(frame, fps));
|
||||
double get _pixelsPerFrame => camera.pixelsPerTick * tick(1);
|
||||
int _delta(int frame) =>
|
||||
((frame - warmFrame) * _pixelsPerFrame * scale).round();
|
||||
int target(int frame) =>
|
||||
(warmFrame + _delta(frame) / (_pixelsPerFrame * scale)).round();
|
||||
|
||||
Future<void> begin() async {
|
||||
final point = ruler.localToGlobal(
|
||||
Offset(
|
||||
camera.screenXForTick(tick(warmFrame), viewport),
|
||||
ruler.size.height / 2,
|
||||
),
|
||||
);
|
||||
_position = Offset(
|
||||
(point.dx * scale).round() / scale,
|
||||
(point.dy * scale).round() / scale,
|
||||
);
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerAddedEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
),
|
||||
);
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerDownEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
buttons: kPrimaryButton,
|
||||
position: _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_active = true;
|
||||
_move(_position + const Offset(40, 0));
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
if (!view.isScrubbing || view.playheadTick != tick(warmFrame)) {
|
||||
throw StateError('Playhead drag warmup failed');
|
||||
}
|
||||
_origin = _position;
|
||||
}
|
||||
|
||||
void moveTo(int frame) {
|
||||
_move(_origin + Offset(_delta(frame) / scale, 0));
|
||||
if (!view.isScrubbing || view.playheadTick != tick(target(frame))) {
|
||||
throw StateError('Real playhead mismatch at input frame $frame');
|
||||
}
|
||||
}
|
||||
|
||||
void _move(Offset next) {
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerMoveEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
buttons: kPrimaryButton,
|
||||
position: next,
|
||||
delta: next - _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_position = next;
|
||||
}
|
||||
|
||||
void end() {
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerUpEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_remove();
|
||||
if (view.isScrubbing || !identical(camera, view.camera)) {
|
||||
throw StateError('Release/camera failure');
|
||||
}
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
if (!_active) return;
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerCancelEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
timeStamp: clock.elapsed,
|
||||
),
|
||||
);
|
||||
_remove();
|
||||
}
|
||||
|
||||
void _remove() {
|
||||
GestureBinding.instance.handlePointerEvent(
|
||||
PointerRemovedEvent(
|
||||
pointer: pointer,
|
||||
device: 42,
|
||||
kind: PointerDeviceKind.mouse,
|
||||
position: _position,
|
||||
),
|
||||
);
|
||||
_active = false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user