浏览代码

Useable browser version (yaaaaay)

CPKreuz 1 年之前
父节点
当前提交
8e87facd1e

+ 4 - 13
src/PixiEditor.AvaloniaUI.Browser/Program.cs

@@ -9,19 +9,10 @@ using PixiEditor.AvaloniaUI;
 
 internal partial class Program
 {
-    private static async Task Main(string[] args)
-    {
-        try
-        {
-            await BuildAvaloniaApp()
-                .WithInterFont()
-                .StartBrowserAppAsync("out");
-        }
-        catch (Exception e)
-        {
-            Console.WriteLine(e);
-        }
-    }
+    private static async Task Main(string[] args) =>
+        await BuildAvaloniaApp()
+            .WithInterFont()
+            .StartBrowserAppAsync("out");
 
     public static AppBuilder BuildAvaloniaApp()
         => AppBuilder.Configure<App>();

+ 13 - 15
src/PixiEditor.AvaloniaUI/Models/Commands/XAML/Command.cs

@@ -22,27 +22,25 @@ internal class Command : MarkupExtension
 
     public override object ProvideValue(IServiceProvider serviceProvider)
     {
-        // if (Design.IsDesignMode)
-        // {
-        //     var attribute = DesignCommandHelpers.GetCommandAttribute(Name);
-        //     return GetICommand(
-        //         new Commands.Command.BasicCommand(null, null)
-        //         {
-        //             InternalName = Name,
-        //             DisplayName = attribute.DisplayName,
-        //             Description = attribute.Description,
-        //             DefaultShortcut = attribute.GetShortcut(),
-        //             Shortcut = attribute.GetShortcut()
-        //         }, false);
-        // }
+        if (Design.IsDesignMode)
+        {
+            var attribute = DesignCommandHelpers.GetCommandAttribute(Name);
+            return GetICommand(
+                new Commands.Command.BasicCommand(null, null)
+                {
+                    InternalName = Name,
+                    DisplayName = attribute.DisplayName,
+                    Description = attribute.Description,
+                    DefaultShortcut = attribute.GetShortcut(),
+                    Shortcut = attribute.GetShortcut()
+                }, false);
+        }
         
         if (commandController is null)
         {
             commandController = CommandController.Current; // TODO: Find a better way to get the current CommandController
         }
 
-        Console.WriteLine($"Hello PixiEditor kakakakaka, 'commandController != null' => {commandController != null}!");
-
         var command = commandController.Commands[Name];
         return GetPixiCommand ? command : GetICommand(command, UseProvided);
     }

+ 3 - 3
src/PixiEditor.AvaloniaUI/Models/DocumentModels/ActionAccumulator.cs

@@ -74,7 +74,7 @@ internal class ActionAccumulator
             }
             else
             {
-                changes = await internals.Tracker.ProcessActions(toExecute);
+                changes = internals.Tracker.ProcessActionsSync(toExecute);
             }
 
             // update viewmodels based on changes
@@ -91,8 +91,8 @@ internal class ActionAccumulator
             // update the contents of the bitmaps
             var affectedAreas = new AffectedAreasGatherer(internals.Tracker, optimizedChanges);
             List<IRenderInfo> renderResult = new();
-            renderResult.AddRange(await canvasUpdater.UpdateGatheredChunks(affectedAreas, undoBoundaryPassed || viewportRefreshRequest));
-            renderResult.AddRange(await previewUpdater.UpdateGatheredChunks(affectedAreas, undoBoundaryPassed));
+            renderResult.AddRange(canvasUpdater.UpdateGatheredChunksSync(affectedAreas, undoBoundaryPassed || viewportRefreshRequest));
+            renderResult.AddRange(previewUpdater.UpdateGatheredChunksSync(affectedAreas, undoBoundaryPassed));
 
             if (undoBoundaryPassed)
             {

+ 2 - 2
src/PixiEditor.AvaloniaUI/ViewModels/Document/DocumentManagerViewModel.cs

@@ -48,9 +48,9 @@ internal class DocumentManagerViewModel : SubViewModel<ViewModelMain>, IDocument
 
     public bool HasActiveDocument => ActiveDocument != null;
 
-    public DocumentManagerViewModel(ViewModelMain owner, WindowViewModel windowViewModel) : base(owner)
+    public DocumentManagerViewModel(ViewModelMain owner) : base(owner)
     {
-        windowViewModel.ActiveViewportChanged += (_, args) => ActiveDocument = args.Document;
+        owner.WindowSubViewModel.ActiveViewportChanged += (_, args) => ActiveDocument = args.Document;
     }
 
     public void MakeActiveDocumentNull() => ActiveDocument = null;

+ 0 - 4
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/FileViewModel.cs

@@ -99,8 +99,6 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
 
     private void Owner_OnStartupEvent(object sender, System.EventArgs e)
     {
-        Console.WriteLine("Owner starutp before");
-        
         // List<string> args = StartupArgs.Args;
         // string file = args.FirstOrDefault(x => Importer.IsSupportedFile(x) && File.Exists(x));
         // if (file != null)
@@ -114,8 +112,6 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         //         OpenHelloTherePopup();
         //     }
         // }
-        
-        Console.WriteLine("Owner startup after");
     }
 
     [Command.Internal("PixiEditor.File.OpenRecent")]

+ 3 - 3
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/LayoutViewModel.cs

@@ -13,11 +13,11 @@ internal class LayoutViewModel : SubViewModel<ViewModelMain>
         private init => SetProperty(ref layoutManagerManager, value);
     }
 
-    public LayoutViewModel(ViewModelMain owner, WindowViewModel windowViewModel) : base(owner)
+    public LayoutViewModel(ViewModelMain owner) : base(owner)
     {
         LayoutManager = new();
-        windowViewModel.ViewportAdded += WindowSubViewModel_ViewportAdded;
-        windowViewModel.ViewportClosed += WindowSubViewModel_ViewportRemoved;
+        owner.WindowSubViewModel.ViewportAdded += WindowSubViewModel_ViewportAdded;
+        owner.WindowSubViewModel.ViewportClosed += WindowSubViewModel_ViewportRemoved;
     }
 
     private void WindowSubViewModel_ViewportAdded(ViewportWindowViewModel obj)

+ 0 - 13
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/SearchViewModel.cs

@@ -49,19 +49,6 @@ internal class SearchViewModel : SubViewModel<ViewModelMain>, ISearchHandler
         {
             SearchTerm = searchTerm;
         }
-
-        try
-        {
-            Owner.FileSubViewModel.NewDocument(b => b
-                .WithSize(64, 64)
-                .WithLayer(l => l
-                    .WithName(new LocalizedString("BASE_LAYER_NAME"))
-                    .WithSurface(new Surface(new VecI(64, 64)))));
-        }
-        catch (Exception e)
-        {
-            Console.WriteLine(e);
-        }
     }
 
     public void OpenSearchWindow(string searchTerm, bool selectAll = true)

+ 1 - 50
src/PixiEditor.AvaloniaUI/ViewModels/ViewModelMain.cs

@@ -1,8 +1,6 @@
 using System.ComponentModel;
 using System.Linq;
-using System.Runtime.CompilerServices;
 using System.Threading.Tasks;
-using ChunkyImageLib;
 using CommunityToolkit.Mvvm.Input;
 using Microsoft.Extensions.DependencyInjection;
 using PixiEditor.AvaloniaUI.Helpers.Collections;
@@ -17,7 +15,6 @@ using PixiEditor.AvaloniaUI.ViewModels.SubViewModels.AdditionalContent;
 using PixiEditor.AvaloniaUI.ViewModels.Tools;
 using PixiEditor.AvaloniaUI.Views.Dialogs;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
-using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.Common.UserPreferences;
 
@@ -108,41 +105,27 @@ internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
     }
 
     public void Setup(IServiceProvider services)
- {
+    {
         Services = services;
 
-        ShowMessage();
-
         Preferences = services.GetRequiredService<IPreferences>();
         Preferences.Init();
 
-        ShowMessage();
-
         CommandController = services.GetService<CommandController>();
 
-        ShowMessage();
-
         LocalizationProvider = services.GetRequiredService<ILocalizationProvider>();
         LocalizationProvider.LoadData();
 
-        ShowMessage();
-
         WindowSubViewModel = services.GetService<WindowViewModel>();
         LayoutSubViewModel = services.GetService<LayoutViewModel>();
 
-        ShowMessage();
-
         DocumentManagerSubViewModel = services.GetRequiredService<DocumentManagerViewModel>();
         SelectionSubViewModel = services.GetService<SelectionViewModel>();
 
-        ShowMessage();
-
         FileSubViewModel = services.GetService<FileViewModel>();
         ToolsSubViewModel = services.GetService<IToolsHandler>();
         ToolsSubViewModel.SelectedToolChanged += ToolsSubViewModel_SelectedToolChanged;
 
-        ShowMessage();
-
         IoSubViewModel = services.GetService<IoViewModel>();
         LayersSubViewModel = services.GetService<LayersViewModel>();
         ClipboardSubViewModel = services.GetService<ClipboardViewModel>();
@@ -151,64 +134,32 @@ internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
         ColorsSubViewModel = services.GetService<ColorsViewModel>();
         ColorsSubViewModel?.SetupPaletteProviders(services);
 
-        ShowMessage();
-
         ToolsSubViewModel?.SetupTools(services);
 
-        ShowMessage();
-
         DiscordViewModel = services.GetService<DiscordViewModel>();
         UpdateSubViewModel = services.GetService<UpdateViewModel>();
         DebugSubViewModel = services.GetService<DebugViewModel>();
 
-        ShowMessage();
-
         StylusSubViewModel = services.GetService<StylusViewModel>();
         RegistrySubViewModel = services.GetService<RegistryViewModel>();
 
-        ShowMessage();
-
         //AdditionalContentSubViewModel = services.GetService<AdditionalContentViewModel>();
 
-        ShowMessage();
-
         CommandController.Init(services);
         LayoutSubViewModel.LayoutManager.InitLayout(this);
 
-        ShowMessage();
-
         MiscSubViewModel = services.GetService<MiscViewModel>();
 
-        ShowMessage();
-
         ShortcutController = new ShortcutController();
 
-        ShowMessage();
-
         ToolsSubViewModel?.SetupToolsTooltipShortcuts(services);
 
-        ShowMessage();
-
         SearchSubViewModel = services.GetService<SearchViewModel>();
 
-        ShowMessage();
-
         ExtensionsSubViewModel = services.GetService<ExtensionsViewModel>(); // Must be last
 
-        ShowMessage();
-        
         DocumentManagerSubViewModel.ActiveDocumentChanged += OnActiveDocumentChanged;
-        
-    }
-    
-    static void ShowMessage(
-        string? message = null,
-        [CallerLineNumber] int lineNumber = 0,
-        [CallerMemberName] string? caller = null)
-    {
-        Console.WriteLine($"{message} {lineNumber} {caller}");
     }
-    
 
     public bool DocumentIsNotNull(object property)
     {

+ 5 - 4
src/PixiEditor.AvaloniaUI/Views/Main/MainTitleBar.axaml

@@ -23,6 +23,11 @@
             <MenuItem
                 ui:Translator.Key="FILE"
                 Focusable="False">
+                <!-- TODO: Please remove in case this makes it out of the testing branch -->
+                <MenuItem
+                    Header="Create debug document"
+                    xaml:Menu.Command="PixiEditor.Debug.CreateDebugDocument"/>
+                <Separator/>
                 <MenuItem
                     ui:Translator.Key="NEW_FILE"
                     xaml:Menu.Command="PixiEditor.File.New" />
@@ -264,10 +269,6 @@
                     Header="Open pointer debug window"
                     xaml:Menu.Command="PixiEditor.Debug.OpenPointerDebugWindow"/>
                 <Separator/>
-                <MenuItem
-                    Header="Create debug document"
-                    xaml:Menu.Command="PixiEditor.Debug.CreateDebugDocument"/>
-                <Separator/>
                 <MenuItem
                     ui:Translator.Key="OPEN_LOCAL_APPDATA_DIR"
                     xaml:Menu.Command="PixiEditor.Debug.OpenLocalAppDataDirectory" />

+ 20 - 2
src/PixiEditor.AvaloniaUI/Views/Main/ViewportControls/Viewport.axaml.cs

@@ -303,6 +303,14 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
 
         //TODO: It's weird that I had to do it this way, right click didn't raise Image_MouseUp otherwise.
         viewportGrid.AddHandler(PointerReleasedEvent, Image_MouseUp, RoutingStrategies.Tunnel);
+        
+        // TODO: this is also weird
+        if (System.OperatingSystem.IsBrowser())
+        {
+            this.AddHandler(PointerMovedEvent, Image_MouseMove, RoutingStrategies.Bubble);
+        }
+
+         // TODO: that's not how you're actually supposed to do it I think
         viewportGrid.AddHandler(PointerPressedEvent, Image_MouseDown, RoutingStrategies.Bubble);
     }
 
@@ -326,7 +334,7 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
     {
         InitializeOverlays();
         Document?.Operations.AddOrUpdateViewport(GetLocation());
-        mouseUpdateController = new MouseUpdateController(this, Image_MouseMove);
+        mouseUpdateController = new MouseUpdateController(this, args => Image_MouseMove(null, args));
     }
 
     private void InitializeOverlays()
@@ -385,6 +393,8 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
 
     private void Image_MouseDown(object? sender, PointerPressedEventArgs e)
     {
+        Console.WriteLine($"we got some mouse button down movement {e.GetCurrentPoint(this).Properties.PointerUpdateKind}");
+        
         bool isMiddle = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed;
         HandleMiddleMouse(isMiddle);
 
@@ -406,10 +416,16 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
             MouseDownCommand.Execute(parameter);
     }
 
-    private void Image_MouseMove(PointerEventArgs e)
+    private void Image_MouseMove(object? sender, PointerEventArgs e)
     {
+        Console.WriteLine("we got some mouse movement");
+
         if (MouseMoveCommand is null)
+        {
+            Console.WriteLine("but there isn't a mouse move comment");
             return;
+        }
+
         Point pos = e.GetPosition(MainImage);
         VecD conv = new VecD(pos.X, pos.Y);
 
@@ -428,6 +444,8 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
 
     private void Image_MouseUp(object? sender, PointerReleasedEventArgs e)
     {
+        Console.WriteLine($"we got some mouse button up movement {e.GetCurrentPoint(this).Properties.PointerUpdateKind}");
+        
         if (MouseUpCommand is null)
             return;
 

+ 2 - 0
src/PixiEditor.ChangeableDocument/DocumentChangeTracker.cs

@@ -317,7 +317,9 @@ public class DocumentChangeTracker : IDisposable
         if (running)
             throw new InvalidOperationException("Already currently processing");
         running = true;
+        Console.WriteLine($"Doing {actions.Count} now");
         var result = ProcessActionList(actions);
+        Console.WriteLine("We're done doing these");
         running = false;
         return result;
     }