Browse Source

Fixed layer selection

Krzysztof Krysiński 2 năm trước cách đây
mục cha
commit
a07bd84494

+ 7 - 1
src/PixiEditor.AvaloniaUI/ViewModels/Document/StructureMemberViewModel.cs

@@ -135,7 +135,13 @@ internal abstract class StructureMemberViewModel : ObservableObject, IStructureM
         }
     }
 
-    public StructureMemberSelectionType Selection { get; set; }
+    private StructureMemberSelectionType selection;
+
+    public StructureMemberSelectionType Selection
+    {
+        get => selection;
+        set => SetProperty(ref selection, value);
+    }
 
     public WriteableBitmap? PreviewBitmap { get; set; }
     public DrawingSurface? PreviewSurface { get; set; }

+ 1 - 1
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/LayersViewModel.cs

@@ -375,7 +375,7 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
                 FileTypeFilter = imagesFilter,
             });
 
-            if (filePicker is null)
+            if (filePicker is null || filePicker.Count == 0)
                 return null;
 
             return filePicker[0].Path.AbsolutePath;

+ 5 - 5
src/PixiEditor.AvaloniaUI/Views/Input/EditableTextBlock.axaml

@@ -10,14 +10,14 @@
     <Grid>
         <TextBlock Foreground="{Binding ElementName=etb, Path=Foreground}" PointerPressed="TextBlock_MouseDown"
                    TextTrimming="CharacterEllipsis" Name="textBlock"
-                   IsVisible="{Binding Path=TextBlockVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
-                   Text="{Binding Path=Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}" />
+                   IsVisible="{Binding Path=TextBlockVisibility, ElementName=etb}"
+                   Text="{Binding Path=Text, ElementName=etb, Mode=TwoWay}" />
         <TextBox Foreground="{Binding ElementName=etb, Path=Foreground}"
-                 MaxLength="{Binding Path=MaxChars, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}"
+                 MaxLength="{Binding Path=MaxChars, ElementName=etb, Mode=TwoWay}"
                  LostFocus="TextBox_LostFocus"
-                 Text="{Binding Path=Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}"
+                 Text="{Binding Path=Text, ElementName=etb, Mode=TwoWay}"
                  KeyDown="TextBox_KeyDown"
-                 IsVisible="{Binding Path=!TextBlockVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
+                 IsVisible="{Binding !TextBlockVisibility, ElementName=etb}"
                  Name="textBox">
             <Interaction.Behaviors>
                 <behaviours:GlobalShortcutFocusBehavior/>

+ 5 - 2
src/PixiEditor.AvaloniaUI/Views/Input/EditableTextBlock.axaml.cs

@@ -3,6 +3,7 @@ using Avalonia.Controls;
 using Avalonia.Input;
 using Avalonia.Interactivity;
 using Avalonia.Media;
+using Avalonia.Threading;
 using PixiEditor.AvaloniaUI.Models.Controllers;
 
 namespace PixiEditor.AvaloniaUI.Views.Input;
@@ -11,7 +12,7 @@ internal partial class EditableTextBlock : UserControl
 {
     public static readonly StyledProperty<bool> TextBlockVisibilityProperty =
         AvaloniaProperty.Register<EditableTextBlock, bool>(
-            nameof(TextBlockVisibility));
+            nameof(TextBlockVisibility), true);
 
 
     public static readonly StyledProperty<string> TextProperty =
@@ -79,7 +80,8 @@ internal partial class EditableTextBlock : UserControl
         TextBlockVisibility = false;
         IsEditing = true;
         //TODO: Note Previously there was a dispatcher and keyboard focus.
-        textBox.Focus();         // Set Logical Focus
+
+        textBox.Focus();
         textBox.SelectAll();
     }
 
@@ -105,6 +107,7 @@ internal partial class EditableTextBlock : UserControl
         if (e.ClickCount == 2)
         {
             EnableEditing();
+            e.Handled = true;
         }
     }
 

+ 10 - 2
src/PixiEditor.AvaloniaUI/Views/Layers/FolderControl.axaml

@@ -57,7 +57,11 @@
                     <StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">
                         <Border Width="32" Height="32" BorderThickness="1" BorderBrush="Black" RenderOptions.BitmapInterpolationMode="None">
                             <Border.Background>
-                                <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile" DestinationRect="0, 0, 0.20, 0.20"/>
+                                <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile">
+                                    <ImageBrush.Transform>
+                                        <ScaleTransform ScaleX="0.4" ScaleY="0.4"/>
+                                    </ImageBrush.Transform>
+                                </ImageBrush>
                             </Border.Background>
                             <Image Source="{Binding Folder.PreviewBitmap, ElementName=folderControl}" Stretch="Uniform" Width="30" Height="30">
                                <!--TODO: Avalonia throws error for below-->
@@ -77,7 +81,11 @@
                             IsVisible="{Binding Folder.HasMaskBindable, ElementName=folderControl}"
                             BorderBrush="White">
                             <Border.Background>
-                                <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile" DestinationRect="0, 0, 0.20, 0.20"/>
+                                <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile">
+                                    <ImageBrush.Transform>
+                                        <ScaleTransform ScaleX="0.4" ScaleY="0.4"/>
+                                    </ImageBrush.Transform>
+                                </ImageBrush>
                             </Border.Background>
                             <Grid IsHitTestVisible="False">
                                 <Image Source="{Binding Folder.MaskPreviewBitmap,ElementName=folderControl}" Stretch="Uniform" Width="30" Height="30"

+ 10 - 3
src/PixiEditor.AvaloniaUI/Views/Layers/LayerControl.axaml

@@ -7,7 +7,6 @@
              xmlns:controls="clr-namespace:PixiEditor.Views.UserControls"
              xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              xmlns:sys="clr-namespace:System;assembly=mscorlib"
-             xmlns:views="clr-namespace:PixiEditor.Views"
              xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
              xmlns:helpers="clr-namespace:PixiEditor.AvaloniaUI.Helpers.UI"
              xmlns:converters="clr-namespace:PixiEditor.AvaloniaUI.Helpers.Converters"
@@ -63,7 +62,11 @@
                         RenderOptions.BitmapInterpolationMode="None"
                         PointerPressed="LayerMouseDown">
                         <Border.Background>
-                            <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile" DestinationRect="0, 0, 0.20, 0.20"/>
+                            <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile">
+                                <ImageBrush.Transform>
+                                    <ScaleTransform ScaleX="0.4" ScaleY="0.4"/>
+                                </ImageBrush.Transform>
+                            </ImageBrush>
                         </Border.Background>
                         <Border.BorderBrush>
                             <MultiBinding Converter="{StaticResource LayerBorderConverter}">
@@ -82,7 +85,11 @@
                         IsVisible="{Binding Layer.HasMaskBindable, ElementName=uc}"
                         PointerPressed="MaskMouseDown">
                         <Border.Background>
-                            <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile" DestinationRect="0, 0, 0.20, 0.20"/>
+                            <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile">
+                                <ImageBrush.Transform>
+                                    <ScaleTransform ScaleX="0.4" ScaleY="0.4"/>
+                                </ImageBrush.Transform>
+                            </ImageBrush>
                         </Border.Background>
                         <Border.BorderBrush>
                             <MultiBinding Converter="{StaticResource MaskBorderConverter}">

+ 2 - 9
src/PixiEditor.AvaloniaUI/Views/Layers/LayersManager.axaml.cs

@@ -9,21 +9,14 @@ using PixiEditor.AvaloniaUI.Helpers;
 using PixiEditor.AvaloniaUI.Models.Controllers;
 using PixiEditor.AvaloniaUI.Models.Layers;
 using PixiEditor.AvaloniaUI.ViewModels;
+using PixiEditor.AvaloniaUI.ViewModels.Dock;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
 
 namespace PixiEditor.AvaloniaUI.Views.Layers;
 #nullable enable
 internal partial class LayersManager : UserControl
 {
-    public static readonly StyledProperty<DocumentViewModel> ActiveDocumentProperty = AvaloniaProperty.Register<LayersManager, DocumentViewModel>(
-        nameof(ActiveDocument));
-
-    public DocumentViewModel ActiveDocument
-    {
-        get => GetValue(ActiveDocumentProperty);
-        set => SetValue(ActiveDocumentProperty, value);
-    }
-
+    public DocumentViewModel ActiveDocument => DataContext is LayersDockViewModel vm ? vm.ActiveDocument : null;
     private readonly IBrush? highlightColor;
     public LayersManager()
     {

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

@@ -167,6 +167,7 @@
                             Height="{Binding Document.ReferenceLayerViewModel.ReferenceBitmap.Size.Height}"
                             Source="{Binding Document.ReferenceLayerViewModel.ReferenceBitmap, Mode=OneWay}"
                             IsVisible="{Binding Document.ReferenceLayerViewModel.IsVisibleBindable}"
+                            RenderTransformOrigin="0, 0"
                             SizeChanged="OnReferenceImageSizeChanged"
                             FlowDirection="LeftToRight">
                             <Image.RenderTransform>
@@ -391,7 +392,8 @@
                             </Rectangle.Fill>
                         </Rectangle>
                     </Grid>
-                    <Rectangle Stroke="{DynamicResource ThemeAccentBrush}" Opacity=".8" ZIndex="2"
+                    <!--TODO: what was the purpose of the rectangle below lol-->
+                    <Rectangle Stroke="{DynamicResource ThemeBackgroundBrush1}" Opacity=".8" ZIndex="2"
                                IsVisible="{Binding Document.ReferenceLayerViewModel.IsVisibleBindable}">
                         <Rectangle.StrokeThickness>
                             <Binding Converter="{converters:ReciprocalConverter}">

+ 1 - 1
src/PixiEditor.AvaloniaUI/Views/MainView.axaml

@@ -20,7 +20,7 @@
             <InvokeCommandAction Command="{Binding StartupCommand}"/>
         </EventTriggerBehavior>
     </Interaction.Behaviors>
-    <Grid>
+    <Grid Focusable="True">
         <Grid.RowDefinitions>
             <RowDefinition Height="25"/>
             <RowDefinition Height="*"/>