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.

Add interactive crop tool, multi-page donut navigation, and schema migration 21

smjriflea57d6c12b74a
diff --git a/src/Filee.App/App.axaml.cs b/src/Filee.App/App.axaml.cs
index ba48ba9c..512626a9 100644
--- a/src/Filee.App/App.axaml.cs
+++ b/src/Filee.App/App.axaml.cs
@@ -72,7 +72,7 @@ public partial class App : Application
var triggers = AppHost.Get<TriggerService>();
var radial = AppHost.Get<RadialController>();
var platform = AppHost.Get<IPlatformServices>();
- triggers.DragStarted += (_, e) => radial.ShowForDrag(e.X, e.Y);
+ triggers.DragStarted += (_, e) => radial.ShowForDrag(e.X, e.Y, e.Gesture);
triggers.DragEnded += (_, _) => radial.OnDragGestureEnded();
triggers.SelectionGesture += async (_, e) =>
{
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 7a0f9ab5..b8c9ae12 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -57,6 +57,9 @@
"donut.empty": "Drag presets here",
"donut.same_format": "Same format",
"donut.group_caption": "Group of {0}",
+ "donut.more": "More →",
+ "donut.back": "← Back",
+ "donut.nav_hint": "Page {0} of {1}",
"toast.converting": "{0} → {1}",
"toast.done": "Done",
@@ -129,8 +132,18 @@
"profile.fonts": "Fonts",
"profile.data": "Data",
"profile.models": "3D models",
+ "profile.utility": "Quick Tools",
"profile.mixed": "Mixed files",
+ "preset.crop": "Crop",
+ "crop.title": "Crop",
+ "crop.save": "Crop & Save",
+ "crop.reset": "Reset",
+ "crop.aspect_title": "Aspect:",
+ "crop.aspect_free": "Free",
+ "crop.aspect_original": "Original",
+ "crop.page_counter": "{0} of {1}",
+
"preset.half_size": "Half size",
"preset.grayscale": "Grayscale",
"preset.remove_background": "Remove background",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 923542c3..c09f9aca 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -57,6 +57,9 @@
"donut.empty": "프리셋을 끌어다 놓으세요",
"donut.same_format": "같은 형식",
"donut.group_caption": "묶음 · {0}개",
+ "donut.more": "더보기 →",
+ "donut.back": "← 이전",
+ "donut.nav_hint": "페이지 {0}/{1}",
"toast.converting": "{0} → {1}",
"toast.done": "완료",
@@ -129,8 +132,18 @@
"profile.fonts": "글꼴",
"profile.data": "데이터",
"profile.models": "3D 모델",
+ "profile.utility": "빠른 도구",
"profile.mixed": "혼합 파일",
+ "preset.crop": "자르기",
+ "crop.title": "자르기",
+ "crop.save": "자르기 및 저장",
+ "crop.reset": "초기화",
+ "crop.aspect_title": "비율:",
+ "crop.aspect_free": "자유",
+ "crop.aspect_original": "원본",
+ "crop.page_counter": "{0}/{1}",
+
"preset.half_size": "50% 축소",
"preset.grayscale": "흑백",
"preset.remove_background": "배경 제거",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index ec2d5a7e..e76d61dc 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -57,6 +57,9 @@
"donut.empty": "Przeciągnij tu ustawienia",
"donut.same_format": "Ten sam format",
"donut.group_caption": "Grupa: {0}",
+ "donut.more": "Więcej →",
+ "donut.back": "← Wstecz",
+ "donut.nav_hint": "Strona {0} z {1}",
"toast.converting": "{0} → {1}",
"toast.done": "Gotowe",
@@ -129,8 +132,18 @@
"profile.fonts": "Czcionki",
"profile.data": "Dane",
"profile.models": "Modele 3D",
+ "profile.utility": "Szybkie narzędzia",
"profile.mixed": "Różne pliki",
+ "preset.crop": "Kadruj",
+ "crop.title": "Kadrowanie",
+ "crop.save": "Kadruj i zapisz",
+ "crop.reset": "Resetuj",
+ "crop.aspect_title": "Proporcje:",
+ "crop.aspect_free": "Dowolne",
+ "crop.aspect_original": "Oryginalne",
+ "crop.page_counter": "{0} z {1}",
+
"preset.half_size": "Połowa rozmiaru",
"preset.grayscale": "Skala szarości",
"preset.remove_background": "Usuń tło",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 5f1f8504..1a554da4 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -57,6 +57,9 @@
"donut.empty": "把预设拖到这里",
"donut.same_format": "同格式",
"donut.group_caption": "组 · {0} 项",
+ "donut.more": "更多 →",
+ "donut.back": "← 返回",
+ "donut.nav_hint": "第 {0}/{1} 页",
"toast.converting": "{0} → {1}",
"toast.done": "完成",
@@ -129,8 +132,18 @@
"profile.fonts": "字体",
"profile.data": "数据",
"profile.models": "3D 模型",
+ "profile.utility": "快捷工具",
"profile.mixed": "混合文件",
+ "preset.crop": "裁剪",
+ "crop.title": "裁剪",
+ "crop.save": "裁剪并保存",
+ "crop.reset": "重置",
+ "crop.aspect_title": "比例:",
+ "crop.aspect_free": "自由",
+ "crop.aspect_original": "原始比例",
+ "crop.page_counter": "{0}/{1}",
+
"preset.half_size": "缩小 50%",
"preset.grayscale": "灰度",
"preset.remove_background": "去除背景",
diff --git a/src/Filee.App/Controls/CropCanvas.cs b/src/Filee.App/Controls/CropCanvas.cs
new file mode 100644
index 00000000..9956f331
--- /dev/null
+++ b/src/Filee.App/Controls/CropCanvas.cs
@@ -0,0 +1,588 @@
+// Interactive crop control with manual screenshot-style selection, 8 resize handles,
+// rule-of-thirds grid, and aspect ratio locking (1:1 square, free-form, etc.).
+
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Media;
+using Avalonia.Media.Imaging;
+
+namespace Filee.App.Controls;
+
+public enum CropHandle
+{
+ None,
+ CreateNew,
+ Body,
+ TopLeft,
+ Top,
+ TopRight,
+ Right,
+ BottomRight,
+ Bottom,
+ BottomLeft,
+ Left,
+}
+
+public sealed class CropCanvas : Control
+{
+ public static readonly StyledProperty<Bitmap?> SourceImageProperty =
+ AvaloniaProperty.Register<CropCanvas, Bitmap?>(nameof(SourceImage));
+
+ public static readonly StyledProperty<Rect> NormalizedCropRectProperty =
+ AvaloniaProperty.Register<CropCanvas, Rect>(nameof(NormalizedCropRect), new Rect(0.1, 0.1, 0.8, 0.8));
+
+ public static readonly StyledProperty<double> AspectRatioProperty =
+ AvaloniaProperty.Register<CropCanvas, double>(nameof(AspectRatio), 0);
+
+ public Bitmap? SourceImage
+ {
+ get => GetValue(SourceImageProperty);
+ set => SetValue(SourceImageProperty, value);
+ }
+
+ public Rect NormalizedCropRect
+ {
+ get => GetValue(NormalizedCropRectProperty);
+ set => SetValue(NormalizedCropRectProperty, value);
+ }
+
+ public double AspectRatio
+ {
+ get => GetValue(AspectRatioProperty);
+ set => SetValue(AspectRatioProperty, value);
+ }
+
+ public event Action<Rect>? CropRectChanged;
+
+ private CropHandle _activeHandle = CropHandle.None;
+ private Point _dragStartPoint;
+ private Rect _dragStartCrop;
+ private const double MinSizePx = 24.0;
+
+ private static readonly IBrush DimMaskBrush = new SolidColorBrush(Color.FromArgb(175, 0, 0, 0));
+ private static readonly IPen CropBorderPen = new Pen(Brushes.White, 1.5);
+ private static readonly IPen GridPen = new Pen(new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)), 1);
+
+ static CropCanvas()
+ {
+ AffectsRender<CropCanvas>(SourceImageProperty, NormalizedCropRectProperty, AspectRatioProperty);
+ }
+
+ public void ResetCrop()
+ {
+ NormalizedCropRect = new Rect(0, 0, 1, 1);
+ CropRectChanged?.Invoke(NormalizedCropRect);
+ InvalidateVisual();
+ }
+
+ public void SetAspectRatio(double ratio)
+ {
+ AspectRatio = ratio;
+ if (ratio <= 0)
+ {
+ InvalidateVisual();
+ return;
+ }
+
+ var imgBounds = CalculateImageBounds();
+ if (imgBounds.Width <= 0 || imgBounds.Height <= 0)
+ return;
+
+ var current = GetScreenCropRect(imgBounds);
+
+ double w, h;
+ if (current.Width / Math.Max(1.0, current.Height) > ratio)
+ {
+ // Current crop is wider than desired ratio: shrink width to match
+ h = current.Height;
+ w = h * ratio;
+ }
+ else
+ {
+ // Current crop is taller than desired ratio: shrink height to match
+ w = current.Width;
+ h = w / ratio;
+ }
+
+ if (w > imgBounds.Width)
+ {
+ w = imgBounds.Width;
+ h = w / ratio;
+ }
+ if (h > imgBounds.Height)
+ {
+ h = imgBounds.Height;
+ w = h * ratio;
+ }
+
+ w = Math.Max(MinSizePx, w);
+ h = Math.Max(MinSizePx, h);
+
+ var x = Math.Clamp(current.Center.X - w / 2.0, imgBounds.Left, Math.Max(imgBounds.Left, imgBounds.Right - w));
+ var y = Math.Clamp(current.Center.Y - h / 2.0, imgBounds.Top, Math.Max(imgBounds.Top, imgBounds.Bottom - h));
+
+ SetCropFromScreen(new Rect(x, y, w, h), imgBounds);
+ }
+
+ public Rect CalculateImageBounds()
+ {
+ if (SourceImage is null || Bounds.Width <= 0 || Bounds.Height <= 0)
+ return default;
+
+ var imgSize = SourceImage.Size;
+ var scale = Math.Min(Bounds.Width / imgSize.Width, Bounds.Height / imgSize.Height);
+ var w = imgSize.Width * scale;
+ var h = imgSize.Height * scale;
+ var x = (Bounds.Width - w) / 2.0;
+ var y = (Bounds.Height - h) / 2.0;
+
+ return new Rect(x, y, w, h);
+ }
+
+ public Rect GetScreenCropRect(Rect imgBounds)
+ {
+ var norm = NormalizedCropRect;
+ return new Rect(
+ imgBounds.X + norm.X * imgBounds.Width,
+ imgBounds.Y + norm.Y * imgBounds.Height,
+ Math.Max(MinSizePx, norm.Width * imgBounds.Width),
+ Math.Max(MinSizePx, norm.Height * imgBounds.Height)
+ );
+ }
+
+ private void SetCropFromScreen(Rect screenCrop, Rect imgBounds)
+ {
+ if (imgBounds.Width <= 0 || imgBounds.Height <= 0)
+ return;
+
+ var x = Math.Clamp(screenCrop.X, imgBounds.Left, Math.Max(imgBounds.Left, imgBounds.Right - MinSizePx));
+ var y = Math.Clamp(screenCrop.Y, imgBounds.Top, Math.Max(imgBounds.Top, imgBounds.Bottom - MinSizePx));
+ var maxW = imgBounds.Right - x;
+ var maxH = imgBounds.Bottom - y;
+ var w = Math.Clamp(screenCrop.Width, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = Math.Clamp(screenCrop.Height, MinSizePx, Math.Max(MinSizePx, maxH));
+
+ NormalizedCropRect = new Rect(
+ (x - imgBounds.Left) / imgBounds.Width,
+ (y - imgBounds.Top) / imgBounds.Height,
+ w / imgBounds.Width,
+ h / imgBounds.Height
+ );
+ CropRectChanged?.Invoke(NormalizedCropRect);
+ InvalidateVisual();
+ }
+
+ public override void Render(DrawingContext context)
+ {
+ base.Render(context);
+ var imgBounds = CalculateImageBounds();
+ if (SourceImage is null || imgBounds.Width <= 0 || imgBounds.Height <= 0)
+ return;
+
+ // 1. Render Source Image
+ context.DrawImage(SourceImage, new Rect(0, 0, SourceImage.Size.Width, SourceImage.Size.Height), imgBounds);
+
+ var crop = GetScreenCropRect(imgBounds);
+
+ // 2. Draw Dim Mask around crop box
+ var topMask = new Rect(imgBounds.X, imgBounds.Y, imgBounds.Width, Math.Max(0, crop.Y - imgBounds.Y));
+ var bottomMask = new Rect(imgBounds.X, crop.Bottom, imgBounds.Width, Math.Max(0, imgBounds.Bottom - crop.Bottom));
+ var leftMask = new Rect(imgBounds.X, crop.Y, Math.Max(0, crop.X - imgBounds.X), crop.Height);
+ var rightMask = new Rect(crop.Right, crop.Y, Math.Max(0, imgBounds.Right - crop.Right), crop.Height);
+
+ context.DrawRectangle(DimMaskBrush, null, topMask);
+ context.DrawRectangle(DimMaskBrush, null, bottomMask);
+ context.DrawRectangle(DimMaskBrush, null, leftMask);
+ context.DrawRectangle(DimMaskBrush, null, rightMask);
+
+ // 3. Draw Rule-of-Thirds Grid
+ if (crop.Width > 50 && crop.Height > 50)
+ {
+ var x1 = crop.X + crop.Width / 3.0;
+ var x2 = crop.X + (crop.Width * 2.0) / 3.0;
+ var y1 = crop.Y + crop.Height / 3.0;
+ var y2 = crop.Y + (crop.Height * 2.0) / 3.0;
+
+ context.DrawLine(GridPen, new Point(x1, crop.Y), new Point(x1, crop.Bottom));
+ context.DrawLine(GridPen, new Point(x2, crop.Y), new Point(x2, crop.Bottom));
+ context.DrawLine(GridPen, new Point(crop.X, y1), new Point(crop.Right, y1));
+ context.DrawLine(GridPen, new Point(crop.X, y2), new Point(crop.Right, y2));
+ }
+
+ // 4. Draw Crop Rectangle Border
+ context.DrawRectangle(null, CropBorderPen, crop);
+
+ // 5. Draw macOS Native Style Corner Brackets and Edge Bars
+ DrawCornerBracket(context, crop.TopLeft, 1, 1);
+ DrawCornerBracket(context, crop.TopRight, -1, 1);
+ DrawCornerBracket(context, crop.BottomLeft, 1, -1);
+ DrawCornerBracket(context, crop.BottomRight, -1, -1);
+
+ DrawEdgeBar(context, new Point(crop.Center.X, crop.Top), isHorizontal: true);
+ DrawEdgeBar(context, new Point(crop.Center.X, crop.Bottom), isHorizontal: true);
+ DrawEdgeBar(context, new Point(crop.Left, crop.Center.Y), isHorizontal: false);
+ DrawEdgeBar(context, new Point(crop.Right, crop.Center.Y), isHorizontal: false);
+ }
+
+ private void DrawCornerBracket(DrawingContext context, Point corner, int dirX, int dirY)
+ {
+ const double length = 18;
+ const double thickness = 3.5;
+ var pCorner = new Pen(Brushes.White, thickness);
+ var pShadow = new Pen(new SolidColorBrush(Color.FromArgb(140, 0, 0, 0)), thickness + 1.5);
+
+ var pHoriz = new Point(corner.X + dirX * length, corner.Y);
+ var pVert = new Point(corner.X, corner.Y + dirY * length);
+
+ // Shadow behind bracket for clear visibility on bright/white photos
+ context.DrawLine(pShadow, new Point(corner.X - dirX * 0.5, corner.Y), pHoriz);
+ context.DrawLine(pShadow, new Point(corner.X, corner.Y - dirY * 0.5), pVert);
+
+ // Crisp white bracket
+ context.DrawLine(pCorner, corner, pHoriz);
+ context.DrawLine(pCorner, corner, pVert);
+ }
+
+ private void DrawEdgeBar(DrawingContext context, Point center, bool isHorizontal)
+ {
+ const double halfLen = 10;
+ const double thickness = 3.5;
+ var pBar = new Pen(Brushes.White, thickness);
+ var pShadow = new Pen(new SolidColorBrush(Color.FromArgb(140, 0, 0, 0)), thickness + 1.5);
+
+ Point p1, p2;
+ if (isHorizontal)
+ {
+ p1 = new Point(center.X - halfLen, center.Y);
+ p2 = new Point(center.X + halfLen, center.Y);
+ }
+ else
+ {
+ p1 = new Point(center.X, center.Y - halfLen);
+ p2 = new Point(center.X, center.Y + halfLen);
+ }
+
+ context.DrawLine(pShadow, p1, p2);
+ context.DrawLine(pBar, p1, p2);
+ }
+
+ private CropHandle HitTestHandle(Point pt, Rect crop, Rect imgBounds)
+ {
+ const double hitTol = 16.0;
+
+ if (Distance(pt, crop.TopLeft) <= hitTol) return CropHandle.TopLeft;
+ if (Distance(pt, crop.TopRight) <= hitTol) return CropHandle.TopRight;
+ if (Distance(pt, crop.BottomLeft) <= hitTol) return CropHandle.BottomLeft;
+ if (Distance(pt, crop.BottomRight) <= hitTol) return CropHandle.BottomRight;
+
+ if (Math.Abs(pt.Y - crop.Top) <= hitTol && pt.X >= crop.Left && pt.X <= crop.Right) return CropHandle.Top;
+ if (Math.Abs(pt.Y - crop.Bottom) <= hitTol && pt.X >= crop.Left && pt.X <= crop.Right) return CropHandle.Bottom;
+ if (Math.Abs(pt.X - crop.Left) <= hitTol && pt.Y >= crop.Top && pt.Y <= crop.Bottom) return CropHandle.Left;
+ if (Math.Abs(pt.X - crop.Right) <= hitTol && pt.Y >= crop.Top && pt.Y <= crop.Bottom) return CropHandle.Right;
+
+ if (crop.Contains(pt)) return CropHandle.Body;
+ if (imgBounds.Contains(pt)) return CropHandle.CreateNew;
+ return CropHandle.None;
+ }
+
+ private static double Distance(Point a, Point b) => Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
+
+ protected override void OnPointerMoved(PointerEventArgs e)
+ {
+ base.OnPointerMoved(e);
+ var imgBounds = CalculateImageBounds();
+ if (imgBounds.Width <= 0 || imgBounds.Height <= 0) return;
+
+ var pt = e.GetPosition(this);
+ var crop = GetScreenCropRect(imgBounds);
+
+ if (_activeHandle == CropHandle.None)
+ {
+ var h = HitTestHandle(pt, crop, imgBounds);
+ Cursor = h switch
+ {
+ CropHandle.TopLeft or CropHandle.BottomRight => new Cursor(StandardCursorType.TopLeftCorner),
+ CropHandle.TopRight or CropHandle.BottomLeft => new Cursor(StandardCursorType.TopRightCorner),
+ CropHandle.Top or CropHandle.Bottom => new Cursor(StandardCursorType.SizeNorthSouth),
+ CropHandle.Left or CropHandle.Right => new Cursor(StandardCursorType.SizeWestEast),
+ CropHandle.Body => new Cursor(StandardCursorType.SizeAll),
+ CropHandle.CreateNew => new Cursor(StandardCursorType.Cross),
+ _ => Cursor.Default,
+ };
+ return;
+ }
+
+ // Active manual screenshot-style selection drag
+ if (_activeHandle == CropHandle.CreateNew)
+ {
+ var p1 = new Point(
+ Math.Clamp(_dragStartPoint.X, imgBounds.Left, imgBounds.Right),
+ Math.Clamp(_dragStartPoint.Y, imgBounds.Top, imgBounds.Bottom));
+ var p2 = new Point(
+ Math.Clamp(pt.X, imgBounds.Left, imgBounds.Right),
+ Math.Clamp(pt.Y, imgBounds.Top, imgBounds.Bottom));
+
+ if (AspectRatio <= 0)
+ {
+ // Free-form box selection
+ var l = Math.Min(p1.X, p2.X);
+ var t = Math.Min(p1.Y, p2.Y);
+ var w = Math.Max(MinSizePx, Math.Abs(p2.X - p1.X));
+ var h = Math.Max(MinSizePx, Math.Abs(p2.Y - p1.Y));
+ SetCropFromScreen(new Rect(l, t, w, h), imgBounds);
+ }
+ else
+ {
+ // Constrained aspect ratio selection (e.g. 1:1 Instagram post)
+ var R = AspectRatio;
+ var dx = p2.X - p1.X;
+ var dy = p2.Y - p1.Y;
+ var signX = dx >= 0 ? 1 : -1;
+ var signY = dy >= 0 ? 1 : -1;
+
+ var rawW = Math.Abs(dx);
+ var rawH = Math.Abs(dy);
+
+ var w = Math.Max(rawW, rawH * R);
+ var h = w / R;
+
+ var maxW = signX > 0 ? (imgBounds.Right - p1.X) : (p1.X - imgBounds.Left);
+ var maxH = signY > 0 ? (imgBounds.Bottom - p1.Y) : (p1.Y - imgBounds.Top);
+
+ if (w > maxW) { w = maxW; h = w / R; }
+ if (h > maxH) { h = maxH; w = h * R; }
+
+ w = Math.Max(MinSizePx, w);
+ h = Math.Max(MinSizePx, h);
+
+ var left = signX > 0 ? p1.X : p1.X - w;
+ var top = signY > 0 ? p1.Y : p1.Y - h;
+
+ SetCropFromScreen(new Rect(left, top, w, h), imgBounds);
+ }
+ return;
+ }
+
+ // Active panning/moving the selection box over the image
+ if (_activeHandle == CropHandle.Body)
+ {
+ var deltaX = pt.X - _dragStartPoint.X;
+ var deltaY = pt.Y - _dragStartPoint.Y;
+
+ var newX = Math.Clamp(_dragStartCrop.X + deltaX, imgBounds.Left, Math.Max(imgBounds.Left, imgBounds.Right - _dragStartCrop.Width));
+ var newY = Math.Clamp(_dragStartCrop.Y + deltaY, imgBounds.Top, Math.Max(imgBounds.Top, imgBounds.Bottom - _dragStartCrop.Height));
+
+ SetCropFromScreen(new Rect(newX, newY, _dragStartCrop.Width, _dragStartCrop.Height), imgBounds);
+ return;
+ }
+
+ // Active handle resizing
+ var dxRes = pt.X - _dragStartPoint.X;
+ var dyRes = pt.Y - _dragStartPoint.Y;
+
+ if (AspectRatio <= 0)
+ {
+ // Free-form handle resizing
+ var left = _dragStartCrop.Left;
+ var top = _dragStartCrop.Top;
+ var right = _dragStartCrop.Right;
+ var bottom = _dragStartCrop.Bottom;
+
+ switch (_activeHandle)
+ {
+ case CropHandle.TopLeft:
+ left = Math.Clamp(_dragStartCrop.Left + dxRes, imgBounds.Left, right - MinSizePx);
+ top = Math.Clamp(_dragStartCrop.Top + dyRes, imgBounds.Top, bottom - MinSizePx);
+ break;
+ case CropHandle.TopRight:
+ right = Math.Clamp(_dragStartCrop.Right + dxRes, left + MinSizePx, imgBounds.Right);
+ top = Math.Clamp(_dragStartCrop.Top + dyRes, imgBounds.Top, bottom - MinSizePx);
+ break;
+ case CropHandle.BottomLeft:
+ left = Math.Clamp(_dragStartCrop.Left + dxRes, imgBounds.Left, right - MinSizePx);
+ bottom = Math.Clamp(_dragStartCrop.Bottom + dyRes, top + MinSizePx, imgBounds.Bottom);
+ break;
+ case CropHandle.BottomRight:
+ right = Math.Clamp(_dragStartCrop.Right + dxRes, left + MinSizePx, imgBounds.Right);
+ bottom = Math.Clamp(_dragStartCrop.Bottom + dyRes, top + MinSizePx, imgBounds.Bottom);
+ break;
+ case CropHandle.Top:
+ top = Math.Clamp(_dragStartCrop.Top + dyRes, imgBounds.Top, bottom - MinSizePx);
+ break;
+ case CropHandle.Bottom:
+ bottom = Math.Clamp(_dragStartCrop.Bottom + dyRes, top + MinSizePx, imgBounds.Bottom);
+ break;
+ case CropHandle.Left:
+ left = Math.Clamp(_dragStartCrop.Left + dxRes, imgBounds.Left, right - MinSizePx);
+ break;
+ case CropHandle.Right:
+ right = Math.Clamp(_dragStartCrop.Right + dxRes, left + MinSizePx, imgBounds.Right);
+ break;
+ }
+
+ SetCropFromScreen(new Rect(left, top, right - left, bottom - top), imgBounds);
+ }
+ else
+ {
+ // Proportional aspect ratio handle resizing (e.g. 1:1 square)
+ var R = AspectRatio;
+
+ switch (_activeHandle)
+ {
+ case CropHandle.BottomRight:
+ {
+ var anchor = _dragStartCrop.TopLeft;
+ var delta = (dxRes + dyRes * R) / 2.0;
+ var maxW = Math.Min(imgBounds.Right - anchor.X, (imgBounds.Bottom - anchor.Y) * R);
+ var w = Math.Clamp(_dragStartCrop.Width + delta, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = w / R;
+ SetCropFromScreen(new Rect(anchor.X, anchor.Y, w, h), imgBounds);
+ break;
+ }
+ case CropHandle.BottomLeft:
+ {
+ var anchorX = _dragStartCrop.Right;
+ var anchorY = _dragStartCrop.Top;
+ var delta = (-dxRes + dyRes * R) / 2.0;
+ var maxW = Math.Min(anchorX - imgBounds.Left, (imgBounds.Bottom - anchorY) * R);
+ var w = Math.Clamp(_dragStartCrop.Width + delta, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = w / R;
+ SetCropFromScreen(new Rect(anchorX - w, anchorY, w, h), imgBounds);
+ break;
+ }
+ case CropHandle.TopRight:
+ {
+ var anchorX = _dragStartCrop.Left;
+ var anchorY = _dragStartCrop.Bottom;
+ var delta = (dxRes - dyRes * R) / 2.0;
+ var maxW = Math.Min(imgBounds.Right - anchorX, (anchorY - imgBounds.Top) * R);
+ var w = Math.Clamp(_dragStartCrop.Width + delta, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = w / R;
+ SetCropFromScreen(new Rect(anchorX, anchorY - h, w, h), imgBounds);
+ break;
+ }
+ case CropHandle.TopLeft:
+ {
+ var anchorX = _dragStartCrop.Right;
+ var anchorY = _dragStartCrop.Bottom;
+ var delta = (-dxRes - dyRes * R) / 2.0;
+ var maxW = Math.Min(anchorX - imgBounds.Left, (anchorY - imgBounds.Top) * R);
+ var w = Math.Clamp(_dragStartCrop.Width + delta, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = w / R;
+ SetCropFromScreen(new Rect(anchorX - w, anchorY - h, w, h), imgBounds);
+ break;
+ }
+ case CropHandle.Right:
+ {
+ var anchorLeft = _dragStartCrop.Left;
+ var maxW = Math.Min(imgBounds.Right - anchorLeft, imgBounds.Height * R);
+ var w = Math.Clamp(_dragStartCrop.Width + dxRes, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = w / R;
+ var y = Math.Clamp(_dragStartCrop.Center.Y - h / 2.0, imgBounds.Top, imgBounds.Bottom - h);
+ SetCropFromScreen(new Rect(anchorLeft, y, w, h), imgBounds);
+ break;
+ }
+ case CropHandle.Left:
+ {
+ var anchorRight = _dragStartCrop.Right;
+ var maxW = Math.Min(anchorRight - imgBounds.Left, imgBounds.Height * R);
+ var w = Math.Clamp(_dragStartCrop.Width - dxRes, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = w / R;
+ var y = Math.Clamp(_dragStartCrop.Center.Y - h / 2.0, imgBounds.Top, imgBounds.Bottom - h);
+ SetCropFromScreen(new Rect(anchorRight - w, y, w, h), imgBounds);
+ break;
+ }
+ case CropHandle.Bottom:
+ {
+ var anchorTop = _dragStartCrop.Top;
+ var maxH = Math.Min(imgBounds.Bottom - anchorTop, imgBounds.Width / R);
+ var h = Math.Clamp(_dragStartCrop.Height + dyRes, MinSizePx, Math.Max(MinSizePx, maxH));
+ var w = h * R;
+ var x = Math.Clamp(_dragStartCrop.Center.X - w / 2.0, imgBounds.Left, imgBounds.Right - w);
+ SetCropFromScreen(new Rect(x, anchorTop, w, h), imgBounds);
+ break;
+ }
+ case CropHandle.Top:
+ {
+ var anchorBottom = _dragStartCrop.Bottom;
+ var maxH = Math.Min(anchorBottom - imgBounds.Top, imgBounds.Width / R);
+ var h = Math.Clamp(_dragStartCrop.Height - dyRes, MinSizePx, Math.Max(MinSizePx, maxH));
+ var w = h * R;
+ var x = Math.Clamp(_dragStartCrop.Center.X - w / 2.0, imgBounds.Left, imgBounds.Right - w);
+ SetCropFromScreen(new Rect(x, anchorBottom - h, w, h), imgBounds);
+ break;
+ }
+ }
+ }
+ }
+
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ base.OnPointerPressed(e);
+ var imgBounds = CalculateImageBounds();
+ if (imgBounds.Width <= 0 || imgBounds.Height <= 0) return;
+
+ var pt = e.GetPosition(this);
+ var crop = GetScreenCropRect(imgBounds);
+ _activeHandle = HitTestHandle(pt, crop, imgBounds);
+
+ if (_activeHandle != CropHandle.None)
+ {
+ _dragStartPoint = pt;
+ _dragStartCrop = crop;
+ e.Pointer.Capture(this);
+ e.Handled = true;
+ }
+ }
+
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ {
+ base.OnPointerReleased(e);
+ if (_activeHandle != CropHandle.None)
+ {
+ _activeHandle = CropHandle.None;
+ e.Pointer.Capture(null);
+ e.Handled = true;
+ }
+ }
+
+ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
+ {
+ base.OnPointerWheelChanged(e);
+ var imgBounds = CalculateImageBounds();
+ if (imgBounds.Width <= 0 || imgBounds.Height <= 0) return;
+
+ var crop = GetScreenCropRect(imgBounds);
+ var delta = e.Delta.Y;
+ if (Math.Abs(delta) < 0.001) return;
+
+ var zoomFactor = delta > 0 ? 1.05 : 0.95;
+ double newW, newH;
+
+ if (AspectRatio > 0)
+ {
+ newW = crop.Width * zoomFactor;
+ newH = newW / AspectRatio;
+ if (newW > imgBounds.Width || newH > imgBounds.Height)
+ {
+ newW = Math.Min(imgBounds.Width, imgBounds.Height * AspectRatio);
+ newH = newW / AspectRatio;
+ }
+ }
+ else
+ {
+ newW = Math.Clamp(crop.Width * zoomFactor, MinSizePx, imgBounds.Width);
+ newH = Math.Clamp(crop.Height * zoomFactor, MinSizePx, imgBounds.Height);
+ }
+
+ newW = Math.Max(MinSizePx, newW);
+ newH = Math.Max(MinSizePx, newH);
+
+ var newX = Math.Clamp(crop.Center.X - newW / 2.0, imgBounds.Left, imgBounds.Right - newW);
+ var newY = Math.Clamp(crop.Center.Y - newH / 2.0, imgBounds.Top, imgBounds.Bottom - newH);
+
+ SetCropFromScreen(new Rect(newX, newY, newW, newH), imgBounds);
+ e.Handled = true;
+ }
+}
diff --git a/src/Filee.App/Controls/DonutMenu.Groups.cs b/src/Filee.App/Controls/DonutMenu.Groups.cs
index 1638c9a1..80d0e394 100644
--- a/src/Filee.App/Controls/DonutMenu.Groups.cs
+++ b/src/Filee.App/Controls/DonutMenu.Groups.cs
@@ -41,6 +41,20 @@ public sealed partial class DonutMenu
private IDisposable? _expandTimer;
private double _pendingDistance;
+ // Navigation slice hover timer (e.g. dwell on "More" or "Back" to turn page)
+ public event EventHandler<int>? NavigationRequested;
+ private int _pendingNav = -1;
+ private IDisposable? _navTimer;
+ private bool _navCooldown;
+ private static readonly TimeSpan NavDelay = TimeSpan.FromSeconds(2.0);
+
+ private void ClearPendingNav()
+ {
+ _pendingNav = -1;
+ _navTimer?.Dispose();
+ _navTimer = null;
+ }
+
/// <summary>How long the pointer rests on a group slice before it opens: passing over on the way elsewhere doesn't.</summary>
internal static readonly TimeSpan ExpandDelay = TimeSpan.FromMilliseconds(160);
@@ -107,15 +121,38 @@ public sealed partial class DonutMenu
var sub = -1;
switch (hit.Kind)
{
+ case DonutHitKind.Segment when hit.Index >= 0 && hit.Index < Count && Items![hit.Index].IsNavigation:
+ _expanded = -1;
+ ClearPending();
+ if (!_navCooldown && _pendingNav != hit.Index)
+ {
+ ClearPendingNav();
+ _pendingNav = hit.Index;
+ var navIndex = hit.Index;
+ var delta = Items![navIndex].IsNextPage ? 1 : -1;
+ _navTimer = DispatcherTimer.RunOnce(() =>
+ {
+ ClearPendingNav();
+ _navCooldown = true; // Stay in cooldown while pointer remains on this slot to prevent bounce-back flicker
+ NavigationRequested?.Invoke(this, delta);
+ }, NavDelay);
+ }
+ break;
case DonutHitKind.Segment when hit.Index == _expanded:
+ _navCooldown = false;
+ ClearPendingNav();
_ringFromKeys = false; // the mouse reached it: from here on it leads
break;
case DonutHitKind.Segment when at is { } across && OnWayToRing(across):
+ _navCooldown = false;
+ ClearPendingNav();
// A neighbour's outer half under the open ring, crossed on the way to its outer slices: that neighbour is
// what a click or a drop here converts with, but the ring stays open.
ClearPending();
break;
case DonutHitKind.Segment when hit.Index >= 0 && hit.Index < Count && Items![hit.Index].CanExpand:
+ _navCooldown = false;
+ ClearPendingNav();
_expanded = -1;
var distance = at is { } p ? Distance(p, Center) : 0;
if (_pendingGroup != hit.Index)
@@ -135,22 +172,32 @@ public sealed partial class DonutMenu
}
break;
case DonutHitKind.SubSegment:
+ _navCooldown = false;
+ ClearPendingNav();
_ringFromKeys = false;
sub = hit.Sub;
break;
case DonutHitKind.Outside when _pendingGroup >= 0 && at is { } flick && InFan(flick, _pendingGroup) &&
Distance(flick, Center) <= SubRadii.Outer + BackdropMargin:
+ _navCooldown = false;
+ ClearPendingNav();
ExpandPendingGroup(); // flicked straight out to where its ring opens: no need to wait
break;
case DonutHitKind.Outside:
+ _navCooldown = false;
+ ClearPendingNav();
ClearPending(); // left the slice before it opened: it stays closed
if (_expanded >= 0 && at is { } q && !InFan(q, _expanded))
_expanded = -1; // went round the outside, away from the ring
break;
case DonutHitKind.Center when _ringFromKeys:
+ _navCooldown = false;
+ ClearPendingNav();
sub = _subHover; // on its way out of the hole to the ring
break;
default:
+ _navCooldown = false;
+ ClearPendingNav();
_expanded = -1;
_ringFromKeys = false;
ClearPending();
@@ -278,12 +325,19 @@ public sealed partial class DonutMenu
/// </summary>
public bool Converts(DonutHit hit) => hit.Kind switch
{
- DonutHitKind.Segment => hit.Index >= 0 && hit.Index < Count && Items![hit.Index] is { IsGroup: false, IsEnabled: true },
+ DonutHitKind.Segment => hit.Index >= 0 && hit.Index < Count && Items![hit.Index] is { IsGroup: false, IsNavigation: false, IsEnabled: true },
DonutHitKind.SubSegment => hit.Index >= 0 && hit.Index < Count && Items![hit.Index].Children is { } children &&
hit.Sub >= 0 && hit.Sub < children.Count && children[hit.Sub].IsEnabled,
_ => false,
};
+ /// <summary>True when <paramref name="hit"/> is a page navigation slice.</summary>
+ public bool IsNavigation(DonutHit hit) =>
+ hit.Kind == DonutHitKind.Segment && hit.Index >= 0 && hit.Index < Count && Items![hit.Index] is { IsNavigation: true };
+
+ /// <summary>True when <paramref name="hit"/> accepts a drag drop (conversion slice or page turn slice).</summary>
+ public bool AcceptsDrop(DonutHit hit) => Converts(hit) || IsNavigation(hit);
+
/// <summary>
/// A drag from outside left the window, last seen at <paramref name="lastAt"/>: clears what it lit up and folds a
/// group. Unless it was still on the donut or on the fan of a group that is open or about to open: Windows and macOS
@@ -393,10 +447,8 @@ public sealed partial class DonutMenu
var item = children[k];
var mid = DonutGeometry.SubMidAngle(parentMid, k, children.Count, subSpan);
var wedge = CreateWedge(center, inner, outer, mid, subSpan);
- context.DrawGeometry(WithOpacity(SliceBrush, SliceOpacity * (item.IsEnabled ? 1 : 0.55)), BorderPen(), wedge);
var hot = k == _subHover && group == _expanded && item.IsEnabled;
- if (hot)
- context.DrawGeometry(WithOpacity(AccentBrush, 0.82), null, wedge);
+ DrawGlassSlice(context, wedge, item, center, inner, outer, mid, subSpan, hot ? 1.0 : 0, false);
DrawLabel(context, item, center, (inner + outer) / 2, mid, subSpan * (inner + outer) / 2 - 8,
SubBand - 8, bold, regular, hot);
}
diff --git a/src/Filee.App/Controls/DonutMenu.Progress.cs b/src/Filee.App/Controls/DonutMenu.Progress.cs
index fb0fd851..1f1d22f2 100644
--- a/src/Filee.App/Controls/DonutMenu.Progress.cs
+++ b/src/Filee.App/Controls/DonutMenu.Progress.cs
@@ -289,10 +289,8 @@ public sealed partial class DonutMenu
using (context.PushOpacity(1 - c))
{
var wedge = CreateWedge(center, r1, r2, i, n);
- context.DrawGeometry(WithOpacity(SliceBrush, SliceOpacity), BorderPen(), wedge);
var hot = i == ActiveIndex;
- if (hot)
- context.DrawGeometry(WithOpacity(AccentBrush, 0.8), null, wedge);
+ DrawGlassSlice(context, wedge, Items![i], center, r1, r2, DonutGeometry.MidAngle(i, n), DonutGeometry.Span(n), hot ? 1.0 : 0, false);
// Labels shrink with their slice instead of vanishing when the collapse starts.
DrawLabel(context, Items![i], center, (r1 + r2) / 2, DonutGeometry.MidAngle(i, n),
DonutGeometry.Span(n) * (r1 + r2) / 2 - 10, r2 - r1 - 16, bold, regular, hot);
@@ -302,7 +300,8 @@ public sealed partial class DonutMenu
// The hole shrinks to the size of the ring's plate.
var plate = RingRadius + RingStroke + 2;
var holeRadius = Lerp(r1 - 6, plate, EaseInCubic(collapseAll));
- context.DrawEllipse(CenterBrush, BorderPen(), center, holeRadius, holeRadius);
+ var isDarkHole = CenterBrush is ISolidColorBrush scHole ? ThemeService.Luminance(scHole.Color) < 0.5 : true;
+ DrawCenterDisc(context, center, holeRadius, isDarkHole);
return;
}
@@ -320,8 +319,9 @@ public sealed partial class DonutMenu
using var __ = context.PushOpacity(opacity);
var plateRadius = RingRadius + RingStroke + 2;
+ var isDarkPlate = CenterBrush is ISolidColorBrush scPlate ? ThemeService.Luminance(scPlate.Color) < 0.5 : true;
DrawPlateShadow(context, center, plateRadius);
- context.DrawEllipse(CenterBrush, BorderPen(), center, plateRadius, plateRadius);
+ DrawCenterDisc(context, center, plateRadius, isDarkPlate);
context.DrawEllipse(null, new Pen(WithOpacity(SecondaryForeground, 0.22), RingStroke), center, RingRadius, RingRadius);
var arcBrush = _outcome switch
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.cs
index 2929cb38..350d36c0 100644
--- a/src/Filee.App/Controls/DonutMenu.cs
+++ b/src/Filee.App/Controls/DonutMenu.cs
@@ -44,6 +44,15 @@ public sealed class DonutItem
/// <summary>A group with something to fan out.</summary>
public bool CanExpand => Children is { Count: > 0 };
+
+ /// <summary>True when this slice navigates between pages of presets rather than converting.</summary>
+ public bool IsNavigation { get; init; }
+
+ /// <summary>True when clicking/hovering this slice advances to the next page.</summary>
+ public bool IsNextPage { get; init; }
+
+ /// <summary>True when clicking/hovering this slice returns to the previous page.</summary>
+ public bool IsPrevPage { get; init; }
}
/// <summary>Donut-shaped menu control.</summary>
@@ -400,6 +409,7 @@ public sealed partial class DonutMenu : Control
_span = Enumerable.Range(0, n).Select(_ => new Spring { Value = DonutGeometry.Span(n) }).ToArray();
_expanded = _shownExpanded = _subHover = -1;
ClearPending();
+ ClearPendingNav();
_expand = default;
// The window is reused: a keyboard hold from the last time it was open must not swallow the first moves now.
_keyboardHold = _ringFromKeys = false;
@@ -804,9 +814,7 @@ public sealed partial class DonutMenu : Control
if (n == 0)
{
var ring = CreateRing(center, r1, r2);
- context.DrawGeometry(WithOpacity(SliceBrush, SliceOpacity), BorderPen(), ring);
- if (_dropTargetIndex >= 0)
- context.DrawGeometry(WithOpacity(AccentBrush, 0.35), null, ring);
+ DrawGlassSlice(context, ring, null, center, r1, r2, 0, 2 * Math.PI, 0, _dropTargetIndex >= 0);
}
for (var i = 0; i < n; i++)
@@ -837,12 +845,7 @@ public sealed partial class DonutMenu : Control
using (context.PushOpacity(Math.Clamp(open, 0, 1) * (i == _dimmedIndex ? 0.3 : 1)))
{
var wedge = CreateWedge(center, r1, r2, mid, span);
- context.DrawGeometry(WithOpacity(SliceBrush, SliceOpacity * (item.IsEnabled ? 1 : 0.55)), BorderPen(), wedge);
-
- // The accent fades in and out with the highlight (no floor: a floor made it vanish with a jump).
- var emphasis = i == _dropTargetIndex ? 1.0 : hover;
- if (emphasis > 0.01 && item.IsEnabled)
- context.DrawGeometry(WithOpacity(AccentBrush, 0.82 * Math.Clamp(emphasis, 0, 1)), null, wedge);
+ DrawGlassSlice(context, wedge, item, center, r1, r2, mid, span, hover, i == _dropTargetIndex);
var hot = (i == ActiveIndex || i == _dropTargetIndex) && item.IsEnabled;
DrawLabel(context, item, center, (r1 + r2) / 2, mid, span * (r1 + r2) / 2 - 10,
@@ -867,21 +870,205 @@ public sealed partial class DonutMenu : Control
private void DrawSoftShadow(DrawingContext context, Point center, double r2)
{
- // A radial gradient ring fakes a soft drop shadow without blur effects (cheap on any GPU).
- var shadowRadius = r2 + 14;
- var brush = new RadialGradientBrush
+ var opening = _open.Length == 0 ? 1 : Math.Clamp(_open.Average(), 0, 1);
+ if (opening <= 0.001)
+ return;
+
+ using (context.PushOpacity(opening))
+ {
+ // macOS Tier 1: Large diffuse ambient shadow
+ var ambientRadius = r2 + 28;
+ var ambientBrush = new RadialGradientBrush
+ {
+ GradientStops =
+ {
+ new GradientStop(Color.FromArgb(0, 0, 0, 0), 0),
+ new GradientStop(Color.FromArgb(0, 0, 0, 0), (r2 - 14) / ambientRadius),
+ new GradientStop(Color.FromArgb(26, 0, 0, 0), (r2 - 2) / ambientRadius),
+ new GradientStop(Color.FromArgb(12, 0, 0, 0), (r2 + 10) / ambientRadius),
+ new GradientStop(Color.FromArgb(0, 0, 0, 0), 1),
+ },
+ };
+ context.DrawEllipse(ambientBrush, null, new Point(center.X, center.Y + 4), ambientRadius, ambientRadius);
+
+ // macOS Tier 2: Directional contact key shadow (grounding the wheel to light from above)
+ var keyRadius = r2 + 12;
+ var keyBrush = new RadialGradientBrush
+ {
+ GradientStops =
+ {
+ new GradientStop(Color.FromArgb(0, 0, 0, 0), 0),
+ new GradientStop(Color.FromArgb(0, 0, 0, 0), (r2 - 16) / keyRadius),
+ new GradientStop(Color.FromArgb(52, 0, 0, 0), (r2 - 2) / keyRadius),
+ new GradientStop(Color.FromArgb(0, 0, 0, 0), 1),
+ },
+ };
+ context.DrawEllipse(keyBrush, null, new Point(center.X, center.Y + 7), keyRadius, keyRadius);
+ }
+ }
+
+ private void DrawGlassSlice(DrawingContext context, Geometry wedge, DonutItem? item, Point center,
+ double r1, double r2, double mid, double span, double hover, bool isDropTarget)
+ {
+ var isEnabled = item?.IsEnabled ?? true;
+ var baseOpacity = SliceOpacity * (isEnabled ? 1.0 : 0.55);
+ var isDark = SliceBrush is ISolidColorBrush sc ? ThemeService.Luminance(sc.Color) < 0.5 : true;
+
+ // 1. Frosted Glass Base Gradient (ambient light catching the upper glass)
+ if (SliceBrush is ISolidColorBrush solid)
+ {
+ var c = solid.Color;
+ var topA = (byte)Math.Clamp(c.A * baseOpacity * (isDark ? 0.94 : 0.96), 0, 255);
+ var botA = (byte)Math.Clamp(c.A * baseOpacity * (isDark ? 0.98 : 0.92), 0, 255);
+ var glassFill = new LinearGradientBrush
+ {
+ StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
+ EndPoint = new RelativePoint(0.5, 1, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(isDark
+ ? Color.FromArgb(topA, (byte)Math.Min(255, c.R + 22), (byte)Math.Min(255, c.G + 24), (byte)Math.Min(255, c.B + 28))
+ : Color.FromArgb(topA, 255, 255, 255), 0),
+ new GradientStop(isDark
+ ? Color.FromArgb(botA, (byte)Math.Max(0, c.R - 8), (byte)Math.Max(0, c.G - 8), (byte)Math.Max(0, c.B - 6))
+ : Color.FromArgb(botA, (byte)Math.Max(0, c.R - 10), (byte)Math.Max(0, c.G - 8), (byte)Math.Max(0, c.B - 4)), 1),
+ }
+ };
+ context.DrawGeometry(glassFill, null, wedge);
+ }
+ else
+ {
+ context.DrawGeometry(WithOpacity(SliceBrush, baseOpacity), null, wedge);
+ }
+
+ // 2. Frosted Specular Sheen (Apple macOS physical glass reflection)
+ var sheenBrush = new LinearGradientBrush
{
+ StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
+ EndPoint = new RelativePoint(0.5, 0.75, RelativeUnit.Relative),
GradientStops =
{
- new GradientStop(Color.FromArgb(0, 0, 0, 0), 0),
- new GradientStop(Color.FromArgb(0, 0, 0, 0), (r2 - 18) / shadowRadius),
- new GradientStop(Color.FromArgb(46, 0, 0, 0), (r2 - 2) / shadowRadius),
- new GradientStop(Color.FromArgb(0, 0, 0, 0), 1),
- },
+ new GradientStop(Color.FromArgb((byte)(isDark ? 30 : 65), 255, 255, 255), 0),
+ new GradientStop(Color.FromArgb((byte)(isDark ? 8 : 16), 255, 255, 255), 0.4),
+ new GradientStop(Color.FromArgb(0, 255, 255, 255), 1),
+ }
};
- var opening = _open.Length == 0 ? 1 : Math.Clamp(_open.Average(), 0, 1);
- using (context.PushOpacity(opening))
- context.DrawEllipse(brush, null, new Point(center.X, center.Y + 4), shadowRadius, shadowRadius);
+ context.DrawGeometry(sheenBrush, null, wedge);
+
+ // 3. Specular Glass Hairline Border (1px light-catching rim)
+ var borderBrush = new LinearGradientBrush
+ {
+ StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
+ EndPoint = new RelativePoint(0.5, 1, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(isDark ? Color.FromArgb(64, 255, 255, 255) : Color.FromArgb(135, 255, 255, 255), 0),
+ new GradientStop(isDark ? Color.FromArgb(32, 255, 255, 255) : Color.FromArgb(42, 0, 0, 0), 0.5),
+ new GradientStop(isDark ? Color.FromArgb(18, 255, 255, 255) : Color.FromArgb(24, 0, 0, 0), 1),
+ }
+ };
+ context.DrawGeometry(null, new Pen(borderBrush, 1), wedge);
+
+ // 4. Vibrant Neon Glass Hover / Active Glow
+ var emphasis = isDropTarget ? 1.0 : hover;
+ if (emphasis > 0.01 && isEnabled)
+ {
+ var clampedEmp = Math.Clamp(emphasis, 0, 1);
+ if (AccentBrush is ISolidColorBrush accentSolid)
+ {
+ var ac = accentSolid.Color;
+ var hoverFill = new RadialGradientBrush
+ {
+ Center = new RelativePoint(0.5, 0.45, RelativeUnit.Relative),
+ GradientOrigin = new RelativePoint(0.5, 0.45, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(Color.FromArgb((byte)(225 * clampedEmp), ac.R, ac.G, ac.B), 0),
+ new GradientStop(Color.FromArgb((byte)(185 * clampedEmp), (byte)Math.Max(0, ac.R - 15), (byte)Math.Max(0, ac.G - 15), (byte)Math.Max(0, ac.B - 15)), 1),
+ }
+ };
+ context.DrawGeometry(hoverFill, null, wedge);
+
+ // Specular inner sheen for the hot state
+ var hotSheen = new LinearGradientBrush
+ {
+ StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
+ EndPoint = new RelativePoint(0.5, 0.6, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(Color.FromArgb((byte)(80 * clampedEmp), 255, 255, 255), 0),
+ new GradientStop(Color.FromArgb(0, 255, 255, 255), 1),
+ }
+ };
+ context.DrawGeometry(hotSheen, null, wedge);
+
+ // Glowing rim on hover
+ var glowPen = new Pen(new SolidColorBrush(Color.FromArgb((byte)(235 * clampedEmp), (byte)Math.Min(255, ac.R + 32), (byte)Math.Min(255, ac.G + 32), (byte)Math.Min(255, ac.B + 32))), 1.2);
+ context.DrawGeometry(null, glowPen, wedge);
+ }
+ else
+ {
+ context.DrawGeometry(WithOpacity(AccentBrush, 0.82 * clampedEmp), null, wedge);
+ }
+ }
+ }
+
+ private void DrawCenterDisc(DrawingContext context, Point center, double radius, bool isDark)
+ {
+ // 1. Frosted glass disc fill with top-to-bottom illumination gradient
+ if (CenterBrush is ISolidColorBrush solid)
+ {
+ var baseC = solid.Color;
+ var centerFill = new LinearGradientBrush
+ {
+ StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
+ EndPoint = new RelativePoint(0.5, 1, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(isDark
+ ? Color.FromArgb(baseC.A, (byte)Math.Min(255, baseC.R + 20), (byte)Math.Min(255, baseC.G + 20), (byte)Math.Min(255, baseC.B + 24))
+ : Color.FromArgb(baseC.A, 255, 255, 255), 0),
+ new GradientStop(isDark
+ ? Color.FromArgb(baseC.A, (byte)Math.Max(0, baseC.R - 8), (byte)Math.Max(0, baseC.G - 8), (byte)Math.Max(0, baseC.B - 6))
+ : Color.FromArgb(baseC.A, (byte)Math.Max(0, baseC.R - 8), (byte)Math.Max(0, baseC.G - 6), (byte)Math.Max(0, baseC.B - 4)), 1),
+ }
+ };
+ context.DrawEllipse(centerFill, null, center, radius, radius);
+ }
+ else
+ {
+ context.DrawEllipse(CenterBrush, null, center, radius, radius);
+ }
+
+ // 3. Inner glass lens specular reflection dome
+ var lensGleam = new RadialGradientBrush
+ {
+ Center = new RelativePoint(0.5, 0.35, RelativeUnit.Relative),
+ GradientOrigin = new RelativePoint(0.5, 0.35, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(Color.FromArgb((byte)(isDark ? 28 : 55), 255, 255, 255), 0),
+ new GradientStop(Color.FromArgb(0, 255, 255, 255), 1),
+ }
+ };
+ context.DrawEllipse(lensGleam, null, center, radius, radius);
+
+ // 4. Specular glass hairline rim
+ var centerBorder = new LinearGradientBrush
+ {
+ StartPoint = new RelativePoint(0.5, 0, RelativeUnit.Relative),
+ EndPoint = new RelativePoint(0.5, 1, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(isDark ? Color.FromArgb(70, 255, 255, 255) : Color.FromArgb(130, 255, 255, 255), 0),
+ new GradientStop(isDark ? Color.FromArgb(30, 255, 255, 255) : Color.FromArgb(40, 0, 0, 0), 0.5),
+ new GradientStop(isDark ? Color.FromArgb(16, 255, 255, 255) : Color.FromArgb(20, 0, 0, 0), 1),
+ }
+ };
+ context.DrawEllipse(null, new Pen(centerBorder, 1), center, radius, radius);
+
+ // 5. Inset subtle bright bevel
+ context.DrawEllipse(null, new Pen(new SolidColorBrush(Colors.White, isDark ? 0.05 : 0.35), 0.5), center, radius - 1, radius - 1);
}
private void DrawCenter(DrawingContext context, Point center, double r1, Typeface bold, Typeface regular)
@@ -889,9 +1076,23 @@ public sealed partial class DonutMenu : Control
var pulse = 1 + _centerPulse.Value * 0.06;
var radius = (r1 - 6) * pulse;
var cancelHot = _externalCenterHot;
- context.DrawEllipse(CenterBrush, BorderPen(), center, radius, radius);
+ var isDark = CenterBrush is ISolidColorBrush sc ? ThemeService.Luminance(sc.Color) < 0.5 : true;
+
+ DrawCenterDisc(context, center, radius, isDark);
+
if (cancelHot)
- context.DrawEllipse(WithOpacity(DangerBrush, 0.18), null, center, radius, radius);
+ {
+ var dangerGlow = new RadialGradientBrush
+ {
+ Center = new RelativePoint(0.5, 0.5, RelativeUnit.Relative),
+ GradientStops =
+ {
+ new GradientStop(Color.FromArgb(60, 220, 60, 60), 0),
+ new GradientStop(Color.FromArgb(100, 200, 40, 40), 1),
+ }
+ };
+ context.DrawEllipse(dangerGlow, new Pen(DangerBrush, 1.2), center, radius, radius);
+ }
var maxWidth = radius * 1.6;
var title = MakeText(CenterTitle ?? "", bold, 14, Foreground, maxWidth, maxLines: 2);
@@ -914,12 +1115,24 @@ public sealed partial class DonutMenu : Control
label.Height + 14 < maxHeight;
var caption = showCaption ? MakeText(item.Caption!, regular, 10.5, hot ? OnAccentBrush : SecondaryForeground, width) : null;
- var total = label.Height + (caption?.Height ?? 0);
+ var total = label.Height + (caption?.Height ?? 0) + (item.IsNavigation && showCaption ? 4 : 0);
var anchor = DonutGeometry.PointAt(center, radius, angle);
var y = anchor.Y - total / 2;
DrawCentered(context, label, anchor.X, y);
if (caption is not null)
- DrawCentered(context, caption, anchor.X, y + label.Height);
+ {
+ var captionY = y + label.Height + (item.IsNavigation ? 3 : 0);
+ if (item.IsNavigation && !hot)
+ {
+ // Sleek macOS glass pill around page numbers e.g. "1/2"
+ var isDark = SliceBrush is ISolidColorBrush sc ? ThemeService.Luminance(sc.Color) < 0.5 : true;
+ var pillWidth = Math.Max(caption.Width + 12, 34);
+ var pillRect = new Rect(anchor.X - pillWidth / 2, captionY - 1, pillWidth, caption.Height + 2);
+ var pillFill = new SolidColorBrush(isDark ? Color.FromArgb(45, 255, 255, 255) : Color.FromArgb(25, 0, 0, 0));
+ context.DrawRectangle(pillFill, null, new RoundedRect(pillRect, 7));
+ }
+ DrawCentered(context, caption, anchor.X, captionY);
+ }
}
private Point EditButtonCenter(int index)
diff --git a/src/Filee.App/Services/CropService.cs b/src/Filee.App/Services/CropService.cs
new file mode 100644
index 00000000..e99abc88
--- /dev/null
+++ b/src/Filee.App/Services/CropService.cs
@@ -0,0 +1,84 @@
+// Service that loads images and executes cropping via ImageMagick.
+
+using System.IO;
+using Avalonia.Media.Imaging;
+using Filee.Core.Presets;
+using ImageMagick;
+
+namespace Filee.App.Services;
+
+public static class CropService
+{
+ /// <summary>
+ /// Loads an image as a standard Avalonia Bitmap along with its true pixel dimensions,
+ /// properly oriented according to EXIF.
+ /// </summary>
+ public static async Task<(Bitmap Bitmap, int Width, int Height)> LoadPreviewAsync(string inputPath)
+ {
+ return await Task.Run(() =>
+ {
+ using var image = new MagickImage(inputPath);
+ image.AutoOrient();
+ var origWidth = (int)image.Width;
+ var origHeight = (int)image.Height;
+
+ // Generate an in-memory PNG for the Avalonia viewport
+ // If the source image is huge (e.g. 40MP camera RAW/photo), scale preview down for UI fluidity
+ var maxDisplayDim = 2560;
+ if (image.Width > maxDisplayDim || image.Height > maxDisplayDim)
+ {
+ image.Resize(new MagickGeometry((uint)maxDisplayDim, (uint)maxDisplayDim) { Greater = true });
+ }
+
+ using var mem = new MemoryStream();
+ image.Write(mem, MagickFormat.Png);
+ mem.Position = 0;
+ var bitmap = new Bitmap(mem);
+
+ return (bitmap, origWidth, origHeight);
+ });
+ }
+
+ /// <summary>
+ /// Crops the image at <paramref name="inputPath"/> with the given pixel coordinates and saves the result.
+ /// </summary>
+ public static async Task<string> CropFileAsync(string inputPath, int x, int y, int width, int height, Preset? preset = null)
+ {
+ return await Task.Run(() =>
+ {
+ var dir = Path.GetDirectoryName(inputPath) ?? "";
+ var nameWithoutExt = Path.GetFileNameWithoutExtension(inputPath);
+ var ext = Path.GetExtension(inputPath);
+
+ var pattern = preset?.Output.FileNamePattern ?? "{name}_cropped";
+ var outputName = pattern.Replace("{name}", nameWithoutExt) + ext;
+ var outputPath = Path.Combine(dir, outputName);
+
+ // Avoid collisions
+ var counter = 1;
+ while (File.Exists(outputPath))
+ {
+ outputPath = Path.Combine(dir, $"{pattern.Replace("{name}", nameWithoutExt)}_{counter}{ext}");
+ counter++;
+ }
+
+ using var image = new MagickImage(inputPath);
+ image.AutoOrient();
+
+ var clampedX = Math.Clamp(x, 0, Math.Max(0, (int)image.Width - 1));
+ var clampedY = Math.Clamp(y, 0, Math.Max(0, (int)image.Height - 1));
+ var clampedW = (uint)Math.Clamp(width, 1, Math.Max(1, (int)image.Width - clampedX));
+ var clampedH = (uint)Math.Clamp(height, 1, Math.Max(1, (int)image.Height - clampedY));
+
+ image.Crop(new MagickGeometry(clampedX, clampedY, clampedW, clampedH));
+ image.ResetPage();
+
+ // Quality
+ if (preset?.Image.Quality is > 0 and <= 100)
+ image.Quality = (uint)preset.Image.Quality;
+
+ image.Write(outputPath);
+ return outputPath;
+ });
+ }
+}
diff --git a/src/Filee.App/Services/PresetAvailability.cs b/src/Filee.App/Services/PresetAvailability.cs
index 742786eb..5076d342 100644
--- a/src/Filee.App/Services/PresetAvailability.cs
+++ b/src/Filee.App/Services/PresetAvailability.cs
@@ -15,6 +15,13 @@ public sealed class PresetAvailability(ConverterCatalog catalog, ILocalizer loc,
/// </summary>
public string? Check(Preset preset, IReadOnlyList<FileFormat> formats)
{
+ if (preset.Kind == PresetKind.Tool)
+ {
+ if (preset.Id == "tool-crop")
+ return formats.Any(f => f.Category == FormatCategory.Image || f.Id == "pdf") ? null : loc["error.unsupported_source"];
+ return null;
+ }
+
// "Compress into one archive" packs the files as they are, so any file works, even of an unknown type.
if (preset.Archive.CombineIntoOne
&& FormatRegistry.FindById(preset.TargetFormat) is { Category: FormatCategory.Archive } archive
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.cs
index 3456df0a..e8128444 100644
--- a/src/Filee.App/Services/RadialController.cs
+++ b/src/Filee.App/Services/RadialController.cs
@@ -19,6 +19,7 @@ using Filee.App.ViewModels;
using Filee.App.Views;
using Filee.Core.Conversion;
using Filee.Core.Platform;
+using Filee.Core.Presets;
using Filee.Core.Profiles;
using Filee.Core.Settings;
using Microsoft.Extensions.Logging;
@@ -53,6 +54,7 @@ public sealed class RadialController(
private static readonly LogThrottle Throttle = new(TimeSpan.FromMinutes(1));
private bool _converted; // a conversion started from the files on the donut now
private readonly HashSet<string> _formatRequestsOffered = new(StringComparer.OrdinalIgnoreCase);
+ private TriggerGesture? _activeGesture;
/// <summary>
/// How long a drag that never brought files may keep the invisible window up, in case the button release is
@@ -69,8 +71,9 @@ public sealed class RadialController(
/// invisible until files are dragged into it (FilesEntered); a gesture without files (text, a rubber-band
/// selection, nothing at all) never shows anything and closes when the button is released.
/// </summary>
- public void ShowForDrag(int x, int y)
+ public void ShowForDrag(int x, int y, TriggerGesture? gesture = null)
{
+ _activeGesture = gesture;
ReleaseProgressToToast();
var window = EnsureWindow();
// A ring from an earlier conversion (finished or handed to the toast) must not keep this gesture's window up.
@@ -191,12 +194,19 @@ public sealed class RadialController(
{
if (viewModel.IsClickMode || SameFiles(files, viewModel.Files))
return;
- viewModel.Load(files, clickMode: false);
+ viewModel.Load(files, clickMode: false, profileId: _activeGesture?.TargetProfileId);
donut.PlayOpenAnimation();
};
window.Dropped += (hit, files) =>
{
_dropped = true;
+ if (hit.Kind is DonutHitKind.Segment && viewModel.IsNavigationAt(hit.Index))
+ {
+ viewModel.NavigateAt(hit.Index);
+ donut.PlayOpenAnimation();
+ _dropped = false;
+ return;
+ }
if (hit.Kind is DonutHitKind.Segment or DonutHitKind.SubSegment)
Convert(hit.Index, hit.Sub, files.Count > 0 ? files : viewModel.Files);
else
@@ -215,7 +225,21 @@ public sealed class RadialController(
};
donut.ActiveIndexChanged += (_, index) => viewModel.ShowHint(index, donut.ActiveSubIndex, donut.IsCenterHot);
- donut.SegmentInvoked += (_, index) => Convert(index, -1, viewModel.Files);
+ donut.SegmentInvoked += (_, index) =>
+ {
+ if (viewModel.IsNavigationAt(index))
+ {
+ viewModel.NavigateAt(index);
+ donut.PlayOpenAnimation();
+ return;
+ }
+ Convert(index, -1, viewModel.Files);
+ };
+ donut.NavigationRequested += (_, delta) =>
+ {
+ viewModel.CyclePage(delta);
+ donut.PlayOpenAnimation();
+ };
donut.SubSegmentInvoked += (_, hit) => Convert(hit.Group, hit.Sub, viewModel.Files);
donut.CenterInvoked += (_, _) => Close();
donut.SegmentContextRequested += async (_, index) => await EditPresetAsync(index);
@@ -240,6 +264,13 @@ public sealed class RadialController(
return;
}
+ if (preset.Kind == PresetKind.Tool && preset.Id == "tool-crop")
+ {
+ Close(animate: false);
+ windows.ShowCropOverlay(files, preset);
+ return;
+ }
+
log.LogInformation("Converting {Count} file(s) with preset {Preset}", files.Count, preset.Id);
var job = conversions.Start(files, preset, showInToast: false);
if (job is null || _window is null)
diff --git a/src/Filee.App/Services/ThemeService.cs b/src/Filee.App/Services/ThemeService.cs
index e87ca333..93f6a01e 100644
--- a/src/Filee.App/Services/ThemeService.cs
+++ b/src/Filee.App/Services/ThemeService.cs
@@ -20,7 +20,7 @@ public sealed class ThemeService(IPlatformServices platform)
private const string Latin = "fonts:Filee#Noto Sans";
private const string Korean = "fonts:Filee#Noto Sans KR";
private const string Chinese = "fonts:Filee#Noto Sans SC";
- private const string SystemFallbacks = "Segoe UI, Malgun Gothic, Microsoft YaHei, PingFang SC, Apple SD Gothic Neo, sans-serif";
+ private const string SystemFallbacks = "-apple-system, BlinkMacSystemFont, \"SF Pro Text\", \"SF Pro Display\", Helvetica Neue, Segoe UI, Malgun Gothic, Microsoft YaHei, PingFang SC, Apple SD Gothic Neo, sans-serif";
public void Apply(ThemeSettings theme, string language)
{
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index a5ded8cb..ab0b115e 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -27,8 +27,28 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mem
internal FormatRequestNoticeWindow? FormatRequestNotice => _formatRequestNotice;
+ private CropOverlayWindow? _cropOverlay;
+
public MainWindow? Main => _main;
+ /// <summary>Opens the zero-window interactive Crop overlay HUD.</summary>
+ public void ShowCropOverlay(IReadOnlyList<string> files, Preset preset)
+ {
+ if (files.Count == 0)
+ return;
+ _cropOverlay?.Close();
+ var vm = new CropOverlayViewModel(files, preset, loc);
+ var win = new CropOverlayWindow { DataContext = vm };
+ win.Closed += (_, _) =>
+ {
+ if (_cropOverlay == win)
+ _cropOverlay = null;
+ };
+ _cropOverlay = win;
+ win.Show();
+ win.Activate();
+ }
+
/// <summary>
/// Shows (or brings to front) the main window, optionally on a page. Going to the tray closes it
/// (<see cref="MainWindow.HideToTray"/>): a new one opens where and on the page the last one was.
diff --git a/src/Filee.App/Styles/Icons.axaml b/src/Filee.App/Styles/Icons.axaml
index b1b2e4e8..5f4ec65d 100644
--- a/src/Filee.App/Styles/Icons.axaml
+++ b/src/Filee.App/Styles/Icons.axaml
@@ -33,4 +33,5 @@
<StreamGeometry x:Key="Icon.Heart">M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z</StreamGeometry>
<StreamGeometry x:Key="Icon.Refresh">M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z</StreamGeometry>
<StreamGeometry x:Key="Icon.Record">M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7Z</StreamGeometry>
+ <StreamGeometry x:Key="Icon.Crop">M7,17V1H5V5H1V7H5V17A2,2 0 0,0 7,19H17V23H19V19H23V17M17,15H19V7C19,5.89 18.1,5 17,5H9V7H17V15Z</StreamGeometry>
</ResourceDictionary>
diff --git a/src/Filee.App/Styles/Soft.axaml b/src/Filee.App/Styles/Soft.axaml
index e1f8e23d..6a6edeac 100644
--- a/src/Filee.App/Styles/Soft.axaml
+++ b/src/Filee.App/Styles/Soft.axaml
@@ -45,7 +45,7 @@
<CornerRadius x:Key="SoftRadius">16</CornerRadius>
<CornerRadius x:Key="SoftRadiusSmall">9</CornerRadius>
<CornerRadius x:Key="SoftRadiusLarge">22</CornerRadius>
- <FontFamily x:Key="AppFontFamily">Segoe UI, Malgun Gothic, Microsoft YaHei, sans-serif</FontFamily>
+ <FontFamily x:Key="AppFontFamily">-apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Segoe UI, Malgun Gothic, Microsoft YaHei, sans-serif</FontFamily>
<!-- Springy easing used by press/hover transitions ("말랑말랑"). -->
<BackEaseOut x:Key="SoftEase" />
diff --git a/src/Filee.App/ViewModels/CropOverlayViewModel.cs b/src/Filee.App/ViewModels/CropOverlayViewModel.cs
new file mode 100644
index 00000000..9046e3ba
--- /dev/null
+++ b/src/Filee.App/ViewModels/CropOverlayViewModel.cs
@@ -0,0 +1,181 @@
+// ViewModel driving the zero-window Crop overlay dialog.
+
+using System.IO;
+using Avalonia;
+using Avalonia.Media.Imaging;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using Filee.App.Services;
+using Filee.Core.Localization;
+using Filee.Core.Presets;
+
+namespace Filee.App.ViewModels;
+
+public sealed partial class CropOverlayViewModel : ObservableObject
+{
+ private readonly IReadOnlyList<string> _files;
+ private readonly Preset _preset;
+ private readonly ILocalizer _loc;
+
+ [ObservableProperty] private int _currentIndex;
+ [ObservableProperty] private string _currentFileName = "";
+ [ObservableProperty] private string _counterText = "";
+ [ObservableProperty] private bool _hasMultipleFiles;
+ [ObservableProperty] private Bitmap? _previewImage;
+ [ObservableProperty] private int _originalWidth;
+ [ObservableProperty] private int _originalHeight;
+ [ObservableProperty] private string _dimensionsText = "";
+ [ObservableProperty] private bool _isBusy;
+ [ObservableProperty] private double _aspectRatio;
+ [ObservableProperty]
+ [NotifyPropertyChangedFor(nameof(IsAspectFree))]
+ [NotifyPropertyChangedFor(nameof(IsAspectOriginal))]
+ [NotifyPropertyChangedFor(nameof(IsAspectSquare))]
+ [NotifyPropertyChangedFor(nameof(IsAspect45))]
+ [NotifyPropertyChangedFor(nameof(IsAspect916))]
+ [NotifyPropertyChangedFor(nameof(IsAspect169))]
+ [NotifyPropertyChangedFor(nameof(IsAspect43))]
+ private string _selectedAspect = "free";
+
+ public bool IsAspectFree => SelectedAspect == "free";
+ public bool IsAspectOriginal => SelectedAspect == "original";
+ public bool IsAspectSquare => SelectedAspect == "1:1";
+ public bool IsAspect45 => SelectedAspect == "4:5";
+ public bool IsAspect916 => SelectedAspect == "9:16";
+ public bool IsAspect169 => SelectedAspect == "16:9";
+ public bool IsAspect43 => SelectedAspect == "4:3";
+
+ public event Action? CloseRequested;
+ public event Action? ResetRequested;
+ public event Action<double>? AspectRatioChanged;
+
+ public Rect CurrentCropRect { get; set; } = new(0.1, 0.1, 0.8, 0.8);
+
+ public CropOverlayViewModel(IReadOnlyList<string> files, Preset preset, ILocalizer loc)
+ {
+ _files = files;
+ _preset = preset;
+ _loc = loc;
+ _hasMultipleFiles = files.Count > 1;
+
+ _ = LoadFileAsync(0);
+ }
+
+ public async Task LoadFileAsync(int index)
+ {
+ if (index < 0 || index >= _files.Count)
+ {
+ CloseRequested?.Invoke();
+ return;
+ }
+
+ IsBusy = true;
+ CurrentIndex = index;
+ var path = _files[index];
+ CurrentFileName = Path.GetFileName(path);
+ CounterText = _loc.Format("crop.page_counter", index + 1, _files.Count);
+
+ try
+ {
+ var (bitmap, origW, origH) = await CropService.LoadPreviewAsync(path);
+ PreviewImage = bitmap;
+ OriginalWidth = origW;
+ OriginalHeight = origH;
+ SelectedAspect = "free";
+ AspectRatio = 0;
+ CurrentCropRect = new Rect(0.05, 0.05, 0.9, 0.9);
+ UpdateDimensions(CurrentCropRect);
+ ResetRequested?.Invoke();
+ }
+ catch (Exception)
+ {
+ // If failed to load this file, advance or close
+ if (index < _files.Count - 1)
+ await LoadFileAsync(index + 1);
+ else
+ CloseRequested?.Invoke();
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ public void UpdateDimensions(Rect norm)
+ {
+ CurrentCropRect = norm;
+ var pixelW = Math.Max(1, (int)Math.Round(norm.Width * OriginalWidth));
+ var pixelH = Math.Max(1, (int)Math.Round(norm.Height * OriginalHeight));
+ DimensionsText = $"{pixelW} × {pixelH} px";
+ }
+
+ [RelayCommand]
+ public async Task CropAndSaveAsync()
+ {
+ if (IsBusy || CurrentIndex >= _files.Count)
+ return;
+
+ IsBusy = true;
+ var path = _files[CurrentIndex];
+ var x = (int)Math.Round(CurrentCropRect.X * OriginalWidth);
+ var y = (int)Math.Round(CurrentCropRect.Y * OriginalHeight);
+ var w = (int)Math.Round(CurrentCropRect.Width * OriginalWidth);
+ var h = (int)Math.Round(CurrentCropRect.Height * OriginalHeight);
+
+ try
+ {
+ await CropService.CropFileAsync(path, x, y, w, h, _preset);
+ }
+ catch (Exception)
+ {
+ // Log/ignore and proceed
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+
+ if (CurrentIndex < _files.Count - 1)
+ {
+ await LoadFileAsync(CurrentIndex + 1);
+ }
+ else
+ {
+ CloseRequested?.Invoke();
+ }
+ }
+
+ [RelayCommand]
+ public void Reset()
+ {
+ SelectedAspect = "free";
+ AspectRatio = 0;
+ AspectRatioChanged?.Invoke(0);
+ ResetRequested?.Invoke();
+ }
+
+ [RelayCommand]
+ public void Cancel()
+ {
+ CloseRequested?.Invoke();
+ }
+
+ [RelayCommand]
+ public void SetAspect(string mode)
+ {
+ SelectedAspect = mode;
+ double ratio = mode switch
+ {
+ "free" => 0,
+ "original" => OriginalHeight > 0 ? (double)OriginalWidth / OriginalHeight : 0,
+ "1:1" => 1.0,
+ "4:5" => 4.0 / 5.0,
+ "9:16" => 9.0 / 16.0,
+ "16:9" => 16.0 / 9.0,
+ "4:3" => 4.0 / 3.0,
+ _ => 0,
+ };
+ AspectRatio = ratio;
+ AspectRatioChanged?.Invoke(ratio);
+ }
+}
diff --git a/src/Filee.App/ViewModels/RadialViewModel.cs b/src/Filee.App/ViewModels/RadialViewModel.cs
index 37f25c5b..f2f6d4ae 100644
--- a/src/Filee.App/ViewModels/RadialViewModel.cs
+++ b/src/Filee.App/ViewModels/RadialViewModel.cs
@@ -40,33 +40,43 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
/// </summary>
[ObservableProperty] private string _hitBackground = "Transparent";
+ [ObservableProperty] private int _currentPage;
+ [ObservableProperty] private int _totalPages = 1;
+
+ /// <summary>Maximum number of slices shown on one page of the donut.</summary>
+ public const int MaxPageSlices = ToolbarProfile.MaxSlices;
+
/// <summary>Files the donut will convert (empty while waiting for a drag to enter).</summary>
public IReadOnlyList<string> Files { get; private set; } = [];
- /// <summary>Presets in slice order.</summary>
+ /// <summary>Presets on the current page in slice order.</summary>
public IReadOnlyList<Preset> Presets { get; private set; } = [];
- /// <summary>For each slice, the presets its group fans out (empty for an ordinary preset).</summary>
+ /// <summary>For each slice on the current page, the presets its group fans out.</summary>
private IReadOnlyList<IReadOnlyList<Preset>> _subPresets = [];
+ private IReadOnlyList<Preset> _allPresets = [];
+ private IReadOnlyList<IReadOnlyList<Preset>> _allSubPresets = [];
+ private IReadOnlyList<DonutItem> _allItems = [];
+
/// <summary>
/// The preset that slice <paramref name="index"/> converts with, or slice <paramref name="sub"/> of its group's ring;
- /// null when there is none or it can't convert these files.
+ /// null when there is none, or when the slice is a navigation page-flip control.
/// </summary>
public Preset? PresetAt(int index, int sub)
{
- if (index < 0 || index >= Items.Count)
+ if (index < 0 || index >= Items.Count || Items[index].IsNavigation)
return null;
if (sub < 0)
- return Items[index] is { IsEnabled: true, IsGroup: false } ? Presets[index] : null;
- return Items[index].Children is { } children && sub < children.Count && children[sub].IsEnabled
+ return Items[index] is { IsEnabled: true, IsGroup: false } && index < Presets.Count ? Presets[index] : null;
+ return Items[index].Children is { } children && sub < children.Count && children[sub].IsEnabled && index < _subPresets.Count
? _subPresets[index][sub]
: null;
}
/// <summary>The preset slice <paramref name="index"/> shows, or slice <paramref name="sub"/> of its group's ring (to edit it).</summary>
public Preset? PresetShownAt(int index, int sub) =>
- index < 0 || index >= Presets.Count ? null
+ index < 0 || index >= Presets.Count || (index < Items.Count && Items[index].IsNavigation) ? null
: sub < 0 ? Presets[index]
: sub < _subPresets[index].Count ? _subPresets[index][sub] : null;
@@ -75,6 +85,48 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
public bool HasFiles => Files.Count > 0;
+ /// <summary>True if the slice at <paramref name="index"/> is a page navigation control.</summary>
+ public bool IsNavigationAt(int index) =>
+ index >= 0 && index < Items.Count && Items[index].IsNavigation;
+
+ /// <summary>Navigates page if the slice at <paramref name="index"/> is a navigation item.</summary>
+ public bool NavigateAt(int index)
+ {
+ if (!IsNavigationAt(index))
+ return false;
+ if (Items[index].IsNextPage)
+ NextPage();
+ else if (Items[index].IsPrevPage)
+ PrevPage();
+ return true;
+ }
+
+ public void NextPage()
+ {
+ if (TotalPages <= 1)
+ return;
+ CurrentPage = (CurrentPage + 1) % TotalPages;
+ ApplyPage();
+ }
+
+ public void PrevPage()
+ {
+ if (TotalPages <= 1)
+ return;
+ CurrentPage = (CurrentPage - 1 + TotalPages) % TotalPages;
+ ApplyPage();
+ }
+
+ public void CyclePage(int delta)
+ {
+ if (TotalPages <= 1)
+ return;
+ if (delta > 0)
+ NextPage();
+ else if (delta < 0)
+ PrevPage();
+ }
+
/// <summary>Drag mode before any file entered: an empty ring saying "Bring files here".</summary>
public void ResetForDrag()
{
@@ -82,6 +134,11 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
Files = [];
Presets = [];
_subPresets = [];
+ _allPresets = [];
+ _allSubPresets = [];
+ _allItems = [];
+ CurrentPage = 0;
+ TotalPages = 1;
ApplyAppearance();
ReserveSubRing = store.Profiles.Any(profile => profile.PresetIds.Any(id => store.FindPreset(id)?.IsGroup == true));
Items = [];
@@ -92,7 +149,7 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
}
/// <summary>Fills the donut for the given files.</summary>
- public void Load(IReadOnlyList<string> files, bool clickMode)
+ public void Load(IReadOnlyList<string> files, bool clickMode, string? profileId = null)
{
IsClickMode = clickMode;
Files = files;
@@ -100,14 +157,15 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
HitBackground = "Transparent";
ApplyAppearance();
- var profile = ProfileSelector.Select(store.Profiles, files);
+ var profile = (!string.IsNullOrEmpty(profileId) ? store.Profiles.FirstOrDefault(p => p.Id == profileId) : null)
+ ?? ProfileSelector.Select(store.Profiles, files);
var formats = ProfileSelector.DetectFormats(files);
- Presets = (profile?.PresetIds ?? [])
+ _allPresets = (profile?.PresetIds ?? [])
.Select(store.FindPreset)
.OfType<Preset>()
.ToList();
- _subPresets = Presets
+ _allSubPresets = _allPresets
.Select(p => (IReadOnlyList<Preset>)(p.IsGroup ? p.SubPresetIds : [])
.Select(store.FindPreset).OfType<Preset>().Where(c => !c.IsGroup).Take(Preset.MaxSubPresets).ToList())
.ToList();
@@ -118,7 +176,6 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
return new DonutItem
{
Id = p.Id,
- // On a group's ring the group's name gives the context: "Rotate" → Left / Right / 180°.
Label = caption ? loc.DisplayName(p) : loc.RingName(p),
Caption = !caption ? null
: p.TargetFormat == BuiltInData.SameAsSource
@@ -129,49 +186,167 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,
};
}
- Items = Presets.Select((p, i) =>
+ _allItems = _allPresets.Select((p, i) =>
{
if (!p.IsGroup)
return ItemOf(p);
- // A group: its own name and size, and its presets on the ring it fans out (labels only, they're small).
- var children = _subPresets[i].Select(c => ItemOf(c, caption: false)).ToList();
+ var children = _allSubPresets[i].Select(c => ItemOf(c, caption: false)).ToList();
return new DonutItem
{
Id = p.Id,
Label = loc.DisplayName(p),
Caption = loc.Format("donut.group_caption", children.Count),
IsEnabled = children.Any(c => c.IsEnabled),
- // Its presets were all deleted since it was made: say so rather than show a dead slice.
DisabledReason = children.Count == 0 ? loc["donut.group_empty"]
: children.Select(c => c.DisabledReason).FirstOrDefault(r => r is not null),
Children = children,
};
}).ToList();
+ CurrentPage = 0;
+ CalculatePages();
+ ApplyPage();
+
CenterTitle = formats.Count == 1
? loc.Format("donut.files_same", files.Count, formats[0].DisplayName)
: loc.Format("donut.files_mixed", files.Count);
- CenterSubtitle = clickMode ? loc["donut.close_hint"] : null;
+ UpdateCenterSubtitle();
+ }
+
+ private void CalculatePages()
+ {
+ if (_allItems.Count <= MaxPageSlices)
+ {
+ TotalPages = 1;
+ return;
+ }
+
+ // Page 0: (MaxPageSlices - 1) items + 1 Next item
+ var remaining = _allItems.Count - (MaxPageSlices - 1);
+ var pages = 1;
+ while (remaining > 0)
+ {
+ pages++;
+ if (remaining <= MaxPageSlices - 1)
+ break;
+ remaining -= (MaxPageSlices - 2); // Middle pages have both Prev and Next
+ }
+ TotalPages = Math.Max(1, pages);
+ }
+
+ private void ApplyPage()
+ {
+ if (TotalPages <= 1 || _allItems.Count <= MaxPageSlices)
+ {
+ Items = _allItems;
+ Presets = _allPresets;
+ _subPresets = _allSubPresets;
+ UpdateCenterSubtitle();
+ return;
+ }
+
+ var pageItems = new List<DonutItem>();
+ var pagePresets = new List<Preset>();
+ var pageSubPresets = new List<IReadOnlyList<Preset>>();
+
+ int startIndex;
+ int takeCount;
+ var hasPrev = CurrentPage > 0;
+ var hasNext = CurrentPage < TotalPages - 1;
+
+ if (CurrentPage == 0)
+ {
+ startIndex = 0;
+ takeCount = MaxPageSlices - 1;
+ }
+ else
+ {
+ startIndex = (MaxPageSlices - 1) + (CurrentPage - 1) * (MaxPageSlices - 2);
+ takeCount = hasNext ? MaxPageSlices - 2 : _allItems.Count - startIndex;
+ }
+
+ if (hasPrev)
+ {
+ pageItems.Add(new DonutItem
+ {
+ Id = "__nav_prev",
+ Label = loc["donut.back"],
+ Caption = $"{CurrentPage + 1}/{TotalPages}",
+ IsNavigation = true,
+ IsPrevPage = true,
+ IsEnabled = true,
+ });
+ pagePresets.Add(new Preset { Id = "__nav_prev", Name = loc["donut.back"] });
+ pageSubPresets.Add([]);
+ }
+
+ for (var i = 0; i < takeCount && startIndex + i < _allItems.Count; i++)
+ {
+ var idx = startIndex + i;
+ pageItems.Add(_allItems[idx]);
+ pagePresets.Add(_allPresets[idx]);
+ pageSubPresets.Add(_allSubPresets[idx]);
+ }
+
+ if (hasNext)
+ {
+ pageItems.Add(new DonutItem
+ {
+ Id = "__nav_next",
+ Label = loc["donut.more"],
+ Caption = $"{CurrentPage + 1}/{TotalPages}",
+ IsNavigation = true,
+ IsNextPage = true,
+ IsEnabled = true,
+ });
+ pagePresets.Add(new Preset { Id = "__nav_next", Name = loc["donut.more"] });
+ pageSubPresets.Add([]);
+ }
+
+ Items = pageItems;
+ Presets = pagePresets;
+ _subPresets = pageSubPresets;
+ UpdateCenterSubtitle();
+ }
+
+ private void UpdateCenterSubtitle()
+ {
+ if (TotalPages > 1)
+ CenterSubtitle = loc.Format("donut.nav_hint", CurrentPage + 1, TotalPages);
+ else
+ CenterSubtitle = IsClickMode ? loc["donut.close_hint"] : null;
}
/// <summary>Updates the centre hint for the emphasised slice (and slice <paramref name="sub"/> of its group's ring).</summary>
public void ShowHint(int index, int sub, bool centerHot)
{
if (centerHot)
+ {
CenterSubtitle = loc["donut.cancel"];
+ }
+ else if (index >= 0 && index < Items.Count && Items[index].IsNavigation)
+ {
+ CenterSubtitle = loc.Format("donut.nav_hint", CurrentPage + 1, TotalPages);
+ }
else if (index >= 0 && index < Items.Count && Items[index].Children is { Count: > 0 } children &&
(sub >= 0 || Items[index].IsEnabled))
+ {
CenterSubtitle = sub >= 0 && sub < children.Count
? children[sub].IsEnabled
? loc.Format(IsClickMode ? "donut.click_to" : "donut.drop_to", $"{Items[index].Label} · {children[sub].Label}")
: children[sub].DisabledReason
: loc["donut.pick_in_group"];
+ }
else if (index >= 0 && index < Items.Count)
+ {
CenterSubtitle = Items[index].IsEnabled
? loc.Format(IsClickMode ? "donut.click_to" : "donut.drop_to", Items[index].Label)
: Items[index].DisabledReason;
+ }
else
- CenterSubtitle = IsClickMode ? loc["donut.close_hint"] : null;
+ {
+ UpdateCenterSubtitle();
+ }
}
/// <summary>Click mode, before the window is placed: room for a group's ring only if this donut has a group.</summary>
diff --git a/src/Filee.App/Views/CropOverlayWindow.axaml b/src/Filee.App/Views/CropOverlayWindow.axaml
new file mode 100644
index 00000000..d9607c41
--- /dev/null
+++ b/src/Filee.App/Views/CropOverlayWindow.axaml
@@ -0,0 +1,116 @@
+<Window xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:vm="using:Filee.App.ViewModels"
+ xmlns:c="using:Filee.App.Controls"
+ x:Class="Filee.App.Views.CropOverlayWindow"
+ x:DataType="vm:CropOverlayViewModel"
+ Title="Filee — Crop"
+ Icon="avares://Filee/Assets/Icons/filee.ico"
+ Width="960" Height="680" MinWidth="680" MinHeight="500"
+ WindowStartupLocation="CenterScreen"
+ WindowDecorations="None"
+ Background="Transparent"
+ TransparencyLevelHint="Transparent"
+ Topmost="True"
+ CanResize="True">
+
+ <Window.Styles>
+ <Style Selector="Button.aspect">
+ <Setter Property="Padding" Value="10,5" />
+ <Setter Property="CornerRadius" Value="6" />
+ <Setter Property="FontSize" Value="12" />
+ <Setter Property="Background" Value="#22FFFFFF" />
+ <Setter Property="Foreground" Value="#EEEEEE" />
+ <Setter Property="BorderThickness" Value="1" />
+ <Setter Property="BorderBrush" Value="#22FFFFFF" />
+ <Setter Property="Cursor" Value="Hand" />
+ </Style>
+ <Style Selector="Button.aspect:pointerover">
+ <Setter Property="Background" Value="#44FFFFFF" />
+ </Style>
+ <Style Selector="Button.aspect.active">
+ <Setter Property="Background" Value="{DynamicResource AccentBrush}" />
+ <Setter Property="Foreground" Value="{DynamicResource OnAccentBrush}" />
+ <Setter Property="FontWeight" Value="SemiBold" />
+ <Setter Property="BorderBrush" Value="{DynamicResource AccentBrush}" />
+ </Style>
+ <Style Selector="Button.aspect.active:pointerover">
+ <Setter Property="Background" Value="{DynamicResource AccentBrush}" />
+ <Setter Property="Opacity" Value="0.9" />
+ </Style>
+ </Window.Styles>
+
+ <!-- Dark translucent overlay card with rounded corners and drop shadow -->
+ <Border Margin="16" CornerRadius="14"
+ Background="#E61A1A1E"
+ BorderBrush="#33FFFFFF" BorderThickness="1"
+ ClipToBounds="True"
+ BoxShadow="0 10 32 0 #80000000">
+ <DockPanel>
+ <!-- Top header bar -->
+ <Border DockPanel.Dock="Top" Height="48" Padding="16,0" BorderBrush="#22FFFFFF" BorderThickness="0,0,0,1"
+ Background="#26000000">
+ <DockPanel VerticalAlignment="Center">
+ <Button DockPanel.Dock="Right" Classes="icon" Command="{Binding CancelCommand}"
+ ToolTip.Tip="{DynamicResource common.cancel}" Margin="4,0,0,0">
+ <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Close}" Foreground="#AAAAAA" />
+ </Button>
+
+ <StackPanel Orientation="Horizontal" Spacing="10" VerticalAlignment="Center">
+ <PathIcon Width="16" Height="16" Data="{StaticResource Icon.Crop}" Foreground="{DynamicResource AccentBrush}" />
+ <TextBlock Text="{DynamicResource preset.crop}" FontWeight="SemiBold" FontSize="14" Foreground="#FFFFFF" />
+ <TextBlock Text="—" Foreground="#666666" />
+ <TextBlock Text="{Binding CurrentFileName}" FontSize="13" Foreground="#CCCCCC" TextTrimming="CharacterEllipsis" MaxWidth="360" />
+
+ <Border IsVisible="{Binding HasMultipleFiles}" Background="#33FFFFFF" CornerRadius="10" Padding="8,2">
+ <TextBlock Text="{Binding CounterText}" FontSize="11" Foreground="#EEEEEE" />
+ </Border>
+ </StackPanel>
+ </DockPanel>
+ </Border>
+
+ <!-- Bottom toolbar HUD -->
+ <Border DockPanel.Dock="Bottom" Padding="16,12" BorderBrush="#22FFFFFF" BorderThickness="0,1,0,0"
+ Background="#26000000">
+ <DockPanel>
+ <!-- Action Buttons on the Right -->
+ <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" Spacing="8" VerticalAlignment="Center">
+ <Button Content="{DynamicResource crop.reset}" Command="{Binding ResetCommand}"
+ Classes="aspect" />
+ <Button Content="{DynamicResource common.cancel}" Command="{Binding CancelCommand}"
+ IsCancel="True" Classes="aspect" />
+ <Button Content="{DynamicResource crop.save}" Command="{Binding CropAndSaveCommand}"
+ IsDefault="True" Classes="accent" FontWeight="SemiBold" Padding="14,6" CornerRadius="6" />
+ </StackPanel>
+
+ <StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
+ <TextBlock Text="{DynamicResource crop.aspect_title}" VerticalAlignment="Center" FontSize="12" Foreground="#888888" Margin="0,0,2,0" />
+ <Button Classes="aspect" Classes.active="{Binding IsAspectFree}" Content="{DynamicResource crop.aspect_free}" Command="{Binding SetAspectCommand}" CommandParameter="free" ToolTip.Tip="Free-form selection" />
+ <Button Classes="aspect" Classes.active="{Binding IsAspectSquare}" Content="1:1" Command="{Binding SetAspectCommand}" CommandParameter="1:1" ToolTip.Tip="1:1 Square (Instagram post)" />
+ <Button Classes="aspect" Classes.active="{Binding IsAspect45}" Content="4:5" Command="{Binding SetAspectCommand}" CommandParameter="4:5" ToolTip.Tip="4:5 Portrait (Instagram feed)" />
+ <Button Classes="aspect" Classes.active="{Binding IsAspect916}" Content="9:16" Command="{Binding SetAspectCommand}" CommandParameter="9:16" ToolTip.Tip="9:16 Vertical (Stories / Reels)" />
+ <Button Classes="aspect" Classes.active="{Binding IsAspect169}" Content="16:9" Command="{Binding SetAspectCommand}" CommandParameter="16:9" ToolTip.Tip="16:9 Widescreen" />
+ <Button Classes="aspect" Classes.active="{Binding IsAspectOriginal}" Content="{DynamicResource crop.aspect_original}" Command="{Binding SetAspectCommand}" CommandParameter="original" ToolTip.Tip="Original photo aspect ratio" />
+
+ <Border Background="#22000000" BorderBrush="#33FFFFFF" BorderThickness="1" CornerRadius="6" Padding="8,4" Margin="6,0,0,0">
+ <TextBlock Text="{Binding DimensionsText}" FontSize="11" FontFamily="Consolas, monospace" Foreground="#DDDDDD" />
+ </Border>
+ </StackPanel>
+ </DockPanel>
+ </Border>
+
+ <!-- Center image viewport and interactive crop canvas -->
+ <Grid Background="#11000000">
+ <c:CropCanvas x:Name="Canvas"
+ SourceImage="{Binding PreviewImage}"
+ HorizontalAlignment="Stretch"
+ VerticalAlignment="Stretch" />
+
+ <!-- Loading spinner / busy indicator -->
+ <Border IsVisible="{Binding IsBusy}" Background="#66000000" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
+ <ProgressBar IsIndeterminate="True" Width="80" Height="4" HorizontalAlignment="Center" VerticalAlignment="Center" />
+ </Border>
+ </Grid>
+ </DockPanel>
+ </Border>
+</Window>
diff --git a/src/Filee.App/Views/CropOverlayWindow.axaml.cs b/src/Filee.App/Views/CropOverlayWindow.axaml.cs
new file mode 100644
index 00000000..6a32cee9
--- /dev/null
+++ b/src/Filee.App/Views/CropOverlayWindow.axaml.cs
@@ -0,0 +1,47 @@
+using Avalonia.Controls;
+using Avalonia.Input;
+using Filee.App.ViewModels;
+
+namespace Filee.App.Views;
+
+public partial class CropOverlayWindow : Window
+{
+ public CropOverlayWindow()
+ {
+ InitializeComponent();
+
+ DataContextChanged += OnDataContextChanged;
+ }
+
+ private void OnDataContextChanged(object? sender, EventArgs e)
+ {
+ if (DataContext is CropOverlayViewModel vm)
+ {
+ vm.CloseRequested += Close;
+ vm.ResetRequested += () => Canvas.ResetCrop();
+ vm.AspectRatioChanged += ratio => Canvas.SetAspectRatio(ratio);
+ Canvas.CropRectChanged += rect => vm.UpdateDimensions(rect);
+ }
+ }
+
+ protected override void OnKeyDown(KeyEventArgs e)
+ {
+ base.OnKeyDown(e);
+ if (e.Key == Key.Escape)
+ {
+ Close();
+ e.Handled = true;
+ }
+ }
+
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ base.OnPointerPressed(e);
+ // Allow dragging the window when clicking on empty header space
+ var pt = e.GetPosition(this);
+ if (pt.Y < 50 && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
+ {
+ BeginMoveDrag(e);
+ }
+ }
+}
diff --git a/src/Filee.App/Views/RadialWindow.axaml.cs b/src/Filee.App/Views/RadialWindow.axaml.cs
index 0cfaab79..8c6c8687 100644
--- a/src/Filee.App/Views/RadialWindow.axaml.cs
+++ b/src/Filee.App/Views/RadialWindow.axaml.cs
@@ -71,7 +71,7 @@ public partial class RadialWindow : Window
Donut.SetExternalHit(hit, at);
// Always COPY. Reporting MOVE would make Explorer delete the source files after the drop.
- e.DragEffects = files && Donut.Converts(hit) ? DragDropEffects.Copy : DragDropEffects.None;
+ e.DragEffects = files && Donut.AcceptsDrop(hit) ? DragDropEffects.Copy : DragDropEffects.None;
e.Handled = true;
}
@@ -88,11 +88,22 @@ public partial class RadialWindow : Window
DragSummary?.Invoke(_dragOverEvents, hit, Donut.LitAmount(hit.Index));
Donut.CollapseGroup();
Donut.SetExternalHighlight(-1);
- e.DragEffects = Donut.Converts(hit) ? DragDropEffects.Copy : DragDropEffects.None;
+ e.DragEffects = Donut.AcceptsDrop(hit) ? DragDropEffects.Copy : DragDropEffects.None;
Dropped?.Invoke(hit, LocalFiles(e));
e.Handled = true;
}
+ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
+ {
+ base.OnPointerWheelChanged(e);
+ if (DataContext is Filee.App.ViewModels.RadialViewModel vm && vm.TotalPages > 1)
+ {
+ vm.CyclePage(e.Delta.Y < 0 ? 1 : -1);
+ Donut.PlayOpenAnimation();
+ e.Handled = true;
+ }
+ }
+
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
diff --git a/src/Filee.Core/Presets/BuiltInData.cs b/src/Filee.Core/Presets/BuiltInData.cs
index 7ec96870..a7771eb3 100644
--- a/src/Filee.Core/Presets/BuiltInData.cs
+++ b/src/Filee.Core/Presets/BuiltInData.cs
@@ -43,6 +43,11 @@ public static class BuiltInData
Id = "remove-background", NameKey = "preset.remove_background", TargetFormat = "png",
Image = { RemoveBackground = true }, Output = { FileNamePattern = "{name}_transparent" },
},
+ new()
+ {
+ Id = "tool-crop", NameKey = "preset.crop", TargetFormat = SameAsSource,
+ Kind = PresetKind.Tool, Output = { FileNamePattern = "{name}_cropped" },
+ },
.. ImageToolPresets(),
new()
{
@@ -344,6 +349,7 @@ public static class BuiltInData
.. WithSubtitleProfile(CatalogProfiles()),
DataProfile(),
ModelProfile(),
+
new()
{
Id = "mixed", NameKey = "profile.mixed", IsFallback = true,
diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.cs
index 305d9b27..139513fd 100644
--- a/src/Filee.Core/Presets/Preset.cs
+++ b/src/Filee.Core/Presets/Preset.cs
@@ -16,6 +16,11 @@ public enum PresetKind
/// conversion is picked (preset list, watch folders, <c>filee --preset</c>).
/// </summary>
Group,
+
+ /// <summary>
+ /// An interactive zero-window desktop tool (such as Crop) that opens an on-screen HUD upon drop.
+ /// </summary>
+ Tool,
}
/// <summary>
@@ -130,6 +135,10 @@ public sealed class Preset
&& MediaOptions.FrameTargets.Contains(TargetFormat)
&& Formats.FormatRegistry.FindById(sourceFormat)?.Category == Formats.FormatCategory.Video;
+ /// <summary>True for a <see cref="PresetKind.Tool"/>.</summary>
+ [JsonIgnore]
+ public bool IsTool => Kind == PresetKind.Tool;
+
/// <summary>Creates a new random preset id.</summary>
public static string NewId() => Guid.NewGuid().ToString("N")[..12];
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index f1fde541..f55d3200 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -64,7 +64,7 @@ public sealed class DonutSettings
public sealed class AppSettings
{
/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>
- public const int CurrentSchemaVersion = 20;
+ public const int CurrentSchemaVersion = 21;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --git a/src/Filee.Core/Settings/TriggerGesture.cs b/src/Filee.Core/Settings/TriggerGesture.cs
index d7a870a0..f8f887e2 100644
--- a/src/Filee.Core/Settings/TriggerGesture.cs
+++ b/src/Filee.Core/Settings/TriggerGesture.cs
@@ -72,6 +72,9 @@ public sealed class TriggerGesture
public TriggerScope Scope { get; set; } = TriggerScope.FileManager;
+ /// <summary>Optional profile id to open when triggered (e.g. "utility" for the quick tools wheel).</summary>
+ public string? TargetProfileId { get; set; }
+
public TriggerGesture Clone() => (TriggerGesture)MemberwiseClone();
/// <summary>Default gestures for the current OS.</summary>
@@ -79,9 +82,11 @@ public sealed class TriggerGesture
{
// On macOS Ctrl+click means right-click, and Option already means "copy" in Finder.
var dragModifier = OperatingSystem.IsMacOS() ? ModifierKeys.Alt : ModifierKeys.Ctrl;
+ var utilityModifier = dragModifier | ModifierKeys.Shift;
return
[
new() { Kind = TriggerKind.Drag, Modifiers = dragModifier, Button = TriggerMouseButton.Left },
+ new() { Kind = TriggerKind.Drag, Modifiers = utilityModifier, Button = TriggerMouseButton.Left, TargetProfileId = "utility" },
new() { Kind = TriggerKind.KeyChord, Modifiers = ModifierKeys.Ctrl | ModifierKeys.Alt, Button = TriggerMouseButton.None, Key = "Space" },
];
}
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index 44dd6d23..0cf0d7dc 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -549,6 +549,17 @@ internal static class SettingsMigrations
changed = true;
}
}
+
+ // v21: interactive "Crop" tool, after "Remove background" as in a new library, on no donut: users add it in Settings → Toolbar.
+ if (from < 21)
+ {
+ if (presets.All(p => p.Id != "tool-crop") && BuiltInData.CreatePresets().FirstOrDefault(p => p.Id == "tool-crop") is { } crop)
+ {
+ var at = presets.FindIndex(p => p.Id == "remove-background");
+ presets.Insert(at < 0 ? presets.Count : at + 1, crop);
+ changed = true;
+ }
+ }
return changed;
}
diff --git a/tests/Filee.Core.Tests/UserDataStoreTests.cs b/tests/Filee.Core.Tests/UserDataStoreTests.cs
index 5b3d34fe..42a6700f 100644
--- a/tests/Filee.Core.Tests/UserDataStoreTests.cs
+++ b/tests/Filee.Core.Tests/UserDataStoreTests.cs
@@ -731,6 +731,22 @@ public class UserDataStoreTests
Assert.False(SettingsMigrations.ApplyToLibrary(17, presets, profiles)); // once only
}
+ [Fact]
+ public void Version_20_libraries_get_crop_tool_preset_after_remove_background_on_no_donut()
+ {
+ var presets = BuiltInData.CreatePresets();
+ presets.RemoveAll(p => p.Id == "tool-crop");
+ var profiles = BuiltInData.CreateProfiles();
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(20, presets, profiles));
+
+ var crop = presets.Single(p => p.Id == "tool-crop");
+ Assert.Equal(PresetKind.Tool, crop.Kind);
+ Assert.Equal("remove-background", presets[presets.IndexOf(crop) - 1].Id);
+ Assert.DoesNotContain(profiles, p => p.PresetIds.Contains("tool-crop"));
+ Assert.False(SettingsMigrations.ApplyToLibrary(20, presets, profiles)); // once only
+ }
+
[Fact]
public void Back_from_an_older_Filee_compress_pdf_compresses_again_and_keeps_the_users_changes()
{