Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
139 lines
3.8 KiB
Dart
139 lines
3.8 KiB
Dart
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:cutdex_core/timeline/layout.dart';
|
|
import 'package:cutdex_timeline_ui/cutdex_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;
|
|
}
|
|
}
|