Pārlūkot izejas kodu

Viewport somewhat is creating

Krzysztof Krysiński 2 gadi atpakaļ
vecāks
revīzija
f8c668ac28

+ 5 - 4
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/Models/Commands/XAML/ShortcutBinding.cs

@@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
 using PixiEditor.AvaloniaUI.Helpers;
 using PixiEditor.AvaloniaUI.Models.Handlers;
 using PixiEditor.AvaloniaUI.Models.Input;
+using PixiEditor.AvaloniaUI.ViewModels;
 using ActualCommand = PixiEditor.AvaloniaUI.Models.Commands.Commands.Command;
 
 namespace PixiEditor.AvaloniaUI.Models.Commands.XAML;
@@ -31,17 +32,17 @@ internal class ShortcutBinding : MarkupExtension
             return new KeyCombination(attribute.Key, attribute.Modifiers).ToString();
         }
 
-        ICommandsHandler? handler = serviceProvider.GetService<ICommandsHandler>();
+        ICommandsHandler? handler = ViewModelMain.Current;
         commandController ??= handler.CommandController;
-        var binding = GetBinding(commandController.Commands[Name], Converter);
+        return GetBinding(commandController.Commands[Name], Converter);
 
-        var targetValue = serviceProvider.GetService<IProvideValueTarget>();
+        /*var targetValue = serviceProvider.GetService<IProvideValueTarget>();
         var targetObject = targetValue.TargetObject as AvaloniaObject;
         var targetProperty = targetValue.TargetProperty as AvaloniaProperty;
 
         var instancedBinding = binding.Initiate(targetObject, targetProperty);
 
-        return instancedBinding; //TODO: This won't work, leaving it for now
+        return instancedBinding; //TODO: This won't work, leaving it for now*/
     }
 
     public static Binding GetBinding(ActualCommand command, IValueConverter converter) => new Binding

+ 2 - 2
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/ViewModels/ViewModelMain.cs

@@ -8,6 +8,7 @@ using PixiEditor.AvaloniaUI.Models.Commands;
 using PixiEditor.AvaloniaUI.Models.Controllers;
 using PixiEditor.AvaloniaUI.Models.Dialogs;
 using PixiEditor.AvaloniaUI.Models.DocumentModels;
+using PixiEditor.AvaloniaUI.Models.Handlers;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels.AdditionalContent;
@@ -19,14 +20,13 @@ using PixiEditor.Extensions.Common.UserPreferences;
 
 namespace PixiEditor.AvaloniaUI.ViewModels;
 
-internal partial class ViewModelMain : ViewModelBase
+internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
 {
     public static ViewModelMain Current { get; set; }
     public IServiceProvider Services { get; private set; }
 
     public Action CloseAction { get; set; }
     public event EventHandler OnStartupEvent;
-
     public FileViewModel FileSubViewModel { get; set; }
 
     public UpdateViewModel UpdateSubViewModel { get; set; }

+ 6 - 4
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/Views/Main/Viewport.axaml

@@ -24,7 +24,8 @@
         PointerPressed="Image_MouseDown"
         PointerReleased="Image_MouseUp">
         <Interaction.Behaviors>
-            <EventTriggerBehavior EventName="StylusButtonDown">
+            <!--TODO: Implement stylus support-->
+            <!--<EventTriggerBehavior EventName="StylusButtonDown">
                 <InvokeCommandAction Command="{Binding StylusButtonDownCommand, ElementName=vpUc}"
                                         PassEventArgsToCommand="True"/>
             </EventTriggerBehavior>
@@ -39,7 +40,7 @@
             <EventTriggerBehavior EventName="StylusOutOfRange">
                 <InvokeCommandAction Command="{Binding StylusOutOfRangeCommand, ElementName=vpUc}"
                                         PassEventArgsToCommand="True"/>
-            </EventTriggerBehavior>
+            </EventTriggerBehavior>-->
         </Interaction.Behaviors>
         <views:TogglableFlyout Margin="5" IconPath="/Images/Settings.png" ui:Translator.TooltipKey="VIEWPORT_SETTINGS"
                                ZIndex="2" HorizontalAlignment="Right" VerticalAlignment="Top">
@@ -110,6 +111,7 @@
         </Border>
             </views:TogglableFlyout.Child>
         </views:TogglableFlyout>
+        <!--TODO: Originally Dimensions and RealDimensions had Binding with OneWayToSource, but it resulted in stack overflow. Investigate-->
         <zoombox:Zoombox
             Tag="{Binding ElementName=vpUc}"
             x:Name="zoombox"
@@ -117,8 +119,8 @@
             Scale="{Binding ZoomboxScale, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
             Center="{Binding Center, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
             Angle="{Binding Angle, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
-            RealDimensions="{Binding RealDimensions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
-            Dimensions="{Binding Dimensions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
+            RealDimensions="{Binding RealDimensions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWay}"
+            Dimensions="{Binding Dimensions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWay}"
             ZoomMode="{Binding ZoomMode, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
             ZoomOutOnClick="{Binding ZoomOutOnClick, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
             FlipX="{Binding FlipX, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"

+ 3 - 3
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/Views/Main/Viewport.axaml.cs

@@ -243,11 +243,11 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
             realDimensions = value;
             ChunkResolution newRes = CalculateResolution();
 
-            PropertyChanged?.Invoke(this, new(nameof(RealDimensions)));
+            //PropertyChanged?.Invoke(this, new(nameof(RealDimensions)));
             Document?.Operations.AddOrUpdateViewport(GetLocation());
 
-            if (oldRes != newRes)
-                PropertyChanged?.Invoke(this, new(nameof(TargetBitmap)));
+            /*if (oldRes != newRes)
+                PropertyChanged?.Invoke(this, new(nameof(TargetBitmap)));*/
         }
     }
 

+ 7 - 18
src/PixiEditor.Avalonia/PixiEditor.AvaloniaUI/Views/MainView.axaml

@@ -55,10 +55,9 @@
 
               <!-- Documents Pane -->
 
-              <DocumentDock x:Name="DocumentsPane" Id="DocumentsPane" CanCreateDocument="True" ActiveDockable="Document1">
-                <DocumentDock.DocumentTemplate>
+              <DocumentDock x:Name="DocumentsPane" Id="DocumentsPane" CanCreateDocument="True">
+                  <DocumentDock.DocumentTemplate>
                   <DocumentTemplate>
-                      <!--Tool cursor not present here, since Avalonia doesn't have Cursor property??-->
                       <userControls:Viewport
                                              CenterViewportTrigger="{Binding CenterViewportTrigger}"
                                             ZoomViewportTrigger="{Binding ZoomViewportTrigger}"
@@ -71,10 +70,6 @@
                                             ZoomMode="{Binding ToolsSubViewModel.ActiveTool, Source={viewModels:MainVM}, Converter={converters:ActiveToolToZoomModeConverter}}"
                                             ZoomOutOnClick="{Binding ToolsSubViewModel.ZoomTool.ZoomOutOnClick, Source={viewModels:MainVM}}"
                                             UseTouchGestures="{Binding StylusSubViewModel.UseTouchGestures, Source={viewModels:MainVM}}"
-                                            StylusButtonDownCommand="{xaml:Command PixiEditor.Stylus.StylusDown, UseProvided=True}"
-                                            StylusButtonUpCommand="{xaml:Command PixiEditor.Stylus.StylusUp, UseProvided=True}"
-                                            StylusGestureCommand="{xaml:Command PixiEditor.Stylus.StylusSystemGesture, UseProvided=True}"
-                                            StylusOutOfRangeCommand="{xaml:Command PixiEditor.Stylus.StylusOutOfRange, UseProvided=True}"
                                             FlipX="{Binding FlipX, Mode=TwoWay}"
                                             FlipY="{Binding FlipY, Mode=TwoWay}"
                                             ContextRequested="Viewport_OnContextMenuOpening"
@@ -93,20 +88,20 @@
                                                                         <StackPanel Orientation="Vertical" Grid.Column="0">
                                                                             <MenuItem
 																		ui:Translator.Key="SELECT_ALL"
-																		xaml:ContextMenu.Command="PixiEditor.Selection.SelectAll" />
+																		xaml:Menu.Command="PixiEditor.Selection.SelectAll" />
                                                                             <MenuItem
                                                                                 ui:Translator.Key="DESELECT"
-                                                                                xaml:ContextMenu.Command="PixiEditor.Selection.Clear" />
+                                                                                xaml:Menu.Command="PixiEditor.Selection.Clear" />
                                                                             <Separator />
                                                                             <MenuItem
                                                                                 ui:Translator.Key="CUT"
-                                                                                xaml:ContextMenu.Command="PixiEditor.Clipboard.Cut" />
+                                                                                xaml:Menu.Command="PixiEditor.Clipboard.Cut" />
                                                                             <MenuItem
                                                                                 ui:Translator.Key="COPY"
-                                                                                xaml:ContextMenu.Command="PixiEditor.Clipboard.Copy" />
+                                                                                xaml:Menu.Command="PixiEditor.Clipboard.Copy" />
                                                                             <MenuItem
                                                                                 ui:Translator.Key="PASTE"
-                                                                                xaml:ContextMenu.Command="PixiEditor.Clipboard.Paste" />
+                                                                                xaml:Menu.Command="PixiEditor.Clipboard.Paste" />
                                                                             <Separator />
                                                                             <MenuItem ui:Translator.Key="FLIP_LAYERS_HORIZONTALLY" xaml:Menu.Command="PixiEditor.Document.FlipLayersHorizontal"/>
                                                                             <MenuItem ui:Translator.Key="FLIP_LAYERS_VERTICALLY" xaml:Menu.Command="PixiEditor.Document.FlipLayersVertical"/>
@@ -156,12 +151,6 @@
                                         </userControls:Viewport>
                   </DocumentTemplate>
                 </DocumentDock.DocumentTemplate>
-                <Document x:Name="Document1" Id="Document1" Title="SomeDrawing.pixi" x:DataType="Document">
-                  <TextBlock Text="{Binding Title}"/>
-                </Document>
-                <Document x:Name="Document2" Id="Document2" Title="SomePng.png" x:DataType="Document">
-                  <TextBlock Text="{Binding Title}"/>
-                </Document>
               </DocumentDock>
 
               <ProportionalDockSplitter x:Name="RightSplitter" Id="RightSplitter" />

+ 1 - 1
src/PixiEditor.Zoombox/Zoombox.axaml.cs

@@ -136,6 +136,7 @@ public partial class Zoombox : ContentControl, INotifyPropertyChanged
 
     internal VecD ToScreenSpace(VecD p)
     {
+        if (mainCanvas == null) return p;
         VecD delta = p - Center;
         delta = delta.Rotate(Angle) * Scale;
         if (FlipX)
@@ -175,7 +176,6 @@ public partial class Zoombox : ContentControl, INotifyPropertyChanged
 
     static Zoombox()
     {
-        // Add here all with notifyingSetter
         ZoomModeProperty.Changed.Subscribe(ZoomModeChanged);
         ScaleProperty.Changed.Subscribe(OnPropertyChange);
         AngleProperty.Changed.Subscribe(OnPropertyChange);