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
@@ -228,6 +228,8 @@ class _EditorPreviewContent extends ConsumerWidget {
|
||||
select: () => (
|
||||
activeController.positionTick,
|
||||
activeController.selectedVisualIds.isNotEmpty,
|
||||
activeController.distortionEditingElement,
|
||||
activeController.distortionPerspective,
|
||||
activeController.maskEditingElement,
|
||||
activeController.obscureEditingElement,
|
||||
),
|
||||
|
||||
@@ -8,6 +8,10 @@ extension TransformChannelLabel on TransformChannel {
|
||||
TransformChannel.rotation => context.l10n.rotation,
|
||||
TransformChannel.scale => context.l10n.scale,
|
||||
TransformChannel.cornerRadius => context.l10n.cornerRadius,
|
||||
TransformChannel.distortTopLeft => context.l10n.distortionTopLeft,
|
||||
TransformChannel.distortTopRight => context.l10n.distortionTopRight,
|
||||
TransformChannel.distortBottomRight => context.l10n.distortionBottomRight,
|
||||
TransformChannel.distortBottomLeft => context.l10n.distortionBottomLeft,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
import 'package:cutdex/l10n/l10n.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/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'property_number_input.dart';
|
||||
|
||||
/// Presentation of four position channels; editing and native lifetime live in the host.
|
||||
class DistortionParameterEditor extends StatelessWidget {
|
||||
const DistortionParameterEditor({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.extent,
|
||||
required this.enabled,
|
||||
required this.editing,
|
||||
required this.perspective,
|
||||
required this.keyframes,
|
||||
required this.editContext,
|
||||
required this.onSubmit,
|
||||
required this.onReset,
|
||||
required this.onPerspective,
|
||||
this.onToggle,
|
||||
this.error,
|
||||
});
|
||||
final ClipDistortion value;
|
||||
final Size extent;
|
||||
final bool enabled, editing, perspective;
|
||||
final PropertyKeyframeControls keyframes;
|
||||
final Object editContext;
|
||||
final Future<bool> Function(int corner, int axis, double value) onSubmit;
|
||||
final VoidCallback? onToggle;
|
||||
final VoidCallback onReset;
|
||||
final ValueChanged<bool> onPerspective;
|
||||
final String? error;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final keys = keyframes, l = context.l10n;
|
||||
final labels = [
|
||||
l.distortionTopLeft,
|
||||
l.distortionTopRight,
|
||||
l.distortionBottomRight,
|
||||
l.distortionBottomLeft,
|
||||
];
|
||||
return AppPropertySection(
|
||||
child: AppPropertyGroup(
|
||||
label: l.distortion,
|
||||
padChild: false,
|
||||
actions: [
|
||||
keys.button(
|
||||
context,
|
||||
ClipDistortion.ids,
|
||||
l.distortion,
|
||||
'distortion-key',
|
||||
),
|
||||
keys.menu(context, ClipDistortion.ids, l.distortion, 'distortion'),
|
||||
],
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
AppPropertyRow(
|
||||
children: [
|
||||
TextButton(
|
||||
key: const ValueKey('distortion-edit'),
|
||||
onPressed: enabled ? onToggle : null,
|
||||
child: Text(editing ? l.finishDistortion : l.editDistortion),
|
||||
),
|
||||
IconButton(
|
||||
key: const ValueKey('distortion-reset'),
|
||||
tooltip: l.resetDistortion,
|
||||
icon: const Icon(AppIcons.reset, size: 16),
|
||||
onPressed: enabled ? onReset : null,
|
||||
),
|
||||
],
|
||||
),
|
||||
AppPropertyRow(
|
||||
children: [
|
||||
AppSelect<bool>(
|
||||
value: perspective,
|
||||
label: l.distortion,
|
||||
emptyLabel: l.freeDistortion,
|
||||
options: [
|
||||
AppSelectOption(false, l.freeDistortion),
|
||||
AppSelectOption(true, l.perspectiveDistortion),
|
||||
],
|
||||
onChanged: enabled ? onPerspective : null,
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var i = 0; i < 4; i++) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
labels[i],
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
keys.menu(
|
||||
context,
|
||||
ClipDistortion.ids.sublist(i * 2, i * 2 + 2),
|
||||
labels[i],
|
||||
'distortion-${ClipDistortion.names[i]}',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
AppPropertyRow(
|
||||
trailing: keys.button(
|
||||
context,
|
||||
ClipDistortion.ids.sublist(i * 2, i * 2 + 2),
|
||||
labels[i],
|
||||
'distortion-${ClipDistortion.names[i]}-key',
|
||||
),
|
||||
children: [
|
||||
for (var axis = 0; axis < 2; axis++)
|
||||
PropertyNumberInput(
|
||||
key: ValueKey(
|
||||
'distortion-${ClipDistortion.names[i]}-${axis == 0 ? 'x' : 'y'}',
|
||||
),
|
||||
label: axis == 0 ? 'X' : 'Y',
|
||||
inlineLabel: true,
|
||||
prefix: axis == 0 ? 'X' : 'Y',
|
||||
value:
|
||||
value.values[i * 2 + axis] *
|
||||
(axis == 0 ? extent.width : extent.height),
|
||||
enabled: enabled,
|
||||
readOnly: false,
|
||||
editContext: editContext,
|
||||
submit: (v) => onSubmit(i, axis, v),
|
||||
onScrubUpdate: (_) {},
|
||||
onScrubEnd: () {},
|
||||
onScrubCancel: () {},
|
||||
scrubbing: false,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (error != null)
|
||||
Padding(padding: const EdgeInsets.all(16), child: Text(error!)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name: 'Distortion / desktop', size: Size(240, 400))
|
||||
Widget distortionEditorPreview() {
|
||||
var value = const ClipDistortion(topLeft: (.05, .1));
|
||||
var perspective = false, editing = false;
|
||||
final stack = ClipParameterAnimation(
|
||||
ElementRecord(
|
||||
id: ElementId('preview'),
|
||||
structure: ElementStructure.content,
|
||||
duration: 1,
|
||||
sourceStart: 0,
|
||||
sourceDuration: 1,
|
||||
enabled: true,
|
||||
),
|
||||
0,
|
||||
);
|
||||
return MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, update) => SingleChildScrollView(
|
||||
child: DistortionParameterEditor(
|
||||
value: value,
|
||||
extent: const Size(300, 200),
|
||||
enabled: true,
|
||||
editing: editing,
|
||||
perspective: perspective,
|
||||
editContext: 'preview',
|
||||
keyframes: PropertyKeyframeControls(
|
||||
stack: stack,
|
||||
enabled: true,
|
||||
onEdit: (ids, {action, interpolation}) async => true,
|
||||
onSeek: (_) async => true,
|
||||
),
|
||||
onSubmit: (corner, axis, input) async {
|
||||
final p = value.corners[corner];
|
||||
final next = value.withCorner(
|
||||
corner,
|
||||
axis == 0 ? input / 300 : p.$1,
|
||||
axis == 1 ? input / 200 : p.$2,
|
||||
);
|
||||
if (!next.isValid) return false;
|
||||
update(() => value = next);
|
||||
return true;
|
||||
},
|
||||
onReset: () => update(() => value = const ClipDistortion()),
|
||||
onToggle: () => update(() => editing = !editing),
|
||||
onPerspective: (v) => update(() => perspective = v),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/preview.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../workspace/timeline_session.dart';
|
||||
import '../preview/preview_panel.dart';
|
||||
import 'property_edit_controller.dart';
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'distortion_parameter_editor.dart';
|
||||
|
||||
class DistortionProperties extends ConsumerStatefulWidget {
|
||||
const DistortionProperties({
|
||||
super.key,
|
||||
required this.projectId,
|
||||
required this.timelineId,
|
||||
required this.session,
|
||||
required this.sequence,
|
||||
required this.clip,
|
||||
});
|
||||
final String projectId, timelineId;
|
||||
final EditorTimelineSession session;
|
||||
final SequenceId sequence;
|
||||
final ElementId clip;
|
||||
@override
|
||||
ConsumerState<DistortionProperties> createState() =>
|
||||
_DistortionPropertiesState();
|
||||
}
|
||||
|
||||
class _DistortionPropertiesState extends ConsumerState<DistortionProperties> {
|
||||
PropertyEditController _create() => PropertyEditController(
|
||||
session: widget.session,
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
projectId: widget.projectId,
|
||||
timelineId: widget.timelineId,
|
||||
operation: 'setTransform',
|
||||
);
|
||||
late PropertyEditController _controller = _create();
|
||||
PreviewController? _preview;
|
||||
bool _perspective = false;
|
||||
void _release() {
|
||||
final previous = _preview;
|
||||
_preview = null;
|
||||
if (previous != null) {
|
||||
scheduleMicrotask(() => previous.releaseDistortionEditing(this));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant DistortionProperties oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (_controller.identity !=
|
||||
(
|
||||
widget.session,
|
||||
widget.sequence,
|
||||
widget.clip,
|
||||
widget.projectId,
|
||||
widget.timelineId,
|
||||
)) {
|
||||
_release();
|
||||
_controller.dispose();
|
||||
_controller = _create();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_release();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final preview = ref
|
||||
.watch(editorPreviewProvider(widget.projectId, widget.timelineId))
|
||||
.asData
|
||||
?.value;
|
||||
if (!identical(_preview, preview)) {
|
||||
_release();
|
||||
_preview = preview;
|
||||
}
|
||||
final view = widget.session.view(widget.sequence);
|
||||
return ListenableBuilder(
|
||||
listenable: Listenable.merge([
|
||||
_controller,
|
||||
view,
|
||||
if (preview != null) preview.transforms,
|
||||
if (preview != null) preview.positionChanges,
|
||||
]),
|
||||
builder: (context, _) {
|
||||
final stack = _controller.animation;
|
||||
if (stack == null) return const SizedBox.shrink();
|
||||
final visual = preview?.visualForProperties(widget.clip);
|
||||
final value = preview?.transforms.hasPending == true && visual != null
|
||||
? visual.transform
|
||||
: ClipTransform.fromRecord(
|
||||
stack.record,
|
||||
sourceTick: stack.sourceTick,
|
||||
);
|
||||
final extent =
|
||||
visual?.geometry.distortionSize ??
|
||||
Size(widget.session.canvas.width, widget.session.canvas.height);
|
||||
final enabled =
|
||||
!_controller.saving &&
|
||||
stack.containsPlayhead &&
|
||||
preview?.transforms.hasPending != true;
|
||||
Future<bool> edit(void Function(EditorCommandService, int) action) =>
|
||||
_controller.run(preview, action);
|
||||
final keys = PropertyKeyframeControls(
|
||||
stack: stack,
|
||||
enabled: enabled,
|
||||
onEdit: (ids, {action, interpolation}) => edit(
|
||||
(c, t) => c.editKeyframeChannel(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
parameterIds: ids,
|
||||
action: action,
|
||||
interpolation: interpolation,
|
||||
),
|
||||
),
|
||||
onSeek: (offset) => _controller.run(
|
||||
preview,
|
||||
(_, t) => view.seekTo(t - stack.localTick + offset),
|
||||
seek: true,
|
||||
),
|
||||
);
|
||||
final editing = preview?.distortionEditingElement == widget.clip;
|
||||
final l = context.l10n;
|
||||
Future<bool> submit(int corner, int axis, double input) => edit(
|
||||
(c, t) => c.setTransform(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
change: (current) {
|
||||
final p = current.distortion.corners[corner];
|
||||
return current.copyWith(
|
||||
distortion: current.distortion.withCorner(
|
||||
corner,
|
||||
axis == 0 ? input / extent.width : p.$1,
|
||||
axis == 1 ? input / extent.height : p.$2,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
return DistortionParameterEditor(
|
||||
value: value.distortion,
|
||||
extent: extent,
|
||||
enabled: enabled,
|
||||
editing: editing,
|
||||
perspective: _perspective,
|
||||
keyframes: keys,
|
||||
editContext: _controller.identity,
|
||||
error: _controller.failed ? l.updateOperationFailed : null,
|
||||
onSubmit: submit,
|
||||
onToggle: preview == null
|
||||
? null
|
||||
: () => _controller.run(
|
||||
preview,
|
||||
(_, t) => preview.setDistortionEditing(
|
||||
editing ? null : widget.clip,
|
||||
owner: this,
|
||||
perspective: _perspective,
|
||||
),
|
||||
seek: true,
|
||||
),
|
||||
onReset: () => edit(
|
||||
(c, t) => c.setTransform(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
change: (v) => v.copyWith(distortion: const ClipDistortion()),
|
||||
),
|
||||
),
|
||||
onPerspective: (v) {
|
||||
setState(() => _perspective = v);
|
||||
if (editing) {
|
||||
preview!.setDistortionEditing(
|
||||
widget.clip,
|
||||
owner: this,
|
||||
perspective: v,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension EffectTypeLabel on ClipEffectType {
|
||||
String label(BuildContext context) => switch (this) {
|
||||
ClipEffectType.dropShadow => context.l10n.dropShadow,
|
||||
ClipEffectType.innerShadow => context.l10n.innerShadow,
|
||||
ClipEffectType.layerBlur => context.l10n.layerBlur,
|
||||
ClipEffectType.backgroundBlur => context.l10n.backgroundBlur,
|
||||
ClipEffectType.glass => context.l10n.glassEffect,
|
||||
ClipEffectType.noise => context.l10n.noiseEffect,
|
||||
ClipEffectType.texture => context.l10n.textureEffect,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'effect_labels.dart';
|
||||
import 'property_layer_row.dart';
|
||||
|
||||
class EffectList extends StatelessWidget {
|
||||
const EffectList({
|
||||
super.key,
|
||||
required this.stack,
|
||||
required this.enabled,
|
||||
required this.keyframes,
|
||||
required this.onAdd,
|
||||
required this.onReorder,
|
||||
required this.onToggle,
|
||||
required this.onRemove,
|
||||
required this.editorBuilder,
|
||||
this.error,
|
||||
});
|
||||
final ClipEffectStack stack;
|
||||
final bool enabled;
|
||||
final PropertyKeyframeControls keyframes;
|
||||
final void Function(ClipEffectType) onAdd;
|
||||
final void Function(List<String>) onReorder;
|
||||
final void Function(ClipEffectLayer) onToggle, onRemove;
|
||||
final Widget Function(ClipEffectLayer) editorBuilder;
|
||||
final String? error;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final layers = stack.layers;
|
||||
return AppPropertySection(
|
||||
bottomSpacing: layers.isEmpty ? 0 : null,
|
||||
child: AppPropertyGroup(
|
||||
label: context.l10n.effects,
|
||||
padChild: false,
|
||||
actions: [
|
||||
keyframes.button(
|
||||
context,
|
||||
stack.parameterIds,
|
||||
context.l10n.effects,
|
||||
'effects-key',
|
||||
),
|
||||
AppDropdownMenu(
|
||||
enabled: enabled,
|
||||
builder: (context, toggle, focus) => IconButton(
|
||||
key: const ValueKey('effect-add'),
|
||||
focusNode: focus,
|
||||
tooltip: context.l10n.addEffect,
|
||||
onPressed: enabled ? toggle : null,
|
||||
icon: const Icon(AppIcons.add, size: 16),
|
||||
),
|
||||
items: [
|
||||
for (final type in ClipEffectType.values)
|
||||
AppMenuItem(
|
||||
label: type.label(context),
|
||||
onPressed: enabled && stack.canAdd(type)
|
||||
? () => onAdd(type)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ReorderableListView(
|
||||
shrinkWrap: true,
|
||||
primary: false,
|
||||
padding: EdgeInsets.zero,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
buildDefaultDragHandles: false,
|
||||
onReorderItem: (from, to) {
|
||||
if (!enabled) return;
|
||||
final order = layers.map((l) => l.id).toList();
|
||||
order.insert(to, order.removeAt(from));
|
||||
onReorder(order);
|
||||
},
|
||||
children: [
|
||||
for (var i = 0; i < layers.length; i++)
|
||||
PropertyLayerRow(
|
||||
key: ValueKey('effect-layer-${layers[i].id}'),
|
||||
id: layers[i].id,
|
||||
prefix: 'effect',
|
||||
index: i,
|
||||
enabled: enabled,
|
||||
visible: layers[i].enabled,
|
||||
label: layers[i].type.label(context),
|
||||
tooltip: context.l10n.effects,
|
||||
onVisibility: () => onToggle(layers[i]),
|
||||
onRemove: () => onRemove(layers[i]),
|
||||
menuItems: [
|
||||
for (final (delta, label) in [
|
||||
(-1, context.l10n.effectMoveUp),
|
||||
(1, context.l10n.effectMoveDown),
|
||||
])
|
||||
AppMenuItem(
|
||||
label: label,
|
||||
closeAncestors: false,
|
||||
onPressed:
|
||||
!enabled ||
|
||||
i + delta < 0 ||
|
||||
i + delta >= layers.length
|
||||
? null
|
||||
: () {
|
||||
final order = layers
|
||||
.map((l) => l.id)
|
||||
.toList();
|
||||
order.insert(i + delta, order.removeAt(i));
|
||||
onReorder(order);
|
||||
},
|
||||
),
|
||||
],
|
||||
editor: editorBuilder(layers[i]),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (error != null)
|
||||
Text(
|
||||
error!,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'effect_labels.dart';
|
||||
import 'property_color_input.dart';
|
||||
import 'property_number_input.dart';
|
||||
|
||||
class EffectParameterEditor extends StatelessWidget {
|
||||
const EffectParameterEditor({
|
||||
super.key,
|
||||
required this.layer,
|
||||
required this.stack,
|
||||
required this.enabled,
|
||||
required this.editContext,
|
||||
required this.keyframes,
|
||||
required this.onChange,
|
||||
required this.onTypeChange,
|
||||
});
|
||||
final ClipEffectLayer layer;
|
||||
final ClipEffectStack stack;
|
||||
final bool enabled;
|
||||
final Object editContext;
|
||||
final PropertyKeyframeControls keyframes;
|
||||
final Future<bool> Function(Map<String, double>) onChange;
|
||||
final void Function(ClipEffectType) onTypeChange;
|
||||
|
||||
String _fieldLabel(BuildContext context, String field) => switch (field) {
|
||||
'x' => 'X',
|
||||
'y' => 'Y',
|
||||
'blur' => context.l10n.shadowBlur,
|
||||
'spread' => context.l10n.shadowSpread,
|
||||
'opacity' => context.l10n.shadowOpacity,
|
||||
'blurEnd' => context.l10n.effectBlurEnd,
|
||||
'start.x' => context.l10n.effectStartX,
|
||||
'start.y' => context.l10n.effectStartY,
|
||||
'end.x' => context.l10n.effectEndX,
|
||||
'end.y' => context.l10n.effectEndY,
|
||||
'lightAngle' => context.l10n.effectLightAngle,
|
||||
'lightIntensity' => context.l10n.effectLightIntensity,
|
||||
'refraction' => context.l10n.effectRefraction,
|
||||
'depth' => context.l10n.effectDepth,
|
||||
'dispersion' => context.l10n.effectDispersion,
|
||||
'frost' => context.l10n.effectFrost,
|
||||
'splay' => context.l10n.effectSplay,
|
||||
'size' => context.l10n.effectNoiseSize,
|
||||
'density' => context.l10n.effectDensity,
|
||||
'radius' => context.l10n.effectTextureRadius,
|
||||
'seed' => context.l10n.effectSeed,
|
||||
_ => field,
|
||||
};
|
||||
Widget _number(BuildContext context, String field) {
|
||||
final label = _fieldLabel(context, field);
|
||||
final structural = EffectParameterTarget.structural.contains(field);
|
||||
final percentage = {
|
||||
'opacity',
|
||||
'density',
|
||||
'lightIntensity',
|
||||
'splay',
|
||||
}.contains(field);
|
||||
final factor = percentage ? 100.0 : 1.0;
|
||||
final definition = EffectParameterTarget.definition(field);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PropertyNumberInput(
|
||||
key: ValueKey('effect-${layer.id}-$field'),
|
||||
label: label,
|
||||
value: layer.values[field]! * factor,
|
||||
unit: percentage ? '%' : null,
|
||||
enabled: enabled && layer.enabled,
|
||||
readOnly: false,
|
||||
scrubbing: false,
|
||||
editContext: (editContext, layer.id, layer.type),
|
||||
onScrubUpdate: (_) {},
|
||||
onScrubEnd: () {},
|
||||
onScrubCancel: () {},
|
||||
submit: (v) => !definition.accepts(v / factor)
|
||||
? Future.value(false)
|
||||
: onChange({field: v / factor}),
|
||||
),
|
||||
),
|
||||
if (!structural) ...[
|
||||
keyframes.button(
|
||||
context,
|
||||
[layer.target(field)],
|
||||
label,
|
||||
'effect-${layer.id}-$field-key',
|
||||
),
|
||||
keyframes.menu(
|
||||
context,
|
||||
[layer.target(field)],
|
||||
label,
|
||||
'effect-${layer.id}-$field',
|
||||
),
|
||||
] else
|
||||
const SizedBox(width: 48),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _color(BuildContext context, String prefix, String label) {
|
||||
final fields = ['${prefix}r', '${prefix}g', '${prefix}b'];
|
||||
final values = fields.map((f) => layer.values[f]!).toList();
|
||||
final hex = values
|
||||
.map((v) => (v * 255).round().toRadixString(16).padLeft(2, '0'))
|
||||
.join()
|
||||
.toUpperCase();
|
||||
final ids = fields.map(layer.target).toList();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(label, style: AppTheme.propertyLabelStyle(context)),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PropertyColorInput(
|
||||
key: ValueKey('effect-${layer.id}-$prefix'),
|
||||
value: hex,
|
||||
color: Color.from(
|
||||
alpha: 1,
|
||||
red: values[0],
|
||||
green: values[1],
|
||||
blue: values[2],
|
||||
),
|
||||
enabled: enabled && layer.enabled,
|
||||
editContext: (editContext, layer.id, layer.type),
|
||||
submit: (rgb) => onChange({
|
||||
fields[0]: ((rgb >> 16) & 255) / 255,
|
||||
fields[1]: ((rgb >> 8) & 255) / 255,
|
||||
fields[2]: (rgb & 255) / 255,
|
||||
}),
|
||||
),
|
||||
),
|
||||
keyframes.button(
|
||||
context,
|
||||
ids,
|
||||
label,
|
||||
'effect-${layer.id}-$prefix-key',
|
||||
),
|
||||
keyframes.menu(context, ids, label, 'effect-${layer.id}-$prefix'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _mode(BuildContext context, String field, List<String> labels) =>
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: SizedBox(
|
||||
height: 24,
|
||||
child: AppSelect<int>(
|
||||
closeAncestors: false,
|
||||
key: ValueKey('effect-${layer.id}-$field'),
|
||||
value: layer.values[field]!.round(),
|
||||
label: field == 'noiseMode'
|
||||
? context.l10n.effectNoiseMode
|
||||
: context.l10n.shadowBlur,
|
||||
emptyLabel: context.l10n.effects,
|
||||
options: [
|
||||
for (var i = 0; i < labels.length; i++)
|
||||
AppSelectOption(i, labels[i]),
|
||||
],
|
||||
onChanged: enabled && layer.enabled
|
||||
? (v) => onChange({field: v.toDouble()})
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 24,
|
||||
child: AppSelect<ClipEffectType>(
|
||||
closeAncestors: false,
|
||||
key: ValueKey('effect-${layer.id}-type'),
|
||||
value: layer.type,
|
||||
label: context.l10n.effects,
|
||||
emptyLabel: context.l10n.effects,
|
||||
options: [
|
||||
for (final type in ClipEffectType.values)
|
||||
if (stack.canAdd(type, excludingId: layer.id))
|
||||
AppSelectOption(type, type.label(context)),
|
||||
],
|
||||
onChanged: enabled ? onTypeChange : null,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (layer.values.containsKey('progressive'))
|
||||
_mode(context, 'progressive', [
|
||||
context.l10n.effectUniform,
|
||||
context.l10n.effectProgressive,
|
||||
]),
|
||||
if (layer.values.containsKey('noiseMode'))
|
||||
_mode(context, 'noiseMode', [
|
||||
context.l10n.effectMono,
|
||||
context.l10n.effectDuo,
|
||||
context.l10n.effectMulti,
|
||||
]),
|
||||
for (final field in layer.values.keys)
|
||||
if (!field.startsWith('color') &&
|
||||
!{'progressive', 'noiseMode', 'clipToShape'}.contains(field) &&
|
||||
!(layer.values['progressive'] == 0 &&
|
||||
{
|
||||
'blurEnd',
|
||||
'start.x',
|
||||
'start.y',
|
||||
'end.x',
|
||||
'end.y',
|
||||
}.contains(field)))
|
||||
_number(context, field),
|
||||
if (layer.values.containsKey('color.r') && layer.values['noiseMode'] != 2)
|
||||
_color(context, 'color.', context.l10n.color),
|
||||
if (layer.values['noiseMode'] == 1)
|
||||
_color(context, 'color2.', context.l10n.effectSecondColor),
|
||||
if (layer.values.containsKey('clipToShape'))
|
||||
CheckboxListTile(
|
||||
key: ValueKey('effect-${layer.id}-clipToShape'),
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
context.l10n.effectClipToShape,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
value: layer.values['clipToShape'] == 1,
|
||||
onChanged: enabled && layer.enabled
|
||||
? (v) => onChange({'clipToShape': v == true ? 1 : 0})
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../workspace/timeline_session.dart';
|
||||
import '../preview/preview_panel.dart';
|
||||
import 'property_edit_controller.dart';
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'effect_list.dart';
|
||||
import 'effect_parameter_editor.dart';
|
||||
|
||||
class EffectProperties extends ConsumerStatefulWidget {
|
||||
const EffectProperties({
|
||||
super.key,
|
||||
required this.projectId,
|
||||
required this.timelineId,
|
||||
required this.session,
|
||||
required this.sequence,
|
||||
required this.clip,
|
||||
});
|
||||
final String projectId, timelineId;
|
||||
final EditorTimelineSession session;
|
||||
final SequenceId sequence;
|
||||
final ElementId clip;
|
||||
|
||||
@override
|
||||
ConsumerState<EffectProperties> createState() => _EffectPropertiesState();
|
||||
}
|
||||
|
||||
class _EffectPropertiesState extends ConsumerState<EffectProperties> {
|
||||
Object get _identity => (
|
||||
widget.session,
|
||||
widget.sequence,
|
||||
widget.clip,
|
||||
widget.projectId,
|
||||
widget.timelineId,
|
||||
);
|
||||
PropertyEditController _createController() => PropertyEditController(
|
||||
session: widget.session,
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
projectId: widget.projectId,
|
||||
timelineId: widget.timelineId,
|
||||
operation: 'editEffect',
|
||||
);
|
||||
late PropertyEditController _controller = _createController();
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant EffectProperties oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (_controller.identity != _identity) {
|
||||
_controller.dispose();
|
||||
_controller = _createController();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final preview = ref
|
||||
.watch(editorPreviewProvider(widget.projectId, widget.timelineId))
|
||||
.asData
|
||||
?.value;
|
||||
final controller = _controller;
|
||||
final view = widget.session.view(widget.sequence);
|
||||
return ListenableBuilder(
|
||||
listenable: Listenable.merge([controller, view]),
|
||||
builder: (context, _) {
|
||||
final animation = controller.animation;
|
||||
if (animation == null) return const SizedBox.shrink();
|
||||
final stack = ClipEffectStack(animation.record, animation.localTick);
|
||||
final enabled =
|
||||
!controller.saving &&
|
||||
stack.containsPlayhead &&
|
||||
preview?.transforms.hasPending != true;
|
||||
Future<bool> edit(void Function(EditorCommandService, int) action) =>
|
||||
controller.run(preview, action);
|
||||
final keyframes = PropertyKeyframeControls(
|
||||
stack: stack,
|
||||
enabled: enabled,
|
||||
onEdit: (ids, {action, interpolation}) => edit(
|
||||
(c, t) => c.editKeyframeChannel(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
parameterIds: ids,
|
||||
action: action,
|
||||
interpolation: interpolation,
|
||||
),
|
||||
),
|
||||
onSeek: (offset) => controller.run(
|
||||
preview,
|
||||
(_, tick) => view.seekTo(tick - stack.localTick + offset),
|
||||
seek: true,
|
||||
),
|
||||
);
|
||||
return EffectList(
|
||||
stack: stack,
|
||||
enabled: enabled,
|
||||
keyframes: keyframes,
|
||||
error: controller.failed ? context.l10n.updateEffectFailed : null,
|
||||
onAdd: (type) => edit(
|
||||
(c, t) => c.addEffect(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
effectId: c.newEffectId(),
|
||||
type: type,
|
||||
),
|
||||
),
|
||||
onReorder: (order) => edit(
|
||||
(c, t) => c.configureEffects(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
order: order,
|
||||
),
|
||||
),
|
||||
onToggle: (layer) => edit(
|
||||
(c, t) => c.configureEffects(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
effectId: layer.id,
|
||||
enabled: !layer.enabled,
|
||||
),
|
||||
),
|
||||
onRemove: (layer) => edit(
|
||||
(c, t) => c.removeEffect(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
effectId: layer.id,
|
||||
),
|
||||
),
|
||||
editorBuilder: (layer) => EffectParameterEditor(
|
||||
layer: layer,
|
||||
stack: stack,
|
||||
enabled: enabled,
|
||||
editContext: controller.identity,
|
||||
keyframes: keyframes,
|
||||
onChange: (values) => edit(
|
||||
(c, t) => c.setEffect(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
effectId: layer.id,
|
||||
values: values,
|
||||
),
|
||||
),
|
||||
onTypeChange: (type) => edit(
|
||||
(c, t) => c.changeEffectType(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
effectId: layer.id,
|
||||
type: type,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,19 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/preview.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../workspace/timeline_session.dart';
|
||||
import 'property_edit_boundary.dart';
|
||||
|
||||
part 'picture_edits.g.dart';
|
||||
part 'picture_edits.freezed.dart';
|
||||
|
||||
enum PictureEditFailure { keyframes, alignment, invalidTransform, transform }
|
||||
|
||||
@freezed
|
||||
abstract class PictureEditTarget with _$PictureEditTarget {
|
||||
const factory PictureEditTarget({
|
||||
required TimelineVersion version,
|
||||
required int tick,
|
||||
}) = _PictureEditTarget;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class PictureEditException
|
||||
with _$PictureEditException
|
||||
@@ -31,35 +25,16 @@ abstract class PictureEditException
|
||||
@riverpod
|
||||
class PictureEdits extends _$PictureEdits {
|
||||
Future<bool>? _pending;
|
||||
late PropertyEditBoundary _boundary;
|
||||
@override
|
||||
AsyncValue<void> build(
|
||||
EditorTimelineSession session,
|
||||
SequenceId sequence,
|
||||
ElementId clip,
|
||||
) => const AsyncData(null);
|
||||
|
||||
PictureEditTarget _capture() {
|
||||
final view = session.view(sequence);
|
||||
return PictureEditTarget(
|
||||
version: view.version.kernelVersion,
|
||||
tick: view.playheadTick,
|
||||
);
|
||||
}
|
||||
|
||||
bool _valid(
|
||||
PictureEditTarget target,
|
||||
bool Function() isCurrent,
|
||||
PreviewController? preview,
|
||||
) {
|
||||
if (!ref.mounted ||
|
||||
!isCurrent() ||
|
||||
session.activeSequenceId != sequence ||
|
||||
preview?.transforms.hasPending == true) {
|
||||
return false;
|
||||
}
|
||||
final view = session.view(sequence);
|
||||
return target.tick == view.playheadTick &&
|
||||
identical(target.version, view.version.kernelVersion);
|
||||
_boundary = PropertyEditBoundary(session, sequence, clip);
|
||||
ref.onDispose(_boundary.dispose);
|
||||
return const AsyncData(null);
|
||||
}
|
||||
|
||||
ClipAnimation? animation() {
|
||||
@@ -86,10 +61,9 @@ class PictureEdits extends _$PictureEdits {
|
||||
if (state.isLoading || preview?.transforms.hasPending == true) {
|
||||
return Future.value(false);
|
||||
}
|
||||
final target = _capture();
|
||||
final work = _run(PictureEditFailure.transform, () async {
|
||||
await preview?.pauseForCanvasInteraction();
|
||||
if (!_valid(target, isCurrent, preview)) return false;
|
||||
final work = _run(PictureEditFailure.transform, preview, isCurrent, (
|
||||
target,
|
||||
) {
|
||||
final current = animation()?.value;
|
||||
if (current == null) return false;
|
||||
final value = change(current);
|
||||
@@ -101,7 +75,8 @@ class PictureEdits extends _$PictureEdits {
|
||||
value.scale == current.scale &&
|
||||
value.scaleY == current.scaleY &&
|
||||
value.rotation == current.rotation &&
|
||||
value.sameCorners(current)) {
|
||||
value.sameCorners(current) &&
|
||||
value.distortion.same(current.distortion)) {
|
||||
return true;
|
||||
}
|
||||
session.commands.setTransform(
|
||||
@@ -133,10 +108,7 @@ class PictureEdits extends _$PictureEdits {
|
||||
preview?.transforms.hasPending == true) {
|
||||
return;
|
||||
}
|
||||
final target = _capture();
|
||||
await _run(PictureEditFailure.keyframes, () async {
|
||||
await preview?.pauseForCanvasInteraction();
|
||||
if (!_valid(target, isCurrent, preview)) return false;
|
||||
await _run(PictureEditFailure.keyframes, preview, isCurrent, (target) {
|
||||
session.commands.editKeyframeChannel(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
@@ -155,7 +127,6 @@ class PictureEdits extends _$PictureEdits {
|
||||
required bool Function() isCurrent,
|
||||
}) async {
|
||||
if (state.isLoading || preview.transforms.hasPending) return;
|
||||
final target = _capture();
|
||||
final current = animation();
|
||||
if (current == null) return;
|
||||
final command = AlignClip(
|
||||
@@ -167,12 +138,13 @@ class PictureEdits extends _$PictureEdits {
|
||||
alignment: alignment,
|
||||
expectedVersion: session.version,
|
||||
);
|
||||
await _run(PictureEditFailure.alignment, () async {
|
||||
await preview.pauseForCanvasInteraction();
|
||||
await _run(PictureEditFailure.alignment, preview, isCurrent, (
|
||||
target,
|
||||
) async {
|
||||
await session.alignClip(
|
||||
sequence,
|
||||
command,
|
||||
isCancelled: () => !_valid(target, isCurrent, preview),
|
||||
isCancelled: () => !target.isCurrent,
|
||||
);
|
||||
return true;
|
||||
});
|
||||
@@ -180,24 +152,22 @@ class PictureEdits extends _$PictureEdits {
|
||||
|
||||
Future<bool> _run(
|
||||
PictureEditFailure failure,
|
||||
Future<bool> Function() action,
|
||||
PreviewController? preview,
|
||||
bool Function() isCurrent,
|
||||
FutureOr<bool> Function(PropertyEditContext) action,
|
||||
) async {
|
||||
final lease = ref.keepAlive();
|
||||
state = const AsyncLoading();
|
||||
try {
|
||||
final applied = await session.runEditAsync(
|
||||
switch (failure) {
|
||||
final applied = await _boundary.run(
|
||||
preview,
|
||||
action,
|
||||
isCurrent: () => ref.mounted && isCurrent(),
|
||||
started: () => state = const AsyncLoading(),
|
||||
operation: switch (failure) {
|
||||
PictureEditFailure.keyframes => 'editKeyframes',
|
||||
PictureEditFailure.alignment => 'alignClip',
|
||||
_ => 'setTransform',
|
||||
},
|
||||
sequence,
|
||||
action,
|
||||
context: {
|
||||
'clipIds': [clip.value],
|
||||
'entryPoint': 'property',
|
||||
'playheadTick': session.view(sequence).playheadTick,
|
||||
},
|
||||
);
|
||||
if (ref.mounted) state = const AsyncData(null);
|
||||
return applied;
|
||||
|
||||
@@ -12,318 +12,6 @@ part of 'picture_edits.dart';
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PictureEditTarget {
|
||||
TimelineVersion get version;
|
||||
int get tick;
|
||||
|
||||
/// Create a copy of PictureEditTarget
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$PictureEditTargetCopyWith<PictureEditTarget> get copyWith =>
|
||||
_$PictureEditTargetCopyWithImpl<PictureEditTarget>(
|
||||
this as PictureEditTarget,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as PictureEditTarget;
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is PictureEditTarget &&
|
||||
(identical(other.version, _this.version) ||
|
||||
other.version == _this.version) &&
|
||||
(identical(other.tick, _this.tick) || other.tick == _this.tick));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as PictureEditTarget;
|
||||
return Object.hash(runtimeType, _this.version, _this.tick);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as PictureEditTarget;
|
||||
return 'PictureEditTarget(version: ${_this.version}, tick: ${_this.tick})';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $PictureEditTargetCopyWith<$Res> {
|
||||
factory $PictureEditTargetCopyWith(
|
||||
PictureEditTarget value,
|
||||
$Res Function(PictureEditTarget) _then,
|
||||
) = _$PictureEditTargetCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({TimelineVersion version, int tick});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PictureEditTargetCopyWithImpl<$Res>
|
||||
implements $PictureEditTargetCopyWith<$Res> {
|
||||
_$PictureEditTargetCopyWithImpl(this._self, this._then);
|
||||
|
||||
final PictureEditTarget _self;
|
||||
final $Res Function(PictureEditTarget) _then;
|
||||
|
||||
/// Create a copy of PictureEditTarget
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? version = null, Object? tick = null}) {
|
||||
return _then(
|
||||
PictureEditTarget(
|
||||
version: null == version
|
||||
? _self.version
|
||||
: version // ignore: cast_nullable_to_non_nullable
|
||||
as TimelineVersion,
|
||||
tick: null == tick
|
||||
? _self.tick
|
||||
: tick // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds pattern-matching-related methods to [PictureEditTarget].
|
||||
extension PictureEditTargetPatterns on PictureEditTarget {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_PictureEditTarget value)? $default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PictureEditTarget() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_PictureEditTarget value) $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PictureEditTarget():
|
||||
return $default(_that);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_PictureEditTarget value)? $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PictureEditTarget() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function(TimelineVersion version, int tick)? $default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PictureEditTarget() when $default != null:
|
||||
return $default(_that.version, _that.tick);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function(TimelineVersion version, int tick) $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PictureEditTarget():
|
||||
return $default(_that.version, _that.tick);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function(TimelineVersion version, int tick)? $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PictureEditTarget() when $default != null:
|
||||
return $default(_that.version, _that.tick);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _PictureEditTarget implements PictureEditTarget {
|
||||
const _PictureEditTarget({required this.version, required this.tick});
|
||||
|
||||
@override
|
||||
final TimelineVersion version;
|
||||
@override
|
||||
final int tick;
|
||||
|
||||
/// Create a copy of PictureEditTarget
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$PictureEditTargetCopyWith<_PictureEditTarget> get copyWith =>
|
||||
__$PictureEditTargetCopyWithImpl<_PictureEditTarget>(this, _$identity);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _PictureEditTarget &&
|
||||
(identical(other.version, version) || other.version == version) &&
|
||||
(identical(other.tick, tick) || other.tick == tick));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType, version, tick);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PictureEditTarget(version: $version, tick: $tick)';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$PictureEditTargetCopyWith<$Res>
|
||||
implements $PictureEditTargetCopyWith<$Res> {
|
||||
factory _$PictureEditTargetCopyWith(
|
||||
_PictureEditTarget value,
|
||||
$Res Function(_PictureEditTarget) _then,
|
||||
) = __$PictureEditTargetCopyWithImpl;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({TimelineVersion version, int tick});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$PictureEditTargetCopyWithImpl<$Res>
|
||||
implements _$PictureEditTargetCopyWith<$Res> {
|
||||
__$PictureEditTargetCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _PictureEditTarget _self;
|
||||
final $Res Function(_PictureEditTarget) _then;
|
||||
|
||||
/// Create a copy of PictureEditTarget
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$Res call({Object? version = null, Object? tick = null}) {
|
||||
return _then(
|
||||
_PictureEditTarget(
|
||||
version: null == version
|
||||
? _self.version
|
||||
: version // ignore: cast_nullable_to_non_nullable
|
||||
as TimelineVersion,
|
||||
tick: null == tick
|
||||
? _self.tick
|
||||
: tick // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PictureEditException {
|
||||
PictureEditFailure get failure;
|
||||
|
||||
@@ -58,7 +58,7 @@ final class PictureEditsProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$pictureEditsHash() => r'5a8ab10fcac9638fb0d98e214744f190fa499434';
|
||||
String _$pictureEditsHash() => r'b3166b6e97f6a711e6e92b67dfc44341a3fec4e2';
|
||||
|
||||
final class PictureEditsFamily extends $Family
|
||||
with
|
||||
|
||||
@@ -22,7 +22,10 @@ import '../../shared/state/operation_scope.dart';
|
||||
import '../preview/preview_panel.dart';
|
||||
import 'property_number_input.dart';
|
||||
import 'picture_edits.dart';
|
||||
import 'shadow_properties.dart';
|
||||
import 'effect_properties.dart';
|
||||
import 'stroke_properties.dart';
|
||||
import 'distortion_properties.dart';
|
||||
import 'effect_labels.dart';
|
||||
|
||||
class PictureProperties extends ConsumerStatefulWidget {
|
||||
const PictureProperties({
|
||||
@@ -208,7 +211,8 @@ class _PicturePropertiesState extends ConsumerState<PictureProperties> {
|
||||
value.rotation == _scrubBase!.rotation &&
|
||||
value.scale == _scrubBase!.scale &&
|
||||
value.scaleY == _scrubBase!.scaleY &&
|
||||
value.sameCorners(_scrubBase!))) {
|
||||
value.sameCorners(_scrubBase!) &&
|
||||
value.distortion.same(_scrubBase!.distortion))) {
|
||||
_cancelScrub();
|
||||
return;
|
||||
}
|
||||
@@ -271,6 +275,10 @@ class _PicturePropertiesState extends ConsumerState<PictureProperties> {
|
||||
value.scale,
|
||||
value.scaleY,
|
||||
value.rotation,
|
||||
value.distortion.topLeft,
|
||||
value.distortion.topRight,
|
||||
value.distortion.bottomRight,
|
||||
value.distortion.bottomLeft,
|
||||
value.cornerRadius,
|
||||
value.topLeftRadius,
|
||||
value.topRightRadius,
|
||||
@@ -866,6 +874,13 @@ class _PicturePropertiesState extends ConsumerState<PictureProperties> {
|
||||
keyTools(TransformChannel.scale),
|
||||
]),
|
||||
],
|
||||
DistortionProperties(
|
||||
projectId: widget.projectId,
|
||||
timelineId: widget.timelineId,
|
||||
session: widget.session,
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip.id,
|
||||
),
|
||||
section([
|
||||
if (desktop)
|
||||
AppPropertyGroup(
|
||||
@@ -921,7 +936,14 @@ class _PicturePropertiesState extends ConsumerState<PictureProperties> {
|
||||
keyTools(TransformChannel.cornerRadius),
|
||||
],
|
||||
]),
|
||||
ShadowProperties(
|
||||
StrokeProperties(
|
||||
projectId: widget.projectId,
|
||||
timelineId: widget.timelineId,
|
||||
session: widget.session,
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip.id,
|
||||
),
|
||||
EffectProperties(
|
||||
projectId: widget.projectId,
|
||||
timelineId: widget.timelineId,
|
||||
session: widget.session,
|
||||
@@ -996,17 +1018,29 @@ class _KeyframeTimeline extends StatelessWidget {
|
||||
for (final (id, label, times) in [
|
||||
for (final channel in TransformChannel.values)
|
||||
(channel.name, channel.label(context), animation.keyTimes(channel)),
|
||||
if (ClipShadowStack(
|
||||
for (final layer in ClipStrokeStack(
|
||||
animation.record,
|
||||
animation.localTick,
|
||||
).layers.isNotEmpty)
|
||||
).layers)
|
||||
(
|
||||
'shadow',
|
||||
context.l10n.shadow,
|
||||
ClipShadowStack(
|
||||
animation.record,
|
||||
animation.localTick,
|
||||
).keyOffsets.map((t) => animation.start + t).toList(),
|
||||
'stroke-${layer.id}',
|
||||
context.l10n.stroke,
|
||||
ClipStrokeStack(animation.record, animation.localTick)
|
||||
.keyOffsets(layer.parameterIds)
|
||||
.map((t) => animation.start + t)
|
||||
.toList(),
|
||||
),
|
||||
for (final layer in ClipEffectStack(
|
||||
animation.record,
|
||||
animation.localTick,
|
||||
).layers)
|
||||
(
|
||||
layer.id,
|
||||
layer.type.label(context),
|
||||
ClipEffectStack(animation.record, animation.localTick)
|
||||
.keyOffsets(layer.parameterIds)
|
||||
.map((t) => animation.start + t)
|
||||
.toList(),
|
||||
),
|
||||
])
|
||||
SizedBox(
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
import '../../shared/state/operation_scope.dart';
|
||||
import 'property_color_picker.dart';
|
||||
|
||||
class PropertyColorInput extends StatefulWidget {
|
||||
const PropertyColorInput({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.color,
|
||||
required this.enabled,
|
||||
required this.editContext,
|
||||
required this.submit,
|
||||
});
|
||||
final String value;
|
||||
final Color color;
|
||||
final bool enabled;
|
||||
final Object editContext;
|
||||
final Future<bool> Function(int) submit;
|
||||
@override
|
||||
State<PropertyColorInput> createState() => _PropertyColorInputState();
|
||||
}
|
||||
|
||||
class _PropertyColorInputState extends State<PropertyColorInput> {
|
||||
late final _text = TextEditingController(text: widget.value);
|
||||
final _focus = FocusNode();
|
||||
bool _dirty = false;
|
||||
String? _error;
|
||||
late final _operations = OperationScope<Object>(widget.editContext);
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focus.addListener(_blur);
|
||||
}
|
||||
|
||||
void _blur() {
|
||||
if (!_focus.hasFocus) _submit();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (!_dirty || !widget.enabled) return;
|
||||
final value = _text.text.replaceFirst('#', '');
|
||||
if (!RegExp(r'^[A-Fa-f0-9]{6}$').hasMatch(value)) {
|
||||
setState(() => _error = context.l10n.invalidNumber);
|
||||
return;
|
||||
}
|
||||
_dirty = false;
|
||||
final guard = _operations.begin();
|
||||
final ok = await widget.submit(int.parse(value, radix: 16));
|
||||
if (!mounted || !guard()) return;
|
||||
setState(() {
|
||||
_error = ok ? null : context.l10n.notApplied;
|
||||
_text.text = widget.value;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant PropertyColorInput oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_operations.bind(widget.editContext);
|
||||
if (oldWidget.editContext != widget.editContext || !widget.enabled) {
|
||||
_dirty = false;
|
||||
_error = null;
|
||||
}
|
||||
if (!_dirty && _text.text != widget.value) _text.text = widget.value;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_operations.dispose();
|
||||
_focus.removeListener(_blur);
|
||||
_focus.dispose();
|
||||
_text.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AppTextField(
|
||||
controller: _text,
|
||||
focusNode: _focus,
|
||||
enabled: widget.enabled,
|
||||
errorText: _error,
|
||||
leading: AppPopover(
|
||||
width: 240,
|
||||
borderRadius: 8,
|
||||
padding: const EdgeInsets.all(16),
|
||||
backgroundColor: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
builder: (context, toggle) => IconButton(
|
||||
key: const ValueKey('effect-color-swatch'),
|
||||
tooltip: context.l10n.color,
|
||||
onPressed: widget.enabled ? toggle : null,
|
||||
padding: EdgeInsets.zero,
|
||||
icon: Container(
|
||||
width: 14,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.color,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: PropertyColorPicker(
|
||||
color: widget.color,
|
||||
enabled: widget.enabled,
|
||||
submit: (color) => widget.submit(color.toARGB32() & 0xFFFFFF),
|
||||
),
|
||||
),
|
||||
onChanged: (_) {
|
||||
_operations.invalidate();
|
||||
_dirty = true;
|
||||
if (_error != null) setState(() => _error = null);
|
||||
},
|
||||
onEditingComplete: () {},
|
||||
onSubmitted: (_) => _submit(),
|
||||
);
|
||||
}
|
||||
|
||||
@Preview(name: 'Property color input', size: Size(240, 80))
|
||||
Widget propertyColorInputPreview() {
|
||||
var rgb = 0x3366FF;
|
||||
return MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: StatefulBuilder(
|
||||
builder: (context, update) => PropertyColorInput(
|
||||
value: rgb.toRadixString(16).padLeft(6, '0').toUpperCase(),
|
||||
color: Color(0xFF000000 | rgb),
|
||||
enabled: true,
|
||||
editContext: 'preview',
|
||||
submit: (value) async {
|
||||
update(() => rgb = value);
|
||||
return true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
class PropertyColorPicker extends StatefulWidget {
|
||||
const PropertyColorPicker({
|
||||
super.key,
|
||||
required this.color,
|
||||
required this.enabled,
|
||||
required this.submit,
|
||||
});
|
||||
final Color color;
|
||||
final bool enabled;
|
||||
final Future<bool> Function(Color) submit;
|
||||
|
||||
@override
|
||||
State<PropertyColorPicker> createState() => _PropertyColorPickerState();
|
||||
}
|
||||
|
||||
class _PropertyColorPickerState extends State<PropertyColorPicker> {
|
||||
late HSVColor _color = HSVColor.fromColor(widget.color);
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant PropertyColorPicker oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.color != oldWidget.color) {
|
||||
_color = HSVColor.fromColor(widget.color);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _commit() async {
|
||||
if (!widget.enabled) return;
|
||||
await widget.submit(_color.toColor());
|
||||
if (mounted) setState(() => _color = HSVColor.fromColor(widget.color));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.color,
|
||||
style: AppTheme.propertySectionTitleStyle(context),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
height: 140,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = constraints.maxWidth;
|
||||
const height = 140.0;
|
||||
void update(Offset position) {
|
||||
if (!widget.enabled) return;
|
||||
setState(
|
||||
() => _color = _color
|
||||
.withSaturation((position.dx / width).clamp(0, 1))
|
||||
.withValue((1 - position.dy / height).clamp(0, 1)),
|
||||
);
|
||||
}
|
||||
|
||||
return Semantics(
|
||||
label: context.l10n.color,
|
||||
child: GestureDetector(
|
||||
key: const ValueKey('effect-color-plane'),
|
||||
onTapDown: (details) => update(details.localPosition),
|
||||
onTapUp: (_) => _commit(),
|
||||
onPanStart: (details) => update(details.localPosition),
|
||||
onPanUpdate: (details) => update(details.localPosition),
|
||||
onPanEnd: (_) => _commit(),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
child: SizedBox(
|
||||
height: height,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: ColoredBox(
|
||||
color: HSVColor.fromAHSV(
|
||||
1,
|
||||
_color.hue,
|
||||
1,
|
||||
1,
|
||||
).toColor(),
|
||||
),
|
||||
),
|
||||
const Positioned.fill(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.white, Color(0x00FFFFFF)],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Positioned.fill(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Colors.transparent, Colors.black],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: (_color.saturation * width - 6).clamp(
|
||||
0,
|
||||
width - 12,
|
||||
),
|
||||
top: ((1 - _color.value) * height - 6).clamp(
|
||||
0,
|
||||
height - 12,
|
||||
),
|
||||
child: Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 2),
|
||||
boxShadow: const [
|
||||
BoxShadow(color: Colors.black54, blurRadius: 2),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
height: 24,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
gradient: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFFFF0000),
|
||||
Color(0xFFFFFF00),
|
||||
Color(0xFF00FF00),
|
||||
Color(0xFF00FFFF),
|
||||
Color(0xFF0000FF),
|
||||
Color(0xFFFF00FF),
|
||||
Color(0xFFFF0000),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SliderTheme(
|
||||
data: SliderTheme.of(context).copyWith(
|
||||
padding: EdgeInsets.zero,
|
||||
trackHeight: 12,
|
||||
activeTrackColor: Colors.transparent,
|
||||
inactiveTrackColor: Colors.transparent,
|
||||
thumbColor: Colors.white,
|
||||
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 6),
|
||||
overlayShape: SliderComponentShape.noOverlay,
|
||||
),
|
||||
child: Slider(
|
||||
key: const ValueKey('effect-color-hue'),
|
||||
min: 0,
|
||||
max: 360,
|
||||
value: _color.hue,
|
||||
onChanged: widget.enabled
|
||||
? (hue) => setState(() => _color = _color.withHue(hue))
|
||||
: null,
|
||||
onChangeEnd: (_) => _commit(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@Preview(name: 'Property color picker', size: Size(240, 240))
|
||||
Widget propertyColorPickerPreview() {
|
||||
var color = const Color(0xFF3366FF);
|
||||
return MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: StatefulBuilder(
|
||||
builder: (context, update) => PropertyColorPicker(
|
||||
color: color,
|
||||
enabled: true,
|
||||
submit: (value) async {
|
||||
update(() => color = value);
|
||||
return true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/preview.dart';
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
|
||||
import '../../workspace/timeline_session.dart';
|
||||
|
||||
/// Shared pause, stale-context checks and diagnostics for inspector edits.
|
||||
class PropertyEditBoundary {
|
||||
PropertyEditBoundary(this.session, this.sequence, this.clip);
|
||||
|
||||
final EditorTimelineSession session;
|
||||
final SequenceId sequence;
|
||||
final ElementId clip;
|
||||
bool _disposed = false;
|
||||
bool _busy = false;
|
||||
|
||||
void dispose() => _disposed = true;
|
||||
|
||||
bool canRun(PreviewController? preview) =>
|
||||
!_disposed &&
|
||||
!_busy &&
|
||||
session.activeSequenceId == sequence &&
|
||||
preview?.transforms.hasPending != true;
|
||||
|
||||
Future<bool> run(
|
||||
PreviewController? preview,
|
||||
FutureOr<bool> Function(PropertyEditContext) action, {
|
||||
required String operation,
|
||||
bool Function()? isCurrent,
|
||||
bool seek = false,
|
||||
void Function()? started,
|
||||
}) async {
|
||||
if (!canRun(preview) || isCurrent?.call() == false) return false;
|
||||
final view = session.view(sequence);
|
||||
final target = PropertyEditContext._(
|
||||
tick: view.playheadTick,
|
||||
version: view.version.kernelVersion,
|
||||
current: () =>
|
||||
!_disposed &&
|
||||
isCurrent?.call() != false &&
|
||||
session.activeSequenceId == sequence &&
|
||||
preview?.transforms.hasPending != true,
|
||||
view: view,
|
||||
);
|
||||
_busy = true;
|
||||
try {
|
||||
started?.call();
|
||||
await preview?.pauseForCanvasInteraction();
|
||||
if (!target.isCurrent) return false;
|
||||
if (seek) return await action(target);
|
||||
return await session.runEditAsync(
|
||||
operation,
|
||||
sequence,
|
||||
() async => action(target),
|
||||
context: {
|
||||
'clipIds': [clip.value],
|
||||
'entryPoint': 'property',
|
||||
'playheadTick': target.tick,
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
_busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyEditContext {
|
||||
PropertyEditContext._({
|
||||
required this.tick,
|
||||
required this._version,
|
||||
required this._current,
|
||||
required this._view,
|
||||
});
|
||||
|
||||
final int tick;
|
||||
final TimelineVersion _version;
|
||||
final bool Function() _current;
|
||||
final TimelineViewController _view;
|
||||
|
||||
/// Async operations check this again immediately before publication.
|
||||
bool get isCurrent =>
|
||||
_current() &&
|
||||
_view.playheadTick == tick &&
|
||||
identical(_view.version.kernelVersion, _version);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/preview.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'property_edit_boundary.dart';
|
||||
import '../../workspace/timeline_session.dart';
|
||||
|
||||
/// Owns the asynchronous edit boundary for one selected clip.
|
||||
class PropertyEditController extends ChangeNotifier {
|
||||
PropertyEditController({
|
||||
required this.session,
|
||||
required this.sequence,
|
||||
required this.clip,
|
||||
required this.projectId,
|
||||
required this.timelineId,
|
||||
required this.operation,
|
||||
});
|
||||
final EditorTimelineSession session;
|
||||
final SequenceId sequence;
|
||||
final ElementId clip;
|
||||
final String projectId, timelineId, operation;
|
||||
Object get identity => (session, sequence, clip, projectId, timelineId);
|
||||
late final _boundary = PropertyEditBoundary(session, sequence, clip);
|
||||
bool _disposed = false;
|
||||
bool _saving = false;
|
||||
bool _failed = false;
|
||||
bool get saving => _saving;
|
||||
bool get failed => _failed;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_boundary.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
ClipParameterAnimation? get animation {
|
||||
final view = session.view(sequence);
|
||||
final query = view.version.kernelVersion.query();
|
||||
final handle = query.elementById(clip);
|
||||
return handle == null
|
||||
? null
|
||||
: ClipParameterAnimation(
|
||||
query.element(handle),
|
||||
view.playheadTick - query.absoluteStart(handle),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> run(
|
||||
PreviewController? preview,
|
||||
void Function(EditorCommandService, int) action, {
|
||||
bool seek = false,
|
||||
}) async {
|
||||
if (_disposed || saving || !_boundary.canRun(preview)) return false;
|
||||
try {
|
||||
return await _boundary.run(
|
||||
preview,
|
||||
(target) {
|
||||
action(session.commands, target.tick);
|
||||
return true;
|
||||
},
|
||||
operation: operation,
|
||||
seek: seek,
|
||||
started: () {
|
||||
_saving = true;
|
||||
_failed = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (_) {
|
||||
if (!_disposed) {
|
||||
_failed = true;
|
||||
notifyListeners();
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
if (!_disposed) {
|
||||
_saving = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
typedef PropertyKeyframeEdit = Future<bool> Function(
|
||||
List<String> ids, {
|
||||
KeyframeAction? action,
|
||||
ParameterInterpolation? interpolation,
|
||||
});
|
||||
|
||||
/// Keyframe controls share channel state and intent callbacks across property fields.
|
||||
class PropertyKeyframeControls {
|
||||
const PropertyKeyframeControls({
|
||||
required this.stack,
|
||||
required this.enabled,
|
||||
required this.onEdit,
|
||||
required this.onSeek,
|
||||
});
|
||||
final ClipParameterAnimation stack;
|
||||
final bool enabled;
|
||||
final PropertyKeyframeEdit onEdit;
|
||||
final Future<bool> Function(int localTick) onSeek;
|
||||
|
||||
Widget button(
|
||||
BuildContext context,
|
||||
List<String> ids,
|
||||
String label,
|
||||
String id,
|
||||
) => IconButton(
|
||||
key: ValueKey(id),
|
||||
tooltip: context.l10n.toggleKeyframe(
|
||||
stack.keyed(ids) ? context.l10n.delete : context.l10n.addKeyframeAction,
|
||||
label,
|
||||
),
|
||||
isSelected: stack.keyed(ids),
|
||||
color: stack.animated(ids) ? Theme.of(context).colorScheme.primary : null,
|
||||
icon: Transform.rotate(
|
||||
angle: math.pi / 4,
|
||||
child: Icon(
|
||||
stack.keyed(ids) ? AppIcons.squareFilled : AppIcons.square,
|
||||
size: 12,
|
||||
),
|
||||
),
|
||||
onPressed: enabled && ids.isNotEmpty ? () => onEdit(ids) : null,
|
||||
);
|
||||
|
||||
Widget menu(BuildContext context, List<String> ids, String label, String id) {
|
||||
final offsets = stack.keyOffsets(ids);
|
||||
final currentTick = stack.localTick;
|
||||
final previous = offsets.where((t) => t < currentTick).lastOrNull;
|
||||
final next = offsets.where((t) => t > currentTick).firstOrNull;
|
||||
return AppDropdownMenu(
|
||||
enabled: enabled,
|
||||
builder: (context, toggle, focus) => IconButton(
|
||||
key: ValueKey('$id-menu'),
|
||||
focusNode: focus,
|
||||
tooltip: context.l10n.keyframeSettings(label),
|
||||
onPressed: enabled ? toggle : null,
|
||||
icon: const Icon(AppIcons.more, size: 16),
|
||||
),
|
||||
items: [
|
||||
AppMenuItem(
|
||||
closeAncestors: false,
|
||||
label: context.l10n.previousKeyframe(label),
|
||||
onPressed: previous == null ? null : () => onSeek(previous),
|
||||
),
|
||||
AppMenuItem(
|
||||
closeAncestors: false,
|
||||
label: context.l10n.nextKeyframe(label),
|
||||
onPressed: next == null ? null : () => onSeek(next),
|
||||
),
|
||||
for (final (mode, text) in [
|
||||
(ParameterInterpolation.linear, context.l10n.linear),
|
||||
(ParameterInterpolation.hold, context.l10n.hold),
|
||||
(ParameterInterpolation.easeIn, context.l10n.easeIn),
|
||||
(ParameterInterpolation.easeOut, context.l10n.easeOut),
|
||||
(ParameterInterpolation.easeInOut, context.l10n.easeInOut),
|
||||
])
|
||||
AppMenuItem(
|
||||
closeAncestors: false,
|
||||
label: text,
|
||||
onPressed: stack.keyed(ids)
|
||||
? () => onEdit(
|
||||
ids,
|
||||
action: KeyframeAction.set,
|
||||
interpolation: mode,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
AppMenuItem(
|
||||
closeAncestors: false,
|
||||
label: context.l10n.removeAllKeyframes,
|
||||
onPressed: stack.animated(ids)
|
||||
? () => onEdit(ids, action: KeyframeAction.clear)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_ui/icons.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/widget_previews.dart';
|
||||
|
||||
class PropertyLayerRow extends StatefulWidget {
|
||||
const PropertyLayerRow({
|
||||
super.key,
|
||||
required this.id,
|
||||
required this.prefix,
|
||||
required this.index,
|
||||
required this.enabled,
|
||||
required this.visible,
|
||||
required this.label,
|
||||
required this.tooltip,
|
||||
required this.onVisibility,
|
||||
required this.onRemove,
|
||||
required this.menuItems,
|
||||
required this.editor,
|
||||
this.leading,
|
||||
this.editorLabel,
|
||||
});
|
||||
final String id, prefix, label, tooltip;
|
||||
final int index;
|
||||
final bool enabled, visible;
|
||||
final VoidCallback onVisibility, onRemove;
|
||||
final List<AppMenuItem> menuItems;
|
||||
final Widget editor;
|
||||
final Widget? leading;
|
||||
final String? editorLabel;
|
||||
|
||||
@override
|
||||
State<PropertyLayerRow> createState() => _PropertyLayerRowState();
|
||||
}
|
||||
|
||||
class _PropertyLayerRowState extends State<PropertyLayerRow> {
|
||||
final _menu = MenuController();
|
||||
final _focus = FocusNode();
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
return MenuAnchor(
|
||||
controller: _menu,
|
||||
childFocusNode: _focus,
|
||||
clipBehavior: Clip.none,
|
||||
// Place the editor beside the inspector, as in Figma's effects panel.
|
||||
alignmentOffset: Offset(
|
||||
-240 - 8 - AppTheme.propertySectionPadding(context).left,
|
||||
0,
|
||||
),
|
||||
style: const MenuStyle(
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
padding: WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
backgroundColor: WidgetStatePropertyAll(Colors.transparent),
|
||||
surfaceTintColor: WidgetStatePropertyAll(Colors.transparent),
|
||||
elevation: WidgetStatePropertyAll(0),
|
||||
side: WidgetStatePropertyAll(BorderSide.none),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
),
|
||||
),
|
||||
onOpen: () => setState(() {}),
|
||||
onClose: () => setState(() {}),
|
||||
menuChildren: [
|
||||
SizedBox(
|
||||
key: ValueKey('${widget.prefix}-editor-${widget.id}'),
|
||||
width: 240,
|
||||
child: Material(
|
||||
color: colors.surfaceContainerLow,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
elevation: 8,
|
||||
shadowColor: colors.shadow.withValues(alpha: .25),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(color: colors.outlineVariant),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: (_, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
_menu.close();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.editorLabel ?? widget.label,
|
||||
style: AppTheme.propertySectionTitleStyle(
|
||||
context,
|
||||
),
|
||||
),
|
||||
),
|
||||
AppDropdownMenu(
|
||||
builder: (context, toggle, focus) => IconButton(
|
||||
focusNode: focus,
|
||||
tooltip: widget.tooltip,
|
||||
icon: const Icon(AppIcons.more, size: 16),
|
||||
onPressed: toggle,
|
||||
),
|
||||
items: widget.menuItems,
|
||||
),
|
||||
IconButton(
|
||||
key: ValueKey(
|
||||
'${widget.prefix}-editor-close-${widget.id}',
|
||||
),
|
||||
tooltip: context.l10n.close,
|
||||
icon: const Icon(AppIcons.close, size: 16),
|
||||
onPressed: _menu.close,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Divider(height: 1, color: theme.dividerColor),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: (MediaQuery.sizeOf(context).height - 120)
|
||||
.clamp(80, 600),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
primary: false,
|
||||
child: widget.editor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
builder: (context, controller, child) => MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: SizedBox(
|
||||
height: AppInspectorMetrics.row,
|
||||
child: Row(
|
||||
children: [
|
||||
ReorderableDragStartListener(
|
||||
key: ValueKey('${widget.prefix}-drag-${widget.id}'),
|
||||
index: widget.index,
|
||||
enabled: widget.enabled,
|
||||
child: MouseRegion(
|
||||
cursor: widget.enabled
|
||||
? SystemMouseCursors.grab
|
||||
: SystemMouseCursors.basic,
|
||||
child: SizedBox(
|
||||
width: 16,
|
||||
child: Icon(
|
||||
AppIcons.dragHandle,
|
||||
size: 12,
|
||||
color: _hovered
|
||||
? colors.onSurfaceVariant
|
||||
: Colors.transparent,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextButton(
|
||||
key: ValueKey('${widget.prefix}-settings-${widget.id}'),
|
||||
focusNode: _focus,
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
minimumSize: const Size(0, 24),
|
||||
maximumSize: const Size(double.infinity, 24),
|
||||
backgroundColor: controller.isOpen
|
||||
? theme.inputDecorationTheme.fillColor
|
||||
: null,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
foregroundColor: widget.visible
|
||||
? colors.onSurface
|
||||
: colors.onSurfaceVariant,
|
||||
textStyle: AppTheme.inputTextStyle(context),
|
||||
),
|
||||
onPressed: () => controller.isOpen
|
||||
? controller.close()
|
||||
: controller.open(),
|
||||
child: Row(
|
||||
children: [
|
||||
widget.leading ??
|
||||
const Icon(PhosphorIconsRegular.sun, size: 16),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: ValueKey('${widget.prefix}-enabled-${widget.id}'),
|
||||
tooltip: widget.visible
|
||||
? context.l10n.disable
|
||||
: context.l10n.enable,
|
||||
icon: Icon(
|
||||
widget.visible
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
size: 16,
|
||||
),
|
||||
onPressed: widget.enabled ? widget.onVisibility : null,
|
||||
),
|
||||
IconButton(
|
||||
key: ValueKey('${widget.prefix}-remove-${widget.id}'),
|
||||
tooltip: context.l10n.delete,
|
||||
icon: const Icon(AppIcons.remove, size: 16),
|
||||
onPressed: widget.enabled ? widget.onRemove : null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name: 'Effect row / desktop', size: Size(560, 480))
|
||||
Widget effectRowPreview() => MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
child: ReorderableListView(
|
||||
shrinkWrap: true,
|
||||
onReorderItem: (_, _) {},
|
||||
buildDefaultDragHandles: false,
|
||||
children: [
|
||||
PropertyLayerRow(
|
||||
key: const ValueKey('preview-effect'),
|
||||
id: 'preview',
|
||||
prefix: 'effect',
|
||||
index: 0,
|
||||
enabled: true,
|
||||
visible: true,
|
||||
label: 'Drop shadow',
|
||||
tooltip: 'Effects',
|
||||
onVisibility: () {},
|
||||
onRemove: () {},
|
||||
menuItems: const [],
|
||||
editor: const Text('X 0 Y 4 Blur 8'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,136 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'property_layer_row.dart';
|
||||
|
||||
class StrokeList extends StatelessWidget {
|
||||
const StrokeList({
|
||||
super.key,
|
||||
required this.stack,
|
||||
required this.enabled,
|
||||
required this.keyframes,
|
||||
required this.onAdd,
|
||||
required this.onReorder,
|
||||
required this.onToggle,
|
||||
required this.onRemove,
|
||||
required this.editorBuilder,
|
||||
this.error,
|
||||
});
|
||||
final ClipStrokeStack stack;
|
||||
final bool enabled;
|
||||
final PropertyKeyframeControls keyframes;
|
||||
final VoidCallback onAdd;
|
||||
final void Function(List<String>) onReorder;
|
||||
final void Function(ClipStrokeLayer) onToggle, onRemove;
|
||||
final Widget Function(ClipStrokeLayer) editorBuilder;
|
||||
final String? error;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final layers = stack.layers;
|
||||
return AppPropertySection(
|
||||
bottomSpacing: layers.isEmpty ? 0 : null,
|
||||
child: AppPropertyGroup(
|
||||
label: context.l10n.strokes,
|
||||
padChild: false,
|
||||
actions: [
|
||||
keyframes.button(
|
||||
context,
|
||||
stack.parameterIds,
|
||||
context.l10n.strokes,
|
||||
'strokes-key',
|
||||
),
|
||||
IconButton(
|
||||
key: const ValueKey('stroke-add'),
|
||||
tooltip: context.l10n.addStroke,
|
||||
onPressed: enabled && stack.canAdd ? onAdd : null,
|
||||
icon: const Icon(AppIcons.add, size: 16),
|
||||
),
|
||||
],
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ReorderableListView(
|
||||
shrinkWrap: true,
|
||||
primary: false,
|
||||
padding: EdgeInsets.zero,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
buildDefaultDragHandles: false,
|
||||
onReorderItem: (from, to) {
|
||||
if (!enabled) return;
|
||||
final order = layers.map((l) => l.id).toList();
|
||||
order.insert(to, order.removeAt(from));
|
||||
onReorder(order);
|
||||
},
|
||||
children: [
|
||||
for (var i = 0; i < layers.length; i++)
|
||||
PropertyLayerRow(
|
||||
key: ValueKey('stroke-layer-${layers[i].id}'),
|
||||
id: layers[i].id,
|
||||
prefix: 'stroke',
|
||||
index: i,
|
||||
enabled: enabled,
|
||||
visible: layers[i].enabled,
|
||||
label:
|
||||
'${layers[i].values['width']!.toStringAsFixed(layers[i].values['width']! % 1 == 0 ? 0 : 1)} · ${(layers[i].values['opacity']! * 100).round()}%',
|
||||
editorLabel: context.l10n.stroke,
|
||||
leading: Container(
|
||||
width: 16,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: Color.from(
|
||||
alpha: layers[i].values['opacity']!,
|
||||
red: layers[i].values['color.r']!,
|
||||
green: layers[i].values['color.g']!,
|
||||
blue: layers[i].values['color.b']!,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
tooltip: context.l10n.strokes,
|
||||
onVisibility: () => onToggle(layers[i]),
|
||||
onRemove: () => onRemove(layers[i]),
|
||||
menuItems: [
|
||||
for (final (delta, label) in [
|
||||
(-1, context.l10n.effectMoveUp),
|
||||
(1, context.l10n.effectMoveDown),
|
||||
])
|
||||
AppMenuItem(
|
||||
label: label,
|
||||
closeAncestors: false,
|
||||
onPressed:
|
||||
!enabled ||
|
||||
i + delta < 0 ||
|
||||
i + delta >= layers.length
|
||||
? null
|
||||
: () {
|
||||
final order = layers
|
||||
.map((l) => l.id)
|
||||
.toList();
|
||||
order.insert(i + delta, order.removeAt(i));
|
||||
onReorder(order);
|
||||
},
|
||||
),
|
||||
],
|
||||
editor: editorBuilder(layers[i]),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (error != null)
|
||||
Text(
|
||||
error!,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'property_color_input.dart';
|
||||
import 'property_number_input.dart';
|
||||
|
||||
class StrokeParameterEditor extends StatelessWidget {
|
||||
const StrokeParameterEditor({
|
||||
super.key,
|
||||
required this.layer,
|
||||
required this.stack,
|
||||
required this.enabled,
|
||||
required this.editContext,
|
||||
required this.keyframes,
|
||||
required this.onChange,
|
||||
});
|
||||
final ClipStrokeLayer layer;
|
||||
final ClipStrokeStack stack;
|
||||
final bool enabled;
|
||||
final Object editContext;
|
||||
final PropertyKeyframeControls keyframes;
|
||||
final Future<bool> Function(Map<String, double>) onChange;
|
||||
|
||||
String _fieldLabel(BuildContext context, String field) => switch (field) {
|
||||
'width' => context.l10n.strokeWidth,
|
||||
'opacity' => context.l10n.shadowOpacity,
|
||||
'dashLength' => context.l10n.strokeDashLength,
|
||||
'dashGap' => context.l10n.strokeDashGap,
|
||||
_ => field,
|
||||
};
|
||||
Widget _number(BuildContext context, String field) {
|
||||
final label = _fieldLabel(context, field);
|
||||
final structural = StrokeParameterTarget.structural.contains(field);
|
||||
final percentage = {
|
||||
'opacity',
|
||||
'density',
|
||||
'lightIntensity',
|
||||
'splay',
|
||||
}.contains(field);
|
||||
final factor = percentage ? 100.0 : 1.0;
|
||||
final definition = StrokeParameterTarget.definition(field);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PropertyNumberInput(
|
||||
key: ValueKey('stroke-${layer.id}-$field'),
|
||||
label: label,
|
||||
value: layer.values[field]! * factor,
|
||||
unit: percentage ? '%' : null,
|
||||
enabled: enabled && layer.enabled,
|
||||
readOnly: false,
|
||||
scrubbing: false,
|
||||
editContext: (editContext, layer.id),
|
||||
onScrubUpdate: (_) {},
|
||||
onScrubEnd: () {},
|
||||
onScrubCancel: () {},
|
||||
submit: (v) => !definition.accepts(v / factor)
|
||||
? Future.value(false)
|
||||
: onChange({field: v / factor}),
|
||||
),
|
||||
),
|
||||
if (!structural) ...[
|
||||
keyframes.button(
|
||||
context,
|
||||
[layer.target(field)],
|
||||
label,
|
||||
'stroke-${layer.id}-$field-key',
|
||||
),
|
||||
keyframes.menu(
|
||||
context,
|
||||
[layer.target(field)],
|
||||
label,
|
||||
'stroke-${layer.id}-$field',
|
||||
),
|
||||
] else
|
||||
const SizedBox(width: 48),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _color(BuildContext context, String prefix, String label) {
|
||||
final fields = ['${prefix}r', '${prefix}g', '${prefix}b'];
|
||||
final values = fields.map((f) => layer.values[f]!).toList();
|
||||
final hex = values
|
||||
.map((v) => (v * 255).round().toRadixString(16).padLeft(2, '0'))
|
||||
.join()
|
||||
.toUpperCase();
|
||||
final ids = fields.map(layer.target).toList();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(label, style: AppTheme.propertyLabelStyle(context)),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PropertyColorInput(
|
||||
key: ValueKey('stroke-${layer.id}-$prefix'),
|
||||
value: hex,
|
||||
color: Color.from(
|
||||
alpha: 1,
|
||||
red: values[0],
|
||||
green: values[1],
|
||||
blue: values[2],
|
||||
),
|
||||
enabled: enabled && layer.enabled,
|
||||
editContext: (editContext, layer.id),
|
||||
submit: (rgb) => onChange({
|
||||
fields[0]: ((rgb >> 16) & 255) / 255,
|
||||
fields[1]: ((rgb >> 8) & 255) / 255,
|
||||
fields[2]: (rgb & 255) / 255,
|
||||
}),
|
||||
),
|
||||
),
|
||||
keyframes.button(
|
||||
context,
|
||||
ids,
|
||||
label,
|
||||
'stroke-${layer.id}-$prefix-key',
|
||||
),
|
||||
keyframes.menu(context, ids, label, 'stroke-${layer.id}-$prefix'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _mode(BuildContext context, String field, List<String> labels) =>
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: SizedBox(
|
||||
height: 24,
|
||||
child: AppSelect<int>(
|
||||
closeAncestors: false,
|
||||
key: ValueKey('stroke-${layer.id}-$field'),
|
||||
value: layer.values[field]!.round(),
|
||||
label: field == 'alignment'
|
||||
? context.l10n.alignment
|
||||
: context.l10n.strokeStyle,
|
||||
emptyLabel: context.l10n.strokes,
|
||||
options: [
|
||||
for (var i = 0; i < labels.length; i++)
|
||||
AppSelectOption(i, labels[i]),
|
||||
],
|
||||
onChanged: enabled && layer.enabled
|
||||
? (v) => onChange({field: v.toDouble()})
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_color(context, 'color.', context.l10n.color),
|
||||
_number(context, 'opacity'),
|
||||
_number(context, 'width'),
|
||||
_mode(context, 'alignment', [
|
||||
context.l10n.strokeInside,
|
||||
context.l10n.strokeCenter,
|
||||
context.l10n.strokeOutside,
|
||||
]),
|
||||
_mode(context, 'style', [
|
||||
context.l10n.strokeSolid,
|
||||
context.l10n.strokeDashed,
|
||||
]),
|
||||
if (layer.style == ClipStrokeStyle.dashed) ...[
|
||||
_number(context, 'dashLength'),
|
||||
_number(context, 'dashGap'),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@Preview(name: 'Stroke editor / desktop', size: Size(240, 360))
|
||||
Widget strokeEditorPreview() {
|
||||
final stack = ClipStrokeStack(
|
||||
ElementRecord(
|
||||
id: ElementId('preview'),
|
||||
structure: ElementStructure.content,
|
||||
duration: 1,
|
||||
sourceStart: 0,
|
||||
sourceDuration: 1,
|
||||
enabled: true,
|
||||
),
|
||||
0,
|
||||
);
|
||||
return MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: StrokeParameterEditor(
|
||||
layer: const ClipStrokeLayer(id: 'preview', values: strokeDefaults),
|
||||
stack: stack,
|
||||
enabled: true,
|
||||
editContext: 'preview',
|
||||
keyframes: PropertyKeyframeControls(
|
||||
stack: stack,
|
||||
enabled: true,
|
||||
onEdit: (ids, {action, interpolation}) async => true,
|
||||
onSeek: (_) async => true,
|
||||
),
|
||||
onChange: (_) async => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../workspace/timeline_session.dart';
|
||||
import '../preview/preview_panel.dart';
|
||||
import 'property_edit_controller.dart';
|
||||
import 'property_keyframe_controls.dart';
|
||||
import 'stroke_list.dart';
|
||||
import 'stroke_parameter_editor.dart';
|
||||
|
||||
class StrokeProperties extends ConsumerStatefulWidget {
|
||||
const StrokeProperties({
|
||||
super.key,
|
||||
required this.projectId,
|
||||
required this.timelineId,
|
||||
required this.session,
|
||||
required this.sequence,
|
||||
required this.clip,
|
||||
});
|
||||
final String projectId, timelineId;
|
||||
final EditorTimelineSession session;
|
||||
final SequenceId sequence;
|
||||
final ElementId clip;
|
||||
|
||||
@override
|
||||
ConsumerState<StrokeProperties> createState() => _StrokePropertiesState();
|
||||
}
|
||||
|
||||
class _StrokePropertiesState extends ConsumerState<StrokeProperties> {
|
||||
Object get _identity => (
|
||||
widget.session,
|
||||
widget.sequence,
|
||||
widget.clip,
|
||||
widget.projectId,
|
||||
widget.timelineId,
|
||||
);
|
||||
PropertyEditController _createController() => PropertyEditController(
|
||||
session: widget.session,
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
projectId: widget.projectId,
|
||||
timelineId: widget.timelineId,
|
||||
operation: 'editStroke',
|
||||
);
|
||||
late PropertyEditController _controller = _createController();
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant StrokeProperties oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (_controller.identity != _identity) {
|
||||
_controller.dispose();
|
||||
_controller = _createController();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final preview = ref
|
||||
.watch(editorPreviewProvider(widget.projectId, widget.timelineId))
|
||||
.asData
|
||||
?.value;
|
||||
final controller = _controller;
|
||||
final view = widget.session.view(widget.sequence);
|
||||
return ListenableBuilder(
|
||||
listenable: Listenable.merge([controller, view]),
|
||||
builder: (context, _) {
|
||||
final animation = controller.animation;
|
||||
if (animation == null) return const SizedBox.shrink();
|
||||
final stack = ClipStrokeStack(animation.record, animation.localTick);
|
||||
final enabled =
|
||||
!controller.saving &&
|
||||
stack.containsPlayhead &&
|
||||
preview?.transforms.hasPending != true;
|
||||
Future<bool> edit(void Function(EditorCommandService, int) action) =>
|
||||
controller.run(preview, action);
|
||||
final keyframes = PropertyKeyframeControls(
|
||||
stack: stack,
|
||||
enabled: enabled,
|
||||
onEdit: (ids, {action, interpolation}) => edit(
|
||||
(c, t) => c.editKeyframeChannel(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
parameterIds: ids,
|
||||
action: action,
|
||||
interpolation: interpolation,
|
||||
),
|
||||
),
|
||||
onSeek: (offset) => controller.run(
|
||||
preview,
|
||||
(_, tick) => view.seekTo(tick - stack.localTick + offset),
|
||||
seek: true,
|
||||
),
|
||||
);
|
||||
return StrokeList(
|
||||
stack: stack,
|
||||
enabled: enabled,
|
||||
keyframes: keyframes,
|
||||
error: controller.failed ? context.l10n.updateStrokeFailed : null,
|
||||
onAdd: () => edit(
|
||||
(c, t) => c.addStroke(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
strokeId: c.newStrokeId(),
|
||||
),
|
||||
),
|
||||
onReorder: (order) => edit(
|
||||
(c, t) => c.configureStrokes(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
order: order,
|
||||
),
|
||||
),
|
||||
onToggle: (layer) => edit(
|
||||
(c, t) => c.configureStrokes(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
strokeId: layer.id,
|
||||
enabled: !layer.enabled,
|
||||
),
|
||||
),
|
||||
onRemove: (layer) => edit(
|
||||
(c, t) => c.removeStroke(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
strokeId: layer.id,
|
||||
),
|
||||
),
|
||||
editorBuilder: (layer) => StrokeParameterEditor(
|
||||
layer: layer,
|
||||
stack: stack,
|
||||
enabled: enabled,
|
||||
editContext: controller.identity,
|
||||
keyframes: keyframes,
|
||||
onChange: (values) => edit(
|
||||
(c, t) => c.setStroke(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip,
|
||||
tick: t,
|
||||
strokeId: layer.id,
|
||||
values: values,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user