Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
228 lines
7.4 KiB
Dart
228 lines
7.4 KiB
Dart
import 'package:cutdex/l10n/l10n.dart';
|
||
import 'package:cutdex_core/editor.dart';
|
||
import 'package:cutdex_native_flutter/contracts.dart';
|
||
import 'package:cutdex_core/timeline/model.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
|
||
import 'package:cutdex_ui/widgets.dart';
|
||
import 'package:cutdex_ui/theme.dart';
|
||
|
||
import '../../workspace/timeline_session.dart';
|
||
|
||
class ProjectSettingsDialog extends StatefulWidget {
|
||
const ProjectSettingsDialog({super.key, required this.session});
|
||
final EditorTimelineSession session;
|
||
|
||
@override
|
||
State<ProjectSettingsDialog> createState() => _ProjectSettingsDialogState();
|
||
}
|
||
|
||
class _ProjectSettingsDialogState extends State<ProjectSettingsDialog> {
|
||
static final _rates = <String, RationalTime>{
|
||
'23.976': RationalTime(1001, 24000),
|
||
'24': RationalTime(1, 24),
|
||
'25': RationalTime(1, 25),
|
||
'29.97': RationalTime(1001, 30000),
|
||
'30': RationalTime(1, 30),
|
||
'50': RationalTime(1, 50),
|
||
'59.94': RationalTime(1001, 60000),
|
||
'60': RationalTime(1, 60),
|
||
'120': RationalTime(1, 120),
|
||
};
|
||
static const _sizes = <String, (int, int)>{
|
||
'1920 × 1080': (1920, 1080),
|
||
'3840 × 2160': (3840, 2160),
|
||
'1280 × 720': (1280, 720),
|
||
'1080 × 1920': (1080, 1920),
|
||
'1080 × 1080': (1080, 1080),
|
||
};
|
||
final _form = GlobalKey<FormState>();
|
||
late final TextEditingController _width;
|
||
late final TextEditingController _height;
|
||
late RationalTime _frame;
|
||
late RenderColorSpace _color;
|
||
String? _preset;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
final canvas = widget.session.canvas;
|
||
_width = TextEditingController(text: canvas.width.toStringAsFixed(0));
|
||
_height = TextEditingController(text: canvas.height.toStringAsFixed(0));
|
||
_frame = widget.session.activeSequenceId == null
|
||
? TimelineFormat.fps24.frameDuration
|
||
: widget.session.persistence
|
||
.timeline(widget.session.activeSequenceId!)
|
||
.format
|
||
.frameDuration;
|
||
_color = widget.session.projectOutputColorSpace;
|
||
_preset = _sizes.entries
|
||
.where((e) => e.value.$1 == canvas.width && e.value.$2 == canvas.height)
|
||
.firstOrNull
|
||
?.key;
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
_width.dispose();
|
||
_height.dispose();
|
||
super.dispose();
|
||
}
|
||
|
||
void _save() {
|
||
if (!_form.currentState!.validate()) return;
|
||
widget.session.setProjectProperties(
|
||
sequence: widget.session.activeSequenceId,
|
||
canvas: ProjectCanvas(
|
||
double.parse(_width.text),
|
||
double.parse(_height.text),
|
||
),
|
||
frameDuration: _frame,
|
||
colorSpace: _color,
|
||
);
|
||
Navigator.of(context).pop();
|
||
}
|
||
|
||
Widget _dimension(
|
||
TextEditingController controller,
|
||
String label,
|
||
String key,
|
||
) => FormField<String>(
|
||
initialValue: controller.text,
|
||
validator: (_) {
|
||
final value = int.tryParse(controller.text);
|
||
return value == null || !ProjectCanvas.isValidDimension(value.toDouble())
|
||
? context.l10n.projectResolutionInvalid
|
||
: null;
|
||
},
|
||
builder: (field) => AppTextField(
|
||
key: ValueKey(key),
|
||
controller: controller,
|
||
label: label,
|
||
errorText: field.errorText,
|
||
keyboardType: TextInputType.number,
|
||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||
onChanged: (value) {
|
||
field.didChange(value);
|
||
setState(() => _preset = null);
|
||
},
|
||
),
|
||
);
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final l10n = context.l10n;
|
||
final rates = {..._rates};
|
||
if (!rates.values.contains(_frame)) {
|
||
rates[(_frame.denominator / _frame.numerator).toStringAsFixed(3)] =
|
||
_frame;
|
||
}
|
||
return AppDialog(
|
||
title: l10n.projectSettings,
|
||
width: 440,
|
||
description: l10n.projectSettingsDescription,
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.of(context).pop(),
|
||
child: Text(l10n.cancel),
|
||
),
|
||
FilledButton(
|
||
key: const ValueKey('project-settings-save'),
|
||
onPressed: _save,
|
||
child: Text(l10n.save),
|
||
),
|
||
],
|
||
child: SingleChildScrollView(
|
||
child: Form(
|
||
key: _form,
|
||
child: AppFieldGroup(
|
||
children: [
|
||
AppField(
|
||
label: l10n.canvasSize,
|
||
child: AppFieldGroup(
|
||
children: [
|
||
AppSelect<String>(
|
||
emptyLabel: context.l10n.noMatchingOptions,
|
||
key: const ValueKey('project-resolution'),
|
||
value: _preset ?? 'custom',
|
||
label: l10n.canvasSize,
|
||
options: [
|
||
for (final name in _sizes.keys)
|
||
AppSelectOption(name, name),
|
||
AppSelectOption('custom', l10n.custom),
|
||
],
|
||
onChanged: (value) => setState(() {
|
||
_preset = value == 'custom' ? null : value;
|
||
final size = _sizes[value];
|
||
if (size != null) {
|
||
_width.text = '${size.$1}';
|
||
_height.text = '${size.$2}';
|
||
}
|
||
}),
|
||
),
|
||
Row(
|
||
spacing: AppSpacing.compact,
|
||
children: [
|
||
Expanded(
|
||
child: _dimension(
|
||
_width,
|
||
l10n.projectWidth,
|
||
'project-width',
|
||
),
|
||
),
|
||
Expanded(
|
||
child: _dimension(
|
||
_height,
|
||
l10n.projectHeight,
|
||
'project-height',
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
),
|
||
AppField(
|
||
label: l10n.frameRate,
|
||
child: AppSelect<RationalTime>(
|
||
emptyLabel: context.l10n.noMatchingOptions,
|
||
key: const ValueKey('project-frame-rate'),
|
||
value: _frame,
|
||
label: l10n.frameRate,
|
||
options: [
|
||
for (final rate in rates.entries)
|
||
AppSelectOption(rate.value, '${rate.key} fps'),
|
||
],
|
||
onChanged: (value) => setState(() => _frame = value),
|
||
),
|
||
),
|
||
AppField(
|
||
label: l10n.projectOutputColorSpace,
|
||
child: AppSelect<RenderColorSpace>(
|
||
emptyLabel: context.l10n.noMatchingOptions,
|
||
key: const ValueKey('project-color-space'),
|
||
value: _color,
|
||
label: l10n.projectOutputColorSpace,
|
||
options: const [
|
||
AppSelectOption(RenderColorSpace.rec709, 'SDR · Rec.709'),
|
||
AppSelectOption(
|
||
RenderColorSpace.rec2020HLG,
|
||
'HDR · Rec.2020 HLG',
|
||
),
|
||
AppSelectOption(
|
||
RenderColorSpace.rec2020PQ,
|
||
'HDR · Rec.2020 PQ',
|
||
),
|
||
],
|
||
onChanged: (value) => setState(() => _color = value),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|