feat(inspector): edit animated effects, strokes and corner distortion
Replace the shadow-only inspector with layered effect and stroke controls and per-corner distortion editors. Share color inputs, layer rows, keyframe controls and property edit boundaries; keep nested selection menus within their property popover and update localized labels. Add property editing, preview interaction and benchmark comparison coverage. Validation: Dart analysis reports no issues and 160 targeted application tests pass. The macOS development app was rebuilt and visually checked during native rendering validation. Exclude local dependency override changes from the committed lockfile.
This commit is contained in:
1 parent
8d1f8db7e8
commit
789af7a68e
58 files changed
+6911
-1972
No files matched your search
@@ -210,7 +210,8 @@ void main() {
|
||||
expect(tester.getRect(input('x')).left, 16);
|
||||
expect(tester.getRect(input('x')).width, (width - 64) / 2);
|
||||
expect(tester.getRect(input('rotation')).width, (width - 64) / 2);
|
||||
expect(find.byType(AppPropertyGroup), findsNWidgets(4));
|
||||
expect(find.byType(AppPropertyGroup), findsNWidgets(6));
|
||||
expect(find.byKey(const ValueKey('stroke-add')), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(input('corner-radius')).width,
|
||||
(width - 64) / 2,
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/features/properties/distortion_properties.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'four corner fields use paired keys; reset preserves animation; no px',
|
||||
(tester) async {
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
clipDuration: RationalTime.seconds(5),
|
||||
),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final sequence = SequenceId('one'),
|
||||
clip = ElementId('clip'),
|
||||
project = f.workspace.project!.info.id;
|
||||
final view = f.timeline.view(sequence);
|
||||
ElementRecord record() {
|
||||
final q = view.version.kernelVersion.query();
|
||||
return q.element(q.elementById(clip)!);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
project,
|
||||
'project',
|
||||
).overrideWith((ref) => null),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
child: SingleChildScrollView(
|
||||
child: DistortionProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
Future<void> settle() async {
|
||||
await tester.pump();
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
await settle();
|
||||
expect(find.text('变形'), findsOneWidget);
|
||||
expect(find.text('px'), findsNothing);
|
||||
expect(find.text('X'), findsNWidgets(4));
|
||||
expect(find.text('Y'), findsNWidgets(4));
|
||||
expect(find.byType(TextField), findsNWidgets(8));
|
||||
final key = find.byKey(const ValueKey('distortion-topLeft-key'));
|
||||
await tester.tap(key);
|
||||
await settle();
|
||||
for (final id in ClipDistortion.ids.take(2)) {
|
||||
expect(record().parameters![id]!.length, 1);
|
||||
}
|
||||
view.seekTo(TimelineClock.ticksPerSecond);
|
||||
await settle();
|
||||
final input = find.descendant(
|
||||
of: find.byKey(const ValueKey('distortion-topLeft-y')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
await tester.enterText(input, '20');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await settle();
|
||||
for (final id in ClipDistortion.ids.take(2)) {
|
||||
expect(record().parameters![id]!.length, 2);
|
||||
}
|
||||
final y = record().parameters![ClipDistortion.ids[1]]!;
|
||||
expect(y.valueAt(TimelineClock.ticksPerSecond), greaterThan(0));
|
||||
for (final id in ClipDistortion.ids.skip(2)) {
|
||||
expect(record().parameters?[id]?.length ?? 0, 0);
|
||||
}
|
||||
await tester.tap(find.byKey(const ValueKey('distortion-reset')));
|
||||
await settle();
|
||||
expect(record().parameters![ClipDistortion.ids[1]]!.length, 2);
|
||||
expect(
|
||||
record().parameters![ClipDistortion.ids[1]]!.valueAt(
|
||||
TimelineClock.ticksPerSecond,
|
||||
),
|
||||
0,
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/features/properties/picture_edits.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/preview.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
for (final invalidation in [
|
||||
'dispose',
|
||||
'seek',
|
||||
'version',
|
||||
'sequence',
|
||||
'selection',
|
||||
]) {
|
||||
test(
|
||||
'picture edit cannot publish after $invalidation during pause',
|
||||
() async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final preview = _PausedPreview(
|
||||
timeline: f.timeline,
|
||||
runtime: CutdexRuntime(),
|
||||
activeSequence: () => f.timeline.activeSequenceId,
|
||||
viewForSequence: f.timeline.view,
|
||||
);
|
||||
final container = ProviderContainer();
|
||||
var disposed = false;
|
||||
addTearDown(() async {
|
||||
if (!disposed) container.dispose();
|
||||
await preview.close();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
});
|
||||
final sequence = SequenceId('one'), clip = ElementId('clip');
|
||||
final provider = pictureEditsProvider(f.timeline, sequence, clip);
|
||||
container.listen(provider, (_, _) {});
|
||||
final edits = container.read(provider.notifier);
|
||||
var current = true;
|
||||
var applied = 0;
|
||||
final pending = edits.commit(preview, (value) {
|
||||
applied++;
|
||||
return value.copyWith(x: .25);
|
||||
}, isCurrent: () => current);
|
||||
expect(container.read(provider).isLoading, isTrue);
|
||||
switch (invalidation) {
|
||||
case 'dispose':
|
||||
container.dispose();
|
||||
disposed = true;
|
||||
case 'seek':
|
||||
f.timeline.view(sequence).seekTo(1);
|
||||
case 'version':
|
||||
f.timeline.commands.addEffect(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
effectId: 'external',
|
||||
type: ClipEffectType.dropShadow,
|
||||
);
|
||||
case 'sequence':
|
||||
f.timeline.selectSequence(SequenceId('empty'));
|
||||
case 'selection':
|
||||
current = false;
|
||||
}
|
||||
preview.paused.complete();
|
||||
expect(await pending, isFalse);
|
||||
expect(applied, 0);
|
||||
if (!disposed) expect(container.read(provider).hasError, isFalse);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
test(
|
||||
'picture keys wait for the input commit and record its new value',
|
||||
() async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final preview = _PausedPreview(
|
||||
timeline: f.timeline,
|
||||
runtime: CutdexRuntime(),
|
||||
activeSequence: () => f.timeline.activeSequenceId,
|
||||
viewForSequence: f.timeline.view,
|
||||
);
|
||||
final container = ProviderContainer();
|
||||
addTearDown(() async {
|
||||
container.dispose();
|
||||
await preview.close();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
});
|
||||
final provider = pictureEditsProvider(
|
||||
f.timeline,
|
||||
SequenceId('one'),
|
||||
ElementId('clip'),
|
||||
);
|
||||
container.listen(provider, (_, _) {});
|
||||
final edits = container.read(provider.notifier);
|
||||
final commit = edits.commit(
|
||||
preview,
|
||||
(v) => v.copyWith(x: .25),
|
||||
isCurrent: () => true,
|
||||
);
|
||||
expect(
|
||||
await edits.commit(
|
||||
preview,
|
||||
(v) => v.copyWith(x: .75),
|
||||
isCurrent: () => true,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
final keys = edits.editKeys(
|
||||
preview,
|
||||
TransformChannel.position,
|
||||
isCurrent: () => true,
|
||||
);
|
||||
preview.paused.complete();
|
||||
expect(await commit, isTrue);
|
||||
await keys;
|
||||
expect(edits.animation()!.value.x, .25);
|
||||
expect(edits.animation()!.keyed(TransformChannel.position), isTrue);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _PausedPreview extends PreviewController {
|
||||
_PausedPreview({
|
||||
required super.timeline,
|
||||
required super.runtime,
|
||||
required super.activeSequence,
|
||||
required super.viewForSequence,
|
||||
});
|
||||
final paused = Completer<void>();
|
||||
@override
|
||||
Future<void> pauseForCanvasInteraction() => paused.future;
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/features/properties/effect_properties.dart';
|
||||
import 'package:cutdex/features/properties/effect_labels.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'blur input and keyframe control edit only the selected property',
|
||||
(tester) async {
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
clipDuration: RationalTime.seconds(5),
|
||||
),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final sequence = SequenceId('one'), clip = ElementId('clip');
|
||||
final view = f.timeline.view(sequence);
|
||||
final commands = f.timeline.commands;
|
||||
ClipEffectStack current() {
|
||||
final query = view.version.kernelVersion.query();
|
||||
final handle = query.elementById(clip)!;
|
||||
return ClipEffectStack(
|
||||
query.element(handle),
|
||||
view.playheadTick - query.absoluteStart(handle),
|
||||
);
|
||||
}
|
||||
|
||||
for (final id in ['a', 'b']) {
|
||||
commands.addEffect(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
effectId: id,
|
||||
type: ClipEffectType.dropShadow,
|
||||
);
|
||||
}
|
||||
final project = f.workspace.project!.info.id;
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
project,
|
||||
'project',
|
||||
).overrideWith((ref) => null),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
child: SingleChildScrollView(
|
||||
child: EffectProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
Future<void> settle() async {
|
||||
await tester.pump();
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
await settle();
|
||||
await tester.tap(find.byKey(const ValueKey('effect-settings-a')));
|
||||
await settle();
|
||||
await tester.tap(find.byKey(const ValueKey('effect-a-blur-key')));
|
||||
await settle();
|
||||
final blurId = const EffectParameterTarget('a', 'blur').parameterId;
|
||||
expect(current().record.parameters?[blurId]?.length, 1);
|
||||
for (final id in current().parameterIds.where((id) => id != blurId)) {
|
||||
expect(current().record.parameters?[id]?.length, 0);
|
||||
}
|
||||
view.seekTo(TimelineClock.ticksPerSecond);
|
||||
await settle();
|
||||
final input = find.descendant(
|
||||
of: find.byKey(const ValueKey('effect-a-blur')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
await tester.enterText(input, '20');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await settle();
|
||||
expect(current().record.parameters?[blurId]?.length, 2);
|
||||
expect(current().layers.first.values['blur'], 20);
|
||||
for (final id in current().parameterIds.where((id) => id != blurId)) {
|
||||
expect(current().record.parameters?[id]?.length, 0);
|
||||
}
|
||||
view.seekTo(TimelineClock.ticksPerSecond ~/ 2);
|
||||
expect(current().layers.last.values['blur'], 8);
|
||||
expect(current().layers.first.values['blur'], closeTo(14, .001));
|
||||
await settle();
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
for (final type in ClipEffectType.values) {
|
||||
testWidgets('${type.name} exposes valid controls at 240 width', (
|
||||
tester,
|
||||
) async {
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/test/video.mov')),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final sequence = SequenceId('one'), clip = ElementId('clip');
|
||||
f.timeline.commands.addEffect(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
effectId: 'test',
|
||||
type: type,
|
||||
);
|
||||
final project = f.workspace.project!.info.id;
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
project,
|
||||
'project',
|
||||
).overrideWith((ref) => null),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
child: SingleChildScrollView(
|
||||
child: EffectProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('effect-settings-test')));
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('effect-editor-test')), findsOneWidget);
|
||||
expect(
|
||||
find.text(type.label(tester.element(find.byType(EffectProperties)))),
|
||||
findsWidgets,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,485 +0,0 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/features/properties/shadow_properties.dart';
|
||||
import 'package:cutdex/features/properties/picture_properties.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'one shadow key captures all layers and structural edits preserve curves',
|
||||
(tester) async {
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
clipDuration: RationalTime.seconds(5),
|
||||
),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final seq = SequenceId('one');
|
||||
final clip = ElementId('clip');
|
||||
final view = f.timeline.view(seq);
|
||||
final project = f.workspace.project!.info.id;
|
||||
ClipShadowStack current() {
|
||||
final q = view.version.kernelVersion.query();
|
||||
final h = q.elementById(clip)!;
|
||||
return ClipShadowStack(
|
||||
q.element(h),
|
||||
view.playheadTick - q.absoluteStart(h),
|
||||
);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
project,
|
||||
'project',
|
||||
).overrideWith((ref) => null),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
child: SingleChildScrollView(
|
||||
child: ShadowProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
sequence: seq,
|
||||
clip: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
Future<void> settle() async {
|
||||
await tester.pump();
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
Future<void> closeEditor() async {
|
||||
final close = find.byWidgetPredicate(
|
||||
(w) =>
|
||||
w is IconButton &&
|
||||
w.key is ValueKey<String> &&
|
||||
(w.key! as ValueKey<String>).value.startsWith(
|
||||
'shadow-editor-close-',
|
||||
),
|
||||
);
|
||||
if (close.evaluate().isNotEmpty) {
|
||||
await tester.tap(close);
|
||||
await settle();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> tap(Key key) async {
|
||||
await closeEditor();
|
||||
final w = find.byKey(key);
|
||||
await tester.ensureVisible(w);
|
||||
await tester.tap(w);
|
||||
await settle();
|
||||
}
|
||||
|
||||
Future<void> enter(String id, String field, String value) async {
|
||||
if (find.byKey(ValueKey('shadow-editor-$id')).evaluate().isEmpty) {
|
||||
await closeEditor();
|
||||
await tester.tap(find.byKey(ValueKey('shadow-settings-$id')));
|
||||
await settle();
|
||||
}
|
||||
final input = find.descendant(
|
||||
of: find.byKey(ValueKey('shadow-$id-$field')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
await tester.ensureVisible(input);
|
||||
await tester.enterText(input, value);
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await settle();
|
||||
}
|
||||
|
||||
await settle();
|
||||
expect(current().layers, isEmpty);
|
||||
expect(tester.getSize(find.byType(AppPropertySection)).height, 40);
|
||||
await tap(const ValueKey('shadow-add'));
|
||||
final a = current().layers.single.id;
|
||||
await tap(const ValueKey('shadow-add'));
|
||||
final b = current().layers.last.id;
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('shadow-layer-$a'))).height,
|
||||
32,
|
||||
);
|
||||
await enter(a, 'x', '12');
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('shadow-editor-$a'))).width,
|
||||
240,
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byKey(ValueKey('shadow-editor-$a'))).right,
|
||||
lessThan(tester.getRect(find.byKey(ValueKey('shadow-layer-$a'))).left),
|
||||
);
|
||||
final xField = find.descendant(
|
||||
of: find.byKey(ValueKey('shadow-$a-x')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
expect(tester.getSize(xField), const Size(100, 24));
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('shadow-editor-$a'))).height,
|
||||
225,
|
||||
);
|
||||
final yField = find.descendant(
|
||||
of: find.byKey(ValueKey('shadow-$a-y')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
expect(tester.getRect(yField).left - tester.getRect(xField).right, 8);
|
||||
final blurInput = find.descendant(
|
||||
of: find.byKey(ValueKey('shadow-$a-blur')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
final blurLabel = find.descendant(
|
||||
of: find.byKey(ValueKey('shadow-$a-blur')),
|
||||
matching: find.text('模糊'),
|
||||
);
|
||||
final colorLabel = find.descendant(
|
||||
of: find.byKey(ValueKey('shadow-editor-$a')),
|
||||
matching: find.text('颜色'),
|
||||
);
|
||||
expect(tester.getSize(blurLabel).height, 16);
|
||||
expect(
|
||||
tester.getRect(blurInput).top - tester.getRect(blurLabel).bottom,
|
||||
4,
|
||||
);
|
||||
expect(tester.getRect(blurLabel).top - tester.getRect(xField).bottom, 12);
|
||||
expect(
|
||||
tester.getRect(colorLabel).top - tester.getRect(blurInput).bottom,
|
||||
12,
|
||||
);
|
||||
expect(tester.widget<Text>(blurLabel).style!.fontSize, 11);
|
||||
expect(
|
||||
tester.widget<Text>(blurLabel).style!.color,
|
||||
Colors.white.withValues(alpha: .7),
|
||||
);
|
||||
expect(tester.widget<TextField>(xField).style!.fontSize, 11);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await settle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await settle();
|
||||
expect(find.byKey(ValueKey('shadow-editor-$a')), findsNothing);
|
||||
await enter(b, 'blur', '20');
|
||||
expect(current().animated, isFalse);
|
||||
expect(current().layers[0].shadow.x, 12);
|
||||
expect(current().layers[1].shadow.blur, 20);
|
||||
await enter(a, 'color', 'FF8800');
|
||||
expect(current().layers.first.shadow.red, 1);
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('shadow-$a-color'))).width,
|
||||
closeTo(
|
||||
2 * tester.getSize(find.byKey(ValueKey('shadow-$a-opacity'))).width,
|
||||
.01,
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('shadow-color-swatch')));
|
||||
await settle();
|
||||
final plane = tester.getRect(
|
||||
find.byKey(const ValueKey('shadow-color-plane')),
|
||||
);
|
||||
await tester.tapAt(plane.topCenter + const Offset(0, 2));
|
||||
await settle();
|
||||
expect(current().layers.first.shadow.blue, greaterThan(.45));
|
||||
expect(find.byKey(const ValueKey('shadow-color-plane')), findsOneWidget);
|
||||
view.undo();
|
||||
await settle();
|
||||
expect(current().layers.first.shadow.green, closeTo(136 / 255, .001));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await settle();
|
||||
expect(find.byKey(const ValueKey('shadow-color-plane')), findsNothing);
|
||||
await enter(a, 'blur', '-1');
|
||||
expect(current().layers.first.shadow.blur, 8);
|
||||
await tap(const ValueKey('shadow-key'));
|
||||
expect(current().keyed, isTrue);
|
||||
expect(current().parameterIds.length, 16);
|
||||
expect(
|
||||
current().parameterIds.every(
|
||||
(id) => current().record.parameters?[id]?.length == 1,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
view.seekTo(2 * TimelineClock.ticksPerSecond);
|
||||
await settle();
|
||||
await enter(a, 'x', '32');
|
||||
await enter(b, 'blur', '40');
|
||||
expect(
|
||||
current().parameterIds.every(
|
||||
(id) => current().record.parameters?[id]?.length == 2,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
view.seekTo(TimelineClock.ticksPerSecond);
|
||||
await settle();
|
||||
expect(current().layers[0].shadow.x, 22);
|
||||
expect(current().layers[1].shadow.blur, 30);
|
||||
final blurField = find.descendant(
|
||||
of: find.byKey(ValueKey('shadow-$b-blur')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
expect(tester.widget<TextField>(blurField).controller!.text, '30');
|
||||
view.seekTo(0);
|
||||
f.timeline.commands.editKeyframeChannel(
|
||||
sequence: seq,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
parameterIds: current().parameterIds,
|
||||
action: KeyframeAction.set,
|
||||
interpolation: ParameterInterpolation.hold,
|
||||
);
|
||||
view.seekTo(TimelineClock.ticksPerSecond);
|
||||
await settle();
|
||||
expect(current().layers.first.shadow.x, 12);
|
||||
expect(current().layers.last.shadow.blur, 20);
|
||||
view.undo();
|
||||
await settle();
|
||||
expect(current().layers.first.shadow.x, 22);
|
||||
f.timeline.commands.editKeyframeChannel(
|
||||
sequence: seq,
|
||||
clip: clip,
|
||||
tick: view.playheadTick,
|
||||
parameterIds: current().parameterIds,
|
||||
action: KeyframeAction.clear,
|
||||
);
|
||||
await settle();
|
||||
expect(current().animated, isFalse);
|
||||
expect(current().layers.first.shadow.x, 22);
|
||||
view.undo();
|
||||
await settle();
|
||||
expect(current().animated, isTrue);
|
||||
final before = current()
|
||||
.record
|
||||
.parameters?[ShadowParameterTarget(a, 'x').parameterId];
|
||||
await closeEditor();
|
||||
final dragWidget = find.byKey(ValueKey('shadow-drag-$a'));
|
||||
expect(
|
||||
tester.widget<ReorderableDragStartListener>(dragWidget).enabled,
|
||||
isTrue,
|
||||
);
|
||||
final drag = tester.getCenter(dragWidget);
|
||||
final gesture = await tester.startGesture(drag);
|
||||
await tester.pump();
|
||||
await gesture.moveBy(const Offset(0, 12));
|
||||
await tester.pump();
|
||||
await gesture.moveBy(const Offset(0, 80));
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
await gesture.up();
|
||||
await settle();
|
||||
expect(current().layers.map((l) => l.id), [b, a]);
|
||||
expect(
|
||||
current().record.parameters?[ShadowParameterTarget(a, 'x').parameterId],
|
||||
same(before),
|
||||
);
|
||||
await tap(ValueKey('shadow-enabled-$b'));
|
||||
expect(current().layers.first.enabled, isFalse);
|
||||
await tap(ValueKey('shadow-remove-$a'));
|
||||
expect(current().layers.length, 1);
|
||||
expect(
|
||||
current().record.parameters?[ShadowParameterTarget(a, 'x').parameterId],
|
||||
isNull,
|
||||
);
|
||||
view.undo();
|
||||
await settle();
|
||||
expect(current().layers.length, 2);
|
||||
expect(current().layers.last.shadow.x, 22);
|
||||
await tap(const ValueKey('shadow-add'));
|
||||
final c = current().layers.last.id;
|
||||
expect(
|
||||
current()
|
||||
.record
|
||||
.parameters?[ShadowParameterTarget(c, 'x').parameterId]
|
||||
?.length,
|
||||
2,
|
||||
);
|
||||
await tap(const ValueKey('shadow-add'));
|
||||
expect(current().layers.length, 4);
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(find.byKey(const ValueKey('shadow-add')))
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
() => f.timeline.commands.addShadow(
|
||||
sequence: seq,
|
||||
clip: clip,
|
||||
tick: view.playheadTick,
|
||||
shadowId: 'fifth',
|
||||
),
|
||||
throwsA(isA<CommandRejected>()),
|
||||
);
|
||||
await tester.tap(find.byKey(ValueKey('shadow-settings-$a')));
|
||||
await settle();
|
||||
await tester.tapAt(const Offset(50, 500));
|
||||
await settle();
|
||||
expect(find.byKey(ValueKey('shadow-editor-$a')), findsNothing);
|
||||
await tester.tap(find.byKey(ValueKey('shadow-settings-$a')));
|
||||
await settle();
|
||||
f.timeline.commands.removeShadow(
|
||||
sequence: seq,
|
||||
clip: clip,
|
||||
tick: view.playheadTick,
|
||||
shadowId: a,
|
||||
);
|
||||
await settle();
|
||||
expect(find.byKey(ValueKey('shadow-editor-$a')), findsNothing);
|
||||
view.undo();
|
||||
await settle();
|
||||
expect(current().layers.length, 4);
|
||||
final compiled = const ExecutionCompiler().compile(
|
||||
ExecutionInput(
|
||||
timeline: f.timeline.persistence.timeline(seq),
|
||||
renderSize: RenderSize(64, 64),
|
||||
media: {
|
||||
PayloadRef('source'): ExecutionMediaBinding(
|
||||
media: MediaReference(
|
||||
id: 'media',
|
||||
uri: Uri.file('/test/video.mov'),
|
||||
),
|
||||
videoTrackSelection: TrackSelection.index(0),
|
||||
),
|
||||
},
|
||||
parameterTargets: ClipTransform.targets,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
compiled.plan.visualLayers.single.automation.map((a) => a.target),
|
||||
contains(ShadowParameterTarget(a, 'x').parameterId),
|
||||
);
|
||||
expect(
|
||||
compiled.plan.visualLayers.single.automation
|
||||
.firstWhere(
|
||||
(c) => c.target == ShadowParameterTarget(a, 'x').parameterId,
|
||||
)
|
||||
.keys
|
||||
.length,
|
||||
2,
|
||||
);
|
||||
// Existing persistence serializes all curves and feeds execution bindings unchanged.
|
||||
final saved = await tester.runAsync(
|
||||
() => f.workspace.project!.loadTimeline('project'),
|
||||
);
|
||||
expect(
|
||||
saved!.sequences.first.elements.first.parameters.map(
|
||||
(p) => p.definition.id,
|
||||
),
|
||||
contains(ShadowParameterTarget(a, 'x').parameterId),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
project,
|
||||
'project',
|
||||
).overrideWith((ref) => null),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 240,
|
||||
child: SingleChildScrollView(
|
||||
child: PictureProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
sequence: seq,
|
||||
clip: current().record,
|
||||
animationView: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await settle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('picture-key-marker-shadow-0')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(
|
||||
const ValueKey(
|
||||
'picture-key-marker-shadow-${2 * TimelineClock.ticksPerSecond}',
|
||||
),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'shadow validation and retimed group keys use the existing source clock',
|
||||
() {
|
||||
expect(const ClipShadow(blur: -1).isValid, isFalse);
|
||||
expect(const ClipShadow(opacity: 2).isValid, isFalse);
|
||||
expect(const ClipShadow(x: double.nan).isValid, isFalse);
|
||||
expect(RenderShadowTarget.parse('shadow.a.color.r')?.field, 'color.r');
|
||||
expect(isRenderVisualTarget('shadow.a.blur'), isTrue);
|
||||
expect(isRenderVisualTarget('shadow.a.invalid'), isFalse);
|
||||
expect(ShadowParameterTarget.parse('shadow.中文.x'), isNull);
|
||||
for (final delta in [8, -8]) {
|
||||
final record = ElementRecord(
|
||||
id: ElementId('clip'),
|
||||
structure: ElementStructure.content,
|
||||
duration: 4 * TimelineClock.ticksPerSecond,
|
||||
sourceStart: 10 * TimelineClock.ticksPerSecond,
|
||||
sourceDuration: 8 * TimelineClock.ticksPerSecond,
|
||||
enabled: true,
|
||||
retime: RetimeMapRecord([
|
||||
RetimeSegmentRecord(
|
||||
projectDuration: 4 * TimelineClock.ticksPerSecond,
|
||||
sourceStart: 10 * TimelineClock.ticksPerSecond,
|
||||
sourceDelta: delta * TimelineClock.ticksPerSecond,
|
||||
),
|
||||
]),
|
||||
);
|
||||
expect(
|
||||
ClipShadowStack(record, TimelineClock.ticksPerSecond).sourceTick,
|
||||
(10 + delta ~/ 4) * TimelineClock.ticksPerSecond,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/features/properties/stroke_properties.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'stroke weight input and keyframe control edit only the selected property',
|
||||
(tester) async {
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
clipDuration: RationalTime.seconds(5),
|
||||
),
|
||||
))!;
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
final sequence = SequenceId('one'), clip = ElementId('clip');
|
||||
final view = f.timeline.view(sequence);
|
||||
final commands = f.timeline.commands;
|
||||
ClipStrokeStack current() {
|
||||
final query = view.version.kernelVersion.query();
|
||||
final handle = query.elementById(clip)!;
|
||||
return ClipStrokeStack(
|
||||
query.element(handle),
|
||||
view.playheadTick - query.absoluteStart(handle),
|
||||
);
|
||||
}
|
||||
|
||||
for (final id in ['a', 'b']) {
|
||||
commands.addStroke(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
strokeId: id,
|
||||
);
|
||||
}
|
||||
final project = f.workspace.project!.info.id;
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
project,
|
||||
'project',
|
||||
).overrideWith((ref) => null),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
EditorTheme.desktop(EditorTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
child: SingleChildScrollView(
|
||||
child: StrokeProperties(
|
||||
projectId: project,
|
||||
timelineId: 'project',
|
||||
session: f.timeline,
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
Future<void> settle() async {
|
||||
await tester.pump();
|
||||
await tester.runAsync(f.timeline.flush);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
await settle();
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-settings-a')));
|
||||
await settle();
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-a-width-key')));
|
||||
await settle();
|
||||
final blurId = const StrokeParameterTarget('a', 'width').parameterId;
|
||||
expect(current().record.parameters?[blurId]?.length, 1);
|
||||
for (final id in current().parameterIds.where((id) => id != blurId)) {
|
||||
expect(current().record.parameters?[id]?.length, 0);
|
||||
}
|
||||
view.seekTo(TimelineClock.ticksPerSecond);
|
||||
await settle();
|
||||
final input = find.descendant(
|
||||
of: find.byKey(const ValueKey('stroke-a-width')),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
await tester.enterText(input, '20');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await settle();
|
||||
expect(current().record.parameters?[blurId]?.length, 2);
|
||||
expect(current().layers.first.values['width'], 20);
|
||||
for (final id in current().parameterIds.where((id) => id != blurId)) {
|
||||
expect(current().record.parameters?[id]?.length, 0);
|
||||
}
|
||||
view.seekTo(TimelineClock.ticksPerSecond ~/ 2);
|
||||
expect(current().layers.last.values['width'], 1);
|
||||
expect(current().layers.first.values['width'], closeTo(10.5, .001));
|
||||
await settle();
|
||||
// Structural selectors and dash fields update statically without keyframe controls.
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-a-alignment')));
|
||||
await settle();
|
||||
await tester.tap(find.text('外侧').last);
|
||||
await settle();
|
||||
expect(current().layers.first.alignment, ClipStrokeAlignment.outside);
|
||||
expect(
|
||||
find.byKey(const ValueKey('stroke-a-alignment-key')),
|
||||
findsNothing,
|
||||
);
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-a-style')));
|
||||
await settle();
|
||||
await tester.tap(find.text('虚线').last);
|
||||
await settle();
|
||||
expect(find.byKey(const ValueKey('stroke-a-dashLength')), findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const ValueKey('stroke-a-dashLength-key')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.textContaining('px'), findsNothing);
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-editor-close-a')));
|
||||
await settle();
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-enabled-a')));
|
||||
await settle();
|
||||
expect(current().layers.first.enabled, isFalse);
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-add')));
|
||||
await settle();
|
||||
expect(current().layers.length, 3);
|
||||
await tester.tap(find.byKey(const ValueKey('stroke-remove-a')));
|
||||
await settle();
|
||||
expect(current().layers.map((l) => l.id), isNot(contains('a')));
|
||||
expect(current().record.parameters?[blurId], isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -209,6 +209,199 @@ void main() {
|
||||
messenger.setMockMethodCallHandler(events, null);
|
||||
});
|
||||
|
||||
test(
|
||||
'canvas tools share one owner and reject cleanup from an earlier tool',
|
||||
() async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final preview = PreviewController(
|
||||
timeline: f.timeline,
|
||||
activeSequence: () => f.timeline.activeSequenceId,
|
||||
viewForSequence: f.timeline.view,
|
||||
runtime: CutdexRuntime(),
|
||||
);
|
||||
addTearDown(() async {
|
||||
await preview.close();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
});
|
||||
await preview.initialize();
|
||||
final clip = ElementId('clip');
|
||||
final owner = Object();
|
||||
void enter(PreviewCanvasEditMode mode, Object owner) {
|
||||
switch (mode) {
|
||||
case PreviewCanvasEditMode.mask:
|
||||
preview.setMaskEditing(clip, owner: owner);
|
||||
case PreviewCanvasEditMode.obscure:
|
||||
preview.setObscureEditing(clip, owner: owner);
|
||||
case PreviewCanvasEditMode.distortion:
|
||||
preview.setDistortionEditing(clip, owner: owner, perspective: true);
|
||||
}
|
||||
}
|
||||
|
||||
void release(PreviewCanvasEditMode mode, Object owner) {
|
||||
switch (mode) {
|
||||
case PreviewCanvasEditMode.mask:
|
||||
preview.releaseMaskEditing(owner);
|
||||
case PreviewCanvasEditMode.obscure:
|
||||
preview.releaseObscureEditing(owner);
|
||||
case PreviewCanvasEditMode.distortion:
|
||||
preview.releaseDistortionEditing(owner);
|
||||
}
|
||||
}
|
||||
|
||||
for (final previous in PreviewCanvasEditMode.values) {
|
||||
for (final next in PreviewCanvasEditMode.values) {
|
||||
enter(previous, owner);
|
||||
final replacement = Object();
|
||||
enter(next, replacement);
|
||||
release(previous, owner);
|
||||
expect(preview.canvasEditing!.mode, next);
|
||||
expect(preview.canvasEditing!.owner, same(replacement));
|
||||
expect(
|
||||
preview.maskEditingElement,
|
||||
next == PreviewCanvasEditMode.mask ? clip : null,
|
||||
);
|
||||
expect(
|
||||
preview.obscureEditingElement,
|
||||
next == PreviewCanvasEditMode.obscure ? clip : null,
|
||||
);
|
||||
expect(
|
||||
preview.distortionEditingElement,
|
||||
next == PreviewCanvasEditMode.distortion ? clip : null,
|
||||
);
|
||||
release(next, replacement);
|
||||
expect(preview.canvasEditing, isNull);
|
||||
expect(preview.distortionPerspective, isFalse);
|
||||
}
|
||||
}
|
||||
// Even when one widget owns both tools, delayed cleanup is specific to its old mode.
|
||||
enter(PreviewCanvasEditMode.mask, owner);
|
||||
enter(PreviewCanvasEditMode.distortion, owner);
|
||||
preview.releaseMaskEditing(owner);
|
||||
preview.setMaskEditing(null);
|
||||
expect(preview.canvasEditing!.mode, PreviewCanvasEditMode.distortion);
|
||||
var notifications = 0;
|
||||
preview.addListener(() => notifications++);
|
||||
enter(PreviewCanvasEditMode.distortion, owner);
|
||||
expect(
|
||||
notifications,
|
||||
0,
|
||||
reason: 'Re-entering the same mode must not cancel its gesture',
|
||||
);
|
||||
preview.selectVisual(null);
|
||||
expect(preview.canvasEditing, isNull);
|
||||
enter(PreviewCanvasEditMode.obscure, owner);
|
||||
f.timeline.selectSequence(SequenceId('empty'));
|
||||
expect(preview.canvasEditing, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'switching canvas tools invalidates a gesture that is still preparing',
|
||||
() async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final preview = PreviewController(
|
||||
timeline: f.timeline,
|
||||
activeSequence: () => f.timeline.activeSequenceId,
|
||||
viewForSequence: f.timeline.view,
|
||||
runtime: CutdexRuntime(),
|
||||
);
|
||||
addTearDown(() async {
|
||||
await preview.close();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
});
|
||||
await preview.initialize();
|
||||
final clip = ElementId('clip');
|
||||
preview.setMaskEditing(clip);
|
||||
preview.addMask(ClipMaskShape.rectangle);
|
||||
await until(() => !preview.busy);
|
||||
preview.cancelTransform();
|
||||
blockedTransform = Completer<void>();
|
||||
final before = f.timeline.view(SequenceId('one')).version.kernelVersion;
|
||||
final pending = preview.beginMaskEdit();
|
||||
preview.updateMask(preview.maskFor(clip)!.copyWith(x: .75));
|
||||
preview.setDistortionEditing(clip);
|
||||
blockedTransform!.complete();
|
||||
expect(await pending, isFalse);
|
||||
preview.endMaskEdit();
|
||||
expect(
|
||||
f.timeline.view(SequenceId('one')).version.kernelVersion,
|
||||
same(before),
|
||||
);
|
||||
expect(preview.maskFor(clip)!.x, .5);
|
||||
expect(preview.canvasEditing!.mode, PreviewCanvasEditMode.distortion);
|
||||
},
|
||||
);
|
||||
|
||||
test('distortion snapshots replace all eight coordinates and share one undo entry', () async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final preview = PreviewController(
|
||||
timeline: f.timeline,
|
||||
activeSequence: () => f.timeline.activeSequenceId,
|
||||
viewForSequence: f.timeline.view,
|
||||
runtime: CutdexRuntime(),
|
||||
);
|
||||
addTearDown(() async {
|
||||
await preview.close();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
});
|
||||
await preview.initialize();
|
||||
final clip = ElementId('clip'), sequence = SequenceId('one');
|
||||
final owner = Object();
|
||||
preview.setDistortionEditing(clip, owner: owner);
|
||||
preview.releaseDistortionEditing(Object());
|
||||
expect(preview.distortionEditingElement, clip);
|
||||
final edit = preview.transforms.begin(preview.visuals.single)!;
|
||||
await edit.prepared;
|
||||
const pose = ClipDistortion(topLeft: (.1, .2));
|
||||
edit.update(edit.initial.transform.copyWith(distortion: pose));
|
||||
await until(
|
||||
() => calls
|
||||
.where((c) => c.method == 'updateInteractiveTransform')
|
||||
.any(
|
||||
(c) =>
|
||||
((c.arguments as Map)['transforms'] as List)
|
||||
.single['distortion'][0] ==
|
||||
.1,
|
||||
),
|
||||
);
|
||||
final payload =
|
||||
((calls
|
||||
.lastWhere(
|
||||
(c) => c.method == 'updateInteractiveTransform',
|
||||
)
|
||||
.arguments
|
||||
as Map)['transforms']
|
||||
as List)
|
||||
.single
|
||||
as Map;
|
||||
expect(payload['distortion'], pose.values);
|
||||
expect(preview.visuals.single.transform.distortion.same(pose), isTrue);
|
||||
await edit.end();
|
||||
final view = f.timeline.view(sequence);
|
||||
final q = view.version.kernelVersion.query();
|
||||
expect(
|
||||
ClipTransform.fromRecord(q.element(q.elementById(clip)!)).distortion
|
||||
.same(pose),
|
||||
isTrue,
|
||||
);
|
||||
view.undo();
|
||||
await until(() => !preview.busy);
|
||||
expect(
|
||||
preview.visuals.single.transform.distortion.values,
|
||||
List.filled(8, 0),
|
||||
);
|
||||
preview.setMaskEditing(clip, owner: Object());
|
||||
expect(preview.distortionEditingElement, isNull);
|
||||
preview.setDistortionEditing(clip, owner: owner, perspective: true);
|
||||
expect(preview.maskEditingElement, isNull);
|
||||
expect(preview.distortionPerspective, isTrue);
|
||||
preview.releaseDistortionEditing(owner);
|
||||
expect(preview.distortionEditingElement, isNull);
|
||||
});
|
||||
|
||||
testWidgets('alignment refreshes selection when the native scene settles', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -1064,7 +1257,39 @@ void main() {
|
||||
await tester.binding.setSurfaceSize(const Size(320, 760));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final f = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/test/video.mov')),
|
||||
() => createPreviewFixture(
|
||||
Uri.file('/test/video.mov'),
|
||||
timelineOverride: TimelineDto(
|
||||
id: SequenceId('one'),
|
||||
name: 'One',
|
||||
format: TimelineFormat.fps30,
|
||||
primaryStorylineId: StorylineId('primary'),
|
||||
storylines: [
|
||||
StorylineDto(
|
||||
id: StorylineId('primary'),
|
||||
elementIds: [ElementId('clip'), ElementId('other')],
|
||||
),
|
||||
],
|
||||
elements: [
|
||||
for (final id in ['clip', 'other'])
|
||||
ElementDto(
|
||||
id: ElementId(id),
|
||||
name: id,
|
||||
structure: ElementStructure.content,
|
||||
payloadRef: PayloadRef('source'),
|
||||
duration: RationalTime.seconds(2),
|
||||
sourceRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(2),
|
||||
),
|
||||
mediaRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(2),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
))!;
|
||||
final preview = PreviewController(
|
||||
timeline: f.timeline,
|
||||
|
||||
@@ -765,6 +765,48 @@ void main() {
|
||||
replacement.dispose();
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'distortion drag edits one paired corner; perspective links the edge; escape cancels',
|
||||
(tester) async {
|
||||
final preview = _Preview()..selectVisual(ElementId('upper'));
|
||||
preview.setDistortionEditing(ElementId('upper'));
|
||||
await mount(tester, preview);
|
||||
final original = preview.visuals.last.geometry;
|
||||
final corner = const Offset(40, 40) + original.corners[0] * .5;
|
||||
var gesture = await tester.startGesture(corner);
|
||||
await gesture.moveBy(const Offset(15, 10));
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(preview.value.distortion.topLeft.$1, closeTo(.1, 1e-6));
|
||||
expect(preview.value.distortion.topLeft.$2, closeTo(.1, 1e-6));
|
||||
expect(preview.value.scale, 1);
|
||||
expect(preview.value.x, 0);
|
||||
expect(preview.value.distortion.topRight, (0, 0));
|
||||
expect(preview.commits, 1);
|
||||
final before = preview.value;
|
||||
final moved =
|
||||
const Offset(40, 40) + preview.visuals.last.geometry.corners[0] * .5;
|
||||
gesture = await tester.startGesture(moved);
|
||||
await gesture.moveBy(const Offset(15, 10));
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(preview.value, same(before));
|
||||
expect(preview.commits, 1);
|
||||
preview.setDistortionEditing(ElementId('upper'), perspective: true);
|
||||
gesture = await tester.startGesture(moved);
|
||||
await gesture.moveBy(const Offset(15, 10));
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(preview.value.distortion.topLeft.$1, closeTo(.2, 1e-6));
|
||||
expect(preview.value.distortion.topRight.$1, closeTo(-.1, 1e-6));
|
||||
expect(preview.value.distortion.topRight.$2, closeTo(.1, 1e-6));
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
preview.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'selection follows video rotation and its visible corners resize',
|
||||
(tester) async {
|
||||
@@ -1105,6 +1147,21 @@ class _MaskPreview extends _Preview {
|
||||
}
|
||||
|
||||
class _Preview extends ChangeNotifier implements PreviewController {
|
||||
@override
|
||||
ElementId? distortionEditingElement;
|
||||
@override
|
||||
bool distortionPerspective = false;
|
||||
@override
|
||||
void setDistortionEditing(
|
||||
ElementId? element, {
|
||||
Object? owner,
|
||||
bool perspective = false,
|
||||
}) {
|
||||
distortionEditingElement = element;
|
||||
distortionPerspective = perspective;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
Listenable get positionChanges => this;
|
||||
|
||||
|
||||
@@ -519,6 +519,21 @@ void main() {
|
||||
}
|
||||
|
||||
class _Preview extends ChangeNotifier implements PreviewController {
|
||||
@override
|
||||
ElementId? distortionEditingElement;
|
||||
@override
|
||||
bool distortionPerspective = false;
|
||||
@override
|
||||
void setDistortionEditing(
|
||||
ElementId? element, {
|
||||
Object? owner,
|
||||
bool perspective = false,
|
||||
}) {
|
||||
distortionEditingElement = element;
|
||||
distortionPerspective = perspective;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
Listenable get positionChanges => this;
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/features/properties/property_color_input.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Widget input({
|
||||
required String value,
|
||||
required Object context,
|
||||
required Future<bool> Function(int) submit,
|
||||
}) => MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 180,
|
||||
child: PropertyColorInput(
|
||||
value: value,
|
||||
color: Color(0xFF000000 | int.parse(value, radix: 16)),
|
||||
enabled: true,
|
||||
editContext: context,
|
||||
submit: submit,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'hex input rejects invalid text and submits the selected RGB value',
|
||||
(tester) async {
|
||||
int? submitted;
|
||||
Future<bool> submit(int value) async {
|
||||
submitted = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
input(value: '3366FF', context: 'a', submit: submit),
|
||||
);
|
||||
await tester.enterText(find.byType(TextField), 'invalid');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pump();
|
||||
expect(submitted, isNull);
|
||||
await tester.enterText(find.byType(TextField), '#12aB34');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pump();
|
||||
expect(submitted, 0x12AB34);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'a pending color submission cannot overwrite a newly selected field',
|
||||
(tester) async {
|
||||
final pending = Completer<bool>();
|
||||
await tester.pumpWidget(
|
||||
input(value: '3366FF', context: 'a', submit: (_) => pending.future),
|
||||
);
|
||||
await tester.enterText(find.byType(TextField), '12AB34');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
await tester.pump();
|
||||
await tester.pumpWidget(
|
||||
input(value: 'FF0000', context: 'b', submit: (_) async => true),
|
||||
);
|
||||
pending.complete(false);
|
||||
await tester.pump();
|
||||
final text = tester.widget<TextField>(find.byType(TextField));
|
||||
expect(text.controller!.text, 'FF0000');
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'package:cutdex/features/properties/property_edit_controller.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'support/preview_fixture.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
for (final invalidation in ['dispose', 'seek', 'version', 'sequence']) {
|
||||
test('pending effect edit is cancelled after $invalidation', () async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final sequence = SequenceId('one'), clip = ElementId('clip');
|
||||
final controller = PropertyEditController(
|
||||
session: f.timeline,
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
projectId: f.workspace.project!.info.id,
|
||||
timelineId: 'project',
|
||||
operation: 'editEffect',
|
||||
);
|
||||
var disposed = false;
|
||||
addTearDown(() async {
|
||||
if (!disposed) controller.dispose();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
});
|
||||
var publications = 0;
|
||||
final pending = controller.run(null, (_, _) => publications++);
|
||||
expect(controller.saving, isTrue);
|
||||
switch (invalidation) {
|
||||
case 'dispose':
|
||||
controller.dispose();
|
||||
disposed = true;
|
||||
case 'seek':
|
||||
f.timeline.view(sequence).seekTo(1);
|
||||
case 'version':
|
||||
f.timeline.commands.addEffect(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
effectId: 'external',
|
||||
type: ClipEffectType.dropShadow,
|
||||
);
|
||||
case 'sequence':
|
||||
f.timeline.selectSequence(SequenceId('empty'));
|
||||
}
|
||||
expect(await pending, isFalse);
|
||||
expect(publications, 0);
|
||||
if (!disposed) {
|
||||
expect(controller.saving, isFalse);
|
||||
expect(controller.failed, isFalse);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test('effect edit excludes duplicate submissions and recovers after a command failure', () async {
|
||||
final f = await createPreviewFixture(Uri.file('/test/video.mov'));
|
||||
final controller = PropertyEditController(
|
||||
session: f.timeline,
|
||||
sequence: SequenceId('one'),
|
||||
clip: ElementId('clip'),
|
||||
projectId: f.workspace.project!.info.id,
|
||||
timelineId: 'project',
|
||||
operation: 'editEffect',
|
||||
);
|
||||
addTearDown(() async {
|
||||
controller.dispose();
|
||||
await f.workspace.close();
|
||||
await f.directory.delete(recursive: true);
|
||||
});
|
||||
var publications = 0;
|
||||
final first = controller.run(null, (_, _) => publications++);
|
||||
expect(await controller.run(null, (_, _) => publications++), isFalse);
|
||||
expect(await first, isTrue);
|
||||
expect(publications, 1);
|
||||
expect(
|
||||
await controller.run(null, (_, _) => throw StateError('Rejected edit')),
|
||||
isFalse,
|
||||
);
|
||||
expect(controller.failed, isTrue);
|
||||
expect(controller.saving, isFalse);
|
||||
expect(await controller.run(null, (_, _) => publications++), isTrue);
|
||||
expect(controller.failed, isFalse);
|
||||
expect(publications, 2);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user