Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

What's new 2.0.0: the redesigned crop overlay and the Theme page as they are now

KnifeLemon8047c9b679c4
diff --git a/src/Filee.App/Assets/WhatsNew/2.0.0/crop.webp b/src/Filee.App/Assets/WhatsNew/2.0.0/crop.webp
index c0509667..280a38de 100644
Binary files a/src/Filee.App/Assets/WhatsNew/2.0.0/crop.webp and b/src/Filee.App/Assets/WhatsNew/2.0.0/crop.webp differ
diff --git a/src/Filee.App/Assets/WhatsNew/2.0.0/slides.json b/src/Filee.App/Assets/WhatsNew/2.0.0/slides.json
index dd4f662f..21a36c1a 100644
--- a/src/Filee.App/Assets/WhatsNew/2.0.0/slides.json
+++ b/src/Filee.App/Assets/WhatsNew/2.0.0/slides.json
@@ -4,8 +4,8 @@
{ "id": "browser", "media": "browser.webp", "poster": 52, "title": "whats_new.2_0_0.browser.title", "text": "whats_new.2_0_0.browser.text" },
{ "id": "flip", "media": "flip.webp", "poster": 75, "title": "whats_new.2_0_0.flip.title", "text": "whats_new.2_0_0.flip.text" },
{ "id": "formats", "media": "formats.webp", "title": "whats_new.2_0_0.formats.title", "text": "whats_new.2_0_0.formats.text" },
- { "id": "crop", "media": "crop.webp", "title": "whats_new.2_0_0.crop.title", "text": "whats_new.2_0_0.crop.text" },
- { "id": "theme", "media": "theme.webp", "title": "whats_new.2_0_0.theme.title", "text": "whats_new.2_0_0.theme.text" },
+ { "id": "crop", "media": "crop.webp", "poster": 72, "title": "whats_new.2_0_0.crop.title", "text": "whats_new.2_0_0.crop.text" },
+ { "id": "theme", "media": "theme.webp", "poster": 28, "title": "whats_new.2_0_0.theme.title", "text": "whats_new.2_0_0.theme.text" },
{ "id": "languages", "media": "languages.webp", "title": "whats_new.2_0_0.languages.title", "text": "whats_new.2_0_0.languages.text" },
{ "id": "more", "media": "more.webp", "title": "whats_new.2_0_0.more.title", "text": "whats_new.2_0_0.more.text" }
]
diff --git a/src/Filee.App/Assets/WhatsNew/2.0.0/theme.webp b/src/Filee.App/Assets/WhatsNew/2.0.0/theme.webp
index a63e158c..7a326b69 100644
Binary files a/src/Filee.App/Assets/WhatsNew/2.0.0/theme.webp and b/src/Filee.App/Assets/WhatsNew/2.0.0/theme.webp differ
diff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.json
index 106fa958..1e40f8e5 100644
--- a/src/Filee.App/Assets/i18n/ar.json
+++ b/src/Filee.App/Assets/i18n/ar.json
@@ -879,9 +879,9 @@
"whats_new.2_0_0.formats.title": "صيغ إضافية",
"whats_new.2_0_0.formats.text": "صفحات الويب المحفوظة بصيغة MHTML، والفواتير الإلكترونية بصيغة OFD، وخرائط Shapefile وGeoJSON وKML وGPX، وصور JPEG XR، ونماذج FBX، وقوالب POTM.",
"whats_new.2_0_0.crop.title": "اقتصاص الصور قبل تحويلها",
- "whats_new.2_0_0.crop.text": "يفتح خيار الاقتصاص صورك واحدةً تلو الأخرى. اسحب إطار الاقتصاص واختر نسبة الأبعاد لحفظ الجزء المحدد فقط.",
+ "whats_new.2_0_0.crop.text": "يفتح خيار الاقتصاص صورك واحدةً تلو الأخرى. اسحب الإطار واختر نسبة الأبعاد من القرص، ثم اضغط «اقتصاص والتالي».",
"whats_new.2_0_0.theme.title": "مظهر أنعم وبألوانك المفضلة",
- "whats_new.2_0_0.theme.text": "يتيح إعداد النعومة تدوير زوايا شرائح القائمة الدائرية، ويمكن تخصيص ألوان Filee بالكامل باستخدام ملف theme.json.",
+ "whats_new.2_0_0.theme.text": "اختر أي لون مميّز، وغيّر استدارة الزوايا، واجعل القائمة الدائرية شبه شفافة.",
"whats_new.2_0_0.languages.title": "لغات إضافية في Filee",
"whats_new.2_0_0.languages.text": "تتوفر الآن الإسبانية والهندية واليابانية والروسية والعربية، إلى جانب الإنجليزية والكورية والصينية والبولندية.",
"whats_new.2_0_0.more.title": "والمزيد من التحسينات",
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 89c97d52..11040a67 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -900,9 +900,9 @@
"whats_new.2_0_0.formats.title": "More formats",
"whats_new.2_0_0.formats.text": "Web archives (MHTML), OFD e-invoices, Shapefile, GeoJSON, KML and GPX maps, JPEG XR, FBX models and POTM templates.",
"whats_new.2_0_0.crop.title": "Crop before you convert",
- "whats_new.2_0_0.crop.text": "The Crop slice opens your pictures one by one. Drag the frame, pick a ratio, and only that part is saved.",
+ "whats_new.2_0_0.crop.text": "The Crop slice opens your pictures one by one. Drag the frame, pick a ratio on the dial, then Crop & Next.",
"whats_new.2_0_0.theme.title": "Softer, and in your colours",
- "whats_new.2_0_0.theme.text": "The donut's slices round off with Softness, and a theme.json file can recolour all of Filee.",
+ "whats_new.2_0_0.theme.text": "Pick any accent colour, round things off with Softness, and make the donut see-through.",
"whats_new.2_0_0.languages.title": "Filee speaks more languages",
"whats_new.2_0_0.languages.text": "Spanish, Hindi, Japanese, Russian and Arabic join English, Korean, Chinese and Polish.",
"whats_new.2_0_0.more.title": "And a little more",
diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.json
index 8d9a057b..6a34ed36 100644
--- a/src/Filee.App/Assets/i18n/es.json
+++ b/src/Filee.App/Assets/i18n/es.json
@@ -880,9 +880,9 @@
"whats_new.2_0_0.formats.title": "Más formatos",
"whats_new.2_0_0.formats.text": "Archivos web (MHTML), facturas electrónicas OFD, mapas Shapefile, GeoJSON, KML y GPX, JPEG XR, modelos FBX y plantillas POTM.",
"whats_new.2_0_0.crop.title": "Recorta antes de convertir",
- "whats_new.2_0_0.crop.text": "La porción Recortar abre tus imágenes una a una. Arrastra el marco, elige una proporción y solo se guarda esa parte.",
+ "whats_new.2_0_0.crop.text": "La porción Recortar abre tus imágenes una a una. Arrastra el marco, elige una proporción en el dial y pulsa «Recortar y seguir».",
"whats_new.2_0_0.theme.title": "Más suave y con tus colores",
- "whats_new.2_0_0.theme.text": "Las porciones del menú circular siguen el Redondeo, y un archivo theme.json puede cambiar los colores de todo Filee.",
+ "whats_new.2_0_0.theme.text": "Elige cualquier color de acento, suaviza las formas con Redondeo y haz translúcido el menú circular.",
"whats_new.2_0_0.languages.title": "Filee habla más idiomas",
"whats_new.2_0_0.languages.text": "El español, el hindi, el japonés, el ruso y el árabe se suman al inglés, el coreano, el chino y el polaco.",
"whats_new.2_0_0.more.title": "Y un poco más",
diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.json
index e219eb65..970c96a3 100644
--- a/src/Filee.App/Assets/i18n/hi.json
+++ b/src/Filee.App/Assets/i18n/hi.json
@@ -880,9 +880,9 @@
"whats_new.2_0_0.formats.title": "और फ़ॉर्मैट",
"whats_new.2_0_0.formats.text": "वेब आर्काइव (MHTML), OFD ई-इनवॉइस, Shapefile, GeoJSON, KML और GPX नक्शे, JPEG XR, FBX मॉडल और POTM टेम्पलेट।",
"whats_new.2_0_0.crop.title": "बदलने से पहले क्रॉप करें",
- "whats_new.2_0_0.crop.text": "क्रॉप स्लाइस आपके चित्र एक-एक करके खोलता है। फ़्रेम खींचें, अनुपात चुनें, और सिर्फ़ वही हिस्सा सहेजा जाता है।",
+ "whats_new.2_0_0.crop.text": "क्रॉप स्लाइस आपके चित्र एक-एक करके खोलता है। फ़्रेम खींचें, डायल पर अनुपात चुनें, फिर “क्रॉप करके अगला” दबाएँ।",
"whats_new.2_0_0.theme.title": "ज़्यादा कोमल, आपके रंगों में",
- "whats_new.2_0_0.theme.text": "डोनट की स्लाइसें कोमलता के साथ गोल होती हैं, और एक theme.json फ़ाइल पूरे Filee के रंग बदल सकती है।",
+ "whats_new.2_0_0.theme.text": "कोई भी एक्सेंट रंग चुनें, कोमलता से आकार गोल करें, और डोनट को अर्ध-पारदर्शी बनाएँ।",
"whats_new.2_0_0.languages.title": "Filee अब और भाषाएँ बोलता है",
"whats_new.2_0_0.languages.text": "अंग्रेज़ी, कोरियाई, चीनी और पोलिश के साथ अब स्पैनिश, हिन्दी, जापानी, रूसी और अरबी भी।",
"whats_new.2_0_0.more.title": "और भी थोड़ा",
diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.json
index d5c6b067..4f3fb355 100644
--- a/src/Filee.App/Assets/i18n/ja.json
+++ b/src/Filee.App/Assets/i18n/ja.json
@@ -880,9 +880,9 @@
"whats_new.2_0_0.formats.title": "対応形式が増えました",
"whats_new.2_0_0.formats.text": "Web アーカイブ (MHTML)、OFD 電子請求書、Shapefile・GeoJSON・KML・GPX の地図、JPEG XR、FBX モデル、POTM テンプレート。",
"whats_new.2_0_0.crop.title": "変換の前にトリミング",
- "whats_new.2_0_0.crop.text": "「トリミング」で画像を 1 枚ずつ開けます。枠をドラッグして比率を選ぶと、その部分だけを保存します。",
+ "whats_new.2_0_0.crop.text": "「トリミング」で画像を 1 枚ずつ開けます。枠をドラッグし、ダイヤルで比率を選んで「トリミングして次へ」。",
"whats_new.2_0_0.theme.title": "やわらかく、好きな色に",
- "whats_new.2_0_0.theme.text": "ドーナツの各スライスが「角の丸み」に合わせて丸くなり、theme.json ファイルで Filee 全体の色を変えられます。",
+ "whats_new.2_0_0.theme.text": "好きなアクセントカラーを選び、「角の丸み」で丸くして、ドーナツメニューを半透明にできます。",
"whats_new.2_0_0.languages.title": "対応言語が増えました",
"whats_new.2_0_0.languages.text": "英語、韓国語、中国語、ポーランド語に、スペイン語、ヒンディー語、日本語、ロシア語、アラビア語が加わりました。",
"whats_new.2_0_0.more.title": "ほかにも",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index d3e05b1a..29a47af8 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -900,9 +900,9 @@
"whats_new.2_0_0.formats.title": "더 많은 형식",
"whats_new.2_0_0.formats.text": "웹 보관 파일(MHTML), OFD 전자 세금계산서, Shapefile·GeoJSON·KML·GPX 지도, JPEG XR, FBX 모델, POTM 서식 파일.",
"whats_new.2_0_0.crop.title": "변환하기 전에 자르기",
- "whats_new.2_0_0.crop.text": "자르기 조각을 고르면 그림이 한 장씩 열려요. 틀을 끌고 비율을 고르면 그 부분만 저장해요.",
+ "whats_new.2_0_0.crop.text": "자르기 조각을 고르면 그림이 한 장씩 열려요. 틀을 끌고 다이얼에서 비율을 고른 뒤 “자르고 다음으로”를 누르세요.",
"whats_new.2_0_0.theme.title": "더 말랑하게, 내 색으로",
- "whats_new.2_0_0.theme.text": "원형 툴바 조각이 말랑함에 맞춰 둥글어지고, theme.json 파일로 Filee 전체의 색을 바꿀 수 있어요.",
+ "whats_new.2_0_0.theme.text": "원하는 강조색을 고르고, 말랑함으로 둥글리고, 원형 툴바를 반투명하게 만들 수 있어요.",
"whats_new.2_0_0.languages.title": "더 많은 언어",
"whats_new.2_0_0.languages.text": "영어, 한국어, 중국어, 폴란드어에 스페인어, 힌디어, 일본어, 러시아어, 아랍어가 더해졌어요.",
"whats_new.2_0_0.more.title": "그리고 조금 더",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index 82559afb..7f66d0c0 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -900,9 +900,9 @@
"whats_new.2_0_0.formats.title": "Więcej formatów",
"whats_new.2_0_0.formats.text": "Archiwa stron (MHTML), e-faktury OFD, mapy Shapefile, GeoJSON, KML i GPX, JPEG XR, modele FBX i szablony POTM.",
"whats_new.2_0_0.crop.title": "Kadrowanie przed konwersją",
- "whats_new.2_0_0.crop.text": "Wycinek Kadruj otwiera obrazy po kolei. Przeciągnij ramkę, wybierz proporcje, a zapisana zostanie tylko ta część.",
+ "whats_new.2_0_0.crop.text": "Wycinek Kadruj otwiera obrazy po kolei. Przeciągnij ramkę, wybierz proporcje na tarczy i kliknij „Kadruj i dalej”.",
"whats_new.2_0_0.theme.title": "Łagodniej i w Twoich kolorach",
- "whats_new.2_0_0.theme.text": "Wycinki pierścienia zaokrąglają się zgodnie z Zaokrągleniem, a plik theme.json może zmienić kolory całego Filee.",
+ "whats_new.2_0_0.theme.text": "Wybierz dowolny kolor akcentu, zaokrąglij kształty suwakiem Zaokrąglenie i zrób pierścień półprzezroczystym.",
"whats_new.2_0_0.languages.title": "Filee mówi w większej liczbie języków",
"whats_new.2_0_0.languages.text": "Do angielskiego, koreańskiego, chińskiego i polskiego dołączają hiszpański, hindi, japoński, rosyjski i arabski.",
"whats_new.2_0_0.more.title": "I jeszcze trochę",
diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.json
index ab823de2..c1ef2d79 100644
--- a/src/Filee.App/Assets/i18n/ru.json
+++ b/src/Filee.App/Assets/i18n/ru.json
@@ -900,9 +900,9 @@
"whats_new.2_0_0.formats.title": "Больше форматов",
"whats_new.2_0_0.formats.text": "Веб-архивы (MHTML), электронные счета OFD, карты Shapefile, GeoJSON, KML и GPX, JPEG XR, модели FBX и шаблоны POTM.",
"whats_new.2_0_0.crop.title": "Обрезка перед конвертацией",
- "whats_new.2_0_0.crop.text": "Сектор «Обрезать» открывает картинки по одной. Перетащите рамку, выберите пропорции, и сохранится только эта часть.",
+ "whats_new.2_0_0.crop.text": "Сектор «Обрезать» открывает картинки по одной. Перетащите рамку, выберите пропорции на круге и нажмите «Обрезать и дальше».",
"whats_new.2_0_0.theme.title": "Мягче и в ваших цветах",
- "whats_new.2_0_0.theme.text": "Секторы кругового меню скругляются вместе с настройкой «Скругление», а файл theme.json может перекрасить весь Filee.",
+ "whats_new.2_0_0.theme.text": "Выберите любой акцентный цвет, скруглите формы настройкой «Скругление» и сделайте круговое меню полупрозрачным.",
"whats_new.2_0_0.languages.title": "Filee говорит на большем числе языков",
"whats_new.2_0_0.languages.text": "К английскому, корейскому, китайскому и польскому добавились испанский, хинди, японский, русский и арабский.",
"whats_new.2_0_0.more.title": "И ещё немного",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index fdc7be5c..73683ee4 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -900,9 +900,9 @@
"whats_new.2_0_0.formats.title": "更多格式",
"whats_new.2_0_0.formats.text": "网页存档 (MHTML)、OFD 电子发票、Shapefile、GeoJSON、KML 和 GPX 地图、JPEG XR、FBX 模型和 POTM 模板。",
"whats_new.2_0_0.crop.title": "转换前先裁剪",
- "whats_new.2_0_0.crop.text": "“裁剪”会逐张打开图片。拖动选框、选择比例,只保存选中的部分。",
+ "whats_new.2_0_0.crop.text": "“裁剪”会逐张打开图片。拖动选框,在转盘上选择比例,再点“裁剪并下一张”。",
"whats_new.2_0_0.theme.title": "更柔和,用你的颜色",
- "whats_new.2_0_0.theme.text": "环形工具栏的扇区会随“圆角”变圆,用 theme.json 文件还能更改整个 Filee 的颜色。",
+ "whats_new.2_0_0.theme.text": "任选强调色,用“圆角”让外形更圆润,还能让环形工具栏半透明。",
"whats_new.2_0_0.languages.title": "支持更多语言",
"whats_new.2_0_0.languages.text": "在英语、韩语、中文和波兰语之外,新增西班牙语、印地语、日语、俄语和阿拉伯语。",
"whats_new.2_0_0.more.title": "还有更多",
diff --git a/src/Filee.App/Controls/CropCanvas.cs b/src/Filee.App/Controls/CropCanvas.cs
index e77553d6..86cc920a 100644
--- a/src/Filee.App/Controls/CropCanvas.cs
+++ b/src/Filee.App/Controls/CropCanvas.cs
@@ -537,7 +537,13 @@ public sealed class CropCanvas : Control
// ───────────────────────── Motion ─────────────────────────
- private static long Now() => Stopwatch.GetTimestamp();
+ /// <summary>
+ /// The clock the animations read (<see cref="Stopwatch"/> ticks). The What's new clip steps it by hand, a frame at
+ /// a time, so a frame that takes long to capture doesn't jump the animations ahead.
+ /// </summary>
+ internal static Func<long> Clock { get; set; } = Stopwatch.GetTimestamp;
+
+ private static long Now() => Clock();
private static double EaseOutCubic(double t) => 1 - Math.Pow(1 - Math.Clamp(t, 0, 1), 3);
diff --git a/tests/Filee.App.Tests/WhatsNewMedia.cs b/tests/Filee.App.Tests/WhatsNewMedia.cs
index ebec6b9a..6291ad3d 100644
--- a/tests/Filee.App.Tests/WhatsNewMedia.cs
+++ b/tests/Filee.App.Tests/WhatsNewMedia.cs
@@ -7,11 +7,14 @@
// tests/Filee.App.Tests/bin/Debug/net10.0/Filee.App.Tests.exe -method "Filee.App.Tests.WhatsNewMedia.*" -explicit only
//
// Each clip is drawn on a 768 × 432 canvas (16:9, shown at 496 × 279 in the window, sharp up to 150 % scaling) in the
-// light theme. The first frame of each clip is what reduced motion shows, so every clip starts on a meaningful picture.
+// light theme. The first frame of each clip is what reduced motion shows, so every clip starts on a meaningful picture;
+// a clip that marks a better one writes it into slides.json as the slide's "poster".
+using System.Text.RegularExpressions;
using Avalonia.Controls;
using Avalonia.Headless;
using Avalonia.Headless.XUnit;
+using Avalonia.Input;
using Avalonia.Threading;
using Avalonia.VisualTree;
using Filee.App.Controls;
@@ -19,11 +22,13 @@ using Filee.App.Services;
using Filee.App.ViewModels;
using Filee.App.ViewModels.Pages;
using Filee.App.Views;
+using Filee.App.Views.Pages;
using Filee.Core.Localization;
using Filee.Core.Presets;
using Filee.Core.Settings;
using ImageMagick;
using ImageMagick.Drawing;
+using static Avalonia.VisualExtensions;
namespace Filee.App.Tests;
@@ -75,7 +80,7 @@ public class WhatsNewMedia
Write(folder, "flip.webp", DonutFlip, onRequestOnly: true);
Write(folder, "formats.webp", FormatDonuts);
Write(folder, "crop.webp", Crop);
- Write(folder, "theme.webp", Softness);
+ Write(folder, "theme.webp", () => Theme("2.0.0"));
Write(folder, "languages.webp", () => Languages("2.0.0"));
Write(folder, "more.webp", () => More("2.0.0"));
}
@@ -225,60 +230,106 @@ public class WhatsNewMedia
return clip;
}
- /// <summary>The crop overlay: the frame closes in on part of a picture, then the square ratio is picked.</summary>
+ /// <summary>
+ /// The crop overlay (#307) with three pictures: a corner of the frame is dragged in (the thirds grid fades in, the
+ /// size chip follows), the aspect dial opens and 1:1 is picked, then "Crop &amp; next" opens the second picture and
+ /// the strip marks the first done. Real pointer input; the canvas's own animations run on the clip's clock
+ /// (<see cref="CropCanvas.Clock"/>) and the transitions of the dial, its slices and the strip are played here as the
+ /// window's styles time them (the render timer, which runs them in the app, keeps wall-clock time).
+ /// </summary>
private static Clip Crop()
{
- var clip = new Clip();
+ var clip = new Clip { Quality = 72 };
var folder = Directory.CreateTempSubdirectory("filee-whatsnew-crop-").FullName;
+ var clock = System.Diagnostics.Stopwatch.GetTimestamp();
+ CropCanvas.Clock = () => clock;
+ CropOverlayWindow? window = null;
try
{
- var picture = Path.Combine(folder, "harbour.jpg");
- DrawLandscape(picture);
+ var files = new[] { "harbour.jpg", "meadow.jpg", "dunes.jpg" }.Select((name, i) =>
+ {
+ var path = Path.Combine(folder, name);
+ DrawLandscape(path, i);
+ return path;
+ }).ToList();
var preset = BuiltInData.CreatePresets().Single(p => p.Id == "tool-crop");
- var vm = new CropOverlayViewModel([picture], preset, AppHost.Get<ILocalizer>(), AppHost.Get<UserDataStore>());
- var window = new CropOverlayWindow
+ var vm = new CropOverlayViewModel(files, preset, AppHost.Get<ILocalizer>(), AppHost.Get<UserDataStore>());
+ window = new CropOverlayWindow
{
DataContext = vm,
- Width = 960,
- Height = 540,
+ Width = 889, // 16:9 at the window's least height
+ Height = 500,
Background = new Avalonia.Media.SolidColorBrush(Avalonia.Media.Color.Parse(Page)),
};
window.Show();
WaitFor(() => vm.PreviewImage is not null && !vm.IsBusy);
- window.SettleForCapture(); // each frame of the clip is drawn where it ends
+ // The styles' transitions off (played below); the canvas animates again, on the stepped clock.
+ window.SettleForCapture();
+ window.CropCanvas.PlayAnimations = true;
Pump();
- var canvas = window.GetVisualDescendants().OfType<CropCanvas>().Single();
- try
- {
- var from = new Avalonia.Rect(0.05, 0.05, 0.9, 0.9);
- var to = new Avalonia.Rect(0.42, 0.18, 0.44, 0.62);
- // Frame 0: the frame already on the part to keep.
- canvas.NormalizedCropRect = to;
- Pump();
- clip.Add(Capture(window), 1200);
- canvas.NormalizedCropRect = from;
- Pump();
- clip.Add(Capture(window), 600);
- const int steps = 18;
- for (var i = 1; i <= steps; i++)
- {
- var t = Ease(i / (double)steps);
- canvas.NormalizedCropRect = Lerp(from, to, t);
- Pump();
- clip.Add(Capture(window), 40);
- }
- clip.Add(Capture(window), 700);
- vm.SetAspect("1:1");
- Pump();
- clip.Add(Capture(window), 1600);
- }
- finally
- {
- window.Close();
- }
+
+ // 20 frames a second keep the clip within the slides' budget.
+ var scene = new Scene(window, clip) { FrameLength = 1 / 20.0 };
+ scene.Steps.Add(dt => clock += (long)(System.Diagnostics.Stopwatch.Frequency * dt));
+ PlayCropTransitions(window, vm, scene);
+
+ var canvas = window.CropCanvas;
+ var origin = (Avalonia.Vector)canvas.TranslatePoint(default, window)!.Value;
+ var image = canvas.CalculateImageBounds().Translate(origin);
+ Avalonia.Rect Frame() => canvas.GetScreenCropRect(canvas.CalculateImageBounds()).Translate(origin);
+ Avalonia.Point Middle(Control control) =>
+ control.TranslatePoint(new Avalonia.Point(control.Bounds.Width / 2, control.Bounds.Height / 2), window)!.Value;
+ Avalonia.Point OnPicture(double x, double y) => new(image.X + image.Width * x, image.Y + image.Height * y);
+
+ // Frame 0: the first picture, the frame around all of it.
+ scene.Place(new Avalonia.Point(image.Right + 70, image.Center.Y + 30));
+ scene.Hold(0.9);
+
+ // A corner in: the handle grows under the pointer, the grid shows while it is held.
+ scene.MoveTo(Frame().TopLeft, 0.55);
+ scene.Hold(0.25);
+ scene.Press();
+ scene.Hold(0.2);
+ scene.MoveTo(OnPicture(0.22, 0.14), 0.9);
+ scene.Hold(0.15);
+ scene.Release();
+ scene.Hold(0.5);
+
+ // The aspect dial grows out of its button; 1:1.
+ var dialButton = window.GetVisualDescendants().OfType<Button>().Single(b => b.Name == "DialButton");
+ scene.MoveTo(Middle(dialButton), 0.55);
+ scene.Hold(0.15);
+ scene.Click();
+ scene.Hold(0.45);
+ var dial = window.AspectDial;
+ var square = dial.Segments.ToList().FindIndex(s => s.Mode == "1:1");
+ var onSquare = dial.TranslatePoint(DonutGeometry.PointAt(new Avalonia.Point(dial.Bounds.Width / 2, dial.Bounds.Height / 2),
+ dial.OuterRadius - 14, DonutGeometry.MidAngle(square, dial.Segments.Count())), window)!.Value; // beside its label
+ scene.MoveTo(onSquare, 0.5);
+ scene.Hold(0.35);
+ // Shown with reduced motion: the dial open, the pointer on 1:1.
+ clip.MarkPoster();
+ scene.Click();
+ Assert.Equal("1:1", vm.SelectedAspect);
+ scene.Hold(1.1);
+
+ // Crop & next: the second picture settles in, the strip marks the first one done.
+ var primary = window.GetVisualDescendants().OfType<Button>().Single(b => b.Name == "PrimaryButton");
+ scene.MoveTo(Middle(primary) + new Avalonia.Vector(-12, 2), 0.55);
+ scene.Hold(0.2);
+ scene.Press();
+ scene.Tick();
+ scene.Release();
+ WaitFor(() => vm.CurrentIndex == 1 && !vm.IsBusy && vm.PreviewImage is not null);
+ Assert.Equal(CropItemState.Done, vm.Queue[0].State);
+ scene.Hold(0.4);
+ scene.MoveTo(Middle(primary) + new Avalonia.Vector(150, -14), 0.4);
+ scene.Hold(1.2);
}
finally
{
+ window?.Close();
+ CropCanvas.Clock = System.Diagnostics.Stopwatch.GetTimestamp;
try
{
Directory.Delete(folder, recursive: true);
@@ -288,41 +339,159 @@ public class WhatsNewMedia
return clip;
}
- /// <summary>The donut rounding off as Softness goes up, then a few accent colours.</summary>
- private static Clip Softness()
+ /// <summary>
+ /// What CropOverlayWindow.axaml's transitions do, on the clip's clock: the dial grows out of its button (opacity
+ /// 0.16 s, scale 0.55 → 1 in 0.34 s) and shrinks away, a slice under the pointer moves out (0.24 s), and the strip's
+ /// tiles grow and shrink as the current file changes (0.32 s).
+ /// </summary>
+ private static void PlayCropTransitions(CropOverlayWindow window, CropOverlayViewModel vm, Scene scene)
{
- var clip = new Clip();
+ var dial = window.AspectDial;
+ dial.Transitions = null;
+ var (opacity, scale) = (new Glide(0, 0.16, t => t), new Glide(0.55, 0.34, BackEaseOut));
+ var pops = dial.Segments.ToDictionary(s => s, _ => new Glide(0, 0.24, BackEaseOut));
+ foreach (var segment in pops.Keys)
+ segment.Transitions = null;
+ var tiles = new Dictionary<Border, (Glide Scale, Glide Opacity)>();
+ scene.Steps.Add(dt =>
+ {
+ var open = vm.IsAspectDialOpen;
+ dial.Opacity = opacity.Step(open ? 1 : 0, dt);
+ var s = scale.Step(open ? 1 : 0.55, dt);
+ dial.RenderTransform = new Avalonia.Media.ScaleTransform(s, s);
+ dial.IsVisible = open || dial.Opacity > 0.001;
+ foreach (var (segment, pop) in pops)
+ segment.Pop = pop.Step(segment.IsPointerOver ? 1 : 0, dt);
+
+ foreach (var tile in window.GetVisualDescendants().OfType<Border>().Where(b => b.Classes.Contains("tile")))
+ {
+ if (!tiles.TryGetValue(tile, out var glide))
+ tiles[tile] = glide = (new Glide(TileScale(tile), 0.32, BackEaseOut), new Glide(TileOpacity(tile), 0.2, t => t));
+ var size = glide.Scale.Step(TileScale(tile), dt);
+ tile.RenderTransform = new Avalonia.Media.ScaleTransform(size, size);
+ tile.Opacity = glide.Opacity.Step(TileOpacity(tile), dt);
+ }
+ });
+
+ static double TileScale(Border tile) => tile.Classes.Contains("current") ? 1.08 : 0.86;
+ static double TileOpacity(Border tile) =>
+ tile.Classes.Contains("current") ? 1 : tile.Classes.Contains("skipped") || tile.Classes.Contains("failed") ? 0.55 : 0.9;
+ }
+
+ /// <summary>
+ /// The Theme page: an accent swatch clicked (the whole window takes the colour), a colour picked on the spectrum of
+ /// the colour picker (#291), Softness rounding the preview donut, and the donut toolbar's opacity (#275) letting the
+ /// backdrop through. Swatch and spectrum get real pointer input; the sliders are moved through the page's settings
+ /// with the pointer on their thumbs.
+ /// </summary>
+ private static Clip Theme(string version)
+ {
+ // 15 frames a second at a lower quality: every change of colour redraws the whole window.
+ var clip = new Clip { Quality = 72 };
+ var store = AppHost.Get<UserDataStore>();
var theme = AppHost.Get<ThemeService>();
- var (window, vm) = OpenDonut([@"C:\photos\a.jpg", @"C:\photos\b.jpg"], clickMode: true);
+ var (themeBefore, opacityBefore) = (store.Settings.Theme, store.Settings.Donut.Opacity);
+ store.Settings.Theme = new ThemeSettings { ReduceMotion = false, Mode = ThemeMode.Light };
+ store.Settings.Donut.Opacity = 1;
+ theme.Apply(store.Settings.Theme, "en");
+ var vm = new MainWindowViewModel(AppHost.Services, AppHost.Get<ILocalizer>(), AppHost.Get<UpdateService>());
+ var window = new MainWindow { DataContext = vm, Width = 1080, Height = 608 };
try
{
- window.DonutControl.FinishAnimations();
- Highlight(window, vm, 2);
- // Frame 0: soft, default colours.
- theme.Apply(new ThemeSettings { ReduceMotion = false, Mode = ThemeMode.Light, CornerRadius = 28 }, "en");
+ vm.Navigate("theme");
+ window.Show();
Pump();
- clip.Add(Capture(window), 1000);
- const int steps = 14;
- for (var i = 0; i <= steps; i++)
- {
- theme.Apply(new ThemeSettings { ReduceMotion = false, Mode = ThemeMode.Light, CornerRadius = 28.0 * i / steps }, "en");
- Pump();
- clip.Add(Capture(window), i == 0 ? 500 : 60);
- }
- clip.Add(Capture(window), 500);
- foreach (var accent in new[] { "#1D9E75", "#D4537E", "#E8873A", "#7F77DD" })
+ var page = (ThemePageViewModel)vm.CurrentPage!;
+ var view = window.GetVisualDescendants().OfType<ThemePage>().Single();
+ var softness = view.GetVisualDescendants().OfType<Slider>().Single(s => s.Name != "DonutOpacitySlider");
+ var opacity = view.FindControl<Slider>("DonutOpacitySlider")!;
+
+ // Scrolled, if the window is too short for it, so the opacity card shows whole.
+ var scroller = window.GetVisualDescendants().OfType<ScrollViewer>().Single(s => s.Name == "PageScroller");
+ var card = opacity.FindAncestorOfType<Border>()!;
+ while (!card.Classes.Contains("card"))
+ card = card.FindAncestorOfType<Border>()!;
+ var cardBottom = card.TranslatePoint(new Avalonia.Point(0, card.Bounds.Height), scroller)!.Value.Y;
+ scroller.Offset = new Avalonia.Vector(0, Math.Max(0, cardBottom + 18 - scroller.Bounds.Height));
+ Pump();
+
+ var scene = new Scene(window, clip, version) { FrameLength = 1 / 15.0 };
+ (string?, double) applied = (store.Settings.Theme.Accent, store.Settings.Theme.CornerRadius);
+ // The app applies the theme when the settings change (App.ApplySettings); here the clip does.
+ scene.Steps.Add(_ =>
{
- theme.Apply(new ThemeSettings { ReduceMotion = false, Mode = ThemeMode.Light, CornerRadius = 28, Accent = accent }, "en");
- Pump();
- clip.Add(Capture(window), 800);
- }
+ var now = (store.Settings.Theme.Accent, store.Settings.Theme.CornerRadius);
+ if (now != applied)
+ {
+ applied = now;
+ theme.Apply(store.Settings.Theme, "en");
+ }
+ });
+ Avalonia.Point Middle(Control control) =>
+ control.TranslatePoint(new Avalonia.Point(control.Bounds.Width / 2, control.Bounds.Height / 2), window)!.Value;
+ Avalonia.Point Thumb(Slider slider) =>
+ Middle(slider.GetVisualDescendants().OfType<Avalonia.Controls.Primitives.Thumb>().Single()) + new Avalonia.Vector(3, 5);
+
+ // Frame 0: the page as it opens.
+ var preview = view.GetVisualDescendants().OfType<DonutMenu>().Single();
+ scene.Place(Middle(preview) + new Avalonia.Vector(150, 40));
+ scene.Hold(0.9);
+
+ // A swatch: the window takes its colour.
+ var swatches = view.FindControl<ListBox>("AccentSwatches")!;
+ scene.MoveTo(Middle(swatches.ContainerFromIndex(1)!) + new Avalonia.Vector(4, 6), 0.5);
+ scene.Click();
+ scene.Hold(0.8);
+
+ // Any colour: a click on the spectrum under the picker.
+ var picker = view.FindControl<ColorPicker>("AccentPicker")!;
+ var dropDown = picker.GetVisualDescendants().OfType<Button>().First();
+ scene.MoveTo(Middle(dropDown) + new Avalonia.Vector(4, 6), 0.45);
+ scene.Click();
+ scene.Hold(0.3);
+ var spectrum = ((Control)((Flyout)dropDown.Flyout!).Content!).GetVisualDescendants().OfType<Avalonia.Controls.Primitives.ColorSpectrum>().Single();
+ scene.MoveTo(spectrum.TranslatePoint(new Avalonia.Point(spectrum.Bounds.Width * 0.6, spectrum.Bounds.Height * 0.3), window)!.Value, 0.45);
+ scene.Click();
+ scene.Hold(0.8);
+ clip.MarkPoster();
+ // A click beside it closes it.
+ scene.MoveTo(Middle(preview) + new Avalonia.Vector(0, 205), 0.45);
+ scene.Click();
+ scene.Hold(0.2);
+
+ // Softness: the preview donut's slices round off and sharpen.
+ scene.MoveTo(Thumb(softness), 0.45);
+ scene.Grab(true);
+ foreach (var (to, seconds) in new[] { (28.0, 0.35), (2.0, 0.7), (20.0, 0.45) })
+ Slide(scene, page.CornerRadius, to, seconds, v => page.CornerRadius = Math.Round(v), () => Thumb(softness));
+ scene.Grab(false);
+ scene.Hold(0.3);
+
+ // The donut toolbar's opacity: the backdrop shows through the slices.
+ scene.MoveTo(Thumb(opacity), 0.4);
+ scene.Grab(true);
+ Slide(scene, page.DonutOpacity, 45, 0.8, v => page.DonutOpacity = Math.Round(v), () => Thumb(opacity));
+ scene.Grab(false);
+ scene.Hold(1.4);
}
finally
{
window.Close();
+ vm.Dispose();
+ (store.Settings.Theme, store.Settings.Donut.Opacity) = (themeBefore, opacityBefore);
theme.Apply(new ThemeSettings { ReduceMotion = false, Mode = ThemeMode.Light }, "en");
}
return clip;
+
+ static void Slide(Scene scene, double from, double to, double seconds, Action<double> set, Func<Avalonia.Point> thumb)
+ {
+ var frames = Math.Max(1, (int)Math.Round(seconds / scene.FrameLength));
+ for (var i = 1; i <= frames; i++)
+ {
+ set(from + (to - from) * Scene.EaseInOut(i / (double)frames));
+ scene.Tick(thumb);
+ }
+ }
}
/// <summary>The Home page in one language after another.</summary>
@@ -415,6 +584,117 @@ public class WhatsNewMedia
// ───────────────────────── Helpers ─────────────────────────
+ /// <summary>
+ /// A window played frame by frame with a pointer: real pointer input (hover, press, drag) and a picture of the
+ /// pointer on every frame. <see cref="Steps"/> run before each frame with its length, for what the clip times itself.
+ /// </summary>
+ private sealed class Scene(TopLevel window, Clip clip, string? version = null)
+ {
+ private bool _grabbed;
+
+ public Avalonia.Point Pointer { get; private set; }
+ public bool Pressed { get; private set; }
+ public List<Action<double>> Steps { get; } = [];
+
+ /// <summary>Seconds per frame.</summary>
+ public double FrameLength { get; init; } = Frame;
+
+ /// <summary>Puts the pointer somewhere at once (before the first frame).</summary>
+ public void Place(Avalonia.Point at)
+ {
+ // Tooltips open on a wall-clock delay: they would come and go at random in the clip.
+ ToolTip.SetServiceEnabled(window, false);
+ Pointer = at;
+ window.MouseMove(at);
+ }
+
+ /// <summary>One frame; <paramref name="pointer"/>, if given, places the pointer once the frame is laid out.</summary>
+ public void Tick(Func<Avalonia.Point>? pointer = null)
+ {
+ foreach (var step in Steps)
+ step(FrameLength);
+ // A few rounds are enough: the capture renders the frame itself.
+ for (var i = 0; i < 3; i++)
+ {
+ Dispatcher.UIThread.RunJobs();
+ AvaloniaHeadlessPlatform.ForceRenderTimerTick();
+ }
+ if (pointer is not null)
+ Pointer = pointer();
+ clip.Add(Capture(window, version, pointer: Pointer, pressed: Pressed || _grabbed), (int)Math.Round(FrameLength * 1000));
+ }
+
+ public void Hold(double seconds)
+ {
+ for (var i = (int)Math.Round(seconds / FrameLength); i > 0; i--)
+ Tick();
+ }
+
+ /// <summary>Moves the pointer to <paramref name="to"/> along a slight curve, easing in and out (a drag while pressed).</summary>
+ public void MoveTo(Avalonia.Point to, double seconds)
+ {
+ var from = Pointer;
+ var normal = new Avalonia.Vector(from.Y - to.Y, to.X - from.X) * 0.06;
+ var frames = Math.Max(1, (int)Math.Round(seconds / FrameLength));
+ for (var i = 1; i <= frames; i++)
+ {
+ var u = EaseInOut(i / (double)frames);
+ Pointer = new Avalonia.Point(from.X + (to.X - from.X) * u, from.Y + (to.Y - from.Y) * u) + normal * Math.Sin(Math.PI * u);
+ window.MouseMove(Pointer, Pressed ? RawInputModifiers.LeftMouseButton : RawInputModifiers.None);
+ Tick();
+ }
+ }
+
+ public void Press()
+ {
+ window.MouseDown(Pointer, MouseButton.Left);
+ Pressed = true;
+ }
+
+ public void Release()
+ {
+ window.MouseUp(Pointer, MouseButton.Left);
+ Pressed = false;
+ }
+
+ /// <summary>A click, the button shown pressed for a frame.</summary>
+ public void Click()
+ {
+ Press();
+ Tick();
+ Release();
+ }
+
+ /// <summary>The pointer drawn pressed without input: for a control the clip moves through its settings.</summary>
+ public void Grab(bool grabbed) => _grabbed = grabbed;
+
+ public static double EaseInOut(double t) => t < 0.5 ? 4 * t * t * t : 1 - Math.Pow(-2 * t + 2, 3) / 2;
+ }
+
+ /// <summary>A value easing to where the styles put it, as their transition would: a new target starts from where it is.</summary>
+ private sealed class Glide(double value, double seconds, Func<double, double> easing)
+ {
+ private double _from = value, _to = value;
+ private double _age = double.PositiveInfinity; // at rest
+ private double _value = value;
+
+ public double Step(double target, double dt)
+ {
+ if (target != _to)
+ (_from, _to, _age) = (_value, target, 0);
+ _age += dt;
+ _value = _from + (_to - _from) * easing(Math.Clamp(_age / seconds, 0, 1));
+ return _value;
+ }
+ }
+
+ /// <summary>Avalonia's BackEaseOut (the SoftEase of Filee's styles).</summary>
+ private static double BackEaseOut(double t)
+ {
+ var p = 1 - t;
+ return 1 - p * (p * p - Math.Sin(p * Math.PI));
+ }
+
private static (RadialWindow Window, RadialViewModel Vm) OpenDonut(IReadOnlyList<string> files, bool clickMode)
{
var vm = AppHost.Get<RadialViewModel>();
@@ -490,23 +770,19 @@ public class WhatsNewMedia
Assert.True(condition());
}
- private static double Ease(double t) => 1 - Math.Pow(1 - t, 3);
-
- private static Avalonia.Rect Lerp(Avalonia.Rect a, Avalonia.Rect b, double t) => new(
- a.X + (b.X - a.X) * t, a.Y + (b.Y - a.Y) * t, a.Width + (b.Width - a.Width) * t, a.Height + (b.Height - a.Height) * t);
-
/// <summary>
/// A rendered frame of <paramref name="window"/> centred on the page-coloured canvas, scaled down to fit. With
/// <paramref name="version"/>, the sidebar shows that version instead of the one being built (the clips are made
- /// before the version is bumped).
+ /// before the version is bumped). With <paramref name="pointer"/> (in the window), a mouse pointer is drawn there.
/// </summary>
- private static MagickImage Capture(TopLevel window, string? version = null, Avalonia.Rect? region = null)
+ private static MagickImage Capture(TopLevel window, string? version = null, Avalonia.Rect? region = null,
+ Avalonia.Point? pointer = null, bool pressed = false)
{
if (window is RadialWindow radial)
KeepFramesComing(radial.DonutControl);
try
{
- return CaptureCore(window, version, region);
+ return CaptureCore(window, version, region, pointer, pressed);
}
finally
{
@@ -526,7 +802,7 @@ public class WhatsNewMedia
/// </summary>
private static void KeepFramesComing(DonutMenu donut) => LastFrameTick.SetValue(donut, Environment.TickCount64);
- private static MagickImage CaptureCore(TopLevel window, string? version, Avalonia.Rect? region)
+ private static MagickImage CaptureCore(TopLevel window, string? version, Avalonia.Rect? region, Avalonia.Point? pointer, bool pressed)
{
if (version is not null)
{
@@ -555,12 +831,14 @@ public class WhatsNewMedia
}
png.Position = 0;
using var shot = new MagickImage(png);
+ var corner = new Avalonia.Point(0, 0);
if (region is { } r)
{
var x = (int)Math.Clamp(r.X, 0, Math.Max(0, shot.Width - r.Width));
var y = (int)Math.Clamp(r.Y, 0, Math.Max(0, shot.Height - r.Height));
shot.Crop(new MagickGeometry(x, y, (uint)r.Width, (uint)r.Height));
shot.ResetPage();
+ corner = new Avalonia.Point(x, y);
}
var canvas = new MagickImage(new MagickColor(Page), CanvasWidth, CanvasHeight);
var scale = Math.Min(1, Math.Min((double)CanvasWidth / shot.Width, (double)CanvasHeight / shot.Height));
@@ -570,21 +848,51 @@ public class WhatsNewMedia
shot.Resize((uint)Math.Round(shot.Width * scale), (uint)Math.Round(shot.Height * scale));
}
canvas.Composite(shot, Gravity.Center, CompositeOperator.Over);
+ if (pointer is { } p)
+ {
+ var left = (CanvasWidth - (int)shot.Width) / 2;
+ var top = (CanvasHeight - (int)shot.Height) / 2;
+ DrawPointer(canvas, new PointD(left + (p.X - corner.X) * scale, top + (p.Y - corner.Y) * scale), pressed);
+ }
return canvas;
}
- /// <summary>A made-up photo (sky, sun, sea, hills) to crop: generated, so no picture is kept in the repository.</summary>
- private static void DrawLandscape(string path)
+ /// <summary>An arrow pointer with its tip at <paramref name="tip"/>, a little smaller while pressed.</summary>
+ private static void DrawPointer(MagickImage canvas, PointD tip, bool pressed)
{
- using var image = new MagickImage("gradient:#8EC5FC-#F8D2A6", 1600, 1000);
+ var size = pressed ? 1.06 : 1.15;
+ PointD[] shape = [new(0, 0), new(0, 17.5), new(4.2, 13.6), new(7.1, 20.3), new(10.1, 19), new(7.3, 12.5), new(12.8, 12.5)];
+ PointD[] At(double dx, double dy) => [.. shape.Select(q => new PointD(tip.X + q.X * size + dx, tip.Y + q.Y * size + dy))];
new Drawables()
- .FillColor(new MagickColor("#FFF2C2")).Circle(1080, 360, 1080, 460)
- .FillColor(new MagickColor("#4F7CAC")).Rectangle(0, 640, 1600, 1000)
- .FillColor(new MagickColor("#6C9A5B")).Polygon(new PointD(0, 700), new PointD(380, 470), new PointD(760, 690), new PointD(0, 760))
- .FillColor(new MagickColor("#3F6E4A")).Polygon(new PointD(600, 700), new PointD(1000, 520), new PointD(1600, 700), new PointD(1600, 760), new PointD(600, 760))
- .FillColor(new MagickColor("#F2F2F2")).Polygon(new PointD(1180, 760), new PointD(1260, 600), new PointD(1260, 760))
- .FillColor(new MagickColor("#7A4E2D")).Rectangle(1150, 760, 1300, 790)
- .Draw(image);
+ .StrokeLineJoin(LineJoin.Round)
+ .FillColor(new MagickColor("#00000038")).StrokeColor(new MagickColor("#0000001F")).StrokeWidth(2.4).Polygon(At(0.6, 1.6))
+ .FillColor(MagickColors.White).StrokeColor(new MagickColor("#1F1E1D")).StrokeWidth(1.15).Polygon(At(0, 0))
+ .Draw(canvas);
+ }
+
+ /// <summary>
+ /// A made-up photo to crop (1600 × 1000): a harbour (sky, sun, sea, hills, a sail), a meadow at noon or dunes at
+ /// dusk. Generated, so no picture is kept in the repository.
+ /// </summary>
+ private static void DrawLandscape(string path, int variant = 0)
+ {
+ var (sky, sun, ground, near, far) = variant switch
+ {
+ 1 => ("gradient:#9FD3F2-#E9F6E4", "#FFF7D6", "#7DB65A", "#4E8F3C", "#A5CC7A"),
+ 2 => ("gradient:#F6B98A-#FCE3C4", "#FFF1D0", "#D9925A", "#B86E3E", "#E7B07A"),
+ _ => ("gradient:#8EC5FC-#F8D2A6", "#FFF2C2", "#4F7CAC", "#3F6E4A", "#6C9A5B"),
+ };
+ using var image = new MagickImage(sky, 1600, 1000);
+ var drawing = new Drawables()
+ .FillColor(new MagickColor(sun)).Circle(1080, 360, 1080, 460)
+ .FillColor(new MagickColor(ground)).Rectangle(0, 640, 1600, 1000)
+ .FillColor(new MagickColor(far)).Polygon(new PointD(0, 700), new PointD(380, 470), new PointD(760, 690), new PointD(0, 760))
+ .FillColor(new MagickColor(near)).Polygon(new PointD(600, 700), new PointD(1000, 520), new PointD(1600, 700), new PointD(1600, 760), new PointD(600, 760));
+ if (variant == 0)
+ drawing
+ .FillColor(new MagickColor("#F2F2F2")).Polygon(new PointD(1180, 760), new PointD(1260, 600), new PointD(1260, 760))
+ .FillColor(new MagickColor("#7A4E2D")).Rectangle(1150, 760, 1300, 790);
+ drawing.Draw(image);
image.Quality = 92;
image.Write(path, MagickFormat.Jpeg);
}
@@ -608,9 +916,23 @@ public class WhatsNewMedia
// The first frame next to the screenshots, for review.
clip.SaveFirstFrame(Path.Combine(TestServices.ScreenshotDirectory, "whatsnew-" + Path.ChangeExtension(name, ".png")));
Assert.InRange(new FileInfo(path).Length, 1, 400 * 1024);
+ if (clip.Poster is { } poster)
+ SetPoster(folder, name, poster);
}
}
+ /// <summary>Writes the frame a clip marked as its <c>poster</c> into the slide of slides.json that shows it.</summary>
+ private static void SetPoster(string folder, string media, int frame)
+ {
+ var path = Path.Combine(folder, "slides.json");
+ var text = File.ReadAllText(path);
+ var slide = Regex.Match(text, $$"""\{[^{}]*"media": "{{Regex.Escape(media)}}"[^{}]*\}""");
+ Assert.True(slide.Success, $"slides.json has no slide showing {media}");
+ var updated = Regex.Replace(slide.Value, """ "poster": \d+,""", "")
+ .Replace($"\"media\": \"{media}\",", $"\"media\": \"{media}\", \"poster\": {frame},", StringComparison.Ordinal);
+ File.WriteAllText(path, text.Replace(slide.Value, updated, StringComparison.Ordinal));
+ }
+
/// <summary>Frames with how long each shows; a frame identical to the one before only lengthens it.</summary>
private sealed class Clip : IDisposable
{
@@ -618,6 +940,15 @@ public class WhatsNewMedia
public int Count => _frames.Count;
+ /// <summary>WebP quality of the frames: lower for a long clip with much movement, to stay within the budget.</summary>
+ public uint Quality { get; init; } = 82;
+
+ /// <summary>The frame reduced motion shows instead of the first (<see cref="MarkPoster"/>).</summary>
+ public int? Poster { get; private set; }
+
+ /// <summary>The frame added last is the clip's poster.</summary>
+ public void MarkPoster() => Poster = _frames.Count - 1;
+
/// <summary>Shows the last frame <paramref name="milliseconds"/> longer.</summary>
public void Hold(int milliseconds) => _frames[^1] = (_frames[^1].Image, _frames[^1].Milliseconds + milliseconds);
@@ -641,7 +972,7 @@ public class WhatsNewMedia
// Delays are in 1/100 s; at least 2 so viewers don't speed the frame up.
copy.AnimationDelay = (uint)Math.Max(2, Math.Round(milliseconds / 10.0));
copy.AnimationTicksPerSecond = 100;
- copy.Quality = 82;
+ copy.Quality = Quality;
collection.Add(copy);
}
var defines = new ImageMagick.Formats.WebPWriteDefines { Method = 6, Lossless = false, ThreadLevel = true };