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.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Flip the donut slice by slice in a wave and swap faces at once (#371)
SeoJCalive8a2b10825e60
diff --git a/src/Filee.App/Controls/DonutMenu.Flip.cs b/src/Filee.App/Controls/DonutMenu.Flip.csindex baed700b..5024cf9a 100644--- a/src/Filee.App/Controls/DonutMenu.Flip.cs+++ b/src/Filee.App/Controls/DonutMenu.Flip.cs@@ -1,14 +1,14 @@// Flipping the donut to its other face: every profile has a front and a back list of slices, and Tab turns the open-// donut over. The ring turns about the vertical axis like a coin (its width goes 1 → 0, the faces swap while it is-// edge-on, 0 → 1); the hub stays where it is and says how to flip ("Tab ↻ back").+// donut over. Each slice folds about its spoke, starting under the pointer and spreading both ways; the hub stays+// where it is and says how to flip ("Tab ↻ back").//// The flip key (Tab unless the user records another in Settings → Shortcuts) and the mouse wheel flip it:// Click mode → the key reaches the focused window (HandleKey), the wheel the donut (OnPointerWheelChanged).// Drag mode → the window has no keyboard focus during an OS drag: RadialController flips when the global hook// sees the key or the wheel (TriggerService.FlipKeyPressed / FlipWheelTurned).//-// The control only animates: the owner swaps Items when FaceSwapping is raised (RadialWindow → RadialViewModel), so-// the slices, hit-testing and what a drop converts with always belong to the face that is drawn.+// The owner swaps Items immediately when FaceSwapping is raised (RadialWindow → RadialViewModel). Old slices are+// retained for drawing only; hit-testing and drops always use the new face.using Avalonia;using Avalonia.Input;@@ -47,14 +47,36 @@ public sealed partial class DonutMenuprivate long? _lastWheel;- /// <summary>How long a flip takes, there and back: the faces swap halfway.</summary>- internal const double FlipDuration = 0.2;+ internal const double SliceTurn = 0.12;+ internal const double Stagger = 0.08;+ internal const double FlipDuration = SliceTurn + Stagger;private double _flipClock = -1; // seconds into the running flip; -1 none- private bool _flipSwapped; // the running flip swapped the faces alreadyprivate bool _flipQueued; // Tab again during a flip: flip once more after itprivate bool _swapping; // FaceSwapping is being handled (Items change for the flip, not for new files)private Point? _lastExternalAt; // where a drag from outside was last seen on the donut+ private OldSlice[]? _oldFace;+ private OldGroup? _oldGroup;+ private double[] _oldDelay = [];+ private double[] _newDelay = [];+ private int _oldOriginIndex = -1;+ private double? _pointingAngle;+ private bool _pointingAtSlice;++ private sealed class OldSlice+ {+ public required DonutItem Item { get; init; }+ public double Mid { get; init; }+ public double Span { get; init; }+ public double Open { get; init; }+ public double Hover { get; set; }+ public double Emphasis { get; set; }+ public bool Hot { get; set; }+ public bool Dimmed { get; init; }+ }++ private sealed record OldGroup(int Index, IReadOnlyList<DonutItem> Children, double Expansion,+ int SubHover, bool Expanded, double Opening, double Span);public bool CanFlip { get => GetValue(CanFlipProperty); set => SetValue(CanFlipProperty, value); }public string? CenterHint { get => GetValue(CenterHintProperty); set => SetValue(CenterHintProperty, value); }@@ -90,7 +112,7 @@ public sealed partial class DonutMenu}/// <summary>- /// The donut is edge-on (at once without animations): the owner shows the other face now by changing+ /// The flip starts: the owner immediately shows the other face by changing/// <see cref="Items"/>, <see cref="CanFlip"/> and <see cref="CenterHint"/>./// </summary>public event EventHandler? FaceSwapping;@@ -98,12 +120,156 @@ public sealed partial class DonutMenu/// <summary>A flip is running.</summary>internal bool IsFlipping => _flipClock >= 0;- /// <summary>How wide the ring is drawn now: 1 normally, down to 0 while a flip has it edge-on.</summary>- internal double FlipScale => _flipClock < 0 ? 1 : Math.Abs(Math.Cos(Math.PI * Math.Min(_flipClock / FlipDuration, 1)));+ internal double? FlipOrigin { get; private set; }+ internal bool HasOldFace => _oldFace is not null;+ internal bool HasOldGroupRing => _oldGroup is not null;+ internal int CachedWedgeCount => _wedges.Count;++ private double Progress(bool oldFace, int index)+ {+ var delays = oldFace ? _oldDelay : _newDelay;+ return Math.Clamp((_flipClock - delays[index]) / SliceTurn, 0, 1);+ }++ internal double SliceFlipWidth(bool oldFace, int index)+ {+ if (oldFace && (_oldFace is null || index < 0 || index >= _oldFace.Length))+ return 0;+ if (!oldFace && (index < 0 || index >= Count))+ return 0;+ if (!IsFlipping)+ return oldFace ? 0 : 1;+ var u = Progress(oldFace, index);+ if (oldFace ? u >= 0.5 : u < 0.5)+ return 0;+ return Math.Max(Math.Abs(Math.Cos(Math.PI * u)), 0.01);+ }++ internal Matrix SliceFlipTransform(bool oldFace, int index)+ {+ if (!IsFlipping)+ return Matrix.Identity;+ var width = SliceFlipWidth(oldFace, index);+ var mid = oldFace ? _oldFace![index].Mid : IsEditMode ? _mid[index].Value : DonutGeometry.MidAngle(index, Count);+ var center = Center;+ return Matrix.CreateTranslation(-center.X, -center.Y) * Matrix.CreateRotation(-mid) *+ Matrix.CreateScale(Math.Max(width, 0.01), 1) * Matrix.CreateRotation(mid) *+ Matrix.CreateTranslation(center.X, center.Y);+ }++ internal double ShadowCoverage+ {+ get+ {+ if (!IsFlipping)+ return 1;+ var coverage = 0.0;+ for (var i = 0; i < Count; i++)+ coverage += SliceFlipWidth(false, i) * DonutGeometry.Span(Count) / (2 * Math.PI);+ if (_oldFace is { } old)+ for (var i = 0; i < old.Length; i++)+ coverage += SliceFlipWidth(true, i) * old[i].Span / (2 * Math.PI);+ return Math.Min(1, coverage);+ }+ }++ private double Delay(int index, int count)+ {+ if (count == 1 || index == DonutGeometry.IndexAt(FlipOrigin!.Value, count))+ return 0;+ return Stagger * Math.Abs(Math.IEEERemainder(DonutGeometry.MidAngle(index, count) - FlipOrigin.Value,+ 2 * Math.PI)) / Math.PI;+ }++ private void BeginWave(bool incomingOnly)+ {+ FlipOrigin = incomingOnly ? 0 : _lastExternalAt is { } drag+ ? drag == Center ? 0 : DonutGeometry.AngleOf(Center, drag)+ : !_keyboardHold && _lastPointer is { } pointer+ ? pointer == Center ? 0 : DonutGeometry.AngleOf(Center, pointer)+ : ActiveIndex >= 0 ? DonutGeometry.MidAngle(ActiveIndex, Count) : 0;+ _oldDelay = _oldFace is { } old+ ? Enumerable.Range(0, old.Length).Select(i => Delay(i, old.Length)).ToArray() : [];+ _oldOriginIndex = _oldFace is { Length: > 0 } ? DonutGeometry.IndexAt(FlipOrigin.Value, _oldFace.Length) : -1;+ _pointingAngle = null;+ _pointingAtSlice = false;+ }++ private void PrepareIncoming()+ {+ _newDelay = Enumerable.Range(0, Count).Select(j =>+ {+ var delay = Delay(j, Count);+ if (_oldFace is { } previous)+ for (var i = 0; i < previous.Length; i++)+ if (Math.Abs(Math.IEEERemainder(previous[i].Mid - DonutGeometry.MidAngle(j, Count), 2 * Math.PI)) <+ (previous[i].Span + DonutGeometry.Span(Count)) / 2)+ delay = Math.Max(delay, _oldDelay[i]);+ return delay;+ }).ToArray();+ }++ private void CaptureOldFace()+ {+ var n = Count;+ _oldFace = Enumerable.Range(0, n).Select(i => new OldSlice+ {+ Item = Items![i],+ Mid = DonutGeometry.MidAngle(i, n),+ Span = DonutGeometry.Span(n),+ Open = _open[i],+ Hover = _hover[i].Value,+ Emphasis = i == _dropTargetIndex ? 1 : _hover[i].Value,+ Hot = i == ActiveIndex || i == _dropTargetIndex,+ Dimmed = i == _dimmedIndex,+ }).ToArray();+ _oldGroup = _shownExpanded >= 0 && _shownExpanded < n && _expand.Value > 0.01 &&+ Items![_shownExpanded].Children is { Count: > 0 } children+ ? new OldGroup(_shownExpanded, children, _expand.Value, _subHover, _expanded == _shownExpanded,+ _open.Length == 0 ? 1 : Math.Clamp(_open.Average(), 0, 1), SubSpanOf(children.Count))+ : null;+ }++ private void PointAtAngle(double angle, bool pointed = true)+ {+ if (!IsFlipping || _oldFace is not { Length: > 0 } old)+ return;+ if (_pointingAngle is { } previous && _pointingAtSlice == pointed &&+ Math.Abs(Math.IEEERemainder(previous - angle, 2 * Math.PI)) < 0.000001)+ return;+ _pointingAngle = angle;+ _pointingAtSlice = pointed;+ var oldIndex = DonutGeometry.IndexAt(angle, old.Length);+ if (oldIndex != _oldOriginIndex && _oldOriginIndex >= 0)+ {+ old[_oldOriginIndex].Hover = 0;+ old[_oldOriginIndex].Emphasis = 0;+ old[_oldOriginIndex].Hot = false;+ if (_oldGroup?.Index == _oldOriginIndex)+ _oldGroup = _oldGroup with { SubHover = -1 };+ }+ if (!pointed)+ {+ InvalidateVisual();+ return;+ }+ if (_flipClock < _oldDelay[oldIndex])+ _oldDelay[oldIndex] = _flipClock;+ var newIndex = DonutGeometry.IndexAt(angle, Count);+ if (newIndex >= 0 && Progress(false, newIndex) < 0.5)+ _newDelay[newIndex] = _flipClock - SliceTurn / 2;+ InvalidateVisual();+ }++ private void PointAtSelection()+ {+ if (IsFlipping && ActiveIndex >= 0)+ PointAtAngle(DonutGeometry.MidAngle(ActiveIndex, Count));+ }/// <summary>- /// Turns the donut over to its other face (Tab), folding an open group's ring away first. Without animations the- /// faces swap at once. Returns false when there is nothing to flip to (<see cref="CanFlip"/>), in the editor or+ /// Immediately switches to the other face (Tab), then folds the old slices and any open group ring away in a wave.+ /// Without animations only the face changes. Returns false when there is nothing to flip to (<see cref="CanFlip"/>), in the editor or/// while the donut shows a conversion's progress./// </summary>public bool Flip()@@ -118,28 +284,47 @@ public sealed partial class DonutMenu}if (!CanFlip)return false;- CollapseGroup();if (!Motion.Enabled){+ CollapseGroup();SwapFaces();return true;}+ CaptureOldFace();+ BeginWave(incomingOnly: false);+ var pointed = _lastExternalAt is { } drag && HitTest(drag).Kind is DonutHitKind.Segment or DonutHitKind.SubSegment+ ? drag : !_keyboardHold && _lastPointer is { } pointer &&+ HitTest(pointer).Kind is DonutHitKind.Segment or DonutHitKind.SubSegment ? pointer : (Point?)null;+ CollapseGroup();+ SwapFaces();+ PrepareIncoming();_flipClock = 0;- _flipSwapped = false;+ // SwapFaces resets the current highlight; only a slice actually under the pointer/drag bypasses overlap.+ if (pointed is { } at)+ {+ var angle = DonutGeometry.AngleOf(Center, at);+ _pointingAngle = angle;+ _pointingAtSlice = true;+ var index = DonutGeometry.IndexAt(angle, Count);+ _newDelay[index] = Delay(index, Count);+ }StartAnimation();return true;}/// <summary>- /// The second half of a flip for items that were already swapped (the editor's Front / Back switch): the ring- /// turns in from edge-on. Nothing without animations.+ /// The incoming slice wave for items already swapped by the editor's Front / Back switch.+ /// Slices unfold from the top; nothing runs without animations./// </summary>public void PlayFlipIn(){if (!Motion.Enabled)return;- _flipClock = FlipDuration / 2;- _flipSwapped = true;+ _oldFace = null;+ _oldGroup = null;+ BeginWave(incomingOnly: true);+ PrepareIncoming();+ _flipClock = SliceTurn / 2;_flipQueued = false;StartAnimation();}@@ -150,21 +335,17 @@ public sealed partial class DonutMenuif (_flipClock < 0)return false;_flipClock += dt;- if (!_flipSwapped && _flipClock >= FlipDuration / 2)- SwapFaces();if (_flipClock < FlipDuration)return true;EndFlip();return IsFlipping; // a queued flip started}- /// <summary>Ends a running flip where it ends (the faces swapped): animations off or frames stalled.</summary>+ /// <summary>Ends a running wave on the new face: animations off or frames stalled.</summary>private void FinishFlip(){while (IsFlipping){- if (!_flipSwapped)- SwapFaces();EndFlip();}}@@ -172,6 +353,9 @@ public sealed partial class DonutMenuprivate void EndFlip(){_flipClock = -1;+ _oldFace = null;+ _oldGroup = null;+ FlipOrigin = null;if (!_flipQueued)return;_flipQueued = false;@@ -182,6 +366,9 @@ public sealed partial class DonutMenu{_flipClock = -1;_flipQueued = false;+ _oldFace = null;+ _oldGroup = null;+ FlipOrigin = null;}/// <summary>@@ -190,7 +377,6 @@ public sealed partial class DonutMenu/// </summary>private void SwapFaces(){- _flipSwapped = true;var dragAt = _lastExternalAt;var pointer = _keyboardHold ? null : _lastPointer;_swapping = true;@@ -218,14 +404,4 @@ public sealed partial class DonutMenuInvalidateVisual();}- /// <summary>Squeezes the ring horizontally about <paramref name="center"/> by <see cref="FlipScale"/>.</summary>- private Matrix FlipTransform(Point center)- {- var scale = FlipScale;- if (scale >= 1)- return Matrix.Identity;- // Never quite 0: a singular transform can't be inverted for hit tests and clips.- return Matrix.CreateTranslation(-center.X, -center.Y) * Matrix.CreateScale(Math.Max(scale, 0.01), 1) *- Matrix.CreateTranslation(center.X, center.Y);- }}diff --git a/src/Filee.App/Controls/DonutMenu.Groups.cs b/src/Filee.App/Controls/DonutMenu.Groups.csindex 9922ae98..5e67be09 100644--- a/src/Filee.App/Controls/DonutMenu.Groups.cs+++ b/src/Filee.App/Controls/DonutMenu.Groups.cs@@ -279,6 +279,7 @@ public sealed partial class DonutMenureturn false;CollapseGroup();SetHover(current < 0 ? (step > 0 ? 0 : Count - 1) : (current + step + Count) % Count);+ PointAtSelection();return true;}@@ -326,7 +327,12 @@ public sealed partial class DonutMenupublic void SetExternalHit(DonutHit hit, Point? at = null){if (at is not null)+ {_lastExternalAt = at; // a flip lights up what the drag rests on, on the other face+ if (IsFlipping)+ PointAtAngle(DonutGeometry.AngleOf(Center, at.Value),+ hit.Kind is DonutHitKind.Segment or DonutHitKind.SubSegment);+ }TrackGroups(hit, at);SetExternalHighlight(hit.Kind is DonutHitKind.Segment or DonutHitKind.SubSegment ? hit.Index : -1,hit.Kind == DonutHitKind.Center);@@ -387,16 +393,31 @@ public sealed partial class DonutMenu{var group = _shownExpanded;var children = Items![group].Children!;- var parentMid = DonutGeometry.MidAngle(group, Count);- var subSpan = SubSpanOf(children.Count);+ DrawGroupRing(context, center, bold, regular, group, children, DonutGeometry.MidAngle(group, Count),+ SubSpanOf(children.Count), _expand.Value, _subHover, group == _expanded,+ _open.Length == 0 ? 1 : Math.Clamp(_open.Average(), 0, 1), false);+ }++ private void DrawOldSubRing(DrawingContext context, Point center, Typeface bold, Typeface regular)+ {+ var ring = _oldGroup!;+ if (SliceFlipWidth(true, ring.Index) == 0)+ return;+ DrawGroupRing(context, center, bold, regular, ring.Index, ring.Children, _oldFace![ring.Index].Mid,+ ring.Span, ring.Expansion, ring.SubHover, ring.Expanded, ring.Opening, true);+ }++ private void DrawGroupRing(DrawingContext context, Point center, Typeface bold, Typeface regular,+ int group, IReadOnlyList<DonutItem> children, double parentMid, double subSpan, double expansion,+ int subHover, bool expanded, double opening, bool oldFace)+ {var (inner, outer) = SubRadii;- var t = Math.Max(0, _expand.Value);- var opening = _open.Length == 0 ? 1 : Math.Clamp(_open.Average(), 0, 1);+ var t = Math.Max(0, expansion);// Grows outward from the group's slice: scaled about the point where it meets the donut.var anchor = DonutGeometry.PointAt(center, inner, parentMid);var scale = 0.8 + 0.2 * t;var transform = Matrix.CreateTranslation(-anchor.X, -anchor.Y) * Matrix.CreateScale(scale, scale) *- Matrix.CreateTranslation(anchor.X, anchor.Y);+ Matrix.CreateTranslation(anchor.X, anchor.Y) * SliceFlipTransform(oldFace, group);using (context.PushTransform(transform))using (context.PushOpacity(Math.Clamp(t, 0, 1) * opening))@@ -407,7 +428,7 @@ public sealed partial class DonutMenuvar 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;+ var hot = k == subHover && expanded && item.IsEnabled;if (hot)context.DrawGeometry(WithOpacity(AccentBrush, 0.82), null, wedge);DrawLabel(context, item, center, (inner + outer) / 2, mid, subSpan * (inner + outer) / 2 - 8,diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex ba00c908..b7f16df7 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -231,6 +231,8 @@ public sealed partial class DonutMenu : Control/// <summary>Shrinks the donut back into the centre, then calls <paramref name="done"/>.</summary>public void PlayCloseAnimation(Action done){+ if (IsFlipping)+ FinishFlip();if (!Motion.Enabled || Count == 0){done();@@ -450,8 +452,9 @@ public sealed partial class DonutMenu : Control_keyboardHold = false;}_lastPointer = p;-var hit = HitTest(p);+ if (IsFlipping)+ PointAtAngle(DonutGeometry.AngleOf(Center, p), hit.Kind is DonutHitKind.Segment or DonutHitKind.SubSegment);TrackGroups(hit, p);SetHover(hit.Kind switch{@@ -816,19 +819,15 @@ public sealed partial class DonutMenu : Controlreturn;}- // A flip turns the ring (and its shadow and a group's ring) about the vertical axis; the hub stays.- var flip = FlipTransform(center);- using (context.PushTransform(flip))- RenderRing(context, center, r1, r2, n, typeface, typefaceRegular);+ RenderRing(context, center, r1, r2, n, typeface, typefaceRegular);var reaching = _expanded >= 0 ? _expanded : _pendingGroup;if (!IsEditMode && reaching >= 0 && reaching < n && Items![reaching].Children is { Count: > 0 } reachable)DrawHitBackdrop(context, center, reaching, reachable.Count);if (!IsEditMode && _shownExpanded >= 0 && _shownExpanded < n && _expand.Value > 0.01)- {- using (context.PushTransform(flip))- DrawSubRing(context, center, typeface, typefaceRegular);- }+ DrawSubRing(context, center, typeface, typefaceRegular);+ if (HasOldGroupRing)+ DrawOldSubRing(context, center, typeface, typefaceRegular);DrawCenter(context, center, r1, typeface, typefaceRegular);@@ -851,6 +850,8 @@ public sealed partial class DonutMenu : Controlfor (var i = 0; i < n; i++){+ if (IsFlipping && SliceFlipWidth(false, i) == 0)+ continue;var item = Items![i];var open = i < _open.Length ? _open[i] : 1;if (open <= 0.001)@@ -871,7 +872,8 @@ public sealed partial class DonutMenu : ControlMatrix.CreateTranslation(-center.X, -center.Y) *Matrix.CreateRotation(rotate) *Matrix.CreateScale(scale * (1 + hover * 0.025), scale * (1 + hover * 0.025)) *- Matrix.CreateTranslation(center.X + offset.X, center.Y + offset.Y);+ Matrix.CreateTranslation(center.X + offset.X, center.Y + offset.Y) *+ SliceFlipTransform(false, i);using (context.PushTransform(transform))using (context.PushOpacity(Math.Clamp(open, 0, 1) * (i == _dimmedIndex ? 0.3 : 1)))@@ -890,6 +892,32 @@ public sealed partial class DonutMenu : Control}}+ if (_oldFace is { } old)+ for (var i = 0; i < old.Length; i++)+ {+ var slice = old[i];+ if (SliceFlipWidth(true, i) == 0 || slice.Open <= 0.001)+ continue;+ var offset = DonutGeometry.PointAt(new Point(0, 0), slice.Hover * PopOut, slice.Mid);+ var scale = 0.55 + 0.45 * slice.Open;+ var rotate = (1 - Math.Min(slice.Open, 1)) * -0.35;+ var transform = Matrix.CreateTranslation(-center.X, -center.Y) * Matrix.CreateRotation(rotate) *+ Matrix.CreateScale(scale * (1 + slice.Hover * 0.025), scale * (1 + slice.Hover * 0.025)) *+ Matrix.CreateTranslation(center.X + offset.X, center.Y + offset.Y) *+ SliceFlipTransform(true, i);+ using (context.PushTransform(transform))+ using (context.PushOpacity(Math.Clamp(slice.Open, 0, 1) * (slice.Dimmed ? 0.3 : 1)))+ {+ var wedge = CreateWedge(center, r1, r2, slice.Mid, slice.Span);+ context.DrawGeometry(WithOpacity(SliceBrush, SliceOpacity * (slice.Item.IsEnabled ? 1 : 0.55)), BorderPen(), wedge);+ if (slice.Emphasis > 0.01 && slice.Item.IsEnabled)+ context.DrawGeometry(WithOpacity(AccentBrush, 0.82 * Math.Clamp(slice.Emphasis, 0, 1)), null, wedge);+ DrawLabel(context, slice.Item, center, (r1 + r2) / 2, slice.Mid,+ slice.Span * (r1 + r2) / 2 - 10, r2 - r1 - 16, typeface, typefaceRegular,+ slice.Hot && slice.Item.IsEnabled);+ }+ }+if (IsEditMode && _previewSpan.Value > 0.01)DrawPreview(context, center, r1, r2, typeface, typefaceRegular);}@@ -909,7 +937,7 @@ public sealed partial class DonutMenu : Control},};var opening = _open.Length == 0 ? 1 : Math.Clamp(_open.Average(), 0, 1);- using (context.PushOpacity(opening))+ using (context.PushOpacity(opening * ShadowCoverage))context.DrawEllipse(brush, null, new Point(center.X, center.Y + 4), shadowRadius, shadowRadius);}diff --git a/src/Filee.App/ViewModels/RadialViewModel.cs b/src/Filee.App/ViewModels/RadialViewModel.csindex 5ea0f6b4..f9b64d55 100644--- a/src/Filee.App/ViewModels/RadialViewModel.cs+++ b/src/Filee.App/ViewModels/RadialViewModel.cs@@ -183,7 +183,7 @@ public sealed partial class RadialViewModel(UserDataStore store, ILocalizer loc,}/// <summary>- /// Shows the other face (the donut is edge-on in its flip). Returns false, changing nothing, when it has no slice+ /// Shows the other face (at the start of the donut's flip). Returns false, changing nothing, when it has no slice/// for these files (<see cref="CanFlip"/>)./// </summary>public bool ToggleFace()diff --git a/tests/Filee.App.Tests/DonutFlipTests.cs b/tests/Filee.App.Tests/DonutFlipTests.csindex f7e81852..9093dd6f 100644--- a/tests/Filee.App.Tests/DonutFlipTests.cs+++ b/tests/Filee.App.Tests/DonutFlipTests.cs@@ -3,6 +3,7 @@// back face greys out what can't convert the files like the front, and "Reduce animations" swaps the faces at once.using Avalonia;+using Avalonia.Controls;using Avalonia.Headless;using Avalonia.Headless.XUnit;using Avalonia.Input;@@ -84,6 +85,532 @@ public class DonutFlipTestsprivate static void HintLikeTheController(RadialViewModel vm, DonutMenu donut) =>donut.ActiveIndexChanged += (_, index) => vm.ShowHint(index, donut.ActiveSubIndex, donut.IsCenterHot);+ private static (DonutMenu Donut, Avalonia.Controls.Window Window) Wave(int front = 6, int back = 4)+ {+ TestServices.EnsureInitialized();+ Motion.Configure(false, () => false);+ DonutItem[] Face(int count, string prefix) =>+ Enumerable.Range(0, count).Select(i => new DonutItem { Id = $"{prefix}{i}", Label = $"{prefix}{i}" }).ToArray();+ var first = Face(front, "front");+ var second = Face(back, "back");+ var donut = new DonutMenu { Items = first, CanFlip = true };+ var backShown = false;+ donut.FaceSwapping += (_, _) => donut.Items = (backShown = !backShown) ? second : first;+ var window = new Avalonia.Controls.Window { Content = donut, SizeToContent = Avalonia.Controls.SizeToContent.WidthAndHeight };+ window.Show();+ Dispatcher.UIThread.RunJobs();+ return (donut, window);+ }++ private static Point At(DonutMenu donut, double angle) =>+ DonutGeometry.PointAt(new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2), donut.OuterRadius * 0.7, angle);++ private static byte[] PixelAt(DonutMenu donut, Point at)+ {+ using var image = new Avalonia.Media.Imaging.RenderTargetBitmap(new PixelSize((int)donut.Bounds.Width, (int)donut.Bounds.Height));+ image.Render(donut);+ var pixel = new byte[4];+ var pin = System.Runtime.InteropServices.GCHandle.Alloc(pixel, System.Runtime.InteropServices.GCHandleType.Pinned);+ try { image.CopyPixels(new PixelRect((int)at.X, (int)at.Y, 1, 1), pin.AddrOfPinnedObject(), 4, 4); }+ finally { pin.Free(); }+ return pixel;+ }++ private static byte AlphaAt(DonutMenu donut, Point at) => PixelAt(donut, at)[3];++ [AvaloniaTheory]+ [InlineData(0.01)]+ [InlineData(0.1)]+ public void T1_drop_during_the_wave_uses_the_new_face_preset(double elapsed) => With(true, null, () =>+ {+ var provider = new TriggerServiceLifecycleTests.DelayedProvider();+ provider.AllowExit.Set();+ using var triggers = TriggerServiceLifecycleTests.Create(provider, () => { });+ var vm = AppHost.Get<RadialViewModel>();+ var radial = new RadialController(vm, AppHost.Get<ConversionService>(), AppHost.Get<WindowService>(), Store,+ AppHost.Get<IPlatformServices>(), triggers, NullLogger<RadialController>.Instance);+ var folder = Directory.CreateTempSubdirectory("filee-wave-drop-");+ var conversions = AppHost.Get<ConversionService>();+ try+ {+ var file = Path.Combine(folder.FullName, "photo.jpg");+ File.WriteAllBytes(file, [0xFF, 0xD8, 0xFF]);+ radial.ShowForDrag(400, 400);+ var window = radial.Window!;+ RenderTests.Pump();+ var data = new DataTransfer();+ data.Add(DataTransferItem.CreateFile(window.StorageProvider.TryGetFileFromPathAsync(file).GetAwaiter().GetResult()!));+ var donut = window.DonutControl;+ var at = At(donut, DonutGeometry.MidAngle(7, ImageBack.Count)); // "to-gif", not the crop tool+ var inWindow = donut.TranslatePoint(at, window)!.Value;+ window.DragDrop(inWindow, RawDragEventType.DragEnter, data, DragDropEffects.Copy, RawInputModifiers.Control);+ Dispatcher.UIThread.RunJobs();+ var frontPreset = vm.PresetAt(donut.HitTest(at).Index, -1)!;+ Assert.True(donut.Flip());+ donut.Advance(elapsed);+ var preset = vm.PresetAt(donut.HitTest(at).Index, -1)!;+ Assert.Contains(preset.Id, ImageBack);+ Assert.NotEqual(frontPreset.Id, preset.Id);+ var before = conversions.Jobs.Select(j => j.Job.Id).ToHashSet();+ window.DragDrop(inWindow, RawDragEventType.Drop, data, DragDropEffects.Copy, RawInputModifiers.Control);+ var job = Assert.Single(conversions.Jobs, j => !before.Contains(j.Job.Id));+ Assert.Equal(preset.Id, job.Job.Preset.Id);+ job.CancelCommand.Execute(null);+ radial.Close(animate: false);+ window.Close();+ }+ finally+ {+ radial.Close(animate: false);+ folder.Delete(recursive: true);+ }+ });++ [AvaloniaFact]+ public void T2_spoke_transforms_origin_priority_and_shadow_are_staggered()+ {+ var (donut, window) = Wave();+ try+ {+ donut.SetExternalHit(donut.HitTest(At(donut, Math.PI / 6)), At(donut, Math.PI / 6));+ Assert.True(donut.Flip());+ Assert.Equal(Math.PI / 6, donut.FlipOrigin!.Value, 8);+ Assert.Equal(1, donut.ShadowCoverage, 8);+ donut.Advance(0.02);+ Assert.InRange(donut.SliceFlipWidth(true, 0), 0.01, 0.99); // off-centre origin has no delay+ Assert.Equal(1, donut.SliceFlipWidth(true, 3));+ var center = new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2);+ var top = donut.SliceFlipTransform(true, 0);+ var right = donut.SliceFlipTransform(true, 1);+ var topWidth = donut.SliceFlipWidth(true, 0);+ var rightWidth = donut.SliceFlipWidth(true, 1);+ Assert.Equal(topWidth, (new Point(center.X + 1, center.Y) * top).X - (center * top).X, 6);+ Assert.Equal(-1, (new Point(center.X, center.Y - 1) * top).Y - (center * top).Y, 6);+ var rightTangent = new Vector(Math.Cos(Math.PI / 3), Math.Sin(Math.PI / 3));+ var basePoint = center * right;+ var tangentPoint = (center + rightTangent) * right;+ Assert.Equal(rightWidth, new Vector(tangentPoint.X - basePoint.X, tangentPoint.Y - basePoint.Y).Length, 6);+ Assert.InRange(donut.ShadowCoverage, 0, 0.999);+ donut.Advance(DonutMenu.FlipDuration);+ Assert.False(donut.HasOldFace);+ Assert.All(Enumerable.Range(0, 4), i => Assert.Equal(1, donut.SliceFlipWidth(false, i)));+ Assert.Equal(1, donut.ShadowCoverage, 8);+ }+ finally { window.Close(); }+ var (four, fourWindow) = Wave(4, 4);+ try+ {+ four.Flip();+ four.Advance(0.06);+ var center = new Point(four.Bounds.Width / 2, four.Bounds.Height / 2);+ var transform = four.SliceFlipTransform(true, 1);+ var transformed = center * transform;+ var radial = (center + new Vector(1, 0)) * transform;+ var tangent = (center + new Vector(0, 1)) * transform;+ Assert.Equal(1, new Vector(radial.X - transformed.X, radial.Y - transformed.Y).Length, 6);+ Assert.Equal(four.SliceFlipWidth(true, 1),+ new Vector(tangent.X - transformed.X, tangent.Y - transformed.Y).Length, 6);+ }+ finally { fourWindow.Close(); }+ foreach (var source in new[] { "pointer", "keyboard", "none" })+ {+ var (other, host) = Wave();+ try+ {+ if (source == "pointer")+ host.MouseMove(At(other, Math.PI));+ if (source == "keyboard")+ {+ for (var i = 0; i < 4; i++)+ other.HandleKey(Key.Right);+ }+ other.Flip();+ Assert.Equal(source == "none" ? 0 : Math.PI, other.FlipOrigin!.Value, 6);+ }+ finally { host.Close(); }+ }+ var (centred, centredHost) = Wave();+ try+ {+ centredHost.MouseMove(At(centred, Math.PI));+ var hub = new Point(centred.Bounds.Width / 2, centred.Bounds.Height / 2);+ centred.SetExternalHit(centred.HitTest(hub), hub);+ centred.Flip();+ Assert.Equal(0, centred.FlipOrigin!.Value, 6); // a drag exactly on the centre is rule 4, not the pointer+ }+ finally { centredHost.Close(); }+ }++ [AvaloniaFact]+ public void T4_a_fresh_drag_highlight_is_kept_as_it_was_drawn()+ {+ var (donut, window) = Wave();+ try+ {+ donut.SliceBrush = Avalonia.Media.Brushes.Blue;+ donut.AccentBrush = Avalonia.Media.Brushes.Red;+ donut.SliceOpacity = 1;+ donut.SliceBorderBrush = null;+ var at = At(donut, Math.PI / 3);+ donut.SetExternalHit(donut.HitTest(at), at);+ var probe = At(donut, Math.PI / 3 + 0.35);+ var before = PixelAt(donut, probe);+ Assert.True(before[0] > before[2], "The highlight has not lit up yet");+ Assert.True(donut.Flip());+ var after = PixelAt(donut, probe);+ Assert.All(Enumerable.Range(0, 4), c => Assert.InRange(after[c] - before[c], -2, 2));+ }+ finally { window.Close(); }+ }++ [AvaloniaFact]+ public void T3_unequal_faces_wait_for_overlapping_old_slices()+ {+ foreach (var (front, back) in new[] { (6, 4), (1, 6), (6, 1) })+ {+ var (donut, window) = Wave(front, back);+ try+ {+ Assert.True(donut.Flip());+ donut.Advance(0.061);+ if (front == 1)+ {+ Assert.Equal(0, donut.SliceFlipWidth(true, 0));+ Assert.True(donut.SliceFlipWidth(false, 0) > 0);+ Assert.Equal(0, donut.SliceFlipWidth(false, 1));+ }+ if (back == 1)+ Assert.Equal(0, donut.SliceFlipWidth(false, 0));+ if (front == 6 && back == 4)+ {+ Assert.True(donut.SliceFlipWidth(true, 1) > 0);+ Assert.Equal(0, donut.SliceFlipWidth(false, 1));+ donut.Advance(0.039);+ Assert.Equal(0, donut.SliceFlipWidth(true, 1));+ Assert.True(donut.SliceFlipWidth(true, 2) > 0);+ Assert.Equal(0, donut.SliceFlipWidth(false, 1));+ donut.Advance(0.014);+ Assert.Equal(0, donut.SliceFlipWidth(true, 2));+ Assert.True(donut.SliceFlipWidth(false, 1) > 0);+ }+ Assert.True(donut.ShadowCoverage <= 1);+ donut.Advance(DonutMenu.FlipDuration);+ Assert.All(Enumerable.Range(0, back), i => Assert.Equal(1, donut.SliceFlipWidth(false, i)));+ }+ finally { window.Close(); }+ }+ var (pointed, pointedWindow) = Wave(6, 1);+ try+ {+ pointed.SetExternalHit(pointed.HitTest(At(pointed, Math.PI)), At(pointed, Math.PI));+ pointed.Flip();+ pointed.Advance(0.061);+ Assert.True(pointed.SliceFlipWidth(false, 0) > 0);+ Assert.True(pointed.SliceFlipWidth(true, 0) > 0);+ }+ finally { pointedWindow.Close(); }+ var (layered, layeredWindow) = Wave(6, 1);+ try+ {+ layered.SliceBrush = Avalonia.Media.Brushes.Blue;+ layered.AccentBrush = Avalonia.Media.Brushes.Red;+ layered.SliceOpacity = 1;+ layered.SliceBorderBrush = null;+ layered.SetExternalHit(layered.HitTest(At(layered, 0)), At(layered, 0));+ layered.Flip();+ layered.Advance(0.13);+ Assert.True(layered.SliceFlipWidth(true, 3) > 0);+ Assert.True(layered.SliceFlipWidth(false, 0) > 0);+ var oldOnTop = PixelAt(layered, At(layered, Math.PI));+ layered.FinishAnimations();+ var newFace = PixelAt(layered, At(layered, Math.PI));+ Assert.True(oldOnTop[0] > oldOnTop[2], "The old blue slice must cover the new red ring");+ Assert.True(newFace[2] > newFace[0], "The new highlighted ring must be red at the same point");+ }+ finally { layeredWindow.Close(); }+ var (keyboard, keyboardWindow) = Wave(6, 1);+ try+ {+ keyboard.HandleKey(Key.Right);+ keyboard.HandleKey(Key.Right); // 60 degrees on the old face+ keyboard.Flip();+ Assert.Equal(Math.PI / 3, keyboard.FlipOrigin!.Value, 8);+ keyboard.Advance(0.13);+ Assert.Equal(0, keyboard.SliceFlipWidth(false, 0));+ keyboard.Advance(0.011);+ Assert.True(keyboard.SliceFlipWidth(false, 0) > 0);+ }+ finally { keyboardWindow.Close(); }+ }++ [AvaloniaFact]+ public void T4_moving_a_drag_retargets_the_old_and_new_slices()+ {+ var (donut, window) = Wave(6, 1);+ try+ {+ donut.SliceBrush = Avalonia.Media.Brushes.Blue;+ donut.AccentBrush = Avalonia.Media.Brushes.Red;+ donut.SliceOpacity = 1;+ donut.SliceBorderBrush = null;+ donut.SetExternalHit(donut.HitTest(At(donut, 0)), At(donut, 0));+ donut.FinishAnimations(); // the drag highlight is fully lit before the flip keeps it+ donut.Flip();+ Assert.Equal("back0", donut.Items![0].Id);+ Assert.True(donut.HasOldFace);+ donut.Advance(0.01);+ var paintAt = DonutGeometry.PointAt(new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2),+ donut.OuterRadius * 0.9, 0);+ var oldHighlight = PixelAt(donut, paintAt);+ donut.SetExternalHit(donut.HitTest(At(donut, Math.PI)), At(donut, Math.PI));+ var clearedHighlight = PixelAt(donut, paintAt);+ Assert.True(oldHighlight[2] > oldHighlight[0], $"The old highlighted slice starts red: {string.Join(',', oldHighlight)}");+ Assert.True(clearedHighlight[0] > clearedHighlight[2], $"Moving the drag clears the old red highlight: {string.Join(',', clearedHighlight)}");+ donut.Advance(0.061);+ Assert.Equal(0, donut.SliceFlipWidth(true, 3));+ Assert.True(donut.SliceFlipWidth(false, 0) > 0);+ Assert.True(donut.SliceFlipWidth(true, 1) > 0);+ var newHighlight = PixelAt(donut, DonutGeometry.PointAt(+ new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2), donut.OuterRadius * 0.9, Math.PI));+ Assert.True(newHighlight[2] > 50 && newHighlight[0] < 255,+ $"The new highlighted slice is visible under the drag: {string.Join(',', newHighlight)}");+ }+ finally { window.Close(); }+ var (pointer, pointerWindow) = Wave(6, 1);+ try+ {+ pointer.SliceBrush = Avalonia.Media.Brushes.Blue;+ pointer.AccentBrush = Avalonia.Media.Brushes.Red;+ pointer.SliceOpacity = 1;+ pointer.SliceBorderBrush = null;+ pointerWindow.MouseMove(At(pointer, 0));+ pointer.Flip();+ pointer.Advance(0.01);+ pointerWindow.MouseMove(At(pointer, Math.PI));+ pointer.Advance(0.061);+ Assert.Equal(0, pointer.SliceFlipWidth(true, 3));+ Assert.True(pointer.SliceFlipWidth(false, 0) > 0);+ var belowPointer = PixelAt(pointer, DonutGeometry.PointAt(+ new Point(pointer.Bounds.Width / 2, pointer.Bounds.Height / 2), pointer.OuterRadius * 0.9, Math.PI));+ Assert.True(belowPointer[2] > 50 && belowPointer[0] < 255,+ $"The pointed new ring is visible after the old slice folds: {string.Join(',', belowPointer)}");+ }+ finally { pointerWindow.Close(); }+ var (keyboard, keyboardWindow) = Wave();+ try+ {+ keyboard.Flip();+ keyboard.Advance(0.01);+ Assert.Equal(0, keyboard.SliceFlipWidth(false, 1));+ keyboard.HandleKey(Key.Right);+ keyboard.HandleKey(Key.Right);+ keyboard.Advance(0.001);+ Assert.True(keyboard.SliceFlipWidth(false, 1) > 0);+ keyboard.Advance(0.061);+ Assert.Equal(0, keyboard.SliceFlipWidth(true, 2));+ }+ finally { keyboardWindow.Close(); }+ With(animations: true, back: null, () =>+ {+ var (vm, live, control) = OpenClickMode();+ control.HandleKey(Key.Right);+ control.HandleKey(Key.Right);+ Assert.Equal(1, control.ActiveIndex);+ control.Flip();+ Assert.True(vm.IsBackFace);+ Assert.Equal(-1, control.ActiveIndex);+ Assert.Equal(AppHost.Get<ILocalizer>()["donut.close_hint"], vm.CenterSubtitle);+ live.MouseMove(control.TranslatePoint(At(control, 0), live)!.Value);+ Assert.Equal(0, control.ActiveIndex);+ Assert.Contains(vm.Items[0].Label, vm.CenterSubtitle);+ live.Close();+ });+ }++ [AvaloniaFact]+ public void Drag_entering_a_slice_on_the_same_spoke_pulls_the_wave_forward()+ {+ var (donut, window) = Wave(6, 1);+ try+ {+ donut.SetExternalHit(donut.HitTest(At(donut, 0)), At(donut, 0));+ donut.Flip();+ donut.Advance(0.01);+ var outside = DonutGeometry.PointAt(+ new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2), donut.OuterRadius + 40, Math.PI);+ donut.SetExternalHit(donut.HitTest(outside), outside);+ Assert.Equal(1, donut.SliceFlipWidth(true, 3));+ var inside = At(donut, Math.PI);+ donut.SetExternalHit(donut.HitTest(inside), inside);+ donut.Advance(0.061);+ Assert.Equal(0, donut.SliceFlipWidth(true, 3));+ Assert.True(donut.SliceFlipWidth(false, 0) > 0);+ }+ finally { window.Close(); }+ }++ [AvaloniaFact]+ public void T5_group_ring_is_retained_only_for_drawing()+ {+ var (donut, window) = Wave();+ try+ {+ donut.ReserveSubRing = true;+ Dispatcher.UIThread.RunJobs();+ donut.SliceBrush = Avalonia.Media.Brushes.Blue;+ donut.AccentBrush = Avalonia.Media.Brushes.Red;+ donut.SliceOpacity = 1;+ donut.SliceBorderBrush = null;+ donut.Items = [new DonutItem { Id = "group", Label = "Group",+ Children = [new DonutItem { Id = "child", Label = "Child" },+ new DonutItem { Id = "other", Label = "Other" }] },+ .. donut.Items!.Skip(1)];+ donut.SetExternalHit(donut.HitTest(At(donut, 0)), At(donut, 0));+ donut.ExpandPendingGroup();+ donut.Advance(0.04);+ var sub = donut.SubSliceCenter(0, 0);+ Assert.Equal(DonutHitKind.SubSegment, donut.HitTest(sub).Kind);+ donut.SetExternalHit(donut.HitTest(sub), sub);+ var highlighted = PixelAt(donut, sub);+ Assert.True(highlighted[2] > highlighted[0], "The selected sub-slice is red");+ donut.Flip();+ Assert.True(donut.HasOldGroupRing);+ Assert.NotEqual(DonutHitKind.SubSegment, donut.HitTest(sub).Kind);+ var retained = PixelAt(donut, sub);+ Assert.All(Enumerable.Range(0, 4), i => Assert.InRange((int)retained[i] - highlighted[i], -2, 2));+ Assert.True(retained[2] > retained[0], "The snapshot retains the selected sub-slice highlight");+ donut.Advance(0.061);+ Assert.Equal(0, donut.SliceFlipWidth(true, 0));+ Assert.Equal(0, AlphaAt(donut, sub));+ donut.Advance(DonutMenu.FlipDuration);+ Assert.False(donut.HasOldGroupRing);+ }+ finally { window.Close(); }+ }++ [AvaloniaFact]+ public void T6_finishing_cancelling_and_closing_release_old_drawings()+ {+ for (var scenario = 0; scenario < 4; scenario++)+ {+ var (donut, window) = Wave();+ try+ {+ donut.Flip();+ Assert.True(donut.HasOldFace);+ switch (scenario)+ {+ case 0: Motion.Configure(true, () => false); donut.Advance(0); break;+ case 1: donut.FinishAnimations(); break;+ case 2: donut.Items = [new DonutItem { Id = "new", Label = "New" }]; break;+ case 3: donut.PlayCloseAnimation(() => { }); break;+ }+ Assert.False(donut.HasOldFace);+ Assert.False(donut.HasOldGroupRing);+ }+ finally { window.Close(); Motion.Configure(false, () => false); }+ }+ }++ [AvaloniaFact]+ public void T7_editor_flip_in_starts_half_open_and_ends_in_point_fourteen_seconds()+ {+ TestServices.EnsureInitialized();+ Motion.Configure(false, () => false);+ var originalBack = Images.BackPresetIds?.ToList();+ using var main = new MainWindowViewModel(AppHost.Services, AppHost.Get<ILocalizer>(), AppHost.Get<UpdateService>());+ main.Navigate("toolbar");+ var window = new MainWindow { DataContext = main, Width = 1080, Height = 1000 };+ try+ {+ window.Show();+ var page = (ToolbarPageViewModel)main.CurrentPage!;+ page.SelectedProfile = page.Profiles.Single(p => p.Profile.Id == "images");+ RenderTests.Pump();+ Motion.Configure(false, () => false);+ var donut = window.GetVisualDescendants().OfType<DonutMenu>().Single();+ var faces = window.GetVisualDescendants().OfType<Avalonia.Controls.Border>()+ .Single(b => b.Name == "FaceSwitch").GetVisualDescendants().OfType<Avalonia.Controls.RadioButton>().ToList();+ faces[1].IsChecked = true;+ Assert.True(page.EditingBack);+ Assert.Equal(ImageBack, page.DonutItems.Select(i => i.Id));+ Assert.True(donut.IsFlipping);+ Assert.False(donut.HasOldFace);+ Assert.Equal(0, donut.FlipOrigin);+ Assert.True(donut.SliceFlipWidth(false, 0) > 0);+ Assert.Equal(0, donut.SliceFlipWidth(false, 2));+ donut.Advance(DonutMenu.FlipDuration - DonutMenu.SliceTurn / 2);+ Assert.False(donut.IsFlipping);+ Assert.Equal(1, donut.SliceFlipWidth(false, 2));+ donut.AccentBrush = Avalonia.Media.Brushes.Red;+ var button = DonutGeometry.PointAt(new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2),+ donut.OuterRadius - 14 + 7, 0);+ var buttonEdge = new Point(button.X + 8, button.Y);+ var beforeHover = PixelAt(donut, buttonEdge);+ window.MouseMove(donut.TranslatePoint(At(donut, 0), window)!.Value);+ var drawnButton = PixelAt(donut, buttonEdge);+ Assert.NotEqual(beforeHover, drawnButton);+ Assert.True(drawnButton[2] > drawnButton[0], "The edit button is drawn after the switch completes");+ var beforeFront = Images.PresetIds.ToList();+ var beforeBack = ImageBack;+ page.RemoveAt(page.SliceCount - 1);+ RenderTests.Pump();+ var chip = window.GetVisualDescendants().OfType<Avalonia.Controls.Border>()+ .Single(b => b.Classes.Contains("chip") && b.DataContext is PaletteChip { PresetId: "to-psd" });+ chip.BringIntoView();+ RenderTests.Pump();+ var from = chip.TranslatePoint(new Point(chip.Bounds.Width / 2, chip.Bounds.Height / 2), window)!.Value;+ var to = donut.TranslatePoint(new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2), window)!.Value;+ window.MouseDown(from, Avalonia.Input.MouseButton.Left);+ window.MouseMove(to);+ window.MouseUp(to, Avalonia.Input.MouseButton.Left);+ RenderTests.Pump();+ Assert.Contains("to-psd", Images.BackPresetIds!);+ Assert.Equal(beforeFront, Images.PresetIds);+ Assert.Equal(beforeBack.Count, Images.BackPresetIds!.Count);+ Motion.Configure(true, () => false);+ faces[0].IsChecked = true;+ Assert.False(donut.IsFlipping);+ Assert.Equal(1, donut.SliceFlipWidth(false, 0));+ }+ finally+ {+ window.Close();+ Images.BackPresetIds = originalBack;+ Store.SaveLibrary();+ Motion.Configure(false, () => false);+ }+ }++ [AvaloniaFact]+ public void T8_wedge_cache_does_not_grow_on_the_second_wave()+ {+ var (donut, window) = Wave();+ try+ {+ donut.Flip();+ using (var image = new Avalonia.Media.Imaging.RenderTargetBitmap(new PixelSize((int)window.Bounds.Width, (int)window.Bounds.Height)))+ image.Render(window);+ donut.FinishAnimations();+ using (var image = new Avalonia.Media.Imaging.RenderTargetBitmap(new PixelSize((int)window.Bounds.Width, (int)window.Bounds.Height)))+ image.Render(window);+ donut.Flip();+ donut.FinishAnimations();+ using (var image = new Avalonia.Media.Imaging.RenderTargetBitmap(new PixelSize((int)window.Bounds.Width, (int)window.Bounds.Height)))+ image.Render(window);+ var cached = donut.CachedWedgeCount;+ donut.Flip();+ foreach (var dt in new[] { 0.02, 0.03, 0.04, 0.05, 0.06 })+ {+ donut.Advance(dt);+ using var image = new Avalonia.Media.Imaging.RenderTargetBitmap(new PixelSize((int)window.Bounds.Width, (int)window.Bounds.Height));+ image.Render(window);+ Assert.Equal(cached, donut.CachedWedgeCount);+ }+ }+ finally { window.Close(); }+ }+[AvaloniaFact]public void Tab_flips_to_the_back_and_shift_tab_back_to_the_front_in_click_mode() => With(animations: true, back: null, () =>{@@ -96,19 +623,20 @@ public class DonutFlipTestsAssert.True(donut.HandleKey(Key.Tab));Assert.True(donut.IsFlipping);- donut.Advance(DonutMenu.FlipDuration * 0.3);- Assert.InRange(donut.FlipScale, 0.01, 0.99); // turning, still the front- Assert.False(vm.IsBackFace);- Assert.Equal(front, vm.Items.Select(i => i.Id));+ Assert.True(vm.IsBackFace);+ Assert.Equal(ImageBack, vm.Items.Select(i => i.Id));+ donut.Advance(DonutMenu.FlipDuration * 0.2);+ Assert.InRange(donut.SliceFlipWidth(true, 0), 0.01, 0.99);- donut.Advance(DonutMenu.FlipDuration * 0.3); // past edge-on: the back+ donut.Advance(DonutMenu.FlipDuration * 0.3);Assert.True(vm.IsBackFace);Assert.Equal(ImageBack, vm.Items.Select(i => i.Id));Assert.Equal(loc.Format("donut.flip_to_front", "Tab"), donut.CenterHint);Assert.Equal(loc["donut.close_hint"], vm.CenterSubtitle);donut.Advance(DonutMenu.FlipDuration);Assert.False(donut.IsFlipping);- Assert.Equal(1, donut.FlipScale);+ Assert.Equal(1, donut.SliceFlipWidth(false, 0));+ Assert.False(donut.HasOldFace);Assert.True(donut.HandleKey(Key.Tab, KeyModifiers.Shift));donut.Advance(DonutMenu.FlipDuration);@@ -169,7 +697,8 @@ public class DonutFlipTestsvar (vm, window, donut) = OpenClickMode();Assert.True(donut.Flip());Assert.False(donut.IsFlipping);- Assert.Equal(1, donut.FlipScale);+ Assert.False(donut.HasOldFace);+ Assert.Equal(1, donut.SliceFlipWidth(false, 0));Assert.True(vm.IsBackFace);Assert.False(donut.Advance(0)); // nothing left to animatewindow.Close();@@ -246,13 +775,17 @@ public class DonutFlipTestsvar group = vm.Items.Count - 1;donut.SetExternalHit(new DonutHit(DonutHitKind.Segment, group));donut.ExpandPendingGroup();- Assert.Equal(DonutHitKind.SubSegment, donut.HitTest(donut.SubSliceCenter(group, 1)).Kind);+ var sub = donut.SubSliceCenter(group, 1);+ Assert.Equal(DonutHitKind.SubSegment, donut.HitTest(sub).Kind);+ donut.Advance(0.04);donut.HandleKey(Key.Tab);- Assert.NotEqual(DonutHitKind.SubSegment, donut.HitTest(donut.SubSliceCenter(group, 1)).Kind);- Assert.False(vm.IsBackFace); // the ring folds first, the faces swap halfway through the turn+ Assert.NotEqual(DonutHitKind.SubSegment, donut.HitTest(sub).Kind);+ Assert.True(vm.IsBackFace); // only the drawing keeps the old ring+ Assert.True(donut.HasOldGroupRing);donut.Advance(DonutMenu.FlipDuration);Assert.True(vm.IsBackFace);+ Assert.False(donut.HasOldGroupRing);window.Close();});@@ -614,19 +1147,20 @@ public class DonutFlipTests// Drawn right here, not by the render loop: that would play the rest of the turn first.donut.HandleKey(Key.Tab);donut.Advance(DonutMenu.FlipDuration * 0.3);- Assert.InRange(donut.FlipScale, 0.2, 0.8);+ Assert.InRange(donut.SliceFlipWidth(false, 0), 0.01, 0.99);var size = new PixelSize((int)window.Bounds.Width, (int)window.Bounds.Height);using (var turning = new Avalonia.Media.Imaging.RenderTargetBitmap(size)){turning.Render(window);- turning.Save(Path.Combine(TestServices.ScreenshotDirectory, $"donut-flip-midway-{suffix}.png"));+ using var png = File.Create(Path.Combine(TestServices.ScreenshotDirectory, $"donut-flip-midway-{suffix}.png"));+ turning.Save(png, new Avalonia.Media.Imaging.PngBitmapEncoderOptions());}donut.FinishAnimations();Assert.True(vm.IsBackFace);donut.SetExternalHighlight(2);RenderTests.Pump();- Assert.Equal(1, donut.FlipScale);+ Assert.Equal(1, donut.SliceFlipWidth(false, 0));RenderTests.Save(window, $"donut-back-{suffix}.png");window.Close();}