Browse Source

Fixed color picker accuracy and handle shutdown as close

Krzysztof Krysiński 2 months ago
parent
commit
3561037ade

+ 3 - 0
src/PixiEditor.ChangeableDocument/Rendering/DocumentRenderer.cs

@@ -5,6 +5,7 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Bridge;
 using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
@@ -211,6 +212,7 @@ public class DocumentRenderer : IPreviewRenderable, IDisposable
     public void RenderDocument(DrawingSurface toRenderOn, KeyFrameTime frameTime, VecI renderSize,
         string? customOutput = null)
     {
+        var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         IsBusy = true;
 
         if (renderTexture == null || renderTexture.Size != renderSize)
@@ -262,6 +264,7 @@ public class DocumentRenderer : IPreviewRenderable, IDisposable
         renderTexture.DrawingSurface.Canvas.Restore();
         toRenderOn.Canvas.Restore();
 
+        ctx.Dispose();
         IsBusy = false;
     }
 

+ 1 - 22
src/PixiEditor/Initialization/ClassicDesktopEntry.cs

@@ -226,28 +226,7 @@ internal class ClassicDesktopEntry
         if (vm is null)
             return;
 
-        if (vm.DocumentManagerSubViewModel.Documents.Any(x => !x.AllChangesSaved))
-        {
-            e.Cancel = true;
-            Task.Run(async () =>
-            {
-                await Dispatcher.UIThread.InvokeAsync(async () =>
-                {
-                    ConfirmationType confirmation = await ConfirmationDialog.Show(
-                        new LocalizedString("SESSION_UNSAVED_DATA", "Shutdown"),
-                        $"Shutdown");
-
-                    if (confirmation == ConfirmationType.Yes)
-                    {
-                        desktop.Shutdown();
-                    }
-                    else
-                    {
-                        e.Cancel = true;
-                    }
-                });
-            });
-        }
+        vm.OnShutdown(e, () => desktop.Shutdown(0));
     }
 
     private void AttachGlobalShortcutBehavior(BehaviorCollection collection)

+ 2 - 2
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -971,10 +971,10 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
             {
                 if (maybeMember is IRasterizable rasterizable)
                 {
-                    using Texture texture = Texture.ForDisplay(SizeBindable);
+                    using Surface texture = new Surface(SizeBindable);
                     using Paint paint = new Paint();
                     rasterizable.Rasterize(texture.DrawingSurface, paint);
-                    return texture.GetSRGBPixel(pos);
+                    return texture.GetSrgbPixel(pos);
                 }
             }
             else

+ 24 - 0
src/PixiEditor/ViewModels/ViewModelMain.cs

@@ -1,6 +1,7 @@
 using System.ComponentModel;
 using System.Linq;
 using System.Threading.Tasks;
+using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Threading;
 using CommunityToolkit.Mvvm.Input;
 using Microsoft.Extensions.DependencyInjection;
@@ -356,6 +357,29 @@ internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
         return false;
     }
 
+
+    public void OnShutdown(ShutdownRequestedEventArgs shutdownRequestedEventArgs, Action shutdown)
+    {
+        shutdownRequestedEventArgs.Cancel = true;
+        Dispatcher.UIThread.InvokeAsync(async () =>
+        {
+            ResetNextSessionFiles();
+            UserWantsToClose = await DisposeAllDocumentsWithSaveConfirmation();
+
+            if (UserWantsToClose)
+            {
+                var analytics = Services.GetService<AnalyticsPeriodicReporter>();
+                if (analytics != null)
+                {
+                    await analytics.StopAsync();
+                }
+
+                OnClose?.Invoke();
+                shutdown();
+            }
+        });
+    }
+
     private void OnActiveDocumentChanged(object sender, DocumentChangedEventArgs e)
     {
         NotifyToolActionDisplayChanged();